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

<?php 
		
									
		If(isset($_POST['tanggal'])){
			
			$date=$_POST['tanggal'];
			$tahun = date("Y", strtotime($date)); //Mengambil tahun dari form
			$bulan = date("m", strtotime($date)); //Mengambil tbulan dari form
			
			$kd_pegawai=$_POST['pegawai'];
			$nama_pegawai = mysqli_query($koneksi,"SELECT * FROM petugas WHERE petugas_id='$kd_pegawai'");
			$np = mysqli_fetch_array($nama_pegawai);
			$nama = $np['petugas_nama'];
			
		} else {
			$tahun = date('Y'); //Mengambil tahun saat ini
			$bulan = date('m'); //Mengambil bulan saat ini
			
			$date='-';
			$kd_pegawai= '0';
			$nama = '-';
		}
	
		$tanggal = cal_days_in_month(CAL_GREGORIAN, $bulan, $tahun);
?>


<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="breadcome-heading">
							
							<form method="POST" class="form-inline">
								  <div class="box-body">
									<th>
									
									<div class="form-group">
									  <label>  Pilih Bulan/Tahun   </label>&emsp;
									  <input type="date" class="form-control" name="tanggal" required="required">
									</div>
									</th>
									&emsp;
									<th>
									<div class="form-group">
									  <label>  Pilih Nama Pegawai </label>&emsp;
									  <select class="form-control" name="pegawai" required="required">
											<option value="">Pilih Pegawai</option>
											<?php 
											$pegawai = mysqli_query($koneksi,"SELECT * FROM petugas");
											while($p = mysqli_fetch_array($pegawai)){
												?>
												<option <?php if(isset($_GET['pegawai'])){if($_GET['pegawai'] == $p['petugas_id']){echo "selected='selected'";}} ?> value="<?php echo $p['petugas_id']; ?>"><?php echo $p['petugas_nama']; ?></option>
												<?php 
											}
											?>
										</select>
									</div>
									</th>
								
									<div class="form-group">&emsp;
									  <input type='submit' name="tampilkan" value="Tampilkan" class='btn btn-success'>
									</div>
								  </div>
							</form>
                          </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

   
       <div class="container-fluid">
              
			  
					<div class="panel">
					
						<h3 class="panel-title">Laporan Harian</h3>
						<br/>
						
						
						
						<form method="POST"  action='absen_detail_laporan.php' target="_blank"  class="form-inline">
								  <div class="box-body">
									<div class="form-group">
									  <label> Periode</label>&emsp;
									  <input type="date" class="form-control" name="periode" value = "<?php echo $date ?>" required="required" readonly >
									</div>
									&emsp;
									<div class="form-group">
									  <input type="hidden" class="form-control" name="kd" value ="<?php echo $kd_pegawai; ?>" required="required" readonly >
									</div>
									&emsp;
									<div class="form-group">
									  <label> Nama </label>&emsp;
									  <input type="text" class="form-control" name="nama" value ="<?php echo $nama; ?>" required="required" readonly >
									</div>
									
									<div class="form-group">&emsp;
									  <input type='submit' name="cetak" value="Cetak" class='btn btn-success'>
									</div>
								  </div>
						</form>
						
						<div class="panel-body">
							 <table class="table table-responsive">
								<thead>
									<tr>
										<th>No</th>
										<th>Tanggal</th>
										<th>Jam Masuk</th>
										<th>Jam Pulang</th>
										<th>Keterangan</th>
									</tr>
								</thead>
								
								<tbody>
								
									<?php 
									
									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-01") ;
									
									for ($i=1; $i < $tanggal+1; $i++) {
										if($i<10){
										$tgl="0".$i;
										}else{
										$tgl=$i;
									}
									
									?>
								
									<tr>
										<th><?php echo $i;?> </th>
										<th><?php echo tglind($a++);?></th>
										<th><?php 
											
											$absen = mysqli_query($koneksi,"SELECT * FROM absensi WHERE kd_pegawai ='$kd_pegawai' and tanggal='$tahun-$bulan-$tgl'");
											$lap_absen = mysqli_num_rows($absen);
											$lap_absen_isi = mysqli_fetch_array ($absen);
												
											if (empty ($lap_absen)) {
													echo '-';
												} else {
													echo $lap_absen_isi['masuk'];
												}
											//}
											?>
										</th>
										<th ><?php 
											$absen = mysqli_query($koneksi,"SELECT * FROM absensi WHERE kd_pegawai ='$kd_pegawai' and tanggal='$tahun-$bulan-$tgl'");
											$lap_absen = mysqli_num_rows($absen);
											$lap_absen_isi = mysqli_fetch_array ($absen);
												
											if (empty ($lap_absen)) {
													echo '-';
												} else {
													echo $lap_absen_isi['pulang'];
												}
										?>
										</th>
										<th>
										
										</th>
									</tr>
									
									<?php }?>
									
								</tbody>
							  </table>
						
							
						</div>

				</div>
                 
          </div>
		
			

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