<? include("si_confi.php"); ?>
<? include("ad_head.php"); ?>

<div class="container">

<? 
include("mn_option.php");
$dtmxone=date_default_timezone_set("Asia/Kolkata");
$weekday = date('l', strtotime($date));
?>

  <? if($_REQUEST['ed']=='suc'){ ?>
  <div class="success" style="width:92%;margin:0 auto;margin-top:9px;">Changes saved successfully.</div><? } ?>
  <? if($_REQUEST['del']=='suc'){ ?>
  <div class="error" style="width:92%;margin:0 auto;margin-top:9px;">One Details Deleted successfully.</div><? } ?>
  
<?
$select_count_emp=mysql_query("select count(*) as num from `leave`");
$fetch_count_emp=mysql_fetch_array($select_count_emp);
$total_emp_result=$fetch_count_emp['num'];


 $empid=$_REQUEST['empid'];
 $dtmxone=date_default_timezone_set("Asia/Kolkata");
 
 
 $yr=date('Y');
  $month=$_REQUEST['month'];
 
 if($_REQUEST['month']!='')
 {
  $mnt = date("m", strtotime($month));
 }
 else
 {
	$mnt=date('m'); 
    $month=date('F');
 }
 
 
 if($mnt[0]==0)
 {
	 $mnth23=$mnt[1];
 }
 else
 {
	 $mnth23=$mnt; 
	
 }

 
  
 $d=cal_days_in_month(CAL_GREGORIAN,$mnth23,$yr);
 



?>
   <div>
   <h2>View Attendance Details&nbsp;&nbsp;&nbsp;(Total&nbsp;:&nbsp;<? echo $total_emp_result; ?>)</h2>
   
<link type="text/css" href="../calender/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="../calender/jquery.min.js"></script>
<script type="text/javascript" src="../calender/jquery.datepick.js"></script>
<script type="text/javascript">
$(function() {
	$('#popupDatepicker').datepick();
	$('#inlineDatepicker').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>
<script type="text/javascript">
$(function() {
	$('#popupDatepicker2').datepick();
	$('#inlineDatepicker2').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>

   
   <form method="post" enctype="multipart/form-data" action="attendance_search.php">
   <table id="serach_astat">
   <tr>
        <td>
        <select name="empid" class="validate-selection" autofocus>
        <option value="" hidden="">Select Employee</option>
        <? $seleect_employee=mysql_query("select * from `employee_mng`");
		while($fetch_employee=mysql_fetch_array($seleect_employee)){ ?>
<option value="<? echo $fetch_employee['emp_id']; ?>"><? echo ucwords($fetch_employee['name']); ?> - <? echo ucwords($fetch_employee['emp_id']); ?>
</option>
		<? } ?>
        </select>
        </td>
        
         <td>
        <select name="month" class="validate-selection" autofocus>
        <option value="" hidden="">Select Month</option>
        <?  for($m=1; $m<=12; ++$m)
		{
        ?>
<option value="<?  echo date('F', mktime(0, 0, 0, $m, 1)); ?>"><? echo  date('F', mktime(0, 0, 0, $m, 1)); ?> </option>
		<? } ?>
        </select>
        </td>
   <td>
   
   <input type="submit" name="search_status" value="Search"></td>
   </tr>
   
   
   
   </table>
   </form>
   <br>
 
   
   <span style="color:#900;">  <h3>
   Month : <? if($_REQUEST['month']!=NULL ){ echo $_REQUEST['month']; ?>&nbsp;&nbsp;&nbsp;
     
   <? } if($_REQUEST['empid']!=NULL){ echo "<span style='color:#900;margin-left:5%;'>Emp Id</span>&nbsp;:&nbsp;".ucwords($_REQUEST['empid'])."";} ?>
    </h3><br> <br>
    
    <?
	
 
 
	
	 ?>
  
  <table width="100%" cellpadding="9" cellspacing="0" border="1">
  <tr bgcolor="#CCCCCC">
  <!--<td>EMP ID</td>-->
  <td>EMP Name</td>
   <? for($v=1;$v<=$d;$v++) { ?>
  <td><? echo $v; ?></td>
  <? } ?>
 
  </tr>
  
 <?
 
  $dtte=date('d');
		
if($dtte[0]==0)
 {
	 $dtte=$mnt[1];
 }
 else
 {
	 $dtte=$dtte; 
 }
 
  $empid=$_REQUEST['empid'];
  
  if($_REQUEST['empid']!='')
  {
  $select_leave_details=mysql_query("select * from `employee_mng` where emp_id='$empid'");
  }
  else
  {
	$select_leave_details=mysql_query("select * from `employee_mng`  order by `id` desc");  
  }

  while($fetch_leave_details=mysql_fetch_array($select_leave_details))
  {
	   $emn=$fetch_leave_details['emp_id'];
	  
 ?>
      
  <tr bgcolor="#FFFFFF">
  <!-- <td><? echo $fetch_leave_details['emp_id']; ?></td>-->
  <td><? echo ucwords($fetch_leave_details['name']); ?></td>
  
  
  
   <?	
					    for($v=1;$v<=$d;$v++)
						{ 
						
						 $ckattm=mysql_query("select * from emp_attendance where empid='$emn' and  `$v`='1' and year='$yr' and month='$month'");
						 $cnm=mysql_num_rows($ckattm); 
						 $nmonth = date("m", strtotime("$month"));
						 $fnday=$yr.'-'.$nmonth.'-'.$v;
						
						 $weekday = date('l', strtotime($fnday));
								
								
								
			if($weekday!='Sunday')
			{		
										
					 if($dtte>=$v)
					 {
						  if($cnm>0)
						  {
					         ?> 
                             <td>
                             <img src="img/PngThumb-red-green-OK-not-OK-Icons-1-14389.png" width="15">
                             </td>
                            <? 
					      } 
						  else
						  {
						   ?>
                           <td><img src="img/ok-512.png" width="15"> </td>
                          <? 
					 }
					  
					}
					else
					{
						?>
                         <td>-</td>
                       <?
					   } }else {
					   ?>
                      
                       <td style="background-color:#09F;">Sun</td>
                     
                    <?php } }   ?> 
 
  
  </tr>
  
  <? } ?>
  <script type="text/javascript">
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=580,width=700,left=140,top=60,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
  </table>  
  </div>
</div><!-- container -->
  </body>
</html>