<?php 
$academic_session=$this->session->userdata("acedemic_session");
$ehid=$this->uri->segment("3");
$table="exam_head_master_".$academic_session;
$get_exam_head_information=$this->ExamManagementModel->get_item_data($ehid,$table);
if($get_exam_head_information){
    foreach($get_exam_head_information as $eh_data){
        $class=$eh_data["class"];
        $sch_table="exam_schedule";
        $get_class_exam_schedule=$this->ExamManagementModel->get_class_exam_schedule($class,$ehid,$sch_table);
        $exam_id=$eh_data['exam_id'];
?>
<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(); ?>ExamManagement">Examination</a>
                </li>
                <li class="breadcrumb-item">Schedule</li>
                <li class="breadcrumb-item"><?php echo $eh_data['exam_head']; ?></li>
                <li class="breadcrumb-item">Class : <?php echo $class; ?></li>
            </ul>
            <form method="post" action="#">
                <input type="hidden" name="exam_head" value="<?php echo $ehid; ?>">
                <input type="hidden" name="academic_session" value="<?php echo $academic_session; ?>">
                <input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>">
                <input type="hidden" name="class" value="<?php echo $class; ?>">
                <div class="table-responsive">
                    <table class="table table-bordered table-striped" id="">
                        <thead>
                            <tr>
                                <th class="sl_no">Sl. No.</th>
                                <th>Subject</th>
                                <th>Date</th>
                                <th>Start Time</th>
                                <th>End Time</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                        $i=0;
                        $exam_subjects_table="exam_subject_master_".$academic_session;
                        $all_subjects=$this->ExamManagementModel->get_class_subjects($class,$academic_session,$exam_subjects_table);
                        if($all_subjects){
                            foreach($all_subjects as $subjects){
                                $i++;
                                $subject_id=$subjects['id'];
                                $exam_date="";
                                $exam_start_time="";
                                $exam_end_time="";
                                if($get_class_exam_schedule){
                                    foreach($get_class_exam_schedule as $ceschd){
                                        if($ceschd['subject_id'] == $subject_id){
                                            $exam_date=$ceschd["exam_date"];
                                            $exam_start_time=$ceschd["exam_start_time"];
                                            $exam_end_time=$ceschd["exam_end_time"];
                                        }
                                    }
                                }
                        ?>
                        <tr>
                            <td><?php echo $i; ?></td>
                            <td><?php echo $subjects['subject']; ?></td>
                            <td>
                                <input type="hidden" name="exam[subject_id][<?php echo $subject_id; ?>]" value="<?php echo $subject_id; ?>">
                                <input type="date" class="form-control" name="exam[date][<?php echo $subject_id; ?>]" value='<?php if($exam_date !=""){ echo $exam_date; }else{ echo set_value("exam[date][".$subject_id."]"); } ?>'>
                                
                            </td>
                            <td>
                                <input type="time" class="form-control" name="exam[start_time][<?php echo $subject_id; ?>]" value='<?php if($exam_start_time !=""){ echo $exam_start_time; }else{ echo set_value("exam[start_time][".$subject_id."]"); } ?>'>
                            </td>
                            <td>
                                <input type="time" class="form-control" name="exam[end_time][<?php echo $subject_id; ?>]" value='<?php if($exam_end_time !=""){ echo $exam_end_time; }else{ echo set_value("exam[end_time][".$subject_id."]"); } ?>'>
                            </td>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                            <tr>
                                <td colspan="5" style="text-align:right;">
                                    <a href="#" class="btn btn-outline-danger">Print</a>&nbsp;&nbsp;
                                        <button class="btn btn-success" name="update_exam_schedule">Submit</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <!--<div class="form-group"></div>-->
            </form>
            <?php 
            $get_class_sections=$this->ExamManagementModel->get_class_sections($class,$academic_session);
            ?>
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>Sl.No.</th>
                                <th>Clas Teacher</th>
                                <th>Section</th>
                                <th>Students</th>
                                <th>Admit Card New</th>
                                <th>Admit Card Old</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            $ii=0;
                            if($get_class_sections){
                                foreach($get_class_sections as $sections){
                                    $ii=$ii + 1;
                            
                            ?>
                            <tr>
                                <td><?php echo $ii; ?></td>
                                <td><?php echo $sections['salutation']." ".$sections['name']; ?></td>
                                <td><?php echo $sections['class']."-".$sections['section']; ?></td>
                                
                                <td>
                                    <a href="<?php echo base_url(); ?>ExamManagement/class_section_students/<?php echo $sections['class']."/".$sections['section']; ?>" class="btn btn-sm btn-outline-info" target="_blank">View</a>
                                </td>
                                <td>
                                    <a href="<?php echo base_url(); ?>ExamManagement/course_admit_card/<?php echo $ehid."/".$class."/".$sections['section']; ?>" class="btn btn-sm btn-outline-danger" target="_blank">Print</a>
                                </td>
                                
                                <td>
                                    <a href="<?php echo base_url(); ?>ExamManagement/course_admit_card_old/<?php echo $ehid."/".$class."/".$sections['section']; ?>" class="btn btn-sm btn-outline-danger" target="_blank">Print</a>
                                </td>
                            </tr>
                            <?php 
                            
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                </table>
            </div>
        </div>
    </div>
</div>
<?php
    }
}
?>