<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>
<section class="content-header">
      <h1>
          Daftar Absen
      </h1>
      <ol class="breadcrumb">
          <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
          <li class="active">Daftar Absen</li>
      </ol>
  </section>
<section class="content">
  <div class="row">
      <div class="col-md-12">
          <div class="box box-primary">
              <div class='box-header with-border'>
                <?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');
        				$harike3=substr(hari($dd,$mm,$yy),0,3);
        				?>
        				<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>
              </div>
        <!-- /.box-header -->
              <div class="box-body table-responsive">
                <?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%>SELFIE DATANG</th>
                    <th width=11%>DATANG</th>
                    <th width=11%>SELFIE 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;
                      $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='';
                      if ($hasilcek1 !=0) {

                        $kehadiran='<b>HADIR</b>';
                        $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;
                        }
                        foreach ($cek1->result() as $rscek1) {
                          $jamcek1=$rscek1->jam;
                          $ketcek1=$rscek1->ket;
                        }
                      } else {
                        $cek3=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3");
                        $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>';
                        } else {
                          if ($cekhari==6){
                            $kehadiran='TIDAK ADA JADWAL';
                          } else {
                            $kehadiran='TIDAK HADIR';
                          }
                        }

                      }

                      ?>
                      <tr>
                      <td class="coba"><?php echo $i;?>.</td>
                      <td class="coba"><?php echo $namasiswa;?></td>
                      <td><?php echo $kehadiran;?></td>
                      <td><img src="<?php base_url();?>../upload/selfie/masuk/<?php echo $kodeabsen.$yy.$mm.$dd.".jpg";?>" height="100"></td>
                      <td><?php echo $jamcek1;?></td>
                      <td><img src="<?php base_url();?>../upload/selfie/pulang/<?php echo $kodeabsen.$yy.$mm.$dd.".jpg";?>" height="100"></td>
                      <td><?php echo $jamcek2;?></td>
                      <td><?php echo $ketcek1;?></td>
                      </tr>
                    <?php }?>
                    </table>
                    <?php
                  }
                ?>
              </div><!-- /.box-body -->
          </div><!-- /.box -->
      </div>
  </div>
