0.8.7g-2.1+pia2p9+neutron1
[debian/cacti] / graph_templates.php
1 <?php
2 /*
3  +-------------------------------------------------------------------------+
4  | Copyright (C) 2004-2010 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 include("./include/auth.php");
26 include_once("./lib/utility.php");
27 include_once("./lib/template.php");
28 include_once("./lib/tree.php");
29 include_once("./lib/html_tree.php");
30
31 define("MAX_DISPLAY_PAGES", 21);
32
33 $graph_actions = array(
34         1 => "Delete",
35         2 => "Duplicate"
36         );
37
38 /* set default action */
39 if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
40
41 switch ($_REQUEST["action"]) {
42         case 'save':
43                 form_save();
44
45                 break;
46         case 'actions':
47                 form_actions();
48
49                 break;
50         case 'template_remove':
51                 template_remove();
52
53                 header("Location: graph_templates.php");
54                 break;
55         case 'input_remove':
56                 input_remove();
57
58                 header("Location: graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]);
59                 break;
60         case 'input_edit':
61                 include_once("./include/top_header.php");
62
63                 input_edit();
64
65                 include_once("./include/bottom_footer.php");
66                 break;
67         case 'template_edit':
68                 include_once ("./include/top_header.php");
69
70                 template_edit();
71
72                 include_once ("./include/bottom_footer.php");
73                 break;
74         default:
75                 include_once("./include/top_header.php");
76
77                 template();
78
79                 include_once("./include/bottom_footer.php");
80                 break;
81 }
82
83 /* --------------------------
84     The Save Function
85    -------------------------- */
86
87 function form_save() {
88         if (isset($_POST["save_component_template"])) {
89                 $save1["id"] = $_POST["graph_template_id"];
90                 $save1["hash"] = get_hash_graph_template($_POST["graph_template_id"]);
91                 $save1["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
92
93                 $save2["id"] = $_POST["graph_template_graph_id"];
94                 $save2["local_graph_template_graph_id"] = 0;
95                 $save2["local_graph_id"] = 0;
96                 $save2["t_image_format_id"] = (isset($_POST["t_image_format_id"]) ? $_POST["t_image_format_id"] : "");
97                 $save2["image_format_id"] = form_input_validate($_POST["image_format_id"], "image_format_id", "", true, 3);
98                 $save2["t_title"] = form_input_validate((isset($_POST["t_title"]) ? $_POST["t_title"] : ""), "t_title", "", true, 3);
99                 $save2["title"] = form_input_validate($_POST["title"], "title", "", (isset($_POST["t_title"]) ? true : false), 3);
100                 $save2["t_height"] = form_input_validate((isset($_POST["t_height"]) ? $_POST["t_height"] : ""), "t_height", "", true, 3);
101                 $save2["height"] = form_input_validate($_POST["height"], "height", "^[0-9]+$", (isset($_POST["t_height"]) ? true : false), 3);
102                 $save2["t_width"] = form_input_validate((isset($_POST["t_width"]) ? $_POST["t_width"] : ""), "t_width", "", true, 3);
103                 $save2["width"] = form_input_validate($_POST["width"], "width", "^[0-9]+$", (isset($_POST["t_width"]) ? true : false), 3);
104                 $save2["t_upper_limit"] = form_input_validate((isset($_POST["t_upper_limit"]) ? $_POST["t_upper_limit"] : ""), "t_upper_limit", "", true, 3);
105                 $save2["upper_limit"] = form_input_validate($_POST["upper_limit"], "upper_limit", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", ((isset($_POST["t_upper_limit"]) || (strlen($_POST["upper_limit"]) === 0)) ? true : false), 3);
106                 $save2["t_lower_limit"] = form_input_validate((isset($_POST["t_lower_limit"]) ? $_POST["t_lower_limit"] : ""), "t_lower_limit", "", true, 3);
107                 $save2["lower_limit"] = form_input_validate($_POST["lower_limit"], "lower_limit", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", ((isset($_POST["t_lower_limit"]) || (strlen($_POST["lower_limit"]) === 0)) ? true : false), 3);
108                 $save2["t_vertical_label"] = form_input_validate((isset($_POST["t_vertical_label"]) ? $_POST["t_vertical_label"] : ""), "t_vertical_label", "", true, 3);
109                 $save2["vertical_label"] = form_input_validate($_POST["vertical_label"], "vertical_label", "", true, 3);
110                 $save2["t_slope_mode"] = form_input_validate((isset($_POST["t_slope_mode"]) ? $_POST["t_slope_mode"] : ""), "t_slope_mode", "", true, 3);
111                 $save2["slope_mode"] = form_input_validate((isset($_POST["slope_mode"]) ? $_POST["slope_mode"] : ""), "slope_mode", "", true, 3);
112                 $save2["t_auto_scale"] = form_input_validate((isset($_POST["t_auto_scale"]) ? $_POST["t_auto_scale"] : ""), "t_auto_scale", "", true, 3);
113                 $save2["auto_scale"] = form_input_validate((isset($_POST["auto_scale"]) ? $_POST["auto_scale"] : ""), "auto_scale", "", true, 3);
114                 $save2["t_auto_scale_opts"] = form_input_validate((isset($_POST["t_auto_scale_opts"]) ? $_POST["t_auto_scale_opts"] : ""), "t_auto_scale_opts", "", true, 3);
115                 $save2["auto_scale_opts"] = form_input_validate($_POST["auto_scale_opts"], "auto_scale_opts", "", true, 3);
116                 $save2["t_auto_scale_log"] = form_input_validate((isset($_POST["t_auto_scale_log"]) ? $_POST["t_auto_scale_log"] : ""), "t_auto_scale_log", "", true, 3);
117                 $save2["auto_scale_log"] = form_input_validate((isset($_POST["auto_scale_log"]) ? $_POST["auto_scale_log"] : ""), "auto_scale_log", "", true, 3);
118                 $save2["t_scale_log_units"] = form_input_validate((isset($_POST["t_scale_log_units"]) ? $_POST["t_scale_log_units"] : ""), "t_scale_log_units", "", true, 3);
119                 $save2["scale_log_units"] = form_input_validate((isset($_POST["scale_log_units"]) ? $_POST["scale_log_units"] : ""), "scale_log_units", "", true, 3);
120                 $save2["t_auto_scale_rigid"] = form_input_validate((isset($_POST["t_auto_scale_rigid"]) ? $_POST["t_auto_scale_rigid"] : ""), "t_auto_scale_rigid", "", true, 3);
121                 $save2["auto_scale_rigid"] = form_input_validate((isset($_POST["auto_scale_rigid"]) ? $_POST["auto_scale_rigid"] : ""), "auto_scale_rigid", "", true, 3);
122                 $save2["t_auto_padding"] = form_input_validate((isset($_POST["t_auto_padding"]) ? $_POST["t_auto_padding"] : ""), "t_auto_padding", "", true, 3);
123                 $save2["auto_padding"] = form_input_validate((isset($_POST["auto_padding"]) ? $_POST["auto_padding"] : ""), "auto_padding", "", true, 3);
124                 $save2["t_base_value"] = form_input_validate((isset($_POST["t_base_value"]) ? $_POST["t_base_value"] : ""), "t_base_value", "", true, 3);
125                 $save2["base_value"] = form_input_validate($_POST["base_value"], "base_value", "^[0-9]+$", (isset($_POST["t_base_value"]) ? true : false), 3);
126                 $save2["t_export"] = form_input_validate((isset($_POST["t_export"]) ? $_POST["t_export"] : ""), "t_export", "", true, 3);
127                 $save2["export"] = form_input_validate((isset($_POST["export"]) ? $_POST["export"] : ""), "export", "", true, 3);
128                 $save2["t_unit_value"] = form_input_validate((isset($_POST["t_unit_value"]) ? $_POST["t_unit_value"] : ""), "t_unit_value", "", true, 3);
129                 $save2["unit_value"] = form_input_validate($_POST["unit_value"], "unit_value", "", true, 3);
130                 $save2["t_unit_exponent_value"] = form_input_validate((isset($_POST["t_unit_exponent_value"]) ? $_POST["t_unit_exponent_value"] : ""), "t_unit_exponent_value", "", true, 3);
131                 $save2["unit_exponent_value"] = form_input_validate($_POST["unit_exponent_value"], "unit_exponent_value", "^-?[0-9]+$", true, 3);
132
133                 if (!is_error_message()) {
134                         $graph_template_id = sql_save($save1, "graph_templates");
135
136                         if ($graph_template_id) {
137                                 raise_message(1);
138                         }else{
139                                 raise_message(2);
140                         }
141                 }
142
143                 if (!is_error_message()) {
144                         $save2["graph_template_id"] = $graph_template_id;
145                         $graph_template_graph_id = sql_save($save2, "graph_templates_graph");
146
147                         if ($graph_template_graph_id) {
148                                 raise_message(1);
149
150                                 push_out_graph($graph_template_graph_id);
151                         }else{
152                                 raise_message(2);
153                         }
154                 }
155         }
156
157         header("Location: graph_templates.php?action=template_edit&id=" . (empty($graph_template_id) ? $_POST["graph_template_id"] : $graph_template_id));
158 }
159
160 /* ------------------------
161     The "actions" function
162    ------------------------ */
163
164 function form_actions() {
165         global $colors, $graph_actions;
166
167         /* if we are to save this form, instead of display it */
168         if (isset($_POST["selected_items"])) {
169                 $selected_items = unserialize(stripslashes($_POST["selected_items"]));
170
171                 if ($_POST["drp_action"] == "1") { /* delete */
172                         db_execute("delete from graph_templates where " . array_to_sql_or($selected_items, "id"));
173
174                         $graph_template_input = db_fetch_assoc("select id from graph_template_input where " . array_to_sql_or($selected_items, "graph_template_id"));
175
176                         if (sizeof($graph_template_input) > 0) {
177                         foreach ($graph_template_input as $item) {
178                                 db_execute("delete from graph_template_input_defs where graph_template_input_id=" . $item["id"]);
179                         }
180                         }
181
182                         db_execute("delete from graph_template_input where " . array_to_sql_or($selected_items, "graph_template_id"));
183                         db_execute("delete from graph_templates_graph where " . array_to_sql_or($selected_items, "graph_template_id") . " and local_graph_id=0");
184                         db_execute("delete from graph_templates_item where " . array_to_sql_or($selected_items, "graph_template_id") . " and local_graph_id=0");
185                         db_execute("delete from host_template_graph where " . array_to_sql_or($selected_items, "graph_template_id"));
186
187                         /* "undo" any graph that is currently using this template */
188                         db_execute("update graph_templates_graph set local_graph_template_graph_id=0,graph_template_id=0 where " . array_to_sql_or($selected_items, "graph_template_id"));
189                         db_execute("update graph_templates_item set local_graph_template_item_id=0,graph_template_id=0 where " . array_to_sql_or($selected_items, "graph_template_id"));
190                         db_execute("update graph_local set graph_template_id=0 where " . array_to_sql_or($selected_items, "graph_template_id"));
191                 }elseif ($_POST["drp_action"] == "2") { /* duplicate */
192                         for ($i=0;($i<count($selected_items));$i++) {
193                                 /* ================= input validation ================= */
194                                 input_validate_input_number($selected_items[$i]);
195                                 /* ==================================================== */
196
197                                 duplicate_graph(0, $selected_items[$i], $_POST["title_format"]);
198                         }
199                 }
200
201                 header("Location: graph_templates.php");
202                 exit;
203         }
204
205         /* setup some variables */
206         $graph_list = ""; $i = 0;
207
208         /* loop through each of the graphs selected on the previous page and get more info about them */
209         while (list($var,$val) = each($_POST)) {
210                 if (ereg("^chk_([0-9]+)$", $var, $matches)) {
211                         /* ================= input validation ================= */
212                         input_validate_input_number($matches[1]);
213                         /* ==================================================== */
214
215                         $graph_list .= "<li>" . db_fetch_cell("select name from graph_templates where id=" . $matches[1]) . "<br>";
216                         $graph_array[$i] = $matches[1];
217
218                         $i++;
219                 }
220         }
221
222         include_once("./include/top_header.php");
223
224         html_start_box("<strong>" . $graph_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
225
226         print "<form action='graph_templates.php' method='post'>\n";
227
228         if (isset($graph_array) && sizeof($graph_array)) {
229                 if ($_POST["drp_action"] == "1") { /* delete */
230                         print " <tr>
231                                         <td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
232                                                 <p>When you click \"Continue\", the following Graph Template(s) will be deleted.  Any Graph(s) associated with
233                                                 the Template(s) will become individual Graph(s).</p>
234                                                 <p><ul>$graph_list</ul></p>
235                                         </td>
236                                 </tr>\n
237                                 ";
238                         $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph Template(s)'>";
239                 }elseif ($_POST["drp_action"] == "2") { /* duplicate */
240                         print " <tr>
241                                         <td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
242                                                 <p>When you click \"Continue\", the following Graph Template(s) will be duplicated. You can
243                                                 optionally change the title format for the new Graph Template(s).</p>
244                                                 <p><ul>$graph_list</ul></p>
245                                                 <p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<template_title> (1)", "", "255", "30", "text"); print "</p>
246                                         </td>
247                                 </tr>\n
248                                 ";
249                         $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph Template(s)'>";
250                 }
251         }else{
252                 print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one graph template.</span></td></tr>\n";
253                 $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
254         }
255
256         print " <tr>
257                         <td align='right' bgcolor='#eaeaea'>
258                                 <input type='hidden' name='action' value='actions'>
259                                 <input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>
260                                 <input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
261                                 $save_html
262                         </td>
263                 </tr>
264                 ";
265
266         html_end_box();
267
268         include_once("./include/bottom_footer.php");
269 }
270
271 function item() {
272         global $colors, $consolidation_functions, $graph_item_types;
273
274         /* ================= input validation ================= */
275         input_validate_input_number(get_request_var("id"));
276         /* ==================================================== */
277
278         if (empty($_GET["id"])) {
279                 $template_item_list = array();
280
281                 $header_label = "[new]";
282         }else{
283                 $template_item_list = db_fetch_assoc("select
284                         graph_templates_item.id,
285                         graph_templates_item.text_format,
286                         graph_templates_item.value,
287                         graph_templates_item.hard_return,
288                         graph_templates_item.graph_type_id,
289                         graph_templates_item.consolidation_function_id,
290                         CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name,
291                         cdef.name as cdef_name,
292                         colors.hex
293                         from graph_templates_item
294                         left join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id)
295                         left join data_local on (data_template_rrd.local_data_id=data_local.id)
296                         left join data_template_data on (data_local.id=data_template_data.local_data_id)
297                         left join cdef on (cdef_id=cdef.id)
298                         left join colors on (color_id=colors.id)
299                         where graph_templates_item.graph_template_id=" . $_GET["id"] . "
300                         and graph_templates_item.local_graph_id=0
301                         order by graph_templates_item.sequence");
302
303                 $header_label = "[edit: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["id"]) . "]";
304         }
305
306         html_start_box("<strong>Graph Template Items</strong> " . htmlspecialchars($header_label), "100%", $colors["header"], "3", "center", "graph_templates_items.php?action=item_edit&graph_template_id=" . $_GET["id"]);
307         draw_graph_items_list($template_item_list, "graph_templates_items.php", "graph_template_id=" . $_GET["id"], false);
308         html_end_box();
309
310         html_start_box("<strong>Graph Item Inputs</strong>", "100%", $colors["header"], "3", "center", "graph_templates_inputs.php?action=input_edit&graph_template_id=" . $_GET["id"]);
311
312         print "<tr bgcolor='#" . $colors["header_panel"] . "'>";
313                 DrawMatrixHeaderItem("Name",$colors["header_text"],2);
314         print "</tr>";
315
316         $template_item_list = db_fetch_assoc("select id,name from graph_template_input where graph_template_id=" . $_GET["id"] . " order by name");
317
318         $i = 0;
319         if (sizeof($template_item_list) > 0) {
320         foreach ($template_item_list as $item) {
321                 form_alternate_row_color($colors["alternate"],$colors["light"],$i);
322         ?>
323                         <td>
324                                 <a class="linkEditMain" href="<?php print htmlspecialchars("graph_templates_inputs.php?action=input_edit&id=" . $item["id"] . "&graph_template_id=" . $_GET["id"]);?>"><?php print htmlspecialchars($item["name"]);?></a>
325                         </td>
326                         <td align="right">
327                                 <a href="<?php print htmlspecialchars("graph_templates_inputs.php?action=input_remove&id=" . $item["id"] . "&graph_template_id=" . $_GET["id"]);?>"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
328                         </td>
329                 </tr>
330         <?php
331         $i++;
332         }
333         }else{
334                 print "<tr bgcolor='#" . $colors["form_alternate2"] . "'><td colspan='2'><em>No Inputs</em></td></tr>";
335         }
336
337         html_end_box();
338 }
339
340 /* ----------------------------
341     template - Graph Templates
342    ---------------------------- */
343
344 function template_edit() {
345         global $colors, $struct_graph, $image_types, $fields_graph_template_template_edit;
346
347         /* ================= input validation ================= */
348         input_validate_input_number(get_request_var("id"));
349         /* ==================================================== */
350
351         /* graph item list goes here */
352         if (!empty($_GET["id"])) {
353                 item();
354         }
355
356         if (!empty($_GET["id"])) {
357                 $template = db_fetch_row("select * from graph_templates where id=" . $_GET["id"]);
358                 $template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $_GET["id"] . " and local_graph_id=0");
359
360                 $header_label = "[edit: " . $template["name"] . "]";
361         }else{
362                 $header_label = "[new]";
363         }
364
365         html_start_box("<strong>Template</strong> " . htmlspecialchars($header_label), "100%", $colors["header"], "3", "center", "");
366
367         draw_edit_form(array(
368                 "config" => array(),
369                 "fields" => inject_form_variables($fields_graph_template_template_edit, (isset($template) ? $template : array()), (isset($template_graph) ? $template_graph : array()))
370                 ));
371
372         html_end_box();
373
374         html_start_box("<strong>Graph Template</strong>", "100%", $colors["header"], "3", "center", "");
375
376         $form_array = array();
377
378         while (list($field_name, $field_array) = each($struct_graph)) {
379                 $form_array += array($field_name => $struct_graph[$field_name]);
380
381                 $form_array[$field_name]["value"] = (isset($template_graph) ? $template_graph[$field_name] : "");
382                 $form_array[$field_name]["form_id"] = (isset($template_graph) ? $template_graph["id"] : "0");
383                 $form_array[$field_name]["description"] = "";
384                 $form_array[$field_name]["sub_checkbox"] = array(
385                         "name" => "t_" . $field_name,
386                         "friendly_name" => "Use Per-Graph Value (Ignore this Value)",
387                         "value" => (isset($template_graph) ? $template_graph{"t_" . $field_name} : "")
388                         );
389         }
390
391         draw_edit_form(
392                 array(
393                         "config" => array(
394                                 ),
395                         "fields" => $form_array
396                         )
397                 );
398
399         form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
400         html_end_box();
401
402         form_save_button("graph_templates.php", "return");
403
404 //Now we need some javascript to make it dynamic
405 ?>
406 <script language="JavaScript">
407
408 dynamic();
409
410 function dynamic() {
411         //alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
412         //alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
413         document.getElementById('t_scale_log_units').disabled=true;
414         document.getElementById('scale_log_units').disabled=true;
415         if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
416                 (document.getElementById('auto_scale_log').checked)) {
417                 document.getElementById('t_scale_log_units').disabled=false;
418                 document.getElementById('scale_log_units').disabled=false;
419         }
420 }
421
422 function changeScaleLog() {
423         //alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
424         document.getElementById('t_scale_log_units').disabled=true;
425         document.getElementById('scale_log_units').disabled=true;
426         if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
427                 (document.getElementById('auto_scale_log').checked)) {
428                 document.getElementById('t_scale_log_units').disabled=false;
429                 document.getElementById('scale_log_units').disabled=false;
430         }
431 }
432 </script>
433 <?php
434
435 }
436
437 function template() {
438         global $colors, $graph_actions;
439
440         /* ================= input validation ================= */
441         input_validate_input_number(get_request_var_request("page"));
442         /* ==================================================== */
443
444         /* clean up search string */
445         if (isset($_REQUEST["filter"])) {
446                 $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
447         }
448
449         /* clean up sort_column string */
450         if (isset($_REQUEST["sort_column"])) {
451                 $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
452         }
453
454         /* clean up sort_direction string */
455         if (isset($_REQUEST["sort_direction"])) {
456                 $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
457         }
458
459         /* if the user pushed the 'clear' button */
460         if (isset($_REQUEST["clear_x"])) {
461                 kill_session_var("sess_graph_template_current_page");
462                 kill_session_var("sess_graph_template_filter");
463                 kill_session_var("sess_graph_template_sort_column");
464                 kill_session_var("sess_graph_template_sort_direction");
465
466                 unset($_REQUEST["page"]);
467                 unset($_REQUEST["filter"]);
468                 unset($_REQUEST["sort_column"]);
469                 unset($_REQUEST["sort_direction"]);
470
471         }
472
473         /* remember these search fields in session vars so we don't have to keep passing them around */
474         load_current_session_value("page", "sess_graph_template_current_page", "1");
475         load_current_session_value("filter", "sess_graph_template_filter", "");
476         load_current_session_value("sort_column", "sess_graph_template_sort_column", "name");
477         load_current_session_value("sort_direction", "sess_graph_template_sort_direction", "ASC");
478
479         html_start_box("<strong>Graph Templates</strong>", "100%", $colors["header"], "3", "center", "graph_templates.php?action=template_edit");
480
481         ?>
482         <tr bgcolor="#<?php print $colors["panel"];?>">
483                 <td>
484                 <form name="form_host_template" action="graph_templates.php">
485                         <table width="100%" cellpadding="0" cellspacing="0">
486                                 <tr>
487                                         <td nowrap style='white-space: nowrap;' width="50">
488                                                 Search:&nbsp;
489                                         </td>
490                                         <td width="1">
491                                                 <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter"));?>">
492                                         </td>
493                                         <td nowrap style='white-space: nowrap;'>
494                                                 &nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
495                                                 <input type="submit" name="clear_x" value="Clear" title="Clear Filters">
496                                         </td>
497                                 </tr>
498                         </table>
499                         <input type='hidden' name='page' value='1'>
500                 </form>
501                 </td>
502         </tr>
503         <?php
504
505         html_end_box();
506
507         /* form the 'where' clause for our main sql query */
508         $sql_where = "WHERE (graph_templates.name LIKE '%%" . get_request_var_request("filter") . "%%')";
509
510         /* print checkbox form for validation */
511         print "<form name='chk' method='post' action='graph_templates.php'>\n";
512
513         html_start_box("", "100%", $colors["header"], "3", "center", "");
514
515         $total_rows = db_fetch_cell("SELECT
516                 COUNT(graph_templates.id)
517                 FROM graph_templates
518                 $sql_where");
519
520         $template_list = db_fetch_assoc("SELECT
521                 graph_templates.id,graph_templates.name
522                 FROM graph_templates
523                 $sql_where
524                 ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") .
525                 " LIMIT " . (read_config_option("num_rows_device")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_device"));
526
527         /* generate page list */
528         $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "graph_templates.php?filter=" . get_request_var_request("filter"));
529
530         $nav = "<tr bgcolor='#" . $colors["header"] . "'>
531                 <td colspan='7'>
532                         <table width='100%' cellspacing='0' cellpadding='0' border='0'>
533                                 <tr>
534                                         <td align='left' class='textHeaderDark'>
535                                                 <strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graph_templates.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")-1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
536                                         </td>\n
537                                         <td align='center' class='textHeaderDark'>
538                                                 Showing Rows " . ((read_config_option("num_rows_device")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_device")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
539                                         </td>\n
540                                         <td align='right' class='textHeaderDark'>
541                                                 <strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graph_templates.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")+1)) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
542                                         </td>\n
543                                 </tr>
544                         </table>
545                 </td>
546                 </tr>\n";
547
548         print $nav;
549
550         $display_text = array(
551                 "name" => array("Template Title", "ASC"));
552
553         html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
554
555         $i = 0;
556         if (sizeof($template_list) > 0) {
557                 foreach ($template_list as $template) {
558                         form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $template["id"]);$i++;
559                         form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("graph_templates.php?action=template_edit&id=" . $template["id"]) . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($template["name"])) : htmlspecialchars($template["name"])) . "</a>", $template["id"]);
560                         form_checkbox_cell($template["name"], $template["id"]);
561                         form_end_row();
562                 }
563                 print $nav;
564         }else{
565                 print "<tr><td><em>No Graph Templates</em></td></tr>\n";
566         }
567         html_end_box(false);
568
569         /* draw the dropdown containing a list of available actions for this form */
570         draw_actions_dropdown($graph_actions);
571
572         print "</form>\n";
573 }
574
575 ?>
576