<?php
$course_id=$this->uri->segment('3');
$acedemic_session=$this->session->userdata('acedemic_session');

$get_students_in_alpha_order=$this->NewExamModel->get_students_in_alpha_order();

?>
<div class="container-fluid mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3 ">
            
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Examination">Exam</a></li>
                <li class="breadcrumb-item">All Courses</li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Roll No.</th>
                            <th>Name</th>
                            <th>Father's Name</th>
                            <th>MM/Obtained</th>
                            <th>%</th>
                            <th>Exams</th>
                            <th>Result</th>
                            <td>Subjects</td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $count=0;
                        if($get_students_in_alpha_order){
                            foreach($get_students_in_alpha_order as $students){
                                $sid=$students['id'];
                                $check_student_exist=$this->NewExamModel->student_course_data($course_id,$sid,$acedemic_session);
                                if($check_student_exist){
                                    foreach($check_student_exist as $student_exist){
                                        $count=$count + 1;
                                        $exam_id=3;
                                    
                                    $exam_result_table="exam_result";
                                    $get_student_exam_result=$this->NewExamModel->student_result($sid,$acedemic_session,$exam_id,$course_id,$exam_result_table);
                                    
                                    
                                    $mm_marks=0;
                                    $obtained_marks=0;
                                    $percentage=0;
                                    if($get_student_exam_result){
                                    foreach($get_student_exam_result as $exam_result){
                                    $mm_marks=$exam_result['MM'];
                                    $obtained_marks=$exam_result['total_obtained_marks'];
                                    $percentage=$exam_result['percentage'];
                                    }
                                    }
                        ?>
                        <tr>
                            <td><?php echo $count;?></td>
                            <td><?php echo $student_exist['roll_no']; ?></td>
                            <td><?php echo $students['student_name'];?></td>
                            <td><?php echo $students['father_name'];?></td>
                            
                            <td><?php echo $mm_marks."/".$obtained_marks; ?></td>
                            <td><?php echo $percentage; ?>%</td>
                            
                            <td><a href="<?php echo base_url();?>Examination/exam_log/<?php echo $sid; ?>" target="_blank">View</a></td>
                            <td>
                                <a href="<?php echo base_url();?>Report/report_card_without_head/<?php echo $sid; ?>" target="_blank" class="btn btn-sm btn-info">Card 1</a>
                                
                                <a href="<?php echo base_url();?>Report/report_card/<?php echo $sid; ?>" target="_blank" class="btn btn-sm btn-info ml-3">Card 2</a>
                            </td>
                            <td><a href="<?php echo base_url();?>Examination/student_subjects/<?php echo $sid; ?>" class="btn btn-primary btn-sm" target="_blank">View</a></td>
                        </tr>                        
                        <?php    
                                    }
                                }
                            }
                        }
                        ?>

                    </tbody>
                </table>
            </div>
            
        </div>
    </div>
</div>