From e243067c4bf4efc9409b8cb583262a93c8156db4 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 23 May 2017 17:13:47 +0200 Subject: [PATCH] New feature: Graphic grouping --- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 38 ++ .../godmode/reporting/create_container.php | 617 ++++++++++++++++++ .../godmode/reporting/graph_container.php | 135 ++++ pandora_console/godmode/reporting/graphs.php | 5 +- pandora_console/godmode/setup/performance.php | 3 + pandora_console/images/graph-container.png | Bin 0 -> 429 bytes pandora_console/include/ajax/graph.ajax.php | 229 +++++++ pandora_console/include/functions_config.php | 6 + .../include/functions_container.php | 328 ++++++++++ pandora_console/include/functions_html.php | 15 +- pandora_console/pandoradb.sql | 36 + pandora_console/pandoradb_data.sql | 5 + 12 files changed, 1411 insertions(+), 6 deletions(-) create mode 100644 pandora_console/godmode/reporting/create_container.php create mode 100644 pandora_console/godmode/reporting/graph_container.php create mode 100644 pandora_console/images/graph-container.png create mode 100644 pandora_console/include/functions_container.php diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 93307fdbc0..924b107944 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1310,3 +1310,41 @@ DROP PROCEDURE addcol; -- Table `tconfig` -- --------------------------------------------------------------------- UPDATE `tconfig` SET `value` = 'login_logo_v7.png' where `token`='custom_logo_login'; + +-- --------------------------------------------------------------------- +-- Table `tcontainer` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tcontainer` ( + `id_container` mediumint(4) unsigned NOT NULL auto_increment, + `name` varchar(100) NOT NULL default '', + `parent` mediumint(4) unsigned NOT NULL default 0, + `disabled` tinyint(3) unsigned NOT NULL default 0, + `id_group` mediumint(8) unsigned NULL default 0, + `description` TEXT NOT NULL, + PRIMARY KEY (`id_container`), + KEY `parent_index` (`parent`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO `tcontainer` SET `name` = 'Default graph container'; + +-- --------------------------------------------------------------------- +-- Table `tcontainer_item` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tcontainer_item` ( + `id_ci` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `id_container` mediumint(4) unsigned NOT NULL default 0, + `type` varchar(30) default 'simple_graph', + `id_agent` int(10) unsigned NOT NULL default 0, + `id_agent_module` bigint(14) unsigned NULL default NULL, + `time_lapse` int(11) NOT NULL default 0, + `id_graph` INTEGER UNSIGNED default 0, + `only_average` tinyint (1) unsigned default 0 not null, + `id_group` INT (10) unsigned NOT NULL DEFAULT 0, + `id_module_group` INT (10) unsigned NOT NULL DEFAULT 0, + `agent` varchar(100) NOT NULL default '', + `module` varchar(100) NOT NULL default '', + `id_tag` integer(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY(`id_ci`), + FOREIGN KEY (`id_container`) REFERENCES tcontainer(`id_container`) + ON DELETE CASCADE +) ENGINE = InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/godmode/reporting/create_container.php b/pandora_console/godmode/reporting/create_container.php new file mode 100644 index 0000000000..fed5a6242a --- /dev/null +++ b/pandora_console/godmode/reporting/create_container.php @@ -0,0 +1,617 @@ + $id_container2, + 'type' => "simple_graph", + 'id_agent' => $id_agent, + 'id_agent_module' => $id_agent_module, + 'time_lapse' => $time_lapse, + 'only_average' => $only_avg); + + $id_item = db_process_sql_insert('tcontainer_item', $values); + return; + } + + if($add_custom){ + $time_lapse = get_parameter('time_lapse'); + $id_custom = get_parameter('id_custom'); + + $values = array( + 'id_container' => $id_container2, + 'type' => "custom_graph", + 'time_lapse' => $time_lapse, + 'id_graph' => $id_custom); + + $id_item = db_process_sql_insert('tcontainer_item', $values); + return; + } + + if($add_dynamic) { + $time_lapse = get_parameter('time_lapse'); + $group = get_parameter('group',0); + $module_group= get_parameter('module_group',0); + $agent_alias = get_parameter('agent_alias',''); + $module_name = get_parameter('module_name',''); + $tag = get_parameter('tag',0); + + $values = array( + 'id_container' => $id_container2, + 'type' => "dynamic_graph", + 'time_lapse' => $time_lapse, + 'id_group' => $group, + 'id_module_group' => $module_group, + 'agent' => $agent_alias, + 'module' => $module_name, + 'id_tag' => $tag); + + $id_item = db_process_sql_insert('tcontainer_item', $values); + return; + } +} + +$add_container = (bool) get_parameter ('add_container',0); +$edit_container = (bool) get_parameter ('edit_container',0); +$update_container = (bool) get_parameter ('update_container',0); +$delete_item = (bool) get_parameter ('delete_item',0); + +if ($edit_container) { + $name = io_safe_input(get_parameter ('name','')); + if (!empty($name)){ + $id_parent = get_parameter ('id_parent',0); + $description = io_safe_input(get_parameter ('description','')); + $id_group = get_parameter ('container_id_group',0); + }else{ + $tcontainer = db_get_row_sql("SELECT * FROM tcontainer WHERE id_container = " . $id_container); + $name = $tcontainer['name']; + $id_parent = $tcontainer['parent']; + $description = $tcontainer['description']; + $id_group = $tcontainer['id_group']; + } + +} + +if($add_container){ + $values = array( + 'name' => $name, + 'description' => $description, + 'parent' => $id_parent, + 'id_group' => $id_group); + $id_container = db_process_sql_insert('tcontainer', $values); +} + +if($update_container){ + if($id_container === $id_parent){ + $success = false; + } else { + $values = array( + 'name' => $name, + 'description' => $description, + 'parent' => $id_parent, + 'id_group' => $id_group); + $success = db_process_sql_update('tcontainer', $values,array('id_container' => $id_container)); + } +} + + +if($delete_item){ + $id_item = get_parameter('id_item',0); + $success = db_process_sql_delete('tcontainer_item', array('id_ci' => $id_item)); +} + +$buttons['graph_container'] = array('active' => false, + 'text' => '' . + html_print_image("images/graph-container.png", true, array ("title" => __('Graph container'))) . ''); + +// Header +ui_print_page_header (__('Create container'), "", false, "", false, $buttons); + +if($add_container){ + ui_print_result_message($id_container, __('Container stored successfully'), __('There was a problem storing container')); +} + +if($update_container){ + ui_print_result_message($success, __("Update the container"), __("Bad update the container")); +} + +echo ""; +if($edit_container){ + echo ""; +} else { + echo ""; +} + +echo ""; +echo ""; +if($id_container === '1'){ + echo ""; +$own_info = get_user_info ($config['id_user']); +if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) + $return_all_groups = true; +else + $return_all_groups = false; + +echo ""; + +echo ""; +echo ""; +if($id_container === '1'){ + echo ""; +$container = folder_get_folders(); +$tree = folder_get_folders_tree_recursive($container); +$containers_tree = folder_flatten_tree_folders($tree,0); +$containers_tree = folder_get_select($containers_tree); + +unset($containers_tree[$id_container]); + +echo ""; +echo ""; +if($id_container === '1'){ + echo ""; + + +echo "
".__('Name')."".__('Group').""; +if($id_container === '1'){ + echo html_print_select_groups($config['id_user'], '', $return_all_groups, 'container_id_group', $id_group, '', '', '', true,false,true,'',true); +} else { + echo html_print_select_groups($config['id_user'], '', $return_all_groups, 'container_id_group', $id_group, '', '', '', true,false,true,'',false); +} + +echo "
".__('Description').""; +echo "
".__("Parent container")."" . html_print_select ($containers_tree, "id_parent", $id_parent, + '', __('none'), 0, true,'',false,'w130',true,'width: 195px',''); +} else { + echo "" . html_print_select ($containers_tree, "id_parent", $id_parent, + '', __('none'), 0, true,'',false,'w130','','width: 195px',''); +} + + +echo "
"; + +if ($edit_container) { + if($id_container !== '1'){ + echo "
"; + } +} +else { + echo "
"; +} + +echo ""; + +echo "
"; +echo "
"; +echo "
"; + +if($edit_container){ + $period = SECONDS_15DAYS; + $periods = array (); + $periods[-1] = __('custom'); + $periods[SECONDS_1HOUR] = __('1 hour'); + $periods[SECONDS_2HOUR] = sprintf(__('%s hours'), '2 '); + $periods[SECONDS_6HOURS] = sprintf(__('%s hours'), '6 '); + $periods[SECONDS_12HOURS] = sprintf(__('%s hours'), '12 '); + $periods[SECONDS_1DAY] = __('1 day'); + $periods[SECONDS_2DAY] = sprintf(__('%s days'), '2 '); + $periods[SECONDS_5DAY] = sprintf(__('%s days'), '5 '); + $periods[SECONDS_1WEEK] = __('1 week'); + $periods[SECONDS_15DAYS] = __('15 days'); + $periods[SECONDS_1MONTH] = __('1 month'); + + $single_table = ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + $single_table .= "
"; + $single_table .= __('Time lapse'); + $single_table .= ui_print_help_tip(__('This is the interval or period of time with which the graph data will be obtained. For example, a week means data from a week ago from now. '),true); + $single_table .= ""; + $single_table .= html_print_extended_select_for_time('period_single', $period, + '', '', '0', 10, true,false,true,'',false,$periods); + $single_table .= "
"; + $single_table .= __('Agent'); + $single_table .= ""; + $params = array(); + + $params['show_helptip'] = false; + $params['input_name'] = 'agent'; + $params['value'] = ''; + $params['return'] = true; + + $params['javascript_is_function_select'] = true; + $params['selectbox_id'] = 'id_agent_module'; + $params['add_none_module'] = true; + $params['use_hidden_input_idagent'] = true; + $params['hidden_input_idagent_id'] = 'hidden-id_agent'; + + + $single_table .= ui_print_agent_autocomplete_input($params); + $single_table .= "
"; + $single_table .= __('Module'); + $single_table .= ""; + if ($idAgent) { + $single_table .= html_print_select_from_sql($sql_modules, 'id_agent_module', $idAgentModule, '', '', '0',true); + } else { + $single_table .= ""; + } + $single_table .= "
"; + $single_table .= __('Only average'); + $single_table .= ""; + $single_table .= html_print_checkbox('only_avg', 1, true,true); + $single_table .= "
"; + $single_table .= ""; + $single_table .= ""; + $single_table .= "
"; + + echo ""; + echo ""; + echo ""; + echo ""; + echo "
"; + echo ui_toggle($single_table,'Simple module graph', '', true, true); + echo "
"; + + $table = new stdClass(); + $table->id = 'custom_graph_table'; + $table->width = '100%'; + $table->cellspacing = 4; + $table->cellpadding = 4; + $table->class = 'dat'; + + $table->styleTable = 'font-weight: bold;'; + $table->style[0] = 'width: 12%'; + $table->data = array(); + + $data = array(); + $data[0] = __('Time lapse'); + $data[0] .= ui_print_help_tip(__('This is the interval or period of time with which the graph data will be obtained. For example, a week means data from a week ago from now. '),true); + $data[1] = html_print_extended_select_for_time('period_custom', $period,'', '', '0', 10, true,false,true,'',false,$periods); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = __('Custom graph'); + + $list_custom_graphs = custom_graphs_get_user ($config['id_user'], false, true, "RR"); + + $graphs = array(); + foreach ($list_custom_graphs as $custom_graph) { + $graphs[$custom_graph['id_graph']] = $custom_graph['name']; + } + + $data[1] = html_print_select($graphs, 'id_custom_graph',$idCustomGraph, '', __('None'), 0,true); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = ""; + $data[1] = ""; + $table->data[] = $data; + $table->rowclass[] = ''; + + echo ""; + echo ""; + echo ""; + echo ""; + echo "
"; + echo ui_toggle(html_print_table($table, true),'Custom graph', '', true, true); + echo "
"; + + unset($table); + + $table = new stdClass(); + $table->id = 'dynamic_rules_table'; + $table->width = '100%'; + $table->cellspacing = 4; + $table->cellpadding = 4; + $table->class = 'dat'; + + $table->styleTable = 'font-weight: bold;'; + $table->style[0] = 'width: 12%'; + $table->data = array(); + + $data = array(); + $data[0] = __('Time lapse'); + $data[0] .= ui_print_help_tip(__('This is the interval or period of time with which the graph data will be obtained. For example, a week means data from a week ago from now. '),true); + $data[1] = html_print_extended_select_for_time('period_dynamic', $period,'', '', '0', 10, true,false,true,'',false,$periods); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = __('Group'); + $data[1] = html_print_select_groups($config['id_user'], 'RW', $return_all_groups, 'container_id_group', $id_group, '', '', '', true); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = __('Module group'); + $data[1] = html_print_select_from_sql( + "SELECT * FROM tmodule_group ORDER BY name", + 'combo_modulegroup', $modulegroup, '',__('All'),false,true); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = __('Agent'); + $data[1] = html_print_input_text ('text_agent', $textAgent, '', 30, 100, true); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = __('Module'); + $data[1] = html_print_input_text ('text_agent_module', $textModule, '', 30, 100, true); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = __('Tag'); + $select_tags = tags_search_tag (false, false, true); + $data[1] = html_print_select ($select_tags, 'tag', + $tag, '', __('Any'), 0, true, false, false); + $table->data[] = $data; + $table->rowclass[] = ''; + + $data = array(); + $data[0] = ""; + $data[1] = ""; + $table->data[] = $data; + $table->rowclass[] = ''; + + echo ""; + echo ""; + echo ""; + echo ""; + echo "
"; + echo ui_toggle(html_print_table($table, true),'Dynamic rules for simple module graph', '', true, true); + echo "
"; + + $total_item = db_get_all_rows_sql("SELECT count(*) FROM tcontainer_item WHERE id_container = " . $id_container); + $result_item = db_get_all_rows_sql("SELECT * FROM tcontainer_item WHERE id_container = " . $id_container . " LIMIT 10 OFFSET ". $offset); + + if(!$result_item){ + echo "
".__('There are no defined item container')."
"; + } else { + ui_pagination ($total_item[0]['count(*)'],false,$offset,10); + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'databox data'; + $table->id = 'item_table'; + $table->align = array (); + $table->head = array (); + $table->head[0] = __('Agent/Module'); + $table->head[1] = __('Custom graph'); + $table->head[2] = __('Group'); + $table->head[3] = __('M.Group'); + $table->head[4] = __('Agent'); + $table->head[5] = __('Module'); + $table->head[6] = __('Tag'); + $table->head[7] = __('Delete'); + + $table->data = array (); + + + foreach ($result_item as $item) { + $data = array (); + switch ($item['type']) { + case 'simple_graph': + $agent_alias = ui_print_truncate_text(agents_get_alias($item['id_agent'],20,false)); + $module_name = ui_print_truncate_text(modules_get_agentmodule_name($item['id_agent_module']),20,false); + $module_name = + $data[0] = $agent_alias . " / " .$module_name; + $data[1] = ''; + $data[2] = ''; + $data[3] = ''; + $data[4] = ''; + $data[5] = ''; + $data[6] = ''; + break; + + case 'custom_graph': + $data[0] = ''; + $name = db_get_value_filter('name','tgraph',array('id_graph' => $item['id_graph'])); + $data[1] = ui_print_truncate_text(io_safe_output($name),35,false); + $data[2] = ''; + $data[3] = ''; + $data[4] = ''; + $data[5] = ''; + $data[6] = ''; + break; + + case 'dynamic_graph': + $data[0] = ''; + $data[1] = ''; + + $data[2] = ui_print_group_icon($item['id_group'],true); + if ($item['id_module_group'] === '0') { + $data[3] = 'All'; + } else { + $data[3] = io_safe_output(db_get_value_filter('name','tmodule_group',array('id_mg' => $item['id_module_group']))); + + } + $data[4] = io_safe_output($item['agent']); + $data[5] = io_safe_output($item['module']); + if ($item['id_tag'] === '0') { + $data[6] = 'Any'; + } else { + $data[6] = io_safe_output(db_get_value_filter('name','ttag',array('id_tag' => $item['id_tag']))); + } + break; + + } + $data[7] = '' . html_print_image("images/cross.png", true, array('alt' => __('Delete'), 'title' => __('Delete'))) . ''; + + array_push ($table->data, $data); + } + html_print_table ($table); + } + + +} + +echo html_print_input_hidden('id_agent', 0); +?> + + \ No newline at end of file diff --git a/pandora_console/godmode/reporting/graph_container.php b/pandora_console/godmode/reporting/graph_container.php new file mode 100644 index 0000000000..92bca7a2e6 --- /dev/null +++ b/pandora_console/godmode/reporting/graph_container.php @@ -0,0 +1,135 @@ + $value) { + $parent = array( + 'parent' => 1); + db_process_sql_update('tcontainer', $parent, array('id_container' => $value['id_container'])); + } + } + db_process_sql_delete('tcontainer', array('id_container' => $id_container)); + +} + +$max_graph = $config['max_graph_container']; + +$buttons['graph_list'] = array('active' => false, + 'text' => '' . + html_print_image("images/list.png", true, array ("title" => __('Graph list'))) .''); + +$enterpriseEnable = false; +if (enterprise_include_once('include/functions_reporting.php') !== ENTERPRISE_NOT_HOOK) { + $enterpriseEnable = true; +} + +if ($enterpriseEnable) { + $buttons = reporting_enterprise_add_template_graph_tabs($buttons); +} + +$subsection = reporting_enterprise_add_graph_template_subsection('', $buttons); +reporting_enterprise_select_graph_template_tab(); + +$buttons['graph_container'] = array('active' => true, + 'text' => '' . + html_print_image("images/graph-container.png", true, array ("title" => __('Graph container'))) . ''); +// Header +ui_print_page_header (__('Graph container'), "", false, "",false,$buttons); + +$container = folder_get_folders(); + +$tree = folder_get_folders_tree_recursive($container); +echo folder_togge_tree_folders($tree); + +echo "
"; + echo '
'; + html_print_submit_button (__('Create container'), 'create', false, 'class="sub next" style="margin-right:5px;margin-top: 15px;"'); + echo "
"; +echo "
"; + +?> + + \ No newline at end of file diff --git a/pandora_console/godmode/reporting/graphs.php b/pandora_console/godmode/reporting/graphs.php index f37b7e0c2f..f235037070 100644 --- a/pandora_console/godmode/reporting/graphs.php +++ b/pandora_console/godmode/reporting/graphs.php @@ -65,7 +65,10 @@ switch ($activeTab) { reporting_enterprise_select_graph_template_tab($activeTab); break; } - +$buttons['graph_container'] = array('active' => false, + 'text' => '' . + html_print_image("images/graph-container.png", true, array ("title" => __('Graphs containers'))) .''); + $delete_graph = (bool) get_parameter ('delete_graph'); $view_graph = (bool) get_parameter ('view_graph'); $id = (int) get_parameter ('id'); diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 89c9fa9d8d..ceeae084c8 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -138,6 +138,9 @@ $table_other->data[10][1] = html_print_input_text ('big_operation_step_datos_pur $table_other->data[11][0] = __('Small Operation Step to purge old data') . ui_print_help_tip(__('The number of rows that are processed in a single query in deletion. Default is 1000. Increase to 3000-5000 in fast systems. Decrease to 500 or 250 on systems with locks.'), true); $table_other->data[11][1] = html_print_input_text ('small_operation_step_datos_purge', $config["small_operation_step_datos_purge"], '', 5, 5, true); +$table_other->data[12][0] = __('Graph container - Max. Items') . ui_print_help_tip(__('The number of graphs that are viewed in a container. Default is 10 .Increasing this number could lead to performance problems'), true); +$table_other->data[12][1] = html_print_input_text ('max_graph_container', $config["max_graph_container"], '', 5, 5, true); + echo '
'; echo "
"; echo "" . __('Database maintenance options') . ""; diff --git a/pandora_console/images/graph-container.png b/pandora_console/images/graph-container.png new file mode 100644 index 0000000000000000000000000000000000000000..0a1b70b721f2c1b9ca20040fc9e44cfdb1913bf9 GIT binary patch literal 429 zcmV;e0aE^nP)xogv0;L0R7_uKoIl$b2 z&9(1=cs`VC0K|$wyaB{vMDnvB5Z?!yAc)HuFvahIlmI^Wf}8;mKqLoy03kInkL42^ zT!bRHk%@poi9mb-!$hD7pfEfS4M$K&^n-#8*PjfC2r0i2?^HK"; + $single_table .= ""; + $single_table .= ""; + $single_table .= __('Time container lapse'); + // $single_table .= ui_print_help_tip(__('This is the range, or period of time over which the report renders the information for this report type. For example, a week means data from a week ago from now. '),true); + $single_table .= ""; + $single_table .= ""; + $single_table .= html_print_extended_select_for_time('period_container_'.$hash, $period, + '', '', '0', 10, true,'font-size: 9pt;width: 130px;',true,'',false,$periods,'vertical-align: middle;'); + $single_table .= ""; + $single_table .= ""; + $single_table .= ""; + + $table .= $single_table; + $contador = $config['max_graph_container']; + foreach ($result_items as $key => $value) { + $table .= "
"; + if($period > 1){ + $value['time_lapse'] = $period; + } + switch ($value['type']) { + case 'simple_graph': + if ($contador > 0) { + $sql_modulo = db_get_all_rows_sql("SELECT nombre, id_agente FROM + tagente_modulo WHERE id_agente_modulo = ". $value['id_agent_module']); + $sql_alias = db_get_all_rows_sql("SELECT alias from tagente + WHERE id_agente = ". $sql_modulo[0]['id_agente']); + $table .= "

AGENT " .$sql_alias[0]['alias']." MODULE ".$sql_modulo[0]['nombre']."


"; + $table .= grafico_modulo_sparse( + $value['id_agent_module'], + $value['time_lapse'], + 0, + 800, + 300, + '', + '', + false, + $value['only_average'], + false, + 0, + '', + 0, + 0, + 1, + false, + ui_get_full_url(false, false, false, false), + 1, + false, + 0, + false, + false, + 1, + 'white', + null, + false, + false, + 'area'); + $contador --; + } + // $table .= "
"; + break; + case 'custom_graph': + if ($contador > 0) { + $graph = db_get_all_rows_field_filter('tgraph', 'id_graph',$value['id_graph']); + + $sources = db_get_all_rows_field_filter('tgraph_source', 'id_graph',$value['id_graph']); + $modules = array (); + $weights = array (); + $labels = array (); + foreach ($sources as $source) { + array_push ($modules, $source['id_agent_module']); + array_push ($weights, $source['weight']); + if ($source['label'] != ''){ + $item['type'] = 'custom_graph'; + $item['id_agent'] = agents_get_module_id($source['id_agent_module']); + $item['id_agent_module'] = $source['id_agent_module']; + $labels[$source['id_agent_module']] = reporting_label_macro($item, $source['label']); + } + } + + $homeurl = ui_get_full_url(false, false, false, false); + $graph_conf = db_get_row('tgraph', 'id_graph', $value['id_graph']); + + if($graph_conf['stacked'] == 4 || $graph_conf['stacked'] == 9){ + $height = 50; + } else if ($graph_conf['stacked'] == 5){ + $height = 200; + } else { + $height = 300; + } + $table .= "

CUSTOM GRAPH ".$graph[0]['name']."


"; + $table .= graphic_combined_module($modules, + $weights, + $value['time_lapse'], + 800, + $height, + '', + '', + 0, + 0, + 0, + $graph_conf['stacked'], + 0, + false, + $homeurl, + 1, + false, + false, + 'white', + array(), + array(), + 1, + 1, + 1, + 1, + $labels, + false, + false, + null, + false); + $contador --; + } + break; + case 'dynamic_graph': + $alias = " AND alias like '%".io_safe_output($value['agent'])."%'"; + + if($value['id_group'] === '0'){ + $id_group = ""; + } else { + $id_group = " AND id_grupo = ".$value['id_group']; + } + + if($value['id_module_group'] === '0'){ + $id_module_group = ""; + } else { + $id_module_group = " AND id_module_group = ".$value['id_module_group']; + } + + if($value['id_tag'] === '0'){ + $tag = ""; + $id_tag = ""; + } else { + $tag = " INNER JOIN ttag_module ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo "; + $id_tag = " AND ttag_module.id_tag = ".$value['id_tag']; + } + + $module_name = " AND nombre like '%".io_safe_output($value['module'])."%'"; + + $id_agent_module = db_get_all_rows_sql("SELECT tagente_modulo.id_agente_modulo FROM tagente_modulo + ". $tag . "WHERE 1=1" . $id_module_group . $module_name . + " AND id_agente IN (SELECT id_agente FROM tagente WHERE 1=1" .$alias.$id_group.")" + . $id_tag); + + foreach ($id_agent_module as $key2 => $value2) { + if ($contador > 0) { + $sql_modulo2 = db_get_all_rows_sql("SELECT nombre, id_agente FROM + tagente_modulo WHERE id_agente_modulo = ". $value2['id_agente_modulo']); + + $sql_alias2 = db_get_all_rows_sql("SELECT alias from tagente + WHERE id_agente = ". $sql_modulo2[0]['id_agente']); + + $table .= "

AGENT " .$sql_alias2[0]['alias']." MODULE ".$sql_modulo2[0]['nombre']."


"; + + $table .= grafico_modulo_sparse( + $value2['id_agente_modulo'], + $value['time_lapse'], + 0, + 800, + 300, + '', + '', + false, + $value['only_average'], + false, + 0, + '', + 0, + 0, + 1, + false, + ui_get_full_url(false, false, false, false), + 1, + false, + 0, + false, + false, + 1, + 'white', + null, + false, + false, + 'area'); + $contador --; + } + } + break; + } + } + $table .= "
"; + echo $table; + return; + + } +} + ?> diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 7dce4cebd3..2443dd9f3b 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -428,6 +428,8 @@ function config_update_config () { if (!config_update_value ('inventory_purge', get_parameter ('inventory_purge'))) $error_update[] = __('Max. days before delete inventory data'); } + if (!config_update_value ('max_graph_container', get_parameter ('max_graph_container'))) + $error_update[] = __('Graph container - Max. Items'); ///////////// break; @@ -913,6 +915,10 @@ function config_process_config () { config_update_value ('inventory_purge', 21); } } + + if (!isset($config['max_graph_container'])) { + config_update_value ('max_graph_container', 10); + } if (!isset($config['max_macro_fields'])) { config_update_value ('max_macro_fields', 10); diff --git a/pandora_console/include/functions_container.php b/pandora_console/include/functions_container.php new file mode 100644 index 0000000000..886260dc1c --- /dev/null +++ b/pandora_console/include/functions_container.php @@ -0,0 +1,328 @@ + $folder) { + if ($folder['id_container'] == 0) { + continue; + } + + if(!in_array($folder['parent'], array_keys($folders))) { + $folder['parent'] = 0; + } + + $tree[$folder['parent']]['hash_branch'] = 1; + $tree[$folder['parent']]['branch'][$key] = &$tree[$key]; + } + + if (isset($folders[0])) { + $tree = array($tree[0]); + } + else { + $tree = $tree[0]['branch']; + } + + return $tree; + +} + +function folder_flatten_tree_folders($tree, $deep) { + foreach ($tree as $key => $folder) { + $return[$key] = $folder; + unset($return[$key]['branch']); + $return[$key]['deep'] = $deep; + + if (!empty($folder['branch'])) { + $return = $return + + folder_flatten_tree_folders($folder['branch'], $deep + 1); + } + } + + return $return; +} + +function folder_get_select($folders_tree){ + + $fields = array(); + + foreach ($folders_tree as $folder_tree) { + $folderName = ui_print_truncate_text($folder_tree['name'], GENERIC_SIZE_TEXT, false, true, false); + + $fields[$folder_tree['id_container']] = str_repeat("    ", $folder_tree['deep']) . $folderName; + } + return $fields; +} + +function folder_togge_tree_folders($tree) { + $return=array(); + foreach ($tree as $key => $folder) { + + $folderName = ui_print_truncate_text($folder['name'], GENERIC_SIZE_TEXT, false, true, false); + $table = ''; + + // style='background: #f2f2f2;border: 1px solid #e2e2e2;margin-bottom: 4px' + if (!empty($folder['branch'])) { + $togge = $table. folder_togge_tree_folders($folder['branch']); + if ($folder['parent']=== '0'){ + $return[$key] .= "
" . ui_toggle_container($togge,$folderName, '', true, true, $folder['id_group'], $folder['id_container'],$folder['parent']) . "
"; + } else { + $return[$key] .= "
" . ui_toggle_container($togge,$folderName, '', true, true, $folder['id_group'], $folder['id_container'],$folder['parent']) . "
"; + } + } else { + if ($folder['parent'] === '0'){ + $return[$key] = "
"; + } else { + $return[$key] = "
"; + } + $return[$key] .= ui_toggle_container($table,$folderName, '', true, true, $folder['id_group'], $folder['id_container'],$folder['parent']); + $return[$key] .= "
"; + } + } + $retorno = implode("", $return); + return $retorno; +} + +function folder_table ($graphs){ + global $config; + $report_r = check_acl ($config['id_user'], 0, "RR"); + $report_w = check_acl ($config['id_user'], 0, "RW"); + $report_m = check_acl ($config['id_user'], 0, "RM"); + $access = ($report_r == true) ? 'RR' : (($report_w == true) ? 'RW' : (($report_m == true) ? 'RM' : 'RR')); + + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'databox data'; + $table->align = array (); + $table->head = array (); + $table->head[0] = __('Graph name'); + $table->head[1] = __('Description'); + $table->head[2] = __('Number of Graphs'); + $table->head[3] = __('Group'); + $table->size[0] = '30%'; + $table->size[2] = '200px'; + $table->size[3] = '200px'; + $table->align[2] = 'left'; + $table->align[3] = 'left'; + if ($report_w || $report_m) { + $table->align[4] = 'left'; + $table->head[4] = __('Op.') . + html_print_checkbox('all_delete', 0, false, true, false, + 'check_all_checkboxes();'); + $table->size[4] = '90px'; + } + $table->data = array (); + + // $result_graphs = array_slice($graphs, $offset, $config['block_size']); + + foreach ($graphs as $graph) { + $data = array (); + + $data[0] = '' . ui_print_truncate_text($graph['name'], 70) . ''; + + $data[1] = ui_print_truncate_text($graph["description"], 70); + + $data[2] = $graph["graphs_count"]; + $data[3] = ui_print_group_icon($graph['id_group'],true); + + if (($report_w || $report_m) && users_can_manage_group_all($access)) { + $data[4] = ''.html_print_image("images/config.png", true).''; + + $data[4] .= ' '; + + $data[4] .= '' . html_print_image("images/cross.png", true, array('alt' => __('Delete'), 'title' => __('Delete'))) . '' . + html_print_checkbox_extended ('delete_multiple[]', $graph['id_graph'], false, false, '', 'class="check_delete" style="margin-left:2px;"', true); + } + + array_push ($table->data, $data); + } + return $table; +} + +function folder_get_all_child_container($parent) { + + $child_folders = db_get_all_rows_filter('tcontainer', + array('parent' => $parent)); + + return $child_folders; +} + +/** +* Get parent id +*/ +function folder_get_parent_id($child) { + + $child_folders = db_get_all_rows_filter('tcontainer', + array('id_container' => $child)); + + return $child_folders[0]['parent']; +} + +/** +* Get all si +*/ +function folder_get_sibling($sibling) { + + $parent_folders = db_get_all_rows_filter('tcontainer', + array('id_container' => $sibling)); + + $sibling_folders = db_get_all_rows_filter('tcontainer', + array('parent' => $parent_folders[0]['parent'])); + + return $sibling_folders; +} + +function ui_toggle_container($code, $name, $title = '', $hidden_default = true, $return = false, $group , $id_container, $parent = false) { + // Generate unique Id + $uniqid = uniqid(''); + + // Options + if ($hidden_default) { + $style = 'display:none'; + $image_a = html_print_image("images/down.png", true, false, true); + $image_b = html_print_image("images/go.png", true, false, true); + $original = "images/go.png"; + } + else { + $style = ''; + $image_a = html_print_image("images/down.png", true, false, true); + $image_b = html_print_image("images/go.png", true, false, true); + $original = "images/down.png"; + } + + // Link to toggle + $table = new stdClass(); + $table->id = 'container_table'; + $table->width = '100%'; + $table->cellspacing = 4; + $table->cellpadding = 4; + $table->class = 'dat'; + + + if(!$parent){ + $table->styleTable = 'font-weight: bold;background: #f2f2f2;border: 1px solid #e2e2e2;margin-bottom: 4px'; + } else { + $table->styleTable = 'font-weight: bold;margin-bottom: 4px;border-bottom: 1px solid #dcdcdc;'; + } + + $table->style[0] = 'width: 30%'; + $table->style[1] = 'width: 30%'; + + if(!$parent){ + $table->style[0] = 'width: 30%'; + $table->style[1] = 'width: 30%'; + if ($id_container === '1'){ + $table->style[2] = 'padding-right: 34px'; + } + $table->align[1] = 'center'; + $table->align[2] = 'center'; + + + } else { + + $id = folder_get_parent_id($id_container); + $i = 0; + while($id !== '0'){ + $id = folder_get_parent_id($id); + $i++; + } + + $padding_group = 28 * $i; + $padding_icon = 10 * $i; + + $table->style[0] = 'width: 30%'; + $table->style[1] = 'width: 30%;padding-right: '.$padding_group.'px'; + $table->style[2] = 'padding-right: '.$padding_icon.'px'; + $table->align[1] = 'center'; + $table->align[2] = 'center'; + } + + $table->data = array(); + + $data = array(); + $data[0] = '' . html_print_image ($original, true, array ("title" => $title, "id" => "image_".$uniqid)) . '  '.$name.''; + $data[1] = ui_print_group_icon($group,true); + $data[2] = ''.html_print_image("images/config.png", true).''; + if ($id_container !== '1'){ + $data[2] .= '    ' .'' . html_print_image("images/cross.png", true, array('alt' => __('Delete'), 'title' => __('Delete'))) . ''; + } + $table->data[] = $data; + $table->rowclass[] = ''; + + $output .= html_print_table($table, true); + + // Code into a div + $output .= "
\n"; + $output .= html_print_input_hidden($uniqid, $id_container); + $output .= $code; + $output .= "
"; + + // JQuery Toggle + $output .= ''; + + if (!$return) { + echo $output; + } + else { + return $output; + } +} + + +?> diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 11ad895262..d868f68f48 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -700,12 +700,17 @@ function html_print_extended_select_for_post_process($name, $selected = '', function html_print_extended_select_for_time ($name, $selected = '', $script = '', $nothing = '', $nothing_value = '0', $size = false, $return = false, $select_style = false, $unique_name = true, $class='', - $readonly = false) { + $readonly = false, $custom_fields = false,$style_icon = '') { global $config; - $fields = get_periods(); - + if($custom_fields){ + $fields = $custom_fields; + } else { + $fields = get_periods(); + } + + if ( ! $selected ) { foreach( $fields as $t_key => $t_value){ if ( $t_key != -1 ) { @@ -770,7 +775,7 @@ function html_print_extended_select_for_time ($name, $selected = '', array('class' => $uniq_name . '_toggler', 'alt' => __('Custom'), 'title' => __('Custom'), - 'style' => 'width: 18px;'), false, false, true) . + 'style' => 'width: 18px;'.$style_icon), false, false, true) . ''; echo '
'; @@ -784,7 +789,7 @@ function html_print_extended_select_for_time ($name, $selected = '', html_print_image('images/default_list.png', true, array('class' => $uniq_name . '_toggler', 'alt' => __('List'), - 'title' => __('List'), 'style' => 'width: 18px;')) . + 'title' => __('List'), 'style' => 'width: 18px;'.$style_icon)) . ''; echo ''; echo "