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)  

vlan_campus.inc.php
Go to the documentation of this file.
1 <?php
2 // DON'T put whitespace at the beginning or end of this file!!!
3 
4 
6 // Function: vlan_campus_add (string $options='')
7 //
8 // $options = key=value pairs of options for this function.
9 // multiple sets of key=value pairs should be separated
10 // by an "&" symbol.
11 //
12 // Input Options:
13 // campus=STRING
14 //
15 // Output:
16 // Adds an vlan campus into the database called 'name'
17 // Returns a two part list:
18 // 1. The exit status of the function. 0 on success, non-zero on
19 // error. All errors messages are stored in $self['error'].
20 // 2. A textual message for display on the console or web interface.
21 //
22 // Example: list($status, $result) = vlan_campus_add('name=blah');
24 function vlan_campus_add($options="") {
25 
26  // The important globals
27  global $conf, $self, $onadb;
28 
29  // Version - UPDATE on every edit!
30  $version = '1.01';
31 
32  printmsg("DEBUG => vlan_campus_add({$options}) called", 3);
33 
34  // Parse incoming options string to an array
35  $options = parse_options($options);
36 
37  // Return the usage summary if we need to
38  if ($options['help'] or !($options['name']) ) {
39  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
40  $self['error'] = 'ERROR => Insufficient parameters';
41  return(array(1,
42 <<<EOM
43 
45 Adds a vlan campus into the database
46 
47  Synopsis: vlan_campus_add [KEY=VALUE] ...
48 
49  Required:
50  name=STRING Campus name
51 
52 \n
53 EOM
54 
55  ));
56  }
57 
58 
59  // The formatting rule on vlan campus names is all upper and trim it, spaces to -
60  $options['name'] = strtoupper(trim($options['name']));
61  $options['name'] = preg_replace('/\s+/', '-', $options['name']);
62 
63  // check to see if the campus already exists
64  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['name']));
65 
66  if ($status or $rows) {
67  printmsg("DEBUG => The vlan campus {$options['name']} already exists!",3);
68  $self['error'] = "ERROR => The vlan campus {$options['name']} already exists!";
69  return(array(3, $self['error'] . "\n"));
70  }
71 
72 
73  // Check permissions
74  if (!auth('vlan_add')) {
75  $self['error'] = "Permission denied!";
76  printmsg($self['error'], 0);
77  return(array(10, $self['error'] . "\n"));
78  }
79 
80  // Get the next ID for the new alias
81  $id = ona_get_next_id('vlan_campuses');
82  if (!$id) {
83  $self['error'] = "ERROR => The ona_get_next_id() call failed!";
84  printmsg($self['error'], 0);
85  return(array(5, $self['error'] . "\n"));
86  }
87  printmsg("DEBUG => ID for new VLAN Campus: $id", 3);
88 
89  // Add the record
90  list($status, $rows) =
92  $onadb,
93  'vlan_campuses',
94  array(
95  'id' => $id,
96  'name' => $options['name']
97  )
98  );
99  if ($status or !$rows) {
100  $self['error'] = "ERROR => vlan_campus_add() SQL Query failed: " . $self['error'];
101  printmsg($self['error'],0);
102  return(array(6, $self['error'] . "\n"));
103  }
104 
105  // Return the success notice
106  $self['error'] = "INFO => VLAN Campus ADDED: {$options['name']}";
107  printmsg($self['error'],0);
108  return(array(0, $self['error'] . "\n"));
109 }
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
123 // Function: vlan_campus_del (string $options='')
124 //
125 // $options = key=value pairs of options for this function.
126 // multiple sets of key=value pairs should be separated
127 // by an "&" symbol.
128 //
129 // Input Options:
130 // name=ID
131 //
132 // Output:
133 // Deletes an vlan campus from the database.
134 // Returns a two part list:
135 // 1. The exit status of the function. 0 on success, non-zero on
136 // error. All errors messages are stored in $self['error'].
137 // 2. A textual message for display on the console or web interface.
138 //
139 // Example: list($status, $result) = vlan_campus_del('name=1223543');
141 function vlan_campus_del($options="") {
142 
143  // The important globals
144  global $conf, $self, $onadb;
145 
146  // Version - UPDATE on every edit!
147  $version = '1.00';
148 
149  printmsg("DEBUG => vlan_campus_del({$options}) called", 3);
150 
151  // Parse incoming options string to an array
152  $options = parse_options($options);
153 
154  // Return the usage summary if we need to
155  if ($options['help'] or !$options['name'] ) {
156  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
157  $self['error'] = 'ERROR => Insufficient parameters';
158  return(array(1,
159 <<<EOM
160 
162 Deletes a vlan campus from the database
163 
164  Synopsis: vlan_campus_del [KEY=VALUE] ...
165 
166  Required:
167  name=NAME or ID Name or ID of the vlan campus to delete
168 
169  Optional:
170  commit=[yes|no] commit db transaction (no)
171 
172 \n
173 EOM
174 
175  ));
176  }
177 
178 
179  // Sanitize options[commit] (default is no)
180  $options['commit'] = sanitize_YN($options['commit'], 'N');
181 
182  // If the vlan provided is numeric, check to see if it's an vlan
183  if (is_numeric($options['name'])) {
184 
185  // See if it's an vlan_campus_id
186  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['name']));
187 
188  if (!$campus['id']) {
189  printmsg("DEBUG => Unable to find VLAN campus using the ID {$options['name']}!",3);
190  $self['error'] = "ERROR => Unable to find VLAN campus using the ID {$options['name']}!";
191  return(array(2, $self['error'] . "\n"));
192  }
193  }
194  else {
195  $options['name'] = strtoupper(trim($options['name']));
196  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['name']));
197  if (!$campus['id']) {
198  printmsg("DEBUG => Unable to find VLAN campus using the name {$options['name']}!",3);
199  $self['error'] = "ERROR => Unable to find VLAN campus using the name {$options['name']}!";
200  return(array(2, $self['error'] . "\n"));
201  }
202  }
203 
204 
205  list($status, $rows, $vlan) = db_get_records($onadb, 'vlans', array('vlan_campus_id' => $campus['id']), '' ,0);
206  if ($rows != 0) {
207  printmsg("DEBUG => This VLAN campus ({$campus['name']}) is in use by {$rows} VLAN(s)!",3);
208  $self['error'] = "ERROR => This VLAN campus ({$campus['name']}) is in use by {$rows} VLAN(s)!";
209  return(array(6, $self['error'] . "\n" .
210  "INFO => Please dis-associate those VLANS from this campus before deleting.\n"));
211  }
212 
213  // If "commit" is yes, delete the record
214  if ($options['commit'] == 'Y') {
215 
216  // Check permissions
217  if (!auth('vlan_del')) {
218  $self['error'] = "Permission denied!";
219  printmsg($self['error'], 0);
220  return(array(10, $self['error'] . "\n"));
221  }
222 
223  list($status, $rows) = db_delete_records($onadb, 'vlan_campuses', array('id' => $campus['id']));
224  if ($status or !$rows) {
225  $self['error'] = "ERROR => vlan_campus_del() SQL Query failed: " . $self['error'];
226  printmsg($self['error'], 0);
227  return(array(4, $self['error'] . "\n"));
228  }
229 
230  // Return the success notice
231  $self['error'] = "INFO => VLAN Campus DELETED: {$campus['name']}";
232  printmsg($self['error'],0);
233  return(array(0, $self['error'] . "\n"));
234  }
235 
236 
237 
238  // Otherwise display the record that would have been deleted
239  $text = <<<EOL
240 Record(s) NOT DELETED (see "commit" option)
241 Displaying record(s) that would have been deleted:
242 
243  NAME: {$campus['name']}
244 
245 EOL;
246 
247  return(array(6, $text));
248 
249 }
250 
251 
252 
253 
254 
255 
256 
257 
258 
260 // Function: vlan_campus_modify (string $options='')
261 //
262 // $options = key=value pairs of options for this function.
263 // multiple sets of key=value pairs should be separated
264 // by an "&" symbol.
265 //
266 // Input Options:
267 // name=NAME or ID campus Name or ID
268 // set_name=STRING change vlan name
269 //
270 // Output:
271 // Updates a vlan campus record in the IP database.
272 // Returns a two part list:
273 // 1. The exit status of the function. 0 on success, non-zero on
274 // error. All errors messages are stored in $self['error'].
275 // 2. A textual message for display on the console or web interface.
276 //
277 // Example: list($status, $result) = vlan_campus_modify('name=23452&name=blah');
279 function vlan_campus_modify($options="") {
280 
281  // The important globals
282  global $conf, $self, $onadb;
283 
284  // Version - UPDATE on every edit!
285  $version = '1.01';
286 
287  printmsg("DEBUG => vlan_campus_modify({$options}) called", 3);
288 
289  // Parse incoming options string to an array
290  $options = parse_options($options);
291 
292  // Return the usage summary if we need to
293  if ($options['help'] or (!$options['name']) or (!$options['set_name']) ) {
294  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
295  $self['error'] = 'ERROR => Insufficient parameters';
296  return(array(1,
297 <<<EOM
298 
300 Modifies an existing vlan campus entry in the database
301 
302  Synopsis: vlan_campus_modify [KEY=VALUE] ...
303 
304  Where:
305  name=NAME or ID campus Name or ID
306 
307  Update:
308  set_name=NAME change VLAN campus name
309 
310 \n
311 EOM
312  ));
313  }
314 
315  // The formatting rule on vlan campus names is all upper and trim it, spaces to -
316  $options['name'] = strtoupper(trim($options['name']));
317  $options['set_name'] = strtoupper(trim($options['set_name']));
318  $options['set_name'] = preg_replace('/\s+/', '-', $options['set_name']);
319 
320  // If the vlan provided is numeric, check to see if it's an vlan
321  if (is_numeric($options['name'])) {
322 
323  // See if it's an vlan_campus_id
324  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['name']));
325 
326  if (!$campus['id']) {
327  printmsg("DEBUG => Unable to find VLAN campus using the ID {$options['name']}!",3);
328  $self['error'] = "ERROR => Unable to find VLAN campus using the ID {$options['name']}!";
329  return(array(2, $self['error'] . "\n"));
330  }
331  }
332  else {
333  $options['name'] = strtoupper(trim($options['name']));
334  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['name']));
335  if (!$campus['id']) {
336  printmsg("DEBUG => Unable to find VLAN campus using the name {$options['name']}!",3);
337  $self['error'] = "ERROR => Unable to find VLAN campus using the name {$options['name']}!";
338  return(array(2, $self['error'] . "\n"));
339  }
340  }
341 
342  printmsg("DEBUG => Found VLAN campus: {$campus['name']}", 3);
343 
344 
345  // This variable will contain the updated info we'll insert into the DB
346  $SET = array();
347 
348 
349  // If they are specifying a new name, process it.
350  if ($options['set_name']) {
351  // Validate that there isn't already an vlan with this name
352  list($status, $rows, $record) = db_get_records($onadb, 'vlan_campuses', "id != {$campus['id']} AND name LIKE '{$options['set_name']}'");
353 
354  if ($status or $rows) {
355  printmsg("DEBUG => The VLAN campus ({$options['set_name']}) already exists!",3);
356  $self['error'] = "ERROR => The VLAN campus {$options['set_name']} already exists!";
357  return(array(4, $self['error'] . "\n"));
358  }
359  $SET['name'] = $options['set_name'];
360  }
361 
362 
363  // Check permissions
364  if (!auth('vlan_modify')) {
365  $self['error'] = "Permission denied!";
366  printmsg($self['error'], 0);
367  return(array(10, $self['error'] . "\n"));
368  }
369 
370 
371  // Update the record
372  list($status, $rows) = db_update_record($onadb, 'vlan_campuses', array('id' => $campus['id']), $SET);
373  if ($status or !$rows) {
374  $self['error'] = "ERROR => vlan_campus_modify() SQL Query failed: " . $self['error'];
375  printmsg($self['error'], 0);
376  return(array(6, $self['error'] . "\n"));
377  }
378 
379  // Return the success notice
380  if($options['set_name'] != $campus['name']) $renamed = "=> {$options['set_name']}";
381  $self['error'] = "INFO => VLAN Campus UPDATED: {$campus['name']} {$renamed}";
382 
383  return(array(0, $self['error'] . "\n"));
384 }
385 
386 
387 
388 
389 
390 
391 
392 
393 
395 // Function: vlan_campus_display (string $options='')
396 //
397 // $options = key=value pairs of options for this function.
398 // multiple sets of key=value pairs should be separated
399 // by an "&" symbol.
400 //
401 // Input Options:
402 // campus=NAME or ID
403 //
404 // Output:
405 // Returns a two part list:
406 // 1. The exit status of the function. 0 on success, non-zero on
407 // error. All errors messages are stored in $self['error'].
408 // 2. A textual message for display on the console or web interface.
409 //
410 // Example: list($status, $result) = vlan_campus_display('campus=test');
412 function vlan_campus_display($options="") {
413  global $conf, $self, $onadb;
414 
415  // Version - UPDATE on every edit!
416  $version = '1.00';
417 
418  printmsg("DEBUG => vlan_campus_display({$options}) called", 3);
419 
420  // Parse incoming options string to an array
421  $options = parse_options($options);
422 
423  // Sanitize options[verbose] (default is yes)
424  $options['verbose'] = sanitize_YN($options['verbose'], 'Y');
425 
426  // Return the usage summary if we need to
427  if ($options['help'] or !$options['campus'] ) {
428  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
429  $self['error'] = 'ERROR => Insufficient parameters';
430  return(array(1,
431 <<<EOM
432 
434 Displays a vlan campus record from the database
435 
436  Synopsis: vlan_campus_display [KEY=VALUE] ...
437 
438  Required:
439  campus=NAME or ID Campus name or ID of the campus display
440 
441  Optional:
442  verbose=[yes|no] Display additional info (DEFAULT: yes)
443 
444 
445 EOM
446 
447  ));
448  }
449 
450  // The formatting rule on campus names is all upper and trim it
451  $options['campus'] = strtoupper(trim($options['campus']));
452 
453 
454  // If the campus provided is numeric, check to see if it's valid
455  if (is_numeric($options['campus'])) {
456 
457  // See if it's an vlan_campus_id
458  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['campus']));
459 
460  if (!$campus['id']) {
461  printmsg("DEBUG => Unable to find campus using the ID {$options['campus']}!",3);
462  $self['error'] = "ERROR => Unable to find campus using the ID {$options['campus']}!";
463  return(array(2, $self['error'] . "\n"));
464  }
465  }
466  else {
467  list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['campus']));
468  if (!$campus['id']) {
469  $self['error'] = "ERROR => Unable to find campus using the name {$options['campus']}!";
470  printmsg("DEBUG => Unable to find campus using the name {$options['campus']}!",3);
471  return(array(2, $self['error'] . "\n"));
472  }
473  }
474 
475  printmsg("DEBUG => Found campus: {$campus['name']}", 3);
476 
477  // Build text to return
478  $text = "VLAN CAMPUS RECORD\n";
479  $text .= format_array($campus);
480 
481  // If 'verbose' is enabled, grab some additional info to display
482  if ($options['verbose'] == 'Y') {
483 
484  // vlan record(s)
485  $i = 0;
486  do {
487  list($status, $rows, $vlan) = ona_get_vlan_record(array('vlan_campus_id' => $campus['id']));
488  if ($rows == 0) { break; }
489  $i++;
490  $text .= "\nASSOCIATED VLAN RECORD ({$i} of {$rows})\n";
491  $text .= format_array($vlan);
492  } while ($i < $rows);
493 
494 
495  }
496 
497  // Return the success notice
498  return(array(0, $text));
499 
500 }
501 
502 
503 
504 
505 
506 
507 
508 
509 
510 // DON'T put whitespace at the beginning or end of this file!!!
511 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
sanitize_YN
sanitize_YN($string="", $default="Y")
Definition: functions_general.inc.php:1637
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
vlan_campus_del
vlan_campus_del($options="")
Definition: vlan_campus.inc.php:141
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
ona_get_vlan_campus_record
ona_get_vlan_campus_record($array)
Definition: functions_db.inc.php:1254
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
db_delete_records
db_delete_records($dbh=0, $table="", $where="")
Definition: functions_db.inc.php:582
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
format_array
format_array($array=array())
Definition: functions_general.inc.php:1745
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
ona_get_vlan_record
ona_get_vlan_record($array)
Definition: functions_db.inc.php:1241
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
vlan_campus_add
vlan_campus_add($options="")
Definition: vlan_campus.inc.php:24
$conf
global $conf
Definition: 2-to-3.php:15
vlan_campus_display
vlan_campus_display($options="")
Definition: vlan_campus.inc.php:412
$text
$text
Definition: install.php:11
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
vlan_campus_modify
vlan_campus_modify($options="")
Definition: vlan_campus.inc.php:279
parse_options
parse_options($options="")
Definition: functions_general.inc.php:1579
$version
$version
Definition: main.inc.php:22