コード例 #1
0
ファイル: import.php プロジェクト: TaylorMonacelli/phplib
 } else {
     $hasdata[$k] = true;
     if ($pref_date == "us") {
         if (!($dt = strtotime($v))) {
             $dt = strtotime_uk($v);
         }
     } else {
         if (!($dt = strtotime_uk($v))) {
             $dt = strtotime($v);
         }
     }
     if ($v == "0" or !$dt) {
         $datecol[$k] = false;
     } else {
         if (strlen($v) > 11) {
             if ($fmt = date_time_format($v)) {
                 $date_time_fmt[$k][$fmt]++;
             }
         }
         if ($fmt = date_format($v)) {
             $date_fmt[$k][$fmt]++;
         }
         if ($fmt = time_format($v)) {
             $time_fmt[$k][$fmt]++;
         }
     }
     $len[$k] = max($len[$k], strlen($v));
     if (preg_match('/\\./', $v) > 1) {
         $integer[$k] = false;
         $float[$k] = false;
         $money[$k] = false;
コード例 #2
0
ファイル: top_header.php プロジェクト: songchin/Cacti
	</div>
	<div id='navbrcrumb'>
		<div style='float:left;'>
			<?php print draw_navigation_text() . "\n";?>
		</div>
		<div style='float:right;'>
			<a href="<?php echo cacti_wiki_url();?>" target="_blank">
			<img src="<?php echo CACTI_URL_PATH; ?>images/help.gif" title="<?php print __("Help");?>" alt="<?php print __("Help");?>" align="top">
			</a>
		</div>
		<div style='float:right'>
		<?php	if (read_config_option("auth_method") != 0) {
					if(read_config_option('i18n_timezone_support') != 0) {
						?><a href="#" id="menu_timezones" rel="<?php echo CACTI_URL_PATH; ?>"><span id="date_time_format"><strong><?php echo __date("D, " . date_time_format() . " T");?></strong></span></a><?php
					}else {
						?><span id="date_time_format"><strong><?php echo __date("D, " . date_time_format() . " T");?></strong></span><?php
					}
				?>
					&nbsp;&nbsp;&nbsp;<?php print __("Logged in as");?> <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="<?php echo CACTI_URL_PATH; ?>logout.php"><?php print __("Logout");?></a>)
		<?php } ?>
		</div>
		<?php if(read_config_option('i18n_support') != 0) {?>
		<div style='float:right;'>
			<a href="#" id="menu_languages" rel="<?php echo CACTI_URL_PATH; ?>"><img src="<?php echo CACTI_URL_PATH; ?>images/flag_icons/<?php print CACTI_COUNTRY;?>.gif" align="top">&nbsp;<?php print $lang2locale[CACTI_LOCALE]["language"];?></a>
		</div>
		<div id="loading" style="display:none; float:right"><img src="<?php echo CACTI_URL_PATH; ?>images/load_small.gif" align="top" alt="<?php print __("loading");?>">LOADING</div>
		<?php }?>
	</div>
</div>
<div id='wrapper' style='opacity:0;'>
	<div id='menu'>
コード例 #3
0
ファイル: rrd.php プロジェクト: songchin/Cacti
function rrdtool_info2html($info_array, $diff=array()) {
	global $colors;

	html_start_box("<strong>" . __("RRD File Information") . "</strong>", "100", $colors["header"], 0, "center", "");

	# header data
	$header_items = array(__("Header"), '');
	print "<tr><td>";
	html_header($header_items, 1, false, 'info_header');
	# add human readable timestamp
	if (isset($info_array["last_update"])) {
		$info_array["last_update"] .= " [" . date(date_time_format(), $info_array["last_update"]) . "]";
	}
	$loop = array(
		"filename" 		=> $info_array["filename"],
		"rrd_version"	=> $info_array["rrd_version"],
		"step" 			=> $info_array["step"],
		"last_update"	=> $info_array["last_update"]);
	foreach ($loop as $key => $value) {
		form_alternate_row_color($key, true);
		form_selectable_cell($key, 'key');
		form_selectable_cell($value, 'value', "", ((isset($diff[$key]) ? "textError" : "")));
		form_end_row();
	}
	form_end_table();

	# data sources
	$header_items = array(__("Data Source Items"), __('Type'), __('Minimal Heartbeat'), __('Min'), __('Max'), __('Last DS'), __('Value'), __('Unkown Sec'));
	print "<tr><td>";
	html_header($header_items, 1, false, 'info_ds');
	if (sizeof($info_array["ds"]) > 0) {
		foreach ($info_array["ds"] as $key => $value) {
			form_alternate_row_color('line' . $key, true);
			form_selectable_cell($key, 																			'name', 				"", (isset($diff["ds"][$key]["error"]) 				? "textError" : ""));
			form_selectable_cell((isset($value['type']) 				? $value['type'] : ''), 				'type', 				"", (isset($diff["ds"][$key]['type']) 				? "textError" : ""));
			form_selectable_cell((isset($value['minimal_heartbeat']) 	? $value['minimal_heartbeat'] : ''), 	'minimal_heartbeat', 	"", (isset($diff["ds"][$key]['minimal_heartbeat'])	? "textError" : ""));
			form_selectable_cell((isset($value['min']) 					? floatval($value['min']) : ''), 		'min', 					"", (isset($diff["ds"][$key]['min']) 				? "textError" : ""));
			form_selectable_cell((isset($value['max']) 					? floatval($value['max']) : ''), 		'max', 					"", (isset($diff["ds"][$key]['max']) 				? "textError" : ""));
			form_selectable_cell((isset($value['last_ds']) 				? $value['last_ds'] : ''), 				'last_ds');
			form_selectable_cell((isset($value['value']) 				? floatval($value['value']) : ''), 		'value');
			form_selectable_cell((isset($value['unknown_sec']) 			? $value['unknown_sec'] : ''), 			'unknown_sec');
			form_end_row();
		}
		form_end_table();
	}


	# round robin archive
	$header_items = array(__("Round Robin Archive"), __('Consolidation Function'), __('Rows'), __('Cur Row'), __('PDP per Row'), __('X Files Factor'), __('CDP Prep Value (0)'), __('CDP Unknown Datapoints (0)'));
	print "<tr><td>";
	html_header($header_items, 1, false, 'info_rra');
	if (sizeof($info_array['rra']) > 0) {
		foreach ($info_array['rra'] as $key => $value) {
			form_alternate_row_color('line_' . $key, true);
			form_selectable_cell($key, 																										'name', 			"", (isset($diff['rra'][$key]["error"]) ? "textError" : ""));
			form_selectable_cell((isset($value['cf']) 								? $value['cf'] : ''), 									'cf');
			form_selectable_cell((isset($value['rows']) 							? $value['rows'] : ''), 								'rows', 			"", (isset($diff['rra'][$key]['rows']) 	? "textError" : ""));
			form_selectable_cell((isset($value['cur_row']) 							? $value['cur_row'] : ''), 								'cur_row');
			form_selectable_cell((isset($value['pdp_per_row']) 						? $value['pdp_per_row'] : ''), 							'pdp_per_row');
			form_selectable_cell((isset($value['xff']) 								? floatval($value['xff']) : ''), 						'xff', 				"", (isset($diff['rra'][$key]['xff']) 	? "textError" : ""));
			form_selectable_cell((isset($value['cdp_prep'][0]['value']) 			? (strtolower($value['cdp_prep'][0]['value']) == "nan") ? $value['cdp_prep'][0]['value'] : floatval($value['cdp_prep'][0]['value']) : ''), 'value');
			form_selectable_cell((isset($value['cdp_prep'][0]['unknown_datapoints'])? $value['cdp_prep'][0]['unknown_datapoints'] : ''), 	'unknown_datapoints');
			form_end_row();
		}
		form_end_table();
	}


	print "</table></td></tr>";		/* end of html_header */


	html_end_box();
}
コード例 #4
0
ファイル: graph_export.php プロジェクト: teddywen/cacti
function tree_export()
{
    global $config;
    include_once $config["base_path"] . "/lib/time.php";
    $total_graphs_created = 0;
    /* set the user to utilize for establishing export permissions */
    $export_user = read_config_option("export_user_id");
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id='" . $export_user . "'");
    $cacti_root_path = $config["base_path"];
    $cacti_export_path = read_config_option("path_html_export");
    /* if the selected user has default rights, show all the graphs */
    if ($current_user["policy_trees"] == 1) {
        $trees = db_fetch_assoc("SELECT\n\t\t\tid,\n\t\t\tname\n\t\t\tFROM graph_tree");
    } else {
        /* otherwise, show only those tree's that the user has access to */
        $trees = db_fetch_assoc("SELECT\n\t\t\tgraph_tree.id AS id,\n\t\t\tgraph_tree.name AS name\n\t\t\tFROM user_auth_perms\n\t\t\tINNER JOIN graph_tree\n\t\t\tON (user_auth_perms.item_id = graph_tree.id)\n\t\t\tWHERE user_auth_perms.user_id ='" . $current_user["id"] . "'");
    }
    /* if tree isolation is off, create the treeview and graphs directories for the initial hierarchy */
    if (read_config_option("export_tree_isolation") == "off") {
        /* create directory structure */
        create_export_directory_structure($cacti_root_path, $cacti_export_path);
        /* export graphs */
        foreach ($trees as $tree) {
            $total_graphs_created += export_tree_graphs_and_graph_html("", $tree["id"]);
        }
        /* build base index files first */
        $stats["timestamp"] = date(date_time_format());
        $stats["total_graphs_created"] = $total_graphs_created;
        build_html_file(0, "index", $stats);
        foreach ($trees as $tree) {
            $leaf["tree_id"] = $tree["id"];
            $leaf["title"] = "";
            $leaf["name"] = $tree["name"];
            build_html_file($leaf, "tree");
            /* build remainder of html files */
            export_tree_html("", clean_up_export_name($tree["name"]) . "_index.html", $tree["id"], 0);
        }
    } else {
        /* now let's populate all the sub trees */
        foreach ($trees as $tree) {
            /* create the base directory */
            if (!is_dir("{$cacti_export_path}/" . clean_up_export_name($tree["name"]))) {
                if (!mkdir("{$cacti_export_path}/" . clean_up_export_name($tree["name"]), 0755, true)) {
                    export_fatal("Create directory '" . clean_up_export_name($tree["name"]) . "' failed.  Can not continue");
                }
            }
            create_export_directory_structure($cacti_root_path, $cacti_export_path . "/" . clean_up_export_name($tree["name"]));
            /* build base index files first */
            $stats["timestamp"] = date(date_time_format());
            $stats["total_graphs_created"] = $total_graphs_created;
            build_html_file($tree["id"], "index", $stats);
            $leaf["tree_id"] = $tree["id"];
            $leaf["title"] = "";
            $leaf["name"] = $tree["name"];
            build_html_file($leaf, "tree");
            $total_graphs_created += export_tree_graphs_and_graph_html(clean_up_export_name($tree["name"]), $tree["id"]);
            export_tree_html("graphs", "index.html", $tree["id"], 0);
        }
    }
    return $total_graphs_created;
}
コード例 #5
0
ファイル: device_form.php プロジェクト: songchin/Cacti
function device() {
	global $colors, $item_rows;
	require(CACTI_BASE_PATH . "/include/device/device_arrays.php");

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("template_id"));
	input_validate_input_number(get_request_var_request("page"));
	input_validate_input_number(get_request_var_request("status"));
	input_validate_input_number(get_request_var_request("rows"));
	input_validate_input_number(get_request_var_request("poller"));
	input_validate_input_number(get_request_var_request("site"));
	/* ==================================================== */

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

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

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

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_device_current_page");
		kill_session_var("sess_device_filter");
		if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) {
			kill_session_var("sess_device_template_id");
		}
		kill_session_var("sess_device_status");
		kill_session_var("sess_device_rows");
		kill_session_var("sess_device_poller");
		kill_session_var("sess_device_site");
		kill_session_var("sess_device_sort_column");
		kill_session_var("sess_device_sort_direction");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) {
			unset($_REQUEST["template_id"]);
		}
		unset($_REQUEST["status"]);
		unset($_REQUEST["poller"]);
		unset($_REQUEST["site"]);
		unset($_REQUEST["rows"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
	}

	/* let's see if someone changed an important setting */
	$changed  = FALSE;
	$changed += check_changed("filter",      "sess_device_filter");
	$changed += check_changed("template_id", "sess_device_template_id");
	$changed += check_changed("status",      "sess_device_status");
	$changed += check_changed("rows",        "sess_device_rows");
	$changed += check_changed("poller",      "sess_device_poller");
	$changed += check_changed("site",        "sess_device_site");
	$changed += check_changed("device_id",	 "sess_ds_device_id");

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

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("page", "sess_device_current_page", "1");
	load_current_session_value("filter", "sess_device_filter", "");
	load_current_session_value("template_id", "sess_device_template_id", "-1");
	load_current_session_value("status", "sess_device_status", "-1");
	load_current_session_value("rows", "sess_device_rows", "-1");
	load_current_session_value("poller", "sess_device_poller", "-1");
	load_current_session_value("site", "sess_device_site", "-1");
	load_current_session_value("sort_column", "sess_device_sort_column", "description");
	load_current_session_value("sort_direction", "sess_device_sort_direction", "ASC");

	?>
	<script type="text/javascript">
	<!--

	function clearDeviceFilterChange(objForm) {
		<?php print (isset($_REQUEST["tab"]) ? "strURL = '?template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "&action=edit&amp;action=edit&tab=" . $_REQUEST["tab"] . "';" : "strURL = '?template_id=-1';");?>
		strURL = strURL + '&filter=';
		strURL = strURL + '&rows=-1';
		document.location = strURL;
	}

	function applyDeviceFilterChange(objForm) {
		if (objForm.template_id.value) {
			strURL = '?template_id=' + objForm.template_id.value;
			strURL = strURL + '&filter=' + objForm.filter.value;
		}else{
			strURL = '?filter=' + objForm.filter.value;
		}
		strURL = strURL + '&status=' + objForm.status.value;
		strURL = strURL + '&rows=' + objForm.rows.value;
		strURL = strURL + '&poller=' + objForm.poller.value;
		strURL = strURL + '&site=' + objForm.site.value;
		<?php print (isset($_REQUEST["tab"]) ? "strURL = strURL + '&id=' + objForm.template_id.value + '&action=edit&action=edit&tab=" . $_REQUEST["tab"] . "';" : "");?>
		document.location = strURL;
	}

	-->
	</script>
	<?php

	html_start_box("<strong>" . __("Devices") . "</strong>", "100", $colors["header"], "3", "center", "devices.php?action=edit&template_id=" . $_REQUEST["template_id"] . "&status=" . $_REQUEST["status"], true);
	?>
	<tr class='rowAlternate2'>
		<td>
			<form action="devices.php" name="form_devices" method="post">
			<table cellpadding="0" cellspacing="3">
				<tr>
					<td class="nw50">
						&nbsp;<?php print __("Type:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="template_id" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option>
							<option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>><?php print __("None");?></option>
							<?php
							$device_templates = db_fetch_assoc("select id,name from device_template order by name");

							if (sizeof($device_templates) > 0) {
							foreach ($device_templates as $device_template) {
								print "<option value='" . $device_template["id"] . "'"; if (get_request_var_request("template_id") == $device_template["id"]) { print " selected"; } print ">" . $device_template["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Status:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="status" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("status") == "-1") {?> selected<?php }?>><?php print __("Any");?></option>
							<option value="-3"<?php if (get_request_var_request("status") == "-3") {?> selected<?php }?>><?php print __("Enabled");?></option>
							<option value="-2"<?php if (get_request_var_request("status") == "-2") {?> selected<?php }?>><?php print __("Disabled");?></option>
							<option value="-4"<?php if (get_request_var_request("status") == "-4") {?> selected<?php }?>><?php print __("Not Up");?></option>
							<option value="3"<?php if (get_request_var_request("status") == "3") {?> selected<?php }?>><?php print __("Up");?></option>
							<option value="1"<?php if (get_request_var_request("status") == "1") {?> selected<?php }?>><?php print __("Down");?></option>
							<option value="2"<?php if (get_request_var_request("status") == "2") {?> selected<?php }?>><?php print __("Recovering");?></option>
							<option value="0"<?php if (get_request_var_request("status") == "0") {?> selected<?php }?>><?php print __("Unknown");?></option>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Rows:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="rows" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>><?php print __("Default");?></option>
							<?php
							if (sizeof($item_rows) > 0) {
							foreach ($item_rows as $key => $value) {
								print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n";
							}
							}
							?>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="0" cellspacing="3">
				<tr>
					<td class="nw50">
						&nbsp;<?php print __("Site:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="site" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("site") == "-1") {?> selected<?php }?>><?php print __("All");?></option>
							<option value="0"<?php if (get_request_var_request("site") == "0") {?> selected<?php }?>><?php print __("Not Defined");?></option>
							<?php
							$sites = db_fetch_assoc("select id,name from sites order by name");

							if (sizeof($sites)) {
							foreach ($sites as $site) {
								print "<option value='" . $site["id"] . "'"; if (get_request_var_request("site") == $site["id"]) { print " selected"; } print ">" . $site["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Poller:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="poller" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("poller") == "-1") {?> selected<?php }?>><?php print __("All");?></option>
							<option value="0"<?php if (get_request_var_request("poller") == "0") {?> selected<?php }?>><?php print __("System Default");?></option>
							<?php
							$pollers = db_fetch_assoc("select id,description AS name from poller order by description");

							if (sizeof($pollers)) {
							foreach ($pollers as $poller) {
								print "<option value='" . $poller["id"] . "'"; if (get_request_var_request("poller") == $poller["id"]) { print " selected"; } print ">" . $poller["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Search:");?>&nbsp;
					</td>
					<td class="w1">
						<input type="text" name="filter" size="20" value="<?php print $_REQUEST["filter"];?>">
					</td>
					<td class="nw120">
						&nbsp;<input type="submit" Value="<?php print __("Go");?>" name="go" align="middle">
						<input type="button" Value="<?php print __("Clear");?>" name="clear_x" align="middle" onClick="clearDeviceFilterChange(document.form_devices)">
					</td>
				</tr>
			</table>
			<div><input type='hidden' name='page' value='1'></div>
			</form>
		</td>
	</tr>
	<?php
	html_end_box(false);

	/* form the 'where' clause for our main sql query */
	if (strlen(get_request_var_request("filter"))) {
		$sql_where = "where (device.hostname like '%%" . $_REQUEST["filter"] . "%%' OR device.description like '%%" . $_REQUEST["filter"] . "%%')";
	}else{
		$sql_where = "";
	}

	if (get_request_var_request("status") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("status") == "-2") {
		$sql_where .= (strlen($sql_where) ? " and device.disabled='on'" : "where device.disabled='on'");
	}elseif (get_request_var_request("status") == "-3") {
		$sql_where .= (strlen($sql_where) ? " and device.disabled=''" : "where device.disabled=''");
	}elseif (get_request_var_request("status") == "-4") {
		$sql_where .= (strlen($sql_where) ? " and (device.status!='3' or device.disabled='on')" : "where (device.status!='3' or device.disabled='on')");
	}else {
		$sql_where .= (strlen($sql_where) ? " and (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')" : "where (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')");
	}

	if (get_request_var_request("template_id") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("template_id") == "0") {
		$sql_where .= (strlen($sql_where) ? " and device.device_template_id=0" : "where device.device_template_id=0");
	}elseif (!empty($_REQUEST["template_id"])) {
		$sql_where .= (strlen($sql_where) ? " and device.device_template_id=" . $_REQUEST["template_id"] : "where device.device_template_id=" . $_REQUEST["template_id"]);
	}

	if (get_request_var_request("poller") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("poller") == "0") {
		$sql_where .= (strlen($sql_where) ? " and device.poller_id=0" : "where device.poller_id=0");
	}elseif (!empty($_REQUEST["poller"])) {
		$sql_where .= (strlen($sql_where) ? " and device.poller_id=" . $_REQUEST["poller"] : "where device.poller_id=" . $_REQUEST["poller"]);
	}

	if (get_request_var_request("site") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("site") == "0") {
		$sql_where .= (strlen($sql_where) ? " and device.site_id=0" : "where device.site_id=0");
	}elseif (!empty($_REQUEST["site"])) {
		$sql_where .= (strlen($sql_where) ? " and device.site_id=" . $_REQUEST["site"] : "where device.site_id=" . $_REQUEST["site"]);
	}

	html_start_box("", "100", $colors["header"], "0", "center", "");

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

	if (get_request_var_request("rows") == "-1") {
		$rows = read_config_option("num_rows_device");
	}else{
		$rows = get_request_var_request("rows");
	}

	$sortby = $_REQUEST["sort_column"];
	if ($sortby=="hostname") {
		$sortby = "INET_ATON(hostname)";
	}

	$device_graphs       = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as graphs FROM graph_local GROUP BY device_id"), "device_id", "graphs");
	$device_data_sources = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as data_sources FROM data_local GROUP BY device_id"), "device_id", "data_sources");

	$sql_query = "SELECT device.*, poller.description AS poller, sites.name AS site
		FROM device
		LEFT JOIN poller
		ON device.poller_id=poller.id
		LEFT JOIN sites
		ON device.site_id=sites.id
		$sql_where
		ORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "
		LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows;

	//print $sql_query;

	$devices = db_fetch_assoc($sql_query);

	/* generate page list navigation */
	$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 13, "devices.php");

	print $nav;
	html_end_box(false);

	$display_text = array(
		"description" => array(__("Description"), "ASC"),
		"device.hostname" => array(__("Hostname"), "ASC"),
		"id" => array(__("ID"), "ASC"),
		"nosort1" => array(__("Graphs"), "ASC"),
		"nosort2" => array(__("Data Sources"), "ASC"),
		"status" => array(__("Status"), "ASC"),
		"status_event_count" => array(__("Event Count"), "ASC"),
		"cur_time" => array(__("Current (ms)"), "DESC"),
		"avg_time" => array(__("Average (ms)"), "DESC"),
		"availability" => array(__("Availability"), "ASC"),
		"polling_time" => array(__("Poll Time"), "DESC"));

	html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));

	if (sizeof($devices) > 0) {
		foreach ($devices as $device) {
			$spanextra = "";
			if($device["disabled"] != CHECKED && $device["status"] == DEVICE_DOWN) {
				$date = __date("D, " . date_time_format() . " T", strtotime($device['status_fail_date']));
				$spanextra = 'title="' . __("Down since %s with error: '%s'", $date, $device['status_last_error']) . '"';
			}

			form_alternate_row_color('line' . $device["id"], true);
			form_selectable_cell("<a style='white-space:nowrap;' class='linkEditMain' href='" . htmlspecialchars("devices.php?action=edit&id=" . $device["id"]) . "'>" .
				(strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["description"]) : $device["description"]) . "</a>", $device["id"]);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["hostname"]) : $device["hostname"]), $device["id"]);
			form_selectable_cell(round(($device["id"]), 2), $device["id"]);
			form_selectable_cell((isset($device_graphs[$device["id"]]) ? $device_graphs[$device["id"]] : 0), $device["id"]);
			form_selectable_cell((isset($device_data_sources[$device["id"]]) ? $device_data_sources[$device["id"]] : 0), $device["id"]);
			form_selectable_cell( "<span $spanextra>".get_colored_device_status(($device["disabled"] == CHECKED ? true : false), $device["status"]) . "</span>", $device["id"]);
			form_selectable_cell(round(($device["status_event_count"]), 2), $device["id"]);
			form_selectable_cell(round(($device["cur_time"]), 2), $device["id"]);
			form_selectable_cell(round(($device["avg_time"]), 2), $device["id"]);
			form_selectable_cell(round($device["availability"], 2), $device["id"]);
			form_selectable_cell(round($device["polling_time"], 2), $device["id"]);
			form_checkbox_cell($device["description"], $device["id"]);
			form_end_row();
		}

		form_end_table();

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

	print "</table>\n";

	/* add a list of tree names to the actions dropdown */
	$device_actions = array_merge($device_actions, api_tree_add_tree_names_to_actions_array());

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

	print "</form>\n";
}