<style>
* {margin:0; padding: 0;}


/* Tombol Button Pesan */
#button {margin: 5% auto; width: 100px; text-align: center;}
#button a {
	width: 100px;
	height: 30px;
	vertical-align: middle;
	background-color: #F00;
	color: #fff;
	text-decoration: none;
	padding: 10px;
	border-radius: 5px;
	border: 1px solid transparent;
}

/* Jendela Pop Up */
#popup {
	width: 100%;
	/*height: 100%;*/
	position: fixed;
	background: rgba(0,0,0,.7);
	top: 0;
	left: 0;
	z-index: 9999;
	visibility: hidden;
}

.window {
	width: 800px;
	/*height: 100px;*/
	background: #fff;
	/*border-radius: 10px;*/
	position: relative;
	padding: 10px;
	/*text-align: center;*/
	margin: 5% auto;
}
.window h2 {
	margin: 30px 0 0 0;
}
/* Button Close */
.close-button {
	width: 6%;
	/*height: 20%;*/
	line-height: 23px;
	background: #000;
	border-radius: 50%;
	border: 3px solid #fff;
	display: block;
	text-align: center;
	color: #fff;
	text-decoration: none;
	position: absolute;
	top: -10px;
	right: -10px;	
}

/* Memunculkan Jendela Pop Up*/
#popup:target {
	visibility: visible;
}
</style>
<script>
function Detail(namapos,tp){ 
			$.ajax({ url: "modules/detlaporan.php?namapos="+namapos+"&tp="+tp, 
		    type: "GET",
			success: function(msg){
					$("#reloadMap").html(msg); 
				} 
	}); 
}
</script>
<?php
include "config/conn.php";
?>
<div id="popup">
    	<div class="window">
        	<a href="#" class="close-button" title="Close">Tutup</a>
            <div id="reloadMap"></div>
        </div>
</div>
          <table class="tablesorter" cellspacing="0" border="1">
              <thead>
              <tr>
                    <th width="40px">Lokasi</th>
                    <!--th width="30px">Sungai/kali</th-->
                    <th width="30px">Siaga.4</th>
                    <th width="30px">Siaga.3</th>
                    <th width="20px">Siaga.2</th>
                    <th width="10px">Siaga.1</th>
                    <th width="30px">Tanggal</th>
                    <th width="20px">Jam</th>
                    <th width="10px">TMA(cm)</th>
                    <th width="10px">Status</th>
               </tr>
               </thead>
               <tbody>
              <?php 
			  $sql="SELECT * FROM m_lokasi WHERE 1=1 AND id_tipe='PDA' AND id_bbws=1 AND status_lokasi=1
UNION
SELECT * FROM m_lokasi WHERE 1=1 AND nama_lokasi IN ('Sawangan','PasarBaru','Manggarai') AND id_bbws=1 AND status_lokasi=1 ORDER BY urutan_sungai ASC ";
              $query = mysql_query($sql);
			  $i=0;
			  date_default_timezone_set('Asia/Jakarta');
			  $tanggal= mktime(0,0,0,date('m'),date('d'),date('Y'));
			  $hariini = date("Y-m-d", $tanggal);
			  //$hariini=date('Y-m-d');
              while ($row_detdata=mysql_fetch_array($query)){
              $i++;
			  $sql1="SELECT ReceivedDate AS SamplingDate,ReceivedTime AS SamplingTime,WLevel, FORMAT(WLevel*100,0) AS klWLevel FROM ".$row_detdata['nama_lokasi']." WHERE 1=1 AND WLevel!=0 GROUP BY SamplingDate, SamplingTime ORDER BY SamplingDate DESC,SamplingTime DESC LIMIT 1";
$query1=mysql_query($sql1);
$row_detdata1=mysql_fetch_array($query1);
	
			  //echo $row_detdata['SamplingDate']."<br>";
			  //echo $row_detdata['WLevel']."<br>";
			  //echo $row_detdata['siaga4']."<br>";
			  //echo $row_detdata['siaga3'];
			  if($row_detdata['id_merk']=="RADIO") { $nilai=$row_detdata1['klWLevel']; } else {
						$nilai=number_format(str_replace(',','',$row_detdata1['WLevel']),0); }
  	  		if(($row_detdata1['SamplingDate']==$hariini) && $nilai>=$row_detdata['siaga4'] && $nilai<$row_detdata['siaga3']) { 
					$sts='<font color="green">siaga 4</font>'; 
				} else if(($row_detdata1['SamplingDate']==$hariini) && $nilai>=$row_detdata['siaga3'] && $nilai<$row_detdata['siaga2']) { 
					$sts='<font color="blue">siaga 3</font>'; 
				} else if(($row_detdata1['SamplingDate']==$hariini) && $nilai>=$row_detdata['siaga2'] && $nilai<$row_detdata['siaga1']) { 
					$sts='<font color="#999900">siaga 2</font>'; 
				} else if(($row_detdata1['SamplingDate']==$hariini) && $nilai>=$row_detdata['siaga1']) { 
				
					if($row_detdata['nama_lokasi']=="awlr_bkt_1" || $row_detdata['nama_lokasi']=="awlr_bkt2" || $row_detdata['nama_lokasi']=="awlr_bkt3" || $row_detdata['nama_lokasi']=="MTHaryono" || $row_detdata['nama_lokasi']=="BendungBekasi") {
						$sts='<font color="red">-</font>'; 
					} else { 
						$sts='<font color="red">siaga 1</font>'; 
					}			
			
			} else if(($row_detdata['SamplingDate']==$hariini) && $nilai<$row_detdata['siaga4']  && $_SESSION['id_bbws']==1) { 
					$sts='<font color="green">Siaga 4</font>'; 
				} else if(($row_detdata1['SamplingDate']==$hariini) && $nilai<$row_detdata['siaga4']) { 
					$sts='<font color="green">Normal</font>'; 
				} else if(($row_detdata1['SamplingDate']==$hariini) && $nilai<0) { 
					$sts='<font color="green">Kering</font>'; 
		} else if(($row_detdata1['SamplingDate']==$hariini) && $nilai>=0 && $nilai<=$row_detdata['siaga4']) { 
					$sts='<font color="green">Normal</font>'; 
				} else if($row_detdata1['SamplingDate']!=$hariini) {
					$sts='<font color="red">Offline</font>';
				}			
              ?>
              <tr>
                  <td width="40px" style="background-color:#003;">
                  <a href="#popup" onclick="Detail('<?php echo $row_detdata['nama_lokasi']; ?>','tma')" 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="15px" style="background-color:#3C0; color:#000;" align="center">
		   &lt;<?php 
   		   //if($row_detdata['nama_lokasi']=="PasarBaru") { $s="m"; $bg="100";}
		   echo number_format($row_detdata['siaga4'],0);
		   ?></td>
           <td width="15px" style="background-color:#06F; color:#000;" align="center">
		   <?php echo number_format($row_detdata['siaga3'],0);?>~<?php echo number_format($row_detdata['siaga2'],0);?></td>
           <td width="15px" style="background-color:#FC0; color:#000;" align="center"><?php echo number_format($row_detdata['siaga2'],0);?>~<?php echo number_format($row_detdata['siaga1'],0);?></td>
           <td width="15px" style="background-color:#F00; color:#000;" align="center"> &gt; <?php echo number_format($row_detdata['siaga1'],0);?></td>
                    <td width="30px"><?php echo date('d/m/Y',strtotime($row_detdata1['SamplingDate']));?></td>
                    <td width="20px"><?php echo date('H:i',strtotime($row_detdata1['SamplingTime']));?></td>
                    <td width="10px" align="center"><?php 
					if($row_detdata['id_merk']=="RADIO") { echo $row_detdata1['klWLevel']; } else {
				if($row_detdata['nama_lokasi']=="awlr_katulampa") { $tma=$row_detdata1['WLevel']-0; } else { $tma=$row_detdata1['WLevel']; }
						echo number_format(str_replace(',','',$tma),0); }
					
					//echo number_format($row_detdata['WLevel'],1);?>
                    </td>
                    <td width="10px"><?php print strtoupper($sts);?></td>
              </tr>
              </tbody>
              <?php
              }
              ?> 	
            </table>