<!DOCTYPE html>
<?php
$tiga=$this->db->query("SELECT * FROM web_setting WHERE id='1'");
foreach ($tiga->result() as $rt) {
$namsek=$rt->nama;
$logo=$rt->logo;
}
$titleweb="Presensi ".$namsek;
//echo "SELECT * FROM web_setting WHERE id='1'";
?>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
  <meta charset="utf-8">
  <title>Presensi <?php echo $namsek;?></title>

  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <meta content="Metronic Shop UI description" name="description">
  <meta content="Metronic Shop UI keywords" name="keywords">
  <meta content="keenthemes" name="author">

  <meta property="og:site_name" content="Presensi Online">
  <meta property="og:title" content="<?php echo $titleweb;?>">
  <meta property="og:description" content="Software, jaringan, Linux, Windows">
  <meta property="og:type" content="website">
  <meta property="og:image" content="-CUSTOMER VALUE-"><!-- link to image for socio -->
  <meta property="og:url" content="xwaja.my.id">
  <link rel="shortcut icon" href="favicon.ico">

   <!-- Global styles START -->
  <link href="assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <link href="assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <!-- Global styles END -->

  <!-- Page level plugin styles START -->
  <link href="assets/global/plugins/fancybox/source/jquery.fancybox.css" rel="stylesheet">
  <link href="assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
  <!-- Page level plugin styles END -->

  <!-- Theme styles START -->
  <link href="assets/global/css/components.css" rel="stylesheet">
  <link href="assets/global/css/plugins.css" rel="stylesheet">
  <link href="assets/frontend/layout/css/style.css" rel="stylesheet">
  <link href="assets/frontend/layout/css/style-responsive.css" rel="stylesheet">
  <link href="assets/frontend/layout/css/themes/red.css" rel="stylesheet" id="style-color">
  <link href="assets/frontend/layout/css/custom.css" rel="stylesheet">
  <script src="assets/js/fungsi.js" type="text/javascript"></script>
    <link rel="stylesheet" href="<?php echo base_url('assets/js/plugins/datatables/dataTables.bootstrap.css'); ?>">
	<script language="JavaScript" type="text/JavaScript">
	function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
	</script>
  <!-- Theme styles END -->
</head>
<!-- Head END -->

<!-- Body BEGIN -->
<body class="corporate">
    <!-- BEGIN HEADER -->
    <div class="header">
      <div class="container">
        <a class="site-logo" href="index"><img src="<?php echo base_url('assets/back/'.$logo.'');?>" height="38" alt="<?php echo $namsek;?>"><?php echo $namsek;?></a>

        <a href="javascript:void(0);" class="mobi-toggler"><i class="fa fa-bars"></i></a>

        <!-- BEGIN NAVIGATION -->
        <div class="header-navigation pull-right font-transform-inherit">
          <ul>
            <li class="active">
              <a href="index.php">Home </a>

            </li>
            <li><a href="bulanan">Rekap Bulanan</a></li>
            <li><a href="rekapindividu">Rekap Individu</a></li>
            <li><a href="login">Login</a></li>

          </ul>
        </div>
        <!-- END NAVIGATION -->
      </div>
    </div>
    <!-- Header END -->

    <div class="main">
      <div class="container">
        <ul class="breadcrumb">
            <li><a href="index.php">Home</a></li>
            <li class="active">Absensi</li>
        </ul>
        <!-- BEGIN SIDEBAR & CONTENT -->
        <div class="row margin-bottom-20">
          <!-- BEGIN CONTENT -->
          <div class="col-md-12 col-sm-12">
            <div class="content-page">
			  <div class="row">
				<div class="col-md-12 ">
				<?php

				$jenis=$this->input->get('jenis');
				$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');
				if (strlen($dd)==1){
					$dd="0".$dd;
				}
				if (strlen($mm)==1){
					$mm="0".$mm;
				}

				$harike3=substr(hari($dd,$mm,$yy),0,3);
				//$akhir  = strtotime(date('H:i:s'));
				$akhir=strtotime('08:05:06');
				$awal = strtotime('07:30:00');
				$diff  = $akhir - $awal;

				$jam   = floor($diff / (60 * 60));
				$menit = $diff - ( $jam * (60 * 60) );
				$detik = $diff % 60;
				$tammenit=floor( $menit / 60 );
				$telat=($jam>0) ? "$jam jam ":" ";
				$telat.=($menit>0) ? "$tammenit menit ": " ";
				$telat.=($detik>0) ? "$detik detik ": " ";
				//echo $telat;
				//echo 'Waktu tinggal: ' . $jam .  ' jam, ' . floor( $menit / 60 ) . ' menit, ' . $detik . ' detik';
				
				?>
				<center>
				<table><tr><td>TANGGAL</td><td>:</td><td>
					<select  name="mm" onChange="MM_jumpMenu('parent',this,0)">
						<?php if (!$dd=='') { ?>
							<option><?php echo $dd;?></option>
						<?php } else {?>
						<?php }
							for ($i=1;$i<=31;$i++) {
										echo "<option value='?yy=$yy&mm=$mm&dd=$i'>$i</option>";
						   } ?>

					</select>
					<select  name="mm" onChange="MM_jumpMenu('parent',this,0)">
						<?php if (!$mm=='') { ?>
							<option><?php echo bulan($mm);?></option>
						<?php } else {?>
						<?php }
							for ($i=1;$i<=12;$i++) {
										echo "<option value='?yy=$yy&mm=$i&dd=$dd'>".bulan($i)."</option>";
						   } ?>

					</select>
					<select  name="yy" onChange="MM_jumpMenu('parent',this,0)">
						<?php if (!$yy=='') { ?>
							<option><?php echo $yy;?></option>
						<?php }
							for ($i=date("Y");$i>date('Y')-10;$i-=1){
										echo "<option value='?yy=$i&mm=$mm&dd=$dd'>$i</option>";
						   } ?>

					</select>
					</td>
					</tr>
					<tr><td>HARI</td><td>:</td><td><b><?php echo hari($dd,$mm,$yy);?></b></td></tr>
					<tr><td>TAMPILKAN</td><td> :</td><td>
						<select name="jenis" onChange="MM_jumpMenu('parent',this,0)">
						<?php if (!$jenis=='') {
								$jurusan1=$this->db->query("SELECT * FROM web_kelas WHERE kode='".$jenis."' ORDER BY urut ASC");
								foreach ($jurusan1->result() as $row1) {
								$nama1=$row1->nama;
								}
							?>

							<option><?php echo $nama1;?></option>
						<?php } else {?>
						<option selected>ALL</option>
						<?php }
						echo "<option value='?yy=$yy&mm=$mm&dd=$dd&jenis='>ALL</option>";
						$jurusan=$this->db->query("SELECT * FROM web_kelas ORDER BY urut ASC");
										foreach ($jurusan->result() as $row) {
										$kode=$row->kode;
										$nama=$row->nama;
										echo "<option value='?yy=$yy&mm=$mm&dd=$dd&jenis=$kode'>$nama</option>";
						?>
						<?php } ?>

						</select>
						</td></tr>
					</table>
					</center><br>
				  <!-- BEGIN SAMPLE FORM PORTLET-->
				  <div class="portlet box blue">
					<div class="portlet-title">
					  <div class="caption">
						<i class="fa fa-gift"></i> Daftar Absensi
					  </div>

					</div>
					<div class="portlet-body">
						<div class="row">
							<div class="col-md-12 ">
							<?php
								if ($jenis =="ALL") {
									$carikelas="SELECT * FROM web_kelas ORDER BY urut ASC";
								}elseif($jenis ==""){
									$carikelas="SELECT * FROM web_kelas ORDER BY urut ASC";
								} else {
									$carikelas="SELECT * FROM web_kelas WHERE kode='".$jenis."' ORDER BY urut ASC";
								}
								$kelas = $this->db->query($carikelas);
								foreach ($kelas->result() as $rs) {
									$namakelas=$rs->nama;
									$kodekelas=$rs->kode;
									?>
									<h2><?php echo $namakelas;?></h2>
									<table class="table table-bordered table-striped">
									<tr>
									<th width=4%>NO</th>
									<th width=35%>NAMA</th>
									<th width=11%>STATUS</th>
									<th width=11%>FOTO DATANG</th>
									<th width=11%>DATANG</th>
									<th width=11%>FOTO PULANG</th>
									<th width=11%>PULANG</th>
									<th width=35%>KETERANGAN</th>
									</tr>
									<?php
									$i=0;
									$siswa = $this->db->query("SELECT * FROM web_siswa WHERE KD_JENIS_KETENAGAAN='$kodekelas' ORDER BY NM_PEGAWAI asc");
									foreach ($siswa->result() as $rssis) {
										$i++;
										$namasiswa=$rssis->NM_PEGAWAI;
										$kodeabsen=$rssis->absen;
										$jenispegawai=$rssis->jenispegawai;
										$cekhari=$rssis->$harike3;
										//echo 'iki cek '.$cekhari;
										$skrg="$yy-$mm-$dd";
										$cek1=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=1");
										$hasilcek1=$cek1->num_rows();
										$jamcek1='';
										$jamcek2='';
										$ketcek1='';
										$filefotodatang='';
										$filefotopulang='';
										if ($jenispegawai ==0) {
											//cekliburan
											$cekijin=$this->db->query("SELECT * FROM web_ijin WHERE tgl='$skrg' AND absen='$kodeabsen'");
											$hasilijin=$cekijin->num_rows();
											$ceklibur=$this->db->query("SELECT * FROM web_libur WHERE tgl='$skrg'");
											$hasillibur=$ceklibur->num_rows();
											if ($hasillibur ==0) {
											  if ($cekhari==6){
												$kehadiran='LIBUR SEKOLAH';
												$filefotodatang='';
												$filefotopulang='';
											  } elseif ($hasilijin != 0){
												foreach ($cekijin->result() as $rsijin) {
												  $hijin=$rsijin->status;
												  $ketcek1=$rsijin->ket;
												  $cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$hijin."'");
												  foreach ($cekst->result() as $rsst) {
													$kehadiran=$rsst->status;
												  }
												}
											  } else {
												if ($hasilcek1 !=0) {
													$kehadiran='<b>HADIR</b>';
													$filefotodatang='<img src="'.base_url().'upload/selfie/masuk/'.$kodeabsen.$yy.$mm.$dd.'.jpg" height="100">';
														$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=2");
														foreach ($cek2->result() as $rscek2) {
															$jamcek2=$rscek2->jam;
															$filefotopulang='<img src="'.base_url().'upload/selfie/pulang/'.$kodeabsen.$yy.$mm.$dd.'.jpg" height="100">';
														}
														foreach ($cek1->result() as $rscek1) {
															$jamcek1=$rscek1->jam;
															$ketcek1=$rscek1->ket;
														}
													} else {
														$cek7=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=7");
														$hasilcek7=$cek7->num_rows();
														if ($hasilcek7 !=0) {
															foreach ($cek7->result() as $rscek7) {
																$jamcek1=$rscek7->jam;
																$ketcek1=$rscek7->ket;
															}
															$kehadiran='<b>WFH</b>';
															$filefotodatang='<img src="'.base_url().'upload/selfie/wfh/'.$kodeabsen.$yy.$mm.$dd.'.jpg" height="100">';
															//$filefotodatang='';
															$filefotopulang='';
														} else {
														$cek3=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3 AND status <=6");
														$hasilcek3=$cek3->num_rows();
														//echo "SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3"."<br>";
														if ($hasilcek3 !=0) {
															foreach ($cek3->result() as $rscek3) {
															$status3=$rscek3->status;
															$ketcek1=$rscek3->ket;
															}
															$cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$status3."'");
															foreach ($cekst->result() as $rsst) {
																$statusku=$rsst->status;
															}
															$kehadiran='<b>'.strtoupper($statusku).'</b>';
															$filefotodatang='';
															$filefotopulang='';
														} else {
															$kehadiran='TIDAK HADIR';
															$filefotodatang='';
															$filefotopulang='';
														}
														}
													}
											  }
											} else {
												$kehadiran='LIBUR NASIONAL';
												$filefotodatang='';
												$filefotopulang='';
												  foreach ($ceklibur->result() as $rslibur) {
													$ketcek1=$rslibur->ket;
												  }
											}

										} elseif ($jenispegawai='1') {
											$cekijin=$this->db->query("SELECT * FROM web_ijin WHERE tgl='$skrg' AND absen='$kodeabsen'");
											$hasilijin=$cekijin->num_rows();
											if ($hasilijin != 0){
												foreach ($cekijin->result() as $rsijin) {
												  $hijin=$rsijin->status;
												  $ketcek1=$rsijin->ket;
												  $cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$hijin."'");
												  foreach ($cekst->result() as $rsst) {
													$kehadiran=$rsst->status;
												  }
												}
											  }
											elseif ($hasilcek1 !=0) {
												$kehadiran='<b>HADIR</b>';
												$filefotodatang='<img src="'.base_url().'upload/selfie/masuk/'.$kodeabsen.$yy.$mm.$dd.'.jpg" height="100">';
												
												foreach ($cek1->result() as $rscek1) {
													$jamcek1=$rscek1->jam;
													$ketcek1=$rscek1->ket;
												}
											}
											$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=2");
											foreach ($cek2->result() as $rscek2) {
												$jamcek2=$rscek2->jam;
												$filefotopulang='<img src="'.base_url().'upload/selfie/pulang/'.$kodeabsen.$yy.$mm.$dd.'.jpg" height="100">';
											}
											
										}

										?>
										<tr>
										<td class="coba"><?php echo $i;?>.</td>
										<td class="coba"><a href="detail/?<?php echo "dd=$dd&mm=$mm&yy=$yy&absen=$kodeabsen";?>"><?php echo balikin($namasiswa);?></a></td>
										<td><?php echo $kehadiran;?></td>
										<td><?php echo $filefotodatang;?></td>
										<td><?php echo $jamcek1;?></td>
										<td><?php echo $filefotopulang;?></td>
										<td><?php echo $jamcek2;?></td>
										<td><?php echo $ketcek1;?></td>
										</tr>
									<?php }?>
									</table>
									<?php
								}
							?>
							<h2>DATANG PALING AWAL HARI INI</h2>
							<?php
							$cekabsen = $this->db->query("SELECT nip,jam FROM web_absen WHERE tgl='$skrg' AND status='1' ORDER BY jam ASC LIMIT 0,1");
							//echo "SELECT nip,jam FROM web_absen WHERE tgl='$skrg' AND status='1' ORDER BY jam ASC LIMIT 0,1"."<br>";
							foreach ($cekabsen->result() as $rscek) {
								$absensiswa=$rscek->nip;
								$jammasuk=$rscek->jam;
							}
							$aa=$this->db->query("SELECT NM_PEGAWAI as A,ALAMAT,KD_JENIS_KETENAGAAN as B,absen as C,NOMOR_INDUK_BARU as D FROM web_siswa WHERE absen='$absensiswa'");
							//echo "SELECT NM_PEGAWAI as A,ALAMAT,KD_JENIS_KETENAGAAN as B,absen as C,NOMOR_INDUK_BARU as D FROM web_siswa WHERE absen='$absensiswa'";
							foreach ($aa->result() as $rssiswa) {
								$namasiswa=$rssiswa->A;
								$kelassiswa=$rssiswa->B;
							}
							?>

									<table class="table table-striped" border="0">
										<tbody>
										<tr>
											<td width="10%" rowspan="3"><img src="<?php echo base_url().'../upload/selfie/masuk/'.$absensiswa.$yy.$mm.$dd.'.jpg';?>" height="100"></td>
											<td width="20%">Nama</td>
											<td>: <?php echo $namasiswa;?></td>
										</tr>
										<?php
										$carikelas3=$this->db->query("SELECT * FROM web_kelas where kode='".$kelassiswa."'");
											foreach ($carikelas3->result() as $baris3) {
												$namakelas=$baris3->nama;
											}
										?>

										<tr>
											<td>Status</td>
											<td>: <?php echo $namakelas;?></td>
										</tr>
										<tr>
											<td>Waktu</td>
											<td>: <?php echo $jammasuk;?></td>
										</tr>
									</tbody>
									</table>
							<br>
							<h2>DATANG PALING AKHIR HARI INI</h2>
							<?php
							$cekabsen = $this->db->query("SELECT nip,jam FROM web_absen WHERE tgl='$skrg' AND status='1' ORDER BY jam DESC LIMIT 1");
							//echo "SELECT nip,jam FROM web_absen WHERE tgl='$skrg' AND status='1' ORDER BY jam ASC LIMIT 0,1"."<br>";
							foreach ($cekabsen->result() as $rscek) {
								$absensiswa=$rscek->nip;
								$jammasuk=$rscek->jam;
							}
							$aa=$this->db->query("SELECT NM_PEGAWAI as A,ALAMAT,KD_JENIS_KETENAGAAN as B,absen as C,NOMOR_INDUK_BARU as D FROM web_siswa WHERE absen='$absensiswa'");
							//echo "SELECT NM_PEGAWAI as A,ALAMAT,KD_JENIS_KETENAGAAN as B,absen as C,NOMOR_INDUK_BARU as D FROM web_siswa WHERE absen='$absensiswa'";
							foreach ($aa->result() as $rssiswa) {
								$namasiswa=$rssiswa->A;
								$kelassiswa=$rssiswa->B;
							}
							?>

									<table class="table table-striped" border="0">
										<tbody>
										<tr>
											<td width="10%" rowspan="3"><img src="<?php echo base_url().'../upload/selfie/masuk/'.$absensiswa.$yy.$mm.$dd.'.jpg';?>" height="100"></td>
											<td width="20%">Nama</td>
											<td>: <?php echo $namasiswa;?></td>
										</tr>
										<?php
										$carikelas3=$this->db->query("SELECT * FROM web_kelas where kode='".$kelassiswa."'");
											foreach ($carikelas3->result() as $baris3) {
												$namakelas=$baris3->nama;
											}
										?>

										<tr>
											<td>Status</td>
											<td>: <?php echo $namakelas;?></td>
										</tr>
										<tr>
											<td>Waktu</td>
											<td>: <?php echo $jammasuk;?></td>
										</tr>
									</tbody>
									</table>


							</div>
						</div>
					</div>
				  </div>
				  <!-- END SAMPLE FORM PORTLET-->
				</div>
			  </div>
          </div>
          <!-- END CONTENT -->
        </div>
        <!-- END SIDEBAR & CONTENT -->
      </div>
    </div>
    <!-- BEGIN FOOTER -->
    <div class="footer">
      <div class="container">
        <div class="row">
          <!-- BEGIN COPYRIGHT -->
          <div class="col-md-6 col-sm-6 padding-top-10">
             2019 © <?php echo $namsek;?>. ALL Rights Reserved. <a href="#">Privacy Policy</a> | <a href="#">Terms of Service</a>
          </div>
          <!-- END COPYRIGHT -->
          <!-- BEGIN PAYMENTS -->
          <div class="col-md-6 col-sm-6">
            <ul class="social-footer list-unstyled list-inline pull-right">
              <li><a href="#"><i class="fa fa-facebook"></i></a></li>
              <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
              <li><a href="#"><i class="fa fa-dribbble"></i></a></li>
              <li><a href="#"><i class="fa fa-linkedin"></i></a></li>
              <li><a href="#"><i class="fa fa-twitter"></i></a></li>
              <li><a href="#"><i class="fa fa-skype"></i></a></li>
              <li><a href="#"><i class="fa fa-github"></i></a></li>
              <li><a href="#"><i class="fa fa-youtube"></i></a></li>
              <li><a href="#"><i class="fa fa-dropbox"></i></a></li>
            </ul>
          </div>
          <!-- END PAYMENTS -->
        </div>
      </div>
    </div>
    <!-- END FOOTER -->

    <!-- Load javascripts at bottom, this will reduce page load time -->
    <!-- BEGIN CORE PLUGINS (REQUIRED FOR ALL PAGES) -->
    <!--[if lt IE 9]>
    <script src="assets/global/plugins/respond.min.js"></script>
    <![endif]-->
    <script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="assets/frontend/layout/scripts/back-to-top.js" type="text/javascript"></script>
	<script src="assets/frontend/layout/scripts/layout.js" type="text/javascript"></script>
	<script src="<?php echo base_url('assets/js/plugins/datatables/jquery.dataTables.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/datatables/dataTables.bootstrap.min.js'); ?>"></script>
	<script>
		  $(function () {
			$('#example1').DataTable();

		  });
		</script>
    <!-- END CORE PLUGINS -->

    <!-- BEGIN PAGE LEVEL JAVASCRIPTS (REQUIRED ONLY FOR CURRENT PAGE) -->
    <script src="assets/global/plugins/fancybox/source/jquery.fancybox.pack.js" type="text/javascript"></script><!-- pop up -->
    <script src="assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript" ></script>
	 <script type="text/javascript">
        jQuery(document).ready(function() {
            Layout.init();
            Layout.initOWL();
            Layout.initTwitter();
            Layout.initFixHeaderWithPreHeader(); /* Switch On Header Fixing (only if you have pre-header) */
            Layout.initNavScrolling();
        });
    </script>

    <!-- END PAGE LEVEL JAVASCRIPTS -->
</body>
</html>
