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

$system_id=$_POST["system_id"];
$company_id_sel=$_POST["company_id_sel"];
$company_id=$_POST["company_id"];
$id=$_POST["id"];
$shift_id = $_POST["shift_id"];
$date_from = $_POST["date_from"];
$date_to = $_POST["date_to"];

$add_hours_hodoor = $_POST["add_hours_hodoor"];
$add_hours_shift = $_POST["add_hours_shift"];
$add_hours_khasm = $_POST["add_hours_khasm"];

$sum_salary = $_POST["sum_salary"];
$khasem_from_salary = $_POST["khasem_from_salary"];
$rest_sallary = $_POST["rest_sallary"];

$add_user_id = $_POST["add_user_id"];

$employee_number_fingerprint = $_POST["employee_number_fingerprint"];

//--------------------------------------------
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"); 
//--------------------------------------------
function GetSeriaother() {	
    $strings = '123456789';	
    $stringLength = strlen($strings);
    $newStrings = '';
    for ($i = 0; $i < 6; $i++) {
        $newStrings .= $strings[rand(0, $stringLength - 1)];
    }
    return $newStrings; 
}


$takeed_id=GetSeriaother();  


for($i=0;$i<count($id);$i++){
    


 $sql_w = "UPDATE hr_add_hodor_ensraf_tbl SET takeed_stat='1' WHERE employee_number_fingerprint='".$_POST["employee_number_fingerprint"][$i]."'";
 $run_w = $conn->query($sql_w) or die("Error in saving ".$conn->error);
  
  
// $sql_w2 = "INSERT INTO hr_takeed_hodor_ensraf_tbl (system_id,company_id,employ_id,shift_id,date_from,date_to,add_hours_hodoor,add_hours_shift,add_hours_ensraf,createdDate_Time,add_user_id) VALUES ('$system_id','".$_POST["company_id"][$i]."','".$_POST["id"][$i]."','".$_POST["shift_id"][$i]."','".$_POST["add_hours_hodoor"][$i]."','".$_POST["add_hours_shift"][$i]."','".$_POST["add_hours_ensraf"][$i]."','$date_from','$date_from','$createdDate_Time','$add_user_id') ";
 
$sql_w2 = "INSERT INTO hr_takeed_hodor_ensraf_tbl (system_id,company_id,employ_id,shift_id,date_from,date_to,add_hours_hodoor,add_hours_shift,add_hours_khasm,sum_salary,khasem_from_salary,rest_sallary,createdDate_Time,add_user_id) VALUES ('$system_id','".$_POST["company_id"][$i]."','".$_POST["id"][$i]."','".$_POST["shift_id"][$i]."','$date_from','$date_to','".$_POST["add_hours_hodoor"][$i]."','".$_POST["add_hours_shift"][$i]."','".$_POST["add_hours_khasm"][$i]."','".$_POST["sum_salary"][$i]."','".$_POST["khasem_from_salary"][$i]."','".$_POST["rest_sallary"][$i]."','$createdDate_Time','$add_user_id') ";
 $run_w2 = $conn->query($sql_w2) or die("Error in saving ".$conn->error);
 

 
//========================send_whats=================================
/*
 $br=  "\r\n";

 $sql_em1="SELECT * FROM hr_employ_tbl where employ_id='".$_POST["employ_id"][$i]."'   ";
       $result_em1 = $conn->query($sql_em1);
       if ($result_em1->num_rows > 0) {
        while($row_em1 = $result_em1->fetch_assoc()) {
            
     $employ_name_ar=$row_em1['employ_name_ar'];    
     $employ_name_en=$row_em1['employ_name_en'];    
     $mobile_number=$row_em1['mobile_number'];  
     $employ_email=$row_em1['employ_email'];   
    
        }}


 $url="https://www.marsalogistics.com/new/Shipping_Clearance_System/jquery/pages/marsa_log/ar/login/login.php";
  $dash='ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ';


    $url="https://www.marsalogistics.com/new/Shipping_Clearance_System/jquery/pages/marsa_log/ar/login/login.php";
   
$m_details_ar='نامل منكم الإفادة عن أسباب ذلك وعلیه تقدیم ما یؤید عذركم من خلال الرابط التالي ، علما بأنه في حالة عدم الالتزام سیتم اتخاذ اللازم حسب التعلیمات';

$m_details_en='We hope that you will inform us about the reasons for this and submit what supports your excuse through the following link, noting that in the event of non-compliance, the necessary measures will be taken according to the instructions.';

$m_day =$hodor_ensraf_date; $newDate = date('l', strtotime($m_day));

if($newDate=='Saturday'){
    $newDatee=$Saturday;
}elseif($newDate=='Sunday'){
 $newDatee=$Saturday;
}elseif($newDate=='Monday'){
 $newDatee=$Monday;
}elseif($newDate=='Tuesday'){
 $newDatee=$Tuesday;
}elseif($newDate=='Wednesday'){
 $newDatee=$Wednesday;
}elseif($newDate=='Thursday'){
 $newDatee=$Thursday;
}elseif($newDate=='Friday'){
 $newDatee=$Friday;
}


$url_m_ar='https://www.marsalogistics.com/new/hr_marsa_system/ar/login/login.php?lang=ar';

$url_m_en='https://www.marsalogistics.com/new/hr_marsa_system/ar/login/login.php?lang=en';


  $message_text_ar='السلام عليكم '.$br.'عزيزي الموظف / '.$br.$employ_name_ar.$br.' تم استثنائك من الخصم'.":".$br.$mosala_title_ar.$br.' : وذلك في يوم'.$br.$newDatee.$br.'التاريخ : '.$br.$hodor_ensraf_date.$br.$br.'التفاصيل / '.$br.'لتفاصيل اكثر يمكنك الدخول على نظام الشركه من خلال الرابط التالي'.$br.$url_m_ar.$br.$br.'إدارة الموادر البشرية-شركة مرسى'.$br.$br.'التأريخ والوقت'.$br.$createdDate_Time.$br.'شكرا لكم'.$br;


  //$message_text_ar='السلام عليكم '.$br.'عزيزي الموظف / '.$br.$employ_name_ar.$br.'يوجد لديك مسائله عنوان المسائله / '.$br.$mosala_title_ar.$br.' : وذلك في يوم'.$br.$newDatee.$br.'التاريخ : '.$br.$hodor_ensraf_date.$br.$br.'التفاصيل / '.$br.$m_details_ar.$br.'رابط التبرير'.$br.$url_m_ar.$br.$br.'إدارة الموادر البشرية-شركة مرسى'.$br.$br.'التأريخ والوقت'.$br.$createdDate_Time.$br.'شكرا لكم'.$br;

  $message_text_en='Hello'.$br.' Dear Employee / '.$br.$employ_name_en.$br.'You are exception cut'.":".$br.$mosala_title_en.$br.'In a day :'.$br.$newDate.$br.'The Date : '.$br.$hodor_ensraf_date.$br.$br.'Details / '.$br.'For more details you can access the company system through the following link'.$br.$url_m_en.$br.$br.'Human Resources Management - Marsa Company'.$br.$br.'Date And Time'.$br.$createdDate_Time.$br.'Thank you all'.$br;


$bb='--------------------------------------------------------';


$message_text2=$message_text_ar.$br.$bb.$br.$message_text_en;



 

// $body .= '<img src="https://www.marsalogistics.com/new/Shipping_Clearance_System/jquery/pages/marsa_log/ar/login/my_icon.jpg" alt="Hotel" /><br/>';

$message_text22=$br.$message_text_ar.$br.$bb.$br.$message_text_en;



$user_id = $_POST["user_id"];

            
                            
//for($i=0;$i<count($id);$i++){

$m=$mobile_number;
$s=$message_text2;
$data["mobile"]="966568884014";
$data["password"]="Compre123";
$data["instanceid"]="19862";
$data["numbers"]=$m;
$data["type"]="1";
$data["message"]=$s;
$data["json"]="1";


$timeout = 10;

$ch = curl_init();    
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );     
curl_setopt( $ch, CURLOPT_URL, "https://hiwhats.com/API/send" );     
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );     
curl_setopt( $ch, CURLOPT_ENCODING, "" );     
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );     
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );     
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls     
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );  
if(!empty($data) && is_array($data)){
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
}
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );    
curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );     
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );     
$response=curl_exec($ch);

//echo $response;
   
   //======================end_send_whats===================================

*/

 
 
 //==================العملايات==================================

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$add_user_id;
 $system_type='hr_marsa_system';
  $proccess_type='takeed_hodoor_ensraf';
  $proccess_details_en='Confirmation of attendance and departure from date'.$_POST["date_from"].' to date'.$_POST["date_to"];
$proccess_details_en='تاكيد كشف الحضور والإنصراف من تاريخ'.$_POST["date_from"].'الى تاريخ'.$_POST["date_to"];
 $table_name='hr_takeed_hodor_ensraf_tbl';   
  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')";
// $run2 = $conn->query($sql2) or die("Error in saving image".$conn->error);    
 //==================العملايات==================================
 

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

}
echo "1";

?>



