<?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" style="margin-top:10px;">
    	    	<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=".$_SESSION['id_bbws']." AND status_lokasi=1 AND id_tipe='PCH'");
			$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 class="tablesorter" cellspacing="0" border="1">
     <thead>
       <tr>
			<th rowspan="2" align="center">Tanggal</th>
			<th align="center">Pembacaan</th>
       		<th rowspan="2" align="center">Keterangan</th>
	   </tr>
       <tr>
			<th align="center">Pagi Jam 07:00</th>
   		</tr>
     </thead>

<?php

$i=0;
//while($rch=mysql_fetch_array($query)){
for($i=1; $i<=31; $i++){
//$i++;
$sql="SELECT Rain FROM ".$namalokasi." WHERE 1=1 AND ML=50 AND ReceivedDate LIKE '".date('Y')."-".$bulanini."-".$i."'";
$query=mysql_query($sql);
$rch=mysql_fetch_array($query);
if($i<date('d')) {
	if($rch['Rain']=='0') { $hjn="-"; } else { $hjn=number_format($rch['Rain'],1)." mm";}
} else { $hjn="";}
?>
	<tr>
    <td align="center"><?php echo $i; ?></td>
    <td align="center"><?php echo $hjn;?></td>
    <td></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>