Example #1
0
function display_day()
{
    global $phpcid, $phpc_cal, $phpc_user, $phpc_script, $phpcdb, $day, $month, $year;
    $monthname = month_name($month);
    $results = $phpcdb->get_occurrences_by_date($phpcid, $year, $month, $day);
    $today_epoch = mktime(0, 0, 0, $month, $day, $year);
    $have_events = false;
    $html_table = tag('table', attributes('class="phpc-main"'), tag('caption', "{$day} {$monthname} {$year}"), tag('thead', tag('tr', tag('th', __('Title')), tag('th', __('Time')), tag('th', __('Description')))));
    if ($phpc_cal->can_modify()) {
        $html_table->add(tag('tfoot', tag('tr', tag('td', attributes('colspan="4"'), create_hidden('action', 'event_delete'), create_hidden('day', $day), create_hidden('month', $month), create_hidden('year', $year), create_submit(__('Delete Selected'))))));
    }
    $html_body = tag('tbody');
    while ($row = $results->fetch_assoc()) {
        $event = new PhpcOccurrence($row);
        if (!$event->can_read()) {
            continue;
        }
        $have_events = true;
        $eid = $event->get_eid();
        $oid = $event->get_oid();
        $html_subject = tag('td');
        if ($event->can_modify()) {
            $html_subject->add(create_checkbox('eid[]', $eid));
        }
        $html_subject->add(create_occurrence_link(tag('strong', $event->get_subject()), 'display_event', $oid));
        if ($event->can_modify()) {
            $html_subject->add(" (");
            $html_subject->add(create_event_link(__('Modify'), 'event_form', $eid));
            $html_subject->add(')');
        }
        $html_body->add(tag('tr', $html_subject, tag('td', $event->get_time_span_string()), tag('td', $event->get_desc())));
    }
    $html_table->add($html_body);
    if ($phpc_cal->can_modify()) {
        $output = tag('form', attributes("action=\"{$phpc_script}\""), $html_table);
    } else {
        $output = $html_table;
    }
    if (!$have_events) {
        $output = tag('h2', __('No events on this day.'));
    }
    return tag('', create_day_menu(), $output);
}
Example #2
0
function display_event_by_eid($eid)
{
    global $phpcdb, $year, $month, $day;
    $event = new PhpcEvent($phpcdb->get_event_by_eid($eid));
    if (!$event->can_read()) {
        return tag('p', __("You do not have permission to read this event."));
    }
    $event_header = tag('div', attributes('class="phpc-event-header"'), tag('div', __('by') . ' ', tag('cite', $event->get_author())));
    $event_header->add(tag('div', __('Created at: '), $event->get_ctime_string()));
    if (!empty($event->mtime)) {
        $event_header->add(tag('div', __('Last modified at: '), $event->get_mtime_string()));
    }
    $category = $event->get_category();
    if (!empty($category)) {
        $event_header->add(tag('div', __('Category') . ': ' . $category));
    }
    // Add modify/delete links if this user has access to this event.
    if ($event->can_modify()) {
        $event_header->add(tag('div', attrs('class="phpc-bar ui-widget-content"'), create_event_link(__('Modify'), 'event_form', $eid), "\n", create_event_link(__('Add Occurrence'), 'occur_form', $eid), "\n", create_event_link(__('Delete'), 'event_delete', $eid)));
    }
    $desc_tag = tag('div', attributes('class="phpc-desc"'), tag('h3', __("Description")), tag('p', $event->get_desc()));
    $occurrences_tag = tag('ul');
    $occurrences = $phpcdb->get_occurrences_by_eid($eid);
    $set_date = false;
    foreach ($occurrences as $occurrence) {
        if (!$set_date) {
            $year = $occurrence->get_start_year();
            $month = $occurrence->get_start_month();
            $day = $occurrence->get_start_day();
        }
        $oid = $occurrence->get_oid();
        $occ_tag = tag('li', attrs('class="ui-widget-content"'), create_occurrence_link($occurrence->get_date_string() . ' ' . __('at') . ' ' . $occurrence->get_time_span_string(), 'display_event', $oid));
        if ($event->can_modify()) {
            $occ_tag->add(" ", create_occurrence_link(__('Edit'), 'occur_form', $oid), " ", create_occurrence_link(__('Remove'), 'occurrence_delete', $oid));
        }
        $occurrences_tag->add($occ_tag);
    }
    return tag('div', attributes('class="phpc-main phpc-event"'), tag('h2', $event->get_subject()), $event_header, $desc_tag, tag('div', attributes('class="phpc-occ"'), tag('h3', __('Occurrences')), $occurrences_tag));
}
Example #3
0
function display_event()
{
    global $vars, $phpcdb, $phpc_year, $phpc_month, $phpc_day, $phpc_cal;
    if (!empty($vars['content']) && $vars['content'] == 'json') {
        return display_event_json();
    }
    if (isset($vars['oid'])) {
        $entry = $phpcdb->get_event_by_oid($vars['oid']);
        if (!$entry) {
            return tag('p', __('There is no event for that OID.'));
        }
        $event = new PhpcEvent($entry);
    } elseif (isset($vars['eid'])) {
        $entry = $phpcdb->get_event_by_eid($vars['eid']);
        if (!$entry) {
            return tag('p', __('There is no event with that EID.'));
        }
        $event = new PhpcEvent($entry);
    }
    if (!isset($event)) {
        soft_error(__("Invalid arguments."));
    }
    if (!$event->can_read()) {
        return tag('p', __("You do not have permission to read this event."));
    }
    $event_header = tag('div', attributes('class="phpc-event-header"'), tag('div', __('created by') . ' ', tag('cite', $event->get_author()), ' ' . __('on') . ' ' . $event->get_ctime_string()));
    if (!empty($event->mtime)) {
        $event_header->add(tag('div', __('Last modified on '), $event->get_mtime_string()));
    }
    $category = $event->get_category();
    if (!empty($category)) {
        $event_header->add(tag('div', __('Category') . ': ' . $category));
    }
    // Add modify/delete links if this user has access to this event.
    $event_menu = '';
    if ($event->can_modify()) {
        $event_menu = tag('div', attrs('class="phpc-bar ui-widget-content"'), create_event_link(__('Modify'), 'event_form', $event->get_eid()), "\n", create_event_link(__('Delete'), 'event_delete', $event->get_eid(), attrs('class="phpc-confirm"')));
    }
    $desc_tag = tag('div', attributes('class="phpc-desc"'), tag('h3', __("Description")), tag('p', $event->get_desc()));
    $occurrences_tag = tag('ul');
    $occurrences = $phpcdb->get_occurrences_by_eid($event->get_eid());
    $set_date = false;
    foreach ($occurrences as $occurrence) {
        if (!$set_date) {
            $phpc_year = $occurrence->get_start_year();
            $phpc_month = $occurrence->get_start_month();
            $phpc_day = $occurrence->get_start_day();
        }
        $oid = $occurrence->get_oid();
        $occ_tag = tag('li', attrs('class="ui-widget-content"'), $occurrence->get_date_string() . ' ' . __('at') . ' ' . $occurrence->get_time_span_string());
        if ($event->can_modify()) {
            $occ_tag->add(" ", create_occurrence_link(__('Edit'), 'occur_form', $oid), " ", create_occurrence_link(__('Remove'), 'occurrence_delete', $oid, attrs('class="phpc-confirm-occ"')));
        }
        $occurrences_tag->add($occ_tag);
    }
    // Add occurrence link if this user has access to this event.
    $occurrences_menu = '';
    if ($event->can_modify()) {
        $occurrences_menu = tag('div', attrs('class="phpc-bar ui-widget-content"'), create_event_link(__('Add Occurrence'), 'occur_form', $event->get_eid()));
    }
    foreach ($event->get_fields() as $field) {
        $def = $phpc_cal->get_field($field['fid']);
        $event_header->add(tag('div', $def['name'] . ": " . $field['value']));
    }
    $dialog = tag('div', attrs('id="phpc-dialog"', 'title="' . __("Confirmation required") . '"'), __("Permanently delete this event?"));
    $dialog2 = tag('div', attrs('id="phpc-dialog-occ"', 'title="' . __("Confirmation required") . '"'), __("Permanently delete this occurrence?"));
    return tag('div', attributes('class="phpc-main phpc-event"'), $dialog, $dialog2, $event_menu, tag('h2', $event->get_subject()), $event_header, $desc_tag, tag('div', attrs('class="phpc-occ"'), tag('h3', __('Occurrences')), $occurrences_menu, $occurrences_tag));
}
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;
}