1<?php
2/*
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004-2021 The Cacti Group                                 |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+
16 | Cacti: The Complete RRDtool-based Graphing Solution                     |
17 +-------------------------------------------------------------------------+
18 | This code is designed, written, and maintained by the Cacti Group. See  |
19 | about.php and/or the AUTHORS file for specific developer information.   |
20 +-------------------------------------------------------------------------+
21 | http://www.cacti.net/                                                   |
22 +-------------------------------------------------------------------------+
23*/
24
25/* get_vdef_item_name - resolves a single VDEF item into its text-based representation
26   @param $vdef_item_id - the id of the individual vdef item
27   @returns - a text-based representation of the vdef item */
28function get_vdef_item_name($vdef_item_id) 	{
29	global $vdef_functions, $vdef_item_types;
30
31	$vdef_item = db_fetch_row_prepared('SELECT type, value FROM vdef_items WHERE id = ?', array($vdef_item_id));
32	$current_vdef_value = $vdef_item['value'];
33
34	switch ($vdef_item['type']) {
35		case '1': return $vdef_functions[$current_vdef_value];
36		case '4': return $current_vdef_value;
37		case '6': return $current_vdef_value;
38	}
39}
40
41/* get_vdef - resolves an entire VDEF into its text-based representation for use in the RRDtool 'graph'
42     string. this name will be resolved recursively if necessary
43   @param $vdef_id - the id of the vdef to resolve
44   @returns - a text-based representation of the vdef */
45function get_vdef($vdef_id, $display = false) {
46	$vdef_items = db_fetch_assoc_prepared('SELECT * FROM vdef_items WHERE vdef_id = ? ORDER BY sequence', array($vdef_id));
47
48	$i = 0; $vdef_string = '';
49
50	if (cacti_sizeof($vdef_items)) {
51		foreach ($vdef_items as $vdef_item) {
52			if ($i > 0) {
53				$vdef_string .= ($display ? ', ':',');
54			}
55
56			if ($vdef_item['type'] == 5) {
57				$current_vdef_id = $vdef_item['value'];
58				$vdef_string .= get_vdef($current_vdef_id, $display);
59			} else {
60				$vdef_string .= get_vdef_item_name($vdef_item['id']);
61			}
62
63			$i++;
64		}
65	}
66
67	return $vdef_string;
68}
69
70function preset_vdef_form_list() {
71	$fields_vdef_edit = array(
72		'name' => array(
73			'method'        => 'textbox',
74			'friendly_name' => __('Name'),
75			'description'   => __('A useful name for this VDEF.'),
76			'value'         => '|arg1:name|',
77			'max_length'    => '255',
78		),
79	);
80
81	return $fields_vdef_edit;
82}
83
84function preset_vdef_item_form_list() {
85	$fields_vdef_item_edit = array(
86		'sequence' => 'sequence',
87		'type' => 'type',
88		'value' => 'value'
89	);
90
91	return $fields_vdef_item_edit;
92}
93