<?php
	// Retrieving values from textboxes
	$staff_id = $_GET['staff_id'];
  $recall_date = $_GET['date'];

	include './conn.php';
	
	// Sql query
$sql1 = "SELECT * FROM staff WHERE staff_id = '".$staff_id."'";
// SQL query to select leave requests for the staff member with a leave status of "Approved"
$sql3 = "SELECT * FROM leave_requests WHERE staff_id = '".$staff_id."' AND (leave_status = 'Approved' OR leave_status = 'Recalled') AND '".$recall_date."' BETWEEN start_date AND end_date";

		
	// Firing query
	$result1 = mysqli_query($conn, $sql1);
  $result3 = mysqli_query($conn, $sql3);

	// Printing nuber of rows affected
	if(mysqli_num_rows($result1) == 0)
	{
		echo 	"<script>
				alert(\"Staff ID ".$staff_id." does not exist !\");
				window.location=\"search_staff_for_recall.php\";</script>";
	}

	while($row1 = mysqli_fetch_array($result1))
	{
		$first_name = $row1['first_name'];
		$middle_name = $row1['middle_name'];
		$last_name = $row1['last_name'];
		$branch = $row1['branch'];

	}

    if(mysqli_num_rows($result3) == 0)
	{
		echo 	"<script>
				alert(\"Staff ID ".$staff_id." had no approved leave on the selected date!\");
				window.location=\"search_staff_for_recall.php\";</script>";
	}
	while($row3 = mysqli_fetch_array($result3))
	{
    $staff_id = $row3['staff_id'];
    $leave_type = $row3['leave_type'];
    $start_date = $row3['start_date'];
    $end_date = $row3['end_date'];
    $no_of_days = $row3['days_requested'];
    $date_applied = $row3['date_applied'];
    $status = $row3['leave_status'];
    $reason = $row3['reason'];
		$status =  $row3['leave_status'];
    $recall_date = $_GET['date'];

	}
   
	mysqli_close($conn);
	
?>
<?php
	session_start();
	if($_SESSION['sid'] == session_id() && $_SESSION['user'] == "admin")
	{
		?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Staff details to recall</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-image: url(../images/bg.gif);
}
</style>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
  <div id="header">
  <div id="title">Lorenzo Group Leave Management</div>
    <div id="quick_links">
   	  <ul>
        	<li><a class="home" href="index.php">Home</a></li>
            <li>|</li>
          
        <li><a class="logout" href="../logout.php">Logout</a></li>
         <li>|</li>
        <li><a class="greeting" href="#">Hi <?php echo $_SESSION['user']; ?></a></li>
      </ul>
    </div>
  </div>

  <div id="side_bar">
  <ul>
  <li class="menu_head">Menu</li>
        <li><a href="staff.php">Staff</a></li>
        <li><a href="add_staff.php">Add Staff</a></li>
        <li><a href="search_staff_for_updation.php">Update Staff</a></li>
        <li><a href="search_staff_for_deletion.php">Delete Staff</a></li>
    	<li><a href="add_leave.php">Add Leave</a></li>
        <li><a href="delete_leave_type.php">Delete Leave</a></li>
        <li><a href="approved_pending_leaves.php">Processed Leaves</a></li>
        <li><a href="search_staff_for_recall.php">Recall a Leave</a></li>
        <li><a href="search_staff_to_assign_pc.php">Program Coordinator</a></li>
    </ul>
  </div>

  <div id="content_panel">
    <div id="heading">Leave Details<hr size="2" color="#FFFFFF" ice:repeating=""/></div>
    <?PHP

	?>

    <div id="form">
    <form method="post" action="approve_recall_db.php">
    <fieldset>
    <legend>General Information</legend>
    <label for="staff_id"><span>Staff ID </span>
    	<input type="text" name="staff_id" id="staff_id" readonly="true" value="<?php echo $staff_id ?>" style="background-color:#F6F6F6; color:#069" />
    </label>
    <label for="staff_name"><span>Staff Name </span>
    	<input type="text" readonly="true" value="<?php echo $first_name." ".$middle_name." ".$last_name ?>" style="background-color:#F6F6F6; color:#069" />
    </label>
    </fieldset>
    <br />
    <fieldset>
    <legend>Leave Information</legend>
       
    <label for="leave_type"><span>Leave Type </span>
    	<input type="text" name="leave_type" id="leave_type" readonly="true" value="<?php echo $leave_type ?>" style="background-color:#F6F6F6; color:#069" />
    </label>
    <label for="date_applied"><span>Leave Applied on </span>
    	<input type="text" name="date_applied_on" id="date_applied_on" readonly="true" value="<?php echo $date_applied ?>" style="background-color:#F6F6F6; color:#069" />
    </label>
    <label for="leave_date"><span>Leave Date </span>
    	<input type="text" name="start_date" id="start_date" readonly="true" value="<?php echo $start_date ?>" style="background-color:#F6F6F6; color:#069" /> &ndash; <input type="text" name="end_date" id="end_date" readonly="true" value="<?php echo $end_date ?>" style="background-color:#F6F6F6; color:#069" /><input type="text" name="no_of_days" id="no_of_days" readonly="true" value="<?PHP echo $no_of_days ?> Day(s)" style="background-color:#F6F6F6; color:#069; width:80px; margin-left:10px;" />
    </label>
    <label for="date_applied"><span>Reason </span>
    <input type="text" name="Reason" id="date_applied_on" readonly="true" value="<?php echo $reason ?>" style="background-color:#F6F6F6; width: 700px; height: 100px; color:#069; overflow: auto;" />
    </label>
    </fieldset>
    
    <br />
    
    <fieldset>
    <legend>Approve/Recall Leave</legend>
    <label for="current_leave_status"><span>Current Status </span>
    	<input type="text" readonly="true" value="<?php echo $status ?>" style="background-color:#F6F6F6; color:#069"/>
    </label>
    <label for="approve_recall"><span>Approve / Recall </span>
    	<select name="approve_recall" id="approve_recall">
            <option value="Approved">Approve</option>
            <option value="Recalled">Recall</option>
        </select>
    </label>
    <label>
    	<input type="submit" value="Submit" />
  	 </label>
    </fieldset>
    </form>
    </div>
  </div>
  
  <div id="footer">
  <p><br />&copy; Lorenzo Group <br><br>All Rights Reserved.</p>
  </div>
</div>
</body>
</html>
<?php
	}
	else
	{
		header("Location: ../index.html");
	}
?>
