<?php
$sid=$this->uri->segment('3');
$get_student_data=$this->ExamModel->get_student_data($sid);
$class='';
?>

<div class="container-fluid mt-3 mb-3">
<div class="row">
<div class="col-sm-12">

<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>NAME</th>
<!--<th>ROLL NO.</th>-->
<th>CLASS-SEC</th>
<th>SCHOLAR NO.</th>
<th>D.O.B</th>
<th>HOUSE</th>
<th>ATTENDANCE</th>
</tr>
</thead>
<tbody>
<?php 
if($get_student_data){
foreach($get_student_data as $student_data){
$class=$student_data['class'];
?>
<tr>
<td><?php echo $student_data['student_name'];?></td>

<td><?php echo $student_data['class']; echo "-"; echo $student_data['section'];?></td>
<td><?php echo $student_data['sch_no'];?></td>
<td><?php echo date('d-m-Y',strtotime($student_data['dob']));?></td>
<td><?php echo $student_data['house'];?></td>
<td>
<?php
$exam_result_data=$this->ExamModel->get_exam_result_data($sid); 
if($exam_result_data){
foreach($exam_result_data as $result_data){
$working_days=$result_data['working_days_half_yearly'];
$present_days=$result_data['attendance_day_half_yearly'];
echo  $present_days; echo " / "; echo $working_days; echo " ( ".round($present_days*100/$working_days,2)." % ) ";


}
}
?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>

<div class="alert alert-success flas_data" role="alert"></div>

<div class="table-responsive">


<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Count</th>
<th>Subject</th>
<th>Exam</th>
<th>Marks</th>
<th>Mark Attendance</th>
<th>Status</th>

</tr>
</thead>
<tbody id="student_data">
<?php
// $count=0;

// $get_subjects=$this->ExamModel->get_active_subject_data($class);
// if($get_subjects){
// foreach($get_subjects as $subjects){

// $subject_id=$subjects['id'];

// $all_heads=$this->ExamModel->get_exam_heads($class);
// if($all_heads){
// foreach($all_heads as $exam_heads){
// $no_log=0;
// $count= $count + 1;
// $ehid=$exam_heads['id'];
// $log_id='';
// $get_exam_log=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
// if($get_exam_log){
// foreach($get_exam_log as $exam_log){
// $log_id=$exam_log['id'];    
    
// }
// }else{$no_log=$no_log + 1;}

// echo "<tr>";
// echo "<td>".$count."</td>";
// echo "<td>".$subjects['subject']."</td>";
// echo "<td>".$exam_heads['exam_head']."</td>";
// echo "<td>";
// echo "<button class='btn btn-success' id='mark_present' log_id='".$log_id."' ehid='".$ehid."' sub_id='".$subject_id."' sid='".$sid."'>Present</button>";
// echo "<button class='btn btn-danger' id='mark_absent' log_id='".$log_id."' ehid='".$ehid."' sub_id='".$subject_id."' sid='".$sid."'>Absent</button>";
// echo "<button class='btn btn-warning text-white' id='mark_leave' log_id='".$log_id."' ehid='".$ehid."' sub_id='".$subject_id."' sid='".$sid."'>Med.Leave</button>";
    
// echo "</td>";
// echo "<td>";

// echo $no_log;
// $get_exam_log=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
// if($get_exam_log){
// foreach($get_exam_log as $exam_log){

// $atd=$exam_log['attendance'];
// if($atd =='A'){
// echo "<span class='btn btn-sm btn-danger'>Absent</span>";
// }else if($atd =='ML'){
// echo "<span class='btn btn-sm btn-warning'>ML</span>";
// }else if($atd =='P'){
// echo "<span class='btn btn-sm btn-success'>Present</span>";
// }

// }
// }


    
    
// echo "</td>";
// echo "</tr>";

// }
// }

// }
// }
?>
</tbody>
</table>
</div>





</div>
</div>
</div>



<script>
$(document).ready(function(){

function get_student_data(){
var sid='<?php echo $sid;?>';  
var eclass='<?php echo $class;?>';  
$.ajax({
url: '<?php echo base_url(); ?>Exam/load_students_for_attendance',
type: 'POST',
data: {sid:sid,eclass:eclass},
success: function(data){
$("#student_data").html(data);
}
});
}
get_student_data();
$(document).on("click","#mark_present",function(){
var val='P';
var log_id = $(this).attr("log_id");
var ehid = $(this).attr("ehid");
var sub_id = $(this).attr("sub_id");
var sid = $(this).attr("sid");
$.ajax({
url: '<?php echo base_url(); ?>Exam/markin',
type: 'POST',
data: { val:val,ehid:ehid,sub_id:sub_id,sid:sid,log_id:log_id},
success: function(data){
$(".flas_data").html(data);
}
});
});

$(document).on("click","#mark_absent",function(){
var val='A';
var log_id = $(this).attr("log_id");
var ehid = $(this).attr("ehid");
var sub_id = $(this).attr("sub_id");
var sid = $(this).attr("sid");
$.ajax({
url: '<?php echo base_url(); ?>Exam/markin',
type: 'POST',
data: { val:val,ehid:ehid,sub_id:sub_id,sid:sid,log_id:log_id},
success: function(data){
$(".flas_data").html(data);
}
});
});

$(document).on("click","#mark_leave",function(){
var val='ML';
var log_id = $(this).attr("log_id");
var ehid = $(this).attr("ehid");
var sub_id = $(this).attr("sub_id");
var sid = $(this).attr("sid");
$.ajax({
url: '<?php echo base_url(); ?>Exam/markin',
type: 'POST',
data: { val:val,ehid:ehid,sub_id:sub_id,sid:sid,log_id:log_id},
success: function(data){
$(".flas_data").html(data);
}
});
});

});
</script>