function graphs() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graphs_new_host_id"); kill_session_var("sess_graphs_new_graph_type"); kill_session_var("sess_graphs_new_filter"); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_type"]); unset($_REQUEST["filter"]); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("host_id", "sess_graphs_new_host_id"); $changed += check_changed("graph_type", "sess_graphs_new_graph_type"); $changed += check_changed("filter", "sess_graphs_new_filter"); } load_current_session_value("host_id", "sess_graphs_new_host_id", db_fetch_cell("select id from host order by description,hostname limit 1")); load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown")); load_current_session_value("filter", "sess_graphs_new_filter", ""); $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); ?> <script type="text/javascript"> <!-- function applyGraphsNewFilterChange(objForm) { strURL = '?graph_type=' + objForm.graph_type.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <?php if (!empty($debug_log)) { debug_log_clear("new_graphs"); ?> <table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'> <tr bgcolor="<?php print $colors["light"]; ?> "> <td style="padding: 3px; font-family: monospace;"> <?php print $debug_log; ?> </td> </tr> </table> <br> <?php } ?> <form name="form_graphs_new"> <table width="100%" cellpadding="4" align="center"> <tr> <td nowrap style='white-space: nowrap;' width="30%" class="textInfo"> <?php print $host["description"]; ?> (<?php print $host["hostname"]; ?> ) </td> <td align="left" class="textInfo" colspan="2" style="color: #aaaaaa;"> <?php if (!empty($host["host_template_id"])) { print db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]); } ?> </td> </tr> </table> <table width="100%" cellpadding="0" align="center"> <tr> <td nowrap style='white-space: nowrap;' width="55" class="textArea"> Host: </td> <td width="1"> <select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $item) { print "<option value='" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="100" class="textArea"> Graph Types: </td> <td width="1"> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <option value="-2"<?php if ($_REQUEST["graph_type"] == "-2") { ?> selected<?php } ?> >All</option> <option value="-1"<?php if ($_REQUEST["graph_type"] == "-1") { ?> selected<?php } ?> >Graph Template Based</option> <?php $snmp_queries = db_fetch_assoc("SELECT\n\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\n\t\t\t\t\tORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query["id"] . "'"; if ($_REQUEST["graph_type"] == $query["id"]) { print " selected"; } print ">" . $query["name"] . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' class="textInfo" align="center" valign="top"> <span style="white-space: nowrap; color: #c16921;">*</span><a href="host.php?action=edit&id=<?php print $_REQUEST["host_id"]; ?> ">Edit this Host</a><br> <span style="white-space: nowrap; color: #c16921;">*</span><a href="host.php?action=edit">Create New Host</a> </td> </tr> </table> <?php if ($_REQUEST["graph_type"] > 0) { ?> <table width="100%" cellpadding="0" align="center"> <tr> <td nowrap style='white-space: nowrap;' width="55" class="textArea"> Search: </td> <td nowrap style='white-space: nowrap;' width="200"> <input type="text" name="filter" size="30" width="200" value="<?php print $_REQUEST["filter"]; ?> "> </td> <td align="left" nowrap style='white-space: nowrap;'> <input type="image" src="images/button_go.gif" name="go" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> </table> <?php } else { form_hidden_box("filter", $_REQUEST["filter"], ""); } ?> </form> <form name="chk" method="post" action="graphs_new.php"> <?php $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"])); $i = 0; if ($_REQUEST["graph_type"] > 0) { load_current_session_value("page" . $_REQUEST["graph_type"], "sess_graphs_new_page" . $_REQUEST["graph_type"], "1"); } else { if ($_REQUEST["graph_type"] == -2) { foreach ($snmp_queries as $query) { load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } } if ($_REQUEST["graph_type"] < 0) { html_start_box("<strong>Graph Templates</strong>", "100%", $colors["header"], "3", "center", ""); print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t\t<td class='textSubHeaderDark'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id AS graph_template_id,\n\t\t\tgraph_templates.name AS graph_template_name\n\t\t\tFROM (host_graph,graph_templates)\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\n\t\t\tORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT\n\t\t\tgraph_local.graph_template_id\n\t\t\tFROM (graph_local,host_graph)\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\n\t\t\tAND graph_local.host_id=host_graph.host_id\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\n\t\t\tGROUP BY graph_local.graph_template_id"); print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; if (sizeof($template_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { print ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</script>\n"; } /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template["graph_template_id"]; print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>"; $i++; print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'><span id='gt_text{$query_row}" . "_0'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . $graph_template["graph_template_name"] . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print "\t\t</td>\n\t\t\t</tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name"); print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (!$changed) { $page = $_REQUEST["page" . $snmp_query["id"]]; } else { $page = 1; } $xml_array = get_data_query_array($snmp_query["id"]); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("SELECT DISTINCT\n\t\t\t\t\t\tdata_local.snmp_index\n\t\t\t\t\t\tFROM (data_local,data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]); print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { print ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } print ")\n"; } print "//-->\n</script>\n"; } print "\t<table width='100%' style='background-color: #" . $colors["form_alternate2"] . "; border: 1px solid #" . $colors["header"] . ";' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td bgcolor='#" . $colors["header"] . "' colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query["name"] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"] . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='Reload Associated Query' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; if ($xml_array != false) { $html_dq_header = ""; $snmp_query_indexes = array(); reset($xml_array["fields"]); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ""; if (strlen($_REQUEST["filter"])) { $sql_where = ""; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST["filter"] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\tAND host_id=" . $host["id"]); if (sizeof($indexes)) { foreach ($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index["snmp_index"] . "'"; } else { $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'"; } } $sql_where .= ")"; } } if (strlen($_REQUEST["filter"]) == 0 || strlen($_REQUEST["filter"]) && sizeof($indexes)) { /* determine the sort order */ if (isset($xml_array["index_order_type"])) { if ($xml_array["index_order_type"] == "numeric") { $sql_order = "ORDER BY CAST(snmp_index AS unsigned)"; } else { if ($xml_array["index_order_type"] == "alphabetic") { $sql_order = "ORDER BY snmp_index"; } else { if ($xml_array["index_order_type"] == "natural") { $sql_order = "ORDER BY INET_ATON(snmp_index)"; } else { $sql_order = ""; } } } } else { $sql_order = ""; } /* get the unique field values from the database */ $field_names = db_fetch_assoc("SELECT DISTINCT field_name\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"]); /* build magic query */ $sql_query = "SELECT host_id, snmp_query_id, snmp_index"; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach ($field_names as $column) { $field_name = $column["field_name"]; $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'"; $i++; } } $sql_query .= " FROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . "," . $row_limit; $rows_query = "SELECT host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page - 1) * $row_limit > $total_rows) { $page = 1; $_REQUEST["page" . $query["id"]] = $page; load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } if ($total_rows > $row_limit) { /* generate page list */ $url_page_select = get_page_list($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, "graphs_new.php?", "page" . $snmp_query["id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\n\t\t\t\t\t\t\t\t\t<td colspan='15'>\n\t\t\t\t\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong><< "; if ($page > 1) { $nav .= "<a class='linkOverDark' href='graphs_new.php?page" . $snmp_query["id"] . "=" . ($page - 1) . "'>"; } $nav .= "Previous"; if ($page > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t\t\t\tShowing Rows " . ($row_limit * ($page - 1) + 1) . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $page ? $total_rows : $row_limit * $page) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>"; if ($page * $row_limit < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs_new.php?page" . $snmp_query["id"] . "=" . ($page + 1) . "'>"; } $nav .= "Next"; if ($page * $row_limit < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n"; print $nav; } while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach ($field_names as $row) { if ($row["field_name"] == $field_name) { $html_dq_header .= "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>This data query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tdata query. You can <a href='host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"] . "'>run this data\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n"; } else { print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n\n\t\t\t\t\t\t\t</tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, "field_name", "field_name"); if (sizeof($snmp_query_indexes) > 0) { foreach ($snmp_query_indexes as $row) { $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]); print "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? "ffffff" : $colors["light"]) . "'>"; $i++; $column_counter = 0; reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; } else { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n"; } print "</table>"; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { form_hidden_box("sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"], $data_query_graphs[0]["id"], ""); } elseif (sizeof($data_query_graphs) > 1) { print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt='' align='absmiddle'> \n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span> \n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . $column_counter . ");'>\n\t\t\t\t\t\t\t\t\t"; html_create_list($data_query_graphs, "name", "id", "0"); print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>"; } print "<br>"; print "<script type='text/javascript'>dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("host_id", $host["id"], "0"); form_hidden_box("host_template_id", $host["host_template_id"], "0"); form_save_button(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function graphs() { /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graphs_new_filter"); unset($_REQUEST["filter"]); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed("host_id", "sess_graphs_new_host_id"); $changed += check_changed("graph_type", "sess_graphs_new_graph_type"); $changed += check_changed("filter", "sess_graphs_new_filter"); } load_current_session_value("host_id", "sess_graphs_new_host_id", db_fetch_cell("select id from host order by description,hostname limit 1")); load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown")); load_current_session_value("filter", "sess_graphs_new_filter", ""); $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); $header = " [ " . htmlspecialchars($host["description"]) . " (" . htmlspecialchars($host["hostname"]) . ") " . (!empty($host["host_template_id"]) ? htmlspecialchars(db_fetch_cell("select name from host_template where id=" . $host["host_template_id"])) : '') . " ]"; html_start_box("<strong>New Graphs for</strong> {$header}", "100%", "", "3", "center", ""); form_alternate_row(); print "<td>"; if (!empty($debug_log)) { debug_log_clear("new_graphs"); if (read_config_option("cacti_popup_messages") == "on") { ?> <div id='message'> <?php print "<table align='center' class='cactiTable' width='100%'><tr><td style='align:center;padding:3px;font-weight:bold;font-size:10pt;text-align:center;'>Graphs Created</td><td style='width:1px;align:right;'><input type='button' value='Clear' onClick='javascript:document.getElementById(\"message\").style.display=\"none\"' style='align=right;'></td></tr></table>"; ?> <?php print "<table align='left' style='width:100%;'><tr><td><ul style='text-align:left;white-space:nowrap;color:#000000;padding:2px 10px;margin:10px;'>" . $debug_log . "</ul></td></tr></table>"; ?> </div> <?php } else { ?> <table width='100%' class='textArea' align='center'> <tr class='even'> <td style="padding: 3px; font-family: monospace;"> <ul style='margin:0px 5px;padding-left:10px'><?php print $debug_log; ?> </ul> </td> </tr> </table> <br><?php } } ?> <script type="text/javascript"> <!-- <?php if (read_config_option("cacti_popup_messages") == "on") { ?> var obj = document.getElementById('message'); if (obj) { if (window.innerHeight) { height = window.innerHeight; width = window.innerWidth; }else{ height = document.body.clientHeight; width = document.body.clientWidth; } obj.style.class = "popupBox"; cw = obj.offsetWidth; // Adjust for IE6 if (!cw) cw = 150; ch = obj.offsetHeight; obj.style.top = '65px'; obj.style.left = ((width/2) - (cw/2) - 88)+'px'; } <?php } ?> function applyGraphsNewFilterChange(objForm) { strURL = '?graph_type=' + objForm.graph_type.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <form name="form_graphs_new" action="graphs_new.php"> <table width="100%" class="textHeader" cellpadding="2" align="left"> <tr> <td width="55" valign='top'> Host: </td> <td width="1" valign='top'> <select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $item) { print "<option value='" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . htmlspecialchars($item["name"]) . "</option>\n"; } } ?> </select> </td> <td style='white-space:nowrap;' valign='top' width="100"> Graph Types: </td> <td width="1" valign='top'> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <option value="-2"<?php if ($_REQUEST["graph_type"] == "-2") { ?> selected<?php } ?> >All</option> <option value="-1"<?php if ($_REQUEST["graph_type"] == "-1") { ?> selected<?php } ?> >Graph Template Based</option> <?php $snmp_queries = db_fetch_assoc("SELECT\n\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\n\t\t\t\t\tORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query["id"] . "'"; if ($_REQUEST["graph_type"] == $query["id"]) { print " selected"; } print ">" . $query["name"] . "</option>\n"; } } ?> </select> </td> <td rowspan="2" class="textInfo" align="right" valign="top"> <span class="linkMarker">*</span><a href="<?php print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]); ?> ">Edit this Host</a><br> <span class="linkMarker">*</span><a href="<?php print htmlspecialchars("host.php?action=edit"); ?> ">Create New Host</a><br> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> <?php if ($_REQUEST["graph_type"] > 0) { ?> <tr> <td width="55" valign='top'> Search: </td> <td valign='top'> <input type="text" name="filter" size="30" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td colspan='2' valign='top'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> <?php } else { form_hidden_box("filter", $_REQUEST["filter"], ""); } ?> </table> </form> </td> </tr> <?php html_end_box(); ?> <form name="chk" method="post" action="graphs_new.php"> <?php $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"])); $i = 0; if ($changed) { foreach ($snmp_queries as $query) { kill_session_var("sess_graphs_new_page" . $query["id"]); unset($_REQUEST["page" . $query["id"]]); load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } if ($_REQUEST["graph_type"] > 0) { load_current_session_value("page" . $_REQUEST["graph_type"], "sess_graphs_new_page" . $_REQUEST["graph_type"], "1"); } else { if ($_REQUEST["graph_type"] == -2) { foreach ($snmp_queries as $query) { load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } } $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n"; if ($_REQUEST["graph_type"] < 0) { html_start_box("<strong>Graph Templates</strong>", "100%", "", "3", "center", ""); print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id AS graph_template_id,\n\t\t\tgraph_templates.name AS graph_template_name\n\t\t\tFROM (host_graph,graph_templates)\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\n\t\t\tORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT\n\t\t\tgraph_local.graph_template_id\n\t\t\tFROM (graph_local,host_graph)\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\n\t\t\tAND graph_local.host_id=host_graph.host_id\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\n\t\t\tGROUP BY graph_local.graph_template_id"); if (sizeof($template_graphs) > 0) { $script .= "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { $script .= ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } $script .= ")\n"; } /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template["graph_template_id"]; print "<tr id='gt_line{$query_row}' class='" . ($i % 2 == 0 ? "odd" : "even") . "'>"; $i++; print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } $script .= "gt_update_deps(1);\n"; $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr class='" . ($i % 2 == 0 ? "odd" : "even") . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print "\t\t</td>\n\t\t\t</tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (!$changed) { $page = $_REQUEST["page" . $snmp_query["id"]]; } else { $page = 1; } $xml_array = get_data_query_array($snmp_query["id"]); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("SELECT DISTINCT\n\t\t\t\t\t\tdata_local.snmp_index\n\t\t\t\t\t\tFROM (data_local,data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]); $script .= "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { $script .= ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } $script .= ")\n"; } } print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query["name"] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars("graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='middle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; if ($xml_array != false) { $html_dq_header = ""; $snmp_query_indexes = array(); reset($xml_array["fields"]); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ""; if (strlen($_REQUEST["filter"])) { $sql_where = ""; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST["filter"] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\tAND host_id=" . $host["id"]); if (sizeof($indexes)) { foreach ($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index["snmp_index"] . "'"; } else { $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'"; } } $sql_where .= ")"; } } if (strlen($_REQUEST["filter"]) == 0 || strlen($_REQUEST["filter"]) && sizeof($indexes)) { /* determine the sort order */ if (isset($xml_array["index_order_type"])) { if ($xml_array["index_order_type"] == "numeric") { $sql_order = "ORDER BY CAST(snmp_index AS unsigned)"; } else { if ($xml_array["index_order_type"] == "alphabetic") { $sql_order = "ORDER BY snmp_index"; } else { if ($xml_array["index_order_type"] == "natural") { $sql_order = "ORDER BY INET_ATON(snmp_index)"; } else { $sql_order = ""; } } } } else { $sql_order = ""; } /* get the unique field values from the database */ $field_names = db_fetch_assoc("SELECT DISTINCT field_name\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"]); /* build magic query */ $sql_query = "SELECT host_id, snmp_query_id, snmp_index"; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach ($field_names as $column) { $field_name = $column["field_name"]; $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'"; $i++; } } $sql_query .= " FROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . "," . $row_limit; $rows_query = "SELECT host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page - 1) * $row_limit > $total_rows) { $page = 1; $_REQUEST["page" . $query["id"]] = $page; load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } $nav = html_nav_bar("graphs_new.php", MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, "Items", "page" . $snmp_query["id"]); print $nav; while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach ($field_names as $row) { if ($row["field_name"] == $field_name) { $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array["name"] . "</td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='odd'><td>This data query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tdata query. You can <a href='" . htmlspecialchars("host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'>run this data\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n"; } else { print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n\n\t\t\t\t\t\t\t</tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, "field_name", "field_name"); if (sizeof($snmp_query_indexes) > 0) { foreach ($snmp_query_indexes as $row) { $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]); print "<tr id='line{$query_row}' class='" . ($row_counter % 2 == 0 ? "odd" : "even") . "'>"; $i++; $column_counter = 0; reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; } else { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n"; } print "</table>"; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { echo "<input type='hidden' id='sgg_" . $snmp_query["id"] . "' name='sgg_" . $snmp_query["id"] . "' value='" . $data_query_graphs[0]["id"] . "'>\n"; } elseif (sizeof($data_query_graphs) > 1) { print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt=''> \n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span> \n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . (isset($column_counter) ? $column_counter : "") . ");'>\n\t\t\t\t\t\t\t\t\t"; html_create_list($data_query_graphs, "name", "id", "0"); print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>"; } print "<br>"; $script .= "dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");\n"; } } } if (strlen($script)) { $script .= "</script>\n"; print $script; } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("host_id", $host["id"], "0"); form_hidden_box("host_template_id", $host["host_template_id"], "0"); if (isset($_SERVER["HTTP_REFERER"]) && !substr_count($_SERVER["HTTP_REFERER"], "graphs_new")) { $_REQUEST["returnto"] = basename($_SERVER["HTTP_REFERER"]); } load_current_session_value("returnto", "sess_graphs_new_returnto", ""); form_save_button($_REQUEST["returnto"]); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
kill_session_var("sess_graph_view_list_graph_list"); unset($_REQUEST["page"]); unset($_REQUEST["rows"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_template_id"]); unset($_REQUEST["graph_list"]); unset($_REQUEST["graph_add"]); unset($_REQUEST["graph_remove"]); } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed("host_id", "sess_graph_view_list_host"); $changed += check_changed("rows", "sess_graph_view_list_rows"); $changed += check_changed("graph_template_id", "sess_graph_view_list_graph_template"); $changed += check_changed("filter", "sess_graph_view_list_filter"); if ($changed) { $_REQUEST["page"] = 1; } } load_current_session_value("host_id", "sess_graph_view_list_host", "0"); load_current_session_value("graph_template_id", "sess_graph_view_list_graph_template", "0"); load_current_session_value("filter", "sess_graph_view_list_filter", ""); load_current_session_value("page", "sess_graph_view_list_current_page", "1"); load_current_session_value("rows", "sess_graph_view_list_rows", "-1"); load_current_session_value("graph_list", "sess_graph_view_list_graph_list", ""); /* save selected graphs into url */ if (!empty($_REQUEST["graph_list"])) { foreach (explode(",", $_REQUEST["graph_list"]) as $item) { $graph_list[$item] = 1; }
function site() { global $colors, $site_actions, $config; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("site_id")); input_validate_input_number(get_request_var_request("device_template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["detail"])) { $_REQUEST["detail"] = sanitize_search_string(get_request_var("detail")); } /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_sites_current_page"); kill_session_var("sess_sites_detail"); kill_session_var("sess_sites_site_id"); kill_session_var("sess_sites_device_template_id"); kill_session_var("sess_sites_filter"); kill_session_var("sess_sites_rows"); kill_session_var("sess_sites_sort_column"); kill_session_var("sess_sites_sort_direction"); $_REQUEST["page"] = 1; unset($_REQUEST["filter"]); unset($_REQUEST["rows"]); unset($_REQUEST["site_id"]); unset($_REQUEST["device_template_id"]); unset($_REQUEST["detail"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("site_id", "sess_sites_site_id"); $changed += check_changed("device_template_id", "sess_sites_device_template_id"); $changed += check_changed("filter", "sess_sites_filter"); $changed += check_changed("rows", "sess_sites_rows"); $changed += check_changed("detail", "sess_sites_detail"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_sites_current_page", "1"); load_current_session_value("rows", "sess_sites_rows", "-1"); load_current_session_value("detail", "sess_sites_detail", "false"); load_current_session_value("site_id", "sess_sites_site_id", "-1"); load_current_session_value("device_template_id", "sess_sites_device_template_id", "-1"); load_current_session_value("filter", "sess_sites_filter", ""); load_current_session_value("rows", "sess_sites_rows", read_config_option("num_rows_devices")); load_current_session_value("sort_column", "sess_sites_sort_column", "name"); load_current_session_value("sort_direction", "sess_sites_sort_direction", "ASC"); site_filter(); html_start_box("", "100", $colors["header"], "0", "center", ""); $sql_where = ""; if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_device"); }else{ $rows = get_request_var_request("rows"); } $sites = site_get_site_records($sql_where, $rows); if (get_request_var_request("detail") == "false") { $total_rows = db_fetch_cell("SELECT COUNT(sites.id) FROM sites $sql_where"); }else{ $total_rows = sizeof(db_fetch_assoc("SELECT device_template.id, sites.name FROM (device_template RIGHT JOIN device ON (device_template.id=device.device_template_id)) RIGHT JOIN sites ON (device.site_id=sites.id) $sql_where GROUP BY sites.name, device_template.id")); } /* generate page list */ $url_page_select = str_replace("&page", "?page", get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, "sites.php")); if (get_request_var_request("detail") == "false") { /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, 6, "sites.php"); print $nav; html_end_box(false); $display_text = array( "name" => array(__("Site Name"), "ASC"), "address1" => array(__("Address"), "ASC"), "city" => array(__("City"), "ASC"), "state" => array(__("State"), "DESC"), "country" => array(__("Country"), "DESC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($sites) > 0) { foreach ($sites as $site) { form_alternate_row_color('line' . $site["id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("sites.php?action=edit&id=" . $site["id"]) . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $site["name"]) : $site["name"]) . "</a>", $site["id"], "20%"); form_selectable_cell($site["address1"], $site["id"]); form_selectable_cell($site["city"], $site["id"]); form_selectable_cell($site["state"], $site["id"]); form_selectable_cell($site["country"], $site["id"]); form_checkbox_cell($site["name"], $site["id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Sites") . "</em></td></tr>"; } print "</table>\n"; # end table of html_header_sort_checkbox }else{ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, 10, "sites.php"); print $nav; html_end_box(false); $display_text = array( "name" => array(__("Site Name"), "ASC"), "device_template_name" => array(__("Device Type"), "ASC"), "total_devices" => array(__("Devices"), "DESC"), "address1" => array(__("Address"), "ASC"), "city" => array(__("City"), "ASC"), "state" => array(__("State"), "DESC"), "country" => array(__("Country"), "DESC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($sites) > 0) { foreach ($sites as $site) { form_alternate_row_color($site["id"], true); $i++; form_selectable_cell("<a class='linkEditMain' href='sites.php?action=edit&id=" . $site["id"] . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $site["name"]) : $site["name"]) . "</a>", $site["id"], "20%"); form_selectable_cell(preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $site["device_template_name"]), $site["id"]); form_selectable_cell($site["total_devices"], $site["id"]); form_selectable_cell($site["address1"], $site["id"]); form_selectable_cell($site["city"], $site["id"]); form_selectable_cell($site["state"], $site["id"]); form_selectable_cell($site["country"], $site["id"]); form_checkbox_cell($site["name"], $site["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Sites") . "</em></td></tr>"; } print "</table>\n"; # end table of html_header_sort_checkbox } /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($site_actions); print "</form>\n"; # end form of html_header_sort_checkbox }
function data_source() { global $colors, $item_rows; require(CACTI_BASE_PATH . "/include/data_source/data_source_arrays.php"); /* validate request variables */ data_source_validate(); /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_ds_current_page"); kill_session_var("sess_ds_filter"); kill_session_var("sess_ds_sort_column"); kill_session_var("sess_ds_sort_direction"); kill_session_var("sess_ds_rows"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_ds_device_id"); } kill_session_var("sess_ds_template_id"); kill_session_var("sess_ds_method_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["rows"]); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["template_id"]); unset($_REQUEST["method_id"]); $_REQUEST["page"] = 1; }else{ /* let's see if someone changed an important setting */ $changed = FALSE; $changed += check_changed("filter", "sess_ds_filter"); $changed += check_changed("rows", "sess_ds_rows"); $changed += check_changed("device_id", "sess_ds_device_id"); $changed += check_changed("template_id", "sess_ds_template_id"); $changed += check_changed("method_id", "sess_ds_method_id"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_ds_current_page", "1"); load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache"); load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC"); load_current_session_value("rows", "sess_ds_rows", "-1"); load_current_session_value("device_id", "sess_ds_device_id", "-1"); load_current_session_value("template_id", "sess_ds_template_id", "-1"); load_current_session_value("method_id", "sess_ds_method_id", "-1"); $device = db_fetch_row("select hostname from device where id=" . $_REQUEST["device_id"]); ?> <script type="text/javascript"> <!-- $().ready(function() { $("#device").autocomplete("./lib/ajax/get_devices_brief.php", { max: 8, highlight: false, scroll: true, scrollHeight: 300 }); $("#device").result(function(event, data, formatted) { if (data) { $(this).parent().find("#device_id").val(data[1]); applyDSFilterChange(document.form_data_sources); }else{ $(this).parent().find("#device_id").val(0); } }); }); function clearDSFilterChange(objForm) { strURL = '?filter='; <?php # called from outside if (isset($_REQUEST["tab"])) { # print the tab print "strURL = strURL + &tab=" . $_REQUEST["tab"] . "';"; # now look for more parameters if (isset($_REQUEST["device_id"])) { print "strURL = strURL + '&device_id=" . $_REQUEST["device_id"] . "&id=" . $_REQUEST["device_id"] . "';"; } if (isset($_REQUEST["template_id"])) { print "strURL = strURL + '&template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "';"; } }else { # clear all parms print "strURL = strURL + '&device_id=-1';"; print "strURL = strURL + '&template_id=-1';"; } ?> strURL = strURL + '&rows=-1'; strURL = strURL + '&method_id=-1'; document.location = strURL; } function applyDSFilterChange(objForm) { strURL = '?filter=' + objForm.filter.value; // take care of parms provided via autocomplete // those are passed as objForm.<parm>.value // instead of $_REQUEST["<parm>"] when called from outside if (objForm.device_id.value) { strURL = '?device_id=' + objForm.device_id.value; }else{ <?php print (isset($_REQUEST["device_id"]) ? "strURL = strURL + '&device_id=" . $_REQUEST["device_id"] . "&id=" . $_REQUEST["device_id"] . "';" : "strURL = strURL + '&device_id=-1';");?> } if (objForm.template_id.value) { strURL = '?template_id=' + objForm.template_id.value; }else{ <?php print (isset($_REQUEST["template_id"]) ? "strURL = strURL + '&template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "';" : "strURL = strURL + '&template_id=-1';");?> } strURL = strURL + '&rows=' + objForm.rows.value; strURL = strURL + '&method_id=' + objForm.method_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("Data Sources") . "</strong> " . __("[device:") . " " . (empty($device["hostname"]) ? __("No Host") : $device["hostname"]) . "]", "100", $colors["header"], "3", "center", "data_sources.php?action=data_source_edit&device_id=" . $_REQUEST["device_id"], true); ?> <tr class='rowAlternate2'> <td> <form action="data_sources.php" name="form_data_sources"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Host:");?> </td> <td class="w1"> <?php if (isset($_REQUEST["device_id"])) { $hostname = db_fetch_cell("SELECT description as name FROM device WHERE id=".$_REQUEST["device_id"]." ORDER BY description,hostname"); } else { $hostname = ""; } ?> <input class="ac_field" type="text" id="device" size="30" value="<?php print $hostname; ?>"> <input type="hidden" id="device_id"> </td> <td class="nw50"> <?php print __("Template:");?> </td> <td class="w1"> <select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>><?php print __("None");?></option> <?php $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name FROM data_template INNER JOIN data_template_data ON data_template.id=data_template_data.data_template_id WHERE data_template_data.local_data_id>0 ORDER BY data_template.name"); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n"; } } ?> </select> </td> <td class="nw120"> <input type="submit" value="<?php print __("Go");?>" name="go" align="middle"> <input type="button" value="<?php print __("Clear");?>" name="clear" align="middle" onClick="clearDSFilterChange(document.form_data_sources)"> </td> </tr> <tr> <td class="nw50"> <?php print __("Method:");?> </td> <td class="w1"> <select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("method_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="0"<?php if (get_request_var_request("method_id") == "0") {?> selected<?php }?>><?php print __("None");?></option> <?php $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name FROM data_input INNER JOIN data_template_data ON data_input.id=data_template_data.data_input_id WHERE data_template_data.local_data_id>0 ORDER BY data_input.name"); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method["id"] . "'"; if (get_request_var_request("method_id") == $method["id"]) { print " selected"; } print ">" . title_trim($method["name"], 40) . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td class="w1"> <select name="rows" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>><?php print __("Default");?></option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding="1" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Search:");?> </td> <td class="w1"> <input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>"> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(false); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where1 = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')"; $sql_where2 = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where1 = ""; $sql_where2 = ""; } if (get_request_var_request("device_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("device_id") == "0") { $sql_where1 .= " AND data_local.device_id=0"; $sql_where2 .= " AND data_local.device_id=0"; }else { $sql_where1 .= " AND data_local.device_id=" . $_REQUEST["device_id"]; $sql_where2 .= " AND data_local.device_id=" . $_REQUEST["device_id"]; } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where1 .= " AND data_template_data.data_template_id=0"; $sql_where2 .= " AND data_template_data.data_template_id=0"; }else { $sql_where1 .= " AND data_template_data.data_template_id=" . $_REQUEST["template_id"]; $sql_where2 .= " AND data_template_data.data_template_id=" . $_REQUEST["template_id"]; } if (get_request_var_request("method_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("method_id") == "0") { $sql_where1 .= " AND data_template_data.data_input_id=0"; $sql_where2 .= " AND data_template_data.data_input_id=0"; }else { $sql_where1 .= " AND data_template_data.data_input_id=" . $_REQUEST["method_id"]; $sql_where2 .= " AND data_template_data.data_input_id=" . $_REQUEST["method_id"]; } if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_data_source"); }else{ $rows = get_request_var_request("rows"); } $total_rows = sizeof(db_fetch_assoc("SELECT data_local.id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where1")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id, Min(data_template_data.rrd_step*rra.steps) AS poller_interval FROM data_template INNER JOIN (data_local INNER JOIN ((data_template_data_rra INNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id) INNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id $sql_where2 GROUP BY data_template_data.local_data_id"), "id", "poller_interval"); $dssql = "SELECT data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_input.name as data_input_name, data_template.name as data_template_name, data_local.device_id FROM (data_local,data_template_data) LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id) LEFT JOIN data_template ON (data_local.data_template_id=data_template.id) WHERE data_local.id=data_template_data.local_data_id $sql_where1 ORDER BY ". get_request_var_request('sort_column') . " " . get_request_var_request('sort_direction') . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows; $data_sources = db_fetch_assoc($dssql); html_start_box("", "100", $colors["header"], "0", "center", ""); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 7, "data_sources.php"); print $nav; html_end_box(false); $display_text = array( "name_cache" => array(__("Name"), "ASC"), "local_data_id" => array(__("ID"),"ASC"), "data_input_name" => array(__("Data Input Method"), "ASC"), "nosort" => array(__("Poller Interval"), "ASC"), "active" => array(__("Active"), "ASC"), "data_template_name" => array(__("Template Name"), "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source = api_plugin_hook_function('data_sources_table', $data_source); $data_template_name = ((empty($data_source["data_template_name"])) ? "<em>" . __("None") . "</em>" : $data_source["data_template_name"]); $data_input_name = ((empty($data_source["data_input_name"])) ? "<em>" . __("External") . "</em>" : $data_source["data_input_name"]); $poller_interval = ((isset($poller_intervals[$data_source["local_data_id"]])) ? $poller_intervals[$data_source["local_data_id"]] : 0); form_alternate_row_color('line' . $data_source["local_data_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=data_source_edit&id=" . $data_source["local_data_id"]) . "' title='" . htmlspecialchars($data_source["name_cache"]) . "'>" . (($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", title_trim(htmlentities($data_source["name_cache"], ENT_NOQUOTES, "UTF-8"), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"], ENT_NOQUOTES, "UTF-8"), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']); form_selectable_cell((($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $data_input_name) : $data_input_name), $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell(($data_source['active'] == CHECKED ? "Yes" : "No"), $data_source["local_data_id"]); form_selectable_cell((($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']), $data_source["local_data_id"]); form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Data Sources") . "</em></td></tr>"; } print "</table>\n"; # end table of html_header_sort_checkbox /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; # end form of html_header_sort_checkbox }
kill_session_var('sess_graph_view_list_graph_list'); unset($_REQUEST['page']); unset($_REQUEST['rows']); unset($_REQUEST['filter']); unset($_REQUEST['host_id']); unset($_REQUEST['graph_template_id']); unset($_REQUEST['graph_list']); unset($_REQUEST['graph_add']); unset($_REQUEST['graph_remove']); } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed('host_id', 'sess_graph_view_list_host'); $changed += check_changed('rows', 'sess_graph_view_list_rows'); $changed += check_changed('graph_template_id', 'sess_graph_view_list_graph_template'); $changed += check_changed('filter', 'sess_graph_view_list_filter'); if ($changed) { $_REQUEST['page'] = 1; } } load_current_session_value('host_id', 'sess_graph_view_list_host', '0'); load_current_session_value('graph_template_id', 'sess_graph_view_list_graph_template', '0'); load_current_session_value('filter', 'sess_graph_view_list_filter', ''); load_current_session_value('page', 'sess_graph_view_list_current_page', '1'); load_current_session_value('rows', 'sess_graph_view_list_rows', '-1'); load_current_session_value('graph_list', 'sess_graph_view_list_graph_list', ''); /* save selected graphs into url */ if (!empty($_REQUEST['graph_list'])) { foreach (explode(',', $_REQUEST['graph_list']) as $item) { $graph_list[$item] = 1; }
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) { global $current_user, $colors, $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"] . "/tree.php"; include_once $config["library_path"] . "/html_utility.php"; define("MAX_DISPLAY_PAGES", 21); if (empty($tree_id)) { return; } $sql_where = ""; $sql_join = ""; $title = ""; $title_delimeter = ""; $search_key = ""; $leaf = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type\r\n\t\t\t\t\tFROM graph_tree_items\r\n\t\t\t\t\tWHERE id={$leaf_id}"); $leaf_type = get_tree_item_type($leaf_id); /* get the "starting leaf" if the user clicked on a specific branch */ if (!empty($leaf_id)) { $search_key = substr($leaf["order_key"], 0, tree_tier($leaf["order_key"]) * CHARS_PER_TIER); } /* graph permissions */ if (read_config_option("auth_method") != 0) { /* get policy information for the sql where clause */ $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $sql_where = empty($sql_where) ? "" : "AND {$sql_where}"; /* modify for multi user start */ if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR && $tree_id == $_SESSION["public_tree_id"]) { $sql_join = "\r\n LEFT JOIN (SELECT local_graph_id ,COUNT(local_graph_id) AS count FROM graph_tree_items WHERE local_graph_id != '0' GROUP BY local_graph_id) AS gti ON graph_tree_items.local_graph_id = gti.local_graph_id \r\n LEFT JOIN host ON (host.id=graph_local.host_id)\r\n LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n LEFT JOIN user_auth_perms ON (graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1)"; $sql_order = "gti.count DESC"; } else { $sql_join = "\r\n\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\r\n\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))"; $sql_order = "graph_tree_items.order_key"; } /* modify for multi user end */ } /* 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>Host:</strong>" . htmlspecialchars($host_name); $title_delimeter = "-> "; } if (!empty($host_group_data_name)) { $title .= $title_delimeter . " {$host_group_data_name}"; $title_delimeter = "-> "; } if (isset($_REQUEST["tree_id"])) { $nodeid = "tree_" . get_request_var_request("tree_id"); } if (isset($_REQUEST["leaf_id"])) { $nodeid .= "_leaf_" . get_request_var_request("leaf_id"); } if (isset($_REQUEST["host_group_data"])) { $type_id = explode(":", get_request_var_request("host_group_data")); if ($type_id[0] == "graph_template") { $nodeid .= "_hgd_gt_" . $type_id[1]; } elseif ($type_id[0] == "data_query") { $nodeid .= "_hgd_dq_" . $type_id[1]; } else { $nodeid .= "_hgd_dqi" . $type_id[1] . "_" . $type_id[2]; } } print "<script type=\"text/javascript\">\n"; print "<!--\n"; print "myNode = findObj(\"{$nodeid}\")\n"; print "myNode.forceOpeningOfAncestorFolders();\n"; print "highlightObjLink(myNode)\n"; print "//-->\n"; print "</script>"; /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("graphs")); input_validate_input_number(get_request_var_post("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var_post("filter")); } /* clean up search string */ if (isset($_REQUEST["thumbnails"])) { $_REQUEST["thumbnails"] = sanitize_search_string(get_request_var_post("thumbnails")); } /* if the user pushed the 'clear' button */ if (isset($_POST["clear_x"])) { kill_session_var("sess_graph_view_graphs"); kill_session_var("sess_graph_view_filter"); kill_session_var("sess_graph_view_thumbnails"); kill_session_var("sess_graph_view_page"); unset($_POST["graphs"]); unset($_REQUEST["graphs"]); unset($_POST["filter"]); unset($_REQUEST["filter"]); unset($_REQUEST["page"]); unset($_POST["thumbnails"]); unset($_REQUEST["thumbnails"]); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("graphs", "sess_graph_view_graphs"); $changed += check_changed("filter", "sess_graph_view_filter"); $changed += check_changed("action", "sess_graph_view_action"); } if (isset($_SESSION["sess_graph_view_tree_id"])) { if ($_SESSION["sess_graph_view_tree_id"] != $tree_id) { $changed += 1; } } $_SESSION["sess_graph_view_tree_id"] = $tree_id; if (isset($_SESSION["sess_graph_view_leaf_id"])) { if ($_SESSION["sess_graph_view_leaf_id"] != $leaf_id) { $changed += 1; } } $_SESSION["sess_graph_view_leaf_id"] = $leaf_id; if (isset($_SESSION["sess_graph_view_host_group_data"])) { if ($_SESSION["sess_graph_view_host_group_data"] != $host_group_data) { $changed += 1; } } $_SESSION["sess_graph_view_host_group_data"] = $host_group_data; if ($changed) { $_REQUEST["page"] = 1; } load_current_session_value("page", "sess_graph_view_page", "1"); load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("treeview_graphs_per_page")); load_current_session_value("filter", "sess_graph_view_filter", ""); if (isset($_SESSION["sess_graph_view_thumbnails"])) { if ($_SESSION["sess_graph_view_thumbnails"] == "on") { if (isset($_POST["filter"])) { if (!isset($_POST["thumbnails"])) { $_SESSION["sess_graph_view_thumbnails"] = 'off'; } } } else { if (isset($_POST["thumbnails"])) { $_SESSION["sess_graph_view_thumbnails"] = 'on'; } } } else { $_SESSION["sess_graph_view_thumbnails"] = read_graph_config_option("thumbnail_section_tree_2"); if ($_SESSION["sess_graph_view_thumbnails"] == '') { $_SESSION["sess_graph_view_thumbnails"] = 'off'; } else { $_SESSION["sess_graph_view_thumbnails"] = 'on'; } } html_start_box("<strong>Graph Filters</strong>", "100%", $colors["header"], "3", "center", ""); /* include time span selector */ if (read_graph_config_option("timespan_sel") == "on") { ?> <tr bgcolor="#<?php print $colors["panel"]; ?> " class="noprint"> <td class="noprint"> <form style="margin:0px;padding:0px;" name="form_timespan_selector" method="post" action="graph_view.php"> <table cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;'> <strong>Presets:</strong> </td> <td nowrap style='white-space: nowrap;'> <select name='predefined_timespan' onChange="applyTimespanFilterChange(document.form_timespan_selector)"> <?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 nowrap style='white-space: nowrap;'> <strong>From:</strong> </td> <td nowrap style='white-space: nowrap;'> <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 nowrap style='white-space: nowrap;'> <input type='image' src='images/calendar.gif' align='middle' alt='Start date selector' title='Start date selector' onclick="return showCalendar('date1');"> </td> <td nowrap style='white-space: nowrap;'> <strong>To:</strong> </td> <td nowrap style='white-space: nowrap;'> <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 nowrap style='white-space: nowrap;'> <input type='image' src='images/calendar.gif' align='middle' alt='End date selector' title='End date selector' onclick="return showCalendar('date2');"> </td> <td nowrap style='white-space: nowrap;'> <input type='image' name='move_left' src='images/move_left.gif' align='middle' alt='Left' title='Shift Left'> </td> <td nowrap style='white-space: nowrap;'> <select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.form_timespan_selector)"> <?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 nowrap style='white-space: nowrap;'> <input type='image' name='move_right' src='images/move_right.gif' align='middle' alt='Right' title='Shift Right'> </td> <td nowrap style='white-space: nowrap;'> <input type='submit' name='button_refresh_x' value='Refresh' title='Refresh selected time span'> </td> <td nowrap style='white-space: nowrap;'> <input type='submit' name='button_clear_x' value='Clear' title='Return to the default time span'> </td> </tr> </table> </form> </td> </tr> <?php } ?> <tr class="noprint" bgcolor="#e5e5e5"> <td class="noprint"> <form style="margin:0px;padding:0px;" name="form_graph_view" method="post"> <table cellspacing="0" cellpadding="0"> <tr> <td width="55" nowrap="" style="white-space: nowrap;"> <strong> Search:</strong> </td> <td width="130" nowrap="" style="white-space: nowrap;"> <input size='30' name='filter' value='<?php print htmlspecialchars(get_request_var_request("filter")); ?> '> </td> <td nowrap style='white-space:nowrap;' width="110"> <strong>Graphs per Page:</strong> </td> <td width="1"> <select name="graphs" id="graphs" onChange="submit()"> <?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 width="40"> <label for="thumbnails"><strong> Thumbnails: </strong></label> </td> <td> <input type="checkbox" name="thumbnails" onClick="submit()" <?php print $_SESSION['sess_graph_view_thumbnails'] == "on" ? "checked" : ""; ?> > </td> <td style='white-space:nowrap;' nowrap> <input type="submit" value="Go" title="Set/Refresh Filter"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> </form> </td> </tr> <?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%", $colors["header"], "3", "center", ""); $graph_list = array(); if ($leaf_type == "header" || empty($leaf_id)) { if (strlen(get_request_var_request("filter"))) { $sql_where = empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%' OR graph_templates_graph.title LIKE '%" . get_request_var_request("filter") . "%')"; } /* modify for multi user start */ $graph_list = db_fetch_assoc("SELECT\r\n\t\t\tgraph_tree_items.id,\r\n\t\t\tgraph_tree_items.title,\r\n\t\t\tgraph_tree_items.local_graph_id,\r\n\t\t\tgraph_tree_items.rra_id,\r\n\t\t\tgraph_tree_items.order_key,\r\n\t\t\tgraph_templates_graph.height,\r\n\t\t\tgraph_templates_graph.title_cache as title_cache\r\n\t\t\tFROM (graph_tree_items,graph_local)\r\n\t\t\tLEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0)\r\n\t\t\t{$sql_join}\r\n\t\t\tWHERE graph_tree_items.graph_tree_id={$tree_id}\r\n\t\t\tAND graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\tAND graph_tree_items.order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'\r\n\t\t\tAND graph_tree_items.local_graph_id>0\r\n\t\t\t{$sql_where}\r\n\t\t\tGROUP BY graph_tree_items.id\r\n\t\t\tORDER BY {$sql_order}"); /* modify for multi user end */ } elseif ($leaf_type == "host") { /* graph template grouping */ if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) { $graph_templates = db_fetch_assoc("SELECT\r\n\t\t\t\tgraph_templates.id,\r\n\t\t\t\tgraph_templates.name\r\n\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\r\n\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\r\n\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t" . (empty($graph_template_id) ? "" : "AND graph_templates.id={$graph_template_id}") . "\r\n\t\t\t\tGROUP BY graph_templates.id\r\n\t\t\t\tORDER BY graph_templates.name"); /* 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) { if (strlen(get_request_var_request("filter"))) { $sql_where = empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')"; } $graphs = db_fetch_assoc("SELECT DISTINCT\r\n\t\t\t\t\tgraph_templates_graph.title_cache,\r\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\r\n\t\t\t\t\tgraph_templates_graph.height\r\n\t\t\t\t\tFROM (graph_local,graph_templates_graph)\r\n\t\t\t\t\t{$sql_join}\r\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\t\tAND graph_local.graph_template_id=" . $graph_template["id"] . "\r\n\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\tORDER BY graph_templates_graph.title_cache"); /* 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\r\n\t\t\t\tsnmp_query.id,\r\n\t\t\t\tsnmp_query.name\r\n\t\t\t\tFROM (graph_local,snmp_query)\r\n\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\r\n\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t" . (!isset($data_query_id) ? "" : "and snmp_query.id={$data_query_id}") . "\r\n\t\t\t\tGROUP BY snmp_query.id\r\n\t\t\t\tORDER BY snmp_query.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) { /* 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 = empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')"; } /* grab a list of all graphs for this host/data query combination */ $graphs = db_fetch_assoc("SELECT\r\n\t\t\t\t\tgraph_templates_graph.title_cache,\r\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\r\n\t\t\t\t\tgraph_templates_graph.height,\r\n\t\t\t\t\tgraph_local.snmp_index\r\n\t\t\t\t\tFROM (graph_local, graph_templates_graph)\r\n\t\t\t\t\t{$sql_join}\r\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\t\tAND graph_local.snmp_query_id=" . $data_query["id"] . "\r\n\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t\t" . (empty($data_query_index) ? "" : "and graph_local.snmp_index='{$data_query_index}'") . "\r\n\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\tGROUP BY graph_templates_graph.local_graph_id\r\n\t\t\t\t\tORDER BY graph_templates_graph.title_cache"); /* re-key the results on data query index */ 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"]; } } /* 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"]])); } } } } } } } $total_rows = sizeof($graph_list); /* generate page list */ if ($total_rows > get_request_var_request("graphs")) { $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graphs"), $total_rows, "graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "")); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page") - 1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Graphs " . (get_request_var_request("graphs") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_graph_config_option("treeview_graphs_per_page") || $total_rows < get_request_var_request("graphs") * get_request_var_request("page") ? $total_rows : get_request_var_request("graphs") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>"; if (get_request_var_request("page") * get_request_var_request("graphs") < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page") + 1)) . "'>"; } $nav .= "Next"; if (get_request_var_request("page") * get_request_var_request("graphs") < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n"; } else { $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing All Graphs" . (strlen(get_request_var_request("filter")) ? " [ Filter '" . htmlspecialchars(get_request_var_request("filter")) . "' Applied ]" : "") . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n"; } print $nav; /* start graph display */ print "<tr bgcolor='#" . $colors["header_panel"] . "'><td width='390' colspan='11' class='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 ($_SESSION["sess_graph_view_thumbnails"] == "on") { html_graph_thumbnail_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } else { html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } if (!empty($leaf_id)) { api_plugin_hook_function('tree_after', $host_name . ',' . get_request_var("leaf_id")); } api_plugin_hook_function('tree_view_page_end'); print $nav; html_end_box(); }
function device() { global $colors, $item_rows; require(CACTI_BASE_PATH . "/include/device/device_arrays.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("status")); input_validate_input_number(get_request_var_request("rows")); input_validate_input_number(get_request_var_request("poller")); input_validate_input_number(get_request_var_request("site")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_device_current_page"); kill_session_var("sess_device_filter"); if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) { kill_session_var("sess_device_template_id"); } kill_session_var("sess_device_status"); kill_session_var("sess_device_rows"); kill_session_var("sess_device_poller"); kill_session_var("sess_device_site"); kill_session_var("sess_device_sort_column"); kill_session_var("sess_device_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) { unset($_REQUEST["template_id"]); } unset($_REQUEST["status"]); unset($_REQUEST["poller"]); unset($_REQUEST["site"]); unset($_REQUEST["rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* let's see if someone changed an important setting */ $changed = FALSE; $changed += check_changed("filter", "sess_device_filter"); $changed += check_changed("template_id", "sess_device_template_id"); $changed += check_changed("status", "sess_device_status"); $changed += check_changed("rows", "sess_device_rows"); $changed += check_changed("poller", "sess_device_poller"); $changed += check_changed("site", "sess_device_site"); $changed += check_changed("device_id", "sess_ds_device_id"); if ($changed) { $_REQUEST["page"] = "1"; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_device_current_page", "1"); load_current_session_value("filter", "sess_device_filter", ""); load_current_session_value("template_id", "sess_device_template_id", "-1"); load_current_session_value("status", "sess_device_status", "-1"); load_current_session_value("rows", "sess_device_rows", "-1"); load_current_session_value("poller", "sess_device_poller", "-1"); load_current_session_value("site", "sess_device_site", "-1"); load_current_session_value("sort_column", "sess_device_sort_column", "description"); load_current_session_value("sort_direction", "sess_device_sort_direction", "ASC"); ?> <script type="text/javascript"> <!-- function clearDeviceFilterChange(objForm) { <?php print (isset($_REQUEST["tab"]) ? "strURL = '?template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "&action=edit&action=edit&tab=" . $_REQUEST["tab"] . "';" : "strURL = '?template_id=-1';");?> strURL = strURL + '&filter='; strURL = strURL + '&rows=-1'; document.location = strURL; } function applyDeviceFilterChange(objForm) { if (objForm.template_id.value) { strURL = '?template_id=' + objForm.template_id.value; strURL = strURL + '&filter=' + objForm.filter.value; }else{ strURL = '?filter=' + objForm.filter.value; } strURL = strURL + '&status=' + objForm.status.value; strURL = strURL + '&rows=' + objForm.rows.value; strURL = strURL + '&poller=' + objForm.poller.value; strURL = strURL + '&site=' + objForm.site.value; <?php print (isset($_REQUEST["tab"]) ? "strURL = strURL + '&id=' + objForm.template_id.value + '&action=edit&action=edit&tab=" . $_REQUEST["tab"] . "';" : "");?> document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("Devices") . "</strong>", "100", $colors["header"], "3", "center", "devices.php?action=edit&template_id=" . $_REQUEST["template_id"] . "&status=" . $_REQUEST["status"], true); ?> <tr class='rowAlternate2'> <td> <form action="devices.php" name="form_devices" method="post"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Type:");?> </td> <td class="w1"> <select name="template_id" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>><?php print __("None");?></option> <?php $device_templates = db_fetch_assoc("select id,name from device_template order by name"); if (sizeof($device_templates) > 0) { foreach ($device_templates as $device_template) { print "<option value='" . $device_template["id"] . "'"; if (get_request_var_request("template_id") == $device_template["id"]) { print " selected"; } print ">" . $device_template["name"] . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Status:");?> </td> <td class="w1"> <select name="status" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("status") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="-3"<?php if (get_request_var_request("status") == "-3") {?> selected<?php }?>><?php print __("Enabled");?></option> <option value="-2"<?php if (get_request_var_request("status") == "-2") {?> selected<?php }?>><?php print __("Disabled");?></option> <option value="-4"<?php if (get_request_var_request("status") == "-4") {?> selected<?php }?>><?php print __("Not Up");?></option> <option value="3"<?php if (get_request_var_request("status") == "3") {?> selected<?php }?>><?php print __("Up");?></option> <option value="1"<?php if (get_request_var_request("status") == "1") {?> selected<?php }?>><?php print __("Down");?></option> <option value="2"<?php if (get_request_var_request("status") == "2") {?> selected<?php }?>><?php print __("Recovering");?></option> <option value="0"<?php if (get_request_var_request("status") == "0") {?> selected<?php }?>><?php print __("Unknown");?></option> </select> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td class="w1"> <select name="rows" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>><?php print __("Default");?></option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Site:");?> </td> <td class="w1"> <select name="site" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("site") == "-1") {?> selected<?php }?>><?php print __("All");?></option> <option value="0"<?php if (get_request_var_request("site") == "0") {?> selected<?php }?>><?php print __("Not Defined");?></option> <?php $sites = db_fetch_assoc("select id,name from sites order by name"); if (sizeof($sites)) { foreach ($sites as $site) { print "<option value='" . $site["id"] . "'"; if (get_request_var_request("site") == $site["id"]) { print " selected"; } print ">" . $site["name"] . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Poller:");?> </td> <td class="w1"> <select name="poller" onChange="applyDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("poller") == "-1") {?> selected<?php }?>><?php print __("All");?></option> <option value="0"<?php if (get_request_var_request("poller") == "0") {?> selected<?php }?>><?php print __("System Default");?></option> <?php $pollers = db_fetch_assoc("select id,description AS name from poller order by description"); if (sizeof($pollers)) { foreach ($pollers as $poller) { print "<option value='" . $poller["id"] . "'"; if (get_request_var_request("poller") == $poller["id"]) { print " selected"; } print ">" . $poller["name"] . "</option>\n"; } } ?> </select> </td> <td class="nw50"> <?php print __("Search:");?> </td> <td class="w1"> <input type="text" name="filter" size="20" value="<?php print $_REQUEST["filter"];?>"> </td> <td class="nw120"> <input type="submit" Value="<?php print __("Go");?>" name="go" align="middle"> <input type="button" Value="<?php print __("Clear");?>" name="clear_x" align="middle" onClick="clearDeviceFilterChange(document.form_devices)"> </td> </tr> </table> <div><input type='hidden' name='page' value='1'></div> </form> </td> </tr> <?php html_end_box(false); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "where (device.hostname like '%%" . $_REQUEST["filter"] . "%%' OR device.description like '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } if (get_request_var_request("status") == "-1") { /* Show all items */ }elseif (get_request_var_request("status") == "-2") { $sql_where .= (strlen($sql_where) ? " and device.disabled='on'" : "where device.disabled='on'"); }elseif (get_request_var_request("status") == "-3") { $sql_where .= (strlen($sql_where) ? " and device.disabled=''" : "where device.disabled=''"); }elseif (get_request_var_request("status") == "-4") { $sql_where .= (strlen($sql_where) ? " and (device.status!='3' or device.disabled='on')" : "where (device.status!='3' or device.disabled='on')"); }else { $sql_where .= (strlen($sql_where) ? " and (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')" : "where (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where .= (strlen($sql_where) ? " and device.device_template_id=0" : "where device.device_template_id=0"); }elseif (!empty($_REQUEST["template_id"])) { $sql_where .= (strlen($sql_where) ? " and device.device_template_id=" . $_REQUEST["template_id"] : "where device.device_template_id=" . $_REQUEST["template_id"]); } if (get_request_var_request("poller") == "-1") { /* Show all items */ }elseif (get_request_var_request("poller") == "0") { $sql_where .= (strlen($sql_where) ? " and device.poller_id=0" : "where device.poller_id=0"); }elseif (!empty($_REQUEST["poller"])) { $sql_where .= (strlen($sql_where) ? " and device.poller_id=" . $_REQUEST["poller"] : "where device.poller_id=" . $_REQUEST["poller"]); } if (get_request_var_request("site") == "-1") { /* Show all items */ }elseif (get_request_var_request("site") == "0") { $sql_where .= (strlen($sql_where) ? " and device.site_id=0" : "where device.site_id=0"); }elseif (!empty($_REQUEST["site"])) { $sql_where .= (strlen($sql_where) ? " and device.site_id=" . $_REQUEST["site"] : "where device.site_id=" . $_REQUEST["site"]); } html_start_box("", "100", $colors["header"], "0", "center", ""); $total_rows = db_fetch_cell("select COUNT(device.id) from device $sql_where"); if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_device"); }else{ $rows = get_request_var_request("rows"); } $sortby = $_REQUEST["sort_column"]; if ($sortby=="hostname") { $sortby = "INET_ATON(hostname)"; } $device_graphs = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as graphs FROM graph_local GROUP BY device_id"), "device_id", "graphs"); $device_data_sources = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as data_sources FROM data_local GROUP BY device_id"), "device_id", "data_sources"); $sql_query = "SELECT device.*, poller.description AS poller, sites.name AS site FROM device LEFT JOIN poller ON device.poller_id=poller.id LEFT JOIN sites ON device.site_id=sites.id $sql_where ORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows; //print $sql_query; $devices = db_fetch_assoc($sql_query); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 13, "devices.php"); print $nav; html_end_box(false); $display_text = array( "description" => array(__("Description"), "ASC"), "device.hostname" => array(__("Hostname"), "ASC"), "id" => array(__("ID"), "ASC"), "nosort1" => array(__("Graphs"), "ASC"), "nosort2" => array(__("Data Sources"), "ASC"), "status" => array(__("Status"), "ASC"), "status_event_count" => array(__("Event Count"), "ASC"), "cur_time" => array(__("Current (ms)"), "DESC"), "avg_time" => array(__("Average (ms)"), "DESC"), "availability" => array(__("Availability"), "ASC"), "polling_time" => array(__("Poll Time"), "DESC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($devices) > 0) { foreach ($devices as $device) { $spanextra = ""; if($device["disabled"] != CHECKED && $device["status"] == DEVICE_DOWN) { $date = __date("D, " . date_time_format() . " T", strtotime($device['status_fail_date'])); $spanextra = 'title="' . __("Down since %s with error: '%s'", $date, $device['status_last_error']) . '"'; } form_alternate_row_color('line' . $device["id"], true); form_selectable_cell("<a style='white-space:nowrap;' class='linkEditMain' href='" . htmlspecialchars("devices.php?action=edit&id=" . $device["id"]) . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["description"]) : $device["description"]) . "</a>", $device["id"]); form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["hostname"]) : $device["hostname"]), $device["id"]); form_selectable_cell(round(($device["id"]), 2), $device["id"]); form_selectable_cell((isset($device_graphs[$device["id"]]) ? $device_graphs[$device["id"]] : 0), $device["id"]); form_selectable_cell((isset($device_data_sources[$device["id"]]) ? $device_data_sources[$device["id"]] : 0), $device["id"]); form_selectable_cell( "<span $spanextra>".get_colored_device_status(($device["disabled"] == CHECKED ? true : false), $device["status"]) . "</span>", $device["id"]); form_selectable_cell(round(($device["status_event_count"]), 2), $device["id"]); form_selectable_cell(round(($device["cur_time"]), 2), $device["id"]); form_selectable_cell(round(($device["avg_time"]), 2), $device["id"]); form_selectable_cell(round($device["availability"], 2), $device["id"]); form_selectable_cell(round($device["polling_time"], 2), $device["id"]); form_checkbox_cell($device["description"], $device["id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Hosts") . "</em></td></tr>"; } print "</table>\n"; /* add a list of tree names to the actions dropdown */ $device_actions = array_merge($device_actions, api_tree_add_tree_names_to_actions_array()); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "</form>\n"; }
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) { global $current_user, $colors, $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"] . "/tree.php"); include_once($config["library_path"] . "/html_utility.php"); define("MAX_DISPLAY_PAGES", 21); if (empty($tree_id)) { return; } $sql_where = ""; $sql_join = ""; $title = ""; $title_delimeter = ""; $search_key = ""; $leaf = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type FROM graph_tree_items WHERE id=$leaf_id"); $leaf_type = get_tree_item_type($leaf_id); /* get the "starting leaf" if the user clicked on a specific branch */ if (!empty($leaf_id)) { $search_key = substr($leaf["order_key"], 0, (tree_tier($leaf["order_key"]) * CHARS_PER_TIER)); } /* graph permissions */ if (read_config_option("auth_method") != 0) { /* get policy information for the sql where clause */ $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $sql_where = (empty($sql_where) ? "" : "AND $sql_where"); $sql_join = " LEFT JOIN host ON (host.id=graph_local.host_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_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> $tree_name"; $title_delimeter = "-> "; } if (!empty($leaf_name)) { $title .= $title_delimeter . "<strong>Leaf:</strong> $leaf_name"; $title_delimeter = "-> "; } if (!empty($host_name)) { $title .= $title_delimeter . "<strong>Host:</strong> $host_name"; $title_delimeter = "-> "; } if (!empty($host_group_data_name)) { $title .= $title_delimeter . " $host_group_data_name"; $title_delimeter = "-> "; } if (isset($_REQUEST["tree_id"])) { $nodeid = "tree_" . get_request_var_request("tree_id"); } if (isset($_REQUEST["leaf_id"])) { $nodeid .= "_leaf_" . get_request_var_request("leaf_id"); } if (isset($_REQUEST["host_group_data"])) { $type_id = explode(":", get_request_var_request("host_group_data")); if ($type_id[0] == "graph_template") { $nodeid .= "_hgd_gt_" . $type_id[1]; }elseif ($type_id[0] == "data_query") { $nodeid .= "_hgd_dq_" . $type_id[1]; }else{ $nodeid .= "_hgd_dqi" . $type_id[1] . "_" . $type_id[2]; } } print "<script type=\"text/javascript\">\n"; print "<!--\n"; print "myNode = findObj(\"$nodeid\")\n"; print "myNode.forceOpeningOfAncestorFolders();\n"; print "highlightObjLink(myNode)\n"; print "//-->\n"; print "</script>"; print "<table width='100%' align='center' cellpadding='3'>"; /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("graphs")); input_validate_input_number(get_request_var_post("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var_post("filter")); } /* clean up search string */ if (isset($_REQUEST["thumbnails"])) { $_REQUEST["thumbnails"] = sanitize_search_string(get_request_var_post("thumbnails")); } /* if the user pushed the 'clear' button */ if (isset($_POST["clear_x"])) { kill_session_var("sess_graph_view_graphs"); kill_session_var("sess_graph_view_filter"); kill_session_var("sess_graph_view_thumbnails"); kill_session_var("sess_graph_view_page"); unset($_POST["graphs"]); unset($_REQUEST["graphs"]); unset($_POST["filter"]); unset($_REQUEST["filter"]); unset($_REQUEST["page"]); unset($_POST["thumbnails"]); unset($_REQUEST["thumbnails"]); $changed = true; }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("graphs", "sess_graph_view_graphs"); $changed += check_changed("filter", "sess_graph_view_filter"); $changed += check_changed("action", "sess_graph_view_action"); } if (isset($_SESSION["sess_graph_view_tree_id"])) { if ($_SESSION["sess_graph_view_tree_id"] != $tree_id) { $changed += 1; } } $_SESSION["sess_graph_view_tree_id"] = $tree_id; if (isset($_SESSION["sess_graph_view_leaf_id"])) { if ($_SESSION["sess_graph_view_leaf_id"] != $leaf_id) { $changed += 1; } } $_SESSION["sess_graph_view_leaf_id"] = $leaf_id; if (isset($_SESSION["sess_graph_view_host_group_data"])) { if ($_SESSION["sess_graph_view_host_group_data"] != $host_group_data) { $changed += 1; } } $_SESSION["sess_graph_view_host_group_data"] = $host_group_data; if ($changed) { $_REQUEST["page"] = 1; } load_current_session_value("page", "sess_graph_view_page", "1"); load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("treeview_graphs_per_page")); load_current_session_value("filter", "sess_graph_view_filter", ""); if (isset($_SESSION["sess_graph_view_thumbnails"])) { if ($_SESSION["sess_graph_view_thumbnails"] == "on") { if (isset($_POST["filter"])) { if (!isset($_POST["thumbnails"])) { $_SESSION["sess_graph_view_thumbnails"] = 'off'; } } }else{ if (isset($_POST["thumbnails"])) { $_SESSION["sess_graph_view_thumbnails"] = 'on'; } } }else{ $_SESSION["sess_graph_view_thumbnails"] = read_graph_config_option("thumbnail_section_tree_2"); if ($_SESSION["sess_graph_view_thumbnails"] == '') { $_SESSION["sess_graph_view_thumbnails"] = 'off'; }else{ $_SESSION["sess_graph_view_thumbnails"] = 'on'; } } html_graph_start_box(1, false); /* include time span selector */ if (read_graph_config_option("timespan_sel") == "on") { ?> <script type='text/javascript'> // Initialize the calendar calendar=null; // This function displays the calendar associated to the input field 'id' function showCalendar(id) { var el = document.getElementById(id); if (calendar != null) { // we already have some calendar created calendar.hide(); // so we hide it first. } else { // first-time call, create the calendar. var cal = new Calendar(true, null, selected, closeHandler); cal.weekNumbers = false; // Do not display the week number cal.showsTime = true; // Display the time cal.time24 = true; // Hours have a 24 hours format cal.showsOtherMonths = false; // Just the current month is displayed calendar = cal; // remember it in the global var cal.setRange(1900, 2070); // min/max year allowed. cal.create(); } calendar.setDateFormat('%Y-%m-%d %H:%M'); // set the specified date format calendar.parseDate(el.value); // try to parse the text in field calendar.sel = el; // inform it what input field we use // Display the calendar below the input field calendar.showAtElement(el, "Br"); // show the calendar return false; } // This function update the date in the input field when selected function selected(cal, date) { cal.sel.value = date; // just update the date in the input field. } // This function gets called when the end-user clicks on the 'Close' button. // It just hides the calendar without destroying it. function closeHandler(cal) { cal.hide(); // hide the calendar calendar = null; } </script> <script type="text/javascript"> <!-- function applyTimespanFilterChange(objForm) { strURL = '?predefined_timespan=' + objForm.predefined_timespan.value; strURL = strURL + '&predefined_timeshift=' + objForm.predefined_timeshift.value; document.location = strURL; } --> </script> <tr bgcolor="<?php print $colors["panel"];?>" class="noprint"> <form name="form_timespan_selector" method="post"> <td class="noprint"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width='55'> <strong>Presets:</strong> </td> <td nowrap style='white-space: nowrap;' width='130'> <select name='predefined_timespan' onChange="applyTimespanFilterChange(document.form_timespan_selector)"> <?php if ($_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 nowrap style='white-space: nowrap;' width='30'> <strong>From:</strong> </td> <td width='150' nowrap style='white-space: nowrap;'> <input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='14' value='<?php print (isset($_SESSION["sess_current_date1"]) ? $_SESSION["sess_current_date1"] : "");?>'> <input style='padding-bottom: 4px;' type='image' src='images/calendar.gif' alt='Start date selector' title='Start date selector' border='0' align='absmiddle' onclick="return showCalendar('date1');"> </td> <td nowrap style='white-space: nowrap;' width='20'> <strong>To:</strong> </td> <td width='150' nowrap style='white-space: nowrap;'> <input type='text' name='date2' id='date2' title='Graph End Timestamp' size='14' value='<?php print (isset($_SESSION["sess_current_date2"]) ? $_SESSION["sess_current_date2"] : "");?>'> <input style='padding-bottom: 4px;' type='image' src='images/calendar.gif' alt='End date selector' title='End date selector' border='0' align='absmiddle' onclick="return showCalendar('date2');"> </td> <td width='130' nowrap style='white-space: nowrap;'> <input style='padding-bottom: 4px;' type='image' name='move_left' src='images/move_left.gif' alt='Left' border='0' align='absmiddle' title='Shift Left'> <select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.form_timespan_selector)"> <?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> <input style='padding-bottom: 4px;' type='image' name='move_right' src='images/move_right.gif' alt='Right' border='0' align='absmiddle' title='Shift Right'> </td> <td nowrap style='white-space: nowrap;'> <input type='image' name='button_refresh' src='images/button_refresh.gif' alt='Refresh selected time span' border='0' align='absmiddle' value='refresh'> <input type='image' name='button_clear' src='images/button_clear.gif' alt='Return to the default time span' border='0' align='absmiddle'> </td> </tr> </table> </td> </form> </tr> <?php } ?> <tr class="noprint" bgcolor="#e5e5e5"> <form name="form_graph_view" method="post"> <td class="noprint"> <table cellspacing="0" cellpadding="0"> <tr> <td width="55" nowrap="" style="white-space: nowrap;"> <strong> Search:</strong> </td> <td width="130" nowrap="" style="white-space: nowrap;"> <input size='30' width='100' name='filter' value='<?php print clean_html_output(get_request_var_request("filter"));?>'> </td> <td nowrap style='white-space:nowrap;' width="110"> <strong>Graphs per Page:</strong> </td> <td width="1"> <select name="graphs" id="graphs" onChange="submit()"> <?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 width="40"> <label for="thumbnails"><strong> Thumbnails: <strong></label> </td> <td> <input type="checkbox" name="thumbnails" onClick="submit()" <?php print (($_SESSION['sess_graph_view_thumbnails'] == "on") ? "checked":"");?>> </td> <td style='white-space:nowrap;' nowrap> <input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> </table> </td> </form> </tr> <?php html_graph_end_box(FALSE); html_graph_start_box(3, TRUE); $graph_list = array(); if (($leaf_type == "header") || (empty($leaf_id))) { if (strlen(get_request_var_request("filter"))) { $sql_where = (empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%' OR graph_templates_graph.title LIKE '%" . get_request_var_request("filter") . "%')"); } $graph_list = db_fetch_assoc("SELECT graph_tree_items.id, graph_tree_items.title, graph_tree_items.local_graph_id, graph_tree_items.rra_id, graph_tree_items.order_key, graph_templates_graph.title_cache as title_cache FROM (graph_tree_items,graph_local) LEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0) $sql_join WHERE graph_tree_items.graph_tree_id=$tree_id AND graph_local.id=graph_templates_graph.local_graph_id AND graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "' AND graph_tree_items.local_graph_id>0 $sql_where GROUP BY graph_tree_items.id ORDER BY graph_tree_items.order_key"); }elseif ($leaf_type == "host") { /* graph template grouping */ if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) { $graph_templates = db_fetch_assoc("SELECT graph_templates.id, graph_templates.name FROM (graph_local,graph_templates,graph_templates_graph) WHERE graph_local.id=graph_templates_graph.local_graph_id AND graph_templates_graph.graph_template_id=graph_templates.id AND graph_local.host_id=" . $leaf["host_id"] . " " . (empty($graph_template_id) ? "" : "AND graph_templates.id=$graph_template_id") . " GROUP BY graph_templates.id ORDER BY graph_templates.name"); /* 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) { if (strlen(get_request_var_request("filter"))) { $sql_where = (empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')"); } $graphs = db_fetch_assoc("SELECT graph_templates_graph.title_cache, graph_templates_graph.local_graph_id FROM (graph_local,graph_templates_graph) $sql_join WHERE graph_local.id=graph_templates_graph.local_graph_id AND graph_local.graph_template_id=" . $graph_template["id"] . " AND graph_local.host_id=" . $leaf["host_id"] . " $sql_where ORDER BY graph_templates_graph.title_cache"); /* 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 snmp_query.id, snmp_query.name FROM (graph_local,snmp_query) WHERE graph_local.snmp_query_id=snmp_query.id AND graph_local.host_id=" . $leaf["host_id"] . " " . (!isset($data_query_id) ? "" : "and snmp_query.id=$data_query_id") . " GROUP BY snmp_query.id ORDER BY snmp_query.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) { /* 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 = (empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')"); } /* grab a list of all graphs for this host/data query combination */ $graphs = db_fetch_assoc("SELECT graph_templates_graph.title_cache, graph_templates_graph.local_graph_id, graph_local.snmp_index FROM (graph_local, graph_templates_graph) $sql_join WHERE graph_local.id=graph_templates_graph.local_graph_id AND graph_local.snmp_query_id=" . $data_query["id"] . " AND graph_local.host_id=" . $leaf["host_id"] . " " . (empty($data_query_index) ? "" : "and graph_local.snmp_index='$data_query_index'") . " $sql_where GROUP BY graph_templates_graph.local_graph_id ORDER BY graph_templates_graph.title_cache"); /* re-key the results on data query index */ 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"]; } } /* 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)); } } } } } } } $total_rows = sizeof($graph_list); /* generate page list */ if ($total_rows > get_request_var_request("graphs")) { $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graphs"), $total_rows, "graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "")); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='11'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Graphs " . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_graph_config_option("treeview_graphs_per_page")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if ((get_request_var_request("page") * get_request_var_request("graphs")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("graphs")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; }else{ $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='11'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='center' class='textHeaderDark'> Showing All Graphs" . (strlen(get_request_var_request("filter")) ? " [ Filter '" . clean_html_output(get_request_var_request("filter")) . "' Applied ]" : "") . " </td> </tr> </table> </td> </tr>\n"; } print $nav; /* start graph display */ print "<tr bgcolor='#" . $colors["header_panel"] . "'><td width='390' colspan='10' class='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 ($_SESSION["sess_graph_view_thumbnails"] == "on") { html_graph_thumbnail_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); }else{ html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } print $nav; print "</table>"; }
function xaxis() { global $colors, $xaxis_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_xaxis_current_page"); kill_session_var("sess_xaxis_filter"); kill_session_var("sess_xaxis_rows"); kill_session_var("sess_xaxis_sort_column"); kill_session_var("sess_xaxis_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* let's see if someone changed an important setting */ $changed = FALSE; $changed += check_changed("filter", "sess_xaxis_filter"); $changed += check_changed("rows", "sess_xaxis_rows"); if ($changed) { $_REQUEST["page"] = "1"; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_xaxis_current_page", "1"); load_current_session_value("filter", "sess_xaxis_filter", ""); load_current_session_value("rows", "sess_xaxis_rows", "-1"); load_current_session_value("sort_column", "sess_xaxis_sort_column", "name"); load_current_session_value("sort_direction", "sess_xaxis_sort_direction", "ASC"); ?> <script type="text/javascript"> <!-- function applyFilterChange(objForm) { strURL = '?rows=' + objForm.rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("X-Axis Presets") . "</strong>", "100", $colors["header"], "3", "center", "xaxis_presets.php?action=edit", true); ?> <tr class='rowAlternate2'> <td> <form action="xaxis_presets.php" name="form_xaxis" method="post"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Search:");?> </td> <td class="w1"><input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>"></td> <td class="nw50"> <?php print __("Rows:");?> </td> <td class="w1"><select name="rows" onChange="applyFilterChange(document.form_xaxis)"> <option value="-1" <?php if (get_request_var_request("rows") == "-1") {?> selected <?php }?>>Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select></td> <td class="nw120"> <input type="submit" Value="<?php print __("Go");?>" name="go" align="middle"> <input type="submit" Value="<?php print __("Clear");?>" name="clear_x" align="middle"></td> </tr> </table> <div><input type='hidden' name='page' value='1'></div> </form> </td> </tr> <?php html_end_box(false); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "where (name like '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } html_start_box("", "100", $colors["header"], "0", "center", ""); $total_rows = db_fetch_cell("select COUNT(id) from graph_templates_xaxis $sql_where"); if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_device"); }else{ $rows = get_request_var_request("rows"); } $sql_query = "SELECT * " . "FROM graph_templates_xaxis " . $sql_where . " ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows; //print $sql_query; $xaxis_array = db_fetch_assoc($sql_query); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 2, "xaxis_presets.php"); print $nav; html_end_box(false); $display_text = array( "name" => array(__("Name"), "ASC"), ); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($xaxis_array) > 0) { foreach ($xaxis_array as $xaxis) { form_alternate_row_color('line' . $xaxis["id"], true); form_selectable_cell("<a style='white-space:nowrap;' class='linkEditMain' href='" . htmlspecialchars("xaxis_presets.php?action=edit&id=" . $xaxis["id"]) . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $xaxis["name"]) : $xaxis["name"]) . "</a>", $xaxis["id"]); form_checkbox_cell($xaxis["name"], $xaxis["id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No X-Axis Presets") . "</em></td></tr>"; } print "</table>\n"; /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($xaxis_actions); print "</form>\n"; }
function graphs_new() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_graphs_new_device_id"); } kill_session_var("sess_graphs_new_graph_type"); kill_session_var("sess_graphs_new_filter"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["graph_type"]); unset($_REQUEST["filter"]); $changed = true; }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("device_id", "sess_graphs_new_device_id"); $changed += check_changed("graph_type", "sess_graphs_new_graph_type"); $changed += check_changed("filter", "sess_graphs_new_filter"); } load_current_session_value("device_id", "sess_graphs_new_device_id", db_fetch_cell("select id from device order by description,hostname limit 1")); load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown")); load_current_session_value("filter", "sess_graphs_new_filter", ""); if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { $file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"]; $file2 = "devices.php"; }else{ $file = "graphs_new.php?device_id=". $_REQUEST["device_id"]; $file2 = "graphs_new.php"; } $device = db_fetch_row("select id,description,hostname,device_template_id from device where id=" . $_REQUEST["device_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); ?> <script type="text/javascript"> <!-- function applyGraphsNewFilterChange(objForm) { strURL = '?action=edit&tab=newgraphs'; strURL = strURL + '&graph_type=' + objForm.graph_type.value; strURL = strURL + '&device_id=' + objForm.device_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . $device["description"] . "(" . $device["hostname"] . ")</strong> " . db_fetch_cell("select name from device_template where id=" . $device["device_template_id"]), "100", $colors["header"], "3", "center", ""); ?> <tr class='rowAlternate2'> <td> <form name="form_graphs_new" method="post" action="<?php print $file2;?>"> <table cellpadding="0" align="left"> <tr> <?php if (!isset($_REQUEST["tab"])) { ?> <td class="nw50 textGraphFilter"> Host: </td> <td width="1"> <select name="device_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $devices = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"); if (sizeof($devices) > 0) { foreach ($devices as $item) { print "<option value='" . $item["id"] . "'"; if (get_request_var_request("device_id") == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> <?php } ?> <td class="nw50 textGraphFilter"> <?php print __("Type:");?> </td> <td width="1"> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <option value="-2"<?php if (get_request_var_request("graph_type") == "-2") {?> selected<?php }?>><?php print __("All");?></option> <option value="-1"<?php if (get_request_var_request("graph_type") == "-1") {?> selected<?php }?>><?php print __("Graph Template Based");?></option> <?php $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,device_snmp_query) WHERE device_snmp_query.snmp_query_id=snmp_query.id AND device_snmp_query.device_id=" . $device["id"] . " ORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query["id"] . "'"; if (get_request_var_request("graph_type") == $query["id"]) { print " selected"; } print ">" . $query["name"] . "</option>\n"; } } ?> </select> </td> <td style="white-space:nowrap;width:1%;" class="textInfo" align="center" valign="top"> <?php if (!isset($_REQUEST["tab"])) { ?><span class="tabedit">*</span><a href="devices.php?action=edit&id=<?php print $_REQUEST["device_id"];?>"><?php print __("Edit this Host");?></a><br><?php } ?> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> </table> <?php if (get_request_var_request("graph_type") > 0) {?> <table cellpadding="0" align="left"> <tr> <td class="nw50 textGraphFilter"> Search: </td> <td class="nw200"> <input type="text" name="filter" size="30" width="200" value="<?php print $_REQUEST["filter"];?>"> </td> <td align="left" class="nw120"> <input type="submit" name="go" value="<?php print __("Go");?>" align="middle"> <input type="submit" name="clear_x" value="<?php print __("Clear");?>" align="middle"> <input type="hidden" name="action" value="edit"> <input type="hidden" name="tab" value="newgraphs"> </td> </tr> </table> <?php }else{ form_hidden_box("filter", get_request_var_request("filter"), ""); }?> </form> </td> </tr> <?php html_end_box(false); $total_rows = sizeof(db_fetch_assoc("select graph_template_id from device_graph where device_id=" . $_REQUEST["device_id"])); $i = 0; if (get_request_var_request("graph_type") > 0) { load_current_session_value("page" . get_request_var_request("graph_type"), "sess_graphs_new_page" . get_request_var_request("graph_type"), "1"); }else if (get_request_var_request("graph_type") == -2) { foreach($snmp_queries as $query) { load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } print "<form name='chk' method='post' action='" . $file2 . "'>"; if (get_request_var_request("graph_type") < 0) { $graph_templates = db_fetch_assoc("SELECT graph_templates.id AS graph_template_id, graph_templates.name AS graph_template_name FROM (device_graph,graph_templates) WHERE device_graph.graph_template_id=graph_templates.id AND device_graph.device_id=" . $_REQUEST["device_id"] . " ORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT graph_local.graph_template_id FROM (graph_local,device_graph) WHERE graph_local.graph_template_id=device_graph.graph_template_id AND graph_local.device_id=device_graph.device_id AND graph_local.device_id=" . $device["id"] . " GROUP BY graph_local.graph_template_id"); if (sizeof($template_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</script>\n"; } else { print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; } print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; html_start_box("<strong>" . __("Graph Templates") . "</strong>", "100", $colors["header"], "3", "center", ""); print " <tr class='rowSubHeader'> <td class='textSubHeaderDark'>" . __("Graph Template Name") . "</td> <td class='rowSubHeader' width='1%' align='center' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='" . __("Select All") . "' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n </tr>\n"; /* create a row for each graph template associated with the device template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template["graph_template_id"]; print "<tr id='gt_line$query_row' bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'>"; $i++; print " <td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'><span id='gt_text$query_row" . "_0'> <strong>" . __("Create:") . "</strong> " . $graph_template["graph_template_name"] . "</span> </td> <td align='right'> <input type='checkbox' name='cg_$query_row' id='cg_$query_row' onClick='gt_update_selection_indicators();'> </td> </tr>"; } } $available_graph_templates = db_fetch_assoc("SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id) WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); /* create a row at the bottom that lets the user create any graph they choose */ print " <tr bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'> <td colspan='2' width='60' nowrap> <strong>" . __("Create:") . "</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print " </td> </tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,device_snmp_query) WHERE device_snmp_query.snmp_query_id=snmp_query.id AND device_snmp_query.device_id=" . $device["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . " ORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (isset($_REQUEST["page" . $snmp_query["id"]])) { $page = $_REQUEST["page" . $snmp_query["id"]]; }elseif (!$changed) { $page = $_REQUEST["page" . $snmp_query["id"]]; }else{ $page = 1; } $xml_array = get_data_query_array($snmp_query["id"]); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell("SELECT count(*) FROM device_snmp_cache WHERE device_id=" . $device["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='$field_name'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("SELECT DISTINCT data_local.snmp_index FROM (data_local,data_template_data) LEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id) LEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id) WHERE data_local.id=data_template_data.local_data_id AND data_input_fields.type_code='output_type' AND data_input_data.value='" . $snmp_query_graph["id"] . "' AND data_local.device_id=" . $device["id"]); print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } print ")\n"; } print "//-->\n</script>\n"; } html_start_box_dq($snmp_query["name"], $snmp_query["id"], $device["id"], $num_input_fields+1, "100", $colors["header"], "0", "center"); if ($xml_array != false) { $html_dq_header = ""; $snmp_query_indexes = array(); reset($xml_array["fields"]); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ""; if (strlen(get_request_var_request("filter"))) { $sql_where = ""; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index FROM device_snmp_cache WHERE field_value LIKE '%%" . get_request_var_request("filter") . "%%' AND snmp_query_id=" . $snmp_query["id"] . " AND device_id=" . $device["id"]); if (sizeof($indexes)) { foreach($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index["snmp_index"] . "'"; }else{ $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'"; } } $sql_where .= ")"; } } if ((strlen(get_request_var_request("filter")) == 0) || ((strlen(get_request_var_request("filter"))) && (sizeof($indexes)))) { /* determine the sort order */ if (isset($xml_array["index_order_type"])) { if ($xml_array["index_order_type"] == "numeric") { $sql_order = "ORDER BY CAST(snmp_index AS unsigned)"; }else if ($xml_array["index_order_type"] == "alphabetic") { $sql_order = "ORDER BY snmp_index"; }else if ($xml_array["index_order_type"] == "natural") { $sql_order = "ORDER BY INET_ATON(snmp_index)"; }else{ $sql_order = ""; } }else{ $sql_order = ""; } /* get the unique field values from the database */ $field_names = db_fetch_assoc("SELECT DISTINCT field_name FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"]); /* build magic query */ $sql_query = "SELECT device_id, snmp_query_id, snmp_index"; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach($field_names as $column) { $field_name = $column["field_name"]; $sql_query .= ", MAX(CASE WHEN field_name='$field_name' THEN field_value ELSE NULL END) AS '$field_name'"; $i++; } } $sql_query .= " FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"] . " $sql_where GROUP BY device_id, snmp_query_id, snmp_index $sql_order LIMIT " . ($row_limit*($page-1)) . "," . $row_limit; $rows_query = "SELECT device_id, snmp_query_id, snmp_index FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"] . " $sql_where GROUP BY device_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page-1) * $row_limit > $total_rows) { $page = 1; $_REQUEST["page" . $query["id"]] = $page; load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { $file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"]; $file2 = "devices.php"; }else{ $file = "graphs_new.php?device_id=". $_REQUEST["device_id"]; $file2 = "graphs_new.php"; } if ($total_rows > $row_limit) { /* generate page list navigation */ $nav = html_create_nav($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, 40, $file, "page" . $snmp_query["id"]); print $nav; } while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach($field_names as $row) { if ($row["field_name"] == $field_name) { # $html_dq_header .= "<td height='1' style='padding:0px 5px 0px 5px;' onMousemove='doColResize(this,event)' onMouseover='doColResize(this,event)' onMouseup='doneColResize()'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n"; $html_dq_header .= "<th style='padding:0px 5px 0px 5px;' onMousemove='doColResize(this,event)' onMouseover='doColResize(this,event)' onMouseup='doneColResize()' class='textSubHeaderDark'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></th>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='rowAlternate1'><td>" . __("This data query returned 0 rows, perhaps there was a problem executing this data query. You can %s run this data query in debug mode %s to get more information.", "<a href='" . htmlspecialchars("devices.php?action=query_verbose&id=" . $snmp_query["id"] . "&device_id=" . $device["id"]) . "'>", "</a>") . "</td></tr>\n"; }else{ print "<tr class='rowSubHeader'> $html_dq_header <td class='rowSubHeader' width='1%' align='center' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='" . __("Select All") ."' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n </tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, "field_name", "field_name"); if (sizeof($snmp_query_indexes) > 0) { foreach($snmp_query_indexes as $row) { $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]); form_alternate_row_color("line" . $query_row, true); $column_counter = 0; reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td style='line-height: 1.5em;padding:0px 5px 0px 5px;' onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text$query_row" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; }else{ print "<td style='line-height: 1.5em;padding:0px 5px 0px 5px;' onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text$query_row" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td style='padding-right: 4px;' align='right'>"; print "<input type='checkbox' name='sg_$query_row' id='sg_$query_row' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } }else{ print "<tr class='rowAlternate1'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>" . __("Search Returned no Rows.") . "</td></tr>\n"; } }else{ print "<tr class='rowAlternate1'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>" . __("Error in data query.") . "</td></tr>\n"; } /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { html_end_box(); form_hidden_box("sgg_" . $snmp_query["id"], $data_query_graphs[0]["id"], ""); }elseif (sizeof($data_query_graphs) > 1) { html_end_box(FALSE); print "<table align='center' width='100%'> <tr> <td width='1' valign='top'> <img src='images/arrow.gif' alt='' align='middle'> </td> <td align='right'> <span class=\"italic\">" . __("Select a graph type:") . "</span> <select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . $column_counter . ");'> "; html_create_list($data_query_graphs,"name","id","0"); print " </select> </td> </tr> </table>"; } print "<script type='text/javascript'>dq_update_deps(" . $snmp_query["id"] . "," . ($num_visible_fields) . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("device_id", $device["id"], "0"); form_hidden_box("device_template_id", $device["device_template_id"], "0"); form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "")); if (!empty($debug_log)) { debug_log_clear("new_graphs"); ?> <table class='topBoxAlt'> <tr> <td class='mono'> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function graph() { global $colors, $item_rows; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("rows")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_sort_column"); kill_session_var("sess_graph_sort_direction"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_graph_device_id"); } kill_session_var("sess_graph_rows"); kill_session_var("sess_graph_template_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["rows"]); unset($_REQUEST["template_id"]); } /* let's see if someone changed an important setting */ $changed = FALSE; $changed += check_changed("filter", "sess_ds_filter"); $changed += check_changed("rows", "sess_ds_rows"); $changed += check_changed("device_id", "sess_ds_device_id"); $changed += check_changed("template_id", "sess_ds_template_id"); if ($changed) { $_REQUEST["page"] = "1"; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache"); load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC"); load_current_session_value("device_id", "sess_graph_device_id", "-1"); load_current_session_value("rows", "sess_graph_rows", "-1"); load_current_session_value("template_id", "sess_graph_template_id", "-1"); ?> <script type="text/javascript"> <!-- $().ready(function() { $("#device").autocomplete("./lib/ajax/get_devices_brief.php", { max: 8, highlight: false, scroll: true, scrollHeight: 300 }); $("#device").result(function(event, data, formatted) { if (data) { $(this).parent().find("#device_id").val(data[1]); applyGraphsFilterChange(document.form_graph_id); }else{ $(this).parent().find("#device_id").val(0); } }); }); function clearGraphsFilterChange(objForm) { strURL = '?filter='; <?php # called from outside if (isset($_REQUEST["tab"])) { # print the tab print "strURL = strURL + &tab=" . $_REQUEST["tab"] . "';"; # now look for more parameters if (isset($_REQUEST["device_id"])) { print "strURL = strURL + '&device_id=" . $_REQUEST["device_id"] . "&id=" . $_REQUEST["device_id"] . "';"; } if (isset($_REQUEST["template_id"])) { print "strURL = strURL + '&template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "';"; } }else { # clear all parms print "strURL = strURL + '&device_id=-1';"; print "strURL = strURL + '&template_id=-1';"; } ?> strURL = strURL + '&rows=-1'; document.location = strURL; } function applyGraphsFilterChange(objForm) { strURL = '?filter=' + objForm.filter.value; // take care of parms provided via autocomplete // those are passed as objForm.<parm>.value // instead of $_REQUEST["<parm>"] when called from outside if (objForm.device_id.value) { strURL = '?device_id=' + objForm.device_id.value; }else{ <?php print (isset($_REQUEST["device_id"]) ? "strURL = strURL + '&device_id=" . $_REQUEST["device_id"] . "&id=" . $_REQUEST["device_id"] . "';" : "strURL = strURL + '&device_id=-1';");?> } if (objForm.template_id.value) { strURL = '?template_id=' + objForm.template_id.value; }else{ <?php print (isset($_REQUEST["template_id"]) ? "strURL = strURL + '&template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "';" : "strURL = strURL + '&template_id=-1';");?> } strURL = strURL + '&rows=' + objForm.rows.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . __("Graph Management") . "</strong>", "100", $colors["header"], "3", "center", "graphs.php?action=graph_edit&device_id=" . $_REQUEST["device_id"], true); ?> <tr class='rowAlternate2'> <td> <form name="form_graph_id" action="graphs.php"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Host:");?> </td> <td width="1"> <?php if (isset($_REQUEST["device_id"])) { $hostname = db_fetch_cell("SELECT description as name FROM device WHERE id=".$_REQUEST["device_id"]." ORDER BY description,hostname"); } else { $hostname = ""; } ?> <input class="ac_field" type="text" id="device" size="30" value="<?php print $hostname; ?>"> <input type="hidden" id="device_id"> </td> <td width="70"> <?php print __("Template:");?> </td> <td width="1"> <select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>><?php print __("None");?></option> <?php if (read_config_option("auth_method") != 0) { $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM (graph_templates_graph,graph_local) LEFT JOIN device ON (device.id=graph_local.device_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")) WHERE graph_templates_graph.local_graph_id=graph_local.id AND graph_templates.id IS NOT NULL " . (empty($sql_where) ? "" : "AND $sql_where") . " ORDER BY name"); }else{ $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM graph_templates ORDER BY name"); } if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n"; } } ?> </select> </td> <td class="nw120"> <input type="submit" Value="<?php print __("Go");?>" name="go" align="middle"> <input type="button" Value="<?php print __("Clear");?>" name="clear_x" align="middle" onClick="clearGraphsFilterChange(document.form_graph_id)"> </td> </tr> </table> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Search:");?> </td> <td> <input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>"> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td width="1"> <select name="rows" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>><?php print __("Default");?></option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(false); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "AND (graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where = ""; } if (get_request_var_request("device_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("device_id") == "0") { $sql_where .= " AND graph_local.device_id=0"; }elseif (!empty($_REQUEST["device_id"])) { $sql_where .= " AND graph_local.device_id=" . $_REQUEST["device_id"]; } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where .= " AND graph_templates_graph.graph_template_id=0"; }elseif (!empty($_REQUEST["template_id"])) { $sql_where .= " AND graph_templates_graph.graph_template_id=" . $_REQUEST["template_id"]; } html_start_box("", "100", $colors["header"], "0", "center", ""); if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_graph"); }else{ $rows = get_request_var_request("rows"); } $total_rows = db_fetch_cell("SELECT COUNT(graph_templates_graph.id) FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where"); $graph_list = db_fetch_assoc("SELECT graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.device_id FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where ORDER BY " . get_request_var_request('sort_column') . " " . get_request_var_request('sort_direction') . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 7, "graphs.php"); print $nav; html_end_box(false); $display_text = array( "title_cache" => array(__("Graph Title"), "ASC"), "local_graph_id" => array(__("ID"), "ASC"), "name" => array(__("Template Name"), "ASC"), "height" => array(__("Size"), "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { $template_name = ((empty($graph["name"])) ? "<em>" . __("None") . "</em>" : $graph["name"]); form_alternate_row_color('line' . $graph["local_graph_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . $graph["title_cache"]) . "'>" . (($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($graph["title_cache"], read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]); form_selectable_cell((($_REQUEST["filter"] != "") ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $template_name) : $template_name), $graph["local_graph_id"]); form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]); form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Graphs Found") . "</em></td></tr>"; } print "</table>\n"; # end table of html_header_sort_checkbox /* add a list of tree names to the actions dropdown */ $graph_actions = array_merge(graph_actions_list(), api_tree_add_tree_names_to_actions_array()); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; # end form of html_header_sort_checkbox }
function process_tree_request_vars() { /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('rows')); input_validate_input_number(get_request_var_request('page')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort solumn */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort direction */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* clean up associated */ if (isset($_REQUEST['associated'])) { $_REQUEST['associated'] = sanitize_search_string(get_request_var_request('associated')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clearf'])) { kill_session_var('sess_uatr_page'); kill_session_var('sess_default_rows'); kill_session_var('sess_uatr_filter'); kill_session_var('sess_uatr_associated'); kill_session_var('sess_uatr_sort_column'); kill_session_var('sess_uatr_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['rows']); unset($_REQUEST['filter']); unset($_REQUEST['associated']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } else { $changed = 0; $changed += check_changed('rows', 'sess_default_rows'); $changed += check_changed('filter', 'sess_uatr_filter'); $changed += check_changed('associated', 'sess_uatr_associated'); $changed += check_changed('sort_column', 'sess_uatr_sort_column'); $changed += check_changed('sort_direction', 'sess_uatr_sort_direction'); if ($changed) { $_REQUEST['page'] = '1'; } $reset_multi = false; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_uatr_page', '1'); load_current_session_value('filter', 'sess_uatr_filter', ''); load_current_session_value('associated', 'sess_uatr_associated', 'true'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); }
function template() { global $host_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up has_hosts string */ if (isset($_REQUEST['has_hosts'])) { $_REQUEST['has_hosts'] = sanitize_search_string(get_request_var_request('has_hosts')); } /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort_direction string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_host_template_current_page'); kill_session_var('sess_host_template_hosts'); kill_session_var('sess_host_template_filter'); kill_session_var('sess_default_rows'); kill_session_var('sess_host_template_sort_column'); kill_session_var('sess_host_template_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['has_hosts']); unset($_REQUEST['filter']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } else { $changed = 0; $changed += check_changed('has_hosts', 'sess_host_template_has_hosts'); $changed += check_changed('rows', 'sess_default_rows'); $changed += check_changed('filter', 'sess_host_template_filter'); if ($changed) { $_REQUEST['page'] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_host_template_current_page', '1'); load_current_session_value('has_hosts', 'sess_host_template_has_hosts', 'true'); load_current_session_value('filter', 'sess_host_template_filter', ''); load_current_session_value('sort_column', 'sess_host_template_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_host_template_sort_direction', 'ASC'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); display_output_messages(); html_start_box('<strong>Device Templates</strong>', '100%', '', '3', 'center', 'host_templates.php?action=edit'); ?> <tr class='even noprint'> <td> <form id="form_host_template" action="host_templates.php"> <table cellpadding="2" cellspacing="0" border="0"> <tr> <td width="50"> Search </td> <td> <input id='filter' type="text" name="filter" size="25" value="<?php print htmlspecialchars(get_request_var_request('filter')); ?> "> </td> <td style='white-space:nowrap;'> Device Templates </td> <td> <select id='rows' name="rows" onChange="applyFilter()"> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type="checkbox" id='has_hosts' <?php print $_REQUEST['has_hosts'] == 'true' ? 'checked' : ''; ?> > </td> <td> <label for='has_hosts' style='white-space:nowrap;'>Has Devices</label> </td> <td> <input type="button" id='refresh' value="Go" title="Set/Refresh Filters"> </td> <td> <input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> <script type='text/javascript'> function applyFilter() { strURL = 'host_templates.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&has_hosts='+$('#has_hosts').is(':checked')+'&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'host_templates.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh, #has_hosts').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_host_template').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST['filter'])) { $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } /* print checkbox form for validation */ print "<form name='chk' method='post' action='host_templates.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); if ($_REQUEST['has_hosts'] == 'true') { $sql_having = 'HAVING hosts>0'; } else { $sql_having = ''; } $total_rows = db_fetch_cell("SELECT COUNT(rows)\n\t\tFROM (\n\t\t\tSELECT\n\t\t\tCOUNT(host_template.id) AS rows, COUNT(DISTINCT host.id) AS hosts\n\t\t\tFROM host_template\n\t\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t\t{$sql_where}\n\t\t\tGROUP BY host_template.id\n\t\t\t{$sql_having}\n\t\t) AS rs"); $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name, COUNT(DISTINCT host.id) AS hosts\n\t\tFROM host_template\n\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t{$sql_where}\n\t\tGROUP BY host_template.id\n\t\t{$sql_having}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows')); $nav = html_nav_bar('host_templates.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Device Templates', 'page', 'main'); print $nav; $display_text = array('name' => array('display' => 'Device Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Device Template.'), "nosort" => array('display' => 'Deletable', 'align' => 'right', 'sort' => '', 'tip' => 'Device Templates in use can not be Deleted. In use is defined as being referenced by a Device.'), 'hosts' => array('display' => 'Devices Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Devices using this Device Template.'), 'host_template.id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device Template. Useful when performing automation or debugging.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { if ($template['hosts'] > 0) { $disabled = true; } else { $disabled = false; } form_alternate_row('line' . $template['id'], true, $disabled); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host_templates.php?action=edit&id=' . $template['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($template['name'])) : htmlspecialchars($template['name'])) . '</a>', $template['id']); form_selectable_cell($disabled ? 'No' : 'Yes', $template['id'], '', 'text-align:right'); form_selectable_cell(number_format($template['hosts']), $template['id'], '', 'text-align:right'); form_selectable_cell($template['id'], $template['id'], '', 'text-align:right'); form_checkbox_cell($template['name'], $template['id'], $disabled); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='4'><em>No Device Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function validate_tree_vars() { /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('graphs')); input_validate_input_number(get_request_var_request('columns')); input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('tree_id')); input_validate_input_number(get_request_var_request('leaf_id')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up search string */ if (isset($_REQUEST['thumbnails'])) { $_REQUEST['thumbnails'] = sanitize_search_string(get_request_var_request('thumbnails')); } /* clean up host_group_data string */ if (isset($_REQUEST['host_group_data'])) { $_REQUEST['host_group_data'] = sanitize_search_string(get_request_var_request('host_group_data')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_graph_tree_graphs'); kill_session_var('sess_graph_tree_columns'); kill_session_var('sess_graph_tree_filter'); kill_session_var('sess_graph_tree_thumbnails'); kill_session_var('sess_graph_tree_page'); unset($_REQUEST['graphs']); unset($_REQUEST['columns']); unset($_REQUEST['filter']); unset($_REQUEST['page']); unset($_REQUEST['thumbnails']); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed('graphs', 'sess_graph_tree_graphs'); $changed += check_changed('columns', 'sess_graph_tree_columns'); $changed += check_changed('filter', 'sess_graph_tree_filter'); } if ($changed) { $_REQUEST['page'] = 1; } load_current_session_value('page', 'sess_graph_tree_page', '1'); load_current_session_value('graphs', 'sess_graph_tree_graphs', '-1'); load_current_session_value('columns', 'sess_graph_tree_columns', read_graph_config_option('num_columns')); load_current_session_value('filter', 'sess_graph_tree_filter', ''); load_current_session_value('thumbnails', 'sess_graph_tree_thumbnails', read_graph_config_option('thumbnail_section_tree_2') == 'on' ? 'true' : 'false'); load_current_session_value('leaf_id', 'sess_graph_tree_leaf_id', ''); load_current_session_value('tree_id', 'sess_graph_tree_tree_id', read_graph_config_option('default_tree_id')); load_current_session_value('nodeid', 'sess_graph_tree_nodeid', ''); load_current_session_value('host_group_data', 'sess_graph_tree_host_group_data', ''); }
function graphs() { global $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('graph_type')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_graphs_new_filter'); kill_session_var('sess_default_rows'); unset($_REQUEST['filter']); unset($_REQUEST['rows']); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed('host_id', 'sess_graphs_new_host_id'); $changed += check_changed('graph_type', 'sess_graphs_new_graph_type'); $changed += check_changed('filter', 'sess_graphs_new_filter'); $changed += check_changed('rows', 'sess_default_rows'); } load_current_session_value('host_id', 'sess_graphs_new_host_id', db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1')); load_current_session_value('graph_type', 'sess_graphs_new_graph_type', read_config_option('default_graphs_new_dropdown')); load_current_session_value('filter', 'sess_graphs_new_filter', ''); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); if (!empty($_REQUEST['host_id'])) { $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id'])); $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]'; } else { $host = array(); $header = 'None Host Type'; } $row_limit = get_request_var_request('rows'); html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', ''); form_alternate_row(); print '<td class="even">'; ?> <script type='text/javascript'> <!-- function applyFilter() { strURL = '?graph_type=' + $('#graph_type').val(); strURL = strURL + '&host_id=' + $('#host_id').val(); strURL = strURL + '&filter=' + $('#filter').val();; strURL = strURL + '&rows=' + $('#rows').val();; document.location = strURL; } --> </script> <form name='form_graphs_new' action='graphs_new.php'> <table width='100%' cellpadding='2' cellspacing='0' border='0' align='left'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td style='white-space:nowrap;' width='1'> Graph Types </td> <td width='1'> <select id='graph_type' name='graph_type' onChange='applyFilter()'> <option value='-2'<?php if ($_REQUEST['graph_type'] == '-2') { ?> selected<?php } ?> >All</option> <option value='-1'<?php if ($_REQUEST['graph_type'] == '-1') { ?> selected<?php } ?> >Graph Template Based</option> <?php $snmp_queries = db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query, host_snmp_query) WHERE host_snmp_query.snmp_query_id = snmp_query.id AND host_snmp_query.host_id = ? ORDER BY snmp_query.name', array($host['id'])); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query['id'] . "'"; if ($_REQUEST['graph_type'] == $query['id']) { print ' selected'; } print '>' . $query['name'] . "</option>\n"; } } ?> </select> </td> <td width='50'> Rows </td> <td> <select id='rows' name='rows' onChange='applyFilter()'> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td rowspan='3' class='textInfo' align='right' valign='top'> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit&id=' . $_REQUEST['host_id']); ?> '>Edit this Device</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit'); ?> '>Create New Device</a><br> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> <tr style='<?php if ($_REQUEST['graph_type'] <= 0) { ?> display:none;<?php } ?> '> <td width='50'> Search </td> <td style='white-space:nowrap;'> <input id='filter' type='text' name='filter' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td colspan='3' style='white-space:nowrap;'> <input type='submit' value='Go' title='Set/Refresh Filters'> <input type='submit' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> </table> </form> </td> </tr> <?php html_end_box(); ?> <form name='chk' method='post' action='graphs_new.php'> <?php $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_REQUEST['host_id']))); $i = 0; if ($changed) { foreach ($snmp_queries as $query) { kill_session_var('sess_graphs_new_page' . $query['id']); unset($_REQUEST['page' . $query['id']]); load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } } if ($_REQUEST['graph_type'] > 0) { load_current_session_value('page' . $_REQUEST['graph_type'], 'sess_graphs_new_page' . $_REQUEST['graph_type'], '1'); } else { if ($_REQUEST['graph_type'] == -2) { foreach ($snmp_queries as $query) { load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } } } $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n"; if ($_REQUEST['graph_type'] < 0) { html_start_box('<strong>Graph Templates</strong>', '100%', '', '3', 'center', ''); print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id AS graph_template_id, graph_templates.name AS graph_template_name FROM (host_graph, graph_templates) WHERE host_graph.graph_template_id = graph_templates.id AND host_graph.host_id = ? ORDER BY graph_templates.name', array($_REQUEST['host_id'])); if (!empty($_REQUEST['host_id'])) { $template_graphs = db_fetch_assoc_prepared('SELECT graph_local.graph_template_id FROM (graph_local, host_graph) WHERE graph_local.graph_template_id = host_graph.graph_template_id AND graph_local.host_id = host_graph.host_id AND graph_local.host_id = ? GROUP BY graph_local.graph_template_id', array($host['id'])); if (sizeof($template_graphs) > 0) { $script .= 'var gt_created_graphs = new Array('; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { $script .= ($cg_ctr > 0 ? ',' : '') . "'" . $template_graph['graph_template_id'] . "'"; $cg_ctr++; } $script .= ")\n"; } } /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template['graph_template_id']; print "<tr id='gt_line{$query_row}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>"; $i++; print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } html_end_box(); html_start_box('', '100%', '', '3', 'center', ''); $available_graph_templates = db_fetch_assoc('SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id) WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name'); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>"; form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea'); print '</td> </tr>'; html_end_box(); } if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) { $snmp_queries = db_fetch_assoc('SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,host_snmp_query) WHERE host_snmp_query.snmp_query_id=snmp_query.id AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . ' ORDER BY snmp_query.name'); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (!$changed) { $page = $_REQUEST['page' . $snmp_query['id']]; } else { $page = 1; } $xml_array = get_data_query_array($snmp_query['id']); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array['fields']); while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input') { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name)); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id'])); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['id'], $host['id'])); $script .= 'created_graphs[' . $snmp_query_graph['id'] . '] = new Array('; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'"; $cg_ctr++; } } $script .= ")\n"; } } print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars('graphs_new.php?action=query_reload&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; if ($xml_array != false) { $html_dq_header = ''; $snmp_query_indexes = array(); reset($xml_array['fields']); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ''; if (strlen($_REQUEST['filter'])) { $sql_where = ''; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\n\t\t\t\t\t\tAND host_id=" . $host['id']); if (sizeof($indexes)) { foreach ($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index['snmp_index'] . "'"; } else { $sql_where .= " AND snmp_index IN('" . $index['snmp_index'] . "'"; } } $sql_where .= ')'; } } if (strlen($_REQUEST['filter']) == 0 || strlen($_REQUEST['filter']) && sizeof($indexes)) { /* determine the sort order */ if (isset($xml_array['index_order_type'])) { if ($xml_array['index_order_type'] == 'numeric') { $sql_order = 'ORDER BY CAST(snmp_index AS unsigned)'; } else { if ($xml_array['index_order_type'] == 'alphabetic') { $sql_order = 'ORDER BY snmp_index'; } else { if ($xml_array['index_order_type'] == 'natural') { $sql_order = 'ORDER BY INET_ATON(snmp_index)'; } else { $sql_order = ''; } } } } else { $sql_order = ''; } /* get the unique field values from the database */ $field_names = db_fetch_assoc_prepared('SELECT DISTINCT field_name FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array($host['id'], $snmp_query['id'])); /* build magic query */ $sql_query = 'SELECT host_id, snmp_query_id, snmp_index'; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach ($field_names as $column) { $field_name = $column['field_name']; $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'"; $i++; } } $sql_query .= ' FROM host_snmp_cache WHERE host_id=' . $host['id'] . ' AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit; $rows_query = 'SELECT host_id, snmp_query_id, snmp_index FROM host_snmp_cache WHERE host_id=' . $host['id'] . ' AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page - 1) * $row_limit > $total_rows) { $page = 1; $_REQUEST['page' . $query['id']] = $page; load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']); print $nav; while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input' && sizeof($field_names)) { foreach ($field_names as $row) { if ($row['field_name'] == $field_name) { $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tData Query. You can <a href='" . htmlspecialchars('host.php?action=query_verbose&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'>run this Data Query in debug mode</a> to get more information.</td></tr>\n"; } else { print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query['id'] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query['id'] . "\",this.checked)'></td>\n\n\t\t\t\t\t\t\t</tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, 'field_name', 'field_name'); if (sizeof($snmp_query_indexes) > 0) { foreach ($snmp_query_indexes as $row) { $query_row = $snmp_query['id'] . '_' . encode_data_query_index($row['snmp_index']); print "<tr id='line{$query_row}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>"; $i++; $column_counter = 0; reset($xml_array['fields']); while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input') { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>'; } else { print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td class='checkbox' align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>"; print '</td>'; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n"; } print '</table>'; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id'])); if (sizeof($data_query_graphs) == 1) { echo "<input type='hidden' id='sgg_" . $snmp_query['id'] . "' name='sgg_" . $snmp_query['id'] . "' value='" . $data_query_graphs[0]['id'] . "'>\n"; } elseif (sizeof($data_query_graphs) > 1) { print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t"; html_create_list($data_query_graphs, 'name', 'id', '0'); print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n"; } print '<br>'; $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n"; } } } if (strlen($script)) { $script .= "</script>\n"; print $script; } form_hidden_box('save_component_graph', '1', ''); if (!empty($_REQUEST['host_id'])) { form_hidden_box('host_id', $host['id'], '0'); form_hidden_box('host_template_id', $host['host_template_id'], '0'); } if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) { $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']); } load_current_session_value('returnto', 'sess_graphs_new_returnto', ''); form_save_button($_REQUEST['returnto']); }
function get_graph_tree_content($tree_id, $leaf_id, $device_group_data) { global $current_user, $colors, $config, $graphs_per_page; include(CACTI_BASE_PATH . "/include/global_arrays.php"); require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php"); include_once(CACTI_BASE_PATH . "/lib/data_query.php"); include_once(CACTI_BASE_PATH . "/lib/tree.php"); include_once(CACTI_BASE_PATH . "/lib/html_utility.php"); include_once(CACTI_BASE_PATH . "/lib/graph/graph_view_form.php"); define("MAX_DISPLAY_PAGES", 21); if (empty($tree_id)) { return; } $sql_where = ""; $sql_join = ""; $title = ""; $title_delimeter = ""; $search_key = ""; $leaf = db_fetch_row("SELECT order_key, title, device_id, device_grouping_type FROM graph_tree_items WHERE id=$leaf_id"); $leaf_type = get_tree_item_type($leaf_id); /* get the "starting leaf" if the user clicked on a specific branch */ if (!empty($leaf_id)) { $search_key = substr($leaf["order_key"], 0, (tree_tier($leaf["order_key"]) * CHARS_PER_TIER)); } /* graph permissions */ if (read_config_option("auth_method") != 0) { /* get policy information for the sql where clause */ $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_devices"], $current_user["policy_graph_templates"]); $sql_where = (empty($sql_where) ? "" : "AND $sql_where"); $sql_join = " LEFT JOIN device ON (device.id=graph_local.device_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_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)) { $device_name = db_fetch_cell("SELECT device.description FROM (graph_tree_items,device) WHERE graph_tree_items.device_id=device.id AND graph_tree_items.id=$leaf_id"); } $device_group_data_array = $device_group_data; if ($device_group_data_array[0] == "gt") { $device_group_data_name = "Graph Template: " . db_fetch_cell("select name from graph_templates where id=" . $device_group_data_array[1]); $graph_template_id = $device_group_data_array[1]; }elseif ($device_group_data_array[0] == "dq") { $device_group_data_name = "Graph Template: " . (empty($device_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $device_group_data_array[1])); $data_query_id = $device_group_data_array[1]; }elseif ($device_group_data_array[0] == "dqi") { $device_group_data_name = "Graph Template: " . (empty($device_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $device_group_data_array[1])) . "-> " . (empty($device_group_data_array[2]) ? "Template Based" : get_formatted_data_query_index($leaf["device_id"], $device_group_data_array[1], $device_group_data_array[2])); $data_query_id = $device_group_data_array[1]; $data_query_index = $device_group_data_array[2]; } if (!empty($tree_name)) { $title .= $title_delimeter . "<strong>Tree:</strong> $tree_name"; $title_delimeter = "-> "; } if (!empty($leaf_name)) { $title .= $title_delimeter . "<strong.Leaf:</strong> $leaf_name"; $title_delimeter = "-> "; } if (!empty($device_name)) { $title .= $title_delimeter . "<strong>Host:</strong> $device_name"; $title_delimeter = "-> "; } if (!empty($device_group_data_name)) { $title .= $title_delimeter . " $device_group_data_name"; $title_delimeter = "-> "; } /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("graphs")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_filter"])) { kill_session_var("sess_graph_view_graphs"); kill_session_var("sess_graph_view_filter"); kill_session_var("sess_graph_view_page"); unset($_REQUEST["graphs"]); unset($_REQUEST["filter"]); unset($_REQUEST["page"]); $changed = true; }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("graphs", "sess_graph_view_graphs"); $changed += check_changed("filter", "sess_graph_view_filter"); $changed += check_changed("action", "sess_graph_view_action"); } if (isset($_SESSION["sess_graph_view_tree_id"])) { if ($_SESSION["sess_graph_view_tree_id"] != $tree_id) { $changed += 1; } } $_SESSION["sess_graph_view_tree_id"] = $tree_id; if (isset($_SESSION["sess_graph_view_leaf_id"])) { if ($_SESSION["sess_graph_view_leaf_id"] != $leaf_id) { $changed += 1; } } $_SESSION["sess_graph_view_leaf_id"] = $leaf_id; if (isset($_SESSION["sess_graph_view_device_group_data"])) { if ($_SESSION["sess_graph_view_device_group_data"] != $device_group_data) { $changed += 1; } } $_SESSION["sess_graph_view_device_group_data"] = $device_group_data; if ($changed) { $_REQUEST["page"] = 1; } load_current_session_value("page", "sess_graph_view_page", "1"); load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("treeview_graphs_per_page")); load_current_session_value("filter", "sess_graph_view_filter", ""); load_current_session_value("thumbnails", "sess_graph_view_thumbnails", (read_graph_config_option("thumbnail_section_tree_2") == CHECKED ? "true":"")); $graph_list = array(); if (($leaf_type == "header") || (empty($leaf_id))) { if (strlen(get_request_var_request("filter"))) { $sql_where = "AND (title_cache LIKE '%" . $_REQUEST["filter"] . "%' OR graph_templates_graph.title LIKE '%" . $_REQUEST["filter"] . "%')"; } $graph_list = db_fetch_assoc("SELECT graph_tree_items.id, graph_tree_items.title, graph_tree_items.local_graph_id, graph_tree_items.rra_id, graph_tree_items.order_key, graph_templates_graph.height, graph_templates_graph.title_cache as title_cache, graph_templates_graph.image_format_id FROM (graph_tree_items,graph_local) LEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0) $sql_join WHERE graph_tree_items.graph_tree_id=$tree_id AND graph_local.id=graph_templates_graph.local_graph_id AND graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "' AND graph_tree_items.local_graph_id>0 $sql_where GROUP BY graph_tree_items.id ORDER BY graph_tree_items.order_key"); }elseif ($leaf_type == "device") { /* graph template grouping */ if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_GRAPH_TEMPLATE) { $graph_templates = db_fetch_assoc("SELECT graph_templates.id, graph_templates.name FROM (graph_local,graph_templates,graph_templates_graph) WHERE graph_local.id=graph_templates_graph.local_graph_id AND graph_templates_graph.graph_template_id=graph_templates.id AND graph_local.device_id=" . $leaf["device_id"] . " " . (empty($graph_template_id) ? "" : "AND graph_templates.id=$graph_template_id") . " GROUP BY graph_templates.id ORDER BY graph_templates.name"); /* 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) { if (strlen(get_request_var_request("filter"))) { $sql_where = "AND (title_cache LIKE '%" . $_REQUEST["filter"] . "%')"; } $graphs = db_fetch_assoc("SELECT graph_templates_graph.title_cache, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.image_format_id FROM (graph_local,graph_templates_graph) $sql_join WHERE graph_local.id=graph_templates_graph.local_graph_id AND graph_local.graph_template_id=" . $graph_template["id"] . " AND graph_local.device_id=" . $leaf["device_id"] . " $sql_where ORDER BY graph_templates_graph.title_cache"); /* let's sort the graphs naturally */ if (sizeof($graphs)) { usort($graphs, 'naturally_sort_graphs'); foreach ($graphs as $graph) { $graph["graph_template_name"] = $graph_template["name"]; array_push($graph_list, $graph); } } } } /* data query index grouping */ }elseif ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_DATA_QUERY_INDEX) { $data_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name FROM (graph_local,snmp_query) WHERE graph_local.snmp_query_id=snmp_query.id AND graph_local.device_id=" . $leaf["device_id"] . " " . (!isset($data_query_id) ? "" : "and snmp_query.id=$data_query_id") . " GROUP BY snmp_query.id ORDER BY snmp_query.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) { /* fetch a list of field names that are sorted by the preferred sort field */ $sort_field_data = get_formatted_data_query_indexes($leaf["device_id"], $data_query["id"]); if (strlen(get_request_var_request("filter"))) { $sql_where = "AND (title_cache LIKE '%" . $_REQUEST["filter"] . "%')"; } /* grab a list of all graphs for this device/data query combination */ $graphs = db_fetch_assoc("SELECT graph_templates_graph.title_cache, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.image_format_id, graph_local.snmp_index FROM (graph_local, graph_templates_graph) $sql_join WHERE graph_local.id=graph_templates_graph.local_graph_id AND graph_local.snmp_query_id=" . $data_query["id"] . " AND graph_local.device_id=" . $leaf["device_id"] . " " . (empty($data_query_index) ? "" : "and graph_local.snmp_index='$data_query_index'") . " $sql_where GROUP BY graph_templates_graph.local_graph_id ORDER BY graph_templates_graph.title_cache"); /* re-key the results on data query index */ if (sizeof($graphs)) { /* let's sort the graphs naturally */ usort($graphs, 'naturally_sort_graphs'); foreach ($graphs as $graph) { $snmp_index_to_graph{$graph["snmp_index"]} = array( "local_graph_id" => $graph["local_graph_id"], "title_cache" => $graph["title_cache"], "image_format_id" => $graph["image_format_id"], ); $graphs_height[$graph["local_graph_id"]] = $graph["height"]; } } /* 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])) { foreach ($snmp_index_to_graph as $graph) { /* 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" => $graph["local_graph_id"], "title_cache" => $graph["title_cache"], "image_format_id" => $graph["image_format_id"], "height" => $graphs_height[$graph["local_graph_id"]] )); } } } } } } } $total_rows = sizeof($graph_list); if (read_graph_config_option("timespan_sel") == CHECKED) { graph_view_timespan_selector(); } graph_view_search_filter(); ?> <script type='text/javascript'> <!-- function pageChange(page) { strURL = '?action=ajax_tree_graphs&page=' + page; $.get("graph_view.php" + strURL, function (data) { $("#graphs").html(data); }); } --> </script> <?php print "<table cellpadding='0' cellspacing='0' style='width:100%;border:1px solid #BEBEBE;'>\n"; /* generate page list */ if ($total_rows > get_request_var_request("graphs")) { $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["graphs"], $total_rows, "pageChange"); $nav = "\t\t\t<tr class='rowHeader'> <td colspan='11'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' style='width:100px;' class='textHeaderDark'>"; if ($_REQUEST["page"] > 1) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]-1) . ")'><< " . __("Previous") . "</a></strong>"; } $nav .= "</td>\n <td align='center' class='textHeaderDark'> " . __("Showing Graphs") . " " . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " " . __("to") . " " . ((($total_rows < read_graph_config_option("treeview_graphs_per_page")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " " . __("of") . " $total_rows [$url_page_select] </td>\n <td align='right' style='width:100px;' class='textHeaderDark'>"; if (($_REQUEST["page"] * $_REQUEST["graphs"]) < $total_rows) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]+1) . ")'>". __("Next") . " >></a></strong>"; } $nav .= "</td>\n </tr> </table> </td> </tr>\n"; }else{ $nav = "<tr class='rowHeader'> <td colspan='11'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='center' class='textHeaderDark'> " . __("Showing All Graphs") . (strlen(get_request_var_request("filter")) ? " [ " . __("Filter") . " '" . get_request_var_request("filter") . "' ". __("Applied") . " ]" : "") . " </td> </tr> </table> </td> </tr>\n"; } print $nav; /* start graph display */ print "\t\t\t<tr class='rowSubHeaderAlt'><td width='390' colspan='10' class='textHeaderLight'>$title</td></tr>"; $i = $_REQUEST["graphs"] * ($_REQUEST["page"] - 1); $last_graph = $i + $_REQUEST["graphs"]; $new_graph_list = array(); while ($i < $total_rows && $i < $last_graph) { $new_graph_list[] = $graph_list[$i]; $i++; } if (get_request_var_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()); }else{ html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } print $nav; print "</table>\n"; }