Exemplo n.º 1
0
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)));
}
Exemplo n.º 2
0
function create_month($month, $year)
{
    global $phpcdb, $phpc_cal, $phpcid;
    $weeks = weeks_in_month($month, $year);
    $first_day = 1 - day_of_week($month, 1, $year);
    $from_stamp = mktime(0, 0, 0, $month, $first_day, $year);
    $last_day = $weeks * 7 - day_of_week($month, 1, $year);
    $to_stamp = mktime(23, 59, 59, $month, $last_day, $year);
    $days_events = get_events($from_stamp, $to_stamp);
    $week_list = array();
    for ($week_of_month = 1; $week_of_month <= $weeks; $week_of_month++) {
        // We could be showing a week from the previous or next year
        $days = ($week_of_month - 1) * 7;
        $start_stamp = strtotime("+{$days} day", $from_stamp);
        $week_list[] = create_week($start_stamp, $year, $days_events);
    }
    return $week_list;
}
Exemplo n.º 3
0
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&amp;phpcid={$phpcid}&amp;week={$prev_week}&amp;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&amp;phpcid={$phpcid}&amp;week={$next_week}&amp;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)));
}
Exemplo n.º 4
0
function create_month($month, $year)
{
    global $phpcdb, $phpc_cal, $phpcid;
    $wim = weeks_in_month($month, $year);
    $first_day = 1 - day_of_week($month, 1, $year);
    $from_stamp = mktime(0, 0, 0, $month, $first_day, $year);
    $last_day = $wim * 7 - day_of_week($month, 1, $year);
    $to_stamp = mktime(23, 59, 59, $month, $last_day, $year);
    $max_events = $phpc_cal->events_max;
    $results = $phpcdb->get_occurrences_by_date_range($phpcid, $from_stamp, $to_stamp);
    $days_events = array();
    while ($row = $results->fetch_assoc()) {
        $event = new PhpcOccurrence($row);
        if (!$event->can_read()) {
            continue;
        }
        $end_stamp = mktime(0, 0, 0, $event->get_end_month(), $event->get_end_day(), $event->get_end_year());
        $start_stamp = mktime(0, 0, 0, $event->get_start_month(), $event->get_start_day(), $event->get_start_year());
        $diff = $from_stamp - $start_stamp;
        if ($diff > 0) {
            $add_days = floor($diff / 86400);
        } else {
            $add_days = 0;
        }
        // put the event in every day until the end
        for (;; $add_days++) {
            $stamp = mktime(0, 0, 0, $event->get_start_month(), $event->get_start_day() + $add_days, $event->get_start_year());
            if ($stamp > $end_stamp || $stamp > $to_stamp) {
                break;
            }
            $key = date('Y-m-d', $stamp);
            if (!isset($days_events[$key])) {
                $days_events[$key] = array();
            }
            if (sizeof($days_events[$key]) == $max_events) {
                $days_events[$key][] = false;
            }
            if (sizeof($days_events[$key]) > $max_events) {
                continue;
            }
            $days_events[$key][] = $event;
        }
    }
    $month_table = tag('tbody');
    for ($week_of_month = 1; $week_of_month <= $wim; $week_of_month++) {
        $month_table->add(create_week($week_of_month, $month, $year, $days_events));
    }
    return $month_table;
}