<?php
$filenya_jamku = base_url()."/android/i_jamku";
$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;*/
}
$dd=$this->input->get('dd');
$mm=$this->input->get('mm');
$yy=$this->input->get('yy');
if (!$dd) $dd=date('d');
if (!$mm) $mm=date('m');
if (!$yy) $yy=date('Y');
//nilai session
$sesiku = $this->session->userdata('sesiku');
$sesinama = balikin($this->session->userdata('sesinama'));
$kd6_session = nosql($this->session->userdata('sesiku'));
$kodeabsen = $this->session->userdata('sesiku');
$hasilwfh=0;
?>

	<script>
	$(document).ready(function(){
		setInterval(loadLog, 1000);
		function loadLog(){
			console.log("interval...");
			$("#ijamku").load("<?php echo $filenya_jamku;?>");
		}
		setInterval(loadLog2, 5000);
		function loadLog2()
			{
			console.log("interval2...");
			}
	})
	</script>
	<br>
	  <div class="row">
	  	<div class="col-md-12" align="center">
	  			<img src="<?php echo base_url('assets/back/'.$logo.'');?>" height="100" />
	  	</div>
	  </div>
	  <div class="row">
	  	<div class="col-md-12" align="center">
	  		<h3>
	  			PRESENSI <?php echo $nama_sekolah;?>
	  		</h3>
	  		<div id="ijamku"></div>
	  	</div>
	  </div>
	<hr>
	<?php
	if (!empty($sesiku))
	{
		?>
		<div class="row">
			<div class="col-12" align="center">
			NAMA :<?php echo strtoupper(balikin($sesinama));?></b>
			</div>
		</div>
		<div class="row">
			<?php
			$hariini = date("Y-m-d");
			$kemarin = date('Y-m-d', strtotime("-1 day", strtotime(date("Y-m-d"))));
			$jamini=date("H:i:s");
			$harike3=substr(hari($dd,$mm,$yy),0,3);
			$siswa = $this->db->query("SELECT * FROM web_siswa WHERE absen='$kodeabsen' ORDER BY NM_PEGAWAI asc");
			foreach ($siswa->result() as $rssis) {
				$cekhari=$rssis->$harike3;
				$jenispegawai=$rssis->jenispegawai;
				
			}
			//echo "embuh sopo ki kog entuk no ".$jenispegawai;
			$cekjam=$this->db->query("SELECT * FROM web_jam WHERE kode='$cekhari'");
			foreach ($cekjam->result() as $rsjam) {
				$awal_masuk= $rsjam->awal_masuk;
				$masuk_jam = $rsjam->jam_masuk;
				$masuk_batas = $rsjam->akhir_masuk;
				$pulang_jam = $rsjam->jam_pulang;
				$pulang_batas = $rsjam->akhir_pulang;
			}
			//cekliburan
			$cekijin=$this->db->query("SELECT * FROM web_ijin WHERE tgl='$hariini' AND absen='$kodeabsen'");
			$hasilijin=$cekijin->num_rows();
			$ceklibur=$this->db->query("SELECT * FROM web_libur WHERE tgl='$hariini'");
			$hasillibur=$ceklibur->num_rows();
			//cek jenispegawai
			if (($jenispegawai ==0) or ($jenispegawai ==2) or ($jenispegawai ==3)) {
				if ($hasillibur ==0) {
					if ($cekhari==6){
						$hasilwfh=0;
						echo '<div class="col" align="center">
							<img src="img/p_masuk.png" height="100" /> 
						</div>';
						echo '<div class="col" align="center">
							<img src="img/p_pulang.png" height="100" />
						</div>';
					} elseif ($hasilijin != 0){
						$hasilwfh=0;
						echo '<div class="col" align="center">
							<img src="img/p_masuk.png" height="100" />
						</div>';
						echo '<div class="col" align="center">
							<img src="img/p_pulang.png" height="100" />
						</div>';
					} else {
						$cek3=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status>=3");
						$hasilcek3=$cek3->num_rows();
						if ($hasilcek3==0){
								$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 $hariini." ".$jamini;
								if ($hasilcek1==0){
									if ($jamini >= $awal_masuk && $jamini <= $masuk_batas) {
										//tombol aktif
										$hasilwfh=1;
										echo '<div class="col" align="center">
											<a href="pmasuk.html" class="shortcut success mt-1"><img src="img/p_masuk.png" height="80" /></a><br>Klik presensi masuk
										</div>';
										}
									else
										{
										//tombol pasif
										echo '<div class="col" align="center">
											<img src="img/p_masuk.png" height="100" /><br>Belum Waktunya Presensi
										</div>';
										}

									//tombol pasif
									echo '<div class="col" align="center">
										<img src="img/p_pulang.png" height="100" /><br>Harus presensi masuk dulu
									</div>';
								} else {
									echo '<div class="col" align="center">
										<img src="img/p_masuk.png" height="100" /><br>Sudah melakukan presensi
									</div>';
									$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 $jamini;
									if($hasilcek2==0) {
											if ($jamini >= $pulang_jam && $jamini <= $pulang_batas){
												//aktif
												echo '<div class="col" align="center">
													<a href="ppulang.html" class="shortcut alert mt-1"><img src="img/p_pulang.png" height="80" /></a><br> Klik presensi pulang
												</div>';
											}	else {
												//pasif
												echo '<div class="col" align="center">
													<img src="img/p_pulang.png" height="100" /><br>Belum waktunya Presensi
												</div>';
											}
									} else {
										echo '<div class="col" align="center">
											<img src="img/p_pulang.png" height="100" /><br>Sudah melakukan presensi
										</div>';
									}
								}
						} else {
							echo '<div class="col" align="center">
								<img src="img/p_masuk.png" height="100" />
							</div>';
							echo '<div class="col" align="center">
								<img src="img/p_pulang.png" height="100" />
							</div>';
						}
					}
				} else {
					echo '<div class="col" align="center">
						<img src="img/p_masuk.png" height="100" />
					</div>';
					echo '<div class="col" align="center">
						<img src="img/p_pulang.png" height="100" />
					</div>';
				}
				//akhir cek libur
			} elseif ($jenispegawai ==1) {
				//echo "Pegawai Luar Biasa";
					//echo $jamini.'<br>'.$awal_masuk.' '.$masuk_batas;
					if ($jamini >= $awal_masuk && $jamini <= $masuk_batas) {
						$cek1=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=1");
						$hasilcek1=$cek1->num_rows();
						if ($hasilcek1==0){
							//tombol aktif
							echo '<div class="col" align="center">
								<a href="pmasuk.html" class="shortcut success mt-1"><img src="img/p_masuk.png" height="80" /></a>
							</div>';
							echo '<div class="col" align="center">
								<img src="img/p_pulang.png" height="100" />
							</div>';
						} else {
							echo '<div class="col" align="center">
								<img src="img/p_masuk.png" height="100" />
							</div>';
							echo '<div class="col" align="center">
								<img src="img/p_pulang.png" height="100" />
							</div>';
						}
					} elseif ($jamini >= $pulang_jam && $jamini <= $pulang_batas){
						//aktif
						$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=2");
						$hasilcek2=$cek2->num_rows();
						if($hasilcek2==0) {
							echo '<div class="col" align="center">
								<img src="img/p_masuk.png" height="100" />
							</div>';
							echo '<div class="col" align="center">
								<a href="ppulang.html" class="shortcut alert mt-1"><img src="img/p_pulang.png" height="80" /></a>
							</div>';
						} else {
							echo '<div class="col" align="center">
								<img src="img/p_masuk.png" height="100" />
							</div>';
							echo '<div class="col" align="center">
								<img src="img/p_pulang.png" height="100" />
							</div>';
						}
					} else {
						echo '<div class="col" align="center">
							<img src="img/p_masuk.png" height="100" />
						</div>';
						echo '<div class="col" align="center">
							<img src="img/p_pulang.png" height="100" />
						</div>';
					}
					
				
			}
				?>

			</div>
			<div class='row'>
				<?php
				if ($hasilwfh == 1)
				{
				?>
				<div class="col" align="center">
					<a class="button primary mt-1" href="pwfh.html"><span class="mif-fingerprint"></span> WFH</a>
				</div>
			<?php } else {
					$cek7=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=7");
					$hasilcek7=$cek7->num_rows();
					if ($hasilcek7 == 0) {
					?>
					<div class="col" align="center">
						
					</div>
					
					<?php
					} else {
						?>
						<div class="col" align="center">
							ANDA SUDAH ABSEN WFH
						</div>
						
						<?php
					}
				}
			?>
				<!--<div class="col" align="center">
					<a class="button primary" href="pabsen2.html">Absen Khusus</a>
				</div>-->
			</div>
			<div class="row">
			 <div class="col-1">
			 </div>

				 <div class="col-10" align="center">
					 <hr>
							 <table width="100%" border="0" cellpadding="5" cellspacing="5">
							 <tr align="top">
							 <td valign="top" align="left">
								 <font color="green">PRESENSI MASUK</font>
							 </td>

							 <td valign="top" align="right">

								 <?php
								 //history hadir ...
								 $jammasuk="";
								 $cek1=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=1");
								 foreach ($cek1->result() as $rt1) {
									 $jammasuk=$rt1->jam; 
								 }
								 //jika ada
									 echo "<font color='green'><b>$jammasuk WIB</b></font>";
								 ?>


							 </td>
							 </tr>
							 </table>
					 <hr>

							 <table width="100%" border="0" cellpadding="5" cellspacing="5">
							 <tr align="top">
							 <td valign="top" align="left">
								 <font color="red">PRESENSI PULANG</font>
							 </td>

							 <td valign="top" align="right">
								 <?php
								 $jampulang="";
								 $cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$hariini' AND nip='$sesiku' AND status=2");
								 foreach ($cek2->result() as $rt2) {
									 $jampulang=$rt2->jam;
								 }
									 echo "<font color='red'><b>$jampulang WIB</b></font>";
								 ?>


							 </td>
							 </tr>
							 </table>
					 <hr>
					<a class="button primary" href="utama.html">Beranda</a>
				 </div>


				 <div class="col-1">

				 </div>

			 </div>
			<?php
	}
	?>
