<?php
include("dbConfig.php");

$id=$_POST["id"];
$att_type_id=$_POST["att_type_id"];
$attach_id=$_POST["attach_id"];
$add_user_id=$_POST["add_user_id"];

//--------------------------------------------
date_default_timezone_set("Asia/Riyadh");
$createdDate_Time = date("Y-m-d h:i:sa");
$createdDate = date("Y-m-d");
$createdTime = date("h:i:sa"); 
//--------------------------------------------
$d = 0;
for($i=0;$i<count($id);$i++){

    $sqlcheck="SELECT * FROM check_confirmation_tb where audit_type='".$_POST["id"][$i]."' and att_type_id='$att_type_id' and attach_id='$attach_id'";
    $result_check = $conn->query($sqlcheck);
    if ($result_check->num_rows > 0) {
        $d++;
    }else{
        $sql_w2 = "INSERT INTO check_confirmation_tb (audit_type,att_type_id,attach_id,add_user_id,created_datetime) VALUES ('".$_POST["id"][$i]."','$att_type_id','$attach_id','$add_user_id','$createdDate_Time') ";
        $run_w2 = $conn->query($sql_w2) or die("Error in saving ".$conn->error);  
        $d++;
    }
    
}

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$add_user_id;
 $system_type='hr_marsa_system';
  $proccess_type='auddit';
  $proccess_details_en='confirmation audit'.$attach_id;
$proccess_details_en='تدقيق النموذج رقم'.$attach_id;
 $table_name='check_confirmation_tb';   
  date_default_timezone_set("Asia/Riyadh");
  $createdDate = date("Y-m-d h:i:sa");
   $sql2 = "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','".$_POST["employee_number_fingerprint"][$i]."',NOW(),NOW(),'$createdDate','$browserAgent')";

if ($conn->query($sql2) === TRUE) {
} else {
  echo "Error: " . $sql2 . "<br>" . $conn->error;
}
 if($d>0){
echo "1";
 }                                   

?>



