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

$pageName = basename($_SERVER['PHP_SELF']);

 $m->where("page_name", $pageName);
 $pageNameAccess=$m->get("eduportal_modules_pages_detail");


$m->where("user_id", $_SESSION['user_id']);
$m->where ("branch_id", $_SESSION['branch']);
$m->where("page_id", $pageNameAccess[0]['page_id']);
$access = $m->get("users_privilege_detail");


if($_REQUEST['date']!=NULL){

    $m->where("date", $_REQUEST['date']);
     }
   else {
    $m->where("date", date("Y-m-d"));
   }  
    if($_REQUEST['session']!=NULL){

    $m->where("session_id", $_REQUEST['session']);
     }

    if($_REQUEST['todayAbsent']!=NULL){

    $m->where("attendance", 'A');
     }

    if($_REQUEST['todayPresent']!=NULL){

    $m->where("attendance", 'P');
     }

     if($_REQUEST['todayLate']!=NULL){

    $m->where("attendance", 'LA');
     }

   $m->where("branch_id", $_SESSION['branch']);

   $WorkAssignListings = $m->get("eduportal_hrm_emp_attendance");
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>View Employee 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;   
             View Staff attendance
             <br><br>
             
          <div class="" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

    <?php if ($video[0]['video_url']!=NULL) { ?>
  
  <a href="watch_video.php?videourl=<?php echo $video[0]['video_url'];?>" target="_blank" class="btn btn-success" style="padding: 10px 10px; font-size:14px;color:white;float: right;"><i class="fa fa-play"></i>&nbsp;&nbsp;Watch Demo</a>

<?php } ?>

<br><br><br>

 <div class="" style="margin-top:10px;">
      <form class="" action="view_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;">View Employee 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 onClick="$('#advanceSearch').toggle('blind')" class="btn btn-primary" style="cursor:pointer;">Advance Search</a>
   <a href="send_emp_absnt_msgs.php" class="btn btn-primary">Staff Absent Report</a>
   <a href="mark_emp_attendance.php" class="btn btn-success">Mark Attendance</a>
   <a href="teacher_daily_lecture_attendance.php" class="btn btn-success">Mark Lecture Attendance</a>

<?php 

 if($_REQUEST['date']!=NULL AND $access[0]['edit_access']!=NULL){

?>

  <a  class="btn btn-warning" href="mark_emp_attendance.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&class_id=<?php echo $_GET['class_id'];?>&section=<?php echo $_GET['section'];?>&date=<?php echo $_GET['date']; ?>&edit=yes">
    Edit Attedance
  </a>

<?php 

   }
?>

</div>



          </span><div class="clearfix"></div> </div>
          <div class="panel-body">
          
            <div class="col-md-12" id="advanceSearch" style="display:none;">

              
               <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" class="form-control" >

                              
                        <?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 echo $WorkAssignListVal['session_year']; ?></option>


                                <?php
                        } ?>

                    </select>
                </div>
              </div>
             
      
              
                <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Date</label>
                  <?php 

                  $date1;
                  if($_REQUEST['date']!=NULL){
                    $date1=$_REQUEST['date'];
                  }else {
                    
                    $date1=date("Y-m-d");
                  }
                  
                  ?>
                  <input class="form-control" type="date" name="date"  id="date" style=""  value="<?php echo $date1;?>" required>
                </div>
              </div>

              <div class="col-md-3" style="padding:2px;">
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 30px;">Search</button>
                </div>
              </div>

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

     

<?php  if(isset($_SESSION['emp_attendance_done'])){?>

   <div id="error"  class="alert alert-success alert-dismissible">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
             <strong>Success !</strong> Attendance is saved succesfully...
    </div>

 <?php  unset($_SESSION['emp_attendance_done']); }?>


 <?php  if(isset($_SESSION['AlreadyAddedEmpAttenddance'])){?>

<div class="alert alert-danger" id="msg">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Danger!</strong> Attendance Is Already Added In This Date...
</div>


<?php  unset($_SESSION['AlreadyAddedEmpAttenddance']); }
?>



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

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

    <input type="hidden" name="action" value="MarkAttendance">
    <input type="hidden" name="class_id" value="<?php echo $_REQUEST['class_id'];?>" />
    <input type="hidden" name="section_id"  value="<?php echo $_REQUEST['section'];?>" >

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

    <table id="listofstudents" data-page-length='50' class="table table-striped table-bordered" style="width:100%">
          
           <thead>
            <tr>
                <th width="5%">S.No</th>
                <th width="20%">First Name</th>
                <th width="20%">Last Name</th>
                <th width="12%">Department </th>
                <th width="12%">Designation</th>                
                <th width="12%" style="text-align:center;"> Date </th>
                <th width="15%">Attendance</th>

            </tr>
        </thead>
        <tbody>

   
        
     <?php
     
     $count=1; 

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

        $m->where("user_id", $WorkAssignListVal['emp_id']);
        $emp=$m->get("edu_user_config");

        $m->where("designation_id", $emp[0]['designation_id']);
        $designation=$m->get("eduportal_designation_config");

        $m->where("department_id", $emp[0]['department_id']);
        $department=$m->get("eduportal_hrm_department_config");

        
      ?>


<tr>
        
     <td style="text-align:center;"> <?php echo $count; $count++; ?>  </td>

  <td> <?php echo $emp[0]['user_fname'];?> </td>
  <td> <?php echo $emp[0]['user_lname'];?> </td>
  
  <td> <?php echo $department[0]['department_name'];?> </td>
  <td> <?php echo $designation[0]['designation_name'];?> </td>
  <td style="text-align:center;"> <?php echo date("d-M-Y",strtotime($WorkAssignListVal['date']));?> </td>

  <td style="text-align:center;<?php if($WorkAssignListVal['attendance']=="L"){echo "background-color:#F2DEE0";} if($WorkAssignListVal['attendance']=="A"){echo "background-color:#E26867;color:white;";} if($WorkAssignListVal['attendance']=="SL"){echo "background-color:#DAF7A6;color:black;";} if($WorkAssignListVal['attendance']=="LA"){echo "background-color:#B9F7CA;color:black;";}?>;" >

  <?php echo $WorkAssignListVal['attendance'];?>

  </td>

</tr>





              <?php
      } ?>




           
            
           
        </tbody>
        
    </table>
  
  </div>
  
</form>

</div>
    <br><br>


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

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  
  <!-- jQuery -->
<!-- Links for Datatable-->
 
  <?php include('RootMe/js_linksscript.php');?>
  <!-- jQuery -->
    <script src="js/ajax_functions.js"></script> 
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
     

  </body>
</html>
