<?php
include("dbConfig.php");
header('Content-Type: application/json; charset=utf-8');

$employ_id = $_GET['employ_id'];
$hodor_ensraf_date = $_GET['hodor_ensraf_date'];
$hodor_time = $_GET['hodor_time'];
$company_id = $_GET['company_id'];
$system_id = '2222';
 $sql_top="SELECT * FROM waseet_company_user_tbl where stop='0' AND deleted='0' AND company_id='$company_id' AND user_type='Top_Manager' ";
                   $result_top = $conn->query($sql_top);
                   if ($result_top->num_rows > 0) {
                   $row_top = $result_top->fetch_assoc();
                    $user_id_top_manager=$row_top['user_id'];
                   }
                   $sql_finger_printer="SELECT * FROM hr_employ_tbl where employ_id='$employ_id'";
                   $result_finger_printer = $conn->query($sql_finger_printer);
                   if ($result_finger_printer->num_rows > 0) {
                   $row_finger_printer = $result_finger_printer->fetch_assoc();
                    $employee_number_fingerprint=$row_finger_printer['employee_number_fingerprint'];
                   }
                   
date_default_timezone_set("Asia/Riyadh");
$createdDate = date("Y-m-d");
$createdDate_Time = date("Y-m-d h:i:sa");

if($employ_id!='' && $hodor_ensraf_date!="0000-00-00" && $hodor_time!="00:00:00"){

    // Update the existing record
    $sql_request = "UPDATE hr_add_hodor_ensraf_tbl SET ensraf_time = '$hodor_time',hodor_ensraf_stat='1',createdDate = '$createdDate',createdDate_Time = '$createdDate_Time' WHERE employ_id='$employ_id' AND hodor_ensraf_date='$hodor_ensraf_date'";

    if ($conn->query($sql_request) === TRUE) {
         //==================العملايات==================================

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$employ_id;
 $add_user_id = $employ_id;
 $system_type='hr_marsa_system';
  $proccess_type='Fingerprint Attendance Recording through the Hr app';
  $proccess_details_en='Fingerprint Attendance Recording through the Hr app';
  $proccess_details='تسجيل حضور وانصراف عن طريق التطبيق';
 $table_name='hr_add_hodor_ensraf_tbl';   
  date_default_timezone_set("Asia/Riyadh");
  $createdDate = date("Y-m-d h:i:sa");
   $sql_req = "INSERT INTO process_systems_tbl(system_type,user_id,user_ip,proccess_type,proccess_details,proccess_details_en,table_name,proccess_id,proccess_date,process_time,process_datetime,browser)values('$system_type','$add_user_id','$user_ip','$proccess_type','$proccess_details','$proccess_details_en','$table_name','$user_id',NOW(),NOW(),'$createdDate','$browserAgent')";
  $run = $conn->query($sql_req) or die("Error in saving ".$conn->error); 
 //==================العملايات==================================

        $success = true;
    $response = array(
        'success' => $success,
        'msg' => "تمت الإضافة بنجاح",
        'status' => "success",
    );
    } else {
        $success = false;
        $response = array(
            'success' => $success,
            'msg' => "هناك خطاء الرجاء اعادة المحاوله",
            'status' => "unsuccess",
        );
    }

}else{
    $success = false;
    $response = array(
        'success' => $success,
        'msg' => "empty",
        'status' => "unsuccess",
    );
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);
?>