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

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

if($operation=="insert_lithology_material_code_data"){
	$flag = 0;
    // Convert $mat_code to lowercase
    $mat_code_lower = strtolower($mat_code);
    
    foreach ($obj->View_colmn_By_Cond("HYDROLOGY.LITHO_CODE_TBL@HYDRO10", "*", "1=1 ORDER BY MATERIAL_CODE") as $value) {
        // Convert $check_duplicate to lowercase
        $check_duplicate_lower = strtolower($value['MATERIAL_CODE']);
        
        if ($mat_code_lower == $check_duplicate_lower) {
            $flag = 1;
            echo $flag;
            exit();
        }
    }


	$form_data['MATERIAL_CODE'] = "'$mat_code'";
	$form_data['DESCRIPTION'] = "'$description'";
	$form_data['LOWER_SIZE'] = "'$lower_size'";
	$form_data['UPPER_SIZE'] = "'$upper_size'";
	$form_data['YL'] = "'$yl'";
	$form_data['YM'] = "'$ym'";
	$form_data['YH'] = "'$yh'";
	// $form_data['STATUS'] = "'$status'";
	$form_data['INSERT_BY'] = "'$user_id'";
	$form_data['INSERT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";

	$table_name = 'HYDROLOGY.LITHO_CODE_TBL@HYDRO10';
	// print_r($form_data);
	// exit();
	$insert = $obj->Insert_Data($table_name, $form_data);
	if($insert){
		$flag = 2;
	}
	echo $flag;
}


if($operation=="update_lithology_material_code_data"){

	//$form_data['MATERIAL_CODE'] = "'$mat_code'";
	$form_data['DESCRIPTION'] = "'$description'";
	$form_data['LOWER_SIZE'] = "'$lower_size'";
	$form_data['UPPER_SIZE'] = "'$upper_size'";
	$form_data['YL'] = "'$yl'";
	$form_data['YM'] = "'$ym'";
	$form_data['YH'] = "'$yh'";
	// $form_data['STATUS'] = "'$status'";
	$form_data['UPDT_BY'] = "'$user_id'";
	$form_data['UPDT_DTM'] = "TO_DATE('$date','DD-MON-YY HH24:MI:SS')";
	//$form_data['STATUS'] = "'$status'";

	$table_name = 'HYDROLOGY.LITHO_CODE_TBL@HYDRO10';
	// print_r($form_data);
	// exit();
	$where_cond = "MATERIAL_CODE='$mat_code'";	
	$update = $obj->Update_Data($table_name, $form_data, $where_cond);
	echo $update;
}

// delete part
if($operation=="delete"){
	$table_name = 'HYDROLOGY.LITHO_CODE_TBL@HYDRO10';
	$where_cond = "MATERIAL_CODE='$material_code'";
	$delete = $obj->Delete_Data_hydro($table_name, $where_cond);
	echo $delete;
}
//end delete part

?>