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_config_type_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 types.
11 // If a type id is found in $form it is used to display an existing
12 // type 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('advanced')) {
21  $response = new xajaxResponse();
22  $response->addScript("alert('Permission denied!');");
23  return($response->getXML());
24  }
25 
26  // Set a few parameters for the "results" window we're about to create
27  $window = array(
28  'title' => 'Config Type Editor',
29  'html' => '',
30  'js' => '',
31  );
32 
33  $window['js'] .= <<<EOL
34  /* Put a minimize icon in the title bar */
35  el('{$window_name}_title_r').innerHTML =
36  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
37  el('{$window_name}_title_r').innerHTML;
38 
39  /* Put a help icon in the title bar */
40  el('{$window_name}_title_r').innerHTML =
41  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
42  el('{$window_name}_title_r').innerHTML;
43 EOL;
44 
45  // If we got a manufacturer, load it for display
46  $overwrite = 'no';
47  if (is_numeric($form)) {
48  list($status, $rows, $record) = db_get_record($onadb,
49  'configuration_types',
50  array('id' => $form));
51  if (!$status and $rows) { $overwrite = 'yes'; }
52  }
53 
54 
55  // Escape data for display in html
56  foreach(array_keys((array)$record) as $key) {$record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);}
57 
58  // Load some html into $window['html']
59  $window['html'] .= <<<EOL
60 
61  <!-- Simple class types Edit Form -->
62  <form id="config_type_edit_form" onSubmit="return false;">
63  <input name="id" type="hidden" value="{$record['id']}">
64  <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;">
65  <tr>
66  <td class="input_required" align="right">
67  Name
68  </td>
69  <td class="padding" align="left" width="100%">
70  <input
71  name="config_type_name"
72  alt="Configuration Type Name"
73  value="{$record['name']}"
74  class="edit"
75  type="text"
76  size="30" maxlength="30"
77  >
78  </td>
79  </tr>
80 
81 
82  <tr>
83  <td align="right" valign="top">
84  &nbsp;
85  </td>
86  <td class="padding" align="right" width="100%">
87  <input type="hidden" name="overwrite" value="{$overwrite}">
88  <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
89  <input class="edit" type="button"
90  name="submit"
91  value="Save"
92  accesskey=" "
93  onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('config_type_edit_form'), 'save');"
94  >
95  </td>
96  </tr>
97 
98  </table>
99  </form>
100 
101 EOL;
102 
103 
104  // Lets build a window and display the results
105  return(window_open($window_name, $window));
106 
107 }
108 
109 
110 
111 
112 
113 
114 
116 // Function:
117 // Save Form
118 //
119 // Description:
120 // Creates/updates a type with the info from the submitted form.
122 function ws_save($window_name, $form='') {
123  global $conf, $self, $onadb;
124 
125  // Check permissions
126  if (!auth('advanced')) {
127  $response = new xajaxResponse();
128  $response->addScript("alert('Permission denied!');");
129  return($response->getXML());
130  }
131 
132  // Instantiate the xajaxResponse object
133  $response = new xajaxResponse();
134  $js = '';
135 
136 
137  // Strip whitespace
138  // FIXME: (PK) What about SQL injection attacks? This is a user-entered string...
139  $form['config_type_name'] = trim($form['config_type_name']);
140 
141  // Don't insert a string of all white space!
142  if(trim($form['config_type_name']) == "") {
143  $self['error'] = "ERROR => Blank names not allowed.";
144  printmsg($self['error'], 0);
145  $response->addScript("alert('{$self['error']}');");
146  return($response->getXML());
147  }
148 
149  // check for an existing entry like this
150  list($status, $rows, $test) = ona_get_record(array('name' => $form['config_type_name']), 'configuration_types');
151  if ($rows) {
152  $self['error'] = "ERROR => The name you are trying to use already exists.";
153  printmsg($self['error'], 0);
154  $response->addScript("alert('{$self['error']}');");
155  return($response->getXML());
156  }
157 
158  // If you get a numeric in $form, update the record
159  if (is_numeric($form['id'])) {
160  // Get the record before updating (logging)
161  list($status, $rows, $original_type) = ona_get_record(array('id' => $form['id']), 'configuration_types');
162 
163  if ($form['config_type_name'] !== $original_type['name']) {
164  list($status, $rows) = db_update_record(
165  $onadb,
166  'configuration_types',
167  array('id' => $form['id']),
168  array('name' => $form['config_type_name'])
169  );
170  if ($status or !$rows) {
171  $self['error'] = "ERROR => config_type_edit update ws_save() failed: " . $self['error'];
172  printmsg($self['error'], 0);
173  $response->addScript("alert('{$self['error']}');");
174  }
175  else {
176  // Get the record after updating (logging)
177  list($status, $rows, $new_type) = ona_get_record(array('id' => $form['id']), 'configuration_types');
178 
179  // Return the success notice
180  $self['error'] = "INFO => Configuration type UPDATED:{$new_type['id']}: {$new_type['name']}";
181  printmsg($self['error'], 0);
182  $log_msg = "INFO => Configuration type UPDATED:{$new_type['id']}: name[{$original_type['name']}=>{$new_type['name']}]";
183  printmsg($log_msg, 0);
184  }
185  }
186  }
187  // If you get nothing in $form, create a new record
188  else {
189  $id = ona_get_next_id('configuration_types');
190 
191  if (!$id) {
192  $self['error'] = "ERROR => The ona_get_next_id() call failed!";
193  printmsg($self['error'], 0);
194  }
195  else {
196  printmsg("DEBUG => id for new config type record: $id", 3);
197  list($status, $rows) = db_insert_record($onadb,
198  "configuration_types",
199  array('id' => $id,
200  'name' => trim($form['config_type_name'])));
201 
202  if ($status or !$rows) {
203  $self['error'] = "ERROR => config_type_edit add ws_save() failed: " . $self['error'];
204  printmsg($self['error'], 0);
205  }
206  else {
207  $self['error'] = "INFO => Configuration type ADDED: {$form['config_type_name']} ";
208  printmsg($self['error'], 0);
209  }
210  }
211  }
212 
213  // If the module returned an error code display a popup warning
214  if ($status or !$rows) {
215  $js .= "alert(\"Save failed. ". trim($self['error']) . " (Hint: Does the name you're trying to insert already exist?)\");";
216  }
217  else {
218  $js .= "removeElement('{$window_name}');";
219  $js .= "xajax_window_submit('app_config_type_list', xajax.getFormValues('app_config_type_list_filter_form'), 'display_list');";
220  }
221 
222  // Return some javascript to the browser
223  $response->addScript($js);
224  return($response->getXML());
225 }
226 
227 
228 
229 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
ona_get_next_id
ona_get_next_id($tablename)
Definition: functions_db.inc.php:1369
Name
Full Name
Definition: app_user_info.inc.php:101
$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
id
id
Definition: app_user_info.inc.php:182
ws_editor
ws_editor($window_name, $form='')
Definition: app_config_type_edit.inc.php:15
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_config_type_edit.inc.php:122
$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
ona_get_record
ona_get_record($where="", $table="", $order="")
Definition: functions_db.inc.php:1053
$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