<?php 
$acedemic_session=$this->session->userdata('acedemic_session');
$get_active_sch_data=$this->TimeTableModel->get_active_sch_data($acedemic_session);
$sch_id="";
if($get_active_sch_data){
    foreach($get_active_sch_data as $sch_data_1){
        $sch_id=$sch_data_1['id'];
    }
}



$tid=$this->session->userdata("tid");

$staff_table="school_staff";
$get_staff_data=$this->TimeTableModel->get_item_data($tid,$staff_table);
if($get_staff_data){
    foreach($get_staff_data as $staff_data){
?>


<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">
                    Time Table
                </li>
                
                <li class="breadcrumb-item"><?php echo $staff_data['salutation']." ".$staff_data['name']; ?></li>
            </ul>
            <!--<p class="main-heading"><?php echo $staff_data['salutation']." ".$staff_data['name']; ?></p>-->
            <p>
                <a href="<?php echo base_url().'TimeTableManagement/time_table_pdf/'.$tid.'/'.$sch_id; ?>" target="_blank" class="btn btn-sm btn-outline-info">
                    Download&nbsp;
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
                        <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
                        <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
                    </svg>
                </a>
            </p>
            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead>
                        
                        <tr>
                            <th>Day</th>
                            <?php 
                            $p_count=0;
                            $periods_table="time_table_periods";
                            $all_periods=$this->TimeTableModel->get_schedule_periods($sch_id,$periods_table);
                            if($all_periods){
                            foreach($all_periods as $periods){
                                $p_count=$p_count + 1;
                            ?>
                            <th class="text-center">
                                <?php echo $periods['period']; ?>
                                <br>
                                <?php echo "(".date('h:i:sa',strtotime($periods['start_time']))."<br>".date('h:i:sa',strtotime($periods['end_time'])).")"?>
                            </th>
                            <?php
                                }
                            }
                            ?>
                            
                        </tr>
                        
                    </thead>
                    <tbody>
                        <?php
                        $acedemic_session=$this->session->userdata('acedemic_session');
                        ?>
                        <tr>
                            <th>Mon</th>
                            
                            <?php
                            if($all_periods){
                                foreach($all_periods as $periods){
                                    echo "<td class='text-center'>";
                                    $period=$periods['id'];
                                    $week_day_1="MON";
                                    $get_teacher_day_schedule=$this->TimeTableModel->get_teacher_day_schedule_comb($tid,$sch_id,$week_day_1,$period);
                                    if($get_teacher_day_schedule){
                                        foreach($get_teacher_day_schedule as $sch_data){
                                            
                                            echo $sch_data['class']."-".$sch_data['section']."<br>";
                                            echo $sch_data['subject'];
                                        }
                                    }
                            echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        <tr>
                            <th>Tue</th>
                            <?php
                            if($all_periods){
                                foreach($all_periods as $periods){
                                    echo "<td class='text-center'>";
                                    $period=$periods['id'];
                                    $week_day_1="TUE";
                                    $get_teacher_day_schedule=$this->TimeTableModel->get_teacher_day_schedule_comb($tid,$sch_id,$week_day_1,$period);
                                    if($get_teacher_day_schedule){
                                        foreach($get_teacher_day_schedule as $sch_data){
                                            
                                            echo $sch_data['class']."-".$sch_data['section']."<br>";
                                            echo $sch_data['subject'];
                                        }
                                    }
                            echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        <tr>
                            <th>Wed</th>
                            <?php
                            if($all_periods){
                                foreach($all_periods as $periods){
                                    echo "<td class='text-center'>";
                                    $period=$periods['id'];
                                    $week_day_1="WED";
                                    $get_teacher_day_schedule=$this->TimeTableModel->get_teacher_day_schedule_comb($tid,$sch_id,$week_day_1,$period);
                                    if($get_teacher_day_schedule){
                                        foreach($get_teacher_day_schedule as $sch_data){
                                            
                                            echo $sch_data['class']."-".$sch_data['section']."<br>";
                                            echo $sch_data['subject'];
                                        }
                                    }
                            echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        <tr>
                            <th>Thu</th>
                            <?php
                            if($all_periods){
                                foreach($all_periods as $periods){
                                    echo "<td class='text-center'>";
                                    $period=$periods['id'];
                                    $week_day_1="THU";
                                    $get_teacher_day_schedule=$this->TimeTableModel->get_teacher_day_schedule_comb($tid,$sch_id,$week_day_1,$period);
                                    if($get_teacher_day_schedule){
                                        foreach($get_teacher_day_schedule as $sch_data){
                                            
                                            echo $sch_data['class']."-".$sch_data['section']."<br>";
                                            echo $sch_data['subject'];
                                        }
                                    }
                            echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        <tr>
                            <th>Fri</th>
                            <?php
                            if($all_periods){
                                foreach($all_periods as $periods){
                                    echo "<td class='text-center'>";
                                    $period=$periods['id'];
                                    $week_day_1="FRI";
                                    $get_teacher_day_schedule=$this->TimeTableModel->get_teacher_day_schedule_comb($tid,$sch_id,$week_day_1,$period);
                                    if($get_teacher_day_schedule){
                                        foreach($get_teacher_day_schedule as $sch_data){
                                            
                                            echo $sch_data['class']."-".$sch_data['section']."<br>";
                                            echo $sch_data['subject'];
                                        }
                                    }
                            echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        <tr>
                            <th>Sat</th>
                            <?php
                            if($all_periods){
                                foreach($all_periods as $periods){
                                    echo "<td class='text-center'>";
                                    $period=$periods['id'];
                                    $week_day_1="SAT";
                                    $get_teacher_day_schedule=$this->TimeTableModel->get_teacher_day_schedule_comb($tid,$sch_id,$week_day_1,$period);
                                    if($get_teacher_day_schedule){
                                        foreach($get_teacher_day_schedule as $sch_data){
                                            
                                            echo $sch_data['class']."-".$sch_data['section']."<br>";
                                            echo $sch_data['subject'];
                                        }
                                    }
                            echo "</td>";
                                }
                            }
                            ?>
                        </tr>
                        
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<?php
    }
}
?>