<?php
include('class/mysql_crud.php');
$db_finger=new Database();
$db_finger->connect();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="">
<input type="hidden" name="proses" />
<select name="ptk">
<?php
$db_finger->select('ptk','*','','','pin asc','');
$data_ptk = $db_finger->getResult();
$no=1;
foreach($data_ptk as $d_data_ptk){
?>
<option value="<?php echo $d_data_ptk['pin']?>"><?php echo $d_data_ptk['nama']?></option>
<?php
}
?>
</select>

Bulan : 
<select name="bulan">
<?php
$bln_tampil=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Obtober","November","Desember");
$bln_angka=array("01","02","03","04","05","06","07","08","09","10","11","12");
for($i=0;$i<=11;$i++){
echo"<option value='$bln_angka[$i]'>$bln_tampil[$i]</option>";	
}
?>
</select> <input type="text" name="tahun" />
<input type="submit" value="PROSES" />
</form>


<?php
if(isset($_POST['proses'])){
$blnsekarang="$_POST[tahun]-$_POST[bulan]";
$jml_hari=@cal_days_in_month(CAL_GREGORIAN, $_POST['bulan'], $_POST['tahun']);
$db_finger->select('libur','*','','left(tanggal_awal,7)="'.$blnsekarang.'"','','');
$cek_libur = $db_finger->numRows();
$data_libur = $db_finger->getResult();
$indexlibur=$cek_libur-1;	
$db_finger->select('ptk','*','','pin="'.$_POST['ptk'].'"','pin asc','');
$data_ptk = $db_finger->getResult();
$pin=$data_ptk[0]['pin'];
$cd=0;
?>	
<form method="post" action="proses_input.php">
<input type="hidden" name="pin" value="<?php echo $pin;?>">	
<input type="hidden" name="bulan" value="<?php echo $_POST['bulan'];?>">	
<input type="hidden" name="tahun" value="<?php echo $_POST['tahun'];?>">	
	<br><br>
<table>
<tr><td width=100>ID</td><td><?php echo $pin;?></td></tr>
<tr><td>Nama</td><td><?php echo $data_ptk[0]['nama'];?></td></tr>
<tr><td>Bulan</td><td>
<?php
$bulan=$_POST['bulan'];
if($bulan=="01"){
	$tampil_bulan="Januari";
}elseif($bulan=="02"){
	$tampil_bulan="Februari";
}elseif($bulan=="03"){
	$tampil_bulan="Maret";
}elseif($bulan=="04"){
	$tampil_bulan="April";
}elseif($bulan=="05"){
	$tampil_bulan="Mei";
}elseif($bulan=="06"){
	$tampil_bulan="Juni";
}elseif($bulan=="07"){
	$tampil_bulan="Juli";
}elseif($bulan=="08"){
	$tampil_bulan="Agustus";
}elseif($bulan=="09"){
	$tampil_bulan="September";
}elseif($bulan=="10"){
	$tampil_bulan="Oktober";
}elseif($bulan=="11"){
	$tampil_bulan="November";
}elseif($bulan=="12"){
	$tampil_bulan="Desember";
}else{
	$tampil_bulan=" ";
}

echo $tampil_bulan." ".$_POST['tahun'];

?>
</td></tr>
</table>	
Random Menit Masuk :<input type="text" name="minmasuk" size=2>	<input type="text" name="maxmasuk" size=2><br>
Random Menit Keluar :<input type="text" name="minkeluar" size=2>	<input type="text" name="maxkeluar" size=2><br>


<table border="1">
<tr><td>TANGGAL</td><td>Scan Masuk</td><td>Scan Keluar</td></tr>
<?php
for($x=1;$x<=@$jml_hari;$x++){
if($x<10){
$tanggal="0".$x;
}else{
$tanggal=$x;	
}	
$d = date("l", mktime(0, 0, 0, $_POST['bulan'], $tanggal, $_POST['tahun']));
$tgl="$_POST[tahun]-$_POST[bulan]-$tanggal";





?>
<tr <?php if($d=="Sunday"){echo"bgcolor=red";}elseif($cek_libur>0 and($tgl>=$data_libur[$cd]['tanggal_awal'] and $tgl<=$data_libur[$cd]['tanggal_akhir'])){echo"bgcolor=red";}elseif($d=="Friday"){echo"bgcolor=yellow";}?>><td>

<?php echo $tanggal;?></td><td>

<?php
$cektanggal="$_POST[tahun]-$_POST[bulan]-$tanggal";
$db_finger->select('absensi_log','*',NULL,'pin="'.$pin.'"'.'and left(scan_date,10)="'.$cektanggal.'"','scan_date asc','0,1');
$data_log=$db_finger->getResult();
$res = $db_finger->getResult(); 

if(@$data_log[0]['scan_date']==0){
$log="06";
$efektif[$tanggal]=1;	
$tidak[$tanggal]=1;
$scan[$tanggal]=0;
}else{
$efektif[$tanggal]=1;
$scan[$tanggal]=1;
$tidak[$tanggal]=0;
$log=substr(@$data_log[0]['scan_date'],11,5);
}
?>

<?php if($d=="Sunday"){echo"&nbsp; ";}elseif($cek_libur>0 and($tgl>=$data_libur[$cd]['tanggal_awal'] and $tgl<=$data_libur[$cd]['tanggal_akhir'])){echo"&nbsp;";}else{?>



<input type="text" size="3" name="in[]" value="<?php echo $log; ?>"> <input type="hidden" size="3" name="tgl[]" value="<?php echo $tanggal; ?>">
<?php } ?>
</td><td>



<?php
//$cektanggal="$_POST[tahun]-$_POST[bulan]-$tanggal";


$db_finger->select('absensi_log','*',NULL,'pin="'.$pin.'"'.'and left(scan_date,10)="'.$cektanggal.'"','scan_date desc','');
$data_log=$db_finger->getResult();
$jm_log=$db_finger->numRows();
$res = $db_finger->getResult(); 
$log="";



if(@$data_log[0]['scan_date']==0 or $jm_log<=1){
if($pin==80 or $pin==84 or $pin==91){
$log_out="17";	
}else{
$log_out="14";
}
$efektif[$tanggal]=1;	
$tidak[$tanggal]=1;
$scan[$tanggal]=0;
}else{
$efektif[$tanggal]=1;
$scan[$tanggal]=1;
$tidak[$tanggal]=0;
$log_out=substr($data_log[0]['scan_date'],11,5);
}	

?>

<?php if($d=="Sunday"){echo"&nbsp; ";}if($d=="Sunday"){echo"&nbsp; ";}elseif($cek_libur>0 and($tgl>=$data_libur[$cd]['tanggal_awal'] and $tgl<=$data_libur[$cd]['tanggal_akhir'])){echo"&nbsp;";}else{?>



<input type="text" size="3" name="out[]" value="<?php echo $log_out; ?>">
<?php } ?>






</td></tr>


<?php	
 if($cd<$indexlibur){$cd++;}
}
?>

</table>

<input type="submit" value="PROSES">
</form>
<?php	
}
?>
</body>
</html>
