1<?php
2
3// Pandora FMS - http://pandorafms.com
4// ==================================================
5// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
6// Please see http://pandorafms.org for full contribution list
7
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation for version 2.
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
16global $config;
17
18require_once('include/functions_custom_graphs.php');
19
20if (is_ajax ()) {
21	$search_agents = (bool) get_parameter ('search_agents');
22
23	if ($search_agents) {
24
25		require_once ('include/functions_agents.php');
26
27		$id_agent = (int) get_parameter ('id_agent');
28		$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
29		$id_group = (int) get_parameter('id_group');
30
31		$filter = array ();
32		$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
33		$filter['id_grupo'] = $id_group;
34
35		$agents = agents_get_agents ($filter, array ('nombre', 'direccion'));
36		if ($agents === false)
37			return;
38
39		foreach ($agents as $agent) {
40			echo $agent['nombre']."|".$agent['direccion']."\n";
41		}
42
43		return;
44	}
45
46	return;
47}
48
49check_login ();
50
51if (! check_acl ($config['id_user'], 0, "RW")) {
52	db_pandora_audit("ACL Violation",
53		"Trying to access graph builder");
54	include ("general/noaccess.php");
55	exit;
56}
57
58if ($edit_graph) {
59	$graphInTgraph = db_get_row_sql("SELECT * FROM tgraph WHERE id_graph = " . $id_graph);
60	$stacked = $graphInTgraph['stacked'];
61	$period = $graphInTgraph['period'];
62	$name = $graphInTgraph['name'];
63	$description = $graphInTgraph['description'];
64	$id_group = $graphInTgraph['id_group'];
65	$width = $graphInTgraph['width'];
66	$height = $graphInTgraph['height'];
67}
68else {
69	$id_agent = 0;
70	$id_module = 0;
71	$id_group = 0;
72	$name = "Pandora FMS combined graph";
73	$width = 550;
74	$height = 210;
75	$period = SECONDS_1DAY;
76	$factor = 1;
77	$stacked = 0;
78}
79
80
81
82// -----------------------
83// CREATE/EDIT GRAPH FORM
84// -----------------------
85
86echo "<table width='100%' cellpadding=4 cellspacing=4 class='databox filters'>";
87
88if ($edit_graph)
89	echo "<form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&edit_graph=1&update_graph=1&id=" . $id_graph . "'>";
90else
91	echo "<form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&edit_graph=1&add_graph=1'>";
92
93echo "<tr>";
94echo "<td class='datos'><b>".__('Name')."</b></td>";
95echo "<td class='datos'><input type='text' name='name' size='25' ";
96if ($edit_graph) {
97	echo "value='" . $graphInTgraph['name'] . "' ";
98}
99echo ">";
100
101$own_info = get_user_info ($config['id_user']);
102if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
103	$return_all_groups = true;
104else
105	$return_all_groups = false;
106
107echo "<td><b>".__('Group')."</b></td><td>" .
108	html_print_select_groups($config['id_user'], "AR", $return_all_groups, 'graph_id_group', $id_group, '', '', '', true) .
109	"</td></tr>";
110echo "<tr>";
111echo "<td class='datos2'><b>".__('Description')."</b></td>";
112echo "<td class='datos2' colspan=3><textarea name='description' style='height:45px;' cols=55 rows=2>";
113if ($edit_graph) {
114	echo $graphInTgraph['description'];
115}
116
117echo "</textarea>";
118echo "</td></tr>";
119if ($stacked == CUSTOM_GRAPH_GAUGE)
120	$hidden = ' style="display:none;" ';
121else
122	$hidden = '';
123echo "<tr>";
124echo "<td class='datos stacked' $hidden>";
125echo "<b>".__('Width')."</b></td>";
126echo "<td class='datos'>";
127echo "<input type='text' name='width' value='$width' $hidden size=6></td>";
128echo "<td class='datos2'>";
129echo "<b>".__('Height')."</b></td>";
130echo "<td class='datos2'>";
131echo "<input type='text' name='height' value='$height' size=6></td></tr>";
132
133echo "<tr>";
134echo "<td class='datos'>";
135echo "<b>".__('Period')."</b></td>";
136echo "<td class='datos'>";
137html_print_extended_select_for_time ('period', $period, '', '', '0', 10);
138echo "</td><td class='datos2'>";
139echo "<b>".__('Type of graph')."</b></td>";
140echo "<td class='datos2'>";
141
142include_once($config["homedir"] . "/include/functions_graph.php");
143
144$stackeds = array(
145	CUSTOM_GRAPH_AREA => __('Area'),
146	CUSTOM_GRAPH_STACKED_AREA => __('Stacked area'),
147	CUSTOM_GRAPH_LINE => __('Line'),
148	CUSTOM_GRAPH_STACKED_LINE => __('Stacked line'),
149	CUSTOM_GRAPH_BULLET_CHART => __('Bullet chart'),
150	CUSTOM_GRAPH_GAUGE => __('Gauge'),
151	CUSTOM_GRAPH_HBARS => __('Horizontal bars'),
152	CUSTOM_GRAPH_VBARS => __('Vertical bars'),
153	CUSTOM_GRAPH_PIE => __('Pie')
154	);
155html_print_select ($stackeds, 'stacked', $stacked);
156echo "</td>";
157
158echo "</table>";
159
160if ($edit_graph) {
161	echo "<div style='width:100%'><input style='float:right;' type=submit name='store' class='sub upd' value='".__('Update')."'></div>";
162}
163else {
164	echo "<div style='width:100%'><input style='float:right;' type=submit name='store' class='sub next' value='".__('Create')."'></div>";
165}
166echo "</form>";
167
168
169echo '<script type="text/javascript">
170	$("#stacked").change(function(){
171		console.log($(this).val());
172		if ( $(this).val() == '. CUSTOM_GRAPH_GAUGE .') {
173			$(".stacked").hide();
174			$("input[name=\'width\']").hide();
175		}
176		else {
177			$(".stacked").show();
178			$("input[name=\'width\']").show();
179		}
180	});
181
182</script>';
183?>