<style>
	th {
		border-bottom: 1px solid #EAEAEA !important;
	}

	hr {
		margin-bottom: 0;
	}
</style>
<?php
include("../../php_crud/my_class.php");
$obj = new my_class();
error_reporting(E_ALL); // Report all types of errors
ini_set('display_errors', 1); // Display errors on the screen

require_once '../../asset/mpdf/vendor/autoload.php';
extract($_REQUEST);
$where = "STAT.DATA_READ_TYPE IN ('AUTO','BOTH') AND STATUS_TBL.RAW_PARAMETER_ID='474' AND STATUS_TBL.STATION_TYPE='AUTO'";



if ($hydro_div == "all") {
	$where = "DATA_READ_TYPE IN ('AUTO','BOTH') AND RAW_PARAMETER_ID='474' AND STATION_TYPE='AUTO'";
	// 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 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 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 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 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 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>";
} 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>";
}

$html .= '
	<html>
	<head>
		<title>GROUND WATER DATA AVAILABILITY STATUS</title>
		<link href="https://fonts.googleapis.com/css?family=Tangerine" rel="stylesheet">
	</head>
	<body>
    <table style="width: 100%;" border="0" cellpadding="0" cellspacing="0" class="table table-bordered table-striped table-bordered table-hover">
		<tr>
			<td style="text-align: center; width: 25%">
				<img src="../../asset/custom/site_images/BWDB-LOGO.jpg" width="100px" />
			</td>
			<td style="text-align: left; width: 75%;">
				<h3 style="text-align: center;">GROUND WATER DATA AVAILABILITY</h3>
                <h3 style="text-align: center;">BANGLADESH WATER DEVELOPMENT BOARD (BWDB)</h3>		
			</td>
		</tr>
	</table>
	<br/>
	  <table style="width: 80%; margin: auto; font-size: 15px !important; border-collapse: collapse;" border="1" cellpadding="5" cellspacing="0" id="station_tbl" class="table table-bordered table-striped table-hover">
        <thead>
            <tr style="background: #f2f2f2;">
                <th style="text-align: center; padding: 8px;">Sl.</th>
                <th style="text-align: center; padding: 8px;">Well Id</th>
                <th style="text-align: center; padding: 8px;">District</th>
                <th style="text-align: center; padding: 8px;">Upazila</th>
                <th style="text-align: center; padding: 8px;">Latitude</th>
                <th style="text-align: center; padding: 8px;">Longitude</th>
                <th style="text-align: center; padding: 8px;">First Date</th>
                <th style="text-align: center; padding: 8px;">To Date</th>
            </tr>
        </thead>
        <tbody>';
		$sl = 0;
		foreach ($obj->load_graph_datatable($where) as $value) {
			$sl++;
			$color_status = "";
			$well_id = $value['STATION_ID'];
			$last_rec_date = $value['LASTRECEIVE_DATE'];
			if ($value['DIFF_HOURS'] > 72) {
				$color_status = "color: #ff3300;";
			} else if ($value['DIFF_HOURS'] <= 72 && $value['DIFF_HOURS'] > 24) {
				$color_status = "color: #000080;";
			} else if ($value['DIFF_HOURS'] <= 24) {
				$color_status = "color: #228B22;";
			}
			
			$database_date_obj = DateTime::createFromFormat('d-M-y', $last_rec_date);
			$database_date_obj->setTime(0, 0, 0);
			$current_date_obj = new DateTime();
			$current_date_obj->setTime(0, 0, 0);
			
			//$font_weight = "";
			if ($database_date_obj > $current_date_obj) {
				$color_status = "color: #ff0066;";
				//$font_weight = "font-weight: bold;";
			}
				
			$html .= "<tr>
                <td style='font-size: 14px; text-align: center;".$color_status."'>".$sl."</td>
                <td style='text-align: center; padding: 8px; ".$color_status."'>".$well_id."</td>
                <td style='padding: 8px;".$color_status."'>".$value['DISTRICT_NAME']."</td>
                <td style='padding: 8px;".$color_status."'>".$value['UPZL_NAME']."</td>
                <td style='text-align: center; padding: 8px;".$color_status."'>".$value['AUTO_LAT']."</td>
                <td style='text-align: center; padding: 8px;".$color_status."'>".$value['AUTO_LONG']."</td>
                <td style='text-align: center; padding: 8px;".$color_status."'>".$value['FIRSTRECEIVE_DATE']."</td>
                <td style='text-align: center; padding: 8px;".$color_status."'>".$value['LASTRECEIVE_DATE']."</td>
            </tr>";
		}
		$html .= '</tbody></table>';
        $html .='</body>
        </html>';

//==============================================================
//==============================================================
//==============================================================
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetFooter('Powered by Leotech | {PAGENO} of {nbpg}');
$mpdf->SetMargins(10, 10, 10,10); // Set top, right, bottom, left margins
$mpdf->shrink_tables_to_fit = false; // Prevent tables from shrinking
$mpdf->default_font_size = 12; // Set default font size for the document
// $mpdf->list_indent_first_level = 0;	// 1 or 0 - whether to indent the first level of a list
$mpdf->SetDisplayMode('fullpage');
// LOAD a stylesheet
// $stylesheet = file_get_contents('mpdfstyletables.css');
// $mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text
// $mpdf->WriteHTML($html,2);
$mpdf->WriteHTML($html);
$mpdf->Output();
//==============================================================
//==============================================================
//==============================================================
?>