function display_week() { global $vars; $heading_html = tag('tr'); $heading_html->add(tag('th', __p('Week', 'W'))); for ($i = 0; $i < 7; $i++) { $d = ($i + day_of_week_start()) % 7; $heading_html->add(tag('th', day_name($d))); } if (!isset($vars['week']) || !isset($vars['year'])) { soft_error(__('Invalid date.')); } $week_of_year = intval($vars['week']); $year = intval($vars['year']); $day_of_year = 1 + ($week_of_year - 1) * 7 - day_of_week(1, 1, $year); $from_stamp = mktime(0, 0, 0, 1, $day_of_year, $year); $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, $year); $end_month = date("n", $to_stamp); $end_year = date("Y", $to_stamp); $heading = month_name($start_month) . " {$start_year}"; if ($end_month != $start_month) { $heading .= " - " . month_name($end_month) . " {$end_year}"; } return tag('', tag("div", attributes('id="phpc-summary-view"'), tag("div", attributes('id="phpc-summary-head"'), tag("div", attributes('id="phpc-summary-title"'), ''), tag("div", attributes('id="phpc-summary-author"'), ''), tag("div", attributes('id="phpc-summary-category"'), ''), tag("div", attributes('id="phpc-summary-time"'), '')), tag("div", attributes('id="phpc-summary-body"'), '')), tag('table', attributes('class="phpc-main phpc-calendar"'), tag('caption', $heading), tag('colgroup', tag('col', attributes('class="phpc-week"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"'))), tag('thead', $heading_html), create_week($week_of_year, $from_stamp, $to_stamp, $year))); }
function display_month() { global $month, $year, $phpc_home_url, $phpcid; $heading_html = tag('tr'); $heading_html->add(tag('th', __p('Week', 'W'))); for ($i = 0; $i < 7; $i++) { $d = ($i + day_of_week_start()) % 7; $heading_html->add(tag('th', day_name($d))); } $months = array(); for ($i = 1; $i <= 12; $i++) { $m = month_name($i); $months["{$phpc_home_url}?action=display_month&phpcid={$phpcid}&month={$i}&year={$year}"] = $m; } $years = array(); for ($i = $year - 5; $i <= $year + 5; $i++) { $years["{$phpc_home_url}?action=display_month&phpcid={$phpcid}&month={$month}&year={$i}"] = $i; } return tag('', tag("div", attributes('id="phpc-summary-view"'), tag("div", attributes('id="phpc-summary-head"'), tag("div", attributes('id="phpc-summary-title"'), ''), tag("div", attributes('id="phpc-summary-author"'), ''), tag("div", attributes('id="phpc-summary-category"'), ''), tag("div", attributes('id="phpc-summary-time"'), '')), tag("div", attributes('id="phpc-summary-body"'), '')), tag('table', attributes('class="phpc-main phpc-calendar"'), tag('caption', create_dropdown_list(month_name($month), $months), create_dropdown_list($year, $years)), tag('colgroup', tag('col', attributes('class="phpc-week"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"'))), tag('thead', $heading_html), create_month($month, $year))); }
function week_of_year($month, $day, $year) { $timestamp = mktime(0, 0, 0, $month, $day, $year); // week_start = 1 uses ISO 8601 and contains the Jan 4th, // Most other places the first week contains Jan 1st // There are a few outliers that start weeks on Monday and use // Jan 1st for the first week. We'll ignore them for now. if (day_of_week_start() == 1) { $year_contains = 4; // if the week is in December and contains Jan 4th, it's a week // from next year if ($month == 12 && $day - 24 >= $year_contains) { $year++; $month = 1; $day -= 31; } } else { $year_contains = 1; } // $day is the first day of the week relative to the current month, // so it can be negative. If it's in the previous year, we want to use // that negative value, unless the week is also in the previous year, // then we want to switch to using that year. if ($day < 1 && $month == 1 && $day > $year_contains - 7) { $day_of_year = $day - 1; } else { $day_of_year = date('z', $timestamp); $year = date('Y', $timestamp); } /* Days in the week before Jan 1. */ $days_before_year = day_of_week(1, $year_contains, $year); // Days left in the week $days_left = 8 - day_of_week_ts($timestamp) - $year_contains; /* find the number of weeks by adding the days in the week before * the start of the year, days up to $day, and the days left in * this week, then divide by 7 */ return ($days_before_year + $day_of_year + $days_left) / 7; }
function form_date_input($qid, $defaults, $dateFormat) { $date_attrs = attrs('type="text"', 'class="form-date"', "name=\"{$qid}-date\"", "id=\"{$qid}-date\""); if (isset($defaults["{$qid}-date"])) { $date_attrs->add("value=\"{$defaults["{$qid}-date"]}\""); } return array(tag('input', $date_attrs), tag('script', attrs('type="text/javascript"'), "\$('#{$qid}-date').datepicker({dateFormat: \"{$dateFormat}\", firstDay: " . day_of_week_start() . " });")); /**** */ }
function create_display_table($heading, $contents) { $heading_html = tag('tr', attrs('class="ui-widget-header"')); $heading_html->add(tag('th', __p('Week', 'W'))); for ($i = 0; $i < 7; $i++) { $d = ($i + day_of_week_start()) % 7; $heading_html->add(tag('th', day_name($d))); } return tag('div', tag("div", attributes('id="phpc-summary-view"'), tag("div", attributes('id="phpc-summary-head"'), tag("div", attributes('id="phpc-summary-title"'), ''), tag("div", attributes('id="phpc-summary-author"'), ''), tag("div", attributes('id="phpc-summary-category"'), ''), tag("div", attributes('id="phpc-summary-time"'), '')), tag("div", attributes('id="phpc-summary-body"'), '')), tag('div', attrs('class="phpc-sub-title phpc-month-title ui-widget-content"'), $heading), tag('table', attrs('class="phpc-month-view"'), tag('colgroup', tag('col', attributes('class="phpc-week"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"'))), tag('thead', $heading_html), tag('tbody', $contents))); }