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

$date=date('Y-m-d');
$branch=$_SESSION['branch'];




?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Mark Attendance | EduPortal</title>
   <?php include('RootMe/css_links.php');?>
   <style type="text/css">
    
    tr th{padding:1%;color:black;}

   </style>
  


<script>


function save_attendance() {
  
  var att=document.getElementById("attendance").value;
  var rollReg=document.getElementById("rollReg").value;
  var date=document.getElementById("date").value;
  var rollno=document.getElementById("search_field").value;

 // alert(rollReg+"=="+att+"=="+date);
 
  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 (this.readyState==4 && this.status==200) {
      document.getElementById("att_data").innerHTML=this.responseText;
      document.getElementById("search_field").value=null;
      //alert(this.responseText);
    }
  }
  xmlhttp.open("GET","save_attendance.php?rollno="+rollno+"&att="+att+"&date="+date+"&rollReg="+rollReg,true);
  xmlhttp.send();

}


var input = document.getElementById("search_field");
input.addEventListener("keyup", function(event) {
  if (event.keyCode === 13) {
   event.preventDefault();
   //save_attendance();
   //alert("786");
  }
});


function myFunction(event) {
  var x = event.which || event.keyCode;
  
  if (x == 13) {
        save_attendance();
    }

}

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

            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;
          <a href="mark_attendance_list.php">Mark Attendance </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;       
            Mark Complete Attendance

<br><br>

          <div class="" style="background-color: white;">
           
  <section class="">
  <div class="container">
  <div class="inner_banner_bg">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <h4> Now you can mark the only absent, leave & short leave students and all other can be present on single green ' Save All Attendance' button.</h4>
    </div>
    
    <div class="clearfix"></div>
    </div>
  </div>
</section>
<br>
<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">
   <div class="box_visa_form">
    <div class="table-responsive" style="min-height:320px;padding:3%;">

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


            <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 Saved...
            </div>


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

          

              <div class="col-md-2 col-xs-9" >
                <div class="form-group ">
                    <label class="required">Attendance</label>
                    <select class="form-control" id="attendance" name="attendance"> 
                      <option value="A"> Absent </option>
                      <option value="L"> Leave </option>
                      <option value="LA"> Late </option>
                      <option value="SL"> Short Leave </option>
                    </select>
                      
                 </div>
               </div>

               <div class="col-md-2 col-xs-9" >
                <div class="form-group ">
                    <label class="required">Choose Between</label>
                    <select class="form-control" id="rollReg" name="rollReg"> 
                      <option value="RollNumber"> Roll No </option>
                      <option value="RegNo"> Adm No </option>
                    </select>
                      
                 </div>
               </div>

              <div class="col-md-3 col-xs-9" >
                <div class="form-group ">
                  <label class="required">Write Roll/Adm and Press Enter</label>
              
                <input  id="search_field" type="text" class="form-control"
                 placeholder="20-003" autocomplete="off" autofocus="1" onkeypress="myFunction(event)" value="<?php echo $_GET['qr'];?>">
                  
               </div>
             </div>

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

    

       <input type="hidden" name="action" value="MarkAllPresentAttendance">
       
              
        <div class="col-md-3 col-xs-9">
                <div class="form-group ">
                  <label class="required">Attendance Date</label>
                  <input class="form-control" type="date" name="date"  id="date"   value="<?php echo $date;?>" required>
                </div>
              </div>


             <!--  <div class="col-md-2 col-xs-9">
                <div class="form-group ">
                <label class="required" style="color:white;">Save</label>
                <input id="search_field" type="button" onclick="save_attendance();" class="btn btn-primary form-control" value="Add to List" >
                  
               </div>
             </div> -->

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

             <div class="col-md-2 col-xs-9">
                <div class="form-group ">
                <label class="required" style="color:white;">Save</label>
                <a href="send_msgs.php" class="btn btn-primary form-control">Send SMS Reporting</a>
               </div>
             </div>
             
           <?php } ?>

             <?php if (!isset($_REQUEST['saveatt'])) { ?>
               
             
             <div class="col-md-12">
              <div class="col-md-3 col-xs-9">
                <div class="form-group ">
                <label class="required">Mark as present!</label>
                <input id="search_field" type="submit" class="btn btn-success form-control" value="Save All Attendance" >
                  
               </div>
             </div>


<!--               <div class="col-md-2 col-xs-9">
                <div class="form-group ">
                <label class="required">Clear All</label>
                <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?action=ClearAttendance">
                  <input id="search_field" type="button" class="btn btn-danger form-control" value="Clear" >
                </a>  
               </div>
             </div>
 -->
             <div class="col-md-4 col-xs-9">
                <div class="form-group ">
                
                <a href="select_edit_attendance.php" class="btn btn-primary" style="margin-top: 22px;">
                  Attendance History
                </a>  

                
               </div>
             </div>

             </div>

           <?php } ?>

           
</form>

<a style="padding:7px; font-size:14px;float: right;" data-toggle="modal" data-target="#Holiday"; class="btn btn-danger"> Mark as holiday </a>

<div id="Holiday" 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;"> Mark As Holiday  </h4>
            </div>

            <div class="modal-body">




<form  action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post">

     <input type="hidden" name="action" value="MarkAllHolidayAttendance"> 
            
      <div class="col-md-12" style="padding: 8px;">

 

      <div class="form-group ">

    <label class="">Session</label>
         <select name="session" class="form-control" >

                    <!-- <option value="">All</option> -->
              

              <?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 class="form-group ">

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

          <input type="date" name="date" class="form-control"
          value="<?php echo date("Y-m-d");?>"  />
        
        </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="col-md-12">  

<br>
    <table  class="table table-striped table-bordered" id="att_data" style="width:100%;background-color:#FFFFFF; float: left;">
        <thead>
            <tr>
        
           <th width="5%">S.No</th>
            <th width="14%">RollNo / RegNo</th>
            <th width="20%">Student</th>
            <th width="20%">Class/Section</th>
            <th width="10%">Status</th>
            <th width="10%">Date</th>
            <th width="20%">Action</th>
           
                    
          </tr>
        </thead>
        <tbody>

     <tbody>   

<?php

$sql="SELECT std.student_id, std.first_name, std.last_name, std.ref_no, std.cell_no, std.status, std.branch_id, std.class_id, std.candidate_roll_no, std.section_id, std.session_id, att.*, sec.*, cl.* FROM edu_student_details as std, eduportal_attendance_temp as att, edu_class_config as cl, edu_adm_section_detail as sec where std.student_id=att.student_id and std.class_id=cl.class_id and std.section_id=sec.section_id and std.branch_id='$branch' order by att.attendance_id desc";

//print_r($sql);

$attendance_data=$m->query($sql);

//echo "===".count($attendance_data);

$count=0;

if(count($attendance_data)>0){


?>
 <?php  foreach ($attendance_data as $data) {    ?>

  <tr>
    <td   style="text-align: center;"><?php $count+=1; echo $count;?></td>
    <td><?php echo $data['candidate_roll_no']." / ".$data['ref_no'];?></td>
    <td><?php echo $data['first_name'];?></td>
    <td><?php echo $data['Class_Name'];?>/<?php echo $data['section_name'];?></td>
    <td><?php echo $data['attendance'];?></td>
    <td><?php echo date("d-M-Y",strtotime($data['date'])); ?></td>
     <td>
      
    
   <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?std=<?php echo $data['student_id'];?>&action=DeleteTempStdAtt" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

   <?php 
    if($data['attendance']=="L"){
    ?>  
      <a style="padding: 0px 5px; font-size:14px;" data-toggle="modal" data-target="#leave<?php echo $data['candidate_roll_no'];?>"  class="btn btn-success"> Leave Reason </a>
    <?php 
    } if($data['attendance']=="SL"){
    ?>

    <a style="padding: 0px 5px; font-size:14px;" data-toggle="modal" data-target="#Shortleave<?php echo $data['candidate_roll_no'];?>"  class="btn btn-success"> Short Leave Details </a>

    <?php 
    }
    ?>

    

<!-- popup to save leave reason -->

   <div id="leave<?php echo $data['candidate_roll_no'];?>" 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;">Leave reasons & history of 
                (<?php echo $data['first_name'];?>  <?php echo $data['Class_Name'];?>/<?php echo $data['section_name'];?>) </h4>
            </div>

            <div class="modal-body">



<table style="width:100%" class="table-bordered table-responsive">
  <tr>
    <th style="color: gray;">Name</th>
    <th style="color: gray;">Leave Reasone</th>
    <th style="color: gray;">Date</th>
  </tr>
 
<?php 
$branch=$_SESSION['branch'];
$StudentId=$data['student_id'];
$sessionIDs=$_SESSION['current_session'];

 $sql = "SELECT class_id, section_id, date, branch_Id, attendance, student_id  FROM  eduportal_attendance_detail  WHERE branch_Id='$branch' and attendance='L' and session_id='$sessionIDs' and student_id='$StudentId' ";
   $StudentLeaveReasone = $m->query($sql);

  foreach ($StudentLeaveReasone as $LeaveData) { 
    
        $m->where("student_id", $LeaveData['student_id']);

        $param = array('student_id','class_id','section_id','first_name','candidate_roll_no','cell_no');
        $student = $m->get("edu_student_details",null,$param);
        //$student=$m->get("edu_student_details");
  ?>
  <tr>
    <td><?php echo $student[0]['first_name'];?></td>
    <td><?php echo $LeaveData['leave_reasons'];?></td>
    <td><?php echo date("d-M-Y",strtotime($LeaveData['date'])); ?></td>
  </tr>
 <?php } ?>
</table>
<br>
<br>

<form  action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post">

           <input type="hidden" name="action" value="LeaveReasone"> 
           <input type="hidden" name="Attendance" value="L">
           <input type="hidden" id="date"  name="date" value="<?php echo $date; ?>" />
           <input type="hidden" id="" name="student_id" value="<?php echo $data['student_id'];?>" />
           <input type="hidden" id="" name="class_id" value="<?php echo $data['class_id'];?>" />
           <input type="hidden" id="" name="section_id" value="<?php echo $data['section_id'];?>" />
           <input type="hidden" id="" name="session_id" value="<?php echo $data['session_id'];?>" />                
                  <div class="col-md-12" style="padding:8px;"  id="col1">

                       <div class="form-group ">

                          <label class="required">Leave Reasons</label>
                              <textarea name="leavereasone"  id="from" value="" type="text" class="form-control"></textarea>
                       
                          </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 -->



  <!-- Student Result popup start -->
<?php 
$branch=$_SESSION['branch'];
$StudentId=$data['student_id'];
$sessionIDs=$_SESSION['current_session'];
 
 $sql = "SELECT att.class_id, att.section_id, att.date, att.branch_Id, att.attendance, att.student_id, res.* FROM  eduportal_attendance_detail as att, eduportal_students_leave_reasons as res  WHERE att.branch_Id='$branch' and att.attendance='SL' and att.session_id='$sessionIDs' and att.student_id='$StudentId' and att.attendance_id=res.attendance_id ";
    
     $StudentLeaveReasone = $m->query($sql);
?>
      <div id="Shortleave<?php echo $data['candidate_roll_no'];?>" 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;"> Reasons of Short Leave </h4>
            </div>

            <div class="modal-body">


<table style="width:100%" class="table-bordered table-responsive">
  <tr>
    <th style="color: gray;">Name</th>
    <th style="color: gray;">Short Leave Reasone</th>
    <th style="color: gray;">Date</th>
  </tr>
  <?php foreach ($StudentLeaveReasone as $LeaveData) { 
    

  ?>
  <tr>
    <td><?php echo $data['first_name'];?></td>
    <td><?php echo $LeaveData['shortleave_reason'];?></td>
    <td><?php echo date("d-M-Y",strtotime($LeaveData['date'])); ?></td>
  </tr>
 <?php } ?>
</table>

<br>
<br>

          <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="ShortLeaveReasone">
            <input type="hidden" id="" name="student_id" value="<?php echo $data['student_id'];?>" />
            <input type="hidden" name="Attendance" value="SL">
            <input type="hidden" id="date"  name="date" value="<?php echo $date; ?>" />
            <input type="hidden" id="shortL"  name="shortL" value="<?php echo $attendance_data[0]['attendance_id']; ?>" />

            <label for="gaurdian_name">Guardian Name:</label><br>
            <input class="form-control" type="text" id="" name="gaurdian_name" value=""><br>
            <label for="guardian_relation">Guardian Relation:</label><br>
            <input class="form-control" type="text" id="" name="guardian_relation" value=""><br>
            <label for="gaurdian_cell">Guardian Cell:</label><br>
            <input class="form-control" type="text" id="" name="gaurdian_cell" value=""><br>
            <label for="leave_reason">Leave Reasons:</label><br>
            <input class="form-control" type="text" id="" name="leave_reason" value=""><br>
            <label for="guardian_address">Guardian Address:</label><br>
            <input class="form-control" type="text" id="" name="guardian_address" value=""><br><br>
            <input type="submit" class="btn btn-primary" value="Submit">
          </form>

          </div>

          </div>

        </div>
      </div>

      <!-- Student result popup ending --> 




    </td>


  </tr>
 <?php 
}

}

else { ?>

  <tr> 
    <td colspan="7" style="color:red;text-align: center;"> No student added, Please enter the Reg No and click the Save button to add!</td>           
  </tr>

<?php } ?> 

        </tbody>
      </table>

</div>


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


           
          </div>
        </div>

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

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

  </body>
</html>
