<?php
include("../../php_crud/my_class.php");
$obj = new my_class();
session_start();
extract($_REQUEST);

// $where = "STAT.DATA_READ_TYPE IN ('AUTO','BOTH') AND STATUS_TBL.RAW_PARAMETER_ID='474' AND STATUS_TBL.STATION_TYPE='AUTO' AND STAT.WELL_DATA_TYPE='1'";
// print_r($where);
$where = "RAW_PARAMETER_ID='474' AND DATA_READ_TYPE IN ('AUTO','BOTH') AND STATION_TYPE='AUTO' AND WELL_DATA_TYPE='1'";



if ($hydro_div == "all") {
	$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND RAW_PARAMETER_ID='474' AND STATION_TYPE='AUTO' AND WELL_DATA_TYPE='1'";
	// print_r($where);
} else {
	if ($hydro_div != "" && $hydro_sub_div == "all" && $district == "") {
		$hydro_div_info = $obj->Details_By_Cond("HYDROLOGY.DIVCODE_TBL@HYDRO10", "HYDDIVCODE='$hydro_div'");
		$hydro_div_name = "<b><font color='#3d0099'>" . $hydro_div_info['DIVISION_NAME'] . "</font></b>";
		$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND WELL_DATA_TYPE='1' AND STATION_TYPE='AUTO' AND RAW_PARAMETER_ID='474' AND HYDDIVCODE='$hydro_div'";
		// $label = "$station_type_name Stations Status Information for Hydro-Division: $hydro_div_name";
	} else if ($hydro_div != "" && $hydro_sub_div == "all" && $district != "") {
		$hydro_div_info = $obj->Details_By_Cond("HYDROLOGY.DIVCODE_TBL@HYDRO10", "HYDDIVCODE='$hydro_div'");
		$hydro_div_name = "<b><font color='#3d0099'>" . $hydro_div_info['DIVISION_NAME'] . "</font></b>";
		$dist_info = $obj->Details_By_Cond("HYDROLOGY.DISTRICT_TBL@HYDRO10", "DISTRICT_NO='$district'");
		$dist_name = "<b><font color='#3d0099'>" . $dist_info['DISTRICT_NAME'] . "</font></b>";
		$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND WELL_DATA_TYPE='1' AND STATION_TYPE='AUTO' 
			AND RAW_PARAMETER_ID='474' AND HYDDIVCODE='$hydro_div' AND DISTRICT_NO='$district'";
		// $label = "$station_type_name Stations Status Information for Hydro-Division: $hydro_div_name and District: $dist_name";
	} else if ($hydro_div != "" && $hydro_sub_div != "" && $district == "") {
		$hydro_div_info = $obj->Details_By_Cond("HYDROLOGY.DIVCODE_TBL@HYDRO10", "HYDDIVCODE='$hydro_div'");
		$hydro_div_name = "<b><font color='#3d0099'>" . $hydro_div_info['DIVISION_NAME'] . "</font></b>";
		$hydro_sub_div_info = $obj->Details_By_Cond("HYDROLOGY.SUBDIVCODE_TBL@HYDRO10", "HYDSUBDIVCODE='$hydro_sub_div'");
		$hydro_sub_div_name = "<b><font color='#3d0099'>" . $hydro_sub_div_info['SUBDIVISION_NAME'] . "</font></b>";
		$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND WELL_DATA_TYPE='1' AND STATION_TYPE='AUTO' 
			AND RAW_PARAMETER_ID='474' AND HYDDIVCODE='$hydro_div' AND HYDSUBDIVCODE='$hydro_sub_div'";
		// $label = "$station_type_name Stations Status Information for Hydro-Division: $hydro_div_name and Hydro-Subdivision: $hydro_sub_div_name";
	} else if ($hydro_div != "" && $hydro_sub_div != "" && $district != "") {
		$hydro_div_info = $obj->Details_By_Cond("HYDROLOGY.DIVCODE_TBL@HYDRO10", "HYDDIVCODE='$hydro_div'");
		$hydro_div_name = "<b><font color='#3d0099'>" . $hydro_div_info['DIVISION_NAME'] . "</font></b>";
		$hydro_sub_div_info = $obj->Details_By_Cond("HYDROLOGY.SUBDIVCODE_TBL@HYDRO10", "HYDSUBDIVCODE='$hydro_sub_div'");
		$hydro_sub_div_name = "<b><font color='#3d0099'>" . $hydro_sub_div_info['SUBDIVISION_NAME'] . "</font></b>";
		$dist_info = $obj->Details_By_Cond("HYDROLOGY.DISTRICT_TBL@HYDRO10", "DISTRICT_NO='$district'");
		$dist_name = "<b><font color='#3d0099'>" . $dist_info['DISTRICT_NAME'] . "</font></b>";
		$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND WELL_DATA_TYPE='1' AND STATION_TYPE='AUTO' 
			AND RAW_PARAMETER_ID='474' AND HYDDIVCODE='$hydro_div' AND HYDSUBDIVCODE='$hydro_sub_div' 
			AND DISTRICT_NO='$district'";
		// $label = "$station_type_name Stations Status Information for Hydro-Division: $hydro_div_name, Hydro-Subdivision: $hydro_sub_div_name and District: $dist_name";
	} else {
		// $label = "$station_type_name Stations Status Information";
		$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND WELL_DATA_TYPE='1' AND STATION_TYPE='AUTO' AND RAW_PARAMETER_ID='474'";
		// print_r($where);

	}
}


$status_label = "Status type: ";
if ($sw_status == 0) {
	$where = $where . "";
	$status_label .= "<b><font color='#8B008B'>Active & Inactive</font></b>";
} else if ($sw_status == 3) {
	$where = $where . " AND STATION_STATUS='ACTIVE'";
	$status_label .= "<b><font color='#228B22'>Active</font></b>";
} else if ($sw_status == 2) {
	$where = $where . " AND STATION_STATUS='INACTIVE' AND DIFF_HOURS<='72' AND DIFF_HOURS>='24'";
	$status_label .= "<b><font color='#000080'>Inactive for 24-72 Hours</font></b>";
} else if ($sw_status == 1) {
	$where = $where . " AND STATION_STATUS='INACTIVE' AND DIFF_HOURS>'72'";
	$status_label .= "<b><font color='#FF0000'>Inactive for more than 72 Hours</font></b>";
	// print_r($status_label);
} else if ($sw_status == 4) {
	$diff_hours_input = $inactive_days * 24;
	$where = $where . " AND STATION_STATUS='INACTIVE' AND DIFF_HOURS>'$diff_hours_input'";
	$status_label .= "<b><font color='#b30000'>Inactive for more than $inactive_days days</font></b>";
}else if ($sw_status == 5) {
	$where = $where . " AND STATION_STATUS='INACTIVE'";
	$status_label .= "<b><font color='#FF0000'>Inactive</font></b>";
} else {
	$where = $where . "";
	$status_label .= "<b><font color='#8B008B'>Active & Inactive</font></b>";
}
//echo $where; exit;
?>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.css" rel="stylesheet" media="all" type="text/css" />
<div style="margin-top: 20px;">
	<h4><?php echo $status_label; ?></h4>
	<!-- <h6 style="font-style: italic; font-weight: bold;">
		<font style='color: #228B22;'>* Active or inactive for 24 hours</font>,
		<font style='color: #000080;'>* Inactive for 24-72 hours</font>,
		<font style='color: #ff3300;'>* Inactive for more than 72 hours</font>
	</h6> -->
	<table id="ground_water_tbl" class="table table-striped table-bordered table-hover">
		<thead>
			<tr style="font-family: 'Open Sans';">
				<td style="text-align: center;font-size:13px;" class="table-header">Sl</td>
				<td style="text-align: center;font-size:13px;" class="table-header">Division</td>
				<td style="text-align: center;font-size:13px;" class="table-header">Sub Division</td>
				<td style="text-align: center;font-size:13px;" class="table-header">District</td>
				<td style="text-align: center;font-size:13px;" class="table-header">Total Stations</td>
				<td style="text-align: center;font-size:13px;" class="table-header">Active Station</td>
				<td style="text-align: center;font-size:13px;" class="table-header">Inactive Station</td>
			</tr>
		</thead>

		<tbody>
			<?php

			$sl = 0;
			foreach ($obj->ground_water_auto_station_status_summary($where) as $value) {
				// print_r($value);
                // exit();
				$sl++;
			?>
				<tr>
					<td style="font-size: 14px; text-align: center;"><?php echo $sl; ?></td>
					<td style="font-size: 14px; text-align: left; padding-left: 10px;"><?php echo $value['DIVISION_NAME']; ?></td>
					<td style="font-size: 14px; text-align: left; padding-left: 10px;"><?php echo $value['SUBDIVISION_NAME']; ?></td>
					<td style="font-size: 14px; text-align: center;"><?php echo $value['DISTRICT_NAME']; ?></td>
					<td style="font-size: 14px; text-align: center;"><?php echo $value['TOTAL_STATIONS']; ?></td>
					<td style="font-size: 14px; text-align: center;"><?php echo $value['ACTIVE_STATIONS']; ?></td>
					<td style="font-size: 14px; text-align: center;"><?php echo $value['INACTIVE_STATIONS']; ?></td>
				</tr>
			<?php } ?>

		</tbody>
	</table>
</div>
<script type="text/javascript">
	var oTable2 = $('#ground_water_tbl').dataTable({
		"aoColumns": [{
				"bSortable": true
			},
			null, null, null, null, null,
			{
				"bSortable": true
			}
		],
		"iDisplayLength": 50
	});
</script>