function display_week() { global $vars, $phpc_home_url, $phpcid, $phpc_year, $phpc_month, $phpc_day; if (!isset($vars['week'])) { $week_of_year = week_of_year($phpc_month, $phpc_day, $phpc_year); } else { if (!is_numeric($vars['week'])) { soft_error(__('Invalid date.')); } $week_of_year = $vars['week']; } $day_of_year = 1 + ($week_of_year - 1) * 7 - day_of_week(1, 1, $phpc_year); $from_stamp = mktime(0, 0, 0, 1, $day_of_year, $phpc_year); $start_day = date("j", $from_stamp); $start_month = date("n", $from_stamp); $start_year = date("Y", $from_stamp); $last_day = $day_of_year + 6; $to_stamp = mktime(23, 59, 59, 1, $last_day, $phpc_year); $end_day = date("j", $to_stamp); $end_month = date("n", $to_stamp); $end_year = date("Y", $to_stamp); $title = month_name($start_month) . " {$start_year}"; if ($end_month != $start_month) { $title .= " - " . month_name($end_month) . " {$end_year}"; } $prev_week = $week_of_year - 1; $prev_year = $phpc_year; if ($prev_week < 1) { $prev_year--; $prev_week = week_of_year($start_month, $start_day - 7, $start_year); } $next_week = $week_of_year + 1; $next_year = $phpc_year; if ($next_week > weeks_in_year($phpc_year)) { $next_week = week_of_year($end_month, $end_day + 1, $end_year); $next_year++; } $heading = tag('', tag('a', attrs('class="phpc-icon-link"', "href=\"{$phpc_home_url}?action=display_week&phpcid={$phpcid}&week={$prev_week}&year={$prev_year}\""), tag('span', attrs('class="fa fa-chevron-left"'), '')), $title, tag('a', attrs('class="phpc-icon-link"', "href=\"{$phpc_home_url}?action=display_week&phpcid={$phpcid}&week={$next_week}&year={$next_year}\""), tag('span', attrs('class="fa fa-chevron-right"'), ''))); return create_display_table($heading, create_week($from_stamp, $phpc_year, get_events($from_stamp, $to_stamp))); }
function create_week($from_stamp, $year, $days_events) { $start_day = date("j", $from_stamp); $start_month = date("n", $from_stamp); $start_year = date("Y", $from_stamp); $week_of_year = week_of_year($start_month, $start_day, $start_year); // Non ISO, the week should be of this year. if (day_of_week_start() != 1) { if ($start_year < $year) { $week_of_year = 1; } } else { // Use week's year as year for ISO $year = $start_year; } $week_html = tag('tr', tag('th', attrs('class="phpc-date ui-state-default"'), create_action_link($week_of_year, 'display_week', array('week' => $week_of_year, 'year' => $year)))); for ($day_of_week = 0; $day_of_week < 7; $day_of_week++) { $day = $start_day + $day_of_week; $week_html->add(create_day($start_month, $day, $start_year, $days_events)); } return $week_html; }
function create_week($week_of_month, $month, $year, $days_events) { $start_day = 1 + ($week_of_month - 1) * 7 - day_of_week($month, 1, $year); $week_of_year = week_of_year($month, $start_day, $year); $args = array('week' => $week_of_year, 'year' => $year); $click = create_plain_link($week_of_year, 'display_week', false, false, false, false, $args); $week_html = tag('tr', tag('th', attrs('class="ui-state-default"', "onclick=\"window.location.href='{$click}'\""), create_action_link($week_of_year, 'display_week', $args))); for ($day_of_week = 0; $day_of_week < 7; $day_of_week++) { $day = $start_day + $day_of_week; $week_html->add(create_day($month, $day, $year, $days_events)); } return $week_html; }
function day($timestamp) { $this->timestamp = $timestamp; $this->year = date('Y', $this->timestamp); $this->month = date('m', $this->timestamp); $this->day = date('d', $this->timestamp); $this->name = date('dMy', $this->timestamp); $this->week = week_of_year($this->timestamp); }