<?php
/*
  Template Name: Timetable
 */

get_header();

if (have_posts()) : while (have_posts()) : the_post();
        $timetable = get_field('timetable');
        if ($timetable):
            ?>
            <div id="body" class="page-row page-row-expanded"> Test
                <div class="container">
                    <div id="content">
                        <div class="">
                            <h1 style="text-align:center;"><?php the_title(); ?></h1>
                            <form action="#" class="filter clearfix">
                                <p class="select-field">
                                    <label><span class="select-label">Day:</span>
                                        <select id="select-day" data-jcf='{"wrapNative": false, "wrapNativeOnMobile": false, "fakeDropInBody": false, "useCustomScroll": false}'>
                                            <option value=""><?php _e('All', 'am') ?></option>
                                            <?php
                                            $Class_arr = array();
                                            $Floor_arr = array();
                                            foreach ($timetable as $dkey => $days) {
                                                echo '<option value="day-' . $dkey . '">' . $days["day_title"] . '</option>';
                                                foreach ($days["items"] as $key => $item) {
                                                    array_push($Class_arr, $item["class"]);
                                                    array_push($Floor_arr, $item["floor"]);
                                                }
                                            }
                                            $Class_arr = array_unique($Class_arr);
                                            $Floor_arr = array_unique($Floor_arr);
                                            ?>
                                        </select>
                                    </label>
                                </p>
                                <p class="select-field">
                                    <label><span class="select-label"><?php _e('Class:','am') ?></span>
                                        <select id="select-class" data-jcf='{"wrapNative": false, "wrapNativeOnMobile": false, "fakeDropInBody": false, "useCustomScroll": false}'>
                                            <option value=""><?php _e('All', 'am') ?></option>
                                            <?php
                                            foreach ($Class_arr as $i) {
                                                echo '<option value="class-' . md5($i) . '">' . $i . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </label>
                                </p>
                                <p class="select-field">
                                    <label><span class="select-label"><?php _e('Floor:','am') ?></span>
                                        <select id="select-floor" data-jcf='{"wrapNative": false, "wrapNativeOnMobile": false, "fakeDropInBody": false, "useCustomScroll": false}'>
                                            <option value=""><?php _e('All', 'am') ?></option>
                                            <?php
                                            foreach ($Floor_arr as $i) {
                                                echo '<option value="floor-' . md5($i) . '">' . $i . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </label>
                                </p>
                            </form>
                            <?php
                            foreach ($timetable as $key=>$day):
                                ?>
                                <div class="day-table day-<?php echo $key; ?>">
                                    <h2><?php echo $day["day_title"]; ?></h2>
                                    <table>
                                        <tr>
                                            <th><?php _e('Time', 'am') ?></th>
                                            <th><?php _e('Class', 'am') ?></th>
                                            <th><?php _e('Floor', 'am') ?></th>
                                        </tr>
                                        <?php
                                        foreach ($day["items"] as $value):
                                            ?>
                                            <tr class="day-table-row class-<?php echo md5($value["class"]); ?> floor-<?php echo md5($value["floor"]); ?>">
                                                <td><?php echo $value["time"]; ?></td>
                                                <td><?php echo $value["class"]; ?></td>
                                                <td><?php echo $value["floor"]; ?></td>
                                            </tr>
                                            <?php
                                        endforeach;
                                        ?>
                                    </table>
                                </div>
                                <?php
                            endforeach;
                            ?>
                        </div>
                    </div>
                    <!-- / content -->

                </div>
                <!-- / container -->
            </div>
            <?php
        endif;
    endwhile;
endif;
get_footer();
?>