<?php include 'header.php'; ?>

<div class="breadcome-area">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="breadcome-list">
                    <div class="row">
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="breadcome-heading">
                                <h4 style="margin-bottom: 0px">Absensi</h4>
                            </div>
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container-fluid">

				<?php 
						if(isset($_GET['alert'])){
							if($_GET['alert'] == "gagal"){
								?>
								<div class="alert alert-danger">Absen Gagal, Silahkah Coba Lagi</div>
								<?php
							}else {
								?>
								<div class="alert alert-success">Absen Berhasil</div>
								<?php
							}
						}
				?>
				
				<?php
						
						date_default_timezone_set('Asia/Makassar'); // Zona Waktu indonesia
						$tahun = date('Y');
						$bulan = date('m');
						$tgl   = date ('d');
						$jam	= date('H:i:s');
						
						function tglind($x){
										$ref=array('','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
										$aref=array('Minggu','Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu');
										$bongkar=explode("-",$x);
										$angka=intval($bongkar[1]);
										$bulanind=$ref[$angka];
										$hari=date_format(date_create($x),"w");
										return "$aref[$hari], $bongkar[2] $bulanind $bongkar[0]";
									}
						$a = date("$tahun-$bulan-$tgl");
						
						$id = $_SESSION['id'];
						$saya = mysqli_query($koneksi,"select * from petugas where petugas_id='$id'");
						$s = mysqli_fetch_assoc($saya);
						
						?>

    <div class="row">
        <div class="col-lg-6 col-lg-offset-3">
            <div class="panel panel">

                <div class="panel-heading">
					<center>
					<h1 class="panel-title" ><?php  echo tglind($a);?></h1>
					<br>
					<h2 class="panel-title" >Saat ini pukul <?php echo $jam; ?></h2>
					</center>
                </div>
				
				
                <div class="panel-body">
						
						 <?php 
                            $cekabsen = mysqli_query($koneksi,"SELECT * FROM absensi where kd_pegawai ='$id' and tanggal='$a'");
                            $ca = mysqli_fetch_array($cekabsen);
                         ?>
						
						
						<div class="form-group">
							<label>Nama</label>
							<input type="text" class="form-control" readonly value="<?php echo $s['petugas_nama']; ?>" >
						</div>
						<div class="form-group">
							<label>Absen Masuk</label>
							<input type="text" class="form-control" readonly value="<?php if (empty ($ca)){ echo "-"; } else {echo $ca['masuk'];} ?>">
						</div>
						<div class="form-group">
							<label>Absen Pulang</label>
							<input type="text" class="form-control" readonly value="<?php if (empty ($ca)){ echo "-"; } else {echo $ca['pulang'];}?>" >
						</div>
						
						
						<?php
						$akhir_masuk = date('10:00:00');
						if ((empty ($ca)) and ($jam <= $akhir_masuk) ){
						 ?>
								<form method="post" action="absen_input.php" enctype="multipart/form-data" >
									<div class ="form-group">
										<input type="hidden" class="form-control" name="tanggal" readonly value="<?php echo $a ?>" >
									</div>
									<div class="form-group">
										<input type="hidden" class="form-control" name="jam" readonly value="<?php echo $jam ?>" >
									</div>
									<div class="form-group">
										<input type="submit" class="btn btn-primary" value="Absen Masuk"> 
									</div>
								</form>
								
						<?php	
							} else {
								
						?>
								<form method="post" action="absen_update.php" enctype="multipart/form-data" >
									<div class ="form-group">
										<input type="hidden" class="form-control" name="tanggal" readonly value="<?php echo $a ?>" >
									</div>
									<div class="form-group">
										<input type="hidden" class="form-control" name="jam" readonly value="<?php echo $jam ?>" >
									</div>
									<div class="form-group">
										<input type="submit" class="btn btn-primary" value="Absen Pulang">
									</div>
								</form>
							
						<?php
							}
						?>
                        
                </div>
            </div>
        </div>
    </div>


</div>


<?php include 'footer.php'; ?>