<?php
include('../include/header.php');
date_default_timezone_set("America/Montreal");

/* Set the date */
$date = strtotime(date("Y-m-d"));
$emp_id = md5($row_emp['emp_id']);
if(isset($_REQUEST['month'])){
$mont = $_REQUEST['month'];

$mh =$mont;
}else{
$mh = date('m', $date);
}

if(isset($_REQUEST['yr'])){
$yer = $_REQUEST['yr'];

$yr =$yer;
}else{
$yr = date('Y', $date);
}

$sqlww = "select *from tbl_emp_master where md5(id)='$emp_id'  ";
						$resultww = $objhr->viewdata($sqlww);
				
					$rowsww = $resultww->fetch_assoc();

 $sql_hd = "SELECT * FROM `tbl_holiday_mstr` ";
						$result_hd = $objhr->viewdata($sql_hd);
						while($rows_hd = $result_hd->fetch_assoc()){
						$sql_at3 = "select *from tbl_emp_attendance where md5(emp_id)='$emp_id' and date_ = '".$rows_hd['date1']."' ";
						$result_at3 = $objhr->viewdata($sql_at3);
				if($result_at3->num_rows <= 0){
				$sql3 = "INSERT INTO `tbl_emp_attendance` (`emp_id`, `present_type_id`, `date_`, `status`) VALUES ('".$rowsww['id']."', '2', '".$rows_hd['date1']."', '1');";
	$result3 = $objhr->insertion($sql3);
						}
						}
						
						
						$sql_lv = "SELECT * FROM `tbl_leave_detail` where md5(emp_id) = '$emp_id' ";
						$result_lv = $objhr->viewdata($sql_lv);
						if($result_lv->num_rows > 0){
						while($rows_lv = $result_lv->fetch_assoc()){
						$sql_at4 = "select *from tbl_emp_attendance where md5(emp_id)='$emp_id' and date_ = '".$rows_lv['leave_date']."' ";
						$result_at4 = $objhr->viewdata($sql_at4);
				if($result_at4->num_rows <= 0){
				$sql4 = "INSERT INTO `tbl_emp_attendance` (`emp_id`, `present_type_id`, `date_`, `status`) VALUES ('".$rowsww['id']."', '3', '".$rows_lv['leave_date']."', '1');";
	$result4 = $objhr->insertion($sql4);
						}
						}
						}
						
		
?>

 <!-- Page wrapper  -->
        <div class="page-wrapper">
            <!-- Bread crumb -->
            <div class="row page-titles">
                <div class="col-md-5 align-self-center">
                    <h3 class="text-primary"></h3> </div>
                <div class="col-md-7 align-self-center">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0)">Home</a></li>
                        <li class="breadcrumb-item active">Attendance Sheet </li>
                    </ol>
                </div>
            </div>
            <!-- End Bread crumb -->
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
						
										<?php	
						?>
						
						   <div class="card-body">
						 <table width="100%">
						 <tr>
							 <td align="left"><input type='button' class="btn btn-default " style=" background:#00FFFF;  "  value="Holiday" /> <input type='button' class="btn btn-default " style=" background:#FF9933;  "  value="Sunday" /> <input type='button' class="btn btn-primary "   value="Leave" /></td>
							 </tr></table>
					
							 <?php
/* Set the default timezone */


$day = date('d', $date);
$month = $mh;
//$year = date('Y', $date);
$year = $yr;
$firstDay = mktime(0,0,0,$month, 1, $year);
$title = strftime('%B', $firstDay);
$dayOfWeek = date('D', $firstDay);
$daysInMonth = cal_days_in_month(0, $month, $year);
/* Get the name of the week days */
$timestamp = strtotime('next Sunday');
$weekDays = array();
for ($i = 0; $i < 7; $i++) {
    $weekDays[] = strftime('%a', $timestamp);
    $timestamp = strtotime('+1 day', $timestamp);
}
$blank = date('w', strtotime("{$year}-{$month}-01"));
?>
<table class='table table-bordered' style="table-layout: fixed;">
    <tr>
        <th colspan="7" class="text-center"><input type="hidden" value="<?php echo $rowsww['id'];?>" id="emp_id" /><input type="hidden" value="<?php echo $month;?>" id="month" /><input type="hidden" id="year"  value="<?php echo $year; ?>" /> <?php echo $title ?> <?php echo $year ?> </th>
    </tr>
    <tr>
        <?php foreach($weekDays as $key => $weekDay) : ?>
            <th class="text-center"><?php echo $weekDay;  ?></th>
        <?php endforeach ?>
    </tr>
    <tr>
        <?php for($i = 0; $i < $blank; $i++): ?>
        <th></th>
    <?php endfor; ?>
    <?php for($i = 1; $i <= $daysInMonth; $i++): ?>
        
		 <th align="left"><?php
		
		 $date_cr = $year.'-'.$month.'-'.$i;
		  $t_date =  date('Y-m-d');
		  $t_day = date('D', strtotime($date_cr));
		
		
		
		if((strtotime($date_cr) <= time())and ($t_day =='Sun')){ 
		 $sql_at2 = "select *from tbl_emp_attendance where md5(emp_id)='$emp_id' and date_ = '$date_cr' ";
						$result_at2 = $objhr->viewdata($sql_at2);
				if($result_at2->num_rows < 1){
				$sql3 = "INSERT INTO `tbl_emp_attendance` (`emp_id`, `present_type_id`, `date_`, `status`) VALUES ('".$rowsww['id']."', '4', '$date_cr', '1');";
	$result3 = $objhr->insertion($sql3);
				}
		 }
	
//echo date('D', strtotime($date_cr));
		 $sql_at = "select *from tbl_emp_attendance where md5(emp_id)='$emp_id' and date_ = '$date_cr' ";
						$result_at = $objhr->viewdata($sql_at);
				if($result_at->num_rows > 0){
					$rows_at = $result_at->fetch_assoc();
					$status = $rows_at['status'];
					$p_type = $rows_at['present_type_id'];
					
					
					if(($p_type=='3') and ($status=='1')){?>
					
					<input type='button' class="btn btn-primary " style="width:50px;  " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none" id="aa<?php echo $i; ?>" >Absent</span>
					<?php
					
					
					}
					
					elseif(($p_type=='3') and ($status=='0')){?>
					 <input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-primary " style="width:50px; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none" id="pp<?php echo $i; ?>" >Present</span>
					
					
					<?php
					}
					elseif(($p_type=='2') and ($status=='1')){?>
					
					<input type='button' class="btn btn-default " style="width:50px; background:#00FFFF;  " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none" id="aa<?php echo $i; ?>" >Absent</span>
					<?php
					
					
					}
					
					elseif(($p_type=='2') and ($status=='0')){?>
					 <input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-default " style="width:50px; background:#00FFFF;  display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none" id="pp<?php echo $i; ?>" >Present</span>
					
					
					<?php
					}
					
					elseif(($p_type=='4') and ($status=='1')){?>
					
					<input type='button' class="btn btn-default " style="width:50px; background:#FF9933; color:#FFFFFF; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none" id="aa<?php echo $i; ?>" >Absent</span>
					<?php
					
					
					}
					
					elseif(($p_type=='4') and ($status=='0')){?>
					 <input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-default " style="width:50px; background:#FF9933; color:#FFFFFF; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none" id="pp<?php echo $i; ?>" >Present</span>
					
					
					<?php
					
					}
					elseif($status=='1'){
					
					?>
					
					<input type='button' class="btn btn-default " style="width:50px; background:#009933; color:#FFFFFF; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none" id="aa<?php echo $i; ?>" >Absent</span>
					
					<?php }elseif($status=='0'){?>
					 <input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-default " style="width:50px; background:#009933; color:#FFFFFF; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none" id="pp<?php echo $i; ?>" >Present</span>
		   </th>
					<?php
					
					
					}
					}else{
		 ?>
		 <input type='button' class="btn btn-default " id="d<?php echo $i; ?>" style="width:50px;" value='<?php echo $i; ?>' onclick='f1(this)' /> 
		 
		 <input type='button' class="btn btn-default " style="width:50px; background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-default " style="width:50px; background:#009933; color:#FFFFFF; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none" id="pp<?php echo $i; ?>" >Present</span>
		 <?php }?>
		 
		
            <!--<th><?php echo '<a href="attendance?date='.$i.'">'.$i.'</a>'?></th> -->
      
        <?php if(($i + $blank) % 7 == 0): ?>
            </tr><tr>
        <?php endif; ?>
    <?php endfor; ?>
    <?php for($i = 0; ($i + $blank + $daysInMonth) % 7 != 0; $i++): ?>
        <th></th>
    <?php endfor; ?>
    </tr>
</table>
							 </div>
							 
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->


<?php
include('../include/footer.php');
?>

