ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

app_group_edit.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function:
7 // Display Edit Form
8 //
9 // Description:
10 // Displays a form for creating/editing a group.
11 // If a group id is found in $form it is used to display an existing
12 // group for editing. When "Save" is pressed the save()
13 // function is called.
15 function ws_editor($window_name, $form='') {
16  global $conf, $self, $onadb;
18 
19  // Check permissions
20  if (!auth('user_admin')) {
21  $response = new xajaxResponse();
22  $response->addScript("alert('Permission denied!');");
23  return($response->getXML());
24  }
25 
26  $window['js'] .= <<<EOL
27  /* Put a minimize icon in the title bar */
28  el('{$window_name}_title_r').innerHTML =
29  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
30  el('{$window_name}_title_r').innerHTML;
31 
32  /* Put a help icon in the title bar */
33  el('{$window_name}_title_r').innerHTML =
34  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
35  el('{$window_name}_title_r').innerHTML;
36 EOL;
37 
38  // Set a few parameters for the "results" window we're about to create
39  $window = array(
40  'title' => 'Group Editor',
41  'html' => '',
42  'js' => '',
43  );
44 
45  // If we got a group ID, load it for display
46  if (is_string($form) and $form) {
47  list($status, $rows, $record) = db_get_record($onadb, 'groups', array('id' => $form));
48  }
49 
50  // Build some html for selecting the groups the group is in
51  $group_check_list = "";
52 
53  // Escape data for display in html
54  foreach(array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); }
55 
56  // Load some html into $window['html']
57  $window['html'] .= <<<EOL
58 
59  <!-- Simple Group Edit Form -->
60  <form id="group_edit_form" onSubmit="return false;">
61  <input type="hidden" name="id" value="{$record['id']}">
62  <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">
63  <tr>
64  <td align="right">
65  Group
66  </td>
67  <td class="padding" align="left" width="100%">
68  <input
69  name="name"
70  alt="Group name"
71  value="{$record['name']}"
72  class="edit"
73  type="text"
74  size="20" maxlength="32"
75  >
76  </td>
77  </tr>
78 
79  <tr>
80  <td align="right">
81  Description
82  </td>
83  <td class="padding" align="left" width="100%">
84  <input
85  name="description"
86  alt="Group description"
87  value="{$record['description']}"
88  class="edit"
89  type="text"
90  size="32" maxlength="128"
91  >
92  </td>
93  </tr>
94 
95  <tr>
96  <td align="right" valign="top">
97  &nbsp;
98  </td>
99  <td class="padding" align="right" width="100%">
100  <input type="hidden" name="overwrite" value="{$overwrite}">
101  <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
102  <input class="edit" type="button"
103  name="submit"
104  value="Save"
105  accesskey=" "
106  onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('group_edit_form'), 'save');"
107  >
108  </td>
109  </tr>
110 
111  </table>
112  </form>
113 
114 EOL;
115 
116 
117  // Lets build a window and display the results
118  return(window_open($window_name, $window));
119 
120 }
121 
122 
123 
124 
125 
126 
127 
129 // Function:
130 // Save Form
131 //
132 // Description:
133 // Creates/updates a group with the info from the submitted form.
135 function ws_save($window_name, $form='') {
136  global $conf, $self, $onadb;
137 
138  // Check permissions
139  if (!auth('user_admin')) {
140  $response = new xajaxResponse();
141  $response->addScript("alert('Permission denied!');");
142  return($response->getXML());
143  }
144 
145  // Instantiate the xajaxResponse object
146  $response = new xajaxResponse();
147  $js = '';
148 
149  // Validate input
150  if (!$form['name']) {
151  $js .= "alert('Error! All fields are required!');";
152  $response->addScript($js);
153  return($response->getXML());
154  }
155  if (!preg_match('/^[A-Za-z0-9.\-_ ]+$/', $form['name'])) {
156  $js .= "alert('Invalid group name! Valid characters: A-Z 0-9 .-_ and space');";
157  $response->addScript($js);
158  return($response->getXML());
159  }
160 
161  //MP: zero out the level for now
162  //TODO: fix or remove level at some point
163  $form['level'] = 0;
164 
165  // Create a new record?
166  if (!$form['id']) {
167  list ($status, $rows) = db_insert_record(
168  $onadb,
169  'groups',
170  array(
171  'name' => $form['name'],
172  'description' => $form['description'],
173  'level' => $form['level']
174  )
175  );
176 
177  if ($status or !$rows) {
178  $self['error'] = "ERROR => group_edit add ws_save() SQL Query failed: " . $self['error'];
179  printmsg($self['error'], 0);
180  }
181  else {
182  $self['error'] = "INFO => Group ADDED: {$form['name']} ";
183  printmsg($self['error'], 0);
184  }
185 
186  }
187 
188  // Update an existing record?
189  else {
190  list($status, $rows, $record) = db_get_record($onadb, 'groups', array('id' => $form['id']));
191  if ($rows != 1 or $record['id'] != $form['id']) {
192  $js .= "alert('Error! The record requested could not be loaded from the database!');";
193  $response->addScript($js);
194  return($response->getXML());
195  }
196 
197  list ($status, $rows) = db_update_record(
198  $onadb,
199  'groups',
200  array(
201  'id' => $form['id'],
202  ),
203  array(
204  'name' => $form['name'],
205  'description' => $form['description']
206  )
207  );
208 
209  if ($status or !$rows) {
210  $self['error'] = "ERROR => group_edit update ws_save() SQL Query failed: " . $self['error'];
211  printmsg($self['error'], 0);
212  }
213  else {
214  list($status, $rows, $new_record) = db_get_record($onadb, 'groups', array('id' => $form['id']));
215 
216  // Return the success notice
217  $self['error'] = "INFO => Group UPDATED:{$record['id']}: {$record['name']}";
218 
219  $log_msg = "INFO => Group UPDATED:{$record['id']}: ";
220  $more="";
221  foreach(array_keys($record) as $key) {
222  if($record[$key] != $new_record[$key]) {
223  $log_msg .= $more . $key . "[" .$record[$key] . "=>" . $new_record[$key] . "]";
224  $more= ";";
225  }
226  }
227 
228  // only print to logfile if a change has been made to the record
229  if($more != '') {
230  printmsg($self['error'], 0);
231  printmsg($log_msg, 0);
232  }
233  }
234  }
235 
236  // If the module returned an error code display a popup warning
237  if ($status) {
238  $js .= "alert('Save failed. Contact the webmaster if this problem persists.');";
239  }
240  else {
241  $js .= "removeElement('{$window_name}');";
242  $js .= "xajax_window_submit('app_group_list', xajax.getFormValues('app_group_list_filter_form'), 'display_list');";
243  }
244 
245  // Insert the new table into the window
246  $response->addScript($js);
247  return($response->getXML());
248 }
249 
250 
251 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
$window
$window['title']
Definition: install.php:26
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
$images
$images
Definition: config.inc.php:26
EOL
< a style="text-decoration: none;" href="/">< input class='edit' type="button" value="I don't like free stuff?" onclick=""/></a ></center ></div > EOL
Definition: install.php:40
ws_save
ws_save($window_name, $form='')
Definition: app_group_edit.inc.php:135
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
nbsp
& nbsp
Definition: install.php:36
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
ws_editor
ws_editor($window_name, $form='')
Definition: app_group_edit.inc.php:15
$self
global $self
Definition: 2-to-3.php:15
db_get_record
db_get_record($dbh=0, $table="", $where="", $order="")
Definition: functions_db.inc.php:708
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119