<?php

 include 'DBConnection4.php';
  $thisid =  $_GET["id"];


if(isset($_POST['submit']))
{
    

 	
    $userid = 0;
    $purpose =$_POST["purpose"];
    $reason =$_POST["reason"];
    $date_from =$_POST["date_from"];
    $date_to =$_POST["date_to"];
    $duration = 0;
    $leave_credit_balance =0;
    $leave_balance =0;
     $status = "pending";
     echo '<script type="text/javascript">alert("'.$date_from.'");</script>';
    //  $date_from_format = DateTime::createFromFormat('m/d/Y:H:i:s', $date_from);
    //  //DateTime::createFromFormat('m-d-Y', '12-08-2004')->format('Y-m-d');
    //  $date_to_format = date_create_from_format('m/d/Y:H:i:s', $date_to);
    //  $diff=date_diff($date_from_format,$date_to_format);

    // $diff = $diff->format("%a");
    // $diff = (int)$diff;

     $SQL = "INSERT INTO leaveform (`emp_id`, `purpose`,`reason`,`from_date`,`to_date`,`duration`,`leave_credit_balance`,`leave_balance`,`status`) VALUES ($userid, '$purpose','$reason','$date_from','$date_to','$diff','$leave_credit_balance','$leave_credit_balance','$status')";
    
mysqli_query($connection, $SQL);

}


    $connection = mysqli_connect("localhost","webster","webster","orangehrm_mysql");

if ($connection->connect_error)
{
    die("Connection failed: " . $connection->connect_error);
} 

    $sql       = 'select * from hs_hr_employee where emp_number = '.$thisid;

    $results   = mysqli_query($connection, $sql);


    $row_count = mysqli_num_rows($results);
    $id = 0;
    $emp_name = 'sdsaddsad';
    while ($row = mysqli_fetch_array($results)) {
      /*  echo '<tr><td><a href="OBApprove.php?id='.$row['obid'].'">'.$row['emp_number'].'</a></td></tr>';
        echo '<td>'.$row['emp_id'].'</td>';
        echo '<td>'.$row['dept_from'].'</td>';
        echo '<td>'.$row['dept_to'].'</td>';
        echo '<td>'.$row['purpose'].'</td>';
        echo '<td>'.$row['dept_time'].'</td>';
        echo '<td>'.$row['return_time'].'</td>';
        echo '<td>'.$row['status'].'</td>';*/

        $emp_name = $row['emp_lastname']." ".$row['emp_firstname'];
        $emp_id = $row['employee_id'];
        $joined_date = $row['joined_date'];
        $job_title_code = $row['job_title_code'];



    }


    if (($job_title_code == 4) || ($job_title_code == 16)){
      header('location:http://192.168.2.117/Otm2/HrView.php?id='.$emp_id);
    }
     else if (($job_title_code <=3 ) || ($job_title_code <= 64) || ($job_title_code != 4) || ($job_title_code != 16) || ($job_title_code =="NULL")) {
      header('location:http://192.168.2.117/Otm2/UserView.php?id='.$emp_id);

}


?> 