<?php
session_start();
// ============

include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============
$branchid = $_SESSION['LOGIN_BRANCH'];

?>
<div class="row-fluid">
    <table id="gw-station-table" class="table table-striped table-bordered table-hover">
		<thead>
            <th style="text-align: center;">SI No.</th>
			<th style="text-align: center;">Well Id</th>
			<th style="text-align: center;">Old Id</th>
			<th style="text-align: center;">District</th>
			<th style="text-align: center;">Upazilla</th>
			<th style="text-align: center;">Sub-Division</th>
            <th style="text-align: center;">Action</th>
		</thead>
		<tbody>
			<?php
			$sl=0;
			$cond = "HYDSUBDIVCODE LIKE 'GW%' ORDER BY WELL_ID";
			//foreach($obj->View_colmn_By_Cond("HYDROLOGY.GWM_TBL@HYDRO10","WELL_ID,OLD_ID,UPAZILA_CODE,HYDSUBDIVCODE","1=1 ORDER BY WELL_ID") as $value){
				foreach($obj->View_colmn_By_Cond("HYDROLOGY.GWM_TBL@HYDRO10 gm_tbl left join HYDROLOGY.UPAZILA_TBL@HYDRO10 upz on gm_tbl.UPAZILA_CODE = upz.UPZL_CODE
				left join  HYDROLOGY.DISTRICT_TBL@HYDRO10 dis on dis.DISTRICT_NO=upz.DST_CODE 
				left join  HYDROLOGY.GW_SUBDIVCODE_TBL@HYDRO10 subdiv_tble on subdiv_tble.HYDSUBDIVCODE = gm_tbl.HYDSUBDIVCODE",
				"gm_tbl.WELL_ID,gm_tbl.OLD_ID,gm_tbl.HYDSUBDIVCODE,upz.UPZL_NAME,dis.DISTRICT_NAME,subdiv_tble.SUBDIVISION_NAME
				","1=1 ORDER BY WELL_ID") as $value){	
				 $sl++;
				$well_id = $value['WELL_ID'];
				$old_id = $value['OLD_ID'];
				$upazila = $value['UPAZILA_CODE'];
				$sub_div = $value['HYDSUBDIVCODE'];
				$upz_name = $value['UPZL_NAME'];
				$dis_name = $value['DISTRICT_NAME'];
				$sd_name = $value['SUBDIVISION_NAME'];

				// $upz_info = $obj->Details_By_Cond("HYDROLOGY.UPAZILA_TBL@HYDRO10","UPZL_CODE='$upazila'");
				// $upz_name = $upz_info['UPZL_NAME'];
				// $dis_code = $upz_info['DST_CODE'];

				// $dis_info = $obj->Details_By_Cond("HYDROLOGY.DISTRICT_TBL@HYDRO10","DISTRICT_NO='$dis_code'");
				// $dis_name = $dis_info['DISTRICT_NAME'];

				// $sd_info = $obj->Details_By_Cond("HYDROLOGY.GW_SUBDIVCODE_TBL@HYDRO10","HYDSUBDIVCODE='$sub_div'");
				// $sd_name = $sd_info['SUBDIVISION_NAME'];

				$sd_text = "";
				if($sub_div == ""){
					$sd_text = "";
				}else{
					$sd_text = "$sd_name ($sub_div)";
				}

				echo "<tr>";
					echo "<td>".$sl."</td>";
					echo "<td>$well_id</td>";
					echo "<td>$old_id</td>";
					echo "<td>$dis_name</td>";
					echo "<td>$upz_name</td>";
					echo "<td>$sd_text</td>";
					//echo "<td>$sd_name ($sub_div)</td>";
						
					echo '<td style="text-align:right;">';
					if($_SESSION['edit']=='Y'){
						echo '<a class="label label-info" style="hover:cursor;" href="#modal-stat-view" data-toggle="modal" onclick="load_station_vw_modal(\''.$well_id.'\')"> <i class="fa fa-eye"></i> View</a>';
						echo '&nbsp;&nbsp;&nbsp;<a class="label label-success" style="hover:cursor;" href="#modal-stat-edit" data-toggle="modal" onclick="load_station_edit_modal(\''.$well_id.'\')"> <i class="fa fa-edit"></i> Edit</a>';
					}
					echo '</td>';
				echo "</tr>";
			}
			?>
		</tbody>
	</table>
</div>
<script type="text/javascript">
$(document).ready(function() {
    var oTable2 = $('#gw-station-table').DataTable({
        "columns": [
            { "orderable": true },
            null, null, null, null,
            { "orderable": true }
        ],
        "iDisplayLength": 50
    });
});
</script>