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


$lang='ar';
include("../languege_filee_hr.php");

$system_id='2222';
$company_id_sel=$_POST["company_id_sel"];
$hr_question_type=$_POST["hr_question_type"];
$hr_question_stat='waiting_employee_response';
$hodor_ensraf_date = $_POST["hodor_ensraf_date"];
$employee_number_fingerprint = $_POST["employee_number_fingerprint"];

$id = $_POST["id"];
$employ_id = $_POST["employ_id"];

$mosala_type = $_POST["mosala_type"];
$add_user_id = $_POST["add_user_id"];

 if($_POST["mosala_type"][$i]=='hodor'){
  $mosala_title_ar='تسجيل انصراف بدون حضور'; 
  $mosala_title_en='Signing off without attending'; 
}elseif($_POST["mosala_type"][$i]=='ensraf'){
  $mosala_title_ar='تسجيل حضور بدون انصراف'; 
  $mosala_title_en='Attendance recording without leaving';    
}elseif($_POST["mosala_type"][$i]=='ghyab'){
  $mosala_title_ar='مسائلة غياب'; 
  $mosala_title_en='absence question';    
}else{}


$ensraf_time = $_POST["ensraf_time"];
$check = $_POST["check"];
$id_num = $_POST["id_num"];
//--------------------------------------------
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; 
}

$hr_question_id=GetSeriaother(); 

$hodoor_ensraf_id = GetSeriaother();  


for($i=0;$i<count($employ_id);$i++){
    
    
     if($_POST["mosala_type"][$i]=='hodor'){
  $mosala_title_ar='تسجيل انصراف بدون حضور'; 
  $mosala_title_en='Signing off without attending'; 
}elseif($_POST["mosala_type"][$i]=='ensraf'){
  $mosala_title_ar='تسجيل حضور بدون انصراف'; 
  $mosala_title_en='Attendance recording without leaving';    
}elseif($_POST["mosala_type"][$i]=='ghyab'){
  $mosala_title_ar='مسائلة غياب'; 
  $mosala_title_en='absence question';    
}else{}


$hodor_ensraf_date = $_POST["hodor_ensraf_date"][$i];

   
 $sql_w = "INSERT INTO hr_add_hodor_ensraf_tbl(system_id,company_id,employee_number_fingerprint,hodor_ensraf_date,hodor_ensraf_stat,createdDate,createdDate_Time,add_user_id)values('$system_id','$company_id_sel','".$_POST["employee_number_fingerprint"][$i]."','".$_POST["hodor_ensraf_date"][$i]."','exception_ghyab','$createdDate','$createdDate_Time',$add_user_id )";
 $run_w = $conn->query($sql_w) 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.' : وذلك في يوم'.$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 excluded from absence'.$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='966568207453';
$s=$message_text2;
$data["mobile"]="966568884014";
$data["password"]="Compre123";
$data["instanceid"]="20111";
$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='exception_ghyab';
  $proccess_details_en='Excluding the employee from absence employee number'.$_POST["employee_number_fingerprint"][$i];
   $proccess_details='إستثناء الموظف من الغياب رقم الموظف'.$_POST["employee_number_fingerprint"][$i];
 $table_name='hr_add_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";

?>



