<?php
session_start();
include "includes/map.php";
$sql_hjn="SELECT DISTINCT
			b.id_merk,
			b.nama_lokasi,
			a.nilai_a,
			a.nilai_b,
			a.nilai_c,
			b.WLevel AS WLevel,
			b.id_merk,
			/*format(a.nilai_c * pow(((b.WLevel/100)+a.nilai_a),a.nilai_b),2) AS debit,*/
			b.ReceivedDate,
			b.id_tipe
			FROM
			m_debit AS a
			RIGHT JOIN m_lokasi AS b ON a.id_lokasi = b.id_lokasi WHERE 1=1 AND status_lokasi=1 AND id_tipe='PDA' ";
			$sql_hjn.=" AND b.id_bbws='".$_SESSION['id_bbws']."'";		
$sql_hjn.=" ORDER BY b.ReceivedDate Desc, b.ReceivedTime Desc";
$query_hjn=mysql_query($sql_hjn);

$sql_hjn2="SELECT * FROM m_lokasi WHERE 1=1 AND id_tipe='PCH' AND id_bbws=".$_SESSION['id_bbws']." AND icon IN ('lebat', 'sedang') ";
$query_hjn2=mysql_query($sql_hjn2);

date_default_timezone_set('Asia/Jakarta');
$tanggal= mktime(0,0,0,date('m'),date('d'),date('Y'));
$hariini = date("Y-m-d", $tanggal);
?>
<body onLoad="load()">
	<article class="module width_quarter">
			<header>
            <h3 class="tabs_involved" style="background-image:url(images/icons/siaga1.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">
            INFO DEBIT - <?php echo date('d M Y'); ?></h3>
            </header>
			<div class="message_list">
				<div class="module_content">
                <div class="spacer" align="left">
                <table border="0" width="100%" class="tablesorter" cellspacing="2">
                <tr>
                	<td align="left"><strong>Keterangan</strong> : <img src="images/icons/checkmark2.png"> : On | <img src="images/icons/cross.png"> : off</td>
                    <td align="right"><a href="#">Download</a></td>
                </tr>
                </table>
                
                <table border="1" width="100%" class="tablesorter" cellspacing="0">
                <thead>
                <tr>
                    <th width="44%">NAMA LOKASI</th>
                    <th width="28%">TMA (m)</th>
                    <th width="45%">DEBIT (m&sup3;/s)</th>
                </tr>
                </thead>
                </table>
                <!--marquee onmouseover="this.stop()" onmouseout="this.start()" scrollamount="2" direction="up" width="100%" height="455" align="center" style="padding-left:1px;"--> 
                <table border="1" width="100%" class="tablesorters" cellspacing="0">
                <thead>
				<?php
                while($rslide=mysql_fetch_array($query_hjn)){
                    if($rslide['id_merk']=="RADIO") { $level=$rslide['WLevel']/100; } else { $level=$rslide['WLevel']/100; }
                    if($hariini==$rslide['ReceivedDate'] && $rslide['id_tipe']=='PDA'){ 
							$sts="style='background-image:url(images/icons/checkmark2.png); background-repeat:no-repeat; padding-left:20px;'";
					} else {
								$sts="style='background-image:url(images/icons/checkmark2.png); background-repeat:no-repeat; padding-left:20px;'";				
					}
					echo "<tr>
                        <th width='44%' align='left' ".$sts.">".str_replace('awlr_','',$rslide['nama_lokasi'])."</th><th width='28%' align='center'>".number_format($level,2)."</th><th width='45%' align='center'>".$rslide['debit']."</th></tr>";
                }
                ?>
                </thead>
                </table>
                <!--/marquee-->
				</div>
			</div>
			<!--footer>
				<form class="post_message">
					<input type="text" value="Message" onFocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
					<input type="submit" class="btn_post_message" value=""/>
				</form>
			</footer-->
		</article>

		<article class="module width_3_quarter">
		<header>
		<h3 class="tabs_involved" style="background-image:url(images/icon_online.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">PETA SEBARAN POS TELEMETRY</h3>
		<form action="" method="post">
        <!--ul class="tabs">
        	<li>Periode : <input type="text" id="tgls" name="tgls" value="<?php echo date('Y-m-d',strtotime($tgls));?>" size="10" /> s/d <input type="text" id="tglf" name="tglf" value="<?php echo date('Y-m-d',strtotime($tglf));?>" size="10" />
            	<input type="submit" id="btncari" name="btncari" value="Search" />	
            </li>
        </ul-->
        </form>
		</header>
		<div class="tab_container">
				        <div id="map" style="width: 100%; height: 371px; background-color:aliceblue;"></div>
			<hr/>
            <article class="module width_quarter_battray">
            <header>
            <h3 class="tabs_involved" style="background-image:url(images/icons/lebat.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">
           	Info Curah Hujan Tinggi</h3>
            </header>
            <div class="tab_container">
				<table class="tablesorter" cellspacing="0" border="0">
                <thead>
                <tr>
                    <th width="44%">NAMA LOKASI</th>
                    <th width="28%">CURAH HUJAN</th>
                    <th width="45%">STATUS</th>
                </tr>
                </thead>
				<?php
                while($rslide2=mysql_fetch_array($query_hjn2)){
                    if($hariini==$rslide2['ReceivedDate'] && $rslide2['id_tipe']=='PCH'){ 
						if($rslide2['id_merk']=="RADIO") { $rain=$rslide2['Rain']; } else { $rain=$rslide['Rain']/100; }
					}
					echo "<tr>
                        <td width='44%' align='left'>".str_replace('arr_','',$rslide2['nama_lokasi'])."</td>
						<td width='28%' align='center'>".number_format($rain,2)." mm</td><td width='45%' align='center'>".$rslide2['icon']."</td></tr>";
                
				}
                ?>
                </table>
            </div><!-- end of .tab_container -->
            </article><!-- end of content manager article --> 

            <article class="module width_quarter_battray">
            <header>
            <h3 class="tabs_involved" style="background-image:url(images/icons/firewall.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">
            Info Temuan Lapangan</h3>
            </header>
            <div class="tab_container">
				<table class="tablesorter" cellspacing="0" border="0">
                <thead>
                <tr>
                	<td>Temuan</td>
                	<td>Keterangan</td>
                	<td>Location</td>
                </tr>
                </thead>
                <?php
				$sql_genangan=mysql_query("SELECT
												b.sumber,
												b.isi_temuan,
												b.creator,
												c.id_bbws,
												tanggal_temuan,
												b.lat,
												b.lot,
												COUNT(a.nama_gambar) jmlGambar
												FROM
												t_gambar AS a
												INNER JOIN t_temuan AS b ON b.id_temuan = a.`foreign`
												INNER JOIN m_user AS c ON c.username = b.creator WHERE 1=1 AND c.id_bbws=".$_SESSION['id_bbws']."");
				$i=0;
				while($row_genangan=mysql_fetch_array($sql_genangan)){
				$i++;
				?>
                <tr>
                <td align="left" valign="top"><?php echo $row_genangan['sumber'];?><br><em>by : <?php echo $row_genangan['creator'];?></em></td>
                <td align="left" valign="top">
                <strong><?php echo $row_genangan['isi_temuan'];?></strong><br /><em><?php echo $row_genangan['tanggal_temuan'];?></em>
                </td>
                <td align="center"><img src="images/iconAlarmNormal.png"></td>
              	</tr>
                <?php 
				} 
				?>
				</table>
            </div><!-- end of .tab_container -->
            </article><!-- end of content manager article --> 
            	
		</div><!-- end of .tab_container -->
		</article><!-- end of content manager article -->        
</body>