<?php
$sid=$this->uri->segment('3');
$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'];
    }
}
// $class='';
?>

<div class="container-fluid">
    <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 $class; echo "-"; echo $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){
if($result_data['result_type'] == 'yearly'){

$working_days=$result_data['annual_working_days'];
$present_days=$result_data['annual_attendance'];
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 style="font-size:12px;">
                            <td>S. No.</td>
                            <th>Subjects</th>
                            <th>MM</th>
                            <th>Half Yearly Marks</th>
                            <?php
                            $get_exam_heads=$this->ExamModel->get_exam_heads($class);
                            if($get_exam_heads){
                                foreach($get_exam_heads as $exam_heads){
                                    // if($exam_heads['exam_mode'] !=''){
                                if($exam_heads['mm'] ==0 ||  $exam_heads['mm'] ==50){
                            ?>
                            <?php
                            }else{
                            ?>
                            <th><?php echo $exam_heads['exam_head']; ?></th>
                            <?php       
                                }
                                    
                                }
                            }
                            ?>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $count=0;
                        $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'];
                                ?>
                                <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>
                                    <td></td>
                                    <?php 
                                    $all_heads=$this->ExamModel->get_exam_heads($class);
                                    if($all_heads){
                                        foreach($all_heads as $exam_heads){
                                            // if($exam_heads['exam_mode'] !=''){
                                                if($exam_type == 'marks' && $exam_heads['mm'] !=0 &&  $exam_heads['mm'] !=50){
                                                    $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 echo $student_log['obtained_marks']; ?>
                                                            </td>
                                                            <?php
                                                        }
                                                    }else{
                                                        ?>
                                                        <td>... <?php echo $sid; echo "/"; echo $exam_head_id; echo "/"; echo $subject_id; ?></td>        
                                                        <?php
                                                        }
                                                }else if($exam_type == 'grade' && $exam_heads['mm'] !=0 &&  $exam_heads['mm'] !=50){
                                                    echo "<td></td>";
                                                    }

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