<?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 date=document.getElementById("date").value;
  var rollno=document.getElementById("search_field").value;

 // alert(rollno+"=="+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;
      //alert(this.responseText);
    }
  }
  xmlhttp.open("GET","save_attendance.php?rollno="+rollno+"&att="+att+"&date="+date,true);
  xmlhttp.send();

}


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



</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">
          <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 'Complete Save 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']); }
          ?>

<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-2 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">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-3 col-xs-9" >
                <div class="form-group ">
                  <label class="required">Enter Student Reg No/Roll No</label>
              
                <input  id="search_field" type="text" class="form-control"
                 placeholder="20-003" autocomplete="off" autofocus="1" value="<?php echo $_GET['qr'];?>">
                  
               </div>
             </div>



              <div class="col-md-1 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="Save" >
                  
               </div>
             </div>


              <div class="col-md-3 col-xs-9">
                <div class="form-group ">
                <label class="required">Mark others as present!</label>
                <input id="search_field" type="submit" class="btn btn-success form-control" value="Mark All as Present" >
                  
               </div>
             </div>


              <div class="col-md-1 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>

           
</form>


 <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="10%">Reg No</th>
            <th width="20%">Student</th>
            <th width="20%">Class/Section</th>
            <th width="10%">Status</th>
            <th width="15%">Date</th>
            <th width="20%">Action</th>
                    
          </tr>
        </thead>
        <tbody>

     <tbody>   

<?php

$sql="SELECT * 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'];?></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 style="padding: 0px 5px; font-size:14px;" data-toggle="modal" data-target="#DeleteStudent"  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'];
$session=$_SESSION['current_session'];

 $sql = "SELECT * FROM  eduportal_attendance_detail  WHERE branch_Id='$branch' and attendance='L' and session_id='$session' and student_id='$StudentId' ";
   $StudentLeaveReasone = $m->query($sql);

  foreach ($StudentLeaveReasone as $LeaveData) { 
    
        $m->where("student_id", $LeaveData['student_id']);
        $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'];
$session=$_SESSION['current_session'];
 
 $sql = "SELECT * 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='$session' 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>
