<?php
require('startinclude.php');
// aaaaaaaaaaaaa
$camara=parametro('camara',-1);
$ventanan=parametro('ventanan',0);
$iuniquev=$_SERVER['REMOTE_ADDR']."_pf_".$ventanan;
if ($camara==-1) {
	$camara=@apc_fetch($iuniquev);
} else {
	
	apc_store($iuniquev,$camara);
}
if ($camara==0) {
	$anterior_num=apc_fetch('numero_de_camaras');
} else {
	$anterior_num=$camara-1;
}
if ($camara==apc_fetch('numero_de_camaras')) {
	$despues_num=0;
} else {
	$despues_num=$camara+1;
}
$anterior_c="<a href='wsensor.php?camara=".$anterior_num."&ventanan=$ventanan'>&lt;&lt;&lt;</a>&nbsp;&nbsp;&nbsp;";
$despues_c="&nbsp;&nbsp;&nbsp;<a href='wsensor.php?camara=".($despues_num)."&ventanan=$ventanan'>&gt;&gt;&gt;</a>";

// aaaaaaaaaaaaaa
setcookie('estado_camara'.$camara,'sensor');


obtener_login_nivel($nivel_usuario);


// comun para todos..
	$camaras_actual=array();
	$camaras=array();
	leer_camaras($camaras);
	leer_camaras_actual($camaras_actual);
	$totalcamaras=count($camaras);
// fin comun

?>
<head>
<title> No title</title>

<meta name="GENERATOR" content="Namo WebEditor">
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> 
<META NAME="ROBOTS" CONTENT="NOARCHIVE"> 
<script type='text/javascript' src='ajaxlib/utils/southprojects.js'></script>
<script type='text/javascript' src='jscriptrpc.js'></script>
<script type='text/javascript' src='ajaxlib/utils/progress.js'></script>
<link href='style2.css' rel='stylesheet' type='text/css'>
<style type="text/css">

.alerta {
	text-decoration:none;
	background-color:#CC0000;
	FONT-WEIGHT: bold;
	font-family:  Tahoma,Verdana, Helvetica;
	font-size:10px;
}
.offline {
	text-decoration:none;
	background-color:#CCC0C0;
	FONT-WEIGHT: normal;
	font-family:  Tahoma,Verdana, Helvetica;
	font-size:10px;
}

.ok {
	text-decoration:none;
	background-color:#FFFFFF;
	FONT-WEIGHT: normal;
	font-family:  Tahoma,Verdana, Helvetica;
	font-size:10px;
}

</style> 


<script type="text/javascript">
	var loader;


		loader = new southprojects.Progress({
			theme: 'default',
			themePath: "ajaxlib/spextra/themes/progress/"
		});



	function showespere() {
		loader.start('espere..');
		//setTimeout("loader.stop();", 4000);
	}

	function clickcheck(direccion) {
		fetchUrl(direccion, 'transportdiv')
		loader.start('espere..');
	}
	function clickcheck2(numero) {
		var direccion;
		var minima;
		var maxima;
		var checkbox;
		minima=document.getElementById('iminima'+numero).value;
		maxima=document.getElementById('imaxima'+numero).value;
		valorn=document.getElementById('ivalorn'+numero).value;
		checkbox=document.getElementById('checkbox').checked;
		
		
		direccion='wsensor2_rpc.php?camara=<? echo $camara; ?>&id='+numero+'&minima='+minima+"&maxima="+maxima+"&valorn="+valorn+"&checkbox="+checkbox;
		loader.start('espere..');
		fetchUrl(direccion, 'transportdiv')
		
	}	


</script>

<script type="text/javascript">
phprpc='wsensor_rpc.php';
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

</script>



</head>
<!--
<BODY  onload="javascript:
inicio_ciclo();
">
-->

<body>
<div id="transportdiv" name='transportdiv' style="border-width:1px; border-color:rgb(0,0,240); border-style:solid; display: none;"></div>            



<?php






/*

$nsensores=array();

*/

$temp=array();


//leer_temperatura($temp,$camara,$maxima,$minima,$estado,$nombre_sensor,$num_temp,$limite);
leer_temperatura2($temp,$camara,0,0,1);

$estado_actual=$camaras_actual[$camara]["estado_actual"];

if ($estado_actual=="V" or $estado_actual=="N") {
	$protegido="";
} else {
	$protegido="";
	//$protegido="disabled=true ";
	
}


if ($nivel_usuario>1) {
	echo "<form name='f1' method='GET'>";
	echo "<table width=100%><tr><td width=100% align=center>";	
	echo "<div id='body' width=600px>\n";
	echo "	<div id='content_fixed'>\n";
	echo "<div id=\"data_table\">\n";
	echo "			<h2 align='left'>$anterior_c".$camaras[$camara]["nombre_camara"]."$despues_c</h2>\n";
	echo "			<h3 align='left' >Listado de Sensores</h3>		\n";
	echo "		\n";
	echo "		<p align='center'><table id='table_1' align='center' width=600px >\n";
	echo "    <thead>\n";
	echo "        <td width='15%'   >Nombre</td>\n";
	echo "        <td width='10%'   >Modulo</td>\n";
	echo "        <td width='15%'   >Valor</td>\n";
	echo "        <td width='10%'   >Habilitado</td>\n";
	echo "        <td width='10%'   >Minima</td>\n";
	echo "        <td width='10%'   >Maxima</td>\n";
	echo "        <td width='20%'   >Valor Nuevo</td>\n";
	echo "        <td width='10%'   >&nbsp;</td>\n";
	echo "    </thead><tbody>\n";
	for ($i=0;$i<$temp["num_temp"];$i++) {
		if ($protegido) {
		$boton="&nbsp;"; //<img src='images/ok.gif' onclick=\"	clickcheck2('$i');\" onmouseover=\"this.style.cursor='pointer'\" onmouseout=\"this.style.cursor='default'\">";
		} else {
		$boton="<img src='images/ok.gif' onclick=\"	clickcheck2('$i');\" onmouseover=\"this.style.cursor='pointer'\" onmouseout=\"this.style.cursor='default'\">";
		}
		if ($temp[$i]["t"]==-66.6) {
			$check="<input type='checkbox'  name='checkb$i' value='1' $protegido onclick=\"	clickcheck('wsensor_rpc.php?id=$i&camara=$camara');\">";
		} else {
			$check="<input type='checkbox'  name='checkb$i' value='1' $protegido onclick=\"	clickcheck('wsensor_rpc.php?id=$i&camara=$camara');\" checked>";
		}
		$clase=(($i%2)==0)?"even":"odd";
		$rtemp=$temp[$i]["t"];
		$rtemp=($rtemp==-55.5)?"NC":$rtemp;
		$rtemp=($rtemp==-66.6)?"OUT":$rtemp;
		echo "    <tr class=$clase>\n";
		echo "        <td  id='celnombre$i' class='ok'  >".$temp[$i]["nombre"]."</td>\n";
		echo "        <td  id='idmodulo$i' class='ok' >".$temp[$i]["id"]."</td>\n";
		echo "        <td  id='valor$i' class='ok' >".$rtemp."</td>\n";
		echo "        <td  id='chk$i'  $protegido>".$check."</td>\n";
		echo "        <td  id='minima$i'  $protegido><input type='text' name='minima$i' id='iminima$i' value='".$temp[$i]['limite_minimo']."' size='5' $protegido></td>\n";
		echo "        <td  id='maxima$i'  $protegido><input type='text' name='maxima$i' id='imaxima$i' value='".$temp[$i]['limite_maximo']."' size='5' $protegido></td>\n";
		$protegidos1=$protegido;
		if ($temp[$i]['solo_lectura']>0) {
			$protegidos1="disabled=true"; 
		}
		echo "        <td  id='valorn$i'  $protegido><input type='text' name='ivalorn$i' id='ivalorn$i' value='' size='5' $protegidos1></td>\n";
		echo "        <td  id='minmax$i'  $protegido>".$boton."</td>\n";
		echo "    </tr>\n";
		
	}
	echo "</tbody>\n";
	echo "</table></p>\n";
	echo "</div><div>\n";
	echo "</div>\n";
	echo "</table>";
} else {
	echo "<form name='f1' method='GET'>";
	echo "<table width=100%><tr><td width=100% align=center>";	
	echo "<div id='body' width=600px>\n";
	echo "	<div id='content_fixed'>\n";
	echo "<div id=\"data_table\">\n";
	echo "			<h2 align='left'>".$camaras[$camara]["nombre_camara"]."</h2>\n";
	echo "			<h3 align='left' >Listado de Sensores</h3>		\n";
	echo "		\n";
	echo "		<p align='center'><table id='table_1' align='center' width=600px >\n";
	echo "    <thead>\n";
	echo "        <td width='20%'   >Nombre</td>\n";
	//echo "        <td width='10%'   >Modulo</td>\n";
	echo "        <td width='20%'   >Valor</td>\n";
	echo "        <td width='10%'   >Habilitado</td>\n";
	echo "        <td width='10%'   >Minima</td>\n";
	echo "        <td width='10%'   >Maxima</td>\n";
	echo "        <td width='20%'   >Valor Nuevo</td>\n";
	echo "        <td width='10%'   >&nbsp;</td>\n";
	echo "    </thead><tbody>\n";
	for ($i=0;$i<$temp["num_temp"];$i++) {
		if ($protegido) {
		$boton="&nbsp;"; //<img src='images/ok.gif' onclick=\"	clickcheck2('$i');\" onmouseover=\"this.style.cursor='pointer'\" onmouseout=\"this.style.cursor='default'\">";
		} else {
		$boton="<img src='images/ok.gif' onclick=\"	clickcheck2('$i');\" onmouseover=\"this.style.cursor='pointer'\" onmouseout=\"this.style.cursor='default'\">";
		}
		if ($temp[$i]["t"]==-66.6) {
			$check="<input type='checkbox'  name='checkb$i' value='1' $protegido onclick=\"	clickcheck('wsensor_rpc.php?id=$i&camara=$camara');\">";
		} else {
			$check="<input type='checkbox'  name='checkb$i' value='1' $protegido onclick=\"	clickcheck('wsensor_rpc.php?id=$i&camara=$camara');\" checked>";
		}
		$clase=(($i%2)==0)?"even":"odd";
		$rtemp=$temp[$i]["t"];
		$rtemp=($rtemp==-55.5)?"NC":$rtemp;
		$rtemp=($rtemp==-66.6)?"OUT":$rtemp;
		echo "    <tr class=$clase>\n";
		echo "        <td  id='celnombre$i' class='ok'  >".$temp[$i]["nombre"]."</td>\n";
		//echo "        <td  id='idmodulo$i' class='ok' >".$temp[$i]["id"]."</td>\n";
		echo "        <td  id='valor$i' class='ok' >".$rtemp."</td>\n";
		echo "        <td  id='chk$i'  $protegido>".$check."</td>\n";
		echo "        <td  id='minima$i'  $protegido><input type='text' name='minima$i' id='iminima$i' value='".$temp[$i]['limite_minimo']."' size='5' $protegido></td>\n";
		echo "        <td  id='maxima$i'  $protegido><input type='text' name='maxima$i' id='imaxima$i' value='".$temp[$i]['limite_maximo']."' size='5' $protegido></td>\n";
		echo "        <td  id='valorn$i'  $protegido><input type='text' name='ivalorn$i' id='ivalorn$i' value='' size='5' $protegido></td>\n";
		echo "        <td  id='minmax$i'  $protegido>".$boton."</td>\n";
		echo "    </tr>\n";
		
	}
	echo "</tbody>\n";
	echo "</table></p>\n";
	echo "</div><div>\n";
	echo "</div>\n";
	echo "</table>";

}
	

echo "<p align='center'>Asignar la minima y maxima a todos los sensores <input name='checkbox' type='checkbox' id='checkbox'   /></p>\n";
echo "<br>";
echo "<br>";
echo "</form>";





?>

<script type="text/javascript">
//document.getElementById('valor0').className='alerta';

//window.parent.window.parent.document.getElementById('spWin0Container').className='spWinRedxpContainer';



</script>
</BODY>
