<?php

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


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

 	
    $userid = 0;
    $to_dept =$_POST["to_dept"];
    $from_dept =$_POST["from_dept"];
    $purpose =$_POST["purpose"];
    $from_time =$_POST["from_time"];
    $to_time =$_POST["to_time"];
    $leave_credit_balance = 0;
    $leave_balance = 0;
     $status = "pending";


     $SQL = "INSERT INTO obform (`emp_id`, `dept_from`,`dept_to`,`purpose`,`dept_time`,`return_time`,`Status`) VALUES ($userid, '$from_dept','$to_dept','$purpose','$from_time','$to_time','$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);

}


?>