<!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;
$batas_jam=$rt->batas_jam;
$waktu_masuk=$rt->jam_masuk;
$jam_pulang=$rt->jam_pulang;
$ip = $_SERVER['REMOTE_ADDR']; // menangkap ip pengunjung
$location = $_SERVER['PHP_SELF']; // menangkap server path
}
?>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
  <meta charset="utf-8">
  <title>Absensi <?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="-CUSTOMER VALUE-">
  <meta property="og:title" content="-CUSTOMER VALUE-">
  <meta property="og:description" content="-CUSTOMER VALUE-">
  <meta property="og:type" content="website">
  <meta property="og:image" content="-CUSTOMER VALUE-"><!-- link to image for socio -->
  <meta property="og:url" content="-CUSTOMER VALUE-">

  <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>
	<script type="text/javascript">        
    function tampilkanwaktu(){         //fungsi ini akan dipanggil di bodyOnLoad dieksekusi tiap 1000ms = 1detik    
    var waktu = new Date();            //membuat object date berdasarkan waktu saat 
    var sh = waktu.getHours() + "";    //memunculkan nilai jam, //tambahan script + "" supaya variable sh bertipe string sehingga bisa dihitung panjangnya : sh.length    //ambil nilai menit
    var sm = waktu.getMinutes() + "";  //memunculkan nilai detik    
    var ss = waktu.getSeconds() + "";  //memunculkan jam:menit:detik dengan menambahkan angka 0 jika angkanya cuma satu digit (0-9)
    document.getElementById("clock").innerHTML = (sh.length==1?"0"+sh:sh) + ":" + (sm.length==1?"0"+sm:sm) + ":" + (ss.length==1?"0"+ss:ss);
    }
</script>
  <!-- Theme styles END -->
</head>
<!-- Head END -->

<!-- Body BEGIN -->
<body onload="tampilkanwaktu();setInterval('tampilkanwaktu()', 1000);" class="corporate">
    <!-- BEGIN HEADER -->
   

    <div class="main">
      <div class="container">
      
        <!-- 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
				$hariini = date("Y-m-d");
				$tgl = date("Y-m-d");
				$jam = date("H:i:s");
				$jamini = date("H:i:s");
				$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);
				?>
				
				  <!-- BEGIN SAMPLE FORM PORTLET-->
				  <div class="portlet box blue">
					<div class="portlet-title">
					  <div class="caption">
						<i class="fa fa-gift"></i> Absensi
					  </div>
					</div>
					<div class="portlet-body">
						<div class="row">
							<div class="col-md-12 ">
									<span id="clock"></span> 

									<?php
									$hari = date('l');
									/*$new = date('l, F d, Y', strtotime($Today));*/
									if ($hari=="Sunday") {
									 echo "Minggu";
									}elseif ($hari=="Monday") {
									 echo "Senin";
									}elseif ($hari=="Tuesday") {
									 echo "Selasa";
									}elseif ($hari=="Wednesday") {
									 echo "Rabu";
									}elseif ($hari=="Thursday") {
									 echo("Kamis");
									}elseif ($hari=="Friday") {
									 echo "Jum'at";
									}elseif ($hari=="Saturday") {
									 echo "Sabtu";
									}
									?>,

									<?php
									$tgl =date('d');
									echo $tgl;
									$bulan =date('F');
									if ($bulan=="January") {
									 echo " Januari ";
									}elseif ($bulan=="February") {
									 echo " Februari ";
									}elseif ($bulan=="March") {
									 echo " Maret ";
									}elseif ($bulan=="April") {
									 echo " April ";
									}elseif ($bulan=="May") {
									 echo " Mei ";
									}elseif ($bulan=="June") {
									 echo " Juni ";
									}elseif ($bulan=="July") {
									 echo " Juli ";
									}elseif ($bulan=="August") {
									 echo " Agustus ";
									}elseif ($bulan=="September") {
									 echo " September ";
									}elseif ($bulan=="October") {
									 echo " Oktober ";
									}elseif ($bulan=="November") {
									 echo " November ";
									}elseif ($bulan=="December") {
									 echo " Desember ";
									}
									$tahun=date('Y');
									echo $tahun;
									?>
									<form id="pengumuman" name="pengumuman" method="post" action="">
									<input class="form-control input-lg" placeholder="BARCODE KARTU" name="nisn" type="text" id="nisn" autofocus> <br>
									<input class="btn btn-primary btn-lg" type="submit" name="go" id="go" value="CEK KARTU" />
									<input class="btn btn-primary btn-lg" type="submit" name="cekjam" id="cekjam" value="CEK JAM" />
									</form>
									<?php
									if(isset($_POST['cekjam']))
								{
									$result=$this->db->query("SELECT * FROM web_siswa WHERE absen='$_POST[nisn]'");
									foreach ($result->result() as $rsj) {
									$nipq=$rsj->absen;
									$namasiswa=$rsj->NM_PEGAWAI;
									$nomoerinduk=$rsj->NOMOR_INDUK;
									$nomerhp=$rsj->NO_HP;
									$cekhari=$rsj->$harike3;
									$absenku=$rsj->NOMOR_INDUK_BARU;
									}
									$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;
									}
									$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];
									echo "iki masuk_jam ".$masuk_jam."<br>";
									echo "iki jamini ".$jamini."<br>";
									//echo "iki dj ".$dj."<br>";
									if ($masuk_jam < $jamini) {
										echo "Terlambat<br>";
									} else {
										echo "OK deh<br>";
									}
									if ($dj>=0) {
										$telat=($dj>0) ? "$dj jam ":" ";
										$telat.=($dm>0) ? "$dm menit ": " ";
										$telat.=($ds>0) ? "$ds detik ": " ";
										echo $telat;
									} else {
										$tepat_waktu="selamat pagi, anda datang tepat waktu";
										echo $tepat_waktu;
									}
								}
									if(isset($_POST['go']))
								{
									$result=$this->db->query("SELECT * FROM web_siswa WHERE absen='$_POST[nisn]'");
									foreach ($result->result() as $rsj) {
									$nipq=$rsj->absen;
									$namasiswa=$rsj->NM_PEGAWAI;
									$nomoerinduk=$rsj->NOMOR_INDUK;
									$nomerhp=$rsj->NO_HP;
									}
										$kett='';
										if (!empty($namasiswa)) {
											$pesane=$namasiswa." Telah absen tanggal ".$hariini." pukul ".$jamini." ";
											//kirimtelegram2($nomerhp,$pesane);
											?>
											<table class="table">
											<tr>
												<td>
												<h2>NAMA : <?php echo balikin($namasiswa)?></h2>
												
												<h2>Terima Kasih</h2>
												</td>
												<td>
												</td>
												<td align="center">
												<!--<img src="<?php echo $filepoto;?>" height="300" width="250">-->
												</td>
											</tr>
											</table>
											<?php
											$cek1=$this->db->query("SELECT nip FROM web_absen WHERE tgl='$hariini' AND nip='$nipq' AND status='1'");
											$hasilcek1=$cek1->num_rows();
											$telat="";
											$tepat_waktu="";
											if ($hasilcek1 ==0) {
												if ($jam <= $batas_jam) {
													$st=1;
													$awal=explode(':',$waktu_masuk);
													$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 !='') { $keterangan="Anda terlambat $telat"; $kett="terlambat $telat";}
													if ($tepat_waktu) { $keterangan=$tepat_waktu; $kett="tepat waktu";}
													$this->db->query("INSERT INTO web_absen(tgl,jam,nip,status,komp,ket) VALUES('$hariini','$jam','$nipq','$st','$ip','$kett')");
												}
											}
											$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$tgl' AND nip='$nipq' AND status=2");
											$hasilcek2=$cek2->num_rows();
											if ($hasilcek2 ==0) {
												if ($jam >= $jam_pulang) {
													$st=2;
													$this->db->query("INSERT INTO web_absen(tgl,jam,nip,status,komp,ket) VALUES('$hariini','$jamini','$nipq','$st','$ip','')");
												}
											}
										} else {
											echo "<h2>SISWA TIDAK TERDAFTAR 1</h2>";
										}
									}
									?>
							</div>
						</div>
					</div>
				  </div>
				  <!-- END SAMPLE FORM PORTLET-->
				</div>
			  </div>
          </div>
          <!-- END CONTENT -->
        </div>
        <!-- END SIDEBAR & CONTENT -->
      </div>
    </div>
    <!-- BEGIN FOOTER -->
   
    <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="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>