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

$date;
  if ($_REQUEST['date']) {

     $date = $_REQUEST['date'];
     } else {
     $date = date("Y-m-d");
     }

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

        $m->where("class_id", $_REQUEST['class_id']);  
      
      if($_REQUEST['date']!=NULL){

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

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

        $m->where("section_id", $_REQUEST['section']);
        
      }


       $m->where("status", '1');
       $m->where("branch_id", $_SESSION['branch']);
       $m->orderBy("student_id", asc);

       $param = array('attendance','student_id','class_id','section_id');
       $WorkAssignListings = $m->get("eduportal_attendance_detail",null,$param);
       
}
else {

       $m->where("status", '1');
       $m->where("date", date("Y-m-d"));
       $m->where("branch_id", $_SESSION['branch']);
       $m->where("attendance", "A");
       $m->orderBy("student_id", asc);
       $param = array('attendance','student_id','class_id','section_id');
       $WorkAssignListings = $m->get("eduportal_attendance_detail",null,$param);
  }
 
     ?>



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

<script type="text/javascript">

function show_message(){
  
  $("#msg").slideDown('slow').delay(4000).slideUp('slow');
}

</script>


  <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">

            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i> <a href="select_edit_attendance.php">Edit Attendance </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              View Classwise Attendance
          <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="view_attendance.php" enctype="multipart/form-data" method="get">
        <div class="panel panel-default">
          <div class="panel-heading"><?php echo count($WorkAssignListings);?> Students 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" />


<a href="mark_attendanceReport_list.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" class="btn btn-info" style="margin-top: 5px;"> Attendance Reports</a>


<?php    if($_REQUEST['class_id']!=NULL && $_REQUEST['section']!=NULL){?>

      <a   class="btn btn-warning"  style="margin-top: 5px;" href="edit_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'];?>&session=<?php echo $_GET['session'];?>&date=<?php echo $_GET['date'];?>"> 
      Edit Attendance </a>


      <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?class_id=<?php echo $_REQUEST['class_id'];?>&date=<?php echo $_REQUEST['date'];?>&session=<?php echo $_REQUEST['session'];?>&section=<?php echo $_GET['section'];?>&action=DeleteClassAttendance" style="" onClick="return confirm('Are you sure you want to delete Class Attendance');"  class="btn btn-danger">Delete Attendance </a>

 <?php    }?>


          </span><div class="clearfix"></div> </div>
          <div class="panel-body">
          
            <div class="col-md-12" id="advanceSearch" style="">
              
               <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Year</label>
                     <select name="year" class="form-control" >                              
                        <?php
                       $match;
                        if(!isset($_REQUEST['year'])){
                          $match=date("Y");
                        }else { $match=$_REQUEST['year']; }
                        for ($i=2020; $i < 2051; $i++) 
                        { ?>
                           <option <?php if($match==$i){echo 'selected';}?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
                        <?php } ?>
                    </select>
                </div>
              </div>


              <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Month</label>
                     <select name="month_id" class="form-control"  >                    

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

                       <option <?php if($_REQUEST['month_id']==$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-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>

                  <select name="class_id" class="form-control" onChange="getsec(this.value)"  >
                    <option value="All">All</option>

                    <?php

                    $m->where("branch_id", $_SESSION['branch']);
                    $WorkAssignList = $m->get("edu_class_config");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($_REQUEST['class_id']==$WorkAssignListVal['class_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['class_id']; ?>"><?php echo $WorkAssignListVal['Class_Name']; ?></option>


                            <?php
                    } ?>

                </select> 
                </div>
              </div>
            
              <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select name="section" id="txt_section" class="form-control" >
                      
                   <?php
                              if($_REQUEST['section']!='')
                              { 

                              $m->where("section_id", $_REQUEST['section']);    

                              $secondLevel = $m->get("edu_adm_section_detail");
                              
                              foreach($secondLevel as $secondLevel_val)
                              {
                              
                               ?>
                                <option <?php if($_REQUEST['section']==$secondLevel_val['section_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['section_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['section_name'])); ?></option>

                              <?php }   ?>
                                
                          <?php } ?>

                    </select>

                  
                </div>
              </div> 
              
              <div class="col-md-2" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Attendance Date</label>
                    <input class="form-control" type="date" name="date"  id="date"  value="<?php echo $date;?>">

                  

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

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

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


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Attendance is updated successfully...
            </div>


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

         

          

  

<div style="">

<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 style="overflow-x:auto;">
   

    <table id="listofstudents" data-page-length='50' class="table table-striped table-bordered datatable" style="width:100%">
          
          <thead>
            <tr>
                <th width="2%">S.No</th>
                <th width="12%">Student Name</th>
                <th width="10%"> Father Name </th>
                <th width="10%"> Cell No </th>
                <th width="8%">Adm/Roll No</th>
                <th width="8%" style="text-align:center;"> Date </th>
                 <th width="10%">Attendance</th>
            </tr>
        </thead>
        <tbody>


   
     
     <?php 
      $count=1;
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 


        $branch=$_SESSION['branch'];    
        $stdID=$WorkAssignListVal['student_id'];
        $sql = "SELECT student_id, first_name, last_name, ref_no, cell_no, candidate_roll_no FROM  edu_student_details  WHERE branch_id='$branch' and student_id='$stdID' ";

        $student = $m->query($sql); 
        
      ?>

        <tr>
                
                  <td style="text-align:center;">

                     <?php echo $count; $count++;?>

                   </td>


                  <td >

                     <a target="_blank" style="text-decoration: none;" 
  href="print_students_attendance_history.php?student=<?php echo $student[0]['student_id'];?>" >
                     <?php echo $student[0]['first_name'];?>
                     </a>

                   </td>

                  <td>  <?php echo $student[0]['last_name'];?> </td>
                  <td>  <?php echo $student[0]['cell_no'];?> </td>

                  <td> <?php echo $student[0]['ref_no'];?> / <?php echo $student[0]['candidate_roll_no'];?> </td>
                 <td style="text-align:center;"><?php echo date("d-M-Y",strtotime($date));?>  </td>

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

                  <?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 -->
  
    <script src="js/ajax_functions.js"></script>
    <?php include('RootMe/js_linksscript.php');?>
    <!-- Links for Datatable-->

<!-- Links for Datatable-->
<link href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />   
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
 <script>
        
  $(document).ready(function() {
    $('#listofstudents').DataTable({
      "pageLength": 1000
    });
    } 
  );

</script>
     
  </body>
</html>
