<?php
    include("../include/session.php");
    if(!$session->isAdmin() && !$session->isRadstoneReceptionUser()){
		header("Location: ../HR/employeeMenu.php");
    }
    else {
    	include("../header.php");
//        include("../include/db.php");
        $start = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
        
        $end = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
        $empId = mysql_real_escape_string($_POST['empId']);
        
        
//		$start = mysql_real_escape_string($_POST['startDate']);
//		$end = mysql_real_escape_string($_POST['endDate']);
		$q = "SELECT * FROM loan WHERE date >= '$start' AND date <= '$end' ORDER BY date DESC";
		if($empId != ""){
			$q = "SELECT * FROM loan WHERE date >= '$start' AND date <= '$end' AND empId = '$empId' ORDER BY date DESC";
		}
		$resultLate = execsql($q);
		$num = mysql_num_rows($resultLate);
		$i = 0;
		
    $qry = "SELECT empId, empFName, empLName FROM employees";
	$resultEmp = execsql($qry);
	$numEmp = mysql_num_rows($resultEmp);
	$j = 0;
	$empArray = array();
	while($j < $numEmp){
		$empArray[mysql_result($resultEmp, $j, "empId")] = mysql_result($resultEmp, $j, "empFName") ." ". mysql_result($resultEmp, $j, "empLName");
		$j++;
	}
	
      $qry1 = "SELECT productId, productName FROM products";
	$resultPro = execsql($qry1);
	$numPro = mysql_num_rows($resultPro);
	$j = 0;
	$proArray = array();
	while($j < $numPro){
		$proArray[mysql_result($resultPro, $j, "productId")] = mysql_result($resultPro, $j, "productName");
		$j++;
	}
	$s = date("d-m-Y", strtotime($start));
	$e = date("d-m-Y", strtotime($end));		
?>	
<h3>Showing Loans between <?php echo $s?> and <?php echo $e?></h3>
<input type="button" value="Print" onclick="JavaScript:printPreviewDiv('top-bar');">
<table id="test1" cellpadding="0" cellspacing="0" border="0" class="rowstyle-alt colstyle-alt no-arrow">
    <thead>
      <tr>
        <th class="sortable-text">Employee Name</th>
        <th class="sortable-text">Product</th>
        <th class="sortable-numeric">Quantity</th>
        <th class="sortable-text">Returned</th>
        <th class="sortable-text">Comments</th>
        <th class="sortable-date-ymd">Date</th>
      </tr>
    </thead>
    <tbody>
<?php
    $i = 0;
    while($i < $num){
       $b1 = mysql_result($resultLate, $i, "empId");
       $b2 = mysql_result($resultLate, $i, "productId");
       $b3 = mysql_result($resultLate, $i, "quantity");
       $b4 = mysql_result($resultLate, $i, "returned");
       $b5 = mysql_result($resultLate, $i, "comments");
       $b6 = mysql_result($resultLate, $i, "date");

      // echo "<tr><td class="sortable-numeric">$b1</td><td>$b2</td><td>$permission</td><td>$b4</td><td>$b5</td><td>$b6</td></tr>";
      // $i++;
   // }
?>

        <tr class="alt">
        <td><a href="../HR/searchAndDisplayE.php?id=<?php echo $b1?>"><?php echo $empArray[$b1] ?></a></td>
        <td><a href="../Store/findDisplay.php?productId=<?php echo $b2?>"><?php echo $proArray[$b2]?></a></td>
        <td><?php echo $b3?></td>
        <td><?php echo $b4?></td>
        <td><?php echo $b5?></td>
        <td><?php echo date("d-m-Y", strtotime($b6))?></td>
        </tr> 
<?php
    $i++;
    }
?>
</tbody>
</table>

<?php
	include("../footer.html");
    }
    ?>