<?php
if(function_exists('date_default_timezone_set')) date_default_timezone_set('Asia/Jakarta');

$server="localhost"; $user="sdatelem_icuadm"; $pass="Icupu2015"; $db="sdatelem_icu";
$con_project=mysql_connect($server, $user, $pass);
$db_project=mysql_select_db($db,$con_project);

$hrini=date('Y-m-d');
$jamini=date('H:00:00');
//echo "<br />";
$jamdualalu=date('H:00:00')-2;
//echo "<br />";
$duajam="0".$jamdualalu.":00:00";
$query_lokasi=mysql_query("select * from m_lokasi where 1=1",$con_project);
while($rl=mysql_fetch_array($query_lokasi)){
	$tglhrini=$rl['ReceivedDate'];
	$dataduajam=$rl['ReceivedTime'];

	$rain=$rl['Rain'];
	$wlevel=$rl['WLevel'];
//echo $rl['siaga4'];
//echo $rl['id_tipe'];
//	echo "<br>";
	//if($rl['id_merk']=="RADIO" || $rl['id_merk']=="FEWS" || $rl['id_merk']=="ICU") {

           if($rl['id_tipe']=="PCH" && $tglhrini==$hrini && $dataduajam>=$duajam){
		if($rain==0 || $rain=="") { $iconNew="cerah"; }
		  else if($rain>=$rl['siaga4'] && $rain<=$rl['siaga3']) { $iconNew="ringan"; }
		  else if($rain>=$rl['siaga3'] && $rain<=$rl['siaga2']) { $iconNew="sedang"; }
		  else if($rain>=$rl['siaga2'] && $rain<=$rl['siaga1']) { $iconNew="lebat"; }
		  else if($rain>$rl['siaga1']) { $iconNew="sangatlebat"; }		
	   } else if($rl['id_tipe']=="PDA" && $tglhrini==$hrini  && $duajam>=$duajam){
		if($wlevel==0 || $wlevel<$rl['siaga4']) { $iconNew="normal"; }
		  else if($wlevel>=$rl['siaga4'] && $wlevel<=$rl['siaga3']) { $iconNew="normal"; }
		  else if($wlevel>=$rl['siaga3'] && $wlevel<=$rl['siaga2']) { $iconNew="siaga3"; }
		  else if($wlevel>=$rl['siaga2'] && $wlevel<=$rl['siaga1']) { $iconNew="siaga2"; }
		  else if($wlevel>$rl['siaga1']) { $iconNew="siaga1"; }		
 	    } else {
		$iconNew="offline";	
	    }
        /* } else {
	   if($rl['id_tipe']=="PCH" && $tglhrini==$hrini){
		if($rain==0 || $rain=="") { $iconNew="cerah"; }
		  else if($rain>=$rl['siaga4'] && $rain<=$rl['siaga3']) { $iconNew="ringan"; }
		  else if($rain>=$rl['siaga3'] && $rain<=$rl['siaga2']) { $iconNew="sedang"; }
		  else if($rain>=$rl['siaga2'] && $rain<=$rl['siaga1']) { $iconNew="lebat"; }
		  else if($rain>$rl['siaga1']) { $iconNew="sangatlebat"; }		
	        } else if($rl['id_tipe']=="PDA" && $tglhrini==$hrini){
		if($wlevel==0) { $iconNew="normal"; }
		  else if($wlevel>=$rl['siaga4'] && $wlevel<=$rl['siaga3']) { $iconNew="normal"; }
		  else if($wlevel>=$rl['siaga3'] && $wlevel<=$rl['siaga2']) { $iconNew="siaga3"; }
		  else if($wlevel>=$rl['siaga2'] && $wlevel<=$rl['siaga1']) { $iconNew="siaga2"; }
		  else if($wlevel>$rl['siaga1']) { $iconNew="siaga1"; }			
	    }  else {
		$iconNew="offline";	
	    }
        }*/

	
	$update="update m_lokasi set icon='".$iconNew."' where nama_lokasi='".$rl['nama_lokasi']."'";
	//echo "<br>";
	$queryUpdate=mysql_query($update,$con_project);
}
?>