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)  

custom_attribute.inc.php
Go to the documentation of this file.
1 <?php
2 
3 // Make sure we have necessary functions & DB connectivity
4 require_once($conf['inc_functions_db']);
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
21 // Function: custom_attribute_add (string $options='')
22 //
23 // Input Options:
24 // $options = key=value pairs of options for this function.
25 // multiple sets of key=value pairs should be separated
26 // by an "&" symbol.
27 //
28 // Output:
29 // Returns a two part list:
30 // 1. The exit status of the function (0 on success, non-zero on error)
31 // 2. A textual message for display on the console or web interface.
32 //
33 // Example: list($status, $result) = custom_attribute_add('host=test');
34 //
35 // Exit codes:
36 // 0 :: No error
37 // 1 :: Help text printed - Insufficient or invalid input received
38 // 4 :: SQL Query failed
39 //
40 //
41 // History:
42 //
43 //
45 function custom_attribute_add($options="") {
46 
47  // The important globals
48  global $conf, $self, $onadb;
49 
50  // Version - UPDATE on every edit!
51  $version = '1.01';
52 
53  printmsg("DEBUG => custom_attribute_add({$options}) called", 3);
54 
55  // Parse incoming options string to an array
56  $options = parse_options($options);
57 
58  // Return the usage summary if we need to
59  if ($options['help'] or
60  (!$options['subnet'] and !$options['host'] and !$options['vlan']) or
61  (!$options['type'] and
62  !$options['value'])) {
63  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
64  $self['error'] = 'ERROR => Insufficient parameters';
65  return(array(1,
66 <<<EOM
67 
69 Adds the custom attribute to the host or subnet specified
70 
71  Synopsis: custom_attribute_add
72 
73  Required:
74  host=NAME[.DOMAIN]|IP hostname or IP of the host
75  OR
76  subnet=NAME|IP name or IP of the subnet
77  OR
78  vlan=NAME name of the VLAN
79 
80  type=ID|STRING the name or ID of the attribute type
81  value="STRING" the value of the attribute
82 
83 \n
84 EOM
85 
86  ));
87  }
88 
89 
90  // If they provided a hostname / ID let's look it up
91  if ($options['host']) {
92  list($status, $rows, $host) = ona_find_host($options['host']);
93  $table_name_ref = 'hosts';
94  $table_id_ref = $host['id'];
95  $desc = $host['fqdn'];
96  }
97 
98  // If they provided a subnet name or ip
99  else if ($options['subnet']) {
100  list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
101  $table_name_ref = 'subnets';
102  $table_id_ref = $subnet['id'];
103  $desc = $subnet['name'];
104  }
105 
106  // If they provided a vlan name
107  else if ($options['vlan']) {
108  list($status, $rows, $vlan) = ona_find_vlan($options['vlan']);
109  $table_name_ref = 'vlans';
110  $table_id_ref = $vlan['id'];
111  $desc = $vlan['name'];
112  }
113 
114  // If we didn't get a record then exit
115  if (!$host['id'] and !$subnet['id'] and !$vlan['id']) {
116  printmsg("DEBUG => No host, subnet or vlan found!",3);
117  $self['error'] = "ERROR => No host, subnet or vlan found!";
118  return(array(4, $self['error'] . "\n"));
119  }
120 
121  // determine how we are searching for the type
122  $typesearch = 'name';
123  if (is_numeric($options['type'])) {
124  $typesearch = 'id';
125  }
126 
127  // find the attribute type
128  list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array($typesearch => $options['type']));
129  if (!$rows) {
130  printmsg("DEBUG => Unable to find custom attribute type: {$options['type']}",3);
131  $self['error'] = "ERROR => Unable to find custom attribute type: {$options['type']}";
132  return(array(5, $self['error'] . "\n"));
133  }
134 
135 
136  // check for existing attributes like this
137  list($status, $rows, $record) = ona_get_custom_attribute_record(array('table_name_ref' => $table_name_ref, 'table_id_ref' => $table_id_ref, 'custom_attribute_type_id' => $catype['id']));
138  if ($rows) {
139  printmsg("DEBUG => The type '{$catype['name']}' is already in use on {$desc}",3);
140  $self['error'] = "ERROR => The type '{$catype['name']}' is already in use on {$desc}";
141  return(array(6, $self['error'] . "\n"));
142  }
143 
144  if (!$catype['failed_rule_text']) $catype['failed_rule_text'] = "Not specified.";
145 
146  // validate the inpute value against the field_validation_rule.
147  if ($catype['field_validation_rule'] and !preg_match($catype['field_validation_rule'], $options['value'])) {
148  printmsg("DEBUG => The value '{$options['value']}' does not match field validation rule: {$catype['field_validation_rule']}",3);
149  $self['error'] = "ERROR => The value: '{$options['value']}', does not match field validation rule: {$catype['field_validation_rule']}\\nReason: {$catype['failed_rule_text']}";
150  return(array(7, $self['error'] . "\n"));
151  }
152 
153  // There is an issue with escaping '=' and '&'. We need to avoid adding escape characters
154  $options['value'] = str_replace('\\=','=',$options['value']);
155  $options['value'] = str_replace('\\&','&',$options['value']);
156 
157  // add it
158  list($status, $rows) = db_insert_record(
159  $onadb,
160  'custom_attributes',
161  array(
162  'table_name_ref' => $table_name_ref,
163  'table_id_ref' => $table_id_ref,
164  'custom_attribute_type_id' => $catype['id'],
165  'value' => trim($options['value'])
166  )
167  );
168  if ($status or !$rows) {
169  $self['error'] = "ERROR => custom_attribute_add() SQL Query failed: " . $self['error'];
170  printmsg($self['error'], 0);
171  return(array(8, $self['error'] . "\n"));
172  }
173 
174 
175  $text = "INFO => Custom Attribute ADDED to: {$desc}\n";
176 
177 
178  // Return the message file
179  return(array(0, $text));
180 
181 }
182 
183 
184 
185 
186 
187 
189 // Function: custom_attribute_del (string $options='')
190 //
191 // $options = key=value pairs of options for this function.
192 // multiple sets of key=value pairs should be separated
193 // by an "&" symbol.
194 //
195 // Input Options:
196 // name=ID
197 //
198 // Output:
199 // Deletes an custom_attribute from the database.
200 // Returns a two part list:
201 // 1. The exit status of the function. 0 on success, non-zero on
202 // error. All errors messages are stored in $self['error'].
203 // 2. A textual message for display on the console or web interface.
204 //
205 // Example: list($status, $result) = custom_attribute_del('name=1223543');
207 function custom_attribute_del($options="") {
208 
209  // The important globals
210  global $conf, $self, $onadb;
211 
212  // Version - UPDATE on every edit!
213  $version = '1.01';
214 
215  printmsg("DEBUG => custom_attribute_del({$options}) called", 3);
216 
217  // Parse incoming options string to an array
218  $options = parse_options($options);
219 
220  // Return the usage summary if we need to
221  if ($options['help'] or
222  (!$options['subnet'] and !$options['host'] and !$options['vlan']) or
223  (!$options['type'] )) {
224  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
225  $self['error'] = 'ERROR => Insufficient parameters';
226  return(array(1,
227 <<<EOM
228 
230 Deletes a custom attribute from the database
231 
232  Synopsis: custom_attribute_del [KEY=VALUE] ...
233 
234  Required:
235  host=NAME[.DOMAIN]|IP hostname or IP of the host
236  OR
237  subnet=NAME|IP name or IP of the subnet
238  OR
239  vlan=NAME name of the VLAN
240 
241  type=ID|STRING the name or ID of the attribute type
242 
243  Optional:
244  commit=[yes|no] commit db transaction (no)
245 
246 \n
247 EOM
248 
249  ));
250  }
251 
252 
253  // Sanitize options[commit] (default is no)
254  $options['commit'] = sanitize_YN($options['commit'], 'N');
255 
256  // If they provided a hostname / ID let's look it up
257  if ($options['host']) {
258  list($status, $rows, $host) = ona_find_host($options['host']);
259  $table_name_ref = 'hosts';
260  $table_id_ref = $host['id'];
261  $desc = $host['fqdn'];
262  }
263 
264  // If they provided a subnet name or ip
265  else if ($options['subnet']) {
266  list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
267  $table_name_ref = 'subnets';
268  $table_id_ref = $subnet['id'];
269  $desc = $subnet['name'];
270  }
271 
272  // If they provided a vlan name
273  else if ($options['vlan']) {
274  list($status, $rows, $vlan) = ona_find_vlan($options['vlan']);
275  $table_name_ref = 'vlans';
276  $table_id_ref = $vlan['id'];
277  $desc = $vlan['name'];
278  }
279 
280  // If we didn't get a record then exit
281  if (!$host['id'] and !$subnet['id'] and !$vlan['id']) {
282  printmsg("DEBUG => No host, subnet or vlan found!",3);
283  $self['error'] = "ERROR => No host, subnet or vlan found!";
284  return(array(1, $self['error'] . "\n"));
285  }
286 
287  // If the type provided is numeric, check to see if it's an vlan
288  if (is_numeric($options['type'])) {
289 
290  // See if it's an vlan_campus_id
291  list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array('id' => $options['type']));
292 
293  if (!$catype['id']) {
294  printmsg("DEBUG => Unable to find custom attribute type using the ID {$options['name']}!",3);
295  $self['error'] = "ERROR => Unable to find custom attribute type using the ID {$options['name']}!";
296  return(array(2, $self['error'] . "\n"));
297  }
298  }
299  else {
300  $options['type'] = trim($options['type']);
301  list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array('name' => $options['type']));
302  if (!$catype['id']) {
303  printmsg("DEBUG => Unable to find custom attribute type using the name {$options['type']}!",3);
304  $self['error'] = "ERROR => Unable to find custom attribute type using the name {$options['type']}!";
305  return(array(3, $self['error'] . "\n"));
306  }
307  }
308 
309  list($status, $rows, $record) = ona_get_custom_attribute_record(array('table_name_ref' => $table_name_ref, 'table_id_ref' => $table_id_ref, 'custom_attribute_type_id' => $catype['id']));
310  if (!$rows) {
311  printmsg("DEBUG => Unable to find custom attribute!",3);
312  $self['error'] = "ERROR => Unable to find custom attribute!";
313  return(array(4, $self['error'] . "\n"));
314  }
315 
316 
317  // If "commit" is yes, delete the record
318  if ($options['commit'] == 'Y') {
319 
320  // Check permissions
321  if (!auth('custom_attribute_del')) {
322  $self['error'] = "Permission denied!";
323  printmsg($self['error'], 0);
324  return(array(5, $self['error'] . "\n"));
325  }
326 
327  list($status, $rows) = db_delete_records($onadb, 'custom_attributes', array('id' => $record['id']));
328  if ($status or !$rows) {
329  $self['error'] = "ERROR => custom_attribute_del() SQL Query failed: " . $self['error'];
330  printmsg($self['error'], 0);
331  return(array(6, $self['error'] . "\n"));
332  }
333 
334  // Return the success notice
335  $self['error'] = "INFO => Custom Attribute DELETED: {$record['name']} ({$record['value']}) from {$desc}";
336  printmsg($self['error'],0);
337  return(array(0, $self['error'] . "\n"));
338  }
339 
340 
341 
342  // Otherwise display the record that would have been deleted
343  $text = <<<EOL
344 Record(s) NOT DELETED (see "commit" option)
345 Displaying record(s) that would have been deleted:
346 
347  ASSOCIATED WITH: {$desc}
348  NAME: {$record['name']}
349  VALUE: {$record['value']}
350 
351 
352 EOL;
353 
354  return(array(6, $text));
355 
356 }
357 
358 
359 
360 
361 
362 
363 
364 
365 
366 
367 
369 // Function: custom_attribute_modify (string $options='')
370 //
371 // Input Options:
372 // $options = key=value pairs of options for this function.
373 // multiple sets of key=value pairs should be separated
374 // by an "&" symbol.
375 //
376 // Output:
377 // Returns a two part list:
378 // 1. The exit status of the function (0 on success, non-zero on error)
379 // 2. A textual message for display on the console or web interface.
380 //
381 // Example: list($status, $result) = custom_attribute_modify('host=test');
382 //
383 // Exit codes:
384 // 0 :: No error
385 // 1 :: Help text printed - Insufficient or invalid input received
386 // 4 :: SQL Query failed
387 //
388 //
389 // History:
390 //
391 //
393 function custom_attribute_modify($options="") {
394 
395  // The important globals
396  global $conf, $self, $onadb;
397 
398  // Version - UPDATE on every edit!
399  $version = '1.00';
400 
401  printmsg("DEBUG => custom_attribute_modify({$options}) called", 3);
402 
403  // Parse incoming options string to an array
404  $options = parse_options($options);
405 
406  // Return the usage summary if we need to
407  if ($options['help'] or
408  !(
409  ($options['id'])
410  and
411  (
412  ($options['set_type'] and array_key_exists('set_value',$options))
413  or
414  (array_key_exists('set_value',$options))
415  or
416  (array_key_exists('set_type',$options))
417  )
418  )
419  )
420  {
421  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
422  $self['error'] = 'ERROR => Insufficient parameters';
423  return(array(1,
424 <<<EOM
425 
427 Modifies the custom attribute specified
428 
429  Synopsis: custom_attribute_modify
430 
431  Where:
432  id=ID custom attribute ID
433 
434  Options:
435  set_type=ID|STRING the name or ID of the attribute type
436  set_value="STRING" the value of the attribute
437 
438  Notes:
439  If you specify a type, you must specify a value.
440 \n
441 EOM
442 
443  ));
444  }
445 
446 
447  // Determine the entry itself exists
448  list($status, $rows, $entry) = ona_get_custom_attribute_record(array('id' => $options['id']));
449  if ($status or !$rows) {
450  printmsg("DEBUG => Invalid Custom Atribute record ID ({$options['id']})!",3);
451  $self['error'] = "ERROR => Invalid Custom Atribute record ID ({$options['id']})!";
452  return(array(2, $self['error']. "\n"));
453  }
454 
455  printmsg("DEBUG => custom_attribute_modify(): Found entry, {$entry['name']} => {$entry['value']}", 3);
456  $desc='';
457 
458  // If they provided a hostname / ID let's look it up
459  if ($entry['table_name_ref'] == "hosts") {
460  list($status, $rows, $host) = ona_find_host($entry['table_id_ref']);
461  $table_name_ref = 'hosts';
462  $table_id_ref = $host['id'];
463  $desc = $host['fqdn'];
464  }
465  if ($entry['table_name_ref'] == "subnets") {
466  list($status, $rows, $subnet) = ona_find_subnet($entry['table_id_ref']);
467  $table_name_ref = 'subnets';
468  $table_id_ref = $subnet['id'];
469  $desc = $subnet['name'];
470  }
471 
472 
473  // This variable will contain the updated info we'll insert into the DB
474  $SET = array();
475 
476  $typesearch = 'id';
477  $typeval = $entry['custom_attribute_type_id'];
478 
479  // determine the attribute type
480  if (array_key_exists('set_type', $options)) {
481  if (!is_numeric($options['set_type'])) {
482  $typesearch = 'name';
483  }
484  $typeval = $options['set_type'];
485  }
486 
487  // Find the attribute type
488  list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array($typesearch => $typeval));
489  if (!$rows) {
490  printmsg("DEBUG => Unable to find custom attribute type: {$typeval}",3);
491  $self['error'] = "ERROR => Unable to find custom attribute type: {$typeval}";
492  return(array(3, $self['error'] . "\n"));
493  }
494 
495  // default to whatever was in the record you are editing
496  $SET['value'] = $entry['value'];
497 
498  if (array_key_exists('set_value', $options)) {
499  // There is an issue with escaping '=' and '&'. We need to avoid adding escape characters
500  $options['set_value'] = str_replace('\\=','=',$options['set_value']);
501  $options['set_value'] = str_replace('\\&','&',$options['set_value']);
502 
503  // trim leading and trailing whitespace from 'value'
504  $SET['value'] = $valinfo = trim($options['set_value']);
505  }
506 
507  if (!$catype['failed_rule_text']) $catype['failed_rule_text'] = "Not specified.";
508 
509  // validate the inpute value against the field_validation_rule.
510  if ($catype['field_validation_rule'] and !preg_match($catype['field_validation_rule'], $SET['value'])) {
511  printmsg("DEBUG => The value '{$SET['value']}' does not match field validation rule: {$catype['field_validation_rule']}",3);
512  $self['error'] = "ERROR => The value: '{$SET['value']}', does not match field validation rule: {$catype['field_validation_rule']}\\nReason: {$catype['failed_rule_text']}";
513  return(array(4, $self['error'] . "\n"));
514  }
515 
516  // if the value has not changed, skip it
517  if ($SET['value'] == $entry['value']) { unset($SET['value']); $valinfo = "Value Not Changed";}
518 
519  // if we change the type do a few things
520  if ($catype['id'] != $entry['custom_attribute_type_id']) {
521  // check for existing attributes like this that might already be assigned
522  list($status, $rows, $record) = ona_get_custom_attribute_record(array('table_name_ref' => $table_name_ref, 'table_id_ref' => $table_id_ref, 'custom_attribute_type_id' => $catype['id']));
523  if ($rows) {
524  printmsg("DEBUG => The type '{$catype['name']}' is already in use on {$desc}",3);
525  $self['error'] = "ERROR => The type '{$catype['name']}' is already in use on {$desc}";
526  return(array(5, $self['error'] . "\n"));
527  }
528 
529  // if we are good to go.. set the new type
530  $SET['custom_attribute_type_id'] = $catype['id'];
531  }
532 
533 
534 
535  $msg = "INFO => Updated Custom Attribute type: {$catype['name']} => '{$valinfo}'.";
536 
537  // If nothing at all changed up to this point, bail out
538  if (!$SET) {
539  $self['error'] = "ERROR => custom_attribute_modify() You didn't change anything. Make sure you have a new value.";
540  printmsg($self['error'], 0);
541  return(array(6, $self['error'] . "\n"));
542  }
543 
544  // Update the record
545  list($status, $rows) = db_update_record($onadb, 'custom_attributes', array('id' => $entry['id']), $SET);
546  if ($status or !$rows) {
547  $self['error'] = "ERROR => custom_attribute_modify() SQL Query failed: " . $self['error'];
548  printmsg($self['error'], 0);
549  return(array(7, $self['error'] . "\n"));
550  }
551 
552 
553  // Return the success notice
554  $self['error'] = $msg;
555  printmsg($self['error'], 0);
556  return(array(0, $self['error'] . "\n"));
557 
558 }
559 
560 
561 
562 
563 
564 
565 
567 // Function: custom_attribute_display (string $options='')
568 //
569 // Input Options:
570 // $options = key=value pairs of options for this function.
571 // multiple sets of key=value pairs should be separated
572 // by an "&" symbol.
573 //
574 // Output:
575 // Returns a two part list:
576 // 1. The exit status of the function (0 on success, non-zero on error)
577 // 2. A textual message for display on the console or web interface.
578 //
579 // Example: list($status, $result) = custom_attribute_modify('host=test');
580 //
581 // Exit codes:
582 // 0 :: No error
583 // 1 :: Help text printed - Insufficient or invalid input received
584 //
585 //
586 // History:
587 //
588 //
590 function custom_attribute_display($options="") {
591 
592  // The important globals
593  global $conf, $self, $onadb;
594 
595  $text_array = array();
596 
597  // Version - UPDATE on every edit!
598  $version = '1.02';
599 
600  printmsg("DEBUG => custom_attribute_display({$options}) called", 3);
601 
602  // Parse incoming options string to an array
603  $options = parse_options($options);
604 
605  // Return the usage summary if we need to
606  if ($options['help'] or (!$options['host'] and !$options['id'] and !$options['subnet'] and !$options['vlan'])) {
607  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
608  $self['error'] = 'ERROR => Insufficient parameters';
609  return(array(1,
610 <<<EOM
611 
613 Display the custom attribute specified or attributes for a host
614 
615  Synopsis: custom_attribute_display
616 
617  Where:
618  id=ID custom attribute ID
619  OR
620  host=ID or NAME[.DOMAIN] display custom attributes for specified host
621  OR
622  subnet=ID or NAME display custom attributes for specified subnet
623  OR
624  vlan=NAME display custom attributes for specified VLAN
625 
626  Optional:
627  type=ID or NAME If you specify a type and a host or subnet you
628  will only get back a 1 or a 0 indicating that
629  that type is set or not set for the host or subnet
630 
631 EOM
632 
633  ));
634  }
635 
636 
637  // if a type was set, check if it is associated with the host or subnet and return 1 or 0
638  if ($options['type']) {
639  $field = (is_numeric($options['type'])) ? 'id' : 'name';
640  list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array($field => $options['type']));
641  // error if we cant find the type specified
642  if (!$catype['id']) {
643  $self['error'] = "ERROR => The custom attribute type specified, {$options['type']}, does not exist!";
644  return(array(5, $self['error']));
645  }
646 
647  $where['custom_attribute_type_id'] = $catype['id'];
648  }
649 
650  // Search for the host first
651  if ($options['host']) {
652  list($status, $rows, $host) = ona_find_host($options['host']);
653 
654  // Error if the host doesn't exist
655  if (!$host['id']) {
656  $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!";
657  return(array(2, $self['error']));
658  } else {
659  $where['table_id_ref'] = $host['id'];
660  $where['table_name_ref'] = 'hosts';
661  list($status, $rows, $cas) = db_get_records($onadb,'custom_attributes', $where );
662  }
663 
664  $anchor = 'host';
665  $desc = $host['fqdn'];
666 
667  }
668 
669  // Search for subnet
670  if ($options['subnet']) {
671  list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
672 
673  // Error if the record doesn't exist
674  if (!$subnet['id']) {
675  $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!";
676  return(array(3, $self['error']));
677  } else {
678  $where['table_id_ref'] = $subnet['id'];
679  $where['table_name_ref'] = 'subnets';
680  list($status, $rows, $cas) = db_get_records($onadb,'custom_attributes', $where );
681  }
682 
683  $anchor = 'subnet';
684  $desc = $subnet['description'];
685 
686  }
687 
688  // Search for vlan
689  if ($options['vlan']) {
690  list($status, $rows, $vlan) = ona_find_vlan($options['vlan']);
691 
692  // Error if the record doesn't exist
693  if (!$vlan['id']) {
694  $self['error'] = "ERROR => The VLAN specified, {$options['vlan']}, does not exist!";
695  return(array(3, $self['error']));
696  } else {
697  $where['table_id_ref'] = $vlan['id'];
698  $where['table_name_ref'] = 'vlans';
699  list($status, $rows, $cas) = db_get_records($onadb,'custom_attributes', $where );
700  }
701 
702  $anchor = 'vlan';
703  $desc = $vlan['description'];
704 
705  }
706 
707  // Now find the ID of the record, returns a specific record only
708  if ($options['id']) {
709  list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $options['id']));
710  if (!$ca['id']) {
711  $self['error'] = "ERROR => The custom attribute specified, {$options['id']}, is invalid!";
712  return(array(4, $self['error']));
713  }
714 
715  $text_array = $ca;
716 
717  $text .= "CUSTOM ATTRIBUTE ENTRY RECORD ({$ca['id']})\n";
718  $text .= format_array($ca);
719  } elseif ($options['type']) {
720  // If we requested type, now is the time to return a response if it is found associated.
721  if ($cas[0]) {
722  $text .= '1';
723  $text_array['has_attribute'] = 'Y';
724  } else {
725  $text .= '0';
726  $text_array['has_attribute'] = 'N';
727  }
728  } else {
729 
730  // Build text to return
731  $text .= strtoupper($anchor) . " CUSTOM ATTRIBUTE RECORDS ({$desc})\n";
732 
733  // Display the record(s)
734  $i = 0;
735  do {
736  $text .= "\nASSOCIATED CUSTOM ATTRIBUTE ENTRY RECORD ({$i} of {$rows})\n";
737  $text .= format_array($cas[$i]);
738 
739  list($status, $carows, $ca) = ona_get_custom_attribute_type_record(array('id' => $cas[$i]['custom_attribute_type_id']));
740  $text_array[$ca['name']]=$cas[$i]['value'];
741 
742  $i++;
743  } while ($i < $rows);
744  }
745 
746  // change the output format if other than default
747  if ($options['format'] == 'json') {
748  $text = $text_array;
749  }
750  if ($options['format'] == 'yaml') {
751  $text = $text_array;
752  }
753 
754  // Return the success notice
755  return(array(0, $text));
756 
757 }
758 
759 
760 
761 
762 
764 // Function: custom_attribute_type_display (string $options='')
765 //
766 // Input Options:
767 // $options = key=value pairs of options for this function.
768 // multiple sets of key=value pairs should be separated
769 // by an "&" symbol.
770 //
771 // Output:
772 // Returns a two part list:
773 // 1. The exit status of the function (0 on success, non-zero on error)
774 // 2. A textual message for display on the console or web interface.
775 //
776 // Example: list($status, $result) = custom_attribute_modify('host=test');
777 //
778 // Exit codes:
779 // 0 :: No error
780 // 1 :: Help text printed - Insufficient or invalid input received
781 //
782 //
783 // History:
784 //
785 //
787 function custom_attribute_type_display($options="") {
788 
789  // The important globals
790  global $conf, $self, $onadb;
791 
792  // Version - UPDATE on every edit!
793  $version = '1.0';
794 
795  printmsg("DEBUG => custom_attribute_type_display({$options}) called", 3);
796 
797  // Parse incoming options string to an array
798  $options = parse_options($options);
799 
800  // Return the usage summary if we need to
801  if ($options['help'] or !$options['name']) {
802  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
803  $self['error'] = 'ERROR => Insufficient parameters';
804  return(array(1,
805 <<<EOM
806 
808 Display the custom attribute type specified
809 
810  Synopsis: custom_attribute_type_display [KEY=VALUE] ...
811 
812  Where:
813  name=NAME or ID custom attribute type name or ID
814 
815 EOM
816 
817  ));
818  }
819 
820 
821 
822  // Now find the ID or NAME of the record
823  if ($options['name']) {
824  $field = (is_numeric($options['name'])) ? 'id' : 'name';
825  list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array($field => $options['name']));
826  if (!$catype['id']) {
827  $self['error'] = "ERROR => The custom attribute type specified, {$options['name']}, is invalid!";
828  return(array(2, $self['error'] . "\n"));
829  }
830 
831  $text .= "CUSTOM ATTRIBUTE TYPE ENTRY RECORD ({$catype['id']})\n";
832  $text .= format_array($catype);
833 
834  // change the output format if other than default
835  if ($options['format'] == 'json') {
836  $text = $catype;
837  }
838  if ($options['format'] == 'yaml') {
839  $text = $catype;
840  }
841 
842  // Return the success notice
843  return(array(0, $text));
844  }
845 }
846 
847 
848 
849 ?>
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
custom_attribute_display
custom_attribute_display($options="")
Definition: custom_attribute.inc.php:590
ona_find_subnet
ona_find_subnet($search="")
Definition: functions_db.inc.php:2003
ona_find_host
ona_find_host($search="")
Definition: functions_db.inc.php:1490
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
custom_attribute_type_display
custom_attribute_type_display($options="")
Definition: custom_attribute.inc.php:787
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
custom_attribute_add
custom_attribute_add($options="")
Definition: custom_attribute.inc.php:45
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
ona_get_custom_attribute_record
ona_get_custom_attribute_record($array)
Definition: functions_db.inc.php:1183
$host
$host
Definition: collate-convert.php:19
db_update_record
db_update_record($dbh=0, $table="", $where="", $insert="")
Definition: functions_db.inc.php:474
custom_attribute_modify
custom_attribute_modify($options="")
Definition: custom_attribute.inc.php:393
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
custom_attribute_del
custom_attribute_del($options="")
Definition: custom_attribute.inc.php:207
$text
$text
Definition: install.php:11
$self
global $self
Definition: 2-to-3.php:15
ona_get_custom_attribute_type_record
ona_get_custom_attribute_type_record($array)
Definition: functions_db.inc.php:1179
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
ona_find_vlan
ona_find_vlan($vlan_search="", $campus_search="")
Definition: functions_db.inc.php:2467
parse_options
parse_options($options="")
Definition: functions_general.inc.php:1579
$version
$version
Definition: main.inc.php:22