$id_container2, 'type' => 'simple_graph', 'id_agent' => $id_agent, 'id_agent_module' => $id_agent_module, 'time_lapse' => $time_lapse, 'type_graph' => $simple_type_graph, 'fullscale' => $fullscale, ]; $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'); $fullscale = get_parameter('fullscale'); if ($fullscale != 'false') { $fullscale = 1; } else { $fullscale = 0; } $values = [ 'id_container' => $id_container2, 'type' => 'custom_graph', 'time_lapse' => $time_lapse, 'id_graph' => $id_custom, 'fullscale' => $fullscale, ]; $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); $simple_type_graph2 = get_parameter('simple_type_graph2'); $fullscale = get_parameter('fullscale'); if ($fullscale != 'false') { $fullscale = 1; } else { $fullscale = 0; } $values = [ '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, 'type_graph' => $simple_type_graph2, 'fullscale' => $fullscale, ]; $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 if ((bool) $id_container !== false) { $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) { if ((bool) $name !== false) { $values = [ 'name' => $name, 'description' => $description, 'parent' => $id_parent, 'id_group' => $id_group, ]; $id_container = db_process_sql_insert('tcontainer', $values); } else { $error = ui_print_error_message( __('Container name is missing.'), '', true ); } } if ($update_container) { if ($id_container === $id_parent) { $success = false; } else { $values = [ 'name' => $name, 'description' => $description, 'parent' => $id_parent, 'id_group' => $id_group, ]; $success = db_process_sql_update('tcontainer', $values, ['id_container' => $id_container]); } } if ($delete_item) { $id_item = get_parameter('id_item', 0); $success = db_process_sql_delete('tcontainer_item', ['id_ci' => $id_item]); } $buttons['graph_container'] = [ 'active' => false, 'text' => ''.html_print_image( 'images/graph-container@svg.svg', true, [ 'title' => __('Graph container'), 'class' => 'invert_filter', ] ).'', ]; // Header. ui_print_standard_header( __('Create container'), 'images/chart.png', false, 'create_container', false, $buttons, [ [ 'link' => '', 'label' => __('Reporting'), ], [ 'link' => '', 'label' => __('Custom graphs'), ], ] ); if ($add_container) { ui_print_result_message($id_container, __('Container stored successfully'), __('There was a problem storing container')); if (empty($error) === false) { echo $error; } } if ($update_container) { ui_print_result_message($success, __('Update the container'), __('Bad update the container')); } $table = ''; if ($edit_container) { $table .= "
"; } else { $table .= ""; } $table .= ""; $table .= ''; $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; } $table .= "'; $table .= "'; $table .= ''; $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]); $table .= '
'; $input_value = ''; if ($edit_container) { $input_value = io_safe_output($name); } if ($id_container === '1') { $input_name = html_print_input_text('name', $input_value, '', false, 255, true, true); } else { $input_name = html_print_input_text('name', $input_value, '', false, 255, true, false, true); } $table .= html_print_label_input_block( __('Name'), $input_name ); $table .= '"; $table .= html_print_label_input_block( __('Group'), html_print_input( [ 'type' => 'select_groups', 'id_user' => $config['id_user'], 'privilege' => 'RW', 'returnAllGroup' => $return_all_groups, 'name' => 'container_id_group', 'selected' => $id_group, 'script' => '', 'nothing' => '', 'nothing_value' => '', 'return' => true, 'required' => true, 'disabled' => ($id_container === '1'), 'style' => 'width:100% !important', ] ) ); $table .= '"; if ($id_container === '1') { $table .= html_print_label_input_block( __('Parent container'), html_print_select( $containers_tree, 'id_parent', $id_parent, '', __('none'), 0, true, '', false, 'w130', true, 'width: 100%', '' ) ); } else { $table .= html_print_label_input_block( __('Parent container'), html_print_select( $containers_tree, 'id_parent', $id_parent, '', __('none'), 0, true, '', false, 'w130', '', 'width: 100%', '' ) ); } $table .= '
'; $textarea_disabled = false; if ($id_container === '1') { $textarea_disabled = true; } $texarea_value = ''; if ($edit_container) { $texarea_value = io_safe_output($description); } $table .= html_print_label_input_block( __('Description'), html_print_textarea( 'description', 2, 95, $texarea_value, '', true, '', $textarea_disabled ) ); $table .= '
'; if ($edit_container) { if ($id_container !== '1') { $table .= html_print_div( [ 'class' => 'action-buttons', 'content' => html_print_submit_button( __('Update'), 'store', false, [ 'mode' => 'mini', 'icon' => 'next', ], true ), ], true ); } } else { $table .= html_print_div( [ 'class' => 'action-buttons', 'content' => html_print_submit_button( __('Create'), 'store', false, [ 'mode' => 'mini', 'icon' => 'next', ], true ), ], true ); } $table .= '
'; ui_toggle( $table, ''.__('Container').'', 'container', '', false, false, '', 'white-box-content', 'box-flat white_table_graph' ); echo '
'; echo '
'; echo '
'; if ($edit_container) { $period = SECONDS_15DAYS; $periods = []; $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'); $type_graphs = []; $type_graphs[0] = __('Area'); $type_graphs[1] = __('Line'); $single_table = ""; $single_table .= ""; $single_table .= "'; $single_table .= "'; $single_table .= "'; $single_table .= ''; $single_table .= ""; $single_table .= "'; $single_table .= "'; $single_table .= ''; $single_table .= '
"; $single_table .= html_print_label_input_block( __('Time lapse').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 ), html_print_extended_select_for_time( 'period_single', $period, '', '', '0', 10, true, 'width:100%', true, '', false, $periods ) ); $single_table .= '"; $params = []; $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 .= html_print_label_input_block( __('Agent'), ui_print_agent_autocomplete_input($params) ); $single_table .= '"; if ($idAgent) { $select_module .= html_print_select_from_sql($sql_modules, 'id_agent_module', $idAgentModule, '', '', '0', true); } else { $select_module .= "'; } $single_table .= html_print_label_input_block( __('Module'), $select_module ); $single_table .= '
"; $single_table .= html_print_label_input_block( __('Type of graph'), html_print_select($type_graphs, 'simple_type_graph2', '', '', '', 0, true, false, true, '', false, 'width:100%') ); $single_table .= '"; $single_table .= html_print_label_input_block( __('Show full scale graph (TIP)').ui_print_help_tip('This option may cause performance issues', true), html_print_checkbox('fullscale', 1, false, true) ); $single_table .= '
'; $single_table .= html_print_div( [ 'class' => 'action-buttons-right-forced mrgn_right_10px', 'content' => html_print_submit_button( __('Add item'), 'add_single', false, [ 'mode' => 'mini', 'icon' => 'next', ], true ), ], true ); ui_toggle( $single_table, ''.__('Simple module graph').'', 'container', '', true, false, '', 'white-box-content', 'box-flat white_table_graph' ); $table = new stdClass(); $table->id = 'custom_graph_table'; $table->width = '100%'; $table->cellspacing = 4; $table->cellpadding = 4; $table->class = 'filter-table-adv'; $table->styleTable = 'font-weight: bold;'; $table->style[0] = 'width: 13%'; $table->data = []; $table->size[0] = '30%'; $table->size[1] = '30%'; $table->size[2] = '30%'; $table->data[0][0] = html_print_label_input_block( __('Time lapse').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 ), html_print_extended_select_for_time('period_custom', $period, '', '', '0', 10, true, 'width:100%', true, '', false, $periods) ); $list_custom_graphs = custom_graphs_get_user($config['id_user'], false, true, 'RR'); $graphs = []; foreach ($list_custom_graphs as $custom_graph) { $graphs[$custom_graph['id_graph']] = $custom_graph['name']; } $table->data[0][1] = html_print_label_input_block( __('Custom graph'), html_print_select($graphs, 'id_custom_graph', $idCustomGraph, '', __('None'), 0, true, '', true, '', false, 'width:100%') ); $table->data[0][2] = html_print_label_input_block( __('Show full scale graph (TIP)').ui_print_help_tip('This option may cause performance issues', true), html_print_checkbox('fullscale_2', 1, false, true) ); $data_toggle = html_print_table($table, true); $data_toggle .= html_print_div( [ 'class' => 'action-buttons-right-forced mrgn_right_10px', 'content' => html_print_submit_button( __('Add item'), 'add_custom', false, [ 'mode' => 'mini', 'icon' => 'next', ], true ), ], true ); ui_toggle( $data_toggle, ''.__('Custom graph').'', 'container', '', true, false, '', 'white-box-content', 'box-flat white_table_graph' ); unset($table); $table = new stdClass(); $table->id = 'dynamic_rules_table'; $table->width = '100%'; $table->cellspacing = 4; $table->cellpadding = 4; $table->class = 'filter-table-adv'; $table->styleTable = 'font-weight: bold;'; $table->data = []; $table->size[0] = '30%'; $table->size[1] = '30%'; $table->size[2] = '30%'; $table->data[0][0] = html_print_label_input_block( __('Time lapse').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 ), html_print_extended_select_for_time('period_custom', $period, '', '', '0', 10, true, 'width:100%', true, '', false, $periods) ); $table->data[0][1] = html_print_label_input_block( __('Group'), html_print_select_groups($config['id_user'], 'RW', $return_all_groups, 'container_id_group', $id_group, '', '', '', true) ); $table->data[0][2] = html_print_label_input_block( __('Module group'), html_print_select_from_sql( 'SELECT * FROM tmodule_group ORDER BY name', 'combo_modulegroup', $modulegroup, '', __('All'), false, true, false, true, false, 'width:100%' ) ); $table->data[1][0] = html_print_label_input_block( __('Agent'), html_print_input_text('text_agent', $textAgent, '', 30, 100, true) ); $table->data[1][1] = html_print_label_input_block( __('Module'), html_print_input_text('text_agent_module', $textModule, '', 30, 100, true) ); $select_tags = tags_search_tag(false, false, true); $table->data[1][2] = html_print_label_input_block( __('Tag'), html_print_select( $select_tags, 'tag', $tag, '', __('Any'), 0, true, false, false, '', false, 'width:100%' ) ); $table->data[2][0] = html_print_label_input_block( __('Type of graph'), html_print_select($type_graphs, 'simple_type_graph2', '', '', '', 0, true, false, true, '', false, 'width:100%') ); $table->data[2][1] = html_print_label_input_block( __('Show full scale graph (TIP)').ui_print_help_tip('This option may cause performance issues', true), html_print_checkbox('fullscale_3', 1, false, true) ); $data_toggle = html_print_table($table, true); $data_toggle .= html_print_div( [ 'class' => 'action-buttons-right-forced mrgn_right_10px', 'content' => html_print_submit_button( __('Add item'), 'add_dynamic', false, [ 'mode' => 'mini', 'icon' => 'next', ], true ), ], true ); ui_toggle( $data_toggle, ''.__('Dynamic rules for simple module graph').'', 'container', '', true, false, '', 'white-box-content', 'box-flat white_table_graph' ); if ((bool) $id_container !== false) { $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 items in this container.').'
'; } else { ui_pagination($total_item[0]['count(*)'], false, $offset, 10); $table = new stdClass(); $table->width = '100%'; $table->class = 'info_table'; $table->id = 'item_table'; $table->align = []; $table->head = []; $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 = []; $i = 0; foreach ($result_item as $item) { $data = []; 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', ['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', ['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', ['id_tag' => $item['id_tag']])); } break; } $table->cellclass[$i][7] = 'table_action_buttons'; $i++; $data[7] = ''.html_print_image('images/delete.svg', true, ['alt' => __('Delete'), 'title' => __('Delete'), 'class' => 'invert_filter main_menu_icon']).''; array_push($table->data, $data); } html_print_table($table); } } echo html_print_input_hidden('id_agent', 0); ?>