<?php include("session_controller.php"); ?>

<?php
$colname_records = "-1";
if (isset($_GET['id'])) {
  $colname_records = $_GET['id'];
}
mysqli_select_db($conn, $database_conn);
//$query_records = sprintf("SELECT m.s_no, m.date, m.student_adm_no, m.class, m.nurse, m.complaint, m.treatment, m.duration, m.bill, m.report, s.surname,s.name,s.middle FROM medical_records m JOIN students s ON (m.student_adm_no = s.admission_no) WHERE student_adm_no = %s ORDER BY `date` DESC", GetSQLValueString($colname_records, "text"));
$query_records = sprintf("SELECT m.s_no, m.date, m.student_adm_no, m.class, m.authorizing_officer, m.reason, m.location, m.duration, m.start_date, m.end_date, m.status, s.surname, s.name, s.middle FROM exit_records m JOIN students s ON (s.admission_no = m.student_adm_no) ORDER BY `date` DESC");
$records = mysqli_query($conn, $query_records) or die(mysqli_error($conn));
$row_records = mysqli_fetch_assoc($records);
$totalRows_records = mysqli_num_rows($records);

?>

<html>
<head>
<title> Gate Pass Records </title>
<link href="style.css" rel="stylesheet"  type="text/css"/>
<script>
function check_confirmation(){
var signal = prompt("Type DELETE");
if(signal == "DELETE"){
	return true;		
}
else{
	return false;
}
}

</script>
</head>
<body>

<?php include("links.php");?>

<div class="container">
<div class="row">
<div class="col-sm-12">


<h3> Timestamp:  <?php echo date('D d, M, Y g:i:s',time()); ?> </h3>


<br />
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered"> 
    <thead>
    <tr>
      <th width="31">S/N </th><th width="120">Date </th><th width="100">Name</th><th width="94">Class </th><th width="106">Authorizing Officer </th><th width="125">Reason </th><th width="128">Location </th><th width="50">Duration (days/hours) </th><th width="84">Start date </th><th width="180">End date</th><th> Status </th><th width="79">Actions 1 </th> <th width="79">Actions 2 </th>
    </tr>
   </thead>
   <tbody> 
 
      <?php 
	  $counter = 0;
	  $d=1;
	  do { ?>
       <tr>
 <td height="40"><?php echo ++$counter; ?></td><td> <?php if(isset($row_records['date'])){echo date('d-m-y g:ia',strtotime($row_records['date'])); } ?></td><td><?php echo $row_records['surname']." ". $row_records['name']." " .$row_records['middle']; ?></td><td> <?php echo $row_records['class']; ?></td><td><?php echo $row_records['authorizing_officer']; ?></td>
        <td><?php echo $row_records['reason']; ?> </td><td><?php echo $row_records['location']; ?> </td><td><?php echo $row_records['duration']; ?> </td><td><?php echo $row_records['start_date']; ?> </td><td><?php echo $row_records['end_date']; ?> </td><td><?php echo $row_records['status']; 
		/*
		if(strtotime($row_records['end_date']) < time()){
			echo "EXPIRED";
		}
		else{
			echo "VALID";
		}
		*/
		
		?> </td>
		<td><?php if(isset($row_records['date']) && ($_SESSION['MM_UserGroup'] == "admin")){ ?><a href="edit_record2.php?id=<?php echo $row_records['s_no']; ?>">EDIT</a><?php } ?></td>
		<td><?php if(isset($row_records['date']) && ($_SESSION['MM_UserGroup'] == "admin")){ ?><a href="delete.php?s_no=<?php echo $row_records['s_no']; ?>" onClick="return check_confirmation();">DELETE </a> <?php } ?></td>
       
  </tr>
  <?php } while ($row_records = mysqli_fetch_assoc($records)); ?>
 </tbody>
 </table>
</div>
</div></div></div>

<br />
 </body>


<?php
mysqli_free_result($records);
  
?>