<?php
include("attendance_func.php");
include(SABLE_INCLUDES_PATH.'googleMaps.php');

$hddnAttendanceId = $_SESSION['caller']['args'][1];
if ($_SESSION['user']['access_level'] < SABLE_ACCESS_MANAGER)
{
	SableGeneralFunctions::divertFromPage();
}
$row = $sableDB->getRow("select * from attendance where attendance_id = ".$hddnAttendanceId);
$selUserCode  = $sableDB->getValue("select concat(user_name, ' ', user_surname) from `user` 
								where user_code = '".$row["user_code"]."'");

$timein = strtotime($row['attendance_in'] ?? 0);
$checkin = date('d F Y [H:i]', $timein);

$timeout = strtotime($row['attendance_out'] ?? 0);
$checkout = date('d F Y [H:i]', $timeout);

$coordsIn = ($row['attendance_in_lat'] ?? '-').' , '.($row['attendance_in_lng'] ?? '-');
$coordsOut = ($row['attendance_out_lat'] ?? '-').' , '.($row['attendance_out_lng'] ?? '-');
?>
<script src="<?php SableGeneralFunctions::printModuleJS('attendance'); ?>"></script>

<!--// Attendance -->
<form id="frmAttendance" name="frmAttendance" autocomplete="on">
	<input type="hidden" value="<?php echo(SableSystem::sableEncode($hddnAttendanceId)); ?>" id="hddnAttendanceId" name="hddnAttendanceId" />
	<div class="forms">
		<div class="container forms-grids">
			<div class="row forms-grid">
				<div class="col-md-12">
					<h3 class="title"><i class="fa fa-eye" aria-hidden="true"></i>&nbsp;View Attendance</h3>
					<p></p>
				</div>
			</div>
			<!--// selUserCode -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="selUserCode" type="text" id="selUserCode"readonly value="<?php echo($selUserCode); ?>" >
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selUserCode">Employee</div>
				</div>
			</div>
			<p></p>
			<!-- selUserCode //-->
			<p></p>
			<!--// edtAttendanceIn -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtAttendanceIn" type="text" id="edtAttendanceIn"readonly value="<?= $checkin ?>" >
					<div class="fieldHint hintUnder" id="hint_edtAttendanceIn">Checked In</div>
				</div>
				<div class="col-md-4">
					<input name="edtAttendanceOut" type="text" id="edtAttendanceOut"readonly value="<?= $checkout ?>" >
					<div class="fieldHint hintUnder" id="hint_edtAttendanceOut">Checked Out</div>
				</div>
			</div>
			<p></p>
			<!-- edtAttendanceIn //-->
			<p></p>
			<!--// edtAttendanceInLat -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtAttendanceInLat" type="text" id="edtAttendanceInLat"  readonly value="<?= $coordsIn ?>" >
					<div class="fieldHint hintUnder" id="hint_edtAttendanceInLat">Checkin Coordinates</div>
					<button type="button" onClick="presentAddress('<?= $row['attendance_in_lat'] ?>', '<?= $row['attendance_in_lng'] ?>', 'edtAttendanceAddress')"><i class="fa fa-street-view"></i>&nbsp;View Map</button>
				</div>
				<div class="col-md-4">
					<input name="edtAttendanceInLng" type="text" id="edtAttendanceInLng"readonly value="<?= $coordsOut ?>" >
					<div class="fieldHint hintUnder" id="hint_edtAttendanceInLng">Checkout Coordinates</div>
					<button type="button" onClick="presentAddress('<?= $row['attendance_out_lat'] ?>', '<?= $row['attendance_out_lng'] ?>', 'edtAttendanceAddress')"><i class="fa fa-street-view"></i>&nbsp;View Map</button>
				</div>
			</div>
			<p></p>
			<p></p>
			<!--// edtAttendanceInIp -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtAttendanceInIp" type="text" id="edtAttendanceInIp"readonly value="<?php echo($row['attendance_in_ip']); ?>" >
					<div class="fieldHint hintUnder" id="hint_edtAttendanceInIp">Checkin IP Address</div>
				</div>
				<div class="col-md-4">
					<input name="edtAttendanceOutIp" type="text" id="edtAttendanceOutIp"readonly value="<?php echo($row['attendance_out_ip']); ?>" >
					<div class="fieldHint hintUnder" id="hint_edtAttendanceOutIp">Checkout IP Address</div>
				</div>
			</div>
			<p></p>
			<!-- edtAttendanceInIp //-->
			<p></p>
			<!--// buttons -->
			<div class="row forms-grid">
				<div class="col-md-2">
					<input type="button" id="btnCancel" value="Back"
					class="submit" onclick="window.location = '<?php SableSystem::printCallPageLink('/attendance/'); ?>'"/>
				</div>
			</div>
			<!-- buttons //-->
			<p></p>
			<!--// address + map -->
			<div class="row forms-grid">
				<div class="col-md-12">
					<h4><span id="edtAttendanceAddress"></span></h4>
				</div>
			</div>
			<!-- address + map //-->			
			<?php include(SABLE_INCLUDES_PATH.'googleMapsDisplay.php'); ?>
		</div>
	</div>
</form>
<!-- Attendance //-->
