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)  

edit_custom_attribute.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_editor()
7 //
8 // Description:
9 // Displays a form for creating/editing an custom attribute record.
10 // If $form is a valid custom_attribute_id, it is used to display an existing
11 // record for editing. "Save" button calls the ws_save() function.
13 function ws_editor($window_name, $form='') {
14  global $conf, $self, $onadb;
16  $window = array();
17 
18  // Check permissions
19  if (!auth('custom_attribute_del')) {
20  $response = new xajaxResponse();
21  $response->addScript("alert('Permission denied!');");
22  return($response->getXML());
23  }
24 
25  // If an array in a string was provided, build the array and store it in $form
26  $form = parse_options_string($form);
27 
28  // If $form is a number, it's a record id- so we transform $form into an array
29  if ($form['id']) {
30  list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $form['id']));
31  $window['title'] = "Edit Custom Attribute";
32  }
33  else {
34  $window['title'] = "Add Custom Attribute";
35  }
36 
37  // Load the subnet record and associated info.
38  if (is_numeric($form['subnet_id'])) {
39  list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id']));
40  // Setup a title description for this edit type
41  $window['edit_type'] = "Subnet";
42  $window['edit_type_value'] = $subnet['name'];
43  }
44 
45  // If they are adding a new CA entry they will usually pass a host_id in
46  if (is_numeric($form['host_id'])) {
47  list($status, $rows, $host) = ona_find_host($form['host_id']);
48  // Setup a title description for this edit type
49  $window['edit_type'] = "Host";
50  $window['edit_type_value'] = $host['fqdn'];
51  }
52 
53  if (is_numeric($form['vlan_id'])) {
54  list($status, $rows, $vlan) = ona_find_vlan($form['vlan_id']);
55  // Setup a title description for this edit type
56  $window['edit_type'] = "Vlan";
57  $window['edit_type_value'] = $vlan['name'];
58  }
59 
60  // Escape data for display in html
61  foreach(array_keys((array)$subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); }
62  foreach(array_keys((array)$host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); }
63 
64 
65 
66  // Build dhcp option list
67  list($status, $rows, $catypes) = db_get_records($onadb, 'custom_attribute_types', 'id >= 1', 'name');
68  $ca_type_list = '';
69  foreach ($catypes as $record) {
70  $selected = "";
71  if ($record['id'] == $ca['custom_attribute_type_id']) { $selected = "SELECTED=\"selected\""; }
72  if ($record['id']) {$ca_type_list .= "<option {$selected} value=\"{$record['id']}\">{$record['name']}</option>\n";}
73  }
74 
75  // Javascript to run after the window is built
76  $window['js'] = <<<EOL
77  /* Put a minimize icon in the title bar */
78  el('{$window_name}_title_r').innerHTML =
79  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
80  el('{$window_name}_title_r').innerHTML;
81 
82  /* Put a help icon in the title bar */
83  el('{$window_name}_title_r').innerHTML =
84  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
85  el('{$window_name}_title_r').innerHTML;
86 
87  el('{$window_name}_form').onsubmit = function() { return false; };
88 EOL;
89 
90 
91  // Define the window's inner html
92  $window['html'] = <<<EOL
93 
94  <!-- Custom Attribute Edit Form -->
95  <form id="{$window_name}_form" onSubmit="return false;">
96  <input type="hidden" name="host" value="{$host['id']}">
97  <input type="hidden" name="subnet" value="{$subnet['id']}">
98  <input type="hidden" name="vlan" value="{$vlan['id']}">
99  <input type="hidden" name="id" value="{$ca['id']}">
100  <input type="hidden" name="js" value="{$form['js']}">
101  <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;">
102 
103  <!-- Custom Attribute RECORD -->
104  <tr>
105  <td align="left" nowrap="true"><b><u>CA Record</u></b>&nbsp;</td>
106  <td class="padding" align="left" width="100%">&nbsp;</td>
107  </tr>
108 
109  <tr>
110  <td align="right" nowrap="true">
111  {$window['edit_type']}:
112  </td>
113  <td class="padding" align="left" width="100%">
114  {$window['edit_type_value']}
115  </td>
116  </tr>
117 
118  <tr>
119  <td class="input_required" align="right" nowrap="true">
120  Type
121  </td>
122  <td class="padding" align="left" width="100%">
123  <select id="type" name="type" class="edit" accesskey="t">
124  {$ca_type_list}
125  </select>
126  </td>
127  </tr>
128 
129  <tr>
130  <td class="input_required" align="right" nowrap="true">
131  Value
132  </td>
133  <td class="padding" align="left" width="100%">
134  <textarea
135  name="value"
136  alt="Value"
137  class="edit"
138  rows="5"
139  cols="25"
140  >{$ca['value']}</textarea>
141  </td>
142  </tr>
143 
144 
145 
146  <tr>
147  <td align="right" valign="top" nowrap="true">
148  &nbsp;
149  </td>
150  <td class="padding" align="right" width="100%">
151  <input type="hidden" name="overwrite" value="{$overwrite}">
152  <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
153  <input class="edit" type="button"
154  name="submit"
155  value="Save"
156  accesskey=" "
157  onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_form'), 'save');"
158  >
159  </td>
160  </tr>
161 
162  </table>
163  </form>
164 EOL;
165 
166 
167  return(window_open($window_name, $window));
168 }
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
188 // Function:
189 // Save Form
190 //
191 // Description:
192 // Creates/updates a custom attribute record.
194 function ws_save($window_name, $form='') {
195  global $base, $include, $conf, $self, $onadb;
196 
197  // Check permissions
198  if (!auth('custom_attribute_add')) {
199  $response = new xajaxResponse();
200  $response->addScript("alert('Permission denied!');");
201  return($response->getXML());
202  }
203 
204  // Instantiate the xajaxResponse object
205  $response = new xajaxResponse();
206  $js = '';
207 
208  // Validate input
209  if (!$form['type'] and !$form['value']) {
210  $response->addScript("alert('Please complete all fields to continue!');");
211  return($response->getXML());
212  }
213 
214  // Validate the host is valid
215  // FIXME: we should do this, but since it's not an editable field it's not too big of a deal
216 
217  // Decide if we're editing or adding
218  $module = 'custom_attribute_add';
219  if ($form['id']) {
220  $module = 'custom_attribute_modify';
221  $form['set_type'] = $form['type'];
222  $form['set_value'] = $form['value'];
223  }
224 
225  // Run the module
226  list($status, $output) = run_module($module, $form);
227 
228  // If the module returned an error code display a popup warning
229  if ($status) {
230  $js .= "alert('Save failed: ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
231  }
232  else {
233  $js .= "removeElement('{$window_name}');";
234  // If there's JS, add it to $js so we'll send it to the browser later.
235  if ($form['js']) { $js .= $form['js']; }
236  }
237 
238  // Insert the new table into the window
239  $response->addScript($js);
240  return($response->getXML());
241 
242 }
243 
244 
245 
246 
247 
248 
249 
250 
252 // Function:
253 // Delete Form
254 //
255 // Description:
256 // Deletes a record.
258 function ws_delete($window_name, $form='') {
259  global $base, $include, $conf, $self, $onadb;
260 
261  // Check permissions
262  if (!auth('custom_attribute_del')) {
263  $response = new xajaxResponse();
264  $response->addScript("alert('Permission denied!');");
265  return($response->getXML());
266  }
267 
268  // If an array in a string was provided, build the array and store it in $form
269  $form = parse_options_string($form);
270 
271  // Instantiate the xajaxResponse object
272  $response = new xajaxResponse();
273  $js = '';
274 
275  // if ($form['host']) {$kind = 'host'; $kindval = $form['host'];}
276  //elseif ($form['subnet']) {$kind = 'subnet'; $kindval = $form['subnet'];}
277 
278  // Run the module
279  list($status, $output) = run_module('custom_attribute_del', array($form['kind'] => $form[$form['kind'].'_id'], 'type' => $form['type'], 'commit' => 'Y'));
280 
281  // If the module returned an error code display a popup warning
282  if ($status) { $js .= "alert('Delete failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');"; }
283  else {
284  // If there's JS, add it to $js so we'll send it to the browser later.
285  if ($form['js']) { $js .= $form['js']; }
286  }
287 
288  // Return an XML response
289  $response->addScript($js);
290  return($response->getXML());
291 
292 }
293 
294 
295 
296 ?>
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
ws_editor
ws_editor($window_name, $form='')
Definition: edit_custom_attribute.inc.php:13
$window
$window['title']
Definition: install.php:26
$include
$include
Definition: 2-to-3.php:10
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
ona_get_custom_attribute_record
ona_get_custom_attribute_record($array)
Definition: functions_db.inc.php:1183
$host
$host
Definition: collate-convert.php:19
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
ws_save
ws_save($window_name, $form='')
Definition: edit_custom_attribute.inc.php:194
$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
$conf
global $conf
Definition: 2-to-3.php:15
ws_delete
ws_delete($window_name, $form='')
Definition: edit_custom_attribute.inc.php:258
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
$output
$output
Definition: dcm.php:16
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$base
$base
Definition: 2-to-3.php:8
ona_get_subnet_record
ona_get_subnet_record($array)
Definition: functions_db.inc.php:1226
ona_find_vlan
ona_find_vlan($vlan_search="", $campus_search="")
Definition: functions_db.inc.php:2467
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88