<?php
include('../include/header.php');



?>

<style>
.table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
    line-height: 5px;
    vertical-align: top;
}

</style>
<?php

$my_random_number = rand(1000, 9999);
 $sql_cod = "select * from tbl_attendance_pass ";
						$result_cod = $objhr->viewdata($sql_cod);
						 if($result_cod->num_rows > 0){
					$rows_cod = $result_cod->fetch_assoc();
					$t_date = date('Y-m-d');
					if($t_date > $rows_cod['date']){
					$sql_dl ="TRUNCATE tbl_attendance_pass;";
					$result_dl = $objhr->deletion($sql_dl);
					
					$sql3 = "INSERT INTO `tbl_attendance_pass` (`code`, `date`) VALUES ('$my_random_number', '$t_date');";
	$result3 = $objhr->insertion($sql3);
					}
					
					}
					if($result_cod->num_rows < 1){
					$t_date = date('Y-m-d');
					$sql3 = "INSERT INTO `tbl_attendance_pass` (`code`, `date`) VALUES ('$my_random_number', '$t_date');";
	$result3 = $objhr->insertion($sql3);
					}
					
					
					
					
					
					
					
	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">Dashboard</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">Dashboard</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">
                            <div class="card-body"> 
							<?php
							 $sql_tc = "select * from tbl_attendance_pass ";
						$result_tc = $objhr->viewdata($sql_tc);
						$rows_tc = $result_tc->fetch_assoc();
							if($type==1):?>
							Today's Attendance pass : <b><?php echo $rows_tc['code']; ?></b>
							
							<?php
							endif
							?>
							
							<div class="row">
							<div class="col-md-8" style="border:1px solid #cccccc;">
							<h3>Attendance</h3>
							<div class="card-body" style="padding:5px; ">
						 <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; height:100px;">
    <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-xs btn-primary " style="  " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
					<?php
					
					
					}
					
					elseif(($p_type=='3') and ($status=='0')){?>
					 <input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-xs btn-primary " style=" display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					
					
					<?php
					}
					elseif(($p_type=='2') and ($status=='1')){?>
					
					<input type='button' class="btn btn-xs btn-default " style=" background:#00FFFF;  " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
					<?php
					
					
					}
					
					elseif(($p_type=='2') and ($status=='0')){?>
					 <input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-xs btn-default " style=" background:#00FFFF;  display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					
					
					<?php
					}
					
					elseif(($p_type=='4') and ($status=='1')){?>
					
					<input type='button' class="btn btn-xs btn-default " style=" background:#FF9933; color:#FFFFFF; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
					<?php
					
					
					}
					
					elseif(($p_type=='4') and ($status=='0')){?>
					 <input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-xs btn-default " style=" background:#FF9933; color:#FFFFFF; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none;font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					
					
					<?php
					
					}
					elseif($status=='1'){
					
					?>
					
					<input type='button' class="btn btn-xs btn-default " style=" background:#009933; color:#FFFFFF; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
					<input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
					
					<?php }elseif($status=='0'){?>
					 <input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-xs btn-default " style=" background:#009933; color:#FFFFFF; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none; font-size:10px; margin-left:2px;" id="pp<?php echo $i; ?>" >Present</span>
		   </th>
					<?php
					
					
					}
					}else{
		 ?>
		 <input type='button' class="btn btn-xs btn-default " id="d<?php echo $i; ?>" style="" value='<?php echo $i; ?>' onclick='f1(this)' /> 
		 
		 <input type='button' class="btn btn-xs btn-default " style=" background:#FF0000; color:#FFFFFF; display:none "  id="a<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' />
		  
		   <span style="color:#FF0000; display:none; font-size:10px; margin-left:2px;" id="aa<?php echo $i; ?>" >Absent</span>
		   
		   <input type='button' class="btn btn-xs btn-default " style=" background:#009933; color:#FFFFFF; display:none; " id="p<?php echo $i; ?>" value='<?php echo $i; ?>' onclick='f1(this)' /><span style="color:#009933; display:none;font-size:10px; margin-left:2px;" 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 class="col-md-1"></div>
							<div class="col-md-3" style="border:1px solid #CCCCCC;">
							<h3>Leave</h3>
							</div>
							
							</div>
							
							
							<br />
							<div class="row">
							
							<div class="col-md-4" style="border:1px solid #CCCCCC;">
							<h3>Birth Day</h3>
							<p style="color:#000;"><b>Today:</b></p>
							<?php
							$sql_db1 = "SELECT * FROM `tbl_emp_master` where dob = '".date('Y-m-d')."'";
						$result_db1 = $objhr->viewdata($sql_db1);
						while($rows_db1 = $result_db1->fetch_assoc()){
						
						
						$sql_p = "SELECT * FROM `tbl_profile_pic` where emp_id = '".$rows_db1['id']."'";
						$result_p = $objhr->viewdata($sql_p);
						$rows_p = $result_p->fetch_assoc();
						if($result_p->num_rows >0){
						$img=$rows_p['image'];
						}else{
						$img='user.png';
						}
							?>
							<P><span style="color:#00CC00;"><img src="images/profile/<?php echo $img; ?>" style=" height:40px; width:40px; border-radius:20px;" />      <?php echo strtoupper($rows_db1['emp_name']);?></span></P>
							<?php
							}if($result_db1->num_rows <1){
							?>
							<P><span style="color:#FF0000;">NONE OF ONE'S.</span>
							<?php }?>
							<p style="color:#FF9933;"><b>This Month:</b></p>
							<marquee direction="up" scrollamount="1" onmouseover="this.stop();"
           onmouseout="this.start();">
		   
		   <?php
		   $sql_db = "SELECT * FROM `tbl_emp_master` where dob>= '".date('Y-m-01')."' and dob <='".date("Y-m-t")."' order by dob";
						$result_db = $objhr->viewdata($sql_db);
						while($rows_db = $result_db->fetch_assoc()){
						$dt=explode('-',$rows_db['dob']);
						
						$sql_pp = "SELECT * FROM `tbl_profile_pic` where emp_id = '".$rows_db['id']."'";
						$result_pp = $objhr->viewdata($sql_pp);
						$rows_pp = $result_pp->fetch_assoc();
						if($result_pp->num_rows >0){
						$img2=$rows_pp['image'];
						}else{
						$img2='user.png';
						}
		    ?>
		   
		   <P style="color:#000000;"><img src="images/profile/<?php echo $img2; ?>" style=" height:40px; width:40px; border-radius:20px;" />   <span style="color:#009933;"><?php echo strtoupper($rows_db['emp_name']);?> </span> on Date <span style="color:#009933;"><?php echo $dt[2]; ?> <?php 
$monthNum  = $dt[1];
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F'); 

echo $monthName; ?></span></P>
		   <?php }?>
							
							</marquee>
							<?php
							if($result_db->num_rows <1){
							?>
							<P><span style="color:#FF0000;">NONE OF ONE'S.</span>
							<?php
							
							}
							
							?>
							</div>
							</div>
							
							
							
							 </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->


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