function mikrotik_view_graphs() { global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes; include './lib/timespan_settings.php'; include './lib/html_graph.php'; html_graph_validate_preview_request_vars(); /* include graph view filter selector */ html_start_box('<strong>Graph Preview Filters</strong>' . (isset($_REQUEST['style']) && strlen($_REQUEST['style']) ? ' [ Custom Graph List Applied - Filtering from List ]' : ''), '100%', '', '3', 'center', ''); html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")'); html_end_box(); /* the user select a bunch of graphs of the 'list' view and wants them displayed here */ $sql_or = ''; if (isset($_REQUEST['style'])) { if (get_request_var_request('style') == 'selective') { /* process selected graphs */ if (!empty($_REQUEST['graph_list'])) { foreach (explode(',', $_REQUEST['graph_list']) as $item) { $graph_list[$item] = 1; } } else { $graph_list = array(); } if (!empty($_REQUEST['graph_add'])) { foreach (explode(',', $_REQUEST['graph_add']) as $item) { $graph_list[$item] = 1; } } /* remove items */ if (!empty($_REQUEST['graph_remove'])) { foreach (explode(',', $_REQUEST['graph_remove']) as $item) { unset($graph_list[$item]); } } $i = 0; foreach ($graph_list as $item => $value) { $graph_array[$i] = $item; $i++; } if (isset($graph_array) && sizeof($graph_array) > 0) { /* build sql string including each graph the user checked */ $sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id'); $set_rra_id = empty($rra_id) ? read_graph_config_option('default_rra_id') : get_request_var_request('rra_id'); } } } $total_graphs = 0; // Filter sql_where $sql_where = strlen($_REQUEST['filter']) ? "gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%'" : ''; $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or; // Host Id sql_where if ($_REQUEST['host_id'] > 0) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . $_REQUEST['host_id']; } else { $host_ids = mikrotik_host_ids_from_hashes($host_template_hashes); if (sizeof($host_ids)) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')'; } else { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0'; } } // Graph Template Id sql_where if ($_REQUEST['graph_template_id'] > 0) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . $_REQUEST['graph_template_id']; } else { $graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes); if (sizeof($graph_template_ids)) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')'; } else { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0'; } } $limit = $_REQUEST['graphs'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['graphs']; $order = 'gtg.title_cache'; $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs); /* do some fancy navigation url construction so we don't have to try and rebuild the url string */ if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) { $nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string()); } else { $nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id'); } $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url); html_start_box('', '100%', '', '3', 'center', ''); $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_graphs, get_request_var_request('columns'), 'Graphs', 'page', 'main'); print $nav; if (get_request_var_request('thumbnails') == 'true') { html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns')); } else { html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns')); } if ($total_graphs > 0) { print $nav; } html_end_box(); bottom_footer(); }
function hmib_view_graphs() { global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes; include './lib/timespan_settings.php'; include './lib/html_graph.php'; html_graph_validate_preview_request_vars(); if (!isset($_SESSION['sess_hmib_gt'])) { $_SESSION['sess_hmib_gt'] = implode(',', array_rekey(db_fetch_assoc('SELECT DISTINCT gl.graph_template_id FROM graph_local AS gl WHERE gl.host_id IN( SELECT host_id FROM plugin_hmib_hrSystem )'), 'graph_template_id', 'graph_template_id')); } $gt = $_SESSION['sess_hmib_gt']; if (!isset($_SESSION['sess_hmib_hosts'])) { $_SESSION['sess_hmib_hosts'] = implode(',', array_rekey(db_fetch_assoc('SELECT h.id FROM host AS h WHERE h.id IN ( SELECT host_id FROM plugin_hmib_hrSystem ) UNION SELECT h.id FROM host AS h INNER JOIN host_template AS ht ON h.host_template_id=ht.id WHERE hash="7c13344910097cc599f0d0485305361d" ORDER BY id DESC'), 'id', 'id')); } $hosts = $_SESSION['sess_hmib_hosts']; /* include graph view filter selector */ html_start_box(__('Graph Preview Filters') . (isset_request_var('style') && strlen(get_request_var('style')) ? ' [ ' . __('Custom Graph List Applied - Filtering from List') . ' ]' : ''), '100%', '', '3', 'center', ''); html_graph_preview_filter('hmib.php', 'graphs', "h.id IN ({$hosts})", "gt.id IN ({$gt})"); html_end_box(); /* the user select a bunch of graphs of the 'list' view and wants them displayed here */ $sql_or = ''; if (isset_request_var('style')) { if (get_request_var('style') == 'selective') { /* process selected graphs */ if (!isempty_request_var('graph_list')) { foreach (explode(',', get_request_var('graph_list')) as $item) { $graph_list[$item] = 1; } } else { $graph_list = array(); } if (!isempty_request_var('graph_add')) { foreach (explode(',', get_request_var('graph_add')) as $item) { $graph_list[$item] = 1; } } /* remove items */ if (!isempty_request_var('graph_remove')) { foreach (explode(',', get_request_var('graph_remove')) as $item) { unset($graph_list[$item]); } } $graph_array = array_keys($graph_list); if (sizeof($graph_array)) { $sql_or = array_to_sql_or($graph_array, 'gl.id'); } } } $total_graphs = 0; // Filter sql_where $sql_where = strlen(get_request_var('filter')) ? "gtg.title_cache LIKE '%" . get_request_var('filter') . "%'" : ''; $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or; // Host Id sql_where if (get_request_var('host_id') > 0) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . get_request_var('host_id'); } // Graph Template Id sql_where if (get_request_var('graph_template_id') > 0) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . get_request_var('graph_template_id'); } $limit = get_request_var('graphs') * (get_request_var('page') - 1) . ',' . get_request_var('graphs'); $order = 'gtg.title_cache'; $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs); /* do some fancy navigation url construction so we don't have to try and rebuild the url string */ if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) { $nav_url = str_replace('&page=' . get_request_var('page'), '', get_browser_query_string()); } else { $nav_url = get_browser_query_string() . '&host_id=' . get_request_var('host_id'); } $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url); $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_graphs, get_request_var('columns'), 'Graphs', 'page', 'main'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); if (get_request_var('thumbnails') == 'true') { html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns')); } else { html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns')); } html_end_box(); if ($total_graphs > 0) { print $nav; } bottom_footer(); }