<?php 
session_start();
include("../../php_crud/my_class.php");
$obj = new my_class();
extract($_POST);
//print_r($_POST);
//echo "23474";


$date_list = $_POST['sel_date'];
//echo $date_list;
$water_table_list = $_POST['water_tbl_list'];
$operation = $_POST['operation'];
$well_id = $_POST['well_id'];
$district = $_POST['district'];
$upazilla = $_POST['upazilla'];

$user_id = $_SESSION['LOGIN_USERID'];
//for current date
$date = date('d-M-y H:i:s');
$date = strtoupper($date);


////////////////////////////////////
/*if($operation=="get_water_tbl_sum"){
	$gwd_cond = "WELL_ID='$well_id' AND TO_CHAR(DT, 'MM-YYYY')='$month-$year'";
	$gwd_cols = "SUM(WATER_TBL) AS TOT_WATER_DATA";
	$gwd_info = $obj->View_column_details_By_Cond_hydro("GWT_DILY_TBL ",$gwd_cols,$gwd_cond);
	echo $gwd_info['TOT_WATER_DATA'];
}*/
if($operation=="single_row_save"){

	$newDate = date("d-M-y", strtotime($date_list));
    $newDate = strtoupper($newDate);
    $date_time = "";
       $date_time = "$newDate";
		$form_data_update['WELL_ID'] = "'$well_id'";
		$form_data_update['DST_CODE'] = "'$district'";
		$form_data_update['UPZL_CODE'] = "'$upazilla'";
		$form_data_update['DT'] = "TO_DATE('$newDate', 'DD-MON-RR')";
		$form_data_update['WATER_TBL'] = "'$water_table_list'";
		$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);
	    // exit();
		$update_cond = "WELL_ID='$well_id' AND TO_CHAR(DT, 'DD-MON-YY')='$newDate'";
        $update2 = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.GWT_DILY_TBL@HYDRO10', $form_data_update, $update_cond);
		
    
}
///////////////////////////////////
if($operation == "single_row_save"){
	//echo"00000";
	$ret_msg = 0;
	$date_list_arr = explode(",", $date_list);
	//echo $date_list_arr;
	$water_tbl_list_arr = explode(",", $water_table_list);
	$district_list_arr = explode(",", $dis_list);
	$upazilla_list_arr = explode(",", $upz_list);

	for($i=0; $i<count($date_list_arr); $i++) {
		$dateListValue = explode("#", $date_list_arr[$i]);
		
		$water_tblListValue = explode("#", $water_tbl_list_arr[$i]);
		$newWater_tbl = $water_tblListValue[1];

		$dis_ListValue = explode("#", $district_list_arr[$i]);
		$new_dis = $dis_ListValue[1];

		$upz_ListValue = explode("#", $upazilla_list_arr[$i]);
		$new_upz = $upz_ListValue[1];

		$newDate = date("d-M-y", strtotime($dateListValue[1]));
    	$newDate = strtoupper($newDate);
    	$date_time = "";
		$date_time = "$newDate";
		
		$form_data_update['WELL_ID'] = "'$well_id'";
		$form_data_update['DST_CODE'] = "'$new_dis'";
		$form_data_update['UPZL_CODE'] = "'$new_upz'";
		$form_data_update['DT'] = "TO_DATE('$newDate', 'DD-MON-RR')";
		$form_data_update['WATER_TBL'] = "'$newWater_tbl'";
		$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);
		//exit();
		$update_cond = "WELL_ID='$well_id' AND TO_CHAR(DT, 'DD-MON-YY')='$newDate'";
       	$update = $obj->Update_Or_Insert_Data_By_Check_Duplicate('HYDROLOGY.GWT_DILY_TBL@HYDRO10', $form_data_update, $update_cond);
		//print_r($update);
		//exit();
		if($update){
			$ret_msg = 1;
		}
		else{
			echo $ret_msg;
		}
	}
	
}
//delete all
if ($operation == "delete_all") {

//////////////////////////////////////////////////////////////////////////////////////////	
	// $newDate = date("d-M-y", strtotime($sel_date));
    // $newDate = strtoupper($newDate);
    // $date_time = "";
    // $date_time = "$newDate";
////////////////////////////////////////////////////////////////////////////////////////
	$ret_msg = 0;
	$date_list_arr = explode(",", $date_list1);
	for($i=0; $i<count($date_list_arr); $i++) {

	$dateListValue = explode("#", $date_list_arr[$i]);
	$newDate = $dateListValue[1];
	$newDate = date("d-M-y", strtotime($dateListValue[1]));
    $newDate = strtoupper($newDate);
    $date_time = "";
	$date_time = "$newDate";

	//echo "WELL_ID='$well_id' AND TO_CHAR(DT, 'DD-MON-YY')='$date_time'";
	$update_cond = "WELL_ID='$well_id' AND TO_CHAR(DT, 'DD-MON-YY')='$date_time'";
    $update2 = $obj->Delete_Data('HYDROLOGY.GWT_DILY_TBL@HYDRO10',$update_cond);	
	if($update2){
		$ret_msg = 1;
	}

}
echo $ret_msg;
}

$conn_close_res = $obj->close_hydro_orcl_conn();
$obj = null;
?>