
<SCRIPT type='text/javascript' language="JavaScript" src='js/jquery-ui-timepicker-addon.js'></SCRIPT>
<link rel="stylesheet" type="text/css" href='js/jquery-ui-timepicker-addon.css'/>
        
<script>
	$(function() {
		var startDateTextBox  = $('.wkt1');
		var endDateTextBox = $('.wkt2');

		$.timepicker.datetimeRange(
			startDateTextBox,
			endDateTextBox,
			{
				minInterval: (1000*60*60), // 1hr
				dateFormat: 'yy-mm-dd', 
				timeFormat: 'HH:mm:ss',
				start: {}, // start picker options
				end: {} // end picker options					
			}
		);
	});
</script>
<?php    
$PID = "card_log";
$SC = $_SERVER["SCRIPT_NAME"];

require_once("lib/dbconn.php");
require_once("lib/form.php");
require_once("lib/functions.php");


if (!isset($GLOBALS['print'])) {
	title_print("Key Card Log Report");
	$tgl = date("d-m-Y");
	$jam = date("H:i:s");
	
?>
<form>
<input type="hidden" name="p" value="<?php echo $PID;?>"/>

<table class="gridtable_form" width="40%">
	<tr>
		<td><b>Date From</b></td>
		<td><input type="text" name="tgl1" class="wkt1" value="<?php echo $_GET["tgl1"]; ?>" ></td>
	</tr>
	<tr>
		<td><b>to</b></td>
		<td><input type="text" name="tgl2" class="wkt2" value="<?php echo $_GET["tgl2"]; ?>" ></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" value="View"/></td>
	</tr>
</table>
</form>
<?php } else { ?>
<table class="gridtable_form" width="50%">
	<tr>
		<td><b>Report Name</b></td>
		<td> : Key Card Log </td>
	</tr>
	<tr>
		<td><b>Date From</b></td>
		<td> : <?php echo $_GET["tgl1"]; ?> <b>to</b> <?php echo $_GET["tgl2"]; ?></td>
	</tr>
	<tr>
		<td><b>Date Print</b></td>
		<td> : <?php echo $tgl; ?> &nbsp; <?php echo $jam; ?></td>
	</tr>
	<tr>
		<td><b>User Print</b></td>
		<td> : <?php echo $_SESSION[nama_usr];?>  </td>
	</tr>
</table>
<?php } ?>
<br/>
<table id='mytable' class="gridtable tableWithFloatingHeader" width="100%" border="1px">
	<tr>
		<td class="gridtable_th" align="center">No</td>
		<td class="gridtable_th" align="center">Room ID</td>
		<td class="gridtable_th" align="center">Guest Name</td>
		<td class="gridtable_th" align="center">Checkin<br>Date</td>
		<td class="gridtable_th" align="center">Checkin<br>Time</td>
		<td class="gridtable_th" align="center">Action</td>
		<td class="gridtable_th" align="center">Booking ID</td>
		<td class="gridtable_th" align="center">Created</td>
	</tr>
	<?php
	$sql = "select * FROM tbl_card_log
			where (CONCAT(created,' ',created) between '".$_GET[tgl1]."' and '".$_GET[tgl2]."' )
			order by created
			 ";
	
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;
	$jml = 0;
while ($row = mysql_fetch_array($r)) {
	$checkin_date =  "";
	$checkout_date =  "";
	$date_checkin=$row['checkin_date'];
	$date_checkout=$row['checkout_date'];;
	if($date_checkin!=""){
		$year_checkin = substr($date_checkin,0,4);
		$month_checkin = substr($date_checkin,4,2);
		$day_checkin = substr($date_checkin,6,2);
		$hour_checkin = substr($date_checkin,8,2);
		$minute_checkin = substr($date_checkin,10,2);
		$checkin_date =$day_checkin."-".$month_checkin."-".$year_checkin." ".$hour_checkin.":".$minute_checkin;
	}
	if($date_checkout!=""){
		$year_checkout = substr($date_checkout,0,4);
		$month_checkout = substr($date_checkout,4,2);
		$day_checkout = substr($date_checkout,6,2);
		$hour_checkout = substr($date_checkout,8,2);
		$minute_checkout = substr($date_checkout,10,2);
		$checkout_date =$day_checkout."-".$month_checkout."-".$year_checkout." ".$hour_checkout.":".$minute_checkout;
	}
		$booking_id = $row['booking_id'];
		if($booking_id!="0"){
			$url ="includes/guestfolio.php?idx=".$booking_id;
			$booking_id = '<a href="'.$url.'" target="_blank">'.$booking_id.'</a>';
		}else{
			$booking_id = 'staff';
		}
		
	?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td" align="center"><?php echo $row['room_number']; ?></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row['nama'])); ?></td>
		<td class="gridtable_td" align="center"><?php echo $checkin_date; ?></td>
		<td class="gridtable_td" align="center"><?php echo $checkout_date; ?></td>
		<td class="gridtable_td"><?php echo $row['action']; ?></td>
		<td class="gridtable_td"><?php echo $booking_id; ?></td>
		<td class="gridtable_td"><?php echo $row['created']; ?></td>
	</tr>
	<?php } ?>
	
</table>