# wpschoolpress/2.2.43/includes/wpsp-viewTimetable.php

School Management System – WPSchoolPress, version 2.2.43. 143 lines.

- Page: https://pluginprobe.com/plugins/wpschoolpress/2.2.43/code/includes/wpsp-viewTimetable.php
- Raw: https://pluginprobe.com/plugins/wpschoolpress/2.2.43/raw/includes/wpsp-viewTimetable.php
- Modified: 2025-11-04T05:58:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpschoolpress/2.2.43/code/includes/wpsp-viewTimetable.php#L10-L20`.

```php
<?php
if (!defined( 'ABSPATH' ) )exit('No Such File');
function wpsp_ViewTimetable($class_id){
        global $wpdb;
        $tt_table = $wpdb->prefix . "wpsp_timetable";
        $subject_table = $wpdb->prefix . "wpsp_subject";
        $wpsp_hours_table = $wpdb->prefix . "wpsp_workinghours";
      //  $get_heading = $wpdb->get_row("SELECT * from $tt_table where class_id='".esc_sql($class_id)."' and heading != ' ' ");
        $get_heading = $wpdb->get_row($wpdb->prepare("SELECT * FROM $tt_table WHERE class_id = %d and heading != %s",$class_id,''));
        $response   =   array();
        ob_start();
        if ($get_heading == null) {
            echo '<section class="content">
                    <div class="wpsp-text-red">Timetable Has Not Created For This Class.</div>
                </section> </div></div>';
            $response['status'] =   1;
        } else {
            $response['status'] =   2;
            $session = unserialize($get_heading->heading);
            $tt_query = $wpdb->prepare("SELECT * FROM $tt_table WHERE class_id = %d",$class_id);
            $tt_days=$wpdb->get_results($tt_query,ARRAY_A);
            foreach($tt_days as $ttd){
                $timetable[$ttd['day']][$ttd['time_id']]=$ttd['subject_id'];
            }
            $ses_info = $wpdb->get_results("Select * from $wpsp_hours_table");
            foreach($ses_info as $time){
                $period_times[$time->id]=array('start'=>$time->begintime,'end'=>$time->endtime,'type'=>$time->type);
            }
            ?>
             <section>

                <div class="wpsp-row">
                    <div class="wpsp-col-md-12">
                    <table class="wpsp-table wpsp-table-bordered"  id="timetable_table" cellspacing="0" width="100%" style="width:100%">
                        <thead>
                            <tr>
                                <th><?php esc_html_e( 'Week', 'wpschoolpress' ); ?></th>
                                <?php foreach ($session as $sess) { ?>
                                    <th><?php echo isset( $period_times[$sess]['start'] ) ? esc_html($period_times[$sess]['start']) :'';
                                            echo " - " ;
                                            echo isset( $period_times[$sess]['end'] ) ? esc_html($period_times[$sess]['end']) :''; ?></th>
                                    <?php
                                }
                                ?>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $week_days=array('1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday','7'=>'Sunday');
                            $leave_table = $wpdb->prefix . "wpsp_leavedays";
                          //  $check      =   $wpdb->get_row("select description from $leave_table where class_id='" . esc_sql($class_id) . "'");
                            $check = $wpdb->get_row($wpdb->prepare("SELECT description FROM $leave_table WHERE class_id = %s",$class_id));
                            $wd = explode(',', $check->description);
                            for ($j = 1; $j <= 7; $j++) {
                                 /* Sat-sun Off */
                                if (!empty($check)) {
                                    if ($wd[0] == $week_days[$j]) {
                                        continue;
                                    }
                                    if (isset($wd[1])) {
                                        if ($wd[1] == $week_days[$j]) {
                                            continue;
                                        }
                                    }
                                } /* Sat-sun Off */
                                if(empty($timetable[$j])){
                                    continue;
                                }
                            ?>
                                <tr id="<?php echo esc_attr($j); ?>">
                                    <td><span class="daynam"><?php echo esc_attr($week_days[$j]);?></span></td>
                                    <?php
                                    $subida = array();
                                    $subida1 = array();
                                    $subtimesloat = array();

                                   // $get_heading = $wpdb->get_results("SELECT * from $tt_table where class_id='".esc_sql($class_id)."' and day = '$j' ORDER BY session_id ASC");
                                    $get_heading = $wpdb->get_results($wpdb->prepare("SELECT * FROM $tt_table WHERE class_id = %s and day = %s ORDER BY session_id ASC",$class_id,$j));

                                    foreach ($get_heading as $subid){
                                        $subida[] = $subid->subject_id;
                                        $subtimesloat[] = $subid->time_id;
                                        $subida1[] = $subid->is_active;
                                        reset($subida);
                                        reset($subida1);
                                        reset($subtimesloat);
                                    }
                                    $pa = 0;
                                    foreach($session as $ses){
                                        if($ses != $subtimesloat[$pa]){
                                         //   $hour_det	=	$wpdb->get_row("Select * from $wpsp_hours_table where id='$ses'");
                                            $hour_det = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpsp_hours_table WHERE id = %s ",$ses));
                                                $brk	=	$hour_det->type == "0" ? "Break" : "";
                                                ?>
                                                <td class = "<?php echo esc_attr($ses); ?> " tid="<?php echo esc_attr($subida[$pa]); ?>" data-sessionid="<?php echo esc_attr($key); ?>"> 
                                                <?php echo $brk;?></td>
                                                
                                            <?php
                                                continue;
                                            }
                                            $ses_type = isset( $period_times[$ses]['type'] ) ? esc_html($period_times[$ses]['type']) :'';
                                            if(isset($timetable[$j][$ses]))
                                                $sub_id=$timetable[$j][$ses];
                                            else
                                                $sub_id='';
                                            if ($sub_id == '') {
                                                if($ses_type==0)
                                                    $sub_name = '<i>Break</i>';
                                                else
                                                    $sub_name='-';
                                            } else {
                                             //   $sub_name_f = $wpdb->get_results("SELECT sub_name from $subject_table where id=$subida[$pa]");
                                                $sub_name_f = $wpdb->get_results($wpdb->prepare("SELECT sub_name FROM $subject_table WHERE id = %s ",$subida[$pa]));
                                                if($subida1[$pa] == 1){
                                                $sub_name = '-';
                                                    } else {
                                                        $sub_name = isset( $sub_name_f[0]->sub_name ) ? $sub_name_f[0]->sub_name : 'N/A';
                                                    }
                                            }
                                            ?>
                                            <td class = "<?php echo esc_attr($subtimesloat[$pa]); ?> " tid="<?php echo esc_attr($subida[$pa]); ?>" data-sessionid="<?php echo esc_attr($key); ?>"> <?php echo esc_html($sub_name); ?> </td>
                                            <?php
                                            $pa++;
                                             reset($subida);
                                             reset($subida1);
                                             reset($subtimesloat);
                                        } ?>
                                </tr>
                            <?php
                            }
                            ?>
                        </tbody>
                    </table>
					</div>
                </div>
            </section>
        </div>
    </div>
        <?php
       }
       $response['msg'] =   ob_get_clean();
       return $response;
}?>
```
