<?php
include "config/conn.php";
if($_POST['cari']=="Cari") {
$bulanini=$_POST['tgl'];
$namalokasi=$_POST['location'];
} else { 
$bulanini=date('Y-m-d');
$namalokasi=$_GET['idloc'];
//	$tgls = date('Y-m-d',strtotime('-1 day',strtotime($tglf))) ;
}

$sqlinfo=mysql_query("select * from m_lokasi where nama_lokasi='".$namalokasi."'");
$rowinfo=mysql_fetch_array($sqlinfo);
?>

        <link rel="stylesheet" href="Highcharts/nesw2/images/style.css" type="text/css">
	    <link type="text/css" href="css/jquery-ui-1.8.6.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.6.custom.min.js"></script>
		<script type="text/javascript">
		jQuery(function($){
		$.datepicker.regional['vi'] = {
			closeText: 'Tutup',
			prevText: 'Sebelum',
			nextText: 'Sesudah',
			currentText: 'Sekarang',
			monthNames: ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
			'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'],
			monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun',
			'Jul', 'Ags', 'Sep', 'Okt', 'Nov', 'Des'],
			dayNames: ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jum&acute;at', 'Sabtu'],
			dayNamesShort: ['Min', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sbt'],
			dayNamesMin: ['Mg', 'Sn', 'Sl', 'Rb', 'Km', 'Jm', 'Sb' ],
			dateFormat: 'yy-mm-dd',
			firstDay: 0,
			isRTL: false,
			showMonthAfterYear: false,
			changeMonth: true,
			changeYear: true,
			yearSuffix: ''};

		$.datepicker.setDefaults($.datepicker.regional['vi']);

	  	$(function(){

				$('#tgl').datepicker({

					inline: true

				});

	    });

		$(function(){

				$('#tglf').datepicker({

					inline: true

				});

	    });

       });
</script>
		<article class="module width_quarter">

		<header>

		<h3 class="tabs_involved" style="background-image:url(images/icons/form.gif); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">INFO POS</h3>

		</header>

		<!--div class="message_list"-->

		<div class="module_content" style="margin-top:-17px;">
        <p style="padding:8px; padding-bottom:-5px; text-align:justify; color:#F00;">Berikut detail rincian hasil pembacaan Curah Hujan.</p>
        	<fieldset>
				<label>Nama Lokasi : <?php echo $rowinfo['nama_alat']; ?></label>
                <label>No.Register : <?php echo $rowinfo['no_hp'];?></label>
				<label>Alamat : <?php echo $rowinfo['lokasi_alamat'];?></label>
				<label>Petugas : <?php echo $rowinfo['nama_pengamat'];?></label>
				<label>Tahun : <?php echo date('Y');?></label>
				<label>Bulan : <?php echo $bulanini;?></label>
			</fieldset>
       	</div>
        <!--/div-->
        </article>

	

		<article class="module width_3_quarter">

			<header>

            <h3 class="tabs_involved" style="background-image:url(images/icons/spreadsheet.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">

            DETAIL DATA</h3>

		<form action="" method="post">
            <ul class="tabs">
    	    	<li>
                <select name="location" id="location" onchange="submitForm();"> 
        	<option value="">Nama Lokasi</option>
			<?php
			$sqllocation=mysql_query("SELECT * FROM m_lokasi WHERE 1=1 AND id_bbws=2 AND status_lokasi=1 AND id_tipe='PDA'");
			$i=0;
			while($rowlocation=mysql_fetch_array($sqllocation)){
			$i++;
			?>	
        	<option value="<?php echo $rowlocation['nama_lokasi'];?>" <?php if($rowlocation['nama_lokasi']==$_POST['location']){ echo "selected";}?>><?php echo strtoupper($rowlocation['nama_alat']);?></option>
			<?php }?>
    	    </select></li>
            <li>
            <select name="tgl" id="tgl"> 
        	<option value="">Bulan</option>
			<?php for($j=1; $j<=12; $j++){?>
        	<option value="<?php echo $j; ?>"><?php echo $j; ?></option>
			<?php }?>
    	    </select><input type="submit" name="cari" id="cari" value="Cari" /></li>
                <li><a href="includes/downloadDataTMA.php?pos=<?php echo $_GET['pos'];?>&tgls=<?php echo $tgls;?>&tglf=<?php echo $tglf;?>">Download XLS</a></li>

	        </ul>
			</form>
            </header>

			<div class="message_list">

				<div class="module_content">

<table width="100%" style="border:0px solid #003;">
                           <thead>
                                <tr>
                                    <!--th style="border:1px solid #003;" rowspan="2">#</th-->
                                    <th style="border:1px solid #003;" rowspan="2" align="center" valign="middle">NAMA POS</th>
                                    <th align="center" rowspan="2" style="border:1px solid #003;" >TANGGAL</th>
                                    <th colspan="3" align="center"style="border:1px solid #003;" >JAM PENCATATAN</th>
                                    <th align="center" style="border:1px solid #003;" rowspan="2" >STATUS<br />LAPORAN</th>
                                </tr>
                            </thead>
                           <thead>
                                <tr>
                                    <th align="center" style="border:1px solid #003;"></th>
                                    <th align="center" style="border:1px solid #003;"></th>
                                    <th align="center" style="border:1px solid #003;">07:00</th>
                                    <th align="center" style="border:1px solid #003;"> 12:00</th>
                                    <th align="center" style="border:1px solid #003;"> 17:00</th>
                                    <th align="center" style="border:1px solid #003;"></th>
                                 </tr>
                            </thead>
							<?php
							
							$tglkemaren = date('Y-m-d', strtotime('-1 days', strtotime($hariini)));
//$sqllocation=mysql_query("SELECT * FROM m_lokasi WHERE 1=1 AND id_bbws=".$_SESSION['id_bbws']." AND status_lokasi=1 AND id_tipe='PDA' ORDER BY id_tipe DESC");
//$i=0;

for($i=1; $i<=31; $i++){

$select_data7=mysql_query("select DISTINCT * from ".$rowlocation['nama_lokasi']." WHERE ReceivedDate='".$hariini."' AND ML='50' AND ReceivedTime='07:00:00' LIMIT 1"); 				$rowdata7=mysql_fetch_array($select_data7);
$select_data12=mysql_query("select DISTINCT * from ".$rowlocation['nama_lokasi']." WHERE ReceivedDate='".$hariini."' AND ML='50' AND ReceivedTime='12:00:00'  LIMIT 1");
$rowdata12=mysql_fetch_array($select_data12);
$select_data17=mysql_query("select DISTINCT * from ".$rowlocation['nama_lokasi']." WHERE ReceivedDate='".$hariini."' AND ML='50' AND ReceivedTime='17:00:00'  LIMIT 1");
$rowdata17=mysql_fetch_array($select_data17);
							
							$jml7=mysql_num_rows($select_data7);
							$jml12=mysql_num_rows($select_data12);
							$jml17=mysql_num_rows($select_data17);
							
/*							if($jml7!=0 && $jml12==0 && $jml17==0){ $sts="SUDAH"; $color='style="background-color:#09F; color:#FFF;"'; } 
							else if($jml7!=0 && $jml12!=0  && $jml17==0){ $sts="SUDAH"; $color='style="background-color:#FF0; color:#FFF;"'; } 
							else if($jml7!=0 && $jml12!=0 && $jml17!=0){ $sts="LENGKAP"; $color='style="background-color:#0C0; color:#FFF;"'; } 
							else 
								{ $color='style="background-color:#F00; color:#FFF;"'; $sts="BELUM"; }
							if($jml7!=0 || $jml12!=0 || $jml17!=0){	
								$tgl=date('d/m/y',strtotime($rowdata7['ReceivedDate']));
							} else { $tgl="-";}
*/							?>
                            <tr <?php echo $color;?>>
                               	<!--td style="border:1px solid #003;"><?php echo $i; ?></td-->
                   	<td style="border:1px solid #003; padding-left:4px;"><a href="?page=detlaptmamanual" style="color:#000; text-transform:uppercase;"><?php echo $rowlocation['nama_alat'];?></a></td>
                               	<td align="center" style="border:1px solid #003; color:#000;"><?php echo $tgl;?></td>
                               <td align="center" style="border:1px solid #003; color:#000; background-color:#09F;"><?php echo number_format($rowdata7['WLevel'],0);?></td>
                              <td align="center" style="border:1px solid #003; color:#000; background-color:#FF0;"><?php echo number_format($rowdata12['WLevel'],0);?></td>                              <td align="center" style="border:1px solid #003; color:#000; background-color:#0C0;"><?php echo number_format($rowdata17['WLevel'],0);?></td>
                               	<td align="center" style="border:1px solid #003; color:#000;"><?php echo $sts;?></td>
                             </tr>
                            <?php }?>
                        </table>

				</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>        
<script src="js/jquery-1.11.1.min.js"></script>
