-
-
Notifications
You must be signed in to change notification settings - Fork 406
/
aggregate_templates.php
762 lines (631 loc) · 23.7 KB
/
aggregate_templates.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 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');
include_once('./lib/api_aggregate.php');
include_once('./lib/data_query.php');
$actions = array(
1 => __('Delete')
);
/* set default action */
set_default_action();
if (get_request_var('action') == 'save') {
if (isset_request_var('id') && get_filter_request_var('id') == 0 && isset_request_var('graph_template_id_prev') && get_filter_request_var('graph_template_id_prev') == 0) {
set_request_var('action', 'edit');
}
}
switch (get_request_var('action')) {
case 'save':
aggregate_form_save();
break;
case 'actions':
aggregate_form_actions();
break;
case 'edit':
top_header();
aggregate_template_edit();
bottom_footer();
break;
default:
top_header();
aggregate_template();
bottom_footer();
break;
}
/**
* aggregate_form_save the save function
*/
function aggregate_form_save() {
/* make sure we are saving aggregate template */
if (!isset_request_var('save_component_template')) {
header('Location: aggregate_templates.php?action=edit&id=' . get_nfilter_request_var('id'));
return null;
}
$save1 = array();
/* updating existing template or creating a new one? */
if (isset_request_var('id') && get_request_var('id') > 0) {
$is_new = false;
$save1['id'] = get_nfilter_request_var('id');
} else {
$is_new = true;
$save1['id'] = 0;
}
/* set some defaults for possibly disabled values */
if (!isset_request_var('total')) {
set_request_var('total', 0);
}
if (!isset_request_var('total_type')) {
set_request_var('total_type', 0);
}
if (!isset_request_var('order_type')) {
set_request_var('order_type', 0);
}
if (!isset_request_var('total_prefix')) {
set_request_var('total_prefix', '');
}
/* populate aggregate template save array and validate posted values*/
$save1['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save1['graph_template_id'] = get_filter_request_var('graph_template_id_prev');
$save1['gprint_prefix'] = form_input_validate(get_nfilter_request_var('gprint_prefix'), 'gprint_prefix', '', true, 3);
$save1['gprint_format'] = isset_request_var('gprint_format') ? 'on' : '';
$save1['graph_type'] = form_input_validate(get_nfilter_request_var('graph_type'), 'graph_type', '', false, 3);
$save1['total'] = form_input_validate(get_nfilter_request_var('total'), 'total', '', false, 3);
$save1['total_type'] = form_input_validate(get_nfilter_request_var('total_type'), 'total_type', '', false, 3);
$save1['total_prefix'] = form_input_validate(get_nfilter_request_var('total_prefix'), 'total_prefix', '', true, 3);
$save1['order_type'] = form_input_validate(get_nfilter_request_var('order_type'), 'order_type', '', false, 3);
$save1['user_id'] = $_SESSION[SESS_USER_ID];
/* form validation failed */
if (is_error_message()) {
header('Location: aggregate_templates.php?action=edit&id=' . get_nfilter_request_var('id'));
return null;
}
cacti_log('AGGREGATE GRAPH TEMPLATE Saved ID: ' . $save1['id'] . ' Name: ' . $save1['name'], false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
/* do a quick comparison to see if anything changed */
if ($is_new == false) {
$old = db_fetch_row_prepared(
'SELECT *
FROM aggregate_graph_templates
WHERE id = ?',
array($save1['id'])
);
$save_me = 0;
$save_me += ($old['name'] != $save1['name']);
$save_me += ($old['gprint_prefix'] != $save1['gprint_prefix']);
$save_me += ($old['gprint_format'] != $save1['gprint_format']);
$save_me += ($old['graph_type'] != $save1['graph_type']);
$save_me += ($old['total'] != $save1['total']);
$save_me += ($old['total_type'] != $save1['total_type']);
$save_me += ($old['total_prefix'] != $save1['total_prefix']);
$save_me += ($old['order_type'] != $save1['order_type']);
} else {
$save_me = 1;
}
if ($save_me) {
$id = sql_save($save1, 'aggregate_graph_templates', 'id');
/* update children of the template */
db_execute_prepared(
"UPDATE aggregate_graphs
SET gprint_prefix = ?, gprint_format = ?, graph_type = ?, total = ?, total_prefix = ?, order_type = ?
WHERE aggregate_template_id = ?
AND template_propogation='on'",
array(
$save1['gprint_prefix'], $save1['gprint_format'], $save1['graph_type'],
$save1['total'], $save1['total_prefix'], $save1['order_type'], $id
)
);
cacti_log('AGGREGATE GRAPH TEMPLATE Saved ID: ' . $id, false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG);
} else {
$id = $save1['id'];
}
if (!$id) {
raise_message(2);
header('Location: aggregate_templates.php?action=edit&id=' . get_nfilter_request_var('id'));
return null;
}
/* save extra graph parameters */
/* validate posted graph params */
$params_new = aggregate_validate_graph_params($_POST, true);
$params_new['aggregate_template_id'] = $id;
/* compare new graph param values with existing in DB.
* We need to know if there were changes so we only
* rebuild existing graphs if needed. */
$params_changed = false;
$params_old = db_fetch_row_prepared(
'SELECT *
FROM aggregate_graph_templates_graph
WHERE aggregate_template_id = ?',
array($id)
);
if (!empty($params_old)) {
foreach ($params_old as $field => $value_old) {
if (isset($params_new[$field]) && $params_new[$field] != $value_old) {
$params_changed = true;
break;
}
}
} else {
$params_changed = true;
}
/* save only if all posted form fields passed validation */
if ($params_changed && !is_error_message()) {
sql_save($params_new, 'aggregate_graph_templates_graph', 'aggregate_template_id', false);
}
/* save the template items now */
/* get existing item ids and sequences from graph template */
$graph_templates_items = array_rekey(
db_fetch_assoc_prepared(
'SELECT id, sequence
FROM graph_templates_item
WHERE local_graph_id=0
AND graph_template_id = ?',
array($save1['graph_template_id'])
),
'id',
array('sequence')
);
/* get existing aggregate template items */
$aggregate_template_items_old = array_rekey(
db_fetch_assoc_prepared('SELECT *
FROM aggregate_graph_templates_item
WHERE aggregate_template_id = ?', array($id)),
'graph_templates_item_id',
array('sequence', 'color_template', 't_graph_type_id', 'graph_type_id', 't_cdef_id', 'cdef_id', 'item_skip', 'item_total')
);
/* update graph template item values with posted values */
aggregate_validate_graph_items($_POST, $graph_templates_items);
$items_changed = false;
$items_to_save = array();
foreach ($graph_templates_items as $item_id => $data) {
$item_new = array();
$item_new['aggregate_template_id'] = $id;
$item_new['graph_templates_item_id'] = $item_id;
$item_new['color_template'] = isset($data['color_template']) ? $data['color_template'] : 0;
$item_new['item_skip'] = isset($data['item_skip']) ? 'on' : '';
$item_new['item_total'] = isset($data['item_total']) ? 'on' : '';
$item_new['sequence'] = isset($data['sequence']) ? $data['sequence'] : 0;
/* compare with old item to see if we need to push out. */
if (!isset($aggregate_template_items_old[$item_id])) {
/* this item does not yet exist */
$items_changed = true;
} else {
// fill in missing fields with db values
$item_new = array_merge($aggregate_template_items_old[$item_id], $item_new);
/* compare data from user to data from DB */
foreach ($data as $field => $new_value) {
if ($aggregate_template_items_old[$item_id][$field] != $new_value) {
$items_changed = true;
}
}
}
$items_to_save[] = $item_new;
}
if ($items_changed) {
aggregate_graph_items_save($items_to_save, 'aggregate_graph_templates_item');
}
if ($save_me || $params_changed || $items_changed) {
push_out_aggregates($id);
}
raise_message(1);
header('Location: aggregate_templates.php?action=edit&id=' . (empty($id) ? get_nfilter_request_var('id') : $id));
}
function aggregate_get_graph_items($table, $id) {
}
/**
* aggregate_form_actions - the action function
*/
function aggregate_form_actions() {
global $actions, $config;
/* ================= input validation ================= */
get_filter_request_var('drp_action');
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
db_execute('DELETE FROM aggregate_graph_templates WHERE ' . array_to_sql_or($selected_items, 'id'));
db_execute('DELETE FROM aggregate_graph_templates_item WHERE ' . array_to_sql_or($selected_items, 'aggregate_template_id'));
db_execute('DELETE FROM aggregate_graph_templates_graph WHERE ' . array_to_sql_or($selected_items, 'aggregate_template_id'));
db_execute("UPDATE aggregate_graphs SET aggregate_template_id=0, template_propogation='' WHERE " . array_to_sql_or($selected_items, 'aggregate_template_id'));
}
}
header('Location: aggregate_templates.php');
exit;
} else {
$ilist = '';
$iarray = array();
/* loop through each of the color templates selected on the previous page and get more info about them */
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1], 'chk[1]');
/* ==================================================== */
$ilist .= '<li>' . html_escape(db_fetch_cell_prepared('SELECT name FROM aggregate_graph_templates WHERE id = ?', array($matches[1]))) . '</li>';
$iarray[] = $matches[1];
}
}
$form_data = array(
'general' => array(
'page' => 'aggregate_templates.php',
'actions' => $actions,
'optvar' => 'drp_action',
'item_array' => $iarray,
'item_list' => $ilist
),
'options' => array(
1 => array(
'smessage' => __('Click \'Continue\' to Delete the following Aggregate Graph Template.'),
'pmessage' => __('Click \'Continue\' to Delete following Aggregate Graph Templates.'),
'scont' => __('Delete Aggregate Graph Template'),
'pcont' => __('Delete Aggregate Graph Templates')
)
)
);
form_continue_confirmation($form_data);
}
}
/**
* aggregate_template_edit edit the color template
*/
function aggregate_template_edit() {
global $image_types, $struct_aggregate_template;
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
if (!isempty_request_var('id')) {
$template = db_fetch_row_prepared(
'SELECT *
FROM aggregate_graph_templates
WHERE id = ?',
array(get_request_var('id'))
);
$header_label = __esc('Aggregate Template [edit: %s]', $template['name']);
} else {
$header_label = __('Aggregate Template [new]');
}
/* populate the graph template id if it's set */
if (isset_request_var('graph_template_id') && !isset($template)) {
/* ================= input validation ================= */
get_filter_request_var('graph_template_id');
/* ==================================================== */
$template['graph_template_id'] = get_nfilter_request_var('graph_template_id');
$template['id'] = 0;
}
form_start('aggregate_templates.php', 'template_edit');
html_start_box($header_label, '100%', true, '3', 'center', '');
$helper_string = '|host_description|';
if (isset($template)) {
$data_query = db_fetch_cell_prepared(
'SELECT snmp_query_id
FROM snmp_query_graph
WHERE graph_template_id = ?',
array($template['graph_template_id'])
);
if ($data_query > 0) {
$data_query_info = get_data_query_array($data_query);
foreach ($data_query_info['fields'] as $field_name => $field_array) {
if ($field_array['direction'] == 'input' || $field_array['direction'] == 'input-output') {
$helper_string .= ($helper_string != '' ? ', ' : '') . '|query_' . $field_name . '|';
}
}
}
}
// Append the helper string
$struct_aggregate_template['suggestions'] = array(
'method' => 'other',
'friendly_name' => __('Prefix Replacement Values'),
'description' => __('You may use these replacement values for the Prefix in the Aggregate Graph'),
'value' => $helper_string
);
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($struct_aggregate_template, (isset($template) ? $template : array()))
)
);
html_end_box(true, true);
if (isset($template)) {
draw_aggregate_graph_items_list(0, $template['graph_template_id'], $template);
/* Draw Graph Configuration form, so user can override some parameters from graph template */
draw_aggregate_template_graph_config($template['id'], $template['graph_template_id']);
}
form_hidden_box('id', (isset($template['id']) ? $template['id'] : '0'), '0');
form_hidden_box('save_component_template', '1', '');
form_save_button('aggregate_templates.php', 'return', 'id');
?>
<script type='text/javascript'>
$(function() {
if ($('#id').val() == 0) {
$('[id^="agg_total_"]').prop('checked', true);
}
var showField = $('#graph_template_id').val() != 0;
toggleField({
name: showField,
spacer1: showField,
gprint_prefix: showField,
gprint_format: showField,
graph_type: showField,
total: showField,
total_type: showField,
total_prefix: showField,
order_type: showField,
});
if ($('#graph_template_id').val() == 0) {
$('#graph_template_id').change(function() {
$('#template_edit').submit();
});
$('#save_component_template').parent().next('table').css('display', 'none');
} else {
$('#graph_template_id').prop('disabled', true);
if ($('#graph_template_id').selectmenu('instance') !== undefined) {
$('#graph_template_id').selectmenu('disable');
}
}
$('#total').change(function() {
changeTotals();
});
$('#total_type').change(function() {
changeTotalsType();
});
$('input[id^="agg_total"], input[id^="agg_skip"]').click(function() {
id = $(this).attr('id');
if (id.indexOf('skip') > 0) {
altId = id.replace('skip', 'total');
} else {
altId = id.replace('total', 'skip');
}
if ($('#' + id).is(':checked')) {
$('#' + altId).prop('checked', false);
} else {
$('#' + altId).prop('checked', true);
}
updateSaveButton();
});
changeTotals();
updateSaveButton();
});
function updateSaveButton() {
if ($('input[id^="agg_total"]').is(':checked')) {
$('#submit').prop('disabled', false);
if ($('#submit').button('instance')) {
$('#submit').button('enable');
}
} else {
$('#submit').prop('disabled', true);
if ($('#submit').button('instance')) {
$('#submit').button('disable');
}
}
}
function changeTotals() {
var showField = $('#total').val() == '<?php print AGGREGATE_TOTAL_NONE; ?>';
toggleField({
total_type: showField,
total_prefix: showField,
order_type: showField,
});
changeTotalsType();
}
function changeTotalsType() {
if ($('#total_type').val() == <?php print AGGREGATE_TOTAL_TYPE_SIMILAR; ?>) {
if ($('#total_prefix').val() == '' && $('#id').val() == 0) {
$('#total_prefix').attr('value', '<?php print __('Total'); ?>');
}
} else if ($('#total_type').val() == <?php print AGGREGATE_TOTAL_TYPE_ALL; ?>) {
if ($('#total_prefix').val() == '' && $('#id').val() == 0) {
$('#total_prefix').attr('value', '<?php print __('All Items'); ?>');
}
}
}
</script>
<?php
}
/**
* aggregate_template
*/
function aggregate_template() {
global $actions, $item_rows, $config;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'pgt.name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'has_graphs' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => read_config_option('default_has') == 'on' ? 'true' : 'false'
)
);
validate_store_request_vars($filters, 'sess_agg_tmp');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
html_start_box(__('Aggregate Templates'), '100%', '', '3', 'center', 'aggregate_templates.php?action=edit');
$filter_html = '<tr class="even">
<td>
<form id="forms">
<table class="filterTable">
<tr>
<td>
' . __('Search') . '
</td>
<td>
<input type="text" class="ui-state-default ui-corner-all" id="filter" size="25" value="' . html_escape_request_var('filter') . '">
</td>
<td>
' . __('Templates') . '
</td>
<td>
<select id="rows" onChange="applyFilter()" data-defaultLabel="' . __('Templates') . '">
<option value="-1" ';
if (get_request_var('rows') == '-1') {
$filter_html .= 'selected';
}
$filter_html .= '>' . __('Default') . '</option>';
if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
$filter_html .= "<option value='" . $key . "'";
if (get_request_var('rows') == $key) {
$filter_html .= ' selected';
}
$filter_html .= '>' . $value . "</option>\n";
}
}
$filter_html .= '</select>
</td>
<td>
<span>
<input type="checkbox" id="has_graphs" ' . (get_request_var('has_graphs') == 'true' ? 'checked' : '') . ' onChange="applyFilter()">
<label for="has_graphs">' . __('Has Graphs') . '</label>
</span>
</td>
<td>
<span>
<input type="submit" class="ui-button ui-corner-all ui-widget" value="' . __esc('Go') . '" id="go">
<input type="button" class="ui-button ui-corner-all ui-widget" value="' . __esc('Clear') . '" id="clear">
</span>
</td>
</tr>
</table>
</form>
</td>
</tr>';
print $filter_html;
html_end_box();
/* form the 'where' clause for our main sql query */
$sql_where = '';
if (get_request_var('filter') != '') {
$sql_where = 'WHERE (pgt.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR gt.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
}
if (get_request_var('has_graphs') == 'true') {
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'gt.graphs > 0';
}
$total_rows = db_fetch_cell("SELECT COUNT(*)
FROM aggregate_graph_templates AS pgt
LEFT JOIN graph_templates AS gt
ON pgt.graph_template_id = gt.id
$sql_where");
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
$template_list = db_fetch_assoc("SELECT pgt.*, gt.name AS graph_template_name
FROM aggregate_graph_templates AS pgt
LEFT JOIN graph_templates AS gt
ON pgt.graph_template_id = gt.id
$sql_where
$sql_order
$sql_limit");
$nav = html_nav_bar('aggregate_templates.php', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 5, __('Aggregate Templates'), 'page', 'main');
form_start('aggregate_templates.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'pgt.name' => array('display' => __('Template Title'), 'align' => 'left', 'sort' => 'ASC'),
'nosort' => array('display' => __('Deletable'), 'align' => 'right', 'tip' => __('Aggregate Templates that are in use can not be Deleted. In use is defined as being referenced by an Aggregate.')),
'graphs.graphs' => array('display' => __('Graphs Using'), 'align' => 'right', 'sort' => 'DESC'),
'graph_template_name' => array('display' => __('Graph Template'), 'align' => 'left', 'sort' => 'ASC')
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (cacti_sizeof($template_list)) {
foreach ($template_list as $template) {
if ($template['graphs'] > 0) {
$disabled = true;
} else {
$disabled = false;
}
form_alternate_row('line' . $template['id'], true, $disabled);
form_selectable_cell(filter_value($template['name'], get_request_var('filter'), 'aggregate_templates.php?action=edit&id=' . $template['id'] . '&page=1'), $template['id']);
form_selectable_cell($disabled ? __('No') : __('Yes'), $template['id'], '', 'right');
form_selectable_cell('<a class="linkEditMain" href="' . html_escape('aggregate_graphs.php?reset=true&template_id=' . $template['id']) . '">' . number_format_i18n($template['graphs'], '-1') . '</a>', $template['id'], '', 'right');
form_selectable_cell(filter_value($template['graph_template_name'], get_request_var('filter')), $template['id']);
form_checkbox_cell($template['graph_template_name'], $template['id'], $disabled);
form_end_row();
}
} else {
print "<tr class='tableRow'><td colspan='" . (cacti_sizeof($display_text) + 1) . "'><em>" . __('No Aggregate Templates Found') . "</em></td></tr>\n";
}
html_end_box(false);
if (cacti_sizeof($template_list)) {
/* put the nav bar on the bottom as well */
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($actions);
form_end();
?>
<script type='text/javascript'>
function applyFilter() {
strURL = 'aggregate_templates.php';
strURL += '?rows=' + $('#rows').val();
strURL += '&has_graphs=' + $('#has_graphs').is(':checked');
strURL += '&filter=' + $('#filter').val();
loadUrl({
url: strURL
})
}
function clearFilter() {
strURL = 'aggregate_templates.php?clear=1';
loadUrl({
url: strURL
})
}
$(function() {
$('#clear').click(function() {
clearFilter();
});
$('#template').submit(function(event) {
event.preventDefault();
applyFilter();
});
$('#forms').submit(function(event) {
event.preventDefault();
applyFilter();
});
});
</script>
<?php
}