<?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';

$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($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_question_tbl(hr_question_id,system_id,company_id,employ_id,hodor_ensraf_id,hr_question_type,hr_question_stat,hr_question_details_ar,hr_question_details_en,hr_question_date,add_user_id,createdDate_time)values('$hr_question_id','$system_id','$company_id_sel','".$_POST["employ_id"][$i]."','".$_POST["id"][$i]."','".$_POST["hr_question_type"][$i]."',$hr_question_stat,'$mosala_title_ar','$mosala_title_en','".$_POST["hodor_ensraf_date"][$i]."'$add_user_id','$createdDate_time')";
 //$run_w = $conn->query($sql_w) or die("Error in saving ".$conn->error);
  
   
   
 $sql_w = "INSERT INTO hr_question_tbl(hr_question_id,system_id,company_id,employ_id,hodor_ensraf_id,hr_question_type,hr_question_stat,hr_question_details_ar,hr_question_details_en,hr_question_date,createdDate_time,add_user_id)values('$hr_question_id','$system_id','$company_id_sel','".$_POST["employ_id"][$i]."','".$_POST["id"][$i]."','".$_POST["mosala_type"][$i]."','$hr_question_stat','$mosala_title_ar','$mosala_title_en','".$_POST["hodor_ensraf_date"][$i]."','$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/employ_dept/hr_question_employ.php?lang=ar&company_id=all_company&employ_id=281198';

$url_m_en='https://www.marsalogistics.com/new/hr_marsa_system/ar/employ_dept/hr_question_employ.php?lang=en&company_id=all_company&employ_id=281198';

//$url_m_arr = Replace($url_m_ar, "amp;amp;", "&");
 // $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_arr.$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;


 //$lang='en';

$message_text_en='Hello'.$br.' Dear Employee / '.$br.$employ_name_en.$br.'You have an issue with the title of the issue/ '.$br.$mosala_title_en.$br.'In a day :'.$br.$newDate.$br.'The Date : '.$br.$hodor_ensraf_date.$br.$br.'Details / '.$br.$m_details_en.$br.'Justification 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;



   //=====================================
   $msg= <<<EOF
   <html>
   <body>
   <table>
     <tr>
      <td><img src="http://d32vlg867bsa1v.cloudfront.net/z/prod/w/2/i/zovi-logo2.png"  />
      </td>
     </tr>
    </table>
    </body>
    </html>
EOF;
   //==================================

// $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"];
$message_customerdetails='تم إرسال رسالة واتس للعميل وفي إنتظار الرد';
 
 
            
                            
//for($i=0;$i<count($id);$i++){

$m='966568207453';
$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===================================

 

  
     //======================send_email===================================

  
   $to      = $mobile_no_email;
    $subject = 'إستعادة الباسورد';
    $message = $message_text22;
    $headers = 'From: mohran@marsaintls.com'       . "\r\n" .
                 'Reply-To: mohran@marsaintls.com' . "\r\n" .
                 'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
     
 
 
        

//======================end_send_whats===================================
 
 /*
 if($_POST["check"][$i]=='1'){ 
     
  $sql1 = "UPDATE  hodoor_ensraf_tbl SET employ_id='".$_POST["id"][$i]."',id_num='".$_POST["id_num"][$i]."',hodoor_ensraf_date='$att_abs_date',hodoor_ensraf_type='$att_or_abs_or_late',hodoor_time='".$_POST["hodoor_time"][$i]."',ensraf_time='".$_POST["ensraf_time"][$i]."',updatedDate_time='$createdDate_Time',update_user_id='$user_id' where employ_id='".$_POST["id"][$i]."' AND hodoor_ensraf_date='$att_abs_date'  " ;                      

 }else{
$sql1 = "INSERT INTO hodoor_ensraf_tbl(employ_id,id_num,hodoor_ensraf_date,hodoor_ensraf_type,hodoor_time,ensraf_time,createdDate_time,user_id)
VALUES ('".$_POST["id"][$i]."','".$_POST["id_num"][$i]."','$att_abs_date','$att_or_abs_or_late','".$_POST["hodoor_time"][$i]."','".$_POST["ensraf_time"][$i]."','$createdDate_Time','$user_id')";
 }
 
 */
 
 
 //==================العملايات==================================

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$add_user_id;
 $system_type='hr_marsa_system';
  $proccess_type='add_mosala';
  $proccess_details_en='Send questions to the staff issue number'.$_POST["id"][$i];
   $proccess_details='إرسال مسائله للموظفين رقم المسائله'.$_POST["id"][$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["id"][$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";
$conn->close();
?>



