<?php 
$id=$this->uri->segment("3");
$table="time_table";
$get_time_table_data=$this->TimeTableModel->get_item_data($id,$table);
if($get_time_table_data){
    foreach($get_time_table_data as $data){
?>
<div class="container-fluid mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <div class="">
                <table class="table table-bordered" style="width:100%">
                    <thead>
                        <tr>
                            <th rowspan="3">Class</th>
                            <?php 
                            $p_count=0;
                            $periods_table="time_table_periods";
                            $all_periods=$this->TimeTableModel->get_schedule_periods($id,$periods_table);
                            if($all_periods){
                            foreach($all_periods as $periods){
                                $p_count=$p_count + 1;
                            ?>
                            <th class="text-center"><?php echo $periods['period']; ?></th>
                            <?php
                                }
                            }
                            ?>
                            
                        </tr>
                        <tr>
                            <?php 
                            $p_count=0;
                            $periods_table="time_table_periods";
                            $all_periods=$this->TimeTableModel->get_schedule_periods($id,$periods_table);
                            if($all_periods){
                            foreach($all_periods as $periods){
                                $p_count=$p_count + 1;
                            ?>
                            <th class="text-center"><?php echo date('h : i : s a',strtotime($periods['start_time'])); ?></th>
                            <?php
                                }
                            }
                            ?>
                        </tr>
                        
                        <tr>
                            <?php 
                            $p_count=0;
                            $periods_table="time_table_periods";
                            $all_periods=$this->TimeTableModel->get_schedule_periods($id,$periods_table);
                            if($all_periods){
                            foreach($all_periods as $periods){
                                $p_count=$p_count + 1;
                            ?>
                            <th class="text-center"><?php echo date('h : i : s a',strtotime($periods['end_time'])); ?></th>
                            <?php
                                }
                            }
                            ?>
                        </tr>
                        
                    </thead>
                    <tbody>
                        <?php
                        $acedemic_session=$this->session->userdata('acedemic_session');
                        $all_classes=$this->TimeTableModel->get_classes_structre($acedemic_session);
                        if($all_classes){
                            foreach($all_classes as $classes){
                                $class=$classes['class'];
                                $section=$classes['section'];
                                
                        ?>
                        <tr>
                            <th><?php echo $classes['class']."-".$classes['section']; ?></th>
                            
                            <?php 
                            $all_periods=$this->TimeTableModel->get_schedule_periods($id,$periods_table);
                            if($all_periods){
                            foreach($all_periods as $periods){
                                echo "<td>";
                                $period=$periods['id'];
                                $get_class_section_record=$this->TimeTableModel->get_class_section_record($id,$class,$section,$period);
                                if($get_class_section_record){
                                    foreach($get_class_section_record as $sch_data){
                                        echo $sch_data['week_day']." : ";
                                        echo $sch_data['salutation']." ".$sch_data['name']."<sub>(".$sch_data['subject'].")</sub><br>";
                                        
                                    }
                                }else{
                                    echo "---";
                                }
                            
                                echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
            </div>
            
        </div>
    </div>
</div>
<?php 
    }
}
?>