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 18if (is_ajax ()) { 19 $search_agents = (bool) get_parameter ('search_agents'); 20 21 if ($search_agents) { 22 23 require_once ('include/functions_agents.php'); 24 25 $id_agent = (int) get_parameter ('id_agent'); 26 $string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */ 27 $id_group = (int) get_parameter('id_group'); 28 29 $filter = array (); 30 $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; 31 $filter['id_grupo'] = $id_group; 32 33 $agents = agents_get_agents ($filter, array ('nombre', 'direccion')); 34 if ($agents === false) 35 return; 36 37 foreach ($agents as $agent) { 38 echo $agent['nombre']."|".$agent['direccion']."\n"; 39 } 40 41 return; 42 } 43 44 return; 45} 46 47check_login (); 48 49if (! check_acl ($config['id_user'], 0, "RW")) { 50 db_pandora_audit("ACL Violation", 51 "Trying to access graph builder"); 52 include ("general/noaccess.php"); 53 exit; 54} 55 56unset($name); 57 58$add_module = (bool) get_parameter ('add_module', false); 59$delete_module = (bool) get_parameter ('delete_module', false); 60$edit_graph = (bool) get_parameter('edit_graph', false); 61$active_tab = get_parameter('tab', 'main'); 62$add_graph = (bool) get_parameter('add_graph', false); 63$update_graph = (bool) get_parameter('update_graph', false); 64$change_weight = (bool) get_parameter('change_weight', false); 65$change_label = (bool) get_parameter('change_label', false); 66$id_graph = (int) get_parameter('id', 0); 67 68if ($add_graph) { 69 $name = get_parameter_post ("name"); 70 $description = get_parameter_post ("description"); 71 $module_number = get_parameter_post ("module_number"); 72 $idGroup = get_parameter_post ('graph_id_group'); 73 $width = get_parameter_post ("width"); 74 $height = get_parameter_post ("height"); 75 $stacked = get_parameter ("stacked", 0); 76 $period = get_parameter_post ("period"); 77 78 // Create graph 79 $values = array( 80 'id_user' => $config['id_user'], 81 'name' => $name, 82 'description' => $description, 83 'period' => $period, 84 'width' => $width, 85 'height' => $height, 86 'private' => 0, 87 'id_group' => $idGroup, 88 'stacked' => $stacked); 89 90 if (trim($name) != "") { 91 $id_graph = db_process_sql_insert('tgraph', $values); 92 if ($id_graph !== false) 93 db_pandora_audit("Report management", "Create graph #$id_graph"); 94 else 95 db_pandora_audit("Report management", "Fail try to create graph"); 96 } 97 else { 98 $id_graph = false; 99 } 100 101 if(!$id_graph) 102 $edit_graph = false; 103} 104 105if ($update_graph) { 106 $id_graph = get_parameter('id'); 107 $name = get_parameter('name'); 108 $id_group = get_parameter('graph_id_group'); 109 $description = get_parameter('description'); 110 $width = get_parameter('width'); 111 $height = get_parameter('height'); 112 $period = get_parameter('period'); 113 $stacked = get_parameter('stacked'); 114 $alerts = get_parameter('alerts'); 115 116 if (trim($name) != "") { 117 118 $success = db_process_sql_update('tgraph', 119 array('name' => $name, 'id_group' => $id_group, 'description' => $description, 'width' => $width, 'height' => $height, 'period' => $period, 'stacked' => $stacked), 120 array('id_graph' => $id_graph)); 121 if ($success !== false) 122 db_pandora_audit("Report management", "Update graph #$id_graph"); 123 else 124 db_pandora_audit("Report management", "Fail try to update graph #$id_graph"); 125 126 } 127 else { 128 $success = false; 129 } 130} 131 132function add_quotes($item) 133{ 134 return "'$item'"; 135} 136 137if ($add_module) { 138 $id_graph = get_parameter('id'); 139 $id_modules = get_parameter('module'); 140 $id_agents = get_parameter('id_agents'); 141 $weight = get_parameter('weight'); 142 143 //Id modules has double entities conversion 144 //Safe output remove all entities 145 io_safe_output_array($id_modules, ""); 146 147 //We need to put the entities again 148 //to browse in db 149 io_safe_input_array($id_modules); 150 151 $id_agent_modules = db_get_all_rows_sql("SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN (". 152 implode(',', $id_agents). 153 ") AND nombre IN ('". 154 implode("','", $id_modules). 155 "')"); 156 157 if (count($id_agent_modules) > 0 && $id_agent_modules != '') { 158 foreach($id_agent_modules as $id_agent_module) 159 $result = db_process_sql_insert('tgraph_source', array('id_graph' => $id_graph, 'id_agent_module' => $id_agent_module['id_agente_modulo'], 'weight' => $weight)); 160 } 161 else 162 $result = false; 163} 164 165if ($delete_module) { 166 $deleteGraph = get_parameter('delete'); 167 $result = db_process_sql_delete('tgraph_source', array('id_gs' => $deleteGraph)); 168} 169 170if ($change_weight) { 171 $weight = get_parameter ('weight'); 172 $id_gs = get_parameter ('graph'); 173 db_process_sql_update('tgraph_source', 174 array('weight' => $weight), 175 array('id_gs' => $id_gs)); 176} 177if ($change_label) { 178 $label = get_parameter ('label'); 179 $id_gs = get_parameter ('graph'); 180 db_process_sql_update('tgraph_source', 181 array('label' => $label), 182 array('id_gs' => $id_gs)); 183} 184 185if ($edit_graph) { 186 $buttons = array( 187 'main' => array('active' => false, 188 'text' => '<a href="index.php?sec=reporting&sec2=godmode/reporting/graph_builder&tab=main&edit_graph=1&id=' . $id_graph . '">' . 189 html_print_image("images/chart.png", true, array ("title" => __('Main data'))) .'</a>'), 190 'graph_editor' => array('active' => false, 191 'text' => '<a href="index.php?sec=reporting&sec2=godmode/reporting/graph_builder&tab=graph_editor&edit_graph=1&id=' . $id_graph . '">' . 192 html_print_image("images/builder.png", true, array ("title" => __('Graph editor'))) .'</a>'), 193 'view' => array('active' => false, 194 'text' => '<a href="index.php?sec=reporting&sec2=operation/reporting/graph_viewer&view_graph=1&id=' . $id_graph . '">' . 195 html_print_image("images/operation.png", true, array ("title" => __('View graph'))) .'</a>') 196 ); 197 198 $buttons[$active_tab]['active'] = true; 199 200 $graphInTgraph = db_get_row_sql("SELECT name FROM tgraph WHERE id_graph = " . $id_graph); 201 $name = $graphInTgraph['name']; 202} 203else { 204 $buttons = ''; 205} 206 207$head = __('Graph builder'); 208 209if (isset($name)) 210 $head .= " - ".$name; 211 212// Header 213$tab = get_parameter("tab", ""); 214switch ($tab) { 215 case "main": 216 ui_print_page_header ($head, "images/chart.png", false, "graph_builder", false, $buttons); 217 break; 218 case "graph_editor": 219 ui_print_page_header ($head, "images/chart.png", false, "graph_editor", false, $buttons); 220 break; 221 default: 222 ui_print_page_header ($head, "images/chart.png", false, "graph_builder", false, $buttons); 223 break; 224} 225 226if ($add_graph) 227 ui_print_result_message($id_graph, __('Graph stored successfully'), __('There was a problem storing Graph')); 228 229if ($add_module) 230 ui_print_result_message($result, __('Module added successfully'), __('There was a problem adding Module')); 231 232if ($update_graph) 233 ui_print_result_message($success, __("Update the graph"), __("Bad update the graph")); 234 235if ($delete_module) { 236 ui_print_result_message($result, __('Graph deleted successfully'), __('There was a problem deleting Graph')); 237} 238 239// Parse CHUNK information into showable information 240// Split id to get all parameters 241if (!$delete_module) { 242 if (isset($_POST["period"])) 243 $period = $_POST["period"]; 244 if ((isset($chunkdata) )&& ($chunkdata != "")) { 245 $module_array = array(); 246 $weight_array = array(); 247 $agent_array = array(); 248 $chunk1 = array(); 249 $chunk1 = explode ("|", $chunkdata); 250 $modules="";$weights=""; 251 for ($a = 0; $a < count($chunk1); $a++) { 252 $chunk2[$a] = array(); 253 $chunk2[$a] = explode ( ",", $chunk1[$a]); 254 if (strpos($modules, $chunk2[$a][1]) == 0) { // Skip dupes 255 $module_array[] = $chunk2[$a][1]; 256 $agent_array[] = $chunk2[$a][0]; 257 $weight_array[] = $chunk2[$a][2]; 258 if ($modules !="") 259 $modules = $modules.",".$chunk2[$a][1]; 260 else 261 $modules = $chunk2[$a][1]; 262 if ($weights !="") 263 $weights = $weights.",".$chunk2[$a][2]; 264 else 265 $weights = $chunk2[$a][2]; 266 } 267 } 268 } 269} 270 271switch ($active_tab) { 272 case 'main': 273 require_once('godmode/reporting/graph_builder.main.php'); 274 break; 275 case 'graph_editor': 276 require_once('godmode/reporting/graph_builder.graph_editor.php'); 277 break; 278} 279?> 280