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

//echo $_GET['rollReg']."/".$_REQUEST['rollno'];

	if($_GET["rollReg"]=="RollNumber") {
  
  $m->where ("candidate_roll_no", $_REQUEST['rollno']);
  $m->where("status", 0);
  $m->where("branch_id", $_SESSION['branch']);
  $Id = $m->get("edu_student_details");
//echo "R";
} else {
//echo "A";
  $m->where ("ref_no", $_REQUEST['rollno']);
  $m->where("status", 0);
  $m->where("branch_id", $_SESSION['branch']);
  $Id = $m->get("edu_student_details");

}
	//print_r($Id);
	
	// delete the old attendance of this student if already saved
	$m->where ("student_id", $Id[0]['student_id']);
	$m->where("date", $_REQUEST['date']);
	$m->where("branch_Id", $_SESSION['branch']);
	$m->delete("eduportal_attendance_temp");


	$data = array(
	'student_id' => $Id[0]['student_id'],
	'attendance' => $_REQUEST['att'],
	'class_id' => $Id[0]['class_id'],
	'section_id' => $Id[0]['section_id'],
	'date' => $_REQUEST['date'],
	'branch_Id' => $_SESSION['branch'],
	'session_id' => $_SESSION['current_session']
	);

	$result = $m->insert('eduportal_attendance_temp',$data);

$branchID=$_SESSION['branch'];
$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 att.branch_Id='$branchID' order by att.attendance_id desc";

$attendance_data=$m->query($sql);
//	echo "<pre>"; print_r($data); echo "</pre>"."<br>";

$count=0;
?>

<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%">Roll/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  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'];
$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'];?>" />                
                  <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; ?>" />

            <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 } ?>

  
        </tbody>
      </table>




