function create_day($month, $day, $year, $days_events)
{
    global $phpc_script, $phpc_cal;
    $date_class = 'ui-state-default';
    if ($day <= 0) {
        $month--;
        if ($month < 1) {
            $month = 12;
            $year--;
        }
        $day += days_in_month($month, $year);
        $date_class .= ' phpc-shadow';
    } elseif ($day > days_in_month($month, $year)) {
        $day -= days_in_month($month, $year);
        $month++;
        if ($month > 12) {
            $month = 1;
            $year++;
        }
    } else {
        $currentday = date('j');
        $currentmonth = date('n');
        $currentyear = date('Y');
        // set whether the date is in the past or future/present
        if ($currentyear == $year && $currentmonth == $month && $currentday == $day) {
            $date_class .= ' ui-state-highlight';
        }
    }
    $click = create_plain_link($day, 'display_day', $year, $month, $day);
    $date_tag = tag('div', attributes("class=\"phpc-date {$date_class}\"", "onclick=\"window.location.href='{$click}'\""), create_action_link_with_date($day, 'display_day', $year, $month, $day));
    if ($phpc_cal->can_write()) {
        $date_tag->add(create_action_link_with_date('+', 'event_form', $year, $month, $day, array('class="phpc-add"')));
    }
    $html_day = tag('td', $date_tag);
    $stamp = mktime(0, 0, 0, $month, $day, $year);
    $can_read = $phpc_cal->can_read();
    $key = date('Y-m-d', $stamp);
    if (!$can_read || !array_key_exists($key, $days_events)) {
        return $html_day;
    }
    $results = $days_events[$key];
    if (empty($results)) {
        return $html_day;
    }
    $html_events = tag('ul', attrs('class="phpc-event-list"'));
    $html_day->add($html_events);
    // Count the number of events
    foreach ($results as $event) {
        if ($event == false) {
            $event_html = tag('li', create_action_link_with_date(__("View Additional Events"), 'display_day', $year, $month, $day, array('class="phpc-date"')));
            $html_events->add($event_html);
            break;
        }
        // TODO - make sure we have permission to read the event
        $subject = $event->get_subject();
        if ($event->get_start_timestamp() >= $stamp) {
            $event_time = $event->get_time_string();
        } else {
            $event_time = '(' . __('continued') . ')';
        }
        if (!empty($event_time)) {
            $title = "{$event_time} - {$subject}";
        } else {
            $title = $subject;
        }
        $style = "";
        if (!empty($event->text_color)) {
            $style .= "color: {$event->get_text_color()} !important;";
        }
        if (!empty($event->bg_color)) {
            $style .= "background: " . $event->get_bg_color() . " !important;";
        }
        $event_html = tag('li', create_occurrence_link($title, "display_event", $event->get_oid(), array("style=\"{$style}\"")));
        $html_events->add($event_html);
    }
    return $html_day;
}
Exemple #2
0
function menu_item_append_with_date(&$html, $name, $action, $year = false, $month = false, $day = false, $attribs = false)
{
    $name = str_replace(' ', '&nbsp;', $name);
    if (!is_object($html)) {
        soft_error('Html is not a valid Html class.');
    }
    $html->add(create_action_link_with_date($name, $action, $year, $month, $day, $attribs));
    $html->add("\n");
}