function is_graph_allowed($local_graph_id) { $rows = 0; $graph = get_allowed_graphs('', '', '', $rows, 0, $local_graph_id); if ($rows > 0) { return true; } else { return false; } }
function thold_add_select_host() { global $config; $host_id = get_filter_request_var('host_id'); $local_graph_id = get_filter_request_var('local_graph_id'); $data_template_rrd_id = get_filter_request_var('data_template_rrd_id'); $hosts = get_allowed_devices(); top_header(); form_start('thold.php?action=save', 'tholdform'); html_start_box(__('Threshold Creation Wizard'), '50%', '', '3', 'center', ''); if ($host_id == '') { print '<tr><td class="center">' . __('Please select a Device') . '</td></tr>'; } else { if ($local_graph_id == '') { print '<tr><td class="center">' . __('Please select a Graph') . '</td></tr>'; } else { if ($data_template_rrd_id == '') { print '<tr><td class="center">' . __('Please select a Data Source') . '</td></tr>'; } else { print '<tr><td class="center">' . __('Please press \'Create\' to activate your Threshold') . '</td></tr>'; } } } html_end_box(); html_start_box('', '50%', '', '3', 'center', ''); /* display the host dropdown */ ?> <tr><td><table class='filterTable' align='center'> <tr> <?php print html_host_filter(get_request_var('host_id')); ?> </tr><?php if ($host_id != '') { $graphs = get_allowed_graphs('gl.host_id=' . $host_id); ?> <tr> <td> <?php print __('Graph'); ?> </td> <td> <select id='local_graph_id' name='local_graph_id' onChange='applyFilter("graph")'> <option value=''></option><?php foreach ($graphs as $row) { echo "<option value='" . $row['local_graph_id'] . "'" . ($row['local_graph_id'] == $local_graph_id ? ' selected' : '') . '>' . htmlspecialchars($row['title_cache'], ENT_QUOTES) . '</option>'; } ?> </select> </td> </tr><?php } else { ?> <tr> <td> <input type='hidden' id='local_graph_id' name='local_graph_id' value=''> </td> </tr><?php } if ($local_graph_id != '') { $dt_sql = 'SELECT DISTINCT dtr.local_data_id FROM data_template_rrd AS dtr LEFT JOIN graph_templates_item AS gti ON gti.task_item_id=dtr.id LEFT JOIN graph_local AS gl ON gl.id=gti.local_graph_id WHERE gl.id = ' . $local_graph_id; $local_data_id = db_fetch_cell($dt_sql); $dss = db_fetch_assoc('SELECT DISTINCT id, data_source_name FROM data_template_rrd WHERE local_data_id IN (' . $dt_sql . ') ORDER BY data_source_name'); /* show the data source options */ ?> <tr> <td> <?php print __('Data Source'); ?> </td> <td> <input type='hidden' id='local_data_id' name='local_data_id' value='<?php print $local_data_id; ?> '> <select id='data_template_rrd_id' name='data_template_rrd_id' onChange='applyFilter("ds")'> <option value=''></option><?php foreach ($dss as $row) { echo "<option value='" . $row['id'] . "'" . ($row['id'] == $data_template_rrd_id ? ' selected' : '') . '>' . htmlspecialchars($row['data_source_name'], ENT_QUOTES) . '</option>'; } ?> </select> </td> </tr></table></td></tr><?php } else { ?> <tr> <td> <input type='hidden' id='data_template_rrd_id' name='data_template_rrd_id' value=''> </td> </tr></table></td></tr><?php } if ($data_template_rrd_id != '') { echo "<tr><td class='center' colspan='2'><input type='hidden' name='save' id='save' value='save'><input id='go' type='button' value='" . __('Create') . "' title='" . __('Create Threshold') . "'></td></tr>"; } else { echo "<tr><td class='center' colspan='2'></td></tr>"; } html_end_box(); form_end(); html_start_box('', '50%', '', '3', 'center', ''); if ($local_graph_id != '') { print "<tr><td style='text-align:center'><img id='graphi' src='../../graph_image.php?local_graph_id={$local_graph_id}&rra_id=0'></td></tr>"; } html_end_box(); ?> <script type='text/javascript'> function applyFilter(target) { strURL = 'thold.php?action=add&header=false&host_id=' + $('#host_id').val(); if (target != 'host_id') { strURL += '&local_graph_id=' + $('#local_graph_id').val(); } if (target == 'ds') { strURL += '&data_template_rrd_id=' + $('#data_template_rrd_id').val(); } loadPageNoHeader(strURL); } $(function() { $('#go').button().click(function() { strURL = $('#tholdform').attr('action'); json = $('input, select').serializeObject(); $.post(strURL, json).done(function(data) { $('#main').html(data); applySkin(); window.scrollTo(0, 0); }); }); }); </script> <?php }
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) { global $current_user, $config, $graphs_per_page, $graph_timeshifts; include $config['include_path'] . '/global_arrays.php'; include_once $config['library_path'] . '/data_query.php'; include_once $config['library_path'] . '/html_utility.php'; if (empty($tree_id)) { return; } if (empty($leaf_id)) { $leaf_id = 0; } $sql_where = ''; $sql_join = ''; $title = ''; $title_delimeter = ''; $leaf = db_fetch_row("SELECT title, host_id, host_grouping_type\n\t\tFROM graph_tree_items\n\t\tWHERE id={$leaf_id}"); $leaf_type = api_tree_get_item_type($leaf_id); /* get information for the headers */ if (!empty($tree_id)) { $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id={$tree_id}"); } if (!empty($leaf_id)) { $leaf_name = $leaf['title']; } if (!empty($leaf_id)) { $host_name = db_fetch_cell("SELECT host.description FROM (graph_tree_items,host) WHERE graph_tree_items.host_id=host.id AND graph_tree_items.id={$leaf_id}"); } $host_group_data_array = explode(':', $host_group_data); if ($host_group_data_array[0] == 'graph_template') { $host_group_data_name = '<strong>Graph Template:</strong> ' . db_fetch_cell('select name from graph_templates where id=' . $host_group_data_array[1]); $graph_template_id = $host_group_data_array[1]; } elseif ($host_group_data_array[0] == 'data_query') { $host_group_data_name = '<strong>Graph Template:</strong> ' . (empty($host_group_data_array[1]) ? 'Non Query Based' : db_fetch_cell('select name from snmp_query where id=' . $host_group_data_array[1])); $data_query_id = $host_group_data_array[1]; } elseif ($host_group_data_array[0] == 'data_query_index') { $host_group_data_name = '<strong>Graph Template:</strong> ' . (empty($host_group_data_array[1]) ? 'Non Query Based' : db_fetch_cell('select name from snmp_query where id=' . $host_group_data_array[1])) . '-> ' . (empty($host_group_data_array[2]) ? 'Template Based' : get_formatted_data_query_index($leaf['host_id'], $host_group_data_array[1], $host_group_data_array[2])); $data_query_id = $host_group_data_array[1]; $data_query_index = $host_group_data_array[2]; } if (!empty($tree_name)) { $title .= $title_delimeter . '<strong>Tree:</strong>' . htmlspecialchars($tree_name); $title_delimeter = '-> '; } if (!empty($leaf_name)) { $title .= $title_delimeter . '<strong>Leaf:</strong>' . htmlspecialchars($leaf_name); $title_delimeter = '-> '; } if (!empty($host_name)) { $title .= $title_delimeter . '<strong>Device:</strong>' . htmlspecialchars($host_name); $title_delimeter = '-> '; } if (!empty($host_group_data_name)) { $title .= $title_delimeter . " {$host_group_data_name}"; $title_delimeter = '-> '; } validate_tree_vars($tree_id, $leaf_id, $host_group_data); html_start_box('<strong>Graph Filters</strong>' . (strlen(get_request_var_request('filter')) ? " [ Filter '" . htmlspecialchars(get_request_var_request('filter')) . "' Applied ]" : ''), '100%', "", '3', 'center', ''); /* include time span selector */ if (read_graph_config_option('timespan_sel') == 'on') { ?> <tr class='even noprint'> <td class='noprint'> <form name='form_timespan_selector' method='post' action='graph_view.php'> <table cellpadding='2' cellspacing='0'> <tr id='timespan'> <td width='50'> Presets </td> <td> <select id='predefined_timespan' name='predefined_timespan' onChange='spanTime()'> <?php if (isset($_SESSION['custom'])) { $graph_timespans[GT_CUSTOM] = 'Custom'; $start_val = 0; $end_val = sizeof($graph_timespans); } else { if (isset($graph_timespans[GT_CUSTOM])) { asort($graph_timespans); array_shift($graph_timespans); } $start_val = 1; $end_val = sizeof($graph_timespans) + 1; } if (sizeof($graph_timespans) > 0) { for ($value = $start_val; $value < $end_val; $value++) { print "<option value='{$value}'"; if ($_SESSION['sess_current_timespan'] == $value) { print ' selected'; } print '>' . title_trim($graph_timespans[$value], 40) . "</option>\n"; } } ?> </select> </td> <td> From </td> <td> <input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='15' value='<?php print isset($_SESSION['sess_current_date1']) ? $_SESSION['sess_current_date1'] : ''; ?> '> </td> <td> <input type='image' src='images/calendar.gif' align='middle' alt='Start date selector' title='Start date selector' onclick="return showCalendar('date1');"> </td> <td> To </td> <td> <input type='text' name='date2' id='date2' title='Graph End Timestamp' size='15' value='<?php print isset($_SESSION['sess_current_date2']) ? $_SESSION['sess_current_date2'] : ''; ?> '> </td> <td> <input type='image' src='images/calendar.gif' align='middle' alt='End date selector' title='End date selector' onclick="return showCalendar('date2');"> </td> <td> <img style='padding-bottom:0px;cursor:pointer;' border='0' src='images/move_left.gif' align='middle' alt='' title='Shift Left' onClick='timeshiftFilterLeft()'/> </td> <td> <select id='predefined_timeshift' name='predefined_timeshift' title='Define Shifting Interval'> <?php $start_val = 1; $end_val = sizeof($graph_timeshifts) + 1; if (sizeof($graph_timeshifts) > 0) { for ($shift_value = $start_val; $shift_value < $end_val; $shift_value++) { print "<option value='{$shift_value}'"; if ($_SESSION['sess_current_timeshift'] == $shift_value) { print ' selected'; } print '>' . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n"; } } ?> </select> </td> <td> <img style='padding-bottom:0px;cursor:pointer;' name='move_right' src='images/move_right.gif' align='middle' alt='' title='Shift Right' onClick='timeshiftFilterRight()'/> </td> <td> <input type='button' name='button_refresh_x' value='Refresh' title='Refresh selected time span' onClick='refreshTimespanFilter()'> </td> <td> <input type='button' name='button_clear_x' value='Clear' title='Return to the default time span' onClick='clearTimespanFilter()'> </td> </tr> <tr id='realtime' style='display:none;'> <td width='50'> Window </td> <td> <select name='graph_start' id='graph_start' onChange='self.imageOptionsChanged("timespan")'> <?php foreach ($realtime_window as $interval => $text) { printf('<option value="%d"%s>%s</option>', $interval, $interval == $_SESSION['sess_realtime_window'] ? ' selected="selected"' : '', $text); } ?> </select> </td> <td> Refresh </td> <td> <select name='ds_step' id='ds_step' onChange="self.imageOptionsChanged('interval')"> <?php foreach ($realtime_refresh as $interval => $text) { printf('<option value="%d"%s>%s</option>', $interval, $interval == $_SESSION['sess_realtime_dsstep'] ? ' selected="selected"' : '', $text); } ?> </select> </td> <td> <input type='button' id='realtimeoff' value='Stop'> </td> <td align='center' colspan='6'> <span id='countdown'></span> </td> </tr> </table> </form> </td> </tr> <?php } ?> <tr class='even noprint' id='search'> <td class='noprint'> <form name='form_graph_view' method='post' onSubmit='changeFilter();return false'> <table cellpadding='2' cellspacing='0'> <tr> <td width='50'> Search </td> <td> <input id='filter' size='30' name='filter' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td> Graphs </td> <td> <select name='graphs' id='graphs' onChange='changeFilter()'> <?php if (sizeof($graphs_per_page) > 0) { foreach ($graphs_per_page as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('graphs') == $key) { print ' selected'; } print '>' . $value . "</option>\n"; } } ?> </select> </td> <td> Columns </td> <td> <select name='columns' id='columns' onChange='changeFilter()' <?php print get_request_var_request('thumbnails') == 'false' ? 'disabled' : ''; ?> > <?php if (get_request_var_request('thumbnails') == 'false') { ?> <option value='<?php print get_request_var_request('columns'); ?> ' selected>N/A</option> <?php } else { ?> <option value='1' <?php print get_request_var_request('columns') == '1' ? ' selected' : ''; ?> >1 Column</option> <option value='2' <?php print get_request_var_request('columns') == '2' ? ' selected' : ''; ?> >2 Columns</option> <option value='3' <?php print get_request_var_request('columns') == '3' ? ' selected' : ''; ?> >3 Columns</option> <option value='4' <?php print get_request_var_request('columns') == '4' ? ' selected' : ''; ?> >4 Columns</option> <option value='5' <?php print get_request_var_request('columns') == '5' ? ' selected' : ''; ?> >5 Columns</option> <?php } ?> </select> </td> <td> <label for='thumbnails'>Thumbnails:</label> </td> <td> <input id='thumbnails' type='checkbox' name='thumbnails' onClick='changeFilter()' <?php print $_REQUEST['thumbnails'] == 'true' ? 'checked' : ''; ?> > </td> <td> <input type='button' value='Go' title='Set/Refresh Filter' onClick='changeFilter()'> </td> <td> <input type='button' value='Clear' title='Clear Filters' onClick='clearFilter()'> </td> </tr> </table> </form> </td> </tr> <script type='text/javascript'> $(function() { var navBar = "<div id='navBar' class='navBar'><?php print draw_navigation_text(); ?> </div>"; if (navBar != '') { $('#navBar').replaceWith(navBar); } setupBreadcrumbs(); }); function changeFilter() { $.get('graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &graphs='+$('#graphs').val()+'&filter='+$('#filter').val()+'&thumbnails='+$('#thumbnails').is(':checked')+'&columns='+$('#columns').val()+'&nodeid='+'<?php print $_SESSION['sess_graph_tree_nodeid']; ?> ', function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { $.get('graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &clear_x=1&nodeid='+'<?php print $_SESSION['sess_graph_tree_nodeid']; ?> ', function(data) { $('#main').html(data); applySkin(); }); } function spanTime() { $.get('graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid='+'<?php print $_SESSION['sess_graph_tree_nodeid']; ?> &predefined_timespan='+$('#predefined_timespan').val()+'&predefined_timeshift='+$('#predefined_timeshift').val(), function(data) { $('#main').html(data); applySkin(); }); } function clearTimespanFilter() { var json = { button_clear_x: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() }; var url = 'graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } function refreshTimespanFilter() { var json = { button_refresh_x: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() }; var url = 'graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } function timeshiftFilterLeft() { var json = { move_left_x: 1, move_left_y: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() }; var url = 'graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } function timeshiftFilterRight() { var json = { move_right_x: 1, move_right_y: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() }; var url = 'graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } function url_graph(strNavURL) { return ''; } </script> <?php html_end_box(); api_plugin_hook_function('graph_tree_page_buttons', array('treeid' => $tree_id, 'leafid' => $leaf_id, 'mode' => 'tree', 'timespan' => $_SESSION['sess_current_timespan'], 'starttime' => get_current_graph_start(), 'endtime' => get_current_graph_end())); html_start_box('', '100%', "", '3', 'center', ''); $graph_list = array(); /* if the number of rows is -1, set it to the default */ if ($_REQUEST['graphs'] == -1) { $_REQUEST['graphs'] = read_graph_config_option('treeview_graphs_per_page'); } if ($leaf_type == 'header' || empty($leaf_id)) { $sql_where = ''; if (strlen(get_request_var_request('filter'))) { $sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%' OR gtg.title LIKE '%" . get_request_var_request('filter') . "%')"; } $graph_list = get_allowed_tree_header_graphs($tree_id, $leaf_id, $sql_where); } elseif ($leaf_type == 'host') { /* graph template grouping */ if ($leaf['host_grouping_type'] == HOST_GROUPING_GRAPH_TEMPLATE) { $sql_where = 'gl.host_id=' . $leaf['host_id'] . (empty($graph_template_id) ? '' : ' AND gt.id=' . $graph_template_id); $graph_templates = get_allowed_graph_templates($sql_where); /* for graphs without a template */ array_push($graph_templates, array('id' => '0', 'name' => '(No Graph Template)')); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $sql_where = ''; if (strlen(get_request_var_request('filter'))) { $sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%')"; } $sql_where .= (strlen($sql_where) ? 'AND' : '') . ' gl.graph_template_id=' . $graph_template['id'] . ' AND gl.host_id=' . $leaf['host_id']; $graphs = get_allowed_graphs($sql_where); /* let's sort the graphs naturally */ usort($graphs, 'naturally_sort_graphs'); if (sizeof($graphs)) { foreach ($graphs as $graph) { $graph['graph_template_name'] = $graph_template['name']; array_push($graph_list, $graph); } } } } /* data query index grouping */ } elseif ($leaf['host_grouping_type'] == HOST_GROUPING_DATA_QUERY_INDEX) { $data_queries = db_fetch_assoc("SELECT sq.id, sq.name\n\t\t\t\tFROM graph_local AS gl\n\t\t\t\tINNER JOIN snmp_query AS sq\n\t\t\t\tON gl.snmp_query_id=sq.id\n\t\t\t\tWHERE gl.host_id=" . $leaf['host_id'] . "\n\t\t\t\t" . (!isset($data_query_id) ? '' : "AND sq.id={$data_query_id}") . "\n\t\t\t\tGROUP BY sq.id\n\t\t\t\tORDER BY sq.name"); /* for graphs without a data query */ if (empty($data_query_id)) { array_push($data_queries, array('id' => '0', 'name' => 'Non Query Based')); } if (sizeof($data_queries) > 0) { foreach ($data_queries as $data_query) { $sql_where = ''; /* fetch a list of field names that are sorted by the preferred sort field */ $sort_field_data = get_formatted_data_query_indexes($leaf['host_id'], $data_query['id']); if (strlen(get_request_var_request('filter'))) { $sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%')"; } /* grab a list of all graphs for this host/data query combination */ $sql_where .= (strlen($sql_where) ? ' AND ' : '') . ' gl.snmp_query_id=' . $data_query['id'] . ' AND gl.host_id=' . $leaf['host_id'] . "\n " . (empty($data_query_index) ? '' : " AND gl.snmp_index='{$data_query_index}'"); $graphs = get_allowed_graphs($sql_where); /* re-key the results on data query index */ $snmp_index_to_graph = array(); if (sizeof($graphs) > 0) { /* let's sort the graphs naturally */ usort($graphs, 'naturally_sort_graphs'); foreach ($graphs as $graph) { $snmp_index_to_graph[$graph['snmp_index']][$graph['local_graph_id']] = $graph['title_cache']; $graphs_height[$graph['local_graph_id']] = $graph['height']; $graphs_width[$graph['local_graph_id']] = $graph['width']; } } /* using the sorted data as they key; grab each snmp index from the master list */ while (list($snmp_index, $sort_field_value) = each($sort_field_data)) { /* render each graph for the current data query index */ if (isset($snmp_index_to_graph[$snmp_index])) { while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) { /* reformat the array so it's compatable with the html_graph* area functions */ array_push($graph_list, array('data_query_name' => $data_query['name'], 'sort_field_value' => $sort_field_value, 'local_graph_id' => $local_graph_id, 'title_cache' => $graph_title, 'height' => $graphs_height[$graph['local_graph_id']], 'width' => $graphs_width[$graph['local_graph_id']])); } } } } } } } $total_rows = sizeof($graph_list); /* generate page list */ $nav = html_nav_bar("graph_view.php?action=tree_content&tree_id={$tree_id}&leaf_id={$leaf_id}&nodeid=" . get_request_var_request('nodeid') . '&host_group_data=' . get_request_var_request('host_group_data'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_rows, 5, 'Graphs', 'page', 'main'); print $nav; /* start graph display */ print "<tr class='tableHeader'><td width='390' colspan='11' class='graphSubHeaderColumn textHeaderDark'>{$title}</td></tr>"; $i = get_request_var_request('graphs') * (get_request_var_request('page') - 1); $last_graph = $i + get_request_var_request('graphs'); $new_graph_list = array(); while ($i < $total_rows && $i < $last_graph) { $new_graph_list[] = $graph_list[$i]; $i++; } if ($_REQUEST['thumbnails'] == 'true') { html_graph_thumbnail_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns')); } else { html_graph_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', 1); } if (!empty($leaf_id)) { api_plugin_hook_function('tree_after', $host_name . ',' . get_request_var_request('leaf_id')); } api_plugin_hook_function('tree_view_page_end'); if ($total_rows > 0) { print $nav; } html_end_box(); }
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(); }
function get_tree_graphs($tree_id, $leaf_id) { if (is_tree_allowed($tree_id)) { if ($leaf_id == -2) { $sql_leaf = 'parent=0 AND'; } elseif ($leaf_id > 0) { $sql_leaf = 'parent=' . $leaf_id . ' AND'; } else { $sql_leaf = ''; } $items = db_fetch_assoc('SELECT * FROM graph_tree_items AS gti WHERE ' . $sql_leaf . ' graph_tree_id=' . $tree_id); $graphs = array(); $hosts = array(); $outArray = array(); if (sizeof($items)) { foreach ($items as $i) { if (empty($i['title']) && $i['local_graph_id'] > 0) { $graphs[$i['local_graph_id']] = $i['local_graph_id']; } elseif ($i['host_id'] > 0 && is_device_allowed($i['host_id'])) { $hosts[$i['host_id']] = $i['host_id']; } elseif ($leaf_id > -2) { $outArray += get_tree_graphs($tree_id, $i['id']); } } } if (sizeof($hosts) && sizeof($graphs)) { $graphs = get_allowed_graphs('(h.id IN(' . implode(',', $hosts) . ') OR gl.id IN(' . implode(',', $graphs) . '))'); } elseif (sizeof($hosts)) { $graphs = get_allowed_graphs('(h.id IN(' . implode(',', $hosts) . '))'); } elseif (sizeof($graphs)) { $graphs = get_allowed_graphs('(gl.id IN(' . implode(',', $graphs) . '))'); } } if (sizeof($graphs)) { foreach ($graphs as $i) { $outArray[$i['local_graph_id']] = $i['title_cache']; } } return $outArray; }
</td> </tr> <?php html_end_box(); /* if the number of rows is -1, set it to the default */ if ($_REQUEST['rows'] == -1) { $_REQUEST['rows'] = read_graph_config_option('num_rows_table'); } /* create filter for sql */ $sql_where = ''; $sql_where .= empty($_REQUEST['filter']) ? '' : " gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%'"; $sql_where .= empty($_REQUEST['host_id']) ? '' : (empty($sql_filter) ? '' : ' AND') . ' gl.host_id=' . get_request_var_request('host_id'); $sql_where .= empty($_REQUEST['graph_template_id']) ? '' : (empty($sql_filter) ? '' : ' AND') . ' gl.graph_template_id=' . get_request_var_request('graph_template_id'); $total_rows = 0; $limit = $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']; $graphs = get_allowed_graphs($sql_where, 'gtg.title_cache', $limit, $total_rows); ?> <form name='chk' id='chk' action='graph_view.php' method='get'> <?php html_start_box('', '100%', '', '3', 'center', ''); $nav = html_nav_bar('graph_view.php?action=list', MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Graphs', 'page', 'main'); print $nav; html_header_checkbox(array('Graph Title', 'Device', 'Graph Template', 'Graph Size'), false); $i = 0; if (sizeof($graphs)) { foreach ($graphs as $graph) { form_alternate_row('line' . $graph['local_graph_id'], true); form_selectable_cell("<strong><a href='" . htmlspecialchars('graph.php?local_graph_id=' . $graph['local_graph_id'] . '&rra_id=all') . "'>" . htmlspecialchars($graph['title_cache']) . '</a></strong>', $graph['local_graph_id']); form_selectable_cell($graph['description'], $graph['local_graph_id']);