function mactrack_view_sites() {
	global $title, $colors, $config, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("site_id"));
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("page"));
	input_validate_input_number(get_request_var_request("rows"));
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["detail"])) {
		$_REQUEST["detail"] = sanitize_search_string(get_request_var("detail"));
	}

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
	}

	/* clean up sort_column */
	if (isset($_REQUEST["sort_column"])) {
		$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
	}

	/* clean up search string */
	if (isset($_REQUEST["sort_direction"])) {
		$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"]) || isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_sites_current_page");
		kill_session_var("sess_mactrack_view_sites_detail");
		kill_session_var("sess_mactrack_view_sites_device_type_id");
		kill_session_var("sess_mactrack_view_sites_site_id");
		kill_session_var("sess_mactrack_view_sites_filter");
		kill_session_var("sess_mactrack_view_sites_rows");
		kill_session_var("sess_mactrack_view_sites_sort_column");
		kill_session_var("sess_mactrack_view_sites_sort_direction");

		$_REQUEST["page"] = 1;

		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["filter"]);
			unset($_REQUEST["rows"]);
			unset($_REQUEST["device_type_id"]);
			unset($_REQUEST["site_id"]);
			unset($_REQUEST["detail"]);
			unset($_REQUEST["sort_column"]);
			unset($_REQUEST["sort_direction"]);
		}
	}else{
		/* if any of the settings changed, reset the page number */
		$changed = 0;
		$changed += mactrack_check_changed("device_type_id", "sess_mactrack_view_sites_device_type_id");
		$changed += mactrack_check_changed("site_id", "sess_mactrack_view_sites_site_id");
		$changed += mactrack_check_changed("filter", "sess_mactrack_view_sites_filter");
		$changed += mactrack_check_changed("rows", "sess_mactrack_view_sites_rows");
		$changed += mactrack_check_changed("detail", "sess_mactrack_view_sites_detail");

		if ($changed) {
			$_REQUEST["page"] = "1";
		}
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("page", "sess_mactrack_view_sites_current_page", "1");
	load_current_session_value("detail", "sess_mactrack_view_sites_detail", "false");
	load_current_session_value("device_type_id", "sess_mactrack_view_sites_device_type_id", "-1");
	load_current_session_value("site_id", "sess_mactrack_view_sites_site_id", "-1");
	load_current_session_value("filter", "sess_mactrack_view_sites_filter", "");
	load_current_session_value("rows", "sess_mactrack_view_sites_rows", "-1");
	load_current_session_value("sort_column", "sess_mactrack_view_sites_sort_column", "site_name");
	load_current_session_value("sort_direction", "sess_mactrack_view_sites_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"];
	}

	if (defined("URL_PATH")) {
		$webroot = URL_PATH;
	}else{
		$webroot = $config["url_path"];
	}

	mactrack_tabs();
	mactrack_view_header();
	mactrack_site_filter();
	mactrack_view_footer();
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$sql_where = "";

	$sites = mactrack_view_get_site_records($sql_where, $row_limit);

	if ($_REQUEST["detail"] == "false") {
		$total_rows = db_fetch_cell("SELECT
			COUNT(mac_track_sites.site_id)
			FROM mac_track_sites
			$sql_where");
	}else{
		$total_rows = sizeof(db_fetch_assoc("SELECT
			mac_track_device_types.device_type_id, mac_track_sites.site_name
			FROM (mac_track_device_types
			RIGHT JOIN mac_track_devices ON (mac_track_device_types.device_type_id = mac_track_devices.device_type_id))
			RIGHT JOIN mac_track_sites ON (mac_track_devices.site_id = mac_track_sites.site_id)
			$sql_where
			GROUP BY mac_track_sites.site_name, mac_track_device_types.device_type_id"));
	}

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

	if (isset($config["base_path"])) {
		if ($total_rows > 0) {
			$nav = "<tr bgcolor='#" . $colors["header"] . "'>
					<td colspan='11'>
						<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_view_sites.php?page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
								</td>\n
								<td align='center' class='textHeaderDark'>
									Showing Rows " . ($total_rows == 0 ? "None" : (($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_view_sites.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";
		}else{
			$nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>
						<td colspan='22'>
							<table width='100%' cellspacing='0' cellpadding='0' border='0'>
								<tr>
									<td align='center' class='textHeaderDark'>
										No Rows Found
									</td>\n
								</tr>
							</table>
						</td>
					</tr>\n";
		}
	}else{
		$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, 11, "mactrack_view_sites.php");
	}

	print $nav;

	if ($_REQUEST["detail"] == "false") {
		$display_text = array(
			"nosort" => array("Actions", ""),
			"site_name" => array("Site Name", "ASC"),
			"total_devices" => array("Devices", "DESC"),
			"total_ips" => array("Total IP's", "DESC"),
			"total_user_ports" => array("User Ports", "DESC"),
			"total_oper_ports" => array("User Ports Up", "DESC"),
			"total_macs" => array("MACS Found", "DESC"),
			"total_device_errors" => array("Device Errors", "DESC"));

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

		$i = 0;
		if (sizeof($sites) > 0) {
			foreach ($sites as $site) {
				form_alternate_row_color($colors["alternate"],$colors["light"],$i,'row_' . $site["site_id"]); $i++;
					?>
					<td width=140>
						<?php
						if (mactrack_authorized(2121)) {
							echo "<a href='" . $webroot . "plugins/mactrack/mactrack_sites.php?action=edit&site_id=" . $site['site_id'] . "' title='Edit Site'><img border='0' src='" . $webroot . "plugins/mactrack/images/edit_object.png'></a>";
							echo "<a href='#'><img id='r_" . $site["site_id"] . "' src='" . $config['url_path'] . "plugins/mactrack/images/rescan_site.gif' alt='' onMouseOver='style.cursor=\"pointer\"' onClick='site_scan(" . $site["site_id"] . ")' title='Rescan Site' border='0'></a>";
						}
						?>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_devices.php?report=devices&reset&site_id=" . $site['site_id'];?>' title='View Devices'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_devices.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_ips.php?report=ips&reset&site_id=" . $site['site_id'];?>' title='View IP Ranges'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_networks.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_arp.php?report=arp&reset&site_id=" . $site['site_id'];?>' title='View IP Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_ipaddresses.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=" . $site['site_id'];?>' title='View MAC Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_macs.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_interfaces.php?report=interfaces&reset&site=" . $site['site_id'];?>' title='View Interfaces'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_interfaces.gif'></a>
					</td>
					<td width=200>
						<?php print "<strong>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $site["site_name"]) : $site["site_name"]) . "</strong>";?>
					</td>
					<td><?php print number_format($site["total_devices"]);?></td>
					<td><?php print number_format($site["total_ips"]);?></td>
					<td><?php print number_format($site["total_user_ports"]);?></td>
					<td><?php print number_format($site["total_oper_ports"]);?></td>
					<td><?php print number_format($site["total_macs"]);?></td>
					<td><?php print ($site["total_device_errors"]);?></td>
				</tr>
				<?php
			}
		}else{
			print "<tr><td colspan='10'><em>No MacTrack Sites</em></td></tr>";
		}

		print $nav;

		html_end_box(false);

		mactrack_display_stats();
	}else{
		$display_text = array(
			"nosort" => array("Actions", ""),
			"site_name" => array("Site Name", "ASC"),
			"vendor" => array("Vendor", "ASC"),
			"description" => array("Device Type", "DESC"),
			"total_devices" => array("Total Devices", "DESC"),
			"sum_ips_total" => array("Total IP's", "DESC"),
			"sum_ports_total" => array("Total User Ports", "DESC"),
			"sum_ports_active" => array("Total Oper Ports", "DESC"),
			"sum_ports_trunk" => array("Total Trunks", "DESC"),
			"sum_macs_active" => array("MACS Found", "DESC"));

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

		$i = 0;
		if (sizeof($sites) > 0) {
			foreach ($sites as $site) {
				form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
					?>
					<td width=100>
						<?php
						if (mactrack_authorized(2121)) {
							echo "<a href='" . $webroot . "plugins/mactrack/mactrack_sites.php?action=edit&site_id=" . $site['site_id'] . "' title='Edit Site'><img border='0' src='" . $webroot . "plugins/mactrack/images/edit_object.png'></a>";
						}
						?>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_devices.php?report=devices&site_id=" . $site['site_id'] . "&device_type_id=" . $site['device_type_id'];?>&type_id=-1&status=-1&filter=' title='View Devices'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_devices.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_ips.php?report=ips&reset&site_id=" . $site['site_id'];?>' title='View IP Ranges'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_networks.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=" . $site['site_id'];?>' title='View MAC Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_macs.gif'></a>
						<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_interfaces.php?report=interfaces&reset&site=" . $site['site_id'];?>' title='View Interfaces'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_interfaces.gif'></a>
					</td>
					<td width=200>
						<?php print "<strong>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $site["site_name"]) : $site["site_name"]) . "</strong>";?>
					</td>
					<td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $site["vendor"]) : $site["vendor"]);?></td>
					<td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $site["description"]) : $site["description"]);?></td>
					<td><?php print number_format($site["total_devices"]);?></td>
					<td><?php print ($site["device_type"] == "1" ? "N/A" : number_format($site["sum_ips_total"]));?></td>
					<td><?php print ($site["device_type"] == "3" ? "N/A" : number_format($site["sum_ports_total"]));?></td>
					<td><?php print ($site["device_type"] == "3" ? "N/A" : number_format($site["sum_ports_active"]));?></td>
					<td><?php print ($site["device_type"] == "3" ? "N/A" : number_format($site["sum_ports_trunk"]));?></td>
					<td><?php print ($site["device_type"] == "3" ? "N/A" : number_format($site["sum_macs_active"]));?></td>
				</tr>
				<?php
			}
		}else{
			print "<tr><td colspan='10'><em>No MacTrack Sites</em></td></tr>";
		}

		print $nav;

		html_end_box(false);

		mactrack_display_stats();
	}

	print "<div id='response'></div>";
}
function mactrack_view_ip_ranges() {
	global $title, $colors, $config, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("site_id"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

	/* 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 (isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_ips_rows_selector");
		kill_session_var("sess_mactrack_view_ips_current_page");
		kill_session_var("sess_mactrack_view_ips_sort_column");
		kill_session_var("sess_mactrack_view_ips_sort_row");

		$_REQUEST["page"] = 1;
	}

	/* if any of the settings changed, reset the page number */
	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"]) || isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_ips_rows_selector");
		kill_session_var("sess_mactrack_view_ips_current_page");
		kill_session_var("sess_mactrack_view_ips_sort_column");
		kill_session_var("sess_mactrack_view_ips_sort_row");

		$_REQUEST["page"] = 1;

		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["rows"]);
			unset($_REQUEST["sort_column"]);
			unset($_REQUEST["sort_direction"]);
		}
	}else{
		$changed = 0;
		$changed += mactrack_check_changed("site_id", "sess_mactrack_view_ips_site_id");
		$changed += mactrack_check_changed("rows", "sess_mactrack_view_ips_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_view_ips_current_page", "1");
	load_current_session_value("site_id", "sess_mactrack_view_ips_site_id", "-1");
	load_current_session_value("rows", "sess_mactrack_view_ips_rows", "-1");
	load_current_session_value("sort_column", "sess_mactrack_view_ips_sort_column", "site_name");
	load_current_session_value("sort_direction", "sess_mactrack_view_ips_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"];
	}

	if (defined("URL_PATH")) {
		$webroot = URL_PATH;
	}else{
		$webroot = $config["url_path"];
	}

	mactrack_tabs();
	mactrack_view_header();
	mactrack_ips_filter();
	mactrack_view_footer();
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$sql_where = "";

	$ip_ranges = mactrack_view_get_ip_range_records($sql_where, $row_limit);

	$total_rows = db_fetch_cell("SELECT
		COUNT(mac_track_ip_ranges.ip_range)
		FROM mac_track_ip_ranges
		INNER JOIN mac_track_sites ON (mac_track_ip_ranges.site_id=mac_track_sites.site_id)
		$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_view_ips.php"));

	if (isset($config["base_path"])) {
		if ($total_rows > 0) {
			$nav = "<tr bgcolor='#" . $colors["header"] . "'>
					<td colspan='13'>
						<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_view_ips.php?page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
								</td>\n
								<td align='center' class='textHeaderDark'>
									Showing Rows " . ($total_rows == 0 ? "None" : (($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_view_ips.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";
		}else{
			$nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>
						<td colspan='22'>
							<table width='100%' cellspacing='0' cellpadding='0' border='0'>
								<tr>
									<td align='center' class='textHeaderDark'>
										No Rows Found
									</td>\n
								</tr>
							</table>
						</td>
					</tr>\n";
		}
	}else{
		$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, 13, "mactrack_view_sites.php");
	}

	print $nav;

	$display_text = array(
		"nosort" => array("Actions", ""),
		"site_name" => array("Site Name", "ASC"),
		"ip_range" => array("IP Range", "ASC"),
		"ips_current" => array("Current IP Addresses", "DESC"),
		"ips_current_date" => array("Current Date", "DESC"),
		"ips_max" => array("Maximum IP Addresses", "DESC"),
		"ips_max_date" => array("Maximum Date", "DESC"));

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

	$i = 0;
	if (sizeof($ip_ranges) > 0) {
		foreach ($ip_ranges as $ip_range) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td width=80>
					<a href='<?php print htmlspecialchars($webroot . "plugins/mactrack/mactrack_sites.php?action=edit&site_id=" . $ip_range['site_id']);?>' title='Edit Site'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/edit_object.png'></a>
					<a href='<?php print htmlspecialchars($webroot . "plugins/mactrack/mactrack_view_macs.php?report=macs&reset&ip_filter_type_id=3&ip_filter=" . $ip_range["ip_range"] . "." . "&device_id=-1&scan_date=3&site_id=" . $ip_range['site_id']);?>' title='View MAC Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_macs.gif'></a>
					<a href='<?php print htmlspecialchars($webroot . "plugins/mactrack/mactrack_view_arp.php?report=arp&reset&ip_filter_type_id=3&ip_filter=" . $ip_range["ip_range"] . "." . "&device_id=-1&scan_date=3&site_id=" . $ip_range['site_id']);?>' title='View IP Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_ipaddresses.gif'></a>
				</td>
				<td width=200>
					<?php print "<strong>" . $ip_range["site_name"] . "</strong>";?>
				</td>
				<td><?php print $ip_range["ip_range"] . ".*";?></td>
				<td><?php print number_format($ip_range["ips_current"]);?></td>
				<td><?php print $ip_range["ips_current_date"];?></td>
				<td><?php print number_format($ip_range["ips_max"]);?></td>
				<td><?php print $ip_range["ips_max_date"];?></td>
			</tr>
			<?php
		}
	}else{
		print "<tr><td colspan='10'><em>No MacTrack Site IP Ranges Found</em></td></tr>";
	}

	print $nav;

	html_end_box(false);

	mactrack_display_stats();
}
function mactrack_view_devices() {
	global $title, $report, $colors, $mactrack_search_types, $mactrack_device_types, $rows_selector, $config, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("site_id"));
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("type_id"));
	input_validate_input_number(get_request_var_request("device_type_id"));
	input_validate_input_number(get_request_var_request("status"));
	input_validate_input_number(get_request_var_request("page"));
	input_validate_input_number(get_request_var_request("rows"));
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
	}

	/* clean up sort_column */
	if (isset($_REQUEST["sort_column"])) {
		$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
	}

	/* clean up search string */
	if (isset($_REQUEST["sort_direction"])) {
		$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"]) || isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_device_current_page");
		kill_session_var("sess_mactrack_view_device_filter");
		kill_session_var("sess_mactrack_view_device_site_id");
		kill_session_var("sess_mactrack_view_device_type_id");
		kill_session_var("sess_mactrack_view_device_rows");
		kill_session_var("sess_mactrack_view_device_device_type_id");
		kill_session_var("sess_mactrack_view_device_status");
		kill_session_var("sess_mactrack_view_device_sort_column");
		kill_session_var("sess_mactrack_view_device_sort_direction");

		$_REQUEST["page"] = 1;

		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["filter"]);
			unset($_REQUEST["site_id"]);
			unset($_REQUEST["type_id"]);
			unset($_REQUEST["rows"]);
			unset($_REQUEST["device_type_id"]);
			unset($_REQUEST["status"]);
			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_view_device_filter");
		$changed += mactrack_check_changed("site_id", "sess_mactrack_view_device_site_id");
		$changed += mactrack_check_changed("rows", "sess_mactrack_view_device_rows");
		$changed += mactrack_check_changed("type_id", "sess_mactrack_view_device_type_id");
		$changed += mactrack_check_changed("device_type_id", "sess_mactrack_view_device_device_type_id");
		$changed += mactrack_check_changed("status", "sess_mactrack_view_device_status");

		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_view_device_current_page", "1");
	load_current_session_value("filter",         "sess_mactrack_view_device_filter", "");
	load_current_session_value("site_id",        "sess_mactrack_view_device_site_id", "-1");
	load_current_session_value("type_id",        "sess_mactrack_view_device_type_id", "-1");
	load_current_session_value("device_type_id", "sess_mactrack_view_device_device_type_id", "-1");
	load_current_session_value("status",         "sess_mactrack_view_device_status", "-1");
	load_current_session_value("rows",           "sess_mactrack_view_device_rows", "-1");
	load_current_session_value("sort_column",    "sess_mactrack_view_device_sort_column", "site_name");
	load_current_session_value("sort_direction", "sess_mactrack_view_device_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"];
	}

	if (defined("URL_PATH")) {
		$webroot = URL_PATH;
	}else{
		$webroot = $config["url_path"];
	}

	mactrack_tabs();
	mactrack_view_header();
	mactrack_device_filter2();
	mactrack_view_footer();
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$sql_where = "";

	$devices = mactrack_view_get_device_records($sql_where, $row_limit);

	$total_rows = db_fetch_cell("SELECT
		COUNT(mac_track_devices.device_id)
		FROM mac_track_sites
		RIGHT JOIN mac_track_devices ON mac_track_devices.site_id = mac_track_sites.site_id
		LEFT JOIN mac_track_device_types ON (mac_track_device_types.device_type_id=mac_track_devices.device_type_id)
		$sql_where");

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_devices.php?report=devices");

	if (isset($config["base_path"])) {
		if ($total_rows > 0) {
			$nav = "<tr bgcolor='#" . $colors["header"] . "'>
					<td colspan='13'>
						<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_view_devices.php?report=devices&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
								</td>\n
								<td align='center' class='textHeaderDark'>
									Showing Rows " . ($total_rows == 0 ? "None" : (($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_view_devices.php?report=devices&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";
		}else{
			$nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>
						<td colspan='22'>
							<table width='100%' cellspacing='0' cellpadding='0' border='0'>
								<tr>
									<td align='center' class='textHeaderDark'>
										No Rows Found
									</td>\n
								</tr>
							</table>
						</td>
					</tr>\n";
		}
	}else{
		$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, 13, "mactrack_view_sites.php");
	}

	print $nav;

	$display_text = array(
		"nosort" => array("Actions", ""),
		"device_name" => array("Device Name", "ASC"),
		"site_name" => array("Site Name", "ASC"),
		"snmp_status" => array("Status", "ASC"),
		"hostname" => array("Hostname", "ASC"),
		"device_type" => array("Device Type", "ASC"),
		"ips_total" => array("Total IP's", "DESC"),
		"ports_total" => array("User Ports", "DESC"),
		"ports_active" => array("User Ports Up", "DESC"),
		"ports_trunk" => array("Trunk Ports", "DESC"),
		"macs_active" => array("Active Macs", "DESC"),
		"vlans_total" => array("Total VLAN's", "DESC"),
		"last_runduration" => array("Last Duration", "DESC"));

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

	$i = 0;
	if (sizeof($devices) > 0) {
		foreach ($devices as $device) {
			$hostinfo["hostname"] = $device["hostname"];
			$hostinfo["user"]     = $device["user_name"];
			switch($device["term_type"]) {
			case 0:
				$hostinfo["transport"] = "none";
				break;
			case 1:
				$hostinfo["transport"] = "telnet";
				break;
			case 2:
				$hostinfo["transport"] = "ssh";
				break;
			case 3:
				$hostinfo["transport"] = "http";
				break;
			case 4:
				$hostinfo["transport"] = "https";
				break;
			}

			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td width=100>
					<?php if (mactrack_authorized(2121)) {?>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_devices.php?action=edit&device_id=" . $device['device_id'];?>' title='Edit Device'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/edit_object.png'></a>
					<?php api_plugin_hook_function('remote_link', $hostinfo); } ?>
					<?php if ($device["host_id"] > 0) {?>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=&host_id=" . $device["host_id"] . "&graph_template_id=0&filter=";?>' title='View Graphs'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_graphs.gif'></a>
					<?php }else{?>
					<img title='Device Not Mapped to Cacti Device' border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_graphs_disabled.gif'>
					<?php }?>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=" . $_REQUEST["site_id"] . "&device_id=" . $device['device_id'];?>' title='View MAC Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_macs.gif'></a>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_interfaces.php?report=interfaces&reset&site=" . $_REQUEST["site_id"] . "&device=" . $device['device_id'];?>' title='View Interfaces'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_interfaces.gif'></a>
				</td>
				<td width=150>
					<?php print "<strong>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["device_name"]) : $device["device_name"]) . "</strong>";?>
				</td>
				<td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["site_name"]) : $device["site_name"]);?></td>
				<td><?php print get_colored_device_status(($device["disabled"] == "on" ? true : false), $device["snmp_status"]);?></td>
				<td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["hostname"]) : $device["hostname"]);?></td>
				<td><?php print $device["device_type"];?></td>
				<td><?php print ($device["scan_type"] == "1" ? "N/A" : $device["ips_total"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_total"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_active"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_trunk"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["macs_active"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["vlans_total"]);?></td>
				<td><?php print number_format($device["last_runduration"], 1);?></td>
			</tr>
			<?php
		}
	}else{
		print "<tr><td colspan='10'><em>No MacTrack Devices</em></td></tr>";
	}

	print $nav;

	html_end_box(false);

	mactrack_display_stats();
}
function mactrack_view_ips() {
	global $title, $report, $colors, $mactrack_search_types, $rows_selector, $config;
	global $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("site_id"));
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("mac_filter_type_id"));
	input_validate_input_number(get_request_var_request("ip_filter_type_id"));
	input_validate_input_number(get_request_var_request("rows"));
	input_validate_input_number(get_request_var_request("authorized"));
	input_validate_input_number(get_request_var_request("vlan"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

	/* clean up filter string */
	if (isset($_REQUEST["ip_filter"])) {
		$_REQUEST["ip_filter"] = sanitize_search_string(get_request_var("ip_filter"));
	}

	/* clean up search string */
	if (isset($_REQUEST["mac_filter"])) {
		$_REQUEST["mac_filter"] = sanitize_search_string(get_request_var("mac_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 (isset($_REQUEST["mac_filter_type_id"])) {
		if ($_REQUEST["mac_filter_type_id"] == 1) {
			unset($_REQUEST["mac_filter"]);
		}
	}

	/* clean up search string */
	if (isset($_REQUEST["scan_date"])) {
		$_REQUEST["scan_date"] = sanitize_search_string(get_request_var("scan_date"));
	}

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
	}

	if (isset($_REQUEST["ip_filter_type_id"])) {
		if ($_REQUEST["ip_filter_type_id"] == 1) {
			unset($_REQUEST["ip_filter"]);
		}
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"]) || isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_ipads_current_page");
		kill_session_var("sess_mactrack_view_ipads_filter");
		kill_session_var("sess_mactrack_view_ipads_mac_filter_type_id");
		kill_session_var("sess_mactrack_view_ipads_mac_filter");
		kill_session_var("sess_mactrack_view_ipads_ip_filter_type_id");
		kill_session_var("sess_mactrack_view_ipads_ip_filter");
		kill_session_var("sess_mactrack_view_ipads_rows_selector");
		kill_session_var("sess_mactrack_view_ipads_site_id");
		kill_session_var("sess_mactrack_view_ipads_device_id");
		kill_session_var("sess_mactrack_view_ipads_sort_column");
		kill_session_var("sess_mactrack_view_ipads_sort_direction");

		$_REQUEST["page"] = 1;

		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["mac_filter"]);
			unset($_REQUEST["mac_filter_type_id"]);
			unset($_REQUEST["ip_filter"]);
			unset($_REQUEST["ip_filter_type_id"]);
			unset($_REQUEST["rows"]);
			unset($_REQUEST["filter"]);
			unset($_REQUEST["site_id"]);
			unset($_REQUEST["device_id"]);
			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("mac_filter",         "sess_mactrack_view_ipads_filter");
		$changed += mactrack_check_changed("mac_filter_type_id", "sess_mactrack_view_ipads_mac_filter_type_id");
		$changed += mactrack_check_changed("ip_filter",          "sess_mactrack_view_ipads_mac_ip_filter");
		$changed += mactrack_check_changed("ip_filter_type_id",  "sess_mactrack_view_ipads_ip_filter_type_id");
		$changed += mactrack_check_changed("filter",             "sess_mactrack_view_ipads_ip_filter");
		$changed += mactrack_check_changed("rows",               "sess_mactrack_view_ipads_rows_selector");
		$changed += mactrack_check_changed("site_id",            "sess_mactrack_view_ipads_site_id");
		$changed += mactrack_check_changed("device_id",          "sess_mactrack_view_ipads_device_id");

		if ($changed) {
			$_REQUEST["page"] = "1";
		}
	}

	/* reset some things if the user has made changes */
	if ((!empty($_REQUEST["site_id"]))&&(!empty($_SESSION["sess_mactrack_view_ipads_site_id"]))) {
		if ($_REQUEST["site_id"] <> $_SESSION["sess_mactrack_view_ipads_site_id"]) {
			$_REQUEST["device_id"] = "-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_view_ipads_current_page", "1");
	load_current_session_value("mac_filter",         "sess_mactrack_view_ipads_mac_filter", "");
	load_current_session_value("mac_filter_type_id", "sess_mactrack_view_ipads_mac_filter_type_id", "1");
	load_current_session_value("ip_filter",          "sess_mactrack_view_ipads_ip_filter", "");
	load_current_session_value("ip_filter_type_id",  "sess_mactrack_view_ipads_ip_filter_type_id", "1");
	load_current_session_value("filter",             "sess_mactrack_view_ipads_filter", "");
	load_current_session_value("rows",               "sess_mactrack_view_ipads_rows_selector", "-1");
	load_current_session_value("site_id",            "sess_mactrack_view_ipads_site_id", "-1");
	load_current_session_value("device_id",          "sess_mactrack_view_ipads_device_id", "-1");
	load_current_session_value("sort_column",        "sess_mactrack_view_ipads_sort_column", "device_name");
	load_current_session_value("sort_direction",     "sess_mactrack_view_ipads_sort_direction", "ASC");

	mactrack_tabs();
	mactrack_view_header();
	mactrack_ip_address_filter();
	mactrack_view_footer();
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$sql_where = "";

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

	$port_results = mactrack_view_get_ip_records($sql_where, TRUE, $row_limit);

	/* prevent table scans, either a device or site must be selected */
	if (!strlen($sql_where)) {
		$total_rows = 0;
	}elseif ($_REQUEST["rows"] == 1) {
		$rows_query_string = "SELECT
			COUNT(mac_track_ips.device_id)
			FROM mac_track_ips
			LEFT JOIN mac_track_sites ON (mac_track_ips.site_id=mac_track_sites.site_id)
			LEFT JOIN mac_track_oui_database ON (mac_track_oui_database.vendor_mac=SUBSTRING(mac_track_ips.mac_address,1,8))
			$sql_where";

		$total_rows = db_fetch_cell($rows_query_string);
	}else{
		$rows_query_string = "SELECT
			COUNT(DISTINCT device_id, mac_address, port_number, ip_address)
			FROM mac_track_ips
			LEFT JOIN mac_track_sites ON (mac_track_ips.site_id=mac_track_sites.site_id)
			LEFT JOIN mac_track_oui_database ON (mac_track_oui_database.vendor_mac=SUBSTRING(mac_track_ips.mac_address,1,8))
			$sql_where";

		$total_rows = db_fetch_cell($rows_query_string);
	}

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_arp.php?report=arp");

	if (isset($config["base_path"])) {
		if ($total_rows > 0) {
			$nav = "<tr bgcolor='#" . $colors["header"] . "'>
						<td colspan='13'>
							<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_view_arp.php?report=arp&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
									</td>\n
									<td align='center' class='textHeaderDark'>
										Showing Rows " . ($total_rows == 0 ? "None" : (($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_view_arp.php?report=arp&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";
		}else{
			$nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>
						<td colspan='22'>
							<table width='100%' cellspacing='0' cellpadding='0' border='0'>
								<tr>
									<td align='center' class='textHeaderDark'>
										No Rows Found
									</td>\n
								</tr>
							</table>
						</td>
					</tr>\n";
		}
	}else{
		$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, 13, "mactrack_view_arp.php?report=arp");
	}

	print $nav;

	if (strlen(read_config_option("mt_reverse_dns")) > 0) {
		if ($_REQUEST["rows"] == 1) {
			$display_text = array(
				"device_name" => array("Switch Name", "ASC"),
				"hostname" => array("Switch Hostname", "ASC"),
				"ip_address" => array("ED IP Address", "ASC"),
				"dns_hostname" => array("ED DNS Hostname", "ASC"),
				"mac_address" => array("ED MAC Address", "ASC"),
				"vendor_name" => array("Vendor Name", "ASC"),
				"port_number" => array("Port Number", "DESC"));
		}else{
			$display_text = array(
				"device_name" => array("Switch Name", "ASC"),
				"hostname" => array("Switch Hostname", "ASC"),
				"ip_address" => array("ED IP Address", "ASC"),
				"dns_hostname" => array("ED DNS Hostname", "ASC"),
				"mac_address" => array("ED MAC Address", "ASC"),
				"vendor_name" => array("Vendor Name", "ASC"),
				"port_number" => array("Port Number", "DESC"));
		}

		html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
	}else{
		if ($_REQUEST["rows"] == 1) {
			$display_text = array(
				"device_name" => array("Switch Name", "ASC"),
				"hostname" => array("Switch Hostname", "ASC"),
				"ip_address" => array("ED IP Address", "ASC"),
				"mac_address" => array("ED MAC Address", "ASC"),
				"vendor_name" => array("Vendor Name", "ASC"),
				"port_number" => array("Port Number", "DESC"));
		}else{
			$display_text = array(
				"device_name" => array("Switch Device", "ASC"),
				"hostname" => array("Switch Hostname", "ASC"),
				"ip_address" => array("ED IP Address", "ASC"),
				"mac_address" => array("ED MAC Address", "ASC"),
				"vendor_name" => array("Vendor Name", "ASC"),
				"port_number" => array("Port Number", "DESC"));
		}

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

	$i = 0;
	$delim = read_config_option("mt_mac_delim");
	if (sizeof($port_results) > 0) {
		foreach ($port_results as $port_result) {
			form_alternate_row_color($colors["alternate"], $colors["light"], $i); $i++;
			echo "<td>" . $port_result["device_name"] . "</td>";
			echo "<td>" . $port_result["hostname"] . "</td>";
			echo "<td>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["ip_address"]) : $port_result["ip_address"])  . "</td>";
			if (strlen(read_config_option("mt_reverse_dns")) > 0) {
				echo "<td>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["dns_hostname"]) : $port_result["dns_hostname"]) . "</td>";
			}
			echo "<td>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["mac_address"]) : $port_result["mac_address"]) . "</td>";
			echo "<td>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["vendor_name"]) : $port_result["vendor_name"]) . "</td>";
			echo "<td>" . $port_result["port_number"] . "</td>";
			form_end_row();
		}
	}else{
		if ($_REQUEST["site_id"] == -1 && $_REQUEST["device_id"] == -1) {
			print "<tr><td colspan='10'><em>You must choose a Site, Device or other search criteria</em></td></tr>";
		}else{
			print "<tr><td colspan='10'><em>No MacTrack IP Results</em></td></tr>";
		}
	}

	print $nav;

	html_end_box(false);

	mactrack_display_stats();
}