<?php
session_start();
include("../../php_crud/my_class.php");
$obj = new my_class();
extract($_REQUEST);
//extract($_GET);
$user_id = $_SESSION['LOGIN_USERID'];
$date = date('d-M-y H:i:s');
$date = strtoupper($date);
if ($operation == "single_col_save") {
	//$day_hr_val = explode("_",$col_name);
	//$day_val = $day_hr_val[1];
	$time = mktime(12, 0, 0, $month, $sel_day, $year);
	if (date('m', $time) == $month) {
		$show_date = date('d-M-y', $time);
		$show_date = strtoupper($show_date);
	}
	$date_time = "";
	if ($col_name == '6hr') {
		$date_time = "$show_date 06:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//	print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == '9hr') {
		$date_time = "$show_date 09:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == '12hr') {
		$date_time = "$show_date 12:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == '15hr') {
		$date_time = "$show_date 15:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == '18hr') {
		$date_time = "$show_date 18:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == 'ht') {
		if (strlen($col_val) == 3) {
			$col_val = "0" . $col_val;
		}
		$ht_hr = substr($col_val, 0, 2);
		$ht_min = substr($col_val, 2);
		$date_time = "$show_date $ht_hr:$ht_min:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['DATA_TYPE'] = "'H'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$show_date' AND DATA_TYPE='H'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == 'hwl') {
		$date_time = "$show_date $ht_val";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'H'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$show_date' AND DATA_TYPE='H'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == 'lt') {
		if (strlen($col_val) == 3) {
			$col_val = "0" . $col_val;
		}
		$lt_hr = substr($col_val, 0, 2);
		$lt_min = substr($col_val, 2);
		$date_time = "$show_date $lt_hr:$lt_min:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['DATA_TYPE'] = "'L'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$show_date' AND DATA_TYPE='L'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else if ($col_name == 'lwl') {
		if (strlen($lt_val) == 3) {
			$lt_val = "0" . $lt_val;
		}
		$lt_hr = substr($lt_val, 0, 2);
		$lt_min = substr($lt_val, 2);
		$date_time = "$show_date $lt_hr:$lt_min:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['WL'] = "'$col_val'";
		$form_data_update['DATA_TYPE'] = "'L'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$show_date' AND DATA_TYPE='L'";
		echo $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
	} else {
		echo "invalid information";
	}
}

if ($operation == "multiple_rows_save") {
	$ret_msg = 1; // Initialize $ret_msg to 1, assuming all rows will be saved successfully

	$newDate = date("d-M-y", strtotime($sel_date));
	$newDate = strtoupper($newDate);
	$date_time = "";
	// Assuming $obj is your database object, adapt the following code for each row
	foreach ($rows as $row) {
		$station_id = $row['station_id']; // Adapt this based on your data structure
		$date_time = $row['date_time'];   // Adapt this based on your data structure
		$six_hr = $row['six_hr'];         // Adapt this based on your data structure
		$nine_hr = $row['nine_hr'];       // Adapt this based on your data structure
		$twelve_hr = $row['twelve_hr'];   // Adapt this based on your data structure
		$fifteen_hr = $row['fifteen_hr']; // Adapt this based on your data structure
		$eighteen_hr = $row['eighteen_hr']; // Adapt this based on your data structure

		if ($six_hr != '') {
			$date_time = "$newDate 06:00:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['WL'] = "'$six_hr'";
			$form_data_update['DATA_TYPE'] = "'R'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
			//echo "<br/>";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($nine_hr != '') {
			$date_time = "$newDate 09:00:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['WL'] = "'$nine_hr'";
			$form_data_update['DATA_TYPE'] = "'R'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($twelve_hr != '') {
			$date_time = "$newDate 12:00:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['WL'] = "'$twelve_hr'";
			$form_data_update['DATA_TYPE'] = "'R'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($fifteen_hr != '') {
			$date_time = "$newDate 15:00:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['WL'] = "'$fifteen_hr'";
			$form_data_update['DATA_TYPE'] = "'R'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($eighteen_hr != '') {
			$date_time = "$newDate 18:00:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['WL'] = "'$eighteen_hr'";
			$form_data_update['DATA_TYPE'] = "'R'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($tidal_status == "T") {
			if ($high_time != '') {
				if (strlen($high_time) == 3) {
					$high_time = "0" . $high_time;
				}
				$ht_hr = substr($high_time, 0, 2);
				$ht_min = substr($high_time, 2);
				$date_time = "$newDate $ht_hr:$ht_min:00";
				$form_data_update['STATION_ID'] = "'$station_id'";
				$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
				$form_data_update['DATA_TYPE'] = "'H'";
				$form_data_update['UPDT_BY'] = "'$user_id'";
				$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
				//echo "<br/>";
				//print_r($form_data_update);
				//echo "<br/>";
				$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='H'";
				$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
				if ($update2 == 1) {
					$ret_msg = 1;
				} else {
					$ret_msg = 0;
				}
			}
			if ($highest_wl != '') {
				if (strlen($high_time) == 3) {
					$high_time = "0" . $high_time;
				}
				$ht_hr = substr($high_time, 0, 2);
				$ht_min = substr($high_time, 2);
				$date_time = "$newDate $ht_hr:$ht_min:00";
				$form_data_update['STATION_ID'] = "'$station_id'";
				$form_data_update['WL'] = "'$highest_wl'";
				$form_data_update['DATA_TYPE'] = "'H'";
				$form_data_update['UPDT_BY'] = "'$user_id'";
				$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
				//echo "<br/>";
				//print_r($form_data_update);
				//echo "<br/>";
				$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='H'";
				$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
				if ($update2 == 1) {
					$ret_msg = 1;
				} else {
					$ret_msg = 0;
				}
			}
			if ($low_time != '') {
				if (strlen($low_time) == 3) {
					$low_time = "0" . $low_time;
				}
				$lt_hr = substr($low_time, 0, 2);
				$lt_min = substr($low_time, 2);
				$date_time = "$newDate $lt_hr:$lt_min:00";
				$form_data_update['STATION_ID'] = "'$station_id'";
				$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
				$form_data_update['DATA_TYPE'] = "'L'";
				$form_data_update['UPDT_BY'] = "'$user_id'";
				$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
				//echo "<br/>";
				//print_r($form_data_update);
				//echo "<br/>";
				$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='L'";
				$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
				if ($update2 == 1) {
					$ret_msg = 1;
				} else {
					$ret_msg = 0;
				}
			}
			if ($lowest_wl != '') {
				if (strlen($low_time) == 3) {
					$low_time = "0" . $low_time;
				}
				$lt_hr = substr($low_time, 0, 2);
				$lt_min = substr($low_time, 2);
				$date_time = "$newDate $lt_hr:$lt_min:00";
				$form_data_update['STATION_ID'] = "'$station_id'";
				$form_data_update['WL'] = "'$lowest_wl'";
				$form_data_update['DATA_TYPE'] = "'L'";
				$form_data_update['UPDT_BY'] = "'$user_id'";
				$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
				//echo "<br/>";
				//print_r($form_data_update);
				//echo "<br/>";
				$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='L'";
				$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
				if ($update2 == 1) {
					$ret_msg = 1;
				} else {
					$ret_msg = 0;
				}
			}
		}
		if ($remarks != '') {
			//echo "remarks";
			$form_data['STATION_ID'] = "'$station_id'";
			$form_data['PARAMETER_TYPE'] = "'WL'";
			$form_data['YEAR'] = "'$year'";
			$form_data['MONTH'] = "'$month'";
			$form_data['REMARKS'] = "'$remarks'";
			$form_data['INSERT_BY'] = "'$user_id'";
			$form_data['INSERT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//print_r($form_data);
			$update_cond = "STATION_ID='$station_id' AND  YEAR = '$year' AND MONTH = '$month'";
			$update3 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWPB_REMARKS@HYDRO10', $form_data, $update_cond);
			if ($update3 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
	}
	echo $ret_msg;

	// if ($remarks != '') {
	//     $form_data['STATION_ID'] = "'$station_id'";
	//     $form_data['PARAMETER_TYPE'] = "'WL'";
	//     $form_data['YEAR'] = "'$year'";
	//     $form_data['MONTH'] = "'$month'";
	//     $form_data['REMARKS'] = "'$remarks'";
	//     $form_data['INSERT_BY'] = "'$user_id'";
	//     $form_data['INSERT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS'";
	//     $update_cond = "STATION_ID='$station_id' AND YEAR = '$year' AND MONTH = '$month'";
	//     $update3 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('SWPB_REMARKS', $form_data, $update_cond);

	//     if ($update3 !== 1) {
	//         $ret_msg = 0; // Set $ret_msg to 0 if the operation fails for the remarks
	//     }
	// }

	// echo $ret_msg; // Return the overall result for all rows
}


if ($operation == "single_row_save") {
	$ret_msg = "";
	$newDate = date("d-M-y", strtotime($sel_date));
	$newDate = strtoupper($newDate);
	//echo $newDate;
	$date_time = "";
	if ($six_hr != '') {
		$date_time = "$newDate 06:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$six_hr'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data_update);
		//echo "<br/>";
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		//echo "<br/>";
		$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
		if ($update2 == 1) {
			$ret_msg = 1;
		} else {
			$ret_msg = 0;
		}
	}
	if ($nine_hr != '') {
		$date_time = "$newDate 09:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$nine_hr'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//echo "<br/>";
		//print_r($form_data_update);
		//echo "<br/>";
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
		if ($update2 == 1) {
			$ret_msg = 1;
		} else {
			$ret_msg = 0;
		}
	}
	if ($twelve_hr != '') {
		$date_time = "$newDate 12:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$twelve_hr'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//echo "<br/>";
		//print_r($form_data_update);
		//echo "<br/>";
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
		if ($update2 == 1) {
			$ret_msg = 1;
		} else {
			$ret_msg = 0;
		}
	}
	if ($fifteen_hr != '') {
		$date_time = "$newDate 15:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$fifteen_hr'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//echo "<br/>";
		//print_r($form_data_update);
		//echo "<br/>";
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
		if ($update2 == 1) {
			$ret_msg = 1;
		} else {
			$ret_msg = 0;
		}
	}
	if ($eighteen_hr != '') {
		$date_time = "$newDate 18:00:00";
		$form_data_update['STATION_ID'] = "'$station_id'";
		$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
		$form_data_update['WL'] = "'$eighteen_hr'";
		$form_data_update['DATA_TYPE'] = "'R'";
		$form_data_update['UPDT_BY'] = "'$user_id'";
		$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//echo "<br/>";
		//print_r($form_data_update);
		//echo "<br/>";
		$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY HH24:MI:SS')='$date_time' AND DATA_TYPE='R'";
		$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
		if ($update2 == 1) {
			$ret_msg = 1;
		} else {
			$ret_msg = 0;
		}
	}
	if ($tidal_status == "T") {
		if ($high_time != '') {
			if (strlen($high_time) == 3) {
				$high_time = "0" . $high_time;
			}
			$ht_hr = substr($high_time, 0, 2);
			$ht_min = substr($high_time, 2);
			$date_time = "$newDate $ht_hr:$ht_min:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['DATA_TYPE'] = "'H'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='H'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($highest_wl != '') {
			if (strlen($high_time) == 3) {
				$high_time = "0" . $high_time;
			}
			$ht_hr = substr($high_time, 0, 2);
			$ht_min = substr($high_time, 2);
			$date_time = "$newDate $ht_hr:$ht_min:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['WL'] = "'$highest_wl'";
			$form_data_update['DATA_TYPE'] = "'H'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='H'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($low_time != '') {
			if (strlen($low_time) == 3) {
				$low_time = "0" . $low_time;
			}
			$lt_hr = substr($low_time, 0, 2);
			$lt_min = substr($low_time, 2);
			$date_time = "$newDate $lt_hr:$lt_min:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['SWL_DATE'] = "TO_DATE('$date_time','DD-MON-YY HH24:MI:SS')";
			$form_data_update['DATA_TYPE'] = "'L'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='L'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
		if ($lowest_wl != '') {
			if (strlen($low_time) == 3) {
				$low_time = "0" . $low_time;
			}
			$lt_hr = substr($low_time, 0, 2);
			$lt_min = substr($low_time, 2);
			$date_time = "$newDate $lt_hr:$lt_min:00";
			$form_data_update['STATION_ID'] = "'$station_id'";
			$form_data_update['WL'] = "'$lowest_wl'";
			$form_data_update['DATA_TYPE'] = "'L'";
			$form_data_update['UPDT_BY'] = "'$user_id'";
			$form_data_update['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
			//echo "<br/>";
			//print_r($form_data_update);
			//echo "<br/>";
			$update_cond = "STATION_ID='$station_id' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$newDate' AND DATA_TYPE='L'";
			$update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWL_DATA@HYDRO10', $form_data_update, $update_cond);
			if ($update2 == 1) {
				$ret_msg = 1;
			} else {
				$ret_msg = 0;
			}
		}
	}
	if ($remarks != '') {
		//echo "remarks";
		$form_data['STATION_ID'] = "'$station_id'";
		$form_data['PARAMETER_TYPE'] = "'WL'";
		$form_data['YEAR'] = "'$year'";
		$form_data['MONTH'] = "'$month'";
		$form_data['REMARKS'] = "'$remarks'";
		$form_data['INSERT_BY'] = "'$user_id'";
		$form_data['INSERT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
		//print_r($form_data);
		$update_cond = "STATION_ID='$station_id' AND  YEAR = '$year' AND MONTH = '$month'";
		$update3 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.SWPB_REMARKS@HYDRO10', $form_data, $update_cond);
		if ($update3 == 1) {
			$ret_msg = 1;
		} else {
			$ret_msg = 0;
		}
	}
	echo $ret_msg;
}

// //delete data	
// if ($operation == "delete") {
// 	$date = date('d-M-y H:i:s');
// 	$date = strtoupper($date);
// 	$newDate = date("d-M-y", strtotime($in_date));
// 	$newDate = strtoupper($newDate);
// 	$date_time = "";
// 	$date_time = "$newDate";
// 	$update_cond = "STATION_ID='$station' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$date_time'";

// 	echo $update2 = $obj->Delete_Data('HYDROLOGY.SWL_DATA@HYDRO10', $update_cond);
// }
// //delete all
// if ($operation == "delete_all") {
// 	// Creating the start date of the month
// 	$start_date = date('d-M-y', strtotime($year . '-' . $month . '-01'));

// 	// Creating the end date of the month
// 	$end_date = date('d-M-y', strtotime('last day of ' . $year . '-' . $month));

// 	// Convert to uppercase
// 	$start_date = strtoupper($start_date);
// 	$end_date = strtoupper($end_date);

// 	$start_date = "$start_date";
// 	$end_date   = "$end_date";
// 	// $newDate = date("d-M-y", strtotime($sel_date));
// 	// $newDate = strtoupper($newDate);
// 	// $date_time = "";
// 	// $date_time = "$newDate";
// 	//print_r($start_date);
// 	// exit();
// 	$update_cond = "STATION_ID = '$station' AND TO_CHAR(SWL_DATE, 'DD-MON-YY') BETWEEN '$start_date' AND '$end_date'";
// 	// exit();
// 	echo $update2 = $obj->Delete_Data('HYDROLOGY.SWL_DATA@HYDRO10', $update_cond);
// 	// if ($update2) {
// 	// 	echo 1;
// 	// }
// }
//delete data	
if ($operation == "delete") {
	$date = date('d-M-y H:i:s');
	$date = strtoupper($date);
	$newDate = date("d-M-y", strtotime($in_date));
	$newDate = strtoupper($newDate);
	$date_time = "";
	$date_time = "$newDate";
	$update_cond = "STATION_ID='$station' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$date_time'";

	echo $update2 = $obj->Delete_Data('HYDROLOGY.SWL_DATA@HYDRO10',$update_cond);	
}
//delete all
if ($operation == "delete_all") {
	//echo 'hello';
	$newDate = date("d-M-y", strtotime($sel_date));
	$newDate = strtoupper($newDate);
	$date_time = "";
	$date_time = "$newDate";
	$update_cond = "STATION_ID='$station' AND TO_CHAR(SWL_DATE, 'DD-MON-YY')='$date_time'";
	echo $update2 = $obj->Delete_Data('HYDROLOGY.SWL_DATA@HYDRO10',$update_cond);
}
$conn_close_res = $obj->close_orcl_conn();
$obj = null;
