<?php
$FtoM['Jan'] = '01';
$FtoM['Feb'] = '02';
$FtoM['Mar'] = '03';
$FtoM['Apr'] = '04';
$FtoM['May'] = '05';
$FtoM['Jun'] = '06';
$FtoM['Jul'] = '07';
$FtoM['Aug'] = '08';
$FtoM['Sep'] = '09';
$FtoM['Oct'] = '10';
$FtoM['Nov'] = '11';
$FtoM['Dec'] = '12';

include "config/conn.php";
if(isset($_GET['tgl'])) {
	$dateTime = DateTime::createFromFormat('dMy', $_GET['tgl']); 
	if ($dateTime === false) { $dateTimestamp = null; } else { $dateTimestamp = $dateTime->getTimestamp(); }
	$hariini=date('Y-m-d', $dateTimestamp);
	$filterRangeDate = substr($_GET['tgl'], 0, 2).' '.substr($_GET['tgl'], 2, 3).' '.substr($_GET['tgl'], 5, 2);
} else { 
	$hariini=date('Y-m-d');
	$filterRangeDate = '';
}
?>
					<link rel="stylesheet" href="https://cdn.datatables.net/1.11.0/css/dataTables.bootstrap5.min.css">
					<!--//Page Toolbar//-->
                    <div class="toolbar pt-4 px-4 px-lg-8">
                        <div class="position-relative container-fluid px-0">
                            <div class="row align-items-center position-relative">
                                <div class="col-md-7">
                                    <h3 class="mb-2">Laporan Tinggi Muka Air Manual </h3>

                                    <!--nav aria-label="breadcrumb">
                                        <ol class="breadcrumb mb-0">
                                            <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                                            <li class="breadcrumb-item active">UI Components</li>
                                            <li class="breadcrumb-item active">Feather Icons</li>
                                        </ol>
                                    </nav-->
                                </div>
                                <div class="col-md-5 text-md-end">
                                  <div class="d-flex justify-content-sm-end align-items-center">
                                    <div class="d-flex align-items-center">
                                       <div id="reportrange"
                                        class="btn btn-secondary small py-1 px-3 rounded-pill d-inline-flex align-items-center"
                                        data-bs-toggle="tooltip" data-bs-placement="top" title="select date">
                                        <i data-feather="calendar" class="fe-1x align-middle me-2"></i>
                                        <span class="block" id="rangedateplacement"><?php echo $filterRangeDate; ?></span>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--//Page Toolbar End//-->

                    <!--//Page content//-->
                    <div class="content pt-4 px-4 px-lg-8 d-flex flex-column-fluid">
                        <div class="container-fluid px-0">
                            <div class="row">
                                <div class="col-12 mb-4">
                                    <div class="row">
                                        <div class="col-12 mb-4">
                                            <div class="card">
                                                <div class="table-responsive">
					                                <table id="datatable" class="table mt-0 table-card table-nowrap" style=" border-radius: 10px;">
					                                    <thead class="text-uppercase small text-muted" style="background-color: #475569;">
					                                        <tr>
					                                            <th class="mc" rowspan="2" style="color:#ffffff;">Lokasi</th>
					                                            <th class="mc" rowspan="2" style="color:#ffffff;">Pengelola</th>
					                                            <th class="mc" colspan="3" style="color:#ffffff;">Jam Pencatatan</th>
					                                            <th class="mc" rowspan="2" style="color:#ffffff;">Status Laporan</th>
					                                        </tr>
					                                        <tr>
					                                        	<th class="mc" style="color:#ffffff;">07:00</th>
					                                        	<th class="mc" style="color:#ffffff;">12:00</th>
					                                        	<th class="mc" style="color:#ffffff;">17:00</th>
					                                        </tr>
					                                    </thead>
					                                    <tbody>
				                                    	<?php
                   										if($_SESSION['id_bbws']==8) { $idbbws="('8','21','23')"; } else { $idbbws="('".$_SESSION['id_bbws']."')";}			
														$tglkemaren = date('Y-m-d', strtotime('-1 days', strtotime($hariini)));
														$sqllocation=mysql_query("SELECT * FROM
																					m_lokasi AS a
																					INNER JOIN m_bbws AS b ON a.id_bbws = b.id_bbws
																					WHERE
																					1 = 1 AND
																					a.id_bbws IN ".$idbbws." AND
																					a.status_lokasi = 1 AND
																					a.id_tipe = 'PDA'
																					ORDER BY
																					a.id_tipe DESC");
														$i=0;

														while($rowlocation=mysql_fetch_array($sqllocation)){
															$i++;
															
															$select_data7=mysql_query("select DISTINCT * from ".$rowlocation['nama_lokasi']." WHERE ReceivedDate='".$hariini."' AND ML='50' AND ReceivedTime='07:00:00' LIMIT 1");
															//echo "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:#c5ebf8;"'; } 
															else if($jml7!=0 && $jml12!=0  && $jml17==0){ $sts="SUDAH"; $color='style="background-color:#ffecc1;"'; } 
															else if($jml7!=0 && $jml12!=0 && $jml17!=0){ $sts="LENGKAP"; $color='style="background-color:#e2f0b5;"'; } 
															else{ $color='style="background-color:#ffcaca;"'; $sts="BELUM"; }
															if($jml7!=0 || $jml12!=0 || $jml17!=0){	
																$tgl=date('d/m/y',strtotime($rowdata7['ReceivedDate']));
															} else { $tgl="-"; }
														?>
					                                        <tr>
                   												<td class="tl"><a href="?page=detlaptmamanual&idloc=<?php echo $rowlocation['nama_lokasi'];?>&bulan=<?php echo date('m');?>" style="color:#0099cb; text-transform:uppercase;"><?php echo $rowlocation['nama_alat'];?></a></td>
                               									<td class="tl"><?php echo $rowlocation['nama_bbws'];?></td>
                               									<td class="tc" style="background-color:#c5ebf8;"><?php echo number_format($rowdata7['WLevel'],0);?></td>
                              									<td class="tc" style="background-color:#ffecc1;"><?php echo number_format($rowdata12['WLevel'],0);?></td>
                              									<td class="tc" style="background-color:#e2f0b5;"><?php echo number_format($rowdata17['WLevel'],0);?></td>
                               									<td class="tc" <?php echo $color;?>><?php echo $sts;?></td>
                             								</tr>
					                                    <?php  
					                                    	
					                                	}
					                                    ?>
					                                    </tbody>
					                                </table>
					                            </div>
					                            
                                            </div>
                                        </div>
                                    </div>
                                    

                                </div>
                            </div>
                        </div>
                    </div>

