Imported Upstream version 0.8.7g
[debian/cacti] / gprint_presets.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
27 /* set default action */
28 if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
29
30 switch ($_REQUEST["action"]) {
31         case 'save':
32                 form_save();
33
34                 break;
35         case 'remove':
36                 gprint_presets_remove();
37
38                 header("Location: gprint_presets.php");
39                 break;
40         case 'edit':
41                 include_once("./include/top_header.php");
42
43                 gprint_presets_edit();
44
45                 include_once("./include/bottom_footer.php");
46                 break;
47         default:
48                 include_once("./include/top_header.php");
49
50                 gprint_presets();
51
52                 include_once("./include/bottom_footer.php");
53                 break;
54 }
55
56 /* --------------------------
57     The Save Function
58    -------------------------- */
59
60 function form_save() {
61         if (isset($_POST["save_component_gprint_presets"])) {
62                 $save["id"] = $_POST["id"];
63                 $save["hash"] = get_hash_gprint($_POST["id"]);
64                 $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
65                 $save["gprint_text"] = form_input_validate($_POST["gprint_text"], "gprint_text", "", false, 3);
66
67                 if (!is_error_message()) {
68                         $gprint_preset_id = sql_save($save, "graph_templates_gprint");
69
70                         if ($gprint_preset_id) {
71                                 raise_message(1);
72                         }else{
73                                 raise_message(2);
74                         }
75                 }
76
77                 if (is_error_message()) {
78                         header("Location: gprint_presets.php?action=edit&id=" . (empty($gprint_preset_id) ? $_POST["id"] : $gprint_preset_id));
79                         exit;
80                 }else{
81                         header("Location: gprint_presets.php");
82                         exit;
83                 }
84         }
85 }
86
87 /* -----------------------------------
88     gprint_presets - GPRINT Presets
89    ----------------------------------- */
90
91 function gprint_presets_remove() {
92         /* ================= input validation ================= */
93         input_validate_input_number(get_request_var("id"));
94         /* ==================================================== */
95
96         if ((read_config_option("deletion_verification") == "on") && (!isset($_GET["confirm"]))) {
97                 include_once("./include/top_header.php");
98                 form_confirm("Are You Sure?", "Are you sure you want to delete the GPRINT preset <strong>'" . htmlspecialchars(db_fetch_cell("select name from graph_templates_gprint where id=" . $_GET["id"])) . "'</strong>? This could affect every graph that uses this preset, make sure you know what you are doing first!", htmlspecialchars("gprint_presets.php"), htmlspecialchars("gprint_presets.php?action=remove&id=" . $_GET["id"]));
99                 exit;
100         }
101
102         if ((read_config_option("deletion_verification") == "") || (isset($_GET["confirm"]))) {
103                 db_execute("delete from graph_templates_gprint where id=" . $_GET["id"]);
104         }
105 }
106
107 function gprint_presets_edit() {
108         global $colors, $fields_grprint_presets_edit;
109
110         /* ================= input validation ================= */
111         input_validate_input_number(get_request_var("id"));
112         /* ==================================================== */
113
114         if (!empty($_GET["id"])) {
115                 $gprint_preset = db_fetch_row("select * from graph_templates_gprint where id=" . $_GET["id"]);
116                 $header_label = "[edit: " . htmlspecialchars($gprint_preset["name"]) . "]";
117         }else{
118                 $header_label = "[new]";
119         }
120
121         html_start_box("<strong>GPRINT Presets</strong> $header_label", "100%", $colors["header"], "3", "center", "");
122
123         draw_edit_form(array(
124                 "config" => array(),
125                 "fields" => inject_form_variables($fields_grprint_presets_edit, (isset($gprint_preset) ? $gprint_preset : array()))
126                 ));
127
128         html_end_box();
129
130         form_save_button("gprint_presets.php");
131 }
132
133 function gprint_presets() {
134         global $colors;
135
136         html_start_box("<strong>GPRINT Presets</strong>", "100%", $colors["header"], "3", "center", "gprint_presets.php?action=edit");
137
138         print " <tr bgcolor='#" . $colors["header_panel"] . "'>
139                         <td colspan='2' class='textSubHeaderDark'>GPRINT Preset Title</td>
140                 </tr>";
141
142         $template_list = db_fetch_assoc("select
143                 graph_templates_gprint.id,
144                 graph_templates_gprint.name
145                 from graph_templates_gprint");
146
147         $i = 0;
148         if (sizeof($template_list) > 0) {
149         foreach ($template_list as $template) {
150                 form_alternate_row_color($colors["alternate"],$colors["light"],$i);
151                         ?>
152                         <td>
153                                 <a class="linkEditMain" href="<?php print htmlspecialchars("gprint_presets.php?action=edit&id=" . $template["id"]);?>"><?php print htmlspecialchars($template["name"]);?></a>
154                         </td>
155                         <td align="right">
156                                 <a href="<?php print htmlspecialchars("gprint_presets.php?action=remove&id=" . $template["id"]);?>"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
157                         </td>
158                 </tr>
159                 <?php
160                 $i++;
161         }
162         }else{
163                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?>
164                         <td colspan="2">
165                                 <em>No Items</em>
166                         </td>
167                 </tr><?php
168         }
169         html_end_box();
170 }