<script>
var view = document.getElementById("tampilkan");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        view.innerHTML = "Yah browsernya ngga support Geolocation bro!";
    }
}
 function showPosition(position) {
    view.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
 }
</script>

<?php
$sesiku = $this->session->userdata('sesiku');
$sesinama = $this->session->userdata('sesinama');
$tiga=$this->db->query("SELECT * from web_setting where id='1'");
foreach ($tiga->result() as $rt) {
	$nama_sekolah=$rt->nama;
	$namsek=$rt->nama;
	$logo=$rt->logo;
	$back=$rt->back;
	$tapel=$rt->tapel;
	$kop=$rt->kop;
	$kepsek = balikin($rt->namakepsek);
	$nipkepsek = $rt->nipkepsek;
	$kabupaten = $rt->kabupaten;
	$masuk_jam = $rt->jam_masuk;
	$masuk_batas = $rt->batas_jam;
	$pulang_jam = $rt->jam_pulang;
	$pulang_batas = $rt->batas_jampulang;
	$radius = $rt->radius;
	$latx = $rt->lat_x;
	$laty = $rt->lat_y;
}

$hariini = date("Y-m-d");
$jamini=date("H:i:s");
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'pmasuk'))
	{
		$cek1=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=1");
		$hasilcek1=$cek1->num_rows();
		//echo "ngecek data ".$hasilcek1."<br>";
		if ($hasilcek1 ==0) {
				//echo "cek jam ".$jamini." ".$masuk_batas."<br>";
			if ($jamini <= $masuk_batas) {
				$tepat_waktu='';
				$telat='';
				$st=1;
				$awal=explode(':',$masuk_jam);
				$akhir=explode(':',$jamini);
				$dj=$akhir[0]-$awal[0];
				$dm=$akhir[1]-$awal[1];
				$ds=$akhir[2]-$awal[2];
				if ($dj>=0) {
					$telat=($dj>0) ? "$dj jam ":" ";
					$telat.=($dm>0) ? "$dm menit ": " ";
					$telat.=($ds>0) ? "$ds detik ": " ";
				} else {
					$tepat_waktu="selamat pagi, anda datang tepat waktu";
				}
				if ($telat) {$kett="terlambat $telat";}
				if ($tepat_waktu) {$kett="tepat waktu";}
				$this->db->query("REPLACE INTO web_absen(tgl,jam,nip,status,komp,ket,lat_x,lat_y) VALUES('$hariini','$jamini','$sesiku','$st','127.0.0.1','$kett','$latx','$laty')");
			?>
			<br>
			<br>
			<div class="col-md-4 col-sm-6 col-xs-12">
						<div class="info-box">
							<span class="info-box-icon bg-green"><img src="img/p_masuk.png" height="75" /></span>

							<div class="info-box-content">
								<span class="info-box-text">PRESENSI MASUK</span>
								<span class="info-box-number">
									BERHASIL...
									</span>
							</div>
							<!-- /.info-box-content -->
						</div>
						<!-- /.info-box -->


			<?php
			echo "<p>$hariini</p>";
			?>
				</div>
			<?php
			}
		} else {
			?>

				<div class="col-md-4 col-sm-6 col-xs-12">
						<div class="info-box">
							<span class="info-box-icon bg-green"><img src="img/p_masuk.png" height="75" /></span>

							<div class="info-box-content">
								<span class="info-box-text">HARI INI SUDAH PRESENSI MASUK</span>
								</br>
								<span class="info-box-number">
									TERIMA KASIH
									</span>
							</div>
							<!-- /.info-box-content -->
						</div>
					</div>
					<?php
		}
}
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'ppulang'))
	{
		$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=2");
		$hasilcek2=$cek2->num_rows();
		//echo "ngecek data ".$hasilcek1."<br>";
		if ($hasilcek2 ==0) {
				//echo "cek jam ".$jamini." ".$pulang_batas."<br>";
			if ($jamini <= $pulang_batas) {

				$this->db->query("REPLACE INTO web_absen(tgl,jam,nip,status,komp,ket,lat_x,lat_y) VALUES('$hariini','$jamini','$sesiku','2','127.0.0.1','','$latx','$laty')");
			?>
			<br>
			<br>
			<div class="col-md-4 col-sm-6 col-xs-12">
						<div class="info-box">
							<span class="info-box-icon bg-green"><img src="img/p_masuk.png" height="75" /></span>

							<div class="info-box-content">
								<span class="info-box-text">PRESENSI PULANG</span>
								<span class="info-box-number">
									BERHASIL...
									</span>
							</div>
							<!-- /.info-box-content -->
						</div>
						<!-- /.info-box -->


			<?php
			echo "<p>	$hariini</p>";
			?>
				</div>
			<?php
			}
		} else {
			?>

				<div class="col-md-4 col-sm-6 col-xs-12">
						<div class="info-box">
							<span class="info-box-icon bg-green"><img src="img/p_masuk.png" height="75" /></span>

							<div class="info-box-content">
								<span class="info-box-text">HARI INI SUDAH PRESENSI PULANG</span>
							</br>
								<span class="info-box-number">
									TERIMA KASIH
									</span>
							</div>
							<!-- /.info-box-content -->
						</div>
					</div>
					<?php
		}
}
 ?>
