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_year, $from_stamp, $to_stamp, $year)
{
    global $phpcdb, $phpcid, $phpc_cal;
    $start_day = date("j", $from_stamp);
    $start_month = date("n", $from_stamp);
    $start_year = date("Y", $from_stamp);
    $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;
        }
    }
    $week_table = tag('tbody');
    $week_html = tag('tr', tag('th', $week_of_year));
    $week_table->add($week_html);
    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_table;
}
Example #3
0
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;
}