function get_timetable($departments_page, $department = null, $mode = null, $hour_category = null) { global $themename; global $blog_id; global $wpdb; if ($hour_category != null && $hour_category != "-") { $hour_category = array_values(array_diff(array_filter(array_map('trim', explode(",", $hour_category))), array("-"))); } $output = ""; $query = "SELECT TIME_FORMAT(t1.start, '%H.%i') AS start, TIME_FORMAT(t1.end, '%H.%i') AS end, t1.tooltip AS tooltip, t1.before_hour_text AS before_hour_text, t1.after_hour_text AS after_hour_text, t1.doctors AS doctors, t2.ID AS department_id, t2.post_title AS department_title, t2.post_name AS post_name, t3.post_title, t3.menu_order FROM " . $wpdb->prefix . "department_hours AS t1 \n\t\t\tLEFT JOIN {$wpdb->posts} AS t2 ON t1.department_id=t2.ID \n\t\t\tLEFT JOIN {$wpdb->posts} AS t3 ON t1.weekday_id=t3.ID \n\t\t\tWHERE \n\t\t\tt2.post_type='departments'\n\t\t\tAND t2.post_status='publish'"; if (is_array($department) && count($department)) { $query .= "\n\t\t\tAND t2.post_name IN('" . join("','", $department) . "')"; } else { if ($department != null) { $query .= "\n\t\t\tAND t2.post_name='" . strtolower(urlencode($department)) . "'"; } } if ($hour_category != null && $hour_category != "-") { $query .= "\n\t\t\tAND t1.category IN('" . join("','", $hour_category) . "')"; } $query .= "\n\t\t\tAND \n\t\t\tt3.post_type='" . $themename . "_weekdays'\n\t\t\tORDER BY FIELD(t3.menu_order,2,3,4,5,6,7,1), t1.start, t1.end"; $department_hours = $wpdb->get_results($query); $department_hours_tt = array(); foreach ($department_hours as $department_hour) { $doctorsString = ""; if ($department_hour->doctors != "") { query_posts(array('post__in' => explode(",", $department_hour->doctors), 'post_type' => 'doctors', 'posts_per_page' => '-1', 'post_status' => 'publish', 'orderby' => 'post_title', 'order' => 'DESC')); while (have_posts()) { the_post(); $doctorsString .= get_the_title() . ", "; } if ($doctorsString != "") { $doctorsString = substr($doctorsString, 0, -2); } } $department_hours_tt[$department_hour->menu_order > 1 ? $department_hour->menu_order - 1 : 7][] = array("start" => $department_hour->start, "end" => $department_hour->end, "tooltip" => $department_hour->tooltip, "before_hour_text" => $department_hour->before_hour_text, "after_hour_text" => $department_hour->after_hour_text, "doctors" => $doctorsString, "tooltip" => $department_hour->tooltip, "id" => $department_hour->department_id, "title" => $department_hour->department_title, "name" => $department_hour->post_name); } $output .= '<table class="timetable"> <thead> <tr> <th></th>'; //get weekdays $query = "SELECT post_title, menu_order FROM {$wpdb->posts}\n\t\t\tWHERE \n\t\t\tpost_type='" . $themename . "_weekdays'\n\t\t\tAND post_status='publish'\n\t\t\tORDER BY FIELD(menu_order,2,3,4,5,6,7,1)"; $weekdays = $wpdb->get_results($query); foreach ($weekdays as $weekday) { $output .= ' <th>' . mb_strtoupper($weekday->post_title) . '</th>'; } $output .= ' </tr> </thead> <tbody>'; //get min anx max hour $query = "SELECT min(TIME_FORMAT(t1.start, '%H.%i')) AS min, max(REPLACE(TIME_FORMAT(t1.end, '%H.%i'), '00.00', '24.00')) AS max FROM " . $wpdb->prefix . "department_hours AS t1\n\t\t\tLEFT JOIN {$wpdb->posts} AS t2 ON t1.department_id=t2.ID \n\t\t\tLEFT JOIN {$wpdb->posts} AS t3 ON t1.weekday_id=t3.ID \n\t\t\tWHERE \n\t\t\tt2.post_type='departments'\n\t\t\tAND t2.post_status='publish'"; if (is_array($department) && count($department)) { $query .= "\n\t\t\tAND t2.post_name IN('" . join("','", $department) . "')"; } else { if ($department != null) { $query .= "\n\t\t\tAND t2.post_name='" . strtolower(urlencode($department)) . "'"; } } if ($hour_category != null && $hour_category != "-") { $query .= "\n\t\t\tAND t1.category IN('" . join("','", $hour_category) . "')"; } $query .= "\n\t\t\tAND \n\t\t\tt3.post_type='" . $themename . "_weekdays'"; $hours = $wpdb->get_row($query); $drop_columns = array(); $l = 0; $max_explode = explode(".", $hours->max); $max_hour = (int) $hours->max + ((int) $max_explode[1] > 0 ? 1 : 0); for ($i = (int) $hours->min; $i < $max_hour; $i++) { $start = str_pad($i, 2, '0', STR_PAD_LEFT) . '.00'; $end = str_replace("24", "00", str_pad($i + 1, 2, '0', STR_PAD_LEFT)) . '.00'; if ($mode == "12h") { $start = date("h.i a", strtotime($start)); $end = date("h.i a", strtotime($end)); } $output .= '<tr class="row_' . ($l + 1) . ($l % 2 == 0 ? ' row_gray' : '') . '"> <td> ' . $start . ' - ' . $end . ' </td>'; for ($j = 0; $j < count($weekdays); $j++) { $weekday_fixed_number = $weekdays[$j]->menu_order > 1 ? $weekdays[$j]->menu_order - 1 : 7; if (!in_array($weekday_fixed_number, (array) (isset($drop_columns[$i]["columns"]) ? $drop_columns[$i]["columns"] : array()))) { if (hour_in_array($i, isset($department_hours_tt[$weekday_fixed_number]) ? $department_hours_tt[$weekday_fixed_number] : array())) { $rowspan = get_rowspan_value($i, $department_hours_tt[$weekday_fixed_number], 1); if ($rowspan > 1) { for ($k = 1; $k < $rowspan; $k++) { $drop_columns[$i + $k]["columns"][] = $weekday_fixed_number; } } $array_count = count($department_hours_tt[$weekday_fixed_number]); $hours = array(); for ($k = (int) $i; $k < (int) $i + $rowspan; $k++) { $hours[] = $k; } $departments = array(); for ($k = 0; $k < $array_count; $k++) { if (in_array((int) $department_hours_tt[$weekday_fixed_number][$k]["start"], $hours)) { $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["name"] = $department_hours_tt[$weekday_fixed_number][$k]["name"]; $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["tooltip"][] = $department_hours_tt[$weekday_fixed_number][$k]["tooltip"]; $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["before_hour_text"][] = $department_hours_tt[$weekday_fixed_number][$k]["before_hour_text"]; $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["after_hour_text"][] = $department_hours_tt[$weekday_fixed_number][$k]["after_hour_text"]; $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["doctors"][] = $department_hours_tt[$weekday_fixed_number][$k]["doctors"]; $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["id"] = $department_hours_tt[$weekday_fixed_number][$k]["id"]; $departments[$department_hours_tt[$weekday_fixed_number][$k]["title"]]["hours"][] = $department_hours_tt[$weekday_fixed_number][$k]["start"] . " - " . $department_hours_tt[$weekday_fixed_number][$k]["end"]; $department_hours_tt[$weekday_fixed_number][$k]["displayed"] = true; } } $color = ""; $text_color = ""; $hover_color = ""; $hover_text_color = ""; $hours_text_color = ""; $hours_hover_text_color = ""; if (count($departments) == 1) { $color = get_post_meta($departments[key($departments)]["id"], $themename . "_color", true); $hover_color = get_post_meta($departments[key($departments)]["id"], $themename . "_hover_color", true); $text_color = get_post_meta($departments[key($departments)]["id"], $themename . "_text_color", true); $hover_text_color = get_post_meta($departments[key($departments)]["id"], $themename . "_hover_text_color", true); $hours_text_color = get_post_meta($departments[key($departments)]["id"], $themename . "_hours_text_color", true); $hours_hover_text_color = get_post_meta($departments[key($departments)]["id"], $themename . "_hours_hover_text_color", true); } $output .= '<td' . ($color != "" || $text_color != "" ? ' style="' . ($color != "" ? 'background-color: #' . $color . ';' : '') . ($text_color != "" ? 'color: #' . $text_color . ';' : '') . '"' : '') . ($hover_color != "" || $hover_text_color != "" || $hours_hover_text_color != "" ? ' onMouseOver="' . ($hover_color != "" ? 'this.style.backgroundColor=\'#' . $hover_color . '\';' : '') . ($hover_text_color != "" ? 'this.style.color=\'#' . $hover_text_color . '\';jQuery(this).find(\'.event_header\').css(\'color\', \'#' . $hover_text_color . '\');' : '') . ($hours_hover_text_color != "" ? 'jQuery(this).find(\'.hours\').css(\'color\',\'#' . $hours_hover_text_color . '\');' : '') . '" onMouseOut="' . ($hover_color != "" ? 'this.style.backgroundColor=\'#' . $color . '\';' : '') . ($hover_text_color != "" ? 'this.style.color=\'#' . $text_color . '\';jQuery(this).find(\'.event_header\').css(\'color\',\'#' . $text_color . '\');' : '') . ($hours_hover_text_color != "" ? 'jQuery(this).find(\'.hours\').css(\'color\',\'#' . $hours_text_color . '\');' : '') . '"' : '') . ' class="event' . (count(array_filter(array_values($departments[key($departments)]['tooltip']))) && count($departments) == 1 ? ' tooltip' : '') . '"' . ($rowspan > 1 ? ' rowspan="' . $rowspan . '"' : '') . '>'; $output .= get_row_content($departments, $departments_page, $mode); $output .= '</td>'; } else { $output .= '<td></td>'; } } } $output .= '</tr>'; $l++; } $output .= ' <tr> <td colspan="8" class="last"> <div class="tip"> ' . __("Click on the department name to get additional info", 'medicenter') . ' </div> </td> </tr> </tbody> </table> <div class="timetable small">'; $l = 0; foreach ($weekdays as $weekday) { $weekday_fixed_number = $weekday->menu_order > 1 ? $weekday->menu_order - 1 : 7; if (isset($department_hours_tt[$weekday_fixed_number])) { $output .= '<h3 class="box_header' . ($l > 0 ? ' page_margin_top' : '') . '"> ' . $weekday->post_title . ' </h3> <ul class="items_list thin page_margin_top clearfix' . ($mode == '12h' ? ' mode12' : '') . '">'; $department_hours_count = count($department_hours_tt[$weekday_fixed_number]); for ($i = 0; $i < $department_hours_count; $i++) { if ($mode == "12h") { $department_hours_tt[$weekday_fixed_number][$i]["start"] = date("g.i a", strtotime($department_hours_tt[$weekday_fixed_number][$i]["start"])); $department_hours_tt[$weekday_fixed_number][$i]["end"] = date("g.i a", strtotime($department_hours_tt[$weekday_fixed_number][$i]["end"])); } $timetable_custom_url = get_post_meta($department_hours_tt[$weekday_fixed_number][$i]["id"], $themename . "_timetable_custom_url", true); $classes_url = $timetable_custom_url != "" ? $timetable_custom_url : get_permalink($departments_page); $output .= '<li class="clearfix icon_clock_black"> <a href="' . $classes_url . '#' . urldecode($department_hours_tt[$weekday_fixed_number][$i]["name"]) . '" title="' . $department_hours_tt[$weekday_fixed_number][$i]["title"] . '"> ' . $department_hours_tt[$weekday_fixed_number][$i]["title"]; if ($department_hours_tt[$weekday_fixed_number][$i]["doctors"] != "") { $output .= ', ' . $department_hours_tt[$weekday_fixed_number][$i]["doctors"]; } $output .= '</a>'; $output .= '<div class="value"> ' . $department_hours_tt[$weekday_fixed_number][$i]["start"] . ' - ' . $department_hours_tt[$weekday_fixed_number][$i]["end"] . ' </div> </li>'; } $output .= '</ul>'; $l++; } } $output .= '</div>'; return $output; }
function get_timetable($classes_url, $class = null, $mode = null) { global $themename; global $blog_id; global $wpdb; $output = ""; $query = "SELECT TIME_FORMAT(t1.start, '%H.%i') AS start, TIME_FORMAT(t1.end, '%H.%i') AS end, t2.ID AS class_id, t2.post_title AS class_title, t2.post_name AS post_name, t3.post_title, t3.menu_order FROM wp_" . $blog_id . "_class_hours AS t1 \n\t\t\tLEFT JOIN {$wpdb->posts} AS t2 ON t1.class_id=t2.ID \n\t\t\tLEFT JOIN {$wpdb->posts} AS t3 ON t1.weekday_id=t3.ID \n\t\t\tWHERE \n\t\t\tt2.post_type='classes'\n\t\t\tAND t2.post_status='publish'"; if ($class != null) { $query .= "\n\t\t\tAND t2.post_name='" . strtolower(urlencode($class)) . "'"; } $query .= "\n\t\t\tAND \n\t\t\tt3.post_type='" . $themename . "_weekdays'\n\t\t\tORDER BY FIELD(t3.menu_order,2,3,4,5,6,7,1), t1.start, t1.end"; $class_hours = $wpdb->get_results($query); $class_hours_tt = array(); foreach ($class_hours as $class_hour) { $class_hours_tt[$class_hour->menu_order > 1 ? $class_hour->menu_order - 1 : 7][] = array("start" => $class_hour->start, "end" => $class_hour->end, "id" => $class_hour->class_id, "title" => $class_hour->class_title, "name" => $class_hour->post_name); } $output .= '<table class="timetable"> <thead> <tr> <th></th>'; //get weekdays $query = "SELECT post_title, menu_order FROM {$wpdb->posts}\n\t\t\tWHERE \n\t\t\tpost_type='" . $themename . "_weekdays'\n\t\t\tAND post_status='publish'\n\t\t\tORDER BY FIELD(menu_order,2,3,4,5,6,7,1)"; $weekdays = $wpdb->get_results($query); foreach ($weekdays as $weekday) { $output .= ' <th>' . strtoupper($weekday->post_title) . '</th>'; } $output .= ' </tr> </thead> <tbody>'; //get min anx max hour $query = "SELECT min(TIME_FORMAT(t1.start, '%H.%i')) AS min, max(REPLACE(TIME_FORMAT(t1.end, '%H.%i'), '00.00', '24.00')) AS max FROM wp_" . $blog_id . "_class_hours AS t1\n\t\t\tLEFT JOIN {$wpdb->posts} AS t2 ON t1.class_id=t2.ID \n\t\t\tLEFT JOIN {$wpdb->posts} AS t3 ON t1.weekday_id=t3.ID \n\t\t\tWHERE \n\t\t\tt2.post_type='classes'\n\t\t\tAND t2.post_status='publish'"; if ($class != null) { $query .= "\n\t\t\tAND t2.post_name='" . strtolower(urlencode($class)) . "'"; } $query .= "\n\t\t\tAND \n\t\t\tt3.post_type='" . $themename . "_weekdays'"; $hours = $wpdb->get_row($query); $drop_columns = array(); $l = 0; $max_explode = explode(".", $hours->max); $max_hour = (int) $hours->max + ((int) $max_explode[1] > 0 ? 1 : 0); for ($i = (int) $hours->min; $i < $max_hour; $i++) { $start = str_pad($i, 2, '0', STR_PAD_LEFT) . '.00'; $end = str_replace("24", "00", str_pad($i + 1, 2, '0', STR_PAD_LEFT)) . '.00'; if ($mode == "12h") { $start = date("h.i a", strtotime($start)); $end = date("h.i a", strtotime($end)); } $output .= '<tr class="row_' . ($l + 1) . ($l % 2 == 0 ? ' row_gray' : '') . '"> <td> ' . $start . ' - ' . $end . ' </td>'; for ($j = 1; $j <= 7; $j++) { if (!in_array($j, (array) $drop_columns[$i]["columns"])) { if (hour_in_array($i, $class_hours_tt[$j])) { $rowspan = get_rowspan_value($i, $class_hours_tt[$j], 1); if ($rowspan > 1) { for ($k = 1; $k < $rowspan; $k++) { $drop_columns[$i + $k]["columns"][] = $j; } } $array_count = count($class_hours_tt[$j]); $hours = array(); for ($k = (int) $i; $k < (int) $i + $rowspan; $k++) { $hours[] = $k; } $classes = array(); for ($k = 0; $k < $array_count; $k++) { if (in_array((int) $class_hours_tt[$j][$k]["start"], $hours)) { $classes[$class_hours_tt[$j][$k]["title"]]["name"] = $class_hours_tt[$j][$k]["name"]; $classes[$class_hours_tt[$j][$k]["title"]]["id"] = $class_hours_tt[$j][$k]["id"]; $classes[$class_hours_tt[$j][$k]["title"]]["hours"][] = $class_hours_tt[$j][$k]["start"] . " - " . $class_hours_tt[$j][$k]["end"]; $class_hours_tt[$j][$k]["displayed"] = true; } } $color = ""; $text_color = ""; if (count($classes) == 1) { $color = get_post_meta($classes[key($classes)]["id"], $themename . "_color", true); $text_color = get_post_meta($classes[key($classes)]["id"], $themename . "_text_color", true); } $output .= '<td' . ($color != "" || $text_color != "" ? ' style="' . ($color != "" ? 'background-color: #' . $color . ';' : '') . ($text_color != "" ? 'color: #' . $text_color . ';' : '') . '"' : '') . ' class="event"' . ($rowspan > 1 ? ' rowspan="' . $rowspan . '"' : '') . '>'; $output .= get_row_content($classes, $classes_url, $mode); $output .= '</td>'; } else { $output .= '<td></td>'; } } } $output .= '</tr>'; $l++; } $output .= ' <tr> <td colspan="8" class="last"> <div class="tip"> ' . __("Click on the class name to get additional info", $themename) . ' </div> </td> </tr> </tbody> </table> <div class="timetable small">'; $l = 0; foreach ($weekdays as $weekday) { $weekday_fixed_number = $weekday->menu_order > 1 ? $weekday->menu_order - 1 : 7; if (isset($class_hours_tt[$weekday_fixed_number])) { $output .= '<h3 class="box_header' . ($l > 0 ? ' page_margin_top' : '') . '"> ' . $weekday->post_title . ' </h3> <ul class="items_list dark opening_hours">'; $class_hours_count = count($class_hours_tt[$weekday_fixed_number]); for ($i = 0; $i < $class_hours_count; $i++) { if ($mode == "12h") { $class_hours_tt[$weekday_fixed_number][$i]["start"] = date("h.i a", strtotime($class_hours_tt[$weekday_fixed_number][$i]["start"])); $class_hours_tt[$weekday_fixed_number][$i]["end"] = date("h.i a", strtotime($class_hours_tt[$weekday_fixed_number][$i]["end"])); } $output .= '<li class="icon_clock_green"> <a href="' . $classes_url . '#' . urldecode($class_hours_tt[$weekday_fixed_number][$i]["name"]) . '" title="' . $class_hours_tt[$weekday_fixed_number][$i]["title"] . '"> ' . $class_hours_tt[$weekday_fixed_number][$i]["title"] . ' </a> <div class="value"> ' . $class_hours_tt[$weekday_fixed_number][$i]["start"] . ' - ' . $class_hours_tt[$weekday_fixed_number][$i]["end"] . ' </div> </li>'; } $output .= '</ul>'; $l++; } } $output .= '</div>'; return $output; }