File: graph_settings.php

package info (click to toggle)
cacti 0.8.8h%2Bds1-10%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,760 kB
  • sloc: php: 35,105; sql: 2,408; xml: 719; sh: 433; perl: 152; makefile: 31
file content (247 lines) | stat: -rw-r--r-- 9,438 bytes parent folder | download
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
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2016 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/                                                   |
 +-------------------------------------------------------------------------+
*/

$guest_account = true;
include("./include/auth.php");

/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }

switch ($_REQUEST["action"]) {
	case 'save':
		form_save();

		break;
	default:
		// We must exempt ourselves from the page refresh, or else the settings page could update while the user is making changes
		$_SESSION['custom'] = 1;
		include_once("./include/top_graph_header.php");
		unset($_SESSION['custom']);

		settings();

		include_once("./include/bottom_footer.php");
		break;
}

/* --------------------------
    The Save Function
   -------------------------- */

function form_save() {
	global $settings_graphs, $cnn_id;

	while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
		while (list($field_name, $field_array) = each($tab_fields)) {
			/* Check every field with a numeric default value and reset it to default if the inputted value is not numeric  */
			if (isset($field_array["default"]) && is_numeric($field_array["default"]) && !is_numeric(get_request_var_post($field_name))) {
				$_POST[$field_name] = $field_array["default"];
			}
			if ($field_array["method"] == "checkbox") {
				if (isset($_POST[$field_name])) {
					db_execute("REPLACE INTO settings_graphs (user_id,name,value) VALUES (" . $_SESSION["sess_user_id"] . ",'$field_name', 'on')");
				}else{
					db_execute("REPLACE INTO settings_graphs (user_id,name,value) VALUES (" . $_SESSION["sess_user_id"] . ",'$field_name', '')");
				}
			}elseif ($field_array["method"] == "checkbox_group") {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					if (isset($_POST[$sub_field_name])) {
						db_execute("REPLACE INTO settings_graphs (user_id,name,value) VALUES (" . $_SESSION["sess_user_id"] . ",'$sub_field_name', 'on')");
					}else{
						db_execute("REPLACE INTO settings_graphs (user_id,name,value) VALUES (" . $_SESSION["sess_user_id"] . ",'$sub_field_name', '')");
					}
				}
			}elseif ($field_array["method"] == "textbox_password") {
				if ($_POST[$field_name] != $_POST[$field_name."_confirm"]) {
					raise_message(4);
					break;
				}elseif (isset($_POST[$field_name])) {
					$value = $cnn_id->qstr(get_request_var_post($field_name));
					db_execute("REPLACE INTO settings_graphs (user_id,name,value) VALUES (" .  $_SESSION["sess_user_id"] . ",'$field_name', $value)");
				}
			}elseif ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					if (isset($_POST[$sub_field_name])) {
						$value = $cnn_id->qstr(get_request_var_post($sub_field_name));
						db_execute("REPLACE INTO settings_graphs (user_id,name,value) values (" . $_SESSION["sess_user_id"] . ",'$sub_field_name', " . $value . ")");
					}
				}
			}else if (isset($_POST[$field_name])) {
				$value = $cnn_id->qstr($_POST[$field_name]);
				db_execute("REPLACE INTO settings_graphs (user_id,name,value) values (" . $_SESSION["sess_user_id"] . ",'$field_name', " . $value . ")");
			}
		}
	}

	/* reset local settings cache so the user sees the new settings */
	kill_session_var("sess_graph_config_array");

	header("Location: " . $_SESSION["graph_settings_referer"]);
}

/* --------------------------
    Graph Settings Functions
   -------------------------- */

function settings() {
	global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user, $graph_tree_views;

	/* you cannot have per-user graph settings if cacti's user management is not turned on */
	if (read_config_option("auth_method") == 0) {
		raise_message(6);
		display_output_messages();
		return;
	}

	/* Find out whether this user has right here */
	if($current_user["graph_settings"] == "") {
		print "<strong><font size='+1' color='#FF0000'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>";
		include_once("./include/bottom_footer.php");
		exit;
	}

	if (read_config_option("auth_method") != 0) {
		if ($current_user["policy_graphs"] == "1") {
			$sql_where = "where user_auth_tree.user_id is null";
		}elseif ($current_user["policy_graphs"] == "2") {
			$sql_where = "where user_auth_tree.user_id is not null";
		}

		$settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true);
	}

	print "<form method='post' action='graph_settings.php'>\n";

	html_start_box("<strong>Graph Settings</strong>", "100%", "", "3", "center", "");

	while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
		?>
		<tr>
			<td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>
				<?php print $tabs_graphs[$tab_short_name];?>
			</td>
		</tr>
		<?php

		$form_array = array();

		while (list($field_name, $field_array) = each($tab_fields)) {
			$form_array += array($field_name => $tab_fields[$field_name]);

			if ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					if (graph_config_value_exists($sub_field_name, $_SESSION["sess_user_id"])) {
						$form_array[$field_name]["items"][$sub_field_name]["form_id"] = 1;
					}

					$form_array[$field_name]["items"][$sub_field_name]["value"] =  db_fetch_cell("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_SESSION["sess_user_id"]);
				}
			}else{
				if (graph_config_value_exists($field_name, $_SESSION["sess_user_id"])) {
					$form_array[$field_name]["form_id"] = 1;
				}

				$form_array[$field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$field_name' and user_id=" . $_SESSION["sess_user_id"]);
			}
		}

		draw_edit_form(
			array(
				"config" => array(
					"no_form_tag" => true
					),
				"fields" => $form_array
				)
			);
	}

	html_end_box();
	?>
	<script type="text/javascript">
	<!--

	function graphSettings() {
		var custom_fonts = document.getElementById('custom_fonts').checked;

		switch(custom_fonts) {
		case true:
			document.getElementById('row_title_size').style.display  = "";
			document.getElementById('row_title_font').style.display  = "";
			document.getElementById('row_legend_size').style.display = "";
			document.getElementById('row_legend_font').style.display = "";
			document.getElementById('row_axis_size').style.display   = "";
			document.getElementById('row_axis_font').style.display   = "";
			document.getElementById('row_unit_size').style.display   = "";
			document.getElementById('row_unit_font').style.display   = "";

			break;
		case false:
			document.getElementById('row_title_size').style.display  = "none";
			document.getElementById('row_title_font').style.display  = "none";
			document.getElementById('row_legend_size').style.display = "none";
			document.getElementById('row_legend_font').style.display = "none";
			document.getElementById('row_axis_size').style.display   = "none";
			document.getElementById('row_axis_font').style.display   = "none";
			document.getElementById('row_unit_size').style.display   = "none";
			document.getElementById('row_unit_font').style.display   = "none";

			break;
		}
	}

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	addLoadEvent(graphSettings);

	-->
	</script>
	<?php

	print "<br>";

	if (isset($_SERVER["HTTP_REFERER"])) {
		$timespan_sel_pos = strpos($_SERVER["HTTP_REFERER"],"&predefined_timespan");
		if ($timespan_sel_pos) {
			$_SERVER["HTTP_REFERER"] = substr($_SERVER["HTTP_REFERER"],0,$timespan_sel_pos);
		}
	}

	$_SESSION["graph_settings_referer"] = (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"]:"graph_view.php"); 
	form_hidden_box("save_component_graph_config","1","");
	form_save_button("graph_settings.php", "save");
}

?>