<?
/*
#============================================================================
# Program: Devices-Graph.php
# Programmer: Remo Rickli
#
# DATE		COMMENT
# -----------------------------------------------------------
# 27/03/06	initial version.
# 15/05/06	new concept towards CPU and Mem graphing
# 02/11/06	cosmetic changes
# 08/11/06	medium graph option
# 05/03/07	support for 8  stacks
# 25/05/07	Minor Improvements, fixed urlencoding (let me know, if you still find non working ones!)
# 30/08/07	implemented CSS scheme
# 20/09/07	implemented language support
*/

include_once ("inc/header.php");

$_GET = sanitize($_GET);
$dv = isset($_GET['dv']) ? $_GET['dv'] : "";
$if = isset($_GET['if']) ? $_GET['if'] : array();
$cpu = isset($_GET['cpu']) ? $_GET['cpu'] : "";
$mem = isset($_GET['mem']) ? $_GET['mem'] : "";
$tmp = isset($_GET['tmp']) ? $_GET['tmp'] : "";
$dur = isset($_GET['dur']) ? $_GET['dur'] : 1;
$sze = isset($_GET['sze']) ? $_GET['sze'] : "l";
?>
<h1>Device <?=$gralbl?></h1>
<form method="get" action="<?=$self?>.php" name="graf">
<table class="content">
<tr class="<?=$modgroup[$self]?>1">
<th width=80><a href="<?=$self?>.php"><img src="img/32/dlog.png"></a></th>
<th>
<select size=6 name="dv" onchange="this.form.submit();">
<?
$link	= @DbConnect($dbhost,$dbuser,$dbpass,$dbname);
$query	= GenQuery('devices','s','name');
$res	= @DbQuery($query,$link);
if($res){
	while( ($d = @DbFetchRow($res)) ){
		echo "<option value=\"$d[0]\" ";
		if($dv == $d[0]){
			echo "selected";
		}
		echo " >$d[0]\n";
	}
	@DbFreeResult($res);
}else{
	print @DbError($link);
}
?>
</select>
<select multiple size=6 name="if[]">
<?
if ($dv) {
	$query	= GenQuery('interfaces','s','ifname,alias,comment','ifname','',array('device'),array('='),array($dv) );
	$res	= @DbQuery($query,$link);
	if($res){
		while( ($i = @DbFetchRow($res)) ){
			echo "<OPTION VALUE=\"$i[0]\" ";
			if(in_array($i[0],$if)){echo "selected";}
			echo " >$i[0] " . substr("$i[1] $i[2]\n",0,30);
		}
		@DbFreeResult($res);
	}
}
?>
</select>
</th>
<td>
<INPUT type="checkbox" name="cpu" <?=($cpu)?"checked":""?> > CPU<br>
<INPUT type="checkbox" name="mem" <?=($mem)?"checked":""?> > Mem<br>
<INPUT type="checkbox" name="tmp" <?=($tmp)?"checked":""?> > Temp<br>
</td>
<th>
<SELECT size=1 name="dur">
<OPTION VALUE="1"><?=$tim['d']?>
<OPTION VALUE="7" <?=($dur == "7")?"selected":""?> ><?=$tim['w']?>
<OPTION VALUE="30" <?=($dur == "30")?"selected":""?> ><?=$tim['m']?>
<OPTION VALUE="360" <?=($dur == "360")?"selected":""?> ><?=$tim['y']?>
</SELECT>
</th>
<th>
<SELECT size=1 name="sze">
<OPTION VALUE="l"><?=$siz['l']?>
<OPTION VALUE="m" <?=($sze == "m")?"selected":""?> ><?=$siz['m']?>
<OPTION VALUE="s" <?=($sze == "s")?"selected":""?> ><?=$siz['s']?>
</SELECT>
</th>
<th width=80><input type="submit" value="<?=$shobtn?>"></th>
</tr></table></form>
<div align="center"><p>
<?
$ud = rawurlencode($dv);
if($cpu ){
	echo "<img src=inc/drawrrd.php?dv=$ud&s=$sze&t=cpu&dur=$dur>\n";
}
if($mem ){
	echo "<img src=inc/drawrrd.php?dv=$ud&s=$sze&t=mem&dur=$dur>\n";
}
if($tmp ){
	echo "<img src=inc/drawrrd.php?dv=$ud&s=$sze&t=tmp&dur=$dur>\n";
}
if( isset($if[0]) ){
	$ifs = "";
	foreach ( $if as $i){
		$ifs .= '&if[]='.rawurlencode($i);
	}
	echo "<p><img src=inc/drawrrd.php?dv=$ud$ifs&s=$sze&t=trf&dur=$dur vspace=8>\n";
	echo "<img src=inc/drawrrd.php?dv=$ud$ifs&s=$sze&t=err&dur=$dur vspace=8>\n";
}
?>
</div>
<?
include_once ("inc/footer.php");
?>