<?php
	/* require '../db.php'; */ 
	include("../../php_crud/my_class.php");
	$obj = new my_class();
	session_start();
	extract($_REQUEST);
?>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.css" rel="stylesheet" media="all" type="text/css" />
<table id="ground_water_tbl" class="table table-striped table-bordered table-hover">
    <thead>
        <tr style="font-family: 'Open Sans';">
            <th>SL.</th>
            <th>WELL ID</th>
			<th>OLD WELL ID</th>
            <th>DISTRICT</th>
			<th>UPAZILA</th>
			<th>LATITUDE</th>
			<th>LONGITUDE</th>
			<th>FROM DATE</th>
			<th>TO DATE</th>
			<th>ACTION</th>
        </tr>
    </thead>
    <tbody>
    <?php
		$table_name =  "TBLGWH_BASICINFOMST ST INNER JOIN TBLGWH_GWHDATADTL GWT ON GWT.STATIONID = ST.NEW_ID LEFT JOIN TBLGWH_DISTRICTINFO DT ON ST.DISTRICTCODE=DT.ID LEFT JOIN TBLGWH_UPAZILA UPZ ON ST.UPAZILACODE = UPZ.ID";
		if($division_id!=""){
			//$where_cond = "ST.NEW_ID IS NOT NULL AND ST.DIVISIONCODE='$division_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_date','DD-MM-YYYY') AND TO_DATE('$to_date','DD-MM-YYYY') GROUP BY ST.NEW_ID,ST.OLD_ID,DT.DISTRICTNAME, UPZ.UPAZILANAME,ST.LATITUDE,ST.LONGITUDE";
			$where_cond = "ST.NEW_ID IS NOT NULL AND ST.DIVISIONCODE='$division_id' GROUP BY ST.NEW_ID,ST.OLD_ID,DT.DISTRICTNAME, UPZ.UPAZILANAME,ST.LATITUDE,ST.LONGITUDE";
		} else if($sub_division_id!=""){
			$where_cond = "ST.NEW_ID IS NOT NULL AND ST.SUBDIVISIONCODE='$sub_division_id' GROUP BY ST.NEW_ID,ST.OLD_ID,DT.DISTRICTNAME, UPZ.UPAZILANAME,ST.LATITUDE,ST.LONGITUDE";
		} else if($district_id!=""){
			$where_cond = "ST.NEW_ID IS NOT NULL AND ST.DISTRICTCODE='$district_id' GROUP BY ST.NEW_ID,ST.OLD_ID,DT.DISTRICTNAME, UPZ.UPAZILANAME,ST.LATITUDE,ST.LONGITUDE";
		} else {
			$where_cond = "ST.NEW_ID IS NOT NULL GROUP BY ST.NEW_ID,ST.OLD_ID,DT.DISTRICTNAME, UPZ.UPAZILANAME,ST.LATITUDE,ST.LONGITUDE";
		}
		$column = "ST.NEW_ID,ST.OLD_ID, MIN(DATETIME) AS MIN_DATE, MAX(DATETIME) AS MAX_DATE, DT.DISTRICTNAME,UPZ.UPAZILANAME,ST.LATITUDE,ST.LONGITUDE";
		$row=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);
		$i = 1;
		foreach($row AS $index=>$val){
			echo "<tr>";  
				$id=$val['GWT.SLNO'];
				?>              
				<td><?php echo $i;?></td>
				<td><?php echo $val['NEW_ID'];?></td>
				<td><?php echo $val['OLD_ID'];?></td>
				<td><?php echo $val['DISTRICTNAME'];?></td>
				<td><?php echo $val['UPAZILANAME'];?></td>
				<td><?php echo $val['LATITUDE'];?></td>
				<td><?php echo $val['LONGITUDE'];?></td>
				
				<td><?php echo $val['MIN_DATE'];?></td>
				<td><?php echo $val['MAX_DATE'];?></td>
				<td>
					<button class="label label-primary" onclick="show_graph('<?php echo $val['NEW_ID'];?>')"><i class="icon-bar-chart"></i> Show Graph</button> 
				</td>
				<?php           
			echo " </tr>";
			$i++;
		}
	?>
    </tbody>
</table>
<script type="text/javascript">			
	var oTable2 = $('#ground_water_tbl').dataTable( {
	"aoColumns": [
	  { "bSortable": true },
	  null, null,null, null,null, null,null,null,
	  { "bSortable": true }
	],
	"iDisplayLength": 50
	} );
</script>