Esempio n. 1
0
function graph()
{
    global $colors, $graph_actions;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_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");
        kill_session_var("sess_graph_host_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["host_id"]);
    }
    /* 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("host_id", "sess_graph_host_id", "-1");
    html_start_box("<strong>Graph Management</strong>", "98%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . $_REQUEST["host_id"]);
    include "./include/html/inc_graph_filter_table.php";
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "AND (graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR graph_templates.name like '%%" . $_REQUEST["filter"] . "%%')";
    if ($_REQUEST["host_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_id"] == "0") {
        $sql_where .= " AND graph_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= " AND graph_local.host_id=" . $_REQUEST["host_id"];
    }
    html_start_box("", "98%", $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(graph_templates_graph.id)\n\t\tFROM (graph_local,graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t{$sql_where}");
    $graph_list = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id\n\t\tFROM (graph_local,graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . read_config_option("num_rows_graph") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_graph"));
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_graph"), $total_rows, "graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]);
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='4'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if ($_REQUEST["page"] > 1) {
        $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] - 1) . "'>";
    }
    $nav .= "Previous";
    if ($_REQUEST["page"] > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_graph") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_graph") || $total_rows < read_config_option("num_rows_graph") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_graph") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>";
    if ($_REQUEST["page"] * read_config_option("num_rows_graph") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] + 1) . "'>";
    }
    $nav .= "Next";
    if ($_REQUEST["page"] * read_config_option("num_rows_graph") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n";
    print $nav;
    $display_text = array("title_cache" => array("Graph Title", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC"));
    html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($graph_list) > 0) {
        foreach ($graph_list as $graph) {
            $template_name = empty($graph["name"]) ? "<em>None</em>" : $graph["name"];
            form_alternate_row_color($colors["alternate"], $colors["light"], $i);
            $i++;
            ?>
				<td>
					<a class="linkEditMain" href="graphs.php?action=graph_edit&id=<?php 
            print $graph["local_graph_id"];
            ?>
" title="<?php 
            print htmlspecialchars($graph["title_cache"]);
            ?>
"><?php 
            if ($_REQUEST["filter"] != "") {
                print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph")));
            } else {
                print title_trim($graph["title_cache"], read_config_option("max_title_graph"));
            }
            ?>
</a>
				</td>
				<td>
					<?php 
            if ($_REQUEST["filter"] != "") {
                print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name);
            } else {
                print $template_name;
            }
            ?>
</a>
				</td>
				<td>
					<?php 
            print $graph["height"];
            ?>
x<?php 
            print $graph["width"];
            ?>
				</td>
				<td style="<?php 
            print get_checkbox_style();
            ?>
" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php 
            print $graph["local_graph_id"];
            ?>
' title="<?php 
            print $graph["title_cache"];
            ?>
">
				</td>
			</tr>
			<?php 
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Graphs Found</em></td></tr>";
    }
    html_end_box(false);
    /* add a list of tree names to the actions dropdown */
    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";
}
Esempio n. 2
0
			print "<td><strong><a href='graph.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=all'>" . $graph["title_cache"] . "</a></strong></td>\n";
			print "<td>" . $graph["height"] . "x" . $graph["width"] . "</td>\n";
			print "</tr>";

			$i++;
		}
	}

	?>
	<tr bgcolor='#6d88ad'>
		<td colspan='3'>
			<table width='100%' cellspacing='0' cellpadding='3' border='0'>
				<tr>
					<?php
					print "<td width='1%' align='right' class='textHeaderDark' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAllGraphs(\"graph_\",this.checked)'></td><td bgcolor='#6D88AD'><strong>Select All</strong></td>\n";
					?>
				</tr>
			</table>
		</td>
	</tr>
	</table>
	<table align='center' width='100%'>
		<tr>
			<td width='1'><img src='images/arrow.gif' alt='' align='absmiddle'>&nbsp;</td>
			<td><input type='image' src='images/button_view.gif' alt='View'></td>
		</tr>
	</table>
	<input type='hidden' name='page' value='1'>
	<input type='hidden' name='style' value='selective'>
	<input type='hidden' name='action' value='preview'>
Esempio n. 3
0
function graphs()
{
    global $colors;
    /* use the first host in the list as the default */
    if (!isset($_SESSION["sess_graphs_new_host_id"]) && empty($_REQUEST["host_id"])) {
        $_REQUEST["host_id"] = db_fetch_cell("select id from host order by description,hostname limit 1");
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    if (isset($_REQUEST["host_id"])) {
        $_SESSION["sess_graphs_new_host_id"] = $_REQUEST["host_id"];
    } else {
        $_REQUEST["host_id"] = $_SESSION["sess_graphs_new_host_id"];
    }
    $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);
    ?>

	<table width="98%" align="center">
		<form name="form_graph_id">
		<tr>
			<td class="textInfo" colspan="2">
				<?php 
    print $host["description"];
    ?>
 (<?php 
    print $host["hostname"];
    ?>
)
			</td>
			<td align="right" class="textInfo" 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>
		<tr>
			<td>
			</td>
		</tr>

		<tr>
			<td class="textArea" style="padding: 3px;" width="300" nowrap>
				<?php 
    echo _("Create new graphs for the following host:");
    ?>
			</td>
			<td class="textInfo" rowspan="2" valign="top">
				<span style="color: #c16921;">*</span><a href="devices.php?action=edit&id=<?php 
    print $_REQUEST["host_id"];
    ?>
"><?php 
    echo _("Edit this Host");
    ?>
</a><br>
				<span style="color: #c16921;">*</span><a href="devices.php?action=edit"><?php 
    echo _("Create New Host");
    ?>
</a>
			</td>
		</tr>
			<td>
				<select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value">
					<?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='graphs_new.php?host_id=" . $item["id"] . "'";
            if ($_REQUEST["host_id"] == $item["id"]) {
                print " selected";
            }
            print ">" . $item["name"] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
		</tr>
		</form>
	</table>

	<br>

	<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"]));
    /* we give users the option to turn off the javascript features for data queries with lots of rows */
    if (read_config_option("max_data_query_javascript_rows") >= $total_rows) {
        $use_javascript = true;
    } else {
        $use_javascript = false;
    }
    /* ==================== Box: Graph Templates ==================== */
    html_start_box("<strong>" . _("Graph Templates") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
    print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t<td class='textSubHeaderDark'>" . _("Name") . "</td>\n\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</tr>\n";
    $ht_graph_templates = db_fetch_assoc("select\n\t\tgraph_template.id,\n\t\tgraph_template.template_name\n\t\tfrom host_graph,graph_template\n\t\twhere host_graph.graph_template_id=graph_template.id\n\t\tand host_graph.host_id = " . $_REQUEST["host_id"] . "\n\t\torder by graph_template.template_name");
    $ht_created_graph_templates = db_fetch_assoc("select\n\t\tgraph.graph_template_id\n\t\tfrom graph,host_graph\n\t\twhere graph.graph_template_id=host_graph.graph_template_id\n\t\tand graph.host_id = " . $host["id"] . "\n\t\tgroup by graph.graph_template_id");
    print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n";
    if (sizeof($ht_created_graph_templates) > 0 && $use_javascript == true) {
        print "<script type='text/javascript'>\n<!--\n";
        print "var gt_created_graphs = new Array(";
        $cg_ctr = 0;
        foreach ($ht_created_graph_templates as $item) {
            print ($cg_ctr > 0 ? "," : "") . "'" . $item["graph_template_id"] . "'";
            $cg_ctr++;
        }
        print ")\n";
        print "//-->\n</script>\n";
    }
    /* create a row for each graph template associated with the host template */
    $i = 0;
    if (sizeof($ht_graph_templates) > 0) {
        foreach ($ht_graph_templates as $item) {
            $query_row = $item["id"];
            print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>";
            $i++;
            print "\t\t<td" . ($use_javascript == true ? " onClick='gt_select_line(" . $item["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> " . $item["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}'" . ($use_javascript == true ? " onClick='gt_update_selection_indicators();'" : "") . ">\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "' colspan=7><em>" . _("No graph templates specified for this host template.") . "</em></td></tr>";
    }
    if ($use_javascript == true) {
        print "<script type='text/javascript'>gt_update_deps(1);</script>\n";
    }
    $available_graph_templates = db_fetch_assoc("SELECT\n\t\tgraph_template.id,\n\t\tgraph_template.template_name as name\n\t\tFROM snmp_query_graph RIGHT JOIN graph_template\n\t\tON (snmp_query_graph.graph_template_id = graph_template.id)\n\t\tWHERE (((snmp_query_graph.name) Is Null))\n\t\tORDER BY graph_template.template_name");
    /* create a row at the bottom that lets the user create any graph they choose */
    print "\t<tr bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>\n\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t<strong>Create:</strong>&nbsp;";
    form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(" . _("Select a graph type to create") . ")", "", "font-size: 10px;");
    print "\t\t</td>\n\t\t</tr>";
    html_end_box();
    /* get a list of all data queries that are assigned to this device */
    $data_queries = api_data_query_device_assigned_list($host["id"]);
    echo "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n";
    if (sizeof($data_queries) > 0) {
        foreach ($data_queries as $data_query) {
            /* we give users the option to turn off the javascript features for data queries with lots of rows */
            if (read_config_option("max_data_query_javascript_rows") >= api_data_query_cache_num_rows_get($data_query["id"], $host["id"])) {
                $use_javascript = true;
            } else {
                $use_javascript = false;
            }
            /* get a list of all graph templates that reference this data query */
            $attached_graph_templates = api_data_query_attached_graphs_list($data_query["id"]);
            /* build a javascript array that keeps tracks of which graphs have already been created */
            if (sizeof($attached_graph_templates) > 0 && $use_javascript == true) {
                echo "<script type='text/javascript'>\n<!--\n";
                foreach ($attached_graph_templates as $graph_template) {
                    /* get a list of all data query indexes that have been created as graphs using this graph template */
                    $created_graphs = api_data_query_graphed_indexes_list($graph_template["id"], $host["id"]);
                    echo "created_graphs[" . $graph_template["id"] . "] = new Array(";
                    $cg_ctr = 0;
                    if (sizeof($created_graphs) > 0) {
                        foreach ($created_graphs as $created_graph) {
                            echo ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["data_query_index"]) . "'";
                            $cg_ctr++;
                        }
                    }
                    echo ")\n";
                }
                echo "//-->\n</script>\n";
            }
            $data_query_indexes = array();
            $data_query_field_names = array();
            $data_query_field_desc = array();
            $num_visible_columns = 0;
            $data_query_fields = api_data_query_field_list($data_query["id"], DATA_QUERY_FIELD_TYPE_INPUT);
            /* retrieve a list of values for each data query field from the cache */
            if (sizeof($data_query_fields) > 0) {
                foreach ($data_query_fields as $field) {
                    $cache_data = api_data_query_cache_field_get($data_query["id"], $host["id"], $field["name"]);
                    /* be sure to ignore the fields which contain no data */
                    if (sizeof($cache_data) > 0) {
                        foreach ($cache_data as $row) {
                            $data_query_data[$row["index_value"]][$field["name"]] = $row["field_value"];
                            if (!in_array($row["index_value"], $data_query_indexes, true)) {
                                $data_query_indexes[] = $row["index_value"];
                            }
                        }
                        /* always make sure that the index field is the first column */
                        if ($data_query["index_field_id"] == $field["id"] && sizeof($data_query_field_names) > 0) {
                            $data_query_field_names[] = $data_query_field_names[0];
                            $data_query_field_names[0] = $field["name"];
                        } else {
                            $data_query_field_names[] = $field["name"];
                        }
                        /* keep a hash of field name->desc mappings for the row headings */
                        $data_query_field_desc[$field["name"]] = $field["name_desc"];
                        $num_visible_columns++;
                    }
                }
            }
            /* if the user specified a prefered sort order; sort the list of indexes before displaying them */
            if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_ALPHABETIC) {
                usort($data_query_indexes, "usort_alphabetic");
            } else {
                if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NATURAL) {
                    usort($data_query_indexes, "usort_natural");
                } else {
                    if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NUMERIC) {
                        usort($data_query_indexes, "usort_numeric");
                    }
                }
            }
            ?>
			<table width='98%' style='background-color: #<?php 
            echo $colors["form_alternate2"];
            ?>
; border: 1px solid #<?php 
            echo $colors["header_background"];
            ?>
;' align='center' cellpadding='3' cellspacing='0'>
				<tr>
					<td bgcolor='#<?php 
            echo $colors["header_background"];
            ?>
' colspan='<?php 
            echo sizeof($data_query_field_names) + 1;
            ?>
'>
						<table  cellspacing='0' cellpadding='0' width='100%' >
							<tr>
								<td class='textHeaderDark'>
									<strong><?php 
            echo _("Data Query");
            ?>
</strong> [<?php 
            echo $data_query["name"];
            ?>
]
								</td>
								<td align='right' nowrap>
									<a href='graphs_new.php?action=query_reload&id=<?php 
            echo $data_query["id"];
            ?>
&host_id=<?php 
            echo $host["id"];
            ?>
'><img src='<?php 
            echo html_get_theme_images_path("reload_icon_small.gif");
            ?>
' alt='<?php 
            echo _("Reload Associated Query");
            ?>
' border='0' align='absmiddle'></a>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php 
            if (sizeof($attached_graph_templates) == 0) {
                echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query is not being used by any graph templates. You must create at least one graph template that references to a data template using this data query.") . "</td></tr>\n";
            } else {
                if (sizeof($data_query_field_names) == 0) {
                    echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query returned 0 rows, perhaps there was a problem executing this data query. You can") . " <a href='devices.php?action=query_verbose&id=" . $data_query["id"] . "&host_id=" . $host["id"] . "'>" . _("run this data query in debug mode</a> to get more information.") . "</td></tr>\n";
                } else {
                    echo "<tr bgcolor='#" . $colors["header_panel_background"] . "'>\n";
                    foreach ($data_query_field_names as $field_name) {
                        echo "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $data_query_field_desc[$field_name] . "</font></strong></td>\n";
                    }
                    echo "<td width='1%' align='center' bgcolor='#" . $colors["header_panel_background"] . "' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $data_query["id"] . "' title='Select All' onClick='" . _("SelectAll") . "(\"sg_" . $data_query["id"] . "\",this.checked);" . ($use_javascript == true ? "dq_update_selection_indicators();" : "") . "'></td>\n</tr>\n";
                }
            }
            $row_counter = 0;
            foreach ($data_query_indexes as $index_value) {
                $query_row = $data_query["id"] . "_" . encode_data_query_index($index_value);
                echo "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>";
                $i++;
                $column_counter = 0;
                foreach ($data_query_field_names as $field_name) {
                    echo "<td " . ($use_javascript == true ? "onClick='dq_select_line(" . $data_query["id"] . ",\"" . encode_data_query_index($index_value) . "\");'" : "") . "><span id='text{$query_row}" . "_" . $column_counter . "'>" . (isset($data_query_data[$index_value][$field_name]) ? $data_query_data[$index_value][$field_name] : "") . "</span></td>";
                    $column_counter++;
                }
                echo "<td align='right'>";
                echo "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' " . ($use_javascript == true ? "onClick='dq_update_selection_indicators();'" : "") . ">";
                echo "</td>";
                echo "</tr>\n";
                $row_counter++;
            }
            echo "</table>";
            if (sizeof($attached_graph_templates) == 1) {
                form_hidden_box("sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"], $attached_graph_templates[0]["id"], "");
            } elseif (sizeof($attached_graph_templates) > 1) {
                print "\t<table align='center' width='98%'>\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='" . html_get_theme_images_path("arrow.gif") . "' alt='' align='absmiddle'>&nbsp;\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>&nbsp;\n\t\t\t\t\t\t\t\t<select name='sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"] . "' " . ($use_javascript == true ? "onChange='dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");'" : "") . ">\n\t\t\t\t\t\t\t\t\t";
                html_create_list($attached_graph_templates, "template_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>";
            if ($use_javascript == true) {
                print "<script type='text/javascript'>dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");</script>\n";
            }
        }
    }
    form_hidden_box("save_component_graph", "1", "");
    form_hidden_box("host_id", $host["id"], "0");
    form_save_button("graphs_new.php");
    print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n";
    print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n";
}
Esempio n. 4
0
function html_header_checkbox($header_items, $form_action = "") {
	global $colors;

	/* default to the 'current' file */
	if ($form_action == "") { $form_action = basename($_SERVER["PHP_SELF"]); }

	print "<tr bgcolor='#" . $colors["header_panel"] . "'>\n";

	for ($i=0; $i<count($header_items); $i++) {
		print "<td class='textSubHeaderDark'>" . $header_items[$i] . "</td>\n";
	}

	print "<td width='1%' align='right' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAll(\"chk_\",this.checked)'></td>\n<form name='chk' method='post' action='$form_action'>\n";
	print "</tr>\n";
}
Esempio n. 5
0
function form_checkbox_cell($title, $id)
{
    print "\t<td onClick='select_line(\"{$id}\", true)' style='" . get_checkbox_style() . "' width='1%' align='right'>\n";
    print "\t\t<input type='checkbox' style='margin: 0px;' id='chk_" . $id . "' name='chk_" . $id . "'>\n";
    print "\t</td>\n";
}
Esempio n. 6
0
function graphs() {
	global $colors;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("host_id"));
	/* ==================================================== */

	/* use the first host in the list as the default */
	if ((!isset($_SESSION["sess_graphs_new_host_id"])) && (empty($_REQUEST["host_id"]))) {
		$_REQUEST["host_id"] = db_fetch_cell("select id from host order by description,hostname limit 1");
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	if (isset($_REQUEST["host_id"])) { $_SESSION["sess_graphs_new_host_id"] = $_REQUEST["host_id"]; }else{ $_REQUEST["host_id"] = $_SESSION["sess_graphs_new_host_id"]; }

	$host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);

	$debug_log = debug_log_return("new_graphs");

	if (!empty($debug_log)) {
		debug_log_clear("new_graphs");
		?>
		<table width='98%' 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_graph_id">
	<table width="98%" align="center">
		<tr>
			<td class="textInfo" colspan="2">
				<?php print $host["description"];?> (<?php print $host["hostname"];?>)
			</td>
			<td align="right" class="textInfo" 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>
		<tr>
			<td>
			</td>
		</tr>

		<tr>
			<td class="textArea" style="padding: 3px;" width="300" nowrap>
				Create new graphs for the following host:
			</td>
			<td class="textInfo" rowspan="2" valign="top">
				<span style="color: #c16921;">*</span><a href="host.php?action=edit&id=<?php print $_REQUEST["host_id"];?>">Edit this Host</a><br>
				<span style="color: #c16921;">*</span><a href="host.php?action=edit">Create New Host</a>
			</td>
		</tr>
			<td>
				<select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value">
					<?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='graphs_new.php?host_id=" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n";
					}
					}
					?>
				</select>
			</td>
		</tr>
	</table>


	</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"]));

	/* we give users the option to turn off the javascript features for data queries with lots of rows */
	if (read_config_option("max_data_query_javascript_rows") >= $total_rows) {
		$use_javascript = true;
	}else{
		$use_javascript = false;
	}

	html_start_box("<strong>Graph Templates</strong>", "98%", $colors["header"], "3", "center", "");

	print "	<tr bgcolor='#" . $colors["header_panel"] . "'>
			<td class='textSubHeaderDark'>Graph Template Name</td>
			<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
		</tr>\n";

	$graph_templates = db_fetch_assoc("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=" . $_REQUEST["host_id"] . "
		order by graph_templates.name");

	$template_graphs = db_fetch_assoc("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=" . $host["id"] . "
		group 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) && ($use_javascript == true)) {
		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 */
	$i = 0;
	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" . (($use_javascript == true) ? " onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'" : "") . "><span id='gt_text$query_row" . "_0'>
					<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'" . (($use_javascript == true) ? " onClick='gt_update_selection_indicators();'" : "") . ">
				</td>
			</tr>";
	}
	}

	if ($use_javascript == true) {
		print "<script type='text/javascript'>gt_update_deps(1);</script>\n";
	}

	$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>&nbsp;";
				form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "font-size: 10px;");
	print "		</td>
		</tr>";

	html_end_box();

	$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"] . "
		order 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);

		$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;
		}

		/* we give users the option to turn off the javascript features for data queries with lots of rows */
		if (read_config_option("max_data_query_javascript_rows") >= $total_rows) {
			$use_javascript = true;
		}else{
			$use_javascript = false;
		}

		$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) && ($use_javascript == true)) {
			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.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 "	<table width='98%' style='background-color: #" . $colors["form_alternate2"] . "; border: 1px solid #" . $colors["header"] . ";' align='center' cellpadding='3' cellspacing='0'>\n
				<tr>
					<td bgcolor='#" . $colors["header"] . "' colspan='" . ($num_input_fields+1) . "'>
						<table  cellspacing='0' cellpadding='0' width='100%' >
							<tr>
								<td class='textHeaderDark'>
									<strong>Data Query</strong> [" . $snmp_query["name"] . "]
								</td>
								<td align='right' nowrap>
									<a href='graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"] . "'><img src='images/reload_icon_small.gif' alt='Reload Associated Query' border='0' align='absmiddle'></a>
								</td>
							</tr>
						</table>
					</td>
				</tr>";

		if ($xml_array != false) {
			$html_dq_header = "";
			$snmp_query_indexes = array();

			reset($xml_array["fields"]);
			while (list($field_name, $field_array) = each($xml_array["fields"])) {
				if ($field_array["direction"] == "input") {
					$raw_data = db_fetch_assoc("select field_value,snmp_index from host_snmp_cache where host_id=" . $host["id"] . " and field_name='$field_name' and snmp_query_id=" . $snmp_query["id"]);

					/* don't even both to display the column if it has no data */
					if (sizeof($raw_data) > 0) {
						/* draw each header item <TD> */
						$html_dq_header .= "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n";

						foreach ($raw_data as $data) {
							$snmp_query_data[$field_name]{$data["snmp_index"]} = $data["field_value"];

							if (!in_array($data["snmp_index"], $snmp_query_indexes,TRUE)) {
								array_push($snmp_query_indexes, $data["snmp_index"]);
							}
						}

						$num_visible_fields++;
					}elseif (sizeof($raw_data) == 0) {
						/* we are choosing to not display this column, so unset the associated
						field in the xml array so it is not drawn */
						unset($xml_array["fields"][$field_name]);
					}
				}
			}

			/* if the user specified a prefered sort order; sort the list of indexes before displaying them */
			if (isset($xml_array["index_order_type"])) {
				if ($xml_array["index_order_type"] == "numeric") {
					usort($snmp_query_indexes, "usort_numeric");
				}else if ($xml_array["index_order_type"] == "alphabetic") {
					usort($snmp_query_indexes, "usort_alphabetic");
				}else if ($xml_array["index_order_type"] == "natural") {
					usort($snmp_query_indexes, "usort_natural");
				}
			}

			if ($num_visible_fields == 0) {
				print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>This data query returned 0 rows, perhaps there was a problem executing this
					data query. You can <a href='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 bgcolor='#" . $colors["header_panel"] . "'>
						$html_dq_header
						<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);" . (($use_javascript == true) ? "dq_update_selection_indicators();" : "") . "'></td>\n
					</tr>\n";
			}

			$row_counter = 0;
			if (sizeof($snmp_query_indexes) > 0) {
			while (list($id, $snmp_index) = each($snmp_query_indexes)) {
				$query_row = $snmp_query["id"] . "_" . encode_data_query_index($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 (isset($snmp_query_data[$field_name][$snmp_index])) {
							print "<td " . (($use_javascript == true) ? "onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($snmp_index) . "\");'" : "")  ."><span id='text$query_row" . "_" . $column_counter . "'>" . $snmp_query_data[$field_name][$snmp_index] . "</span></td>";
						}else{
							print "<td " . (($use_javascript == true) ? "onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($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' " . (($use_javascript == true) ? "onClick='dq_update_selection_indicators();'" : "") . ">";
				print "</td>";
				print "</tr>\n";

				$row_counter++;
			}
			}
		}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 "	<table align='center' width='98%'>
					<tr>
						<td width='1' valign='top'>
							<img src='images/arrow.gif' alt='' align='absmiddle'>&nbsp;
						</td>
						<td align='right'>
							<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span>&nbsp;
							<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' " . (($use_javascript == true) ? "onChange='dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");'" : "") . ">
								"; html_create_list($data_query_graphs,"name","id","0"); print "
							</select>
						</td>
					</tr>
				</table>";
		}

		print "<br>";

		if ($use_javascript == true) {
			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";
}
Esempio n. 7
0
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>&nbsp;";
        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=''>&nbsp;\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>&nbsp;\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";
}
Esempio n. 8
0
function html_header_checkbox($header_items, $include_form = true, $form_action = "")
{
    /* default to the 'current' file */
    if ($form_action == "") {
        $form_action = basename($_SERVER["PHP_SELF"]);
    }
    print "<tr class='tableHeader'>\n";
    for ($i = 0; $i < count($header_items); $i++) {
        print "<th>" . $header_items[$i] . "</th>\n";
    }
    print "<th width='1%' class='tdSelectAll' align='right' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAll(\"chk_\",this.checked)'></th>\n" . ($include_form ? "<th style='display:none;'><form name='chk' method='post' action='{$form_action}'></th>\n" : "");
    print "</tr>\n";
}
Esempio n. 9
0
function form_checkbox_cell($title, $id)
{
    print "<td style='" . get_checkbox_style() . "' width='1%' align='right'>\n\t\t\t\t\t<input type='checkbox' style='margin: 0px;' id='chk_" . $id . "' name='chk_" . $id . "'>\n\t</td>";
}
Esempio n. 10
0
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">
						&nbsp;Host:&nbsp;
					</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">
						&nbsp;<?php print __("Type:");?>&nbsp;
					</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">
						&nbsp;Search:&nbsp;
					</td>
					<td class="nw200">
						<input type="text" name="filter" size="30" width="200" value="<?php print $_REQUEST["filter"];?>">
					</td>
					<td align="left" class="nw120">
						&nbsp;<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>&nbsp;";
					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'>&nbsp;
							</td>
							<td align='right'>
								<span class=\"italic\">" . __("Select a graph type:") . "</span>&nbsp;
								<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";
}
Esempio n. 11
0
File: html.php Progetto: MrWnn/cacti
function html_header_checkbox($header_items, $include_form = true, $form_action = "", $resizable = true)
{
    /* default to the 'current' file */
    if ($form_action == "") {
        $form_action = basename($_SERVER["PHP_SELF"]);
    }
    print "<tr class='tableHeader " . (!$resizable ? 'tableFixed' : '') . "'>\n";
    for ($i = 0; $i < count($header_items); $i++) {
        if (is_array($header_items[$i])) {
            print "<th style='text-align:" . $header_items[$i]['align'] . ";'>" . $header_items[$i]['display'] . "</td>";
        } else {
            print "<th style='text-align:left;'>" . $header_items[$i] . "</th>\n";
        }
    }
    print "<th width='1%' class='tableSubHeaderCheckbox' align='right' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All Rows' onClick='SelectAll(\"chk_\",this.checked)'></th>\n" . ($include_form ? "<th style='display:none;'><form name='chk' method='post' action='{$form_action}'></th>\n" : "");
    print "</tr>\n";
}
Esempio n. 12
0
function template()
{
    global $colors, $host_actions;
    display_output_messages();
    html_start_box("<strong>" . _("Device Templates") . "</strong>", "98%", $colors["header_background"], "3", "center", "device_templates.php?action=edit");
    html_header_checkbox(array("Template Title"));
    $host_templates = db_fetch_assoc("select * from host_template order by name");
    $i = 0;
    if (sizeof($host_templates) > 0) {
        foreach ($host_templates as $host_template) {
            form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
            $i++;
            ?>
			<td>
				<a class="linkEditMain" href="device_templates.php?action=edit&id=<?php 
            print $host_template["id"];
            ?>
"><?php 
            print $host_template["name"];
            ?>
</a>
			</td>
			<td style="<?php 
            print get_checkbox_style();
            ?>
" width="1%" align="right">
				<input type='checkbox' style='margin: 0px;' name='chk_<?php 
            print $host_template["id"];
            ?>
' title="<?php 
            print $host_template["name"];
            ?>
">
			</td>
		</tr>
	<?php 
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "' colspan=7><em>" . _("No Device Templates") . "</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($host_actions);
    print "</form>\n";
}
Esempio n. 13
0
function user_realms_edit()
{
    global $colors, $user_auth_realms;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    ?>
	<table width='100%' align='center' cellpadding="5">
		<tr>
			<td>
				<span style='font-size: 12px; font-weight: bold;'>Realm permissions control which sections of Cacti this user will have access to.</span>
			</td>
		</tr>
	</table>
	<?php 
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    print "\t<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td class='textHeaderDark'><strong>Realm Permissions</strong></td>\n\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAll(\"section\",this.checked)'></td>\n\n\t\t</tr>\n";
    ?>

	<tr>
		<td colspan="2" width="100%">
			<table width="100%">
				<tr>
					<td align="top" width="50%">
						<?php 
    $i = 0;
    while (list($realm_id, $realm_name) = each($user_auth_realms)) {
        if (sizeof(db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE user_id = " . get_request_var("id", 0) . " AND realm_id = " . $realm_id)) > 0) {
            $old_value = "on";
        } else {
            $old_value = "";
        }
        $column1 = floor(sizeof($user_auth_realms) / 2 + sizeof($user_auth_realms) % 2);
        if ($i == $column1) {
            print "</td><td valign='top' width='50%'>";
        }
        form_checkbox("section" . $realm_id, $old_value, $realm_name, "", "", "", !empty($_GET["id"]) ? 1 : 0);
        print "<br>";
        $i++;
    }
    ?>
					</td>
				</tr>
			</table>
		</td>
	</tr>

	<?php 
    html_end_box();
    form_hidden_box("save_component_realm_perms", "1", "");
}
Esempio n. 14
0
function host()
{
    global $colors, $device_actions;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("host_status"));
    /* ==================================================== */
    /* 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");
        kill_session_var("sess_device_host_template_id");
        kill_session_var("sess_host_status");
        kill_session_var("sess_host_sort_column");
        kill_session_var("sess_host_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host_template_id"]);
        unset($_REQUEST["host_status"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    if (!empty($_SESSION["sess_host_status"]) && !empty($_REQUEST["host_status"])) {
        if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) {
            $_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("host_template_id", "sess_device_host_template_id", "-1");
    load_current_session_value("host_status", "sess_host_status", "-1");
    load_current_session_value("sort_column", "sess_host_sort_column", "description");
    load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC");
    html_start_box("<strong>Devices</strong>", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]);
    include "./include/html/inc_device_filter_table.php";
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "where (host.hostname like '%%" . $_REQUEST["filter"] . "%%' OR host.description like '%%" . $_REQUEST["filter"] . "%%')";
    if ($_REQUEST["host_status"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_status"] == "-2") {
        $sql_where .= " and host.disabled='on'";
    } elseif ($_REQUEST["host_status"] == "-3") {
        $sql_where .= " and host.disabled=''";
    } else {
        $sql_where .= " and (host.status=" . $_REQUEST["host_status"] . " AND host.disabled = '')";
    }
    if ($_REQUEST["host_template_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_template_id"] == "0") {
        $sql_where .= " and host.host_template_id=0";
    } elseif (!empty($_REQUEST["host_template_id"])) {
        $sql_where .= " and host.host_template_id=" . $_REQUEST["host_template_id"];
    }
    html_start_box("", "98%", $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("select\n\t\tCOUNT(host.id)\n\t\tfrom host\n\t\t{$sql_where}");
    $sortby = $_REQUEST["sort_column"];
    if ($sortby == "hostname") {
        $sortby = "INET_ATON(hostname)";
    }
    $hosts = db_fetch_assoc("SELECT\n\t\thost.id,\n\t\thost.disabled,\n\t\thost.status,\n\t\thost.hostname,\n\t\thost.description,\n\t\thost.min_time,\n\t\thost.max_time,\n\t\thost.cur_time,\n\t\thost.avg_time,\n\t\thost.availability\n\t\tFROM host\n\t\t{$sql_where}\n\t\tORDER BY " . $sortby . " " . $_REQUEST["sort_direction"] . "\n\t\tLIMIT " . read_config_option("num_rows_device") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_device"));
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]);
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='7'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if ($_REQUEST["page"] > 1) {
        $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"] - 1) . "'>";
    }
    $nav .= "Previous";
    if ($_REQUEST["page"] > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_device") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < read_config_option("num_rows_device") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_device") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>";
    if ($_REQUEST["page"] * read_config_option("num_rows_device") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"] + 1) . "'>";
    }
    $nav .= "Next";
    if ($_REQUEST["page"] * read_config_option("num_rows_device") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n";
    print $nav;
    $display_text = array("description" => array("Description", "ASC"), "status" => array("Status", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC"));
    html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i);
            $i++;
            ?>
				<td width=250>
					<a class="linkEditMain" href="host.php?action=edit&id=<?php 
            print $host["id"];
            ?>
"><?php 
            print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]);
            ?>
</a>
				</td>
				<td><?php 
            print get_colored_device_status($host["disabled"] == "on" ? true : false, $host["status"]);
            ?>
</td>
				<td><?php 
            print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["hostname"]);
            ?>
</td>
				<td><?php 
            print round($host["cur_time"], 2);
            ?>
</td>
				<td><?php 
            print round($host["avg_time"], 2);
            ?>
</td>
				<td><?php 
            print round($host["availability"], 2);
            ?>
%</td>
				<td style="<?php 
            print get_checkbox_style();
            ?>
" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php 
            print $host["id"];
            ?>
' title="<?php 
            print $host["description"];
            ?>
">
				</td>
			</tr>
			<?php 
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Hosts</em></td></tr>";
    }
    html_end_box(false);
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($device_actions);
}
Esempio n. 15
0
function template() {
	global $colors, $ds_actions;

	html_start_box("<strong>Data Templates</strong>", "98%", $colors["header"], "3", "center", "data_templates.php?action=template_edit");

	html_header_checkbox(array("Template Name", "Data Input Method", "Status"));

	$template_list = db_fetch_assoc("select
		data_template.id,
		data_template.name,
		data_input.name as data_input_method,
		data_template_data.active as active
		from data_template,data_template_data
		left join data_input on data_template_data.data_input_id = data_input.id
		where data_template.id = data_template_data.data_template_id
		and data_template_data.local_data_id = 0
		order by data_template.name");

	$i = 0;
	if (sizeof($template_list) > 0) {
	foreach ($template_list as $template) {
		form_alternate_row_color($colors["alternate"],$colors["light"],$i);
			?>
			<td>
				<a class="linkEditMain" href="data_templates.php?action=template_edit&id=<?php print $template["id"];?>"><?php print $template["name"];?></a>
			</td>
			<td>
				<?php print (empty($template["data_input_method"]) ? "<em>None</em>": $template["data_input_method"]);?>
			</td>
			<td>
				<?php if ($template["active"] == "on") print "Active"; else print "Disabled";?>
			</td>
			<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
				<input type='checkbox' style='margin: 0px;' name='chk_<?php print $template["id"];?>' title="<?php print $template["name"];?>">
			</td>
		</tr>
		<?php
		$i++;
	}
	}else{
		print "<tr><td><em>No Data Templates</em></td></tr>\n";
	}
	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($ds_actions);

	print "</form>\n";
}
Esempio n. 16
0
function mactrack_maca() {
	global $colors, $maca_actions, $config, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("page"));
	input_validate_input_number(get_request_var_request("mac_id"));
	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_mactrack_maca_current_page");
		kill_session_var("sess_mactrack_maca_filter");
		kill_session_var("sess_mactrack_maca_rows");
		kill_session_var("sess_mactrack_maca_sort_column");
		kill_session_var("sess_mactrack_maca_sort_direction");

		$_REQUEST["page"] = 1;
		unset($_REQUEST["filter"]);
		unset($_REQUEST["rows"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
	}else{
		/* if any of the settings changed, reset the page number */
		$changed = 0;
		$changed += mactrack_check_changed("filter", "sess_mactrack_maca_filter");
		$changed += mactrack_check_changed("detail", "sess_mactrack_maca_detail");
		$changed += mactrack_check_changed("rows", "sess_mactrack_maca_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_mactrack_maca_current_page", "1");
	load_current_session_value("rows", "sess_mactrack_maca_rows", "-1");
	load_current_session_value("filter", "sess_mactrack_maca_filter", "");
	load_current_session_value("sort_column", "sess_mactrack_maca_sort_column", "mac_address");
	load_current_session_value("sort_direction", "sess_mactrack_maca_sort_direction", "ASC");

	if ($_REQUEST["rows"] == -1) {
		$row_limit = read_config_option("num_rows_mactrack");
	}elseif ($_REQUEST["rows"] == -2) {
		$row_limit = 999999;
	}else{
		$row_limit = $_REQUEST["rows"];
	}

	html_start_box("<strong>MacTrack MacAuth Filters</strong>", "100%", $colors["header"], "3", "center", "mactrack_macauth.php?action=edit");
	mactrack_maca_filter();
	html_end_box();
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$sql_where = "";

	$maca = mactrack_maca_get_maca_records($sql_where, $row_limit);

	$total_rows = db_fetch_cell("SELECT count(*)
		FROM mac_track_macauth
		$sql_where");

	/* generate page list */
	$url_page_select = str_replace("&page", "?page", get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_macauth.php"));

	if (defined("CACTI_VERSION")) {
		/* generate page list navigation */
		$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, 9, "mactrack_macauth.php?filter=" . $_REQUEST["filter"]);
	}else{
		$nav = "<tr bgcolor='#" . $colors["header"] . "'>
				<td colspan='9'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='left' class='textHeaderDark'>
								<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='mactrack_macauth.php?page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
							</td>\n
							<td align='center' class='textHeaderDark'>
								Showing Rows " . (($row_limit*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < $row_limit) || ($total_rows < ($row_limit*$_REQUEST["page"]))) ? $total_rows : ($row_limit*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
							</td>\n
							<td align='right' class='textHeaderDark'>
								<strong>"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "<a class='linkOverDark' href='mactrack_macauth.php?page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
							</td>\n
						</tr>
					</table>
				</td>
			</tr>\n";
	}

	if ($total_rows) {
		print $nav;
	}

	$display_text = array(
		"mac_address" => array("Mac Address", "ASC"),
		"" => array("Reason", "ASC"),
		"added_date" => array("Added/Modified", "ASC"),
		"date_last_seen" => array("By", "ASC"));

	html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);

	$i = 0;
	if (sizeof($maca) > 0) {
		foreach ($maca as $mac) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td width="20%">
					<a class="linkEditMain" href="mactrack_macauth.php?action=edit&mac_id=<?php print $mac['mac_id'];?>"><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $mac["mac_address"]) : $mac["mac_address"]);?></a>
				</td>
				<td width="50%"><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $mac["description"]) : $mac["description"]);?></td>
				<td width="20%"><?php print $mac["added_date"];?></td>
				<td width="10%"><?php print db_fetch_cell("SELECT full_name FROM user_auth WHERE id='" . $mac["added_by"] . "'");?></td>

				<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php print $mac["mac_id"];?>' title="<?php print $mac["name"];?>">
				</td>
			</tr>
			<?php
		}

		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td colspan=10><em>No Authorized Mac Addresses</em></td></tr>";
	}
	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	mactrack_draw_actions_dropdown($maca_actions);
}
Esempio n. 17
0
function graph() {
	global $colors, $graph_actions;

	/* 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_host_id");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["host_id"]);
	}

	/* 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("host_id", "sess_graph_host_id", "-1");

	html_start_box("<strong>Graph Management</strong>", "98%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . $_REQUEST["host_id"]);

	include("./include/html/inc_graph_filter_table.php");

	html_end_box();

	/* form the 'where' clause for our main sql query */
	$sql_where = "and graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'";

	if ($_REQUEST["host_id"] == "-1") {
		/* Show all items */
	}elseif ($_REQUEST["host_id"] == "0") {
		$sql_where .= " and graph_local.host_id=0";
	}elseif (!empty($_REQUEST["host_id"])) {
		$sql_where .= " and graph_local.host_id=" . $_REQUEST["host_id"];
	}

	html_start_box("", "98%", $colors["header"], "3", "center", "");

	$total_rows = db_fetch_cell("select
		COUNT(graph_templates_graph.id)
		from graph_local,graph_templates_graph
		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.host_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 graph_templates_graph.title_cache,graph_local.host_id
		limit " . (read_config_option("num_rows_graph")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_graph"));

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_graph"), $total_rows, "graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]);

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='4'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing Rows " . ((read_config_option("num_rows_graph")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_graph")) || ($total_rows < (read_config_option("num_rows_graph")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_graph")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_graph")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_graph")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
						</td>\n
					</tr>
				</table>
			</td>
		</tr>\n";

	print $nav;

	html_header_checkbox(array("Graph Title", "Template Name", "Size"));

	$i = 0;
	if (sizeof($graph_list) > 0) {
		foreach ($graph_list as $graph) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td>
					<a class="linkEditMain" href="graphs.php?action=graph_edit&id=<?php print $graph["local_graph_id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph")));?></a>
				</td>
				<td>
					<?php print ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]); ?>
				</td>
				<td>
					<?php print $graph["height"];?>x<?php print $graph["width"];?>
				</td>
				<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php print $graph["local_graph_id"];?>' title="<?php print $graph["title_cache"];?>">
				</td>
			</tr>
			<?php
		}

		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td><em>No Graphs Found</em></td></tr>";
	}

	html_end_box(false);

	/* add a list of tree names to the actions dropdown */
	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";
}
Esempio n. 18
0
function form_checkbox_cell($title, $id, $checked = false) {
	print "\t<td onClick='select_line(\"$id\",true)' style='" . get_checkbox_style() . "' width='1%' align='center'>\n";
	print "\t\t<input type='checkbox' title='$title' style='margin: 0px;' id='chk_" . $id . "' name='chk_" . $id . "'" . ($checked ? " checked" : "") . ">\n";
	print "\t</td>\n";
}
Esempio n. 19
0
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:&nbsp;
			</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">
				&nbsp;Graph Types:&nbsp;
			</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:&nbsp;
			</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;'>
				&nbsp;<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>&nbsp;";
        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>&lt;&lt; ";
                            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 .= " &gt;&gt;</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'>&nbsp;\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>&nbsp;\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";
}
Esempio n. 20
0
function user() {
	global $user_actions, $colors, $auth_realms;

	html_start_box("<strong>" . _("User Management") . "</strong>", "98%", $colors["header_background"], "3", "center", "user_admin.php?action=user_edit");

	html_header_checkbox(array(_("User Name"), _("Full Name"), _("Status"),_("Realm"), _("Default Graph Policy"), _("Last Login"), _("Last Login From"),_("Last Password Change")));

	$user_list = api_user_list( array( "1" => "username" ) );

	$i = 0;
	if (sizeof($user_list) > 0) {
	foreach ($user_list as $user_list_values) {
		$user = api_user_info( array( "id" => $user_list_values["id"] ) );
		form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
			?>
			<td>
				<a class="linkEditMain" href="user_admin.php?action=user_edit&id=<?php print $user["id"];?>"><?php print $user["username"];?></a>
			</td>
			<td>
				<?php print $user["full_name"];?>
			</td>
			<td>
				<?php if ($user["enabled"] == "1") { print _("Enabled"); }else{ print _("Disabled"); }?>
			</td>
			<td>
				<?php print $auth_realms[$user["realm"]];?>
			</td>
			<td>
				<?php if ($user["policy_graphs"] == "1") { print _("ALLOW"); }else{ print _("DENY"); }?>
			</td>
			<td>
				<?php print $user["last_login_formatted"];?>
			</td>
			<td>
				<?php print $user["last_login_ip"];?>
			</td>
			<td>
				<?php
				if ($user["realm"] != "0") {
					print _("N/A");
				}else{
					if ($user["password_change_last"] == "0000-00-00 00:00:00") {
						print _("Never");
					}else{
						print $user["password_change_last_formatted"];
					}
				} ?>
			</td>


			<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
				<input type='checkbox' style='margin: 0px;' name='chk_<?php print $user["id"];?>' title="<?php print $user["username"];?>">
			</td>
		</tr>
	<?php
	$i++;
	}
	}
	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($user_actions);

}
Esempio n. 21
0
function template() {
	global $colors, $host_actions;

	/* 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"));
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("sort_column", "sess_host_template_column", "name");
	load_current_session_value("sort_direction", "sess_host_template_sort_direction", "ASC");

	display_output_messages();

	html_start_box("<strong>Host Templates</strong>", "98%", $colors["header"], "3", "center", "host_templates.php?action=edit");

	$display_text = array(
		"name" => array("Template Title", "ASC"));

	html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);

	$host_templates = db_fetch_assoc("SELECT *
		FROM host_template
		ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']);

	$i = 0;
	if (sizeof($host_templates) > 0) {
	foreach ($host_templates as $host_template) {
		form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
			?>
			<td>
				<a class="linkEditMain" href="host_templates.php?action=edit&id=<?php print $host_template["id"];?>"><?php print $host_template["name"];?></a>
			</td>
			<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
				<input type='checkbox' style='margin: 0px;' name='chk_<?php print $host_template["id"];?>' title="<?php print $host_template["name"];?>">
			</td>
		</tr>
	<?php
	}
	}else{
		print "<tr><td><em>No Host 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";
}
Esempio n. 22
0
function draw_graph_item_editor($graph_X_id, $form_type, $disable_controls) {
	global $colors;

	require_once(CACTI_BASE_PATH . "/lib/graph/graph_utility.php");
	require_once(CACTI_BASE_PATH . "/include/graph/graph_constants.php");
	require(CACTI_BASE_PATH . "/include/graph/graph_arrays.php");
	require(CACTI_BASE_PATH . "/include/data_source/data_source_arrays.php");

	$graph_actions = array(
		1 => _("Delete Items"),
		2 => _("Duplicate Items")
		);

	if ($form_type == "graph_template") {
		$item_list = db_fetch_assoc("select
			graph_template_item.id,
			graph_template_item.legend_format,
			graph_template_item.legend_value,
			graph_template_item.gprint_format,
			graph_template_item.hard_return,
			graph_template_item.graph_item_type,
			graph_template_item.consolidation_function,
			graph_template_item.color,
			graph_template_item.sequence,
			graph_template.auto_padding,
			data_template_item.data_source_name
			from (graph_template_item,graph_template)
			left join data_template_item on (graph_template_item.data_template_item_id=data_template_item.id)
			where graph_template_item.graph_template_id=graph_template.id
			and graph_template_item.graph_template_id = $graph_X_id
			order by graph_template_item.sequence");

		$url_filename = "graph_templates_items.php";
		$url_data = "&graph_template_id=$graph_X_id";
	}else if ($form_type == "graph") {
		$item_list = db_fetch_assoc("select
			graph_item.id,
			graph_item.legend_format,
			graph_item.legend_value,
			graph_item.gprint_format,
			graph_item.hard_return,
			graph_item.graph_item_type,
			graph_item.consolidation_function,
			graph_item.color,
			graph_item.sequence,
			graph.auto_padding,
			data_source_item.data_source_name
			from (graph_item,graph)
			left join data_source_item on (graph_item.data_source_item_id=data_source_item.id)
			where graph_item.graph_id=graph.id
			and graph_item.graph_id = $graph_X_id
			order by graph_item.sequence");

		$url_filename = "graphs_items.php";
		$url_data = "&graph_id=$graph_X_id";
	}else{
		return;
	}

	?>
	<tr bgcolor='#<?php echo $colors["header_panel_background"];?>'>
		<td width='12'>
			&nbsp;
		</td>
		<td width='60' class='textSubHeaderDark'>
			Item
		</td>
		<td class='textSubHeaderDark'>
			Graph Item Type
		</td>
		<td class='textSubHeaderDark'>
			Data Source
		</td>
		<td class='textSubHeaderDark'>
			Legend Text
		</td>
		<td class='textSubHeaderDark'>
			Color
		</td>
		<td class='textSubHeaderDark'>
			CF Type
		</td>
		<td>
			&nbsp;
		</td>
		<td>
			&nbsp;
		</td>
		<td width='1%' align='right' bgcolor='#819bc0' style='<?php echo get_checkbox_style();?>'>
			<input type='checkbox' style='margin: 0px;' name='all' title='<?php echo _("Select All");?>' onClick='graph_item_rows_selection(this.checked)'>
		</td>
	</tr>
	<?php

	if (sizeof($item_list) > 0) {
		/* calculate auto padding information and other information that we will need below */
		$max_pad_length = 0;
		$total_num_rows = 0;

		for ($i=0; $i<sizeof($item_list); $i++) {
			if (($i == 0) || (!empty($item_list{$i-1}["hard_return"]))) {
				if (strlen($item_list[$i]["legend_format"]) > $max_pad_length) {
					$max_pad_length = strlen($item_list[$i]["legend_format"]);
				}

				$total_num_rows++;
			}
		}

		$i = 0;
		$row_counter = 1;

		/* preload expand/contract icons */
		echo "<script type='text/javascript'>\nvar auxImg;\nauxImg = new Image();auxImg.src = '" . html_get_theme_images_path("show.gif") . "';\nauxImg.src = '" . html_get_theme_images_path("hide.gif") . "';\n</script>\n";

		/* initialize JS variables */
		echo "<script type='text/javascript'>\nvar item_row_list = new Array()\n</script>\n";

		foreach ($item_list as $item) {
			$matrix_title = "";
			$hard_return = "";
			$show_moveup = true;
			$show_movedown = true;

			if (is_graph_item_type_primary($item["graph_item_type"])) {
				$matrix_title = "(" . $item["data_source_name"] . "): " . $item["legend_format"];
			}else if (($item["graph_item_type"] == GRAPH_ITEM_TYPE_HRULE) || ($item["graph_item_type"] == GRAPH_ITEM_TYPE_VRULE)) {
				$matrix_title = $graph_item_types{$item["graph_item_type"]} . ": " . $item["legend_value"];
			}else if ($item["graph_item_type"] == GRAPH_ITEM_TYPE_COMMENT) {
				$matrix_title = "COMMENT: " . $item["legend_format"];
			}

			if (!empty($item["hard_return"])) {
				$hard_return = "<strong><font color=\"#FF0000\">&lt;HR&gt;</font></strong>";
			}

			if (($i == 0) || (!empty($item_list{$i-1}["hard_return"]))) {
				?>
				<tr bgcolor="#<?php echo $colors["form_custom1"];?>">
					<td width='12' style='border-bottom: 1px solid #b5b5b5;' align='center'>
						<a href="javascript:graph_item_row_visibility(<?php echo $row_counter;?>)"><img id='img_<?php echo $row_counter;?>' src='<?php echo html_get_theme_images_path("hide.gif");?>' border='0' title='<?php echo _("Collapse Row");?>' alt='<?php echo _("Collapse Row");?>' align='absmiddle'></a>
					</td>
					<td style='border-right: 1px solid #b5b5b5; border-bottom: 1px solid #b5b5b5;' width='60'>
						<strong><?php echo _("Row #") . $row_counter;?></strong>
					</td>
					<td colspan='5' style='font-family: monospace; color: #515151; cursor: pointer; border-bottom: 1px solid #b5b5b5;' onClick="graph_item_row_visibility(<?php echo $row_counter;?>)" nowrap>
						<pre><?php
						$j = $i;
						$graph_item_row = array();
						do {
							$_item = $item_list[$j];
							if (is_graph_item_type_primary($_item["graph_item_type"])) {
								if ($_item["color"] != "") {
									echo "<img src='" . html_get_theme_images_path("transparent_line.gif") . "'style='width: 9px; height: 9px; border: 1px solid #000000; background-color: #" . $_item["color"] . "' border='0' align='absmiddle' alt=''>&nbsp;";
								}
							}

							if ($_item["graph_item_type"] == GRAPH_ITEM_TYPE_GPRINT) {
								printf(" " . $_item["legend_format"] . $_item["gprint_format"], "0", "");
							}else{
								echo $_item["legend_format"];
							}

							/* the first item of the row is where auto padding is applied */
							if ($i == $j) {
								echo (empty($_item["auto_padding"])) ? "" : str_repeat(" ", (($max_pad_length + 1) - strlen($_item["legend_format"])));
							}

							/* keep track of each item in this row so we can create a JS array below */
							$graph_item_row[] = $_item["id"];

							$j++;
						} while ((empty($item_list{$j-1}["hard_return"])) && (($j+1)<=sizeof($item_list)));
						?></pre>
					</td>
					<td align='center' width='15' style='border-bottom: 1px solid #b5b5b5;'>
						<?php if ($row_counter < $total_num_rows) { ?>
						<a href='<?php echo $url_filename;?>?action=row_movedown&row=<?php echo $row_counter;?><?php echo $url_data;?>'><img src='<?php echo html_get_theme_images_path("move_down.gif");?>' border='0' title='<?php echo _("Move Item Down");?>' alt='<?php echo _("Move Item Down");?>'></a>
						<?php }else{ ?>
						&nbsp;
						<?php } ?>
					</td>
					<td align='left' width='25' style='border-bottom: 1px solid #b5b5b5;'>
						<?php if ($i > 0) { ?>
						<a href='<?php echo $url_filename;?>?action=row_moveup&row=<?php echo $row_counter;?><?php echo $url_data;?>'><img src='<?php echo html_get_theme_images_path("move_up.gif");?>' border='0' title='<?php echo _("Move Item Up");?>' alt='<?php echo _("Move Item Up");?>'></a>
						<?php }else{ ?>
						&nbsp;
						<?php } ?>
					</td>
					<td style="<?php echo get_checkbox_style();?> border-bottom: 1px solid #b5b5b5;" width="1%" align="right">
						<input type='checkbox' style='margin: 0px;' onClick="graph_item_row_selection(<?php echo $row_counter;?>)" name='row_chk_<?php echo $row_counter;?>' id='row_chk_<?php echo $row_counter;?>' title="<?php echo _('Row #') . $row_counter;?>">
					</td>
				</tr>
				<?php

				/* create a JS array of graph items in each row */
				echo "<script type='text/javascript'>\nitem_row_list[$row_counter] = new Array(";

				for ($j=0; $j<sizeof($graph_item_row); $j++) {
					echo "'" . $graph_item_row[$j] . "'" . (($j+1) < sizeof($graph_item_row) ? "," : "");
				}

				echo ")\n</script>\n";

				$row_counter++;
			}

			/* only show arrows when they are supposed to be shown */
			if ($i == 0) {
				$show_moveup = false;
			}else if (($i+1) == sizeof($item_list)) {
				$show_movedown = false;
			}

			if (empty($item["graph_template_item_group_id"])) {
				$row_color = $colors["form_alternate1"];
			}else{
				$row_color = $colors["alternate"];
			}

			?>
			<tr id="tr_<?php echo $item["id"];?>" bgcolor="#<?php echo $row_color;?>">
				<td width='12' align='center'>
					&nbsp;
				</td>
				<td width='60' style='border-right: 1px solid #b5b5b5;'>
					<a href='<?php echo $url_filename;?>?action=edit&id=<?php echo $item["id"];?>&<?php echo $url_data;?>'><?php echo _("Item #") . ($i+1);?></a>
				</td>
				<td>
					<?php echo $graph_item_types{$item["graph_item_type"]};?>
				</td>
				<td>
					<?php echo $item["data_source_name"];?>
				</td>
				<td>
					<?php echo $item["legend_format"];?><?php echo (empty($item["hard_return"]) ? "" : "<span style='color: red; font-weight: bold;'>&lt;HR&gt;</span>");?>
				</td>
				<td>
					<?php echo $item["color"];?>
				</td>
				<td>
					<?php echo $consolidation_functions{$item["consolidation_function"]};?>
				</td>
				<td width='15' align='center'>
					<?php if (($i+1) < sizeof($item_list)) { ?>
					<a href='<?php echo $url_filename;?>?action=item_movedown&id=<?php echo $item["id"];?>&<?php echo $url_data;?>'><img src='<?php echo html_get_theme_images_path("move_down.gif");?>' border='0' title='<?php echo _("Move Item Down");?>' alt='<?php echo _("Move Item Down");?>'></a>
					<?php } ?>
				</td>
				<td width='25' align='left'>
					<?php if ($i > 0) { ?>
					<a href='<?php echo $url_filename;?>?action=item_moveup&id=<?php echo $item["id"];?>&<?php echo $url_data;?>'><img src='<?php echo html_get_theme_images_path("move_up.gif");?>' border='0' title='<?php echo _("Move Item Up");?>' alt='<?php echo _("Move Item Up");?>'></a>
					<?php } ?>
				</td>
				<td width='1' style="<?php echo get_checkbox_style();?>" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_gi_<?php echo $item["id"];?>' id='chk_<?php echo $item["id"];?>' title="<?php echo _('Item #') . ($i + 1);?>">
				</td>
			</tr>
			<?php

			$i++;
		}

		/* create a JS array for each row */
		echo "<script type='text/javascript'>\nvar item_rows = new Array(";

		for ($j=1; $j<$row_counter; $j++) {
			echo $j . (($j+1) < $row_counter ? "," : "");
		}

		echo ")\n</script>\n";

		?>
		<tr bgcolor='#ffffff'>
			<td colspan='10' style='border-top: 1px dashed #a1a1a1;'>
				<?php draw_actions_dropdown($graph_actions, 2, 100); ?>
			</td>
		</tr>
		<?php
	}else{
		echo "<tr><td><em>" . _("No graph items found.") . "</em></td></tr>\n";
	}
}
Esempio n. 23
0
function template() {
	global $colors, $graph_actions;

	html_start_box("<strong>Graph Templates</strong>", "98%", $colors["header"], "3", "center", "graph_templates.php?action=template_edit");

	html_header_checkbox(array("Template Title"));

	$template_list = db_fetch_assoc("select
		graph_templates.id,graph_templates.name
		from graph_templates
		order by name");

	$i = 0;
	if (sizeof($template_list) > 0) {
	foreach ($template_list as $template) {
		form_alternate_row_color($colors["alternate"],$colors["light"],$i);
			?>
			<td>
				<a class="linkEditMain" href="graph_templates.php?action=template_edit&id=<?php print $template["id"];?>"><?php print $template["name"];?></a>
			</td>
			<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
				<input type='checkbox' style='margin: 0px;' name='chk_<?php print $template["id"];?>' title="<?php print $template["name"];?>">
			</td>
		</tr>
		<?php
		$i++;
	}
	}else{
		print "<tr><td><em>No Graph Templates</em></td></tr>\n";
	}
	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($graph_actions);

	print "</form>\n";
}
Esempio n. 24
0
function form_checkbox_cell($title, $id, $disabled = false)
{
    print "\t<td class='checkbox' style='" . get_checkbox_style() . "' width='1%' align='right'>\n";
    print "\t\t<input type='checkbox' " . ($disabled ? "disabled='disabled' class='disabled'" : '') . " style='margin: 0px;' id='chk_" . $id . "' name='chk_" . $id . "'>\n";
    print "\t</td>\n";
}
Esempio n. 25
0
function user_realms_edit() {
	global $colors, $user_auth_realms;

	?>
	<table width='98%' align='center' cellpadding="5">
		<tr>
			<td>
				<span style='font-size: 12px; font-weight: bold;'>Realm permissions control which sections of Cacti this user will have access to.</span>
			</td>
		</tr>
	</table>
	<?php

	html_start_box("", "98%", $colors["header"], "3", "center", "");

	print "	<tr bgcolor='#" . $colors["header"] . "'>
			<td class='textHeaderDark'><strong>Realm Permissions</strong></td>
			<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAll(\"section\",this.checked)'></td>\n
		</tr>\n";

	$realms = db_fetch_assoc("select
		user_auth_realm.user_id,
		user_realm.id,
		user_realm.name
		from user_realm
		left join user_auth_realm on (user_realm.id=user_auth_realm.realm_id and user_auth_realm.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . ")
		order by user_realm.name");

	?>

	<tr>
		<td colspan="2" width="100%">
			<table width="100%">
				<tr>
					<td align="top" width="50%">
						<?php
						$i = 0;
						while (list($realm_id, $realm_name) = each($user_auth_realms)) {
							if (sizeof(db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . " and realm_id=$realm_id")) > 0) {
								$old_value = "on";
							}else{
								$old_value = "";
							}

							$column1 = floor((sizeof($user_auth_realms) / 2) + (sizeof($user_auth_realms) % 2));

							if ($i == $column1) {
								print "</td><td valign='top' width='50%'>";
							}

							form_checkbox("section" . $realm_id, $old_value, $realm_name, "", (!empty($_GET["id"]) ? 1 : 0)); print "<br>";

							$i++;
						}
						?>
					</td>
				</tr>
			</table>
		</td>
	</tr>

	<?php
	html_end_box();

	form_hidden_box("save_component_realm_perms","1","");
}
Esempio n. 26
0
function ds() {
	global $colors, $ds_actions;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("host_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_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_host_id");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
		unset($_REQUEST["host_id"]);
	}

	/* 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("host_id", "sess_ds_host_id", "-1");

	$host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]);

	html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "98%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . $_REQUEST["host_id"]);

	include("./include/html/inc_data_source_filter_table.php");

	html_end_box();

	/* form the 'where' clause for our main sql query */
	$sql_where = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" .
		" OR data_template.name like '%%" . $_REQUEST["filter"] . "%%'" .
		" OR data_input.name like '%%" . $_REQUEST["filter"] . "%%')";

	if ($_REQUEST["host_id"] == "-1") {
		/* Show all items */
	}elseif ($_REQUEST["host_id"] == "0") {
		$sql_where .= " AND data_local.host_id=0";
	}elseif (!empty($_REQUEST["host_id"])) {
		$sql_where .= " AND data_local.host_id=" . $_REQUEST["host_id"];
	}

	$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_where"));
	$data_sources = db_fetch_assoc("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.host_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_where
		ORDER BY ". $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] .
		" LIMIT " . (read_config_option("num_rows_data_source")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_data_source"));

	html_start_box("", "98%", $colors["header"], "3", "center", "");

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]);

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='5'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing Rows " . ((read_config_option("num_rows_data_source")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_data_source")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
						</td>\n
					</tr>
				</table>
			</td>
		</tr>\n";

	print $nav;

	$display_text = array(
		"name_cache" => array("Name", "ASC"),
		"data_input_name" => array("Data Input Method", "ASC"),
		"active" => array("Active", "ASC"),
		"data_template_name" => array("Template Name", "ASC"));

	html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);

	$i = 0;
	if (sizeof($data_sources) > 0) {
		foreach ($data_sources as $data_source) {
			$data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : $data_source["data_template_name"]);
			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td>
					<a class='linkEditMain' href='data_sources.php?action=ds_edit&id=<?php print $data_source["local_data_id"];?>' title='<?php print $data_source["name_cache"];?>'><?php if ($_REQUEST["filter"] != "") { print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($data_source["name_cache"], read_config_option("max_title_data_source"))); }else{ print title_trim($data_source["name_cache"], read_config_option("max_title_data_source")); } ?></a>
				</td>
				<td>
					<?php if ($_REQUEST["filter"] != "") { print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source["data_input_name"]); }else{ print $data_source["data_input_name"]; } ?></a>
				</td>
				<td>
					<?php print (($data_source["active"] == "on") ? "Yes" : "<span style='color: red;'>No</span>");?>
				</td>
				<td>
					<?php if ($_REQUEST["filter"] != "") { print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_template_name); }else{ print $data_template_name; } ?></a>
				</td>
				<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php print $data_source["local_data_id"];?>' title="<?php print $data_source["name_cache"];?>">
				</td>
			</tr>
			<?php
		}

		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td><em>No Data Sources</em></td></tr>";
	}

	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($ds_actions);

	print "</form>\n";
}
Esempio n. 27
0
function host() {
	global $colors, $device_actions;

	/* 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");
		kill_session_var("sess_device_host_template_id");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["host_template_id"]);
	}

	/* 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("host_template_id", "sess_device_host_template_id", "-1");

	html_start_box("<strong>Devices</strong>", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"]);

	include("./include/html/inc_device_filter_table.php");

	html_end_box();

	/* form the 'where' clause for our main sql query */
	$sql_where = "where host.description like '%%" . $_REQUEST["filter"] . "%%'";

	if ($_REQUEST["host_template_id"] == "-1") {
		/* Show all items */
	}elseif ($_REQUEST["host_template_id"] == "0") {
		$sql_where .= " and host.host_template_id=0";
	}elseif (!empty($_REQUEST["host_template_id"])) {
		$sql_where .= " and host.host_template_id=" . $_REQUEST["host_template_id"];
	}

	html_start_box("", "98%", $colors["header"], "3", "center", "");

	$total_rows = db_fetch_cell("select
		COUNT(host.id)
		from host
		$sql_where");

	$hosts = db_fetch_assoc("select
		host.id,
		host.disabled,
		host.status,
		host.hostname,
		host.description,
		host.min_time,
		host.max_time,
		host.cur_time,
		host.avg_time,
		host.availability
		from host
		$sql_where
		order by host.description
		limit " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device"));

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"]);

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='7'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
						</td>\n
					</tr>
				</table>
			</td>
		</tr>\n";

	print $nav;

	html_header_checkbox(array("Description", "Status", "Hostname", "Current (ms)", "Average (ms)", "Availability"));

	$i = 0;
	if (sizeof($hosts) > 0) {
		foreach ($hosts as $host) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td width=200>
					<a class="linkEditMain" href="host.php?action=edit&id=<?php print $host["id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]);?></a>
				</td>
				<td>
					<?php print get_colored_device_status(($host["disabled"] == "on" ? true : false), $host["status"]);?>
				</td>
				<td>
					<?php print $host["hostname"];?>
				</td>
				<td>
					<?php print round(($host["cur_time"]), 2);?>
				</td>
				<td>
					<?php print round(($host["avg_time"]), 2);?>
				</td>
				<td>
					<?php print round($host["availability"], 2);?>%
				</td>
				<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php print $host["id"];?>' title="<?php print $host["description"];?>">
				</td>
			</tr>
			<?php
		}

		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td><em>No Hosts</em></td></tr>";
	}
	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($device_actions);
}
Esempio n. 28
0
function template() {
	global $colors, $graph_actions;

	/* ================= input validation ================= */
	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"));
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_template_current_page");
		kill_session_var("sess_graph_template_filter");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("page", "sess_graph_template_current_page", "1");
	load_current_session_value("filter", "sess_graph_template_filter", "");

	html_start_box("<strong>Graph Templates</strong>", "98%", $colors["header"], "3", "center", "graph_templates.php?action=template_edit");

	include("./include/html/inc_graph_template_filter_table.php");

	html_end_box();

	/* form the 'where' clause for our main sql query */
	$sql_where = "where (graph_templates.name like '%%" . $_REQUEST["filter"] . "%%')";

	html_start_box("", "98%", $colors["header"], "3", "center", "");

	$total_rows = db_fetch_cell("select
		COUNT(graph_templates.id)
		from graph_templates
		$sql_where");

	$template_list = db_fetch_assoc("select
		graph_templates.id,graph_templates.name
		from graph_templates
		$sql_where
		order by name
		limit " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device"));

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "graph_templates.php?filter=" . $_REQUEST["filter"]);

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
		<td colspan='7'>
			<table width='100%' cellspacing='0' cellpadding='0' border='0'>
				<tr>
					<td align='left' class='textHeaderDark'>
						<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='graph_templates.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
					</td>\n
					<td align='center' class='textHeaderDark'>
						Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
					</td>\n
					<td align='right' class='textHeaderDark'>
						<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graph_templates.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
					</td>\n
				</tr>
			</table>
		</td>
		</tr>\n";

	print $nav;

	html_header_checkbox(array("Template Title"));

	$i = 0;
	if (sizeof($template_list) > 0) {
		foreach ($template_list as $template) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i);
				?>
			<td>
				<a class="linkEditMain" href="graph_templates.php?action=template_edit&id=<?php print $template["id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template["name"]);?></a>
			</td>
			<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
				<input type='checkbox' style='margin: 0px;' name='chk_<?php print $template["id"];?>' title="<?php print $template["name"];?>">
			</td>
			</tr>
			<?php
			$i++;
		}
		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td><em>No Graph Templates</em></td></tr>\n";
	}
	html_end_box(false);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($graph_actions);

	print "</form>\n";
}
Esempio n. 29
0
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']);
}
Esempio n. 30
0
function user_realms_edit($header_label)
{
    global $user_auth_realms;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    print "<form name='chk' action='user_admin.php' method='post'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    $all_realms = $user_auth_realms;
    print "\t<tr class='cactiTableTitle'>\n\t\t\t<td class='textHeaderDark'><strong>Realm Permissions</strong> {$header_label}</td>\n\t\t\t<td class='tableHeader' width='1%' align='center' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='selectAllRealms(this.checked)'></td>\n\n\t\t</tr>\n";
    /* do cacti realms first */
    print "<tr class='tableHeader'><th colspan='2'>Base Permissions</th></tr>\n";
    print "<tr class='odd'><td colspan='4' width='100%'><table width='100%'><tr><td valign='top' style='white-space:nowrap;' width='20%'>\n";
    $i = 1;
    $j = 1;
    $base = array(7, 8, 15, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 101);
    foreach ($base as $realm) {
        if (isset($user_auth_realms[$realm])) {
            $set = db_fetch_cell_prepared('SELECT realm_id 
				FROM user_auth_realm 
				WHERE user_id = ? 
				AND realm_id = ?', array(get_request_var_request('id', 0), $realm));
            if (!empty($set)) {
                $old_value = 'on';
            } else {
                $old_value = '';
            }
            unset($all_realms[$realm]);
            if ($j == 5) {
                print "</td><td valign='top' width='20%' style='white-space:nowrap;'>\n";
                $j = 1;
            }
            form_checkbox('section' . $realm, $old_value, $user_auth_realms[$realm], '', '', '', !empty($_REQUEST['id']) ? 1 : 0);
            print '<br>';
            $j++;
        }
    }
    print "</td></tr></table></td></tr>\n";
    /* do plugin realms */
    $realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display
		FROM plugin_config AS pc
		INNER JOIN plugin_realms AS pr
		ON pc.directory = pr.plugin
		ORDER BY pc.name, pr.display');
    print "<tr class='tableHeader'><th colspan='2'>Plugin Permissions</th></tr>\n";
    print "<tr class='odd'><td colspan='4' width='100%'><table width='100%' cellpadding='0' cellspacing='0'><tr><td valign='top' width='20%' style='white-space:nowrap;'>\n";
    if (sizeof($realms)) {
        $last_plugin = 'none';
        $i = 1;
        $j = 1;
        $level = floor(sizeof($all_realms) / 4);
        $break = false;
        foreach ($realms as $r) {
            if ($last_plugin != $r['name']) {
                if ($break) {
                    print "</td><td valign='top' width='20%' style='white-space:nowrap;'>\n";
                    $break = false;
                    $j = 1;
                }
                print '<strong>' . $r['name'] . "</strong><br>\n";
                $last_plugin = $r['name'];
            } elseif ($break) {
                print "</td><td valign='top' width='20%' style='white-space:nowrap;'>\n";
                $break = false;
                $j = 1;
                print '<strong>' . $r['name'] . " (cont)</strong><br>\n";
            }
            if ($j == 6) {
                $break = true;
            }
            $realm = $r['realm_id'] + 100;
            $set = db_fetch_cell_prepared('SELECT realm_id 
				FROM user_auth_realm 
				WHERE user_id = ? 
				AND realm_id = ?', array(get_request_var_request('id', 0), $realm));
            if (!empty($set)) {
                $old_value = 'on';
            } else {
                $old_value = '';
            }
            unset($all_realms[$realm]);
            $pos = strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->') + 2 : 0;
            form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', !empty($_REQUEST['id']) ? 1 : 0);
            print '<br>';
            $j++;
        }
    }
    /* get the old PIA 1.x realms */
    if (sizeof($all_realms)) {
        if ($break) {
            print "</td><td valign='top' width='20%' style='white-space:nowrap;'>\n";
        }
        print "<strong>Legacy 1.x Plugins</strong><br>\n";
        foreach ($all_realms as $realm => $name) {
            if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array(get_request_var_request('id', 0), $realm))) > 0) {
                $old_value = 'on';
            } else {
                $old_value = '';
            }
            $pos = strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->') + 2 : 0;
            form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', !empty($_REQUEST['id']) ? 1 : 0);
            print '<br>';
        }
    }
    print "</td></tr></table></td></tr>\n";
    print "<script type='text/javascript'>function selectAllRealms(checked) { if (checked) { \$('input[id^=\"section\"]').prop('checked', true); } else { \$('input[id^=\"section\"]').prop('checked', false); } }</script>\n";
    html_end_box();
    form_hidden_box('action', 'user_edit', '');
    form_hidden_box('id', get_request_var_request('id'), '');
    form_hidden_box('tab', 'realms', '');
    form_hidden_box('save_component_realm_perms', '1', '');
    form_save_button('user_admin.php', 'return');
}