-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgpstemplates.php
More file actions
294 lines (249 loc) · 10 KB
/
Copy pathgpstemplates.php
File metadata and controls
294 lines (249 loc) · 10 KB
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
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2009-2013 Andrew Aloia |
| Copyright (C) 2014 Wixiweb |
| Copyright (C) 2004-2026 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. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
include_once('./include/auth.php');
include_once('./plugins/gpsmap/gpsmap_security.php');
$ds_actions = [
1 => __('Delete')
];
set_default_action();
if (isset_request_var('drp_action')) {
if (get_filter_request_var('drp_action') == 1) {
set_request_var('action', 'delete');
}
}
switch (get_nfilter_request_var('action')) {
case 'delete':
template_delete();
break;
case 'edit':
template_edit();
break;
case 'save':
gpsmap_save_template();
break;
default:
top_header();
templates();
bottom_footer();
break;
}
/**
* Renders the main Map Templates list page: a checkbox table of every
* gpsmap_templates row (host template mapping, up/down/recovering icons,
* Access Point flag), with a bulk-delete action. Invoked from this
* file's dispatcher for the default (no 'action') request.
*
* @return void Outputs the list page HTML directly.
*
* @global array $config Cacti global configuration array; used to
* build each icon's image URL.
* @global array $ds_actions Map of bulk-action ids to their display
* labels (only '1' => Delete), used to
* populate the actions dropdown.
*/
function templates() {
global $config, $ds_actions;
form_start('gpstemplates.php', 'chk');
html_start_box(__('Map Templates', 'gpsmap'), '100%', false, 3, 'center', 'gpstemplates.php?action=edit');
$display_text = [
__('Host Template', 'gpsmap'),
__('Up Image', 'gpsmap'),
__('Recovering Image', 'gpsmap'),
__('Down Image', 'gpsmap'),
__('Is AP', 'gpsmap')
];
html_header_checkbox($display_text);
$template_list = db_fetch_assoc('SELECT *
FROM gpsmap_templates
ORDER BY templateID');
if (cacti_sizeof($template_list)) {
foreach ($template_list as $template) {
if ($template['AP']) {
$isAP = __('True', 'gpsmap');
} else {
$isAP = __('False', 'gpsmap');
}
$url = $config['url_path'] . 'plugins/gpsmap/gpstemplates.php?action=edit&id=' . $template['templateID'];
form_alternate_row('line' . $template['templateID'], true);
form_selectable_cell("<a class='linkEditMain' href='" . html_escape($url) . "'>" . html_escape($template['templateName']) . '</a>', $template['templateID']);
form_selectable_cell("<img src='" . $config['url_path'] . 'plugins/gpsmap/images/icons/' . html_escape($template['upimage']) . "'>", $template['templateID']);
form_selectable_cell("<img src='" . $config['url_path'] . 'plugins/gpsmap/images/icons/' . html_escape($template['recoverimage']) . "'>", $template['templateID']);
form_selectable_cell("<img src='" . $config['url_path'] . 'plugins/gpsmap/images/icons/' . html_escape($template['downimage']) . "'>", $template['templateID']);
form_selectable_cell($isAP, $template['templateID']);
form_checkbox_cell($template['templateID'], $template['templateID']);
form_end_row();
}
} else {
print '<tr><td colspan="' . (cacti_sizeof($display_text) + 1) . '"><em>No Data Templates</em></td></tr>';
}
html_end_box(false);
draw_actions_dropdown($ds_actions);
form_end();
}
/**
* Deletes every Map Template selected via the templates list's bulk-
* delete checkboxes. Invoked from this file's dispatcher when the
* request's 'action' (derived from 'drp_action') is 'delete'.
*
* @return void Redirects back to the template list; does not return a
* value.
*/
function template_delete() {
foreach (gpsmap_template_ids_from_request($_POST) as $id) {
db_execute_prepared('DELETE FROM gpsmap_templates WHERE templateID = ?', [$id]);
}
header('Location: gpstemplates.php?header=false');
exit;
}
/**
* Renders the add/edit form for a single Map Template (host template
* mapping, up/down/recovering icons, Access Point flag), with a custom
* jQuery UI selectmenu that shows each icon's image inline in the
* dropdown. Invoked from this file's dispatcher when the request's
* 'action' is 'edit'.
*
* @return void Outputs the edit form HTML and JavaScript directly.
*
* @global array $config Cacti global configuration array; used to build
* each icon's image URL in the custom selectmenu
* widget.
*/
function template_edit() {
global $config;
$template = db_fetch_row_prepared('SELECT *
FROM `gpsmap_templates`
WHERE templateID = ?',
[get_filter_request_var('id')]);
// get all icons in the icon folder
$iconArray = getIcons();
$form_template = [
'templateID' => [
'method' => 'drop_sql',
'friendly_name' => __('Device Template', 'gpsmap'),
'description' => __('Choose the Device Template to base this Map Template type.', 'gpsmap'),
'value' => '|arg1:templateID|',
'sql' => 'SELECT id, name FROM host_template ORDER BY name ASC'
],
'upimage' => [
'method' => 'drop_array',
'friendly_name' => __('Up Image', 'gpsmap'),
'description' => __('Select the Image to Show for an Up Device', 'gpsmap'),
'value' => '|arg1:upimage|',
'default' => 'Green.png',
'array' => $iconArray
],
'recoverimage' => [
'method' => 'drop_array',
'friendly_name' => __('Recovering Image', 'gpsmap'),
'description' => __('Select the Image to Show for a Recovering Device', 'gpsmap'),
'value' => '|arg1:recoverimage|',
'default' => 'Orange.png',
'array' => $iconArray
],
'downimage' => [
'method' => 'drop_array',
'friendly_name' => __('Down Image', 'gpsmap'),
'description' => __('Select the Image to Show for a Down Device', 'gpsmap'),
'value' => '|arg1:downimage|',
'default' => 'Red.png',
'array' => $iconArray
],
'AP' => [
'method' => 'drop_array',
'friendly_name' => __('Access Point', 'gpsmap'),
'description' => __('Does this Device Template Represent an Access Point.', 'gpsmap'),
'value' => '|arg1:AP|',
'array' => [
0 => __('No', 'gpsmap'),
1 => __('Yes', 'gpsmap')
]
]
];
top_header();
form_start('gpstemplates.php', 'gpsform');
html_start_box(__('Map Template Edit', 'gpsmap'), '100%', false, 3, 'center', '');
draw_edit_form(
[
'config' => ['no_form_tag' => true],
'fields' => inject_form_variables($form_template, $template)
]
);
?>
<script type='text/javascript'>
$.widget('custom.mapiconselectmenu', $.ui.selectmenu, {
_renderItem: function(ul, item) {
var li = $('<li>');
//var wrapper = $('<div>', {title: item.label});
var wrapper = $('<div>');
if (item.disabled) {
li.addClass('ui-state-disabled');
}
$('<img>', {
src: urlPath+'plugins/gpsmap/images/icons/'+item.label,
style: 'display:inline-block;width:12px;height:20px;'
}).appendTo(wrapper);
return li.append(wrapper).prependTo(ul);
}
});
$(function() {
$('#upimage').selectmenu('destroy').mapiconselectmenu().mapiconselectmenu('menuWidget').addClass('ui-menu-icons customicons');
$('#recoverimage').selectmenu('destroy').mapiconselectmenu().mapiconselectmenu('menuWidget').addClass('ui-menu-icons customicons');
$('#downimage').selectmenu('destroy').mapiconselectmenu().mapiconselectmenu('menuWidget').addClass('ui-menu-icons customicons');
});
</script>
<?php
html_end_box();
form_save_button('gpstemplates.php?action=edit&id=' . get_request_var('id'));
bottom_footer();
}
/**
* Validates and saves a single Map Template (deriving its display name
* from the mapped host template, and normalizing each selected icon
* filename to a known-safe value) from the submitted edit form. Invoked
* from this file's dispatcher when the request's 'action' is 'save'.
*
* @return void
*
* @global array $config Cacti global configuration array; reserved/
* declared for parity with other save functions in
* this file; not used directly here.
*/
function gpsmap_save_template() {
global $config;
$iconArray = getIcons();
$save = [];
$save['templateID'] = get_filter_request_var('templateID');
$save['templateName'] = db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', [$save['templateID']]);
$save['upimage'] = gpsmap_normalize_icon_name(get_nfilter_request_var('upimage'), $iconArray, 'Green.png');
$save['recoverimage'] = gpsmap_normalize_icon_name(get_nfilter_request_var('recoverimage'), $iconArray, 'Orange.png');
$save['downimage'] = gpsmap_normalize_icon_name(get_nfilter_request_var('downimage'), $iconArray, 'Red.png');
$save['AP'] = get_filter_request_var('AP');
$templateID = sql_save($save, 'gpsmap_templates', 'templateID');
if ($templateID > 0) {
raise_message(1);
} else {
raise_message(2);
}
header('Location: gpstemplates.php?header=false');
exit;
}
// ------------------------------------------------------------------------------