<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php

$branch=$_SESSION['branch'];

 $m->where("status", '0');
 $m->where("branch_id", $_SESSION['branch']);
 $m->where("designation_id!=14");
 $m->orderBy("user_id", 'desc');
 $WorkAssignListings = $m->get("edu_user_config");
 
  // settings month details

    $default;
    
    if($_GET["month"]!=NULL ){
      $default= $_GET["month"];
    }
    else{
      $default= date("m");
    }
  

    $session;
    
    if($_GET["session"]!=NULL ){
      $session= $_GET["session"];
    }
    else{
      $session= $_SESSION['current_session'];
    }



 $m->where("session_id", $session);
 $session_ID = $m->get("edu_session_config");

 $yr=explode("-", $session_ID[0]['session_year']);

   // print_r($WorkAssignListings);



     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Monthly Employees Attendance | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
  




  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
             <br>
          <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;   
             Attendance Report
             <br><br>
          <div class="" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
      <form class="" action="mark_emp_attendance.php" enctype="multipart/form-data" method="get">
        <div class="panel panel-default">
          <div class="panel-heading"><b style="font-size: 22px;color: gray;">Monthly  Attendance:</b> (<?php echo count($WorkAssignListings);?> Employee Records) <span style="float:right;margin-top: -7px;">

          <input type="hidden" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="session" />


<div class="pull-right">         

  
   <a class="btn btn-primary" href="staff_attendance_sheet.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>"> Monthly Attendance Sheet </a> 



</div>



          </span><div class="clearfix"></div> </div>
         
        </div>
      </form>
      <div class="clearfix"></div>
    </div>

<div style="">
      
<div class="clearfix"></div>
<form class="form-style-7" action="monthly_attendance.php" method="Get"  onSubmit="return student_check();"  enctype="multipart/form-data">

<?php 

 if(isset($_SESSION['emp_error_msg'])){
?>
<div class="col-md-12">

  <div  style="display:block;" class="alert alert-danger alert-dismissible">
      <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
       <strong>Warning !</strong> Attendance has already saved of this date!!!
  </div>

</div>
<?php 
  unset($_SESSION['emp_error_msg']);
   }
?> 
      
              
              <div class="col-md-3 col-sm-12 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" class="form-control"  style="height:40px;">

                              
                        <?php

                       $match;
                        if(!isset($_REQUEST['session'])){
                          $match=$_SESSION['current_session'];
                        }else { $match=$_REQUEST['session']; }
                       
                                 
                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($match==$WorkAssignListVal['session_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['session_id']; ?>">
                            <?php  $val=explode("-",$WorkAssignListVal['session_year']); echo $val[0];?></option>


                                <?php
                        } ?>

                    </select>
                </div>
              </div>


              <div class="col-md-3 col-sm-12 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                <label class="required">Month</label>
                <select style="height:40px;" name="month" id="month" class="form-control"  required>

                              <option value="">Select Month</option>
                        

                        <?php
                        $WorkAssignList = $m->get("eduportal_month_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($default==$WorkAssignListVal['Month_Id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['Month_Id']; ?>"><?php echo $WorkAssignListVal['Month_Name']; ?></option>


                                <?php
                        } ?>

                    </select>
              </div>
            </div>
 

              <div class="col-md-3 " style="padding:2px;">
    
           <?php    if(count($WorkAssignListings)>0){?>

                <div class="form-group ">
                   
                <button type="submit" class="btn btn-primary" style="margin-top: 34px;">Search Attendance</button>
               
               <a target="_blank" href="print_monthly_attendance.php?month=<?php echo $_GET['month']; ?>&session=<?php echo $_GET['session']; ?>"> 

                <button type="button" class="btn btn-success" style="margin-top: 34px;">Print</button>

               </a>
                
                </div>
    

         <?php    }?>

              </div>


    <table id="listofstudents3" data-page-length='100' class="table table-striped table-bordered" style="width:100%">
          
          <thead>
            <tr>
                
                <th width="15%">Name</th>
        
        
       <th width="85%">
        
      <table border="1" width="100%"  class="responsive">
              <?php 

         // $days=date("t");
          $days=cal_days_in_month(CAL_GREGORIAN, $default, date("Y"));
          for($i=1;$i<$days+1;$i++){     

          ?>

           <th width="2%" class="thStyle" style="padding:0px;text-align: center;"> <?php echo $i;?>  </th>

          <?php } ?>
                
      </table>
      
      </th>
    

            </tr>
      
        </thead>
        <tbody>
     
     <?php
     
     $count=1; 

     /*print_r($WorkAssignListings);
     echo "=======";*/
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
      
      ?>


<tr>
        
     

  <td>
    <a href="print_staff_attendance_history.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&emp=<?php echo $WorkAssignListVal['user_id'];?>&month=<?php echo $default;?>&year=<?php echo date("Y");?>">
    <?php echo $WorkAssignListVal['user_fname'];?>
   </a>
    <input name="attendance[]" id="attendance[]" type="hidden" value="<?php echo $WorkAssignListVal['emp_id'];?>">
            
                     
  </td>

      
      

      <td>

    <div style="">


    <table border="1" width="100%"  class="responsive">  

    <tr>  
<?php 

//$days=date("t");
$days=cal_days_in_month(CAL_GREGORIAN, $default, date("Y"));
for($i=1;$i<$days+1;$i++){

   $date=$yr[0]."-".str_pad($default, 2, '0', STR_PAD_LEFT)."-".str_pad($i, 2, '0', STR_PAD_LEFT);
   
   $id=$WorkAssignListVal['user_id'];  
   $qr="select * from eduportal_hrm_emp_attendance where date='$date' and emp_id='$id' and branch_id=".$_SESSION['branch'];
   $att = $m->query($qr);
?>

 <th  width="2%" style="padding:0px;text-align: center;"> <?php  if($att[0]['attendance']!=NULL){echo $att[0]['attendance'];}else {echo "--";};?> </th>

<?php } ?>

  </tr>

</table>

  </div>

   

      </td>
</tr>

        <?php } ?>



           
            
           
        </tbody>
        
    </table>

</form>
<div class="clearfix"></div>
</div>

    <br><br>


  </div>
  <div class="clearfix"></div>
</section>          
    

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
