<?php
$class=$this->uri->segment('3');
$section=$this->uri->segment('4');
$acedemic_session=$this->session->userdata('acedemic_session');
$all_students=$this->NewExamModel->get_students_ac_session_by_course_and_class($acedemic_session,$class,$section);
?>

<div class="container 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/all_classes">All Courses</a>
                </li>
                <li class="breadcrumb-item"><?php echo $class; ?></li>
                <li class="breadcrumb-item"><?php echo $section; ?></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>Rank</th>
                            <th>Status</th>
                            <th>Exam</th>
                            <th>Result</th>
                            <th>Subjects</th>
                            <th>Second Term Report Card</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $scount=0;
                    $exam_id=3;
                    if($all_students){
                        foreach($all_students as $data){
                            $sid=$data['sid'];
                            $student_table='student';
                            $get_student_data=$this->NewExamModel->get_item_data($sid,$student_table);
                            if($get_student_data ){
                                foreach($get_student_data as $students){
                                    if($students['status'] ==1){
                                        $roll_no="";
                                        $scount++;
                                        $exam_result_table="exam_result";
                                        $get_student_exam_result=$this->NewExamModel->student_result_data($sid,$acedemic_session,$exam_id,$exam_result_table);
                                    
                                    
                                    $mm_marks=0;
                                    $obtained_marks=0;
                                    $percentage=0;
                                    $rank_in_class="";
                                    if($get_student_exam_result){
                                    foreach($get_student_exam_result as $exam_result){
                                        $roll_no=$exam_result['roll_no'];
                                    $mm_marks=$exam_result['MM'];
                                    $obtained_marks=$exam_result['total_obtained_marks'];
                                        $percentage=$exam_result['percentage'];
                                        $rank_in_class=$exam_result['rank_in_class'];
                                    }
                                    }
                        ?>
                        <tr>
                            <td><?php echo $scount; ?></td>
                            <td><?php echo $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><?php echo $rank_in_class; ?></td>
                            <td>
                            <?php
                            if($exam_result['result_status'] = "Pass"){
                                echo $exam_result['result_status'];
                                
                            }else{
                                echo $exam_result['result_status']."-".$exam_result['no_of_failure_subjects'];
                            }
                            ?></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>
                            <td class="text-center">
                                <a href="<?php echo base_url()."Report/annual_report_card/".$sid; ?>" target="_blank" class="btn btn-outline-info">Card 1</a>&nbsp;&nbsp;&nbsp;&nbsp;
                                
                                <a href="<?php echo base_url()."Report/annual_report_card_1/".$sid; ?>" target="_blank" class="btn btn-outline-info">Card 2</a>
                            </td>
                        </tr>
                        <?php
                                    }
                                }
                            }
                        }
                    }
                    ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

