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

<?php  include("sessioncheck.php"); ?>

<?php



  

   $session;



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



      $session=$_REQUEST['session'];

      

    }else {

      

      $session=$_SESSION['current_session'];

    }





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

   

       $branch=$_SESSION['branch'];

       $classID=$_REQUEST['class_id'];

       $sectionID=$_REQUEST['section'];

     /*  $sql = "SELECT student_id, first_name, last_name, ref_no, cell_no, status, branch_id, class_id, candidate_roll_no, section_id, session_id FROM  edu_student_details  WHERE branch_id='$branch' and status='0' and session_id='$session' and class_id='$classID' and section_id='$sectionID' ";



       $WorkAssignListings = $m->query($sql); */   



    }





    $date1;

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

      $date1=$_REQUEST['date'];

    }else {

      

      $date1=date("Y-m-d");

    }





     ?>





<!DOCTYPE html>

<html lang="en">

  <head>

   

    <title>Mark Attendance | EduPortal</title>

    <?php include('RootMe/css_links.php');?>

   



<style>

/* The container */

.btn_style {

    display: block;

    position: relative;

    padding-left: 35px;

    margin-bottom: 12px;

    cursor: pointer;

    font-size: 12px;

    -webkit-user-select: none;

    -moz-user-select: none;

    -ms-user-select: none;

    user-select: none;

}



/* Hide the browser's default radio button */

.btn_style input {

    position: absolute;

    opacity: 0;

    cursor: pointer;

}



/* Create a custom radio button */

.checkmark {

    position: absolute;

    top: 0;

    left: 0;

    height: 20px;

    width: 20px;

    background-color: #eee;

    border-radius: 50%;

}



/* On mouse-over, add a grey background color */

.btn_style:hover input ~ .checkmark {

    background-color: #ccc;

}



/* When the radio button is checked, add a blue background */

.btn_style input:checked ~ .checkmark {

    background-color: #2196F3;

}



/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {

    content: "";

    position: absolute;

    display: none;

}



/* Show the indicator (dot/circle) when checked */

.btn_style input:checked ~ .checkmark:after {

    display: block;

}



/* Style the indicator (dot/circle) */

.btn_style .checkmark:after {

  top: 6px;

  left: 6px;

  width: 8px;

  height: 8px;

  border-radius: 50%;

  background: white;

}

</style>





</head>



<input type="hidden" value="<?php echo $_SESSION['branch'];?>" id="branch" >

<input type="hidden" name="" id="class_id" value="<?php echo $_REQUEST['class_id'];?>">

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



<script>



   window.onload = function() {

  var bid=document.getElementById("branch").value;

  



    $(document).ready( function () {

    getDataForLoacalStorage(bid);

    $('#listofstudents').DataTable();

} );

};



  function getDataForLoacalStorage(id) {



//alert(id);



if (localStorage.getItem("Students") === null) {





    if (window.XMLHttpRequest) {



      // code for IE7+, Firefox, Chrome, Opera, Safari



      xmlhttp=new XMLHttpRequest();



    } else { // code for IE6, IE5



      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");



    }



    xmlhttp.onreadystatechange=function() {



      if (xmlhttp.readyState==4 && xmlhttp.status==200) {

       

         var studentData=xmlhttp.responseText;



         

         localStorage.setItem('Students',studentData);

       



          }



    }



    xmlhttp.open("GET","get_students_local_storage.php?branch="+id,true);



    xmlhttp.send();







    } else {



var cls=document.getElementById("class_id").value;

var sec=document.getElementById("section_id").value;



var clssec=cls+sec;

//alert(clssec);



 let arr=JSON.parse(localStorage.getItem('Students'));

        arr=arr[clssec];

  

        if(arr !=null){

          let html='';

          let sno=1;

          html=`

       

          <table id="listofstudents" data-page-length='100' class="table table-striped table-bordered dataTable no-footer" style="width:100%;background-color: white;">

          

          <thead>

            <tr>

                <th width="5%">S.No</th>

                <th width="15%">Student Name</th>

                <th width="15%">Father Name </th>                

                <th width="40%">Attendance</th>

                <th width="10%">Roll#</th>

                <th width="10%">Adm#</th>

            </tr>

        </thead>

        <tbody>

        `;

          for(let k in arr){

        

            html=html+`

          

            <tr>

            <td>${sno++}</td>  

            <td style='text-align:left;'>${arr[k].first_name}</td>

            <td style='text-align:left;'>

            <input name="attendance[]" id="attendance[]" type="hidden" value="${arr[k].student_id}">

            ${arr[k].last_name}</td>

            <td>



            <div style="float:left;">

                    

              <label class="btn_style">Present

                <input type="radio" checked="checked" name="${arr[k].student_id}" value="P" />

                <span class="checkmark"></span>

              </label>



            </div>



            <div style="float:left;margin-left:2%">

                    

              <label class="btn_style">Absent

                <input type="radio" name="${arr[k].student_id}" value="A" />

                <span class="checkmark"></span>

              </label>



            </div>



            <div style="float:left;margin-left:2%">

              

              <label class="btn_style">Leave

                <input type="radio" name="${arr[k].student_id}" value="L" />

                <span class="checkmark"></span>

              </label>



            </div>

            



            <div style="float:left;margin-left:2%">

              

              <label class="btn_style">Late

                <input type="radio" name="${arr[k].student_id}" value="LA" />

                <span class="checkmark"></span>

              </label>



            </div>



            <div style="float:left;margin-left:2%">

              

              <label class="btn_style">Short Leave

                <input type="radio" name="${arr[k].student_id}" value="SL" />

                <span class="checkmark"></span>

              </label>



            </div>





            </td>

            <td style='text-align:left;'>${arr[k].candidate_roll_no}</td>   

            <td style='border-right:1px solid black;'>${arr[k].ref_no}</td>

            </tr>`;



          

}



          html=html+`

            </tbody>

        

            </table>

            `;

          document.getElementById('ajaxData').innerHTML=html;



        }



    } // end else condition





} // end function





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

          <div class="" style="" >

      <h3 style="float: left;">Students Mark Attendance <!-- <small>(<?php echo count($WorkAssignListings);?> Students Records)</small> --> </h3>     

    <section class="add_sub_agent" id="table_sub_agent">

  <div class="container">



 <div class="" style="margin-top:10px;">





      <form class="" action="mark_attend.php" enctype="multipart/form-data" method="get">

       

          



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





<div class="pull-right">   





  <?php if ($_REQUEST['save']=="save") { ?>



    <a href="send_msgs.php" class="btn btn-success" target="_blank" >Send SMS Reporting</a>

    

 <?php } ?>

  

  <a href="select_edit_attendance.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&page=<?php echo $pageNameAccess[0]['page_id'];?>&date=<?php echo date('Y-m-d');?>&attendance=A" class="btn btn-info"  target="_blank">Daily Attendance Report</a>





  <a href="view_attendance.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&class_id=<?php echo $_REQUEST['class_id'];?>&section=<?php echo $_REQUEST['section'];?>&session=<?php echo $_SESSION['current_session'];?>&date=<?php echo $_REQUEST['date'];?>"  target="_blank" class="btn btn-success">View / Edit Attendance</a>







</div>







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

          <div class="panel-body" style="padding: 0px;">

          

            <div class="col-md-12" id="" 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</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" required >

                      

                   <?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" style="padding: 8px;">

                <div class="form-group ">

                  <label class="required">Date</label>

                  

                  <input class="form-control" type="date" name="date"  id="date"  value="<?php echo $date1;?>" required>

                </div>

              </div>







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

                <div class="form-group ">

                   <input type="hidden" name="addaccountAdmin" value="1">

                <button type="submit" class="btn btn-primary" style="margin-top: 28px;">Search</button>

                </div>

              </div>



              



             

            </div>

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

          </div>

        </div>

      </form>

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

    </div>

    <br>



        





          

<?php 



 if(!isset($_REQUEST['class_id'])){



?>

          <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> Please select class and month from advance search to mark attendance !!!

                  </div>

            </div>

<?php 



   }

?>  



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



            <div class="alert alert-success" id="msg">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Success!</strong> Attendance Save successfully... Please Search again class and section to mark attendance !!!

            </div>





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





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



            <div class="alert alert-danger" id="msg">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Warning!</strong> Attendance Already Saved !!!

            </div>





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





<?php 







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

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

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

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

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



  $records =  $m->get('eduportal_attendance_detail');    



    if(count($records)>0){ 



?>



         <div class="alert alert-danger" style="font-weight: bold;font-size: 18px;" >

             <a href="#" class="close"  data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Warning!</strong> Attendance Already Saved !!!

            </div>





<?php } ?>





<div style="">

      

<?php if (!isset($_REQUEST['save'])) { ?>



<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" id="class_id"  name="class_id" value="<?php echo $_GET['class_id']; ?>" />

  <input type="hidden" id="section_id"  name="section_id" value="<?php echo $_GET['section']; ?>" />

  <input type="hidden" id="year"  name="year" value="<?php echo $_GET['year']; ?>" />

  <input type="hidden" id="month"  name="month_id" value="<?php echo $_GET['month_id']; ?>" />

  <input type="hidden" id="date"  name="date" value="<?php echo $date1; ?>" />







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



       <input type="submit" name="submit" class="btn btn-success pull-right"  value="Save Attendance" style=""  />



       <input type="submit" name="holiday" class="btn btn-danger pull-right"  value="Mark as holiday" style="margin-right: 15px;"  />



        

         <?php    }?>



    

      

      

       <div id="ajaxData">

               

        

    </div> 



</form>

<?php } ?>

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



     

  </body>

</html>

