<?php 

function my_timetable_cb() {
	$session = Session::getInstance();
	$post = new post;
	if(isset($_GET['id'])) {
		if(!verify_token($_GET['token'])) {
           token_error();
           return_method();
           return;
        }
		$teacher_id = $_GET['id'];
	} else $teacher_id = $session->id;
	$timetable = get_option('timetable');
	$teacher_mapping = get_option('teacher_mapping');
	$days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
	$class = $post->get_post_by_meta_data(['type' => 'class']);
	$category = $post->get_post_by_meta_data(['type' => 'category']);
	if(_count($class) > 0) {
		foreach ($class as $class_meta) {
			if(_count($category) > 0) {
				foreach ($category as $category_meta) {
					$my_timetable[$class_meta['class_name']][$category_meta['category_name']] = get_teachers_period($teacher_id, $class_meta['id'], $category_meta['id'], $timetable, $teacher_mapping);
				}
			}
		}
	}
	if(is_array($my_timetable) && _count($my_timetable)) :
	foreach ($my_timetable as $class_name => $class_cat_timetable) {
		if(is_array($class_cat_timetable) && _count($class_cat_timetable)) {
			foreach ($class_cat_timetable as $category_name => $class_timetable) {
				if(!$class_timetable) {
					continue;
				} else echo $class_name.' '.$category_name;
			}
		} else continue;
	?>
	<div class="col-md-12">
        <div class="card">
            <div class="card-header">
                <strong class="card-title">My periods for <?=$class_name.' '.$category_name; ?></strong>
            </div>
            <div class="card-body">
                <table class="table table-bordered table-striped table-hover">
					<tr>
						<th>Start</th>
						<th>Stop</th>
						<?php 
						foreach ($days as $day) {
							echo '<th>'.$day.'</th>';
						}
						 ?>
					</tr>
<?php
if(is_array($class_timetable) && _count($class_timetable)) :
	foreach ($class_timetable as $period => $value) {
		?>
					<tr>
						<td><?=$value['start']?></td>
						<td><?=$value['stop']?></td>
						<?php 
						foreach ($days as $day) {
							$col = '<td>';
							$col .= isset($value[$day]) ? $value[$day] : '-';
							$col .= '</td>';
							echo $col;
						}
						?>
					</tr>
		<?php
	}
endif;
 ?>
</table>
</div>
</div>
</div>
	<?php
	}
endif;
}