<?php
$exam_id=$this->uri->segment('3');
$exam_shift_table='exam_shift';
$get_exam_shift_data=$this->NewExamModel->exam_data($exam_id,$exam_shift_table);
?>

<div class="container mt-3 mb-3 pt-3 pb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">
            <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">Schedule</li>
            </ul>
            <a href="<?php echo base_url();?>Examination/add_new_exam_schedule/<?php echo $exam_id; ?>" class="btn btn-sm btn-info mb-3">Add New Exam Schedule</a>
            <a href="<?php echo base_url();?>Examination/exam_dates/<?php echo $exam_id;?>" class="btn btn-sm btn-primary mb-3">Exam Dates</a>
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Date</th>
                            <?php
                            if($get_exam_shift_data){
                                foreach($get_exam_shift_data as $exam_shift_data){
                            ?>
                            <th><?php echo $exam_shift_data['start_time']; echo " "; echo $exam_shift_data['end_time'];?></th>
                            <?php
                                }
                            }
                            
                            ?>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $exam_date_table='exam_date';
                        $all_exam_date=$this->NewExamModel->exam_data($exam_id,$exam_date_table);
                        if($all_exam_date){
                            foreach($all_exam_date as $exam_date_info){
                        ?>
                        <tr>
                            
                            <td><?php echo date('d-M-Y',strtotime($exam_date_info['exam_date']));?></td>
                            <?php
                            if($get_exam_shift_data){
                                foreach($get_exam_shift_data as $exam_shift_data){
                            ?>
                            <td>
                            
                            <?php 
                            $exam_date_id=$exam_date_info['id'];
                            $get_exam_schedule=$this->NewExamModel->get_exam_schedule($exam_id,$exam_shift_data['id'],$exam_date_id);
                            if($get_exam_schedule){
                                foreach($get_exam_schedule as $exam_schedule_data){
                                    $course_id=$exam_schedule_data["course_id"];
                            ?>
                            
                                <p class=""><?php echo $exam_schedule_data['exam_paper_name']; echo " ( "; 
                                $course_table='courses';
                                $get_course_info=$this->NewExamModel->get_item_data($course_id,$course_table);
                                if($get_course_info){
                                    foreach($get_course_info as $course_info){
                                        echo $course_info['course']; echo " "; echo $course_info['subject_stream'];
                                    }
                                }
                                echo " ) ";
                                ?></p>
                            
                            <?php
                                }
                            }
                            ?>    
                            
                                
                            </td>
                            <?php
                                }
                            }
                            ?>
                        </tr>    
                        <?php
                        
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
            </div>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Exam</th>
                            <th>Course</th>
                            <th>Exam Paper</th>
                            <th>Exam Date</th>
                            <th>Exam Timing</th>
                            <th>Update</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $exam_schedule_table='exam_schedule';
                        $count=0;
                        $all_exam_schedule=$this->NewExamModel->exam_data($exam_id,$exam_schedule_table);
                        if($all_exam_schedule){
                            foreach($all_exam_schedule as $exam_schedule){
                                $count=$count + 1;
                        ?>
                        <tr>
                            <td><?php echo $count;?></td>
                            <?php
                            $exam_table='all_exams';
                            $get_exam_info=$this->NewExamModel->get_item_data($exam_id,$exam_table);
                            if($get_exam_info){
                                foreach($get_exam_info as $exam_info){
                            ?>
                            <td><?php echo $exam_info['exam_title'];?></td>
                            <?php
                                }
                            }
                            ?>
                            
                            <?php
                            $courses_table='courses';
                            
                            $get_course_info=$this->NewExamModel->get_item_data($exam_schedule['course_id'],$courses_table);
                            if($get_course_info){
                                foreach($get_course_info as $course_info){
                            ?>
                            <td><?php echo $course_info['course']; echo " "; echo $course_info['subject_stream'];?></td>
                            <?php
                                }
                            }else{
                            ?>
                            <td>--</td>
                            <?php
                            }
                            ?>
                            
                            
                            <td><?php echo $exam_schedule['exam_paper_name'];?></td>
                            <td><?php if($exam_schedule['exam_date']){echo date('d-M-Y',strtotime($exam_schedule['exam_date']));}else{echo "--";}?></td>
                            <td><?php echo $exam_schedule['exam_start_time']; echo " <b class='text-danger'> to </b> "; echo $exam_schedule['exam_end_time'];?></td>
                            <td><a href="<?php echo base_url();?>Examination/update_exam_schedule/<?php echo $exam_schedule['id'];?>" class="btn btn-sm btn-warning text-white">Update</a></td>
                            <td>
                                <?php
                                if($exam_schedule['status'] == 1){
                                ?>
                                <button class="btn btn-sm btn-success status-btn" db_id="<?php echo $exam_schedule['status'];?>">Active</button>
                                <?php
                                }else{
                                ?>
                                <button class="btn btn-sm btn-danger status-btn" db_id="<?php echo $exam_schedule['status'];?>">Inactive</button>
                                <?php
                                }
                                ?>
                                
                            </td>
                        </tr>                        
                        <?php
                            }
                        }
                        ?>

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