<?php
include "config/conn.php";
$sql="SELECT * FROM m_lokasi WHERE 1=1 AND id_tipe='PCH' AND id_bbws='1' AND status_lokasi='1' ORDER BY ReceivedDate Desc";              
?>
          <table class="tablesorter" cellspacing="0" border="1">
              <thead>
              <tr>
                    <th width="30" >Lokasi</th>
                    <th width="20" >Tanggal</th>
                    <th width="40" align="center">Hari ini<br />24 Jam(mm)</th>
                    <th width="40"  align="center"> Update<br /> Terakhir(jam)</th>
                    <th width="30"  align="center"> Curah Hujan (mm)</th>
                    <th width="10" >Status</th>
               </tr>
               </thead>
               <tbody>
                            <?php 
			  $query = mysql_query($sql);
			  $i=0;
			  date_default_timezone_set('Asia/Jakarta');
			  $tanggal= mktime(date("m"),date("d"),date("Y"));
			  $hariini = date("Y-m-d", $tanggal);
			  $kemarin = strtotime ( '-1 day' , strtotime ($hariini));
			  $harikemarin = date("Y-m-d", $kemarin);
			  $jamskrg=date('H:i:00');
			  $totrain=0;
              while ($row_detdata=mysql_fetch_array($query)){
			  $i++;
$sql1="SELECT ReceivedDate,ReceivedTime, Rain FROM ".$row_detdata['nama_lokasi']." WHERE 1=1 ORDER BY ReceivedDate DESC,ReceivedTime DESC LIMIT 0,1";
$query1=mysql_query($sql1);
$row_detdata1=mysql_fetch_array($query1);

$sql12="SELECT sum(Rain) AS jmlRain FROM ".$row_detdata['nama_lokasi']." WHERE ReceivedDate>='".$harikemarin."' AND ReceivedDate<='".$hariini."' AND ReceivedTime>='".$jamskrg."' ORDER BY ReceivedDate DESC,ReceivedTime DESC LIMIT 0,1";
$query12=mysql_query($sql12);
$row_detdata12=mysql_fetch_array($query12);

if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']<=$row_detdata['siaga4']) { 
					$sts='<font color="blue">cerah</font>'; 
				} else if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']>=$row_detdata['siaga4'] && $row_detdata1['Rain']<=$row_detdata['siaga3']) { 
					$sts='<font color="green">Ringan</font>'; 
				} else if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']>=$row_detdata['siaga3'] && $row_detdata1['Rain']<=$row_detdata['siaga2']) { 
					$sts='<font color="#999900">Sedang</font>'; 
				} else if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']>=$row_detdata['siaga2'] && $row_detdata1['Rain']<=$row_detdata['siaga1']) { 
					$sts='<font color="red">Lebat</font>'; 
			} else if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']>$row_detdata['siaga1']) { 			$sts='<font color="red">Sangat Lebat</font>'; 
			} else if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']<$row_detdata['siaga4']  && $_SESSION['id_bbws']==1) { 
					$sts='<font color="blue">Cerah</font>'; 
				} else if(($row_detdata1['ReceivedDate']==$hariini) && $row_detdata1['Rain']<$row_detdata['siaga4'] && $row_detdata1['Rain']<$row_detdata['siaga3']) { 
					$sts='<font color="blue">Cerah</font>'; 
				} else if($row_detdata1['ReceivedDate']!=$hariini) {
					$sts='<font color="red">offline</font>';
				}

              ?>

              <tr>
                  <td width="30" style="background-color:#003;">
                  <a href="?page=detlaporan&namapos=<?php echo $row_detdata['nama_lokasi']; ?>&tp=ch" style="background:none; color:#FFF;">
									<?php echo str_replace('_','',strtoupper(str_replace('awlr_','',$row_detdata['nama_alat'])));?></a></td>
                    <!--td width="30px"><?php echo $row_detdata['id_das'];?></td->
           <td width="10px" style="background-color:#FC0; color:#000;" align="center"><?php echo number_format($row_detdata['siaga3'],0);?></td>
           <td width="10px" style="background-color:#0C3; color:#000;" align="center"><?php echo number_format($row_detdata['siaga2'],0);?></td>
           <td width="10px" style="background-color:#F00; color:#000;" align="center"><?php echo number_format($row_detdata['siaga1'],0);?></td-->
                    <td width="20"><?php echo date('d/m/Y',strtotime($row_detdata1['ReceivedDate']));?></td>
                    <td width="30"><strong><?php echo number_format($row_detdata12['jmlRain'],1);?></strong></td>
                    <td width="30"><?php echo date('H:i',strtotime($row_detdata1['ReceivedTime']));?></td>
                    <td width="30"><?php echo number_format($row_detdata1['Rain'],1);?></td>
                    <td width="10"><?php echo strtoupper($sts);?></td>
              </tr>
              </tbody>
              <?php
              }
              ?> 	
            </table>