forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_templates_items.php
233 lines (190 loc) · 9.67 KB
/
color_templates_items.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2015 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include_once('./include/auth.php');
/* set default action */
if (!isset($_REQUEST['action'])) { $_REQUEST['action'] = ''; }
switch ($_REQUEST['action']) {
case 'save':
aggregate_color_item_form_save();
break;
case 'item_remove':
aggregate_color_item_remove();
header('Location: color_templates.php?header=false&action=template_edit&color_template_id=' . $_GET['color_template_id']);
break;
case 'item_movedown':
aggregate_color_item_movedown();
header('Location: color_templates.php?header=false&action=template_edit&color_template_id=' . $_GET['color_template_id']);
break;
case 'item_moveup':
aggregate_color_item_moveup();
header('Location: color_templates.php?header=false&action=template_edit&color_template_id=' . $_GET['color_template_id']);
break;
case 'item_edit':
top_header();
aggregate_color_item_edit();
bottom_footer();
break;
case 'item':
top_header();
aggregate_color_item();
bottom_footer();
break;
}
/* --------------------------
The Save Function
-------------------------- */
/**
* aggregate_color_item_form_save the save function
*/
function aggregate_color_item_form_save() {
if (isset($_POST['save_component_item'])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post('color_template_id'));
/* ==================================================== */
$items[0] = array();
foreach ($items as $item) {
/* generate a new sequence if needed */
if (empty($_POST['sequence'])) {
$_POST['sequence'] = get_next_sequence($_POST['sequence'], 'sequence', 'color_template_items', 'color_template_id=' . $_POST['color_template_id'], 'color_template_id');
}
$save['color_template_item_id'] = htmlspecialchars($_POST['color_template_item_id']);
$save['color_template_id'] = htmlspecialchars($_POST['color_template_id']);
$save['color_id'] = form_input_validate((isset($item['color_id']) ? $item['color_id'] : $_POST['color_id']), 'color_id', '', true, 3);
$save['sequence'] = htmlspecialchars($_POST['sequence']);
if (!is_error_message()) {
$color_template_item_id = sql_save($save, 'color_template_items', 'color_template_item_id');
if ($color_template_item_id) {
raise_message(1);
}else{
raise_message(2);
}
}
$_POST['sequence'] = 0;
}
if (is_error_message()) {
header('Location: color_templates_items.php?header=false&action=item_edit&color_template_item_id=' . (empty($color_template_item_id) ? $_POST['color_template_item_id'] : $color_template_item_id) . '&color_template_id=' . $_POST['color_template_id']);
exit;
}else{
header('Location: color_templates.php?header=false&action=template_edit&color_template_id=' . $_POST['color_template_id']);
exit;
}
}
}
/* -----------------------
item - Graph Items
----------------------- */
/**
* aggregate_color_item_movedown move item down
*/
function aggregate_color_item_movedown() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var('color_template_item_id'));
input_validate_input_number(get_request_var('color_template_id'));
/* ==================================================== */
$current_sequence = db_fetch_row('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE color_template_item_id=' . $_GET['color_template_item_id'], true);
cacti_log('movedown Id: ' . $current_sequence['color_template_item_id'] . ' Seq:' . $current_sequence['sequence'], FALSE, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
$next_sequence = db_fetch_row('SELET color_template_item_id, sequence
FROM color_template_items
WHERE sequence>' . $current_sequence['sequence'] . '
AND color_template_id=' . $_GET['color_template_id'] . '
ORDER BY sequence ASC limit 1', true);
cacti_log('movedown Id: ' . $next_sequence['color_template_item_id'] . ' Seq:' . $next_sequence['sequence'], FALSE, POLLER_VERBOSITY_DEBUG);
db_execute('UPDATE color_template_items
SET sequence=' . $next_sequence['sequence'] . '
WHERE color_template_id=' . $_GET['color_template_id'] . '
AND color_template_item_id=' . $current_sequence['color_template_item_id']);
db_execute('UPDATE color_template_items
SET sequence=' . $current_sequence['sequence'] . '
WHERE color_template_id=' . $_GET['color_template_id'] . '
AND color_template_item_id=' . $next_sequence['color_template_item_id']);
}
/**
* aggregate_color_item_moveup move item up
*/
function aggregate_color_item_moveup() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var('color_template_item_id'));
input_validate_input_number(get_request_var('color_template_id'));
/* ==================================================== */
$current_sequence = db_fetch_row('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE color_template_item_id=' . $_GET['color_template_item_id'], true);
cacti_log('moveup Id: ' . $current_sequence['color_template_item_id'] . ' Seq:' . $current_sequence['sequence'], FALSE, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
$previous_sequence = db_fetch_row('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE sequence < ' . $current_sequence['sequence'] . '
AND color_template_id=' . $_GET['color_template_id'] . '
ORDER BY sequence DESC limit 1', true);
cacti_log('moveup Id: ' . $previous_sequence['color_template_item_id'] . ' Seq:' . $previous_sequence['sequence'], FALSE, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
db_execute('UPDATE color_template_items
SET sequence=' . $previous_sequence['sequence'] . '
WHERE color_template_id=' . $_GET['color_template_id'] . '
AND color_template_item_id=' . $current_sequence['color_template_item_id']);
db_execute('UPDATE color_template_items
SET sequence=' . $current_sequence['sequence'] . '
WHERE color_template_id=' . $_GET['color_template_id'] . '
AND color_template_item_id=' . $previous_sequence['color_template_item_id']);
}
/**
* aggregate_color_item_remove remove item
*/
function aggregate_color_item_remove() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var('color_template_item_id'));
input_validate_input_number(get_request_var('color_template_id'));
/* ==================================================== */
db_execute('DELETE FROM color_template_items WHERE color_template_item_id=' . $_GET['color_template_item_id']);
}
/**
* aggregate_color_item_edit edit item
*/
function aggregate_color_item_edit() {
global $struct_color_template_item;
/* ================= input validation ================= */
input_validate_input_number(get_request_var('color_template_item_id'));
input_validate_input_number(get_request_var('color_template_id'));
/* ==================================================== */
$template = db_fetch_row('SELECT * FROM color_templates WHERE color_template_id=' . $_GET['color_template_id']);
if (isset($_REQUEST['color_template_item_id']) && ($_REQUEST['color_template_item_id'] > 0)) {
$template_item = db_fetch_row('select * from color_template_items where color_template_item_id=' . $_GET['color_template_item_id']);
$header_label = '[edit Report Item: ' . $template['name'] . ']';
}else{
$template_item = array();
$header_label = '[new Report Item: ' . $template['name'] . ']';
}
form_start('color_templates_items.php', 'aggregate_color_item_edit');
html_start_box("Color Template Items $header_label", '100%', '', '3', 'center', '');
draw_edit_form(array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($struct_color_template_item, (isset($template_item) ? $template_item : array()))
));
html_end_box();
form_hidden_box('color_template_item_id', (array_key_exists('color_template_item_id', $template_item) ? $template_item['color_template_item_id'] : '0'), '');
form_hidden_box('color_template_id', $_GET['color_template_id'], '0');
form_hidden_box('sequence', (array_key_exists('sequence', $template_item) ? $template_item['sequence'] : '0'), '');
form_hidden_box('save_component_item', '1', '');
form_save_button(htmlspecialchars('color_templates.php?header=false&action=template_edit&color_template_id=' . $_GET['color_template_id']), '', 'color_template_item_id');
}