<?php
$sid=$this->uri->segment('3');
$class='';
$section='';
$get_student_data=$this->ExamModel->get_student_data($sid);
$acedemic_session=$this->session->userdata('acedemic_session');
$get_student_course_data=$this->ExamModel->get_student_course_info($sid,$acedemic_session);
if($get_student_course_data){
    foreach($get_student_course_data as $student_course_data){
        $class=$student_course_data['class'];
        $section=$student_course_data['section'];
    }
}
?>

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

<div class="input-section">
<h3 class="text-center">SESSION 2020 - 21</h3>
<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 $class; echo "-"; echo $section;?></td>
<td><?php echo $student_data['sch_no'];?></td>
<td><?php echo $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="table-responsive">
<table class="table table-bordered table-striped">
<thead>

<tr>

<td colspan="11" class="text-center font-weight-bold">HALF YEARLY</td>

</tr>

<tr>
<td>S. No.</td>
<th>Subjects</th>
<th>MM</th>
<?php
$get_exam_heads=$this->ExamModel->get_exam_heads($class);
if($get_exam_heads){
foreach($get_exam_heads as $exam_heads){
?>
<th><?php echo $exam_heads['exam_head']; ?></th>
<?php
}
}

?>
<th>Total (100)</th>

<th>Action</th>
</tr>
    
</thead>
<tbody>
<?php 
 
$count=0;
$total_mm=0;
$grand_total=0;

if($class !=9){
$total_mm=0;    
}else{
$total_mm=-100;    
}


$get_subjects=$this->ExamModel->get_active_subject_data($class);
if($get_subjects){
foreach($get_subjects as $subjects){
$count= $count + 1;
$subject_id=$subjects['id'];
$exam_type=$subjects['exam_type'];

// $max_marks=$subjects['MM'];
// $total_mm=$total_mm + $max_marks;

// if($subjects['subject_type'] =='main_subject'){
$max_marks=$subjects['MM'];
$total_mm=$total_mm + $max_marks;
// }

?>
<tr>
<td><?php echo $count; ?></td>
    
<td><?php echo $subjects['subject']; ?></td>
<td><?php  if($exam_type=='marks'){echo $subjects['MM']; }
// else if($exam_type=='grade'){echo "Grd";}
?>
</td>
<?php 
$all_heads=$this->ExamModel->get_exam_heads($class);
if($all_heads){
foreach($all_heads as $exam_heads){
$exam_head_id=$exam_heads['id'];
$student_log_data=$this->ExamModel->student_exam_log($sid,$exam_head_id,$subject_id);
if($student_log_data){
foreach($student_log_data as $student_log){

?>
<td><?php  if($exam_type=='marks'){echo $student_log['obtained_marks']; }else if($exam_type=='grade'){echo "<span class='text-uppercase'>".$student_log['grade']."</span>";}?></td>



<?php
}
}else{
?>
<td>...</td>
<?php
}

}
}

?>
<td>
<?php
$total=0;
if($all_heads){
foreach($all_heads as $exam_heads){
$ehid=$exam_heads['id'];

$get_all_marks_total_data=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
if($get_all_marks_total_data){
foreach($get_all_marks_total_data as $total_data){
$total = $total + $total_data['obtained_marks'];
}
}

}
}
if($exam_type=='marks'){
echo  $total;
$grand_total=$grand_total + $total;



}
?>      
</td>
<td><a href="<?php echo base_url();?>Exam/add_exam_log/<?php echo $sid; echo "/"; echo $subjects['id']; ?>" class="btn btn-sm btn-warning">Edit</a></td>
</tr>
<?php
}
}
?>    
<tr>
<td colspan="2"></td>
<td><?php  echo $total_mm; ?></td>
<td colspan="6"></td>
<td><?php echo $grand_total; echo "("; echo round(($grand_total * 100)/$total_mm,2); echo "%)"; ?></td>
<td></td>
</tr>   
</tbody>
</table>
</div>


</div>

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

