<?php
session_start();
include("dbConfig.php");
if(ISSET($_POST['sav_btn'])){
$holiday_id=$_POST["holiday_id"];
$company_id = $_POST["company_id"];
$system_id=$_POST["system_id"];

$company_id_sel = $_POST["company_id_sel"];
$user_id_top_manager=$_POST["user_id_top_manager"];

$holiday_name_ar=$_POST["holiday_name_ar"];
$holiday_name_en = $_POST["holiday_name_en"];
$holiday_details = $_POST["holiday_details"];
$holiday_start_date	= $_POST["holiday_start_date"];
$holiday_end_date = $_POST["holiday_end_date"];

$add_user_id = $_POST["add_user_id"];

date_default_timezone_set("Asia/Riyadh");
  $created_date = date("Y-m-d");
  $createdDate_time = date("Y-m-d h:i:sa");
  $subscription_end_date = date('Y-m-d', strtotime($created_date . ' +15 day'));
  
  $link_lang = $_POST["link_lang"];
 $messag_add = $_POST["messag_add"];
 

  //$sql1 = "INSERT INTO holidays_tbl(holiday_id,system_id,company_id,user_id_top_manager,holiday_name_ar,holiday_name_en,holiday_details,holiday_start_date,holiday_end_date,CreatedDate,createdDate_time,add_user_id)values('$holiday_id','$system_id','$company_id_sel',$user_id_top_manager,'$holiday_name_ar','$holiday_name_en','$holiday_details','$holiday_start_date','$holiday_end_date','$created_date','$createdDate_time','$add_user_id')";


  $sql1 = "UPDATE holidays_tbl SET company_id='$company_id_sel',holiday_name_ar='$holiday_name_ar',holiday_name_en='$holiday_name_en',holiday_details='$holiday_details',holiday_start_date='$holiday_start_date',holiday_end_date='$holiday_end_date' where holiday_id='$holiday_id' ";


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

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$_SESSION['user_id'];
 $system_type='hr_marsa_system';
  $proccess_type='add_holiday';
  $proccess_details_en='Edit Holiday'.$holiday_id;
   $proccess_details=' تعديل عطله جديده رقم  '.$holiday_id;
 $table_name='dept_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','$holiday_id',NOW(),NOW(),'$createdDate','$browserAgent')";
 //==================العملايات==================================
  
if ($conn->query($sql1) === TRUE  && $conn->query($sql2) === TRUE) {
    //$_SESSION['message'] = "تم إضافة القسم بنجاح";
   
     $_SESSION['message'] =$messag_add;
   
 // header("Refresh:0; url=add_dpet.php?company_id=$company_id");
   
   header("Refresh:0; url=hr_holidayslist.php?$link_lang&company_id=$company_id");


} else {
  echo "Error: " . $sql1 . "<br>" . $conn->error;
}

}

?>

