forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_templates_items.php
369 lines (298 loc) · 12.8 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2021 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 */
set_default_action();
switch (get_request_var('action')) {
case 'save':
aggregate_color_item_form_save();
break;
case 'ajax_dnd':
color_templates_item_dnd();
break;
case 'item_remove_confirm':
aggregate_color_item_remove_confirm();
break;
case 'item_remove':
get_filter_request_var('color_template_id');
aggregate_color_item_remove();
header('Location: color_templates.php?action=template_edit&color_template_id=' . get_request_var('id'));
break;
case 'item_movedown':
get_filter_request_var('color_template_id');
aggregate_color_item_movedown();
header('Location: color_templates.php?action=template_edit&color_template_id=' . get_request_var('color_template_id'));
break;
case 'item_moveup':
get_filter_request_var('color_template_id');
aggregate_color_item_moveup();
header('Location: color_templates.php?action=template_edit&color_template_id=' . get_request_var('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_request_var('save_component_item')) {
/* ================= input validation ================= */
get_filter_request_var('color_template_id');
get_filter_request_var('color_template_item_id');
get_filter_request_var('sequence');
/* ==================================================== */
$items[0] = array();
$sequence = get_nfilter_request_var('sequence');
foreach ($items as $item) {
/* generate a new sequence if needed */
if (empty($sequence)) {
$sequence = get_next_sequence($sequence, 'sequence', 'color_template_items', 'color_template_id=' . get_nfilter_request_var('color_template_id'), 'color_template_id');
}
$save['color_template_item_id'] = html_escape_request_var('color_template_item_id');
$save['color_template_id'] = html_escape_request_var('color_template_id');
$save['color_id'] = form_input_validate((isset($item['color_id']) ? $item['color_id'] : get_nfilter_request_var('color_id')), 'color_id', '', true, 3);
$save['sequence'] = $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);
}
}
$sequence = 0;
}
if (is_error_message()) {
header('Location: color_templates_items.php?action=item_edit&color_template_item_id=' . (empty($color_template_item_id) ? get_nfilter_request_var('color_template_item_id') : $color_template_item_id) . '&color_template_id=' . get_nfilter_request_var('color_template_id'));
exit;
} else {
header('Location: color_templates.php?action=template_edit&color_template_id=' . get_nfilter_request_var('color_template_id'));
exit;
}
}
}
/* -----------------------
item - Graph Items
----------------------- */
function color_templates_item_dnd() {
/* ================= Input validation ================= */
get_filter_request_var('id');
/* ================= Input validation ================= */
if (isset_request_var('color_item') && is_array(get_nfilter_request_var('color_item'))) {
$color_items = get_nfilter_request_var('color_item');
if (cacti_sizeof($color_items)) {
$sequence = 1;
foreach($color_items as $option_id) {
$option = str_replace('line', '', $option_id);
db_execute_prepared('UPDATE color_template_items
SET sequence = ?
WHERE color_template_item_id = ?',
array($sequence, $option));
$sequence++;
}
}
}
header('Location: color_templates.php?action=template_edit&color_template_id=' . get_request_var('id'));
exit;
}
/**
* aggregate_color_item_movedown move item down
*/
function aggregate_color_item_movedown() {
/* ================= input validation ================= */
get_filter_request_var('color_template_item_id');
get_filter_request_var('color_template_id');
/* ==================================================== */
$current_sequence = db_fetch_row_prepared('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE color_template_item_id = ?',
array(get_request_var('color_template_item_id')));
cacti_log('movedown Id: ' . $current_sequence['color_template_item_id'] . ' Seq:' . $current_sequence['sequence'],
false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
$next_sequence = db_fetch_row_prepared('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE sequence > ?
AND color_template_id = ?
ORDER BY sequence ASC limit 1',
array($current_sequence['sequence'], get_request_var('color_template_id')));
cacti_log('movedown Id: ' . $next_sequence['color_template_item_id'] . ' Seq:' . $next_sequence['sequence'],
false, POLLER_VERBOSITY_DEBUG);
db_execute_prepared('UPDATE color_template_items
SET sequence = ?
WHERE color_template_id = ?
AND color_template_item_id = ?',
array($next_sequence['sequence'], get_request_var('color_template_id'), $current_sequence['color_template_item_id']));
db_execute_prepared('UPDATE color_template_items
SET sequence = ?
WHERE color_template_id = ?
AND color_template_item_id = ?',
array($current_sequence['sequence'], get_request_var('color_template_id'), $next_sequence['color_template_item_id']));
}
/**
* aggregate_color_item_moveup move item up
*/
function aggregate_color_item_moveup() {
/* ================= input validation ================= */
get_filter_request_var('color_template_item_id');
get_filter_request_var('color_template_id');
/* ==================================================== */
$current_sequence = db_fetch_row_prepared('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE color_template_item_id = ?',
array(get_request_var('color_template_item_id')));
cacti_log('moveup Id: ' . $current_sequence['color_template_item_id'] . ' Seq:' . $current_sequence['sequence'],
false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
$previous_sequence = db_fetch_row_prepared('SELECT color_template_item_id, sequence
FROM color_template_items
WHERE sequence < ?
AND color_template_id = ?
ORDER BY sequence DESC limit 1',
array($current_sequence['sequence'], get_request_var('color_template_id')));
cacti_log('moveup Id: ' . $previous_sequence['color_template_item_id'] . ' Seq:' . $previous_sequence['sequence'],
false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
db_execute_prepared('UPDATE color_template_items
SET sequence = ?
WHERE color_template_id = ?
AND color_template_item_id = ?',
array($previous_sequence['sequence'], get_request_var('color_template_id'), $current_sequence['color_template_item_id']));
db_execute_prepared('UPDATE color_template_items
SET sequence = ?
WHERE color_template_id = ?
AND color_template_item_id = ?',
array($current_sequence['sequence'], get_request_var('color_template_id'), $previous_sequence['color_template_item_id']));
}
function aggregate_color_item_remove_confirm() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('color_id');
/* ==================================================== */
form_start('color_templates.php');
html_start_box('', '100%', '', '3', 'center', '');
$template = db_fetch_row_prepared('SELECT *
FROM color_templates
WHERE color_template_id = ?',
array(get_request_var('id')));
$color_item = db_fetch_row_prepared('SELECT *
FROM color_template_items
WHERE color_template_item_id = ?',
array(get_request_var('color_id')));
$color_hex = db_fetch_cell_prepared('SELECT hex
FROM colors
WHERE id = ?',
array($color_item['color_id']));
?>
<tr>
<td class='topBoxAlt'>
<p><?php print __('Click \'Continue\' to delete the following Color Template Color.'); ?></p>
<p><?php print __('Color Name:');?> '<?php print html_escape($template['name']);?>'<br>
<?php print __('Color Hex:');?><strong><?php print $color_hex;?></p>
</td>
</tr>
<tr>
<td class='right'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='cancel' value='<?php print __esc('Cancel');?>' onClick='$("#cdialog").dialog("close");' name='cancel'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='continue' value='<?php print __esc('Continue');?>' name='continue' title='<?php print __esc('Remove Color Item');?>'>
</td>
</tr>
<?php
html_end_box();
form_end();
?>
<script type='text/javascript'>
$(function() {
$('#continue').click(function(data) {
var options = {
url: 'color_templates_items.php?action=item_remove',
redirect: 'color_templates.php?action=template_edit&color_template_id=<?php print get_request_var('id');?>'
}
var data = {
__csrf_magic: csrfMagicToken,
color_id: <?php print get_request_var('color_id');?>,
id: <?php print get_request_var('id');?>
}
postUrl(options, data);
});
});
</script>
<?php
}
/**
* aggregate_color_item_remove remove item
*/
function aggregate_color_item_remove() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('color_id');
/* ==================================================== */
db_execute_prepared('DELETE FROM color_template_items
WHERE color_template_item_id = ?',
array(get_request_var('color_id')));
}
/**
* aggregate_color_item_edit edit item
*/
function aggregate_color_item_edit() {
global $struct_color_template_item;
/* ================= input validation ================= */
get_filter_request_var('color_template_item_id');
get_filter_request_var('color_template_id');
/* ==================================================== */
$template = db_fetch_row_prepared('SELECT *
FROM color_templates
WHERE color_template_id = ?',
array(get_request_var('color_template_id')));
if (isset_request_var('color_template_item_id') && (get_request_var('color_template_item_id') > 0)) {
$template_item = db_fetch_row_prepared('SELECT *
FROM color_template_items
WHERE color_template_item_id = ?',
array(get_request_var('color_template_item_id')));
$header_label = __esc('Color Template Items [edit Report Item: %s]', $template['name']);
} else {
$template_item = array();
$header_label = __esc('Color Template Items [new Report Item: %s]', $template['name']);
}
form_start('color_templates_items.php', 'aggregate_color_item_edit');
html_start_box($header_label, '100%', true, '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(true, true);
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_request_var('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('color_templates.php?action=template_edit&color_template_id=' . get_request_var('color_template_id'), '', 'color_template_item_id');
}