<?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("class_id", $_REQUEST['class_id']);
 $m->where("section_id", $_REQUEST['section']);
// $m->where("session_id", $_SESSION['current_session']);
 if ($_REQUEST['orderBy']=="Name") {
    $m->orderBy("first_name","asc");    
 }

 if ($_REQUEST['orderBy']=="RollNoWise") {
    $m->orderBy("candidate_roll_no","asc");
     }

 if ($_REQUEST['orderBy']=="RegNoWise") {   
    $m->orderBy("ref_no","asc");
 }

 $param = array('student_id','first_name','last_name');

 $WorkAssignListings = $m->get("edu_student_details",null,$param);
 
  // settings month details

    $default;
    
    if($_GET["month"]!=NULL ){
      $default= $_GET["month"];
    }
    else{
      $default= date("m");
    }
  
   // print_r($WorkAssignListings);
  
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Monthly Students 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">
          <div class="" style="background-color: white;">
           
        <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
    
         <a href="mark_attendanceReport_list.php">Attendance Reports </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
          Filled Attendance Sheet

          <br><br>



  <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);?> Student 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-success" href="classwise_monthly_attendance_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>"style="cursor:pointer;" >  All Classes Attendance Report </a> -->

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

  <?php if (isset($_GET['class_id'])) { ?>

<!--   <a href="print_attendance_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&month=<?php echo $_GET['month'];?>&class_id=<?php echo $_GET['class_id'];?>&section=<?php echo $_GET['section'];?>&orderBy=<?php echo $_GET['orderBy'];?>" id="subuser"target="_blank" class="btn btn-success" style="">Print Report </a> -->

  <a style="padding:7px; font-size:14px;" data-toggle="modal" data-target="#attendance" class="btn btn-success"> Print Report </a>
<?php } ?>


 


</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_report.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-2 col-sm-12 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Year</label>
                   <select style="height:40px;" 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 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-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>

            
                    <select style="height:40px;" name="class_id" onChange="getsec(this.value)" class="form-control" >
                     <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 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select style="height:40px;" name="section" id="txt_section" class="form-control" >
                      
                   <?php
                              if($_REQUEST['section']!='')
                              { 

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

                              $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 col-sm-12 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                <label class="required">List Order</label>
                <select name="orderBy" id="orderBy" class="form-control" style="height:40px;" >
            
                     <option  value="Name">Name Alphabetically</option>
                     <option  value="RollNoWise">Roll No Wise</option>
                     <option  value="RegNoWise">Adm No Wise</option>
                       
                    </select>
              </div>
            </div>
 

              <div class="col-md-2 " style="padding:2px;">

                
    
           
                <div class="form-group ">
                   
                <button type="submit" class="btn btn-primary" style="margin-top: 34px;">Search Attendance</button>
                </div>        

              </div>

              

<?php if (isset($_GET['class_id'])) { ?>


    

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

         // $days=date("t");
          $days=cal_days_in_month(CAL_GREGORIAN, $default, $_GET["year"]);
          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 style="text-align:center;padding: 0px;"><?php echo $count++;?></td>
  <td>

  <a target="_blank" style="text-decoration: none;" 
  href="print_students_attendance_history.php?student=<?php echo $WorkAssignListVal['student_id'];?>&class_id=<?php echo $_REQUEST['class_id'] ;?>&section_id=<?php echo $_REQUEST['section'];?>&session=<?php echo $_REQUEST['session'];?>" >
    
    <?php echo $WorkAssignListVal['first_name']/*.' '. $WorkAssignListVal['last_name']*/;?>
    <input name="attendance[]" id="attendance[]" type="hidden" value="<?php echo $WorkAssignListVal['student_id'];?>">
    </a>       
                     
  </td>

      
      

      <td>

    <div style="">


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

    <tr>  
<?php 

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

   $date=$_GET["year"]."-".str_pad($_GET['month'], 2, '0', STR_PAD_LEFT)."-".str_pad($i, 2, '0', STR_PAD_LEFT);
   
   $id=$WorkAssignListVal['student_id'];  
   $qr="select attendance from eduportal_attendance_detail where date='$date' and student_id='$id' and branch_Id=".$_SESSION['branch'];
   //echo $qr;
   $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>
<?php  } else {?>
<br><br><br><br><br><br><br><br>
  <div  style="display:block;" class="alert alert-danger alert-dismissible">
      <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
       <strong>Warning !</strong> Please select Class and Section For Attendance  !!!
  </div>
  <?php }?>
</form>

<!-- start popup code  -->

      <div id="attendance" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header" style="border-bottom:none;">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title" style="text-align:center;">  </h4>
            </div>

            <div class="modal-body">




<form  action="print_attendance_report.php">

     <input type="hidden" name="sess" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>"> 
     <input type="hidden" name="month" value="<?php echo $_GET['month']; ?>" />
     <input type="hidden" name="class_id" value="<?php echo $_GET['class_id']; ?>">
     <input type="hidden" name="section" value="<?php echo $_GET['section']; ?>">
     <input type="hidden" name="year" value="<?php echo $_GET['year']; ?>">
     <input type="hidden" name="orderBy" value="<?php echo $_GET['orderBy']; ?>">

           
<div class="col-md-12" style="padding: 8px;">



      <div class="form-group ">

    <label class="">Display Cell Number SMS</label>
        <select  name="display_cell" class="form-control"  >

          <option value='YES'>YES</option>
          <option value='NO'>NO</option>                   

        </select>
      </div>

       
</div> 
                   
              
                  
                                  
      
            <div class="modal-footer">

            <button type="submit" class="btn btn-primary" name="submit" >Submit </button>
              


            </div>



                 </form>

          </div>

          </div>

        </div>
      </div>

      <!-- Student result popup ending -->
<div class="clearfix"></div>
</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');?>
  </body>
</html>
