function search_results() { global $vars, $phpcdb, $phpcid, $sort_options, $order_options; $searchstring = $vars['searchstring']; if (!empty($vars['search-from-date']) && strlen($vars['search-from-date']) > 0) { $start = get_timestamp('search-from'); } else { $start = false; } if (!empty($vars['search-to-date']) && strlen($vars['search-to-date']) > 0) { $end = get_timestamp('search-to'); } else { $end = false; } // make sure sort is valid $sort = htmlentities($vars['sort']); if (array_search($sort, array_keys($sort_options)) === false) { soft_error(__('Invalid sort option') . ": {$sort}"); } // make sure order is valid $order = htmlentities($vars['order']); if (array_search($order, array_keys($order_options)) === false) { soft_error(__('Invalid order option') . ": {$order}"); } $keywords = explode(" ", $searchstring); $results = $phpcdb->search($phpcid, $keywords, $start, $end, $sort, $order); $tags = array(); foreach ($results as $event) { if (!$event->can_read()) { continue; } $name = $event->get_author(); $subject = $event->get_subject(); $desc = $event->get_desc(); $date = $event->get_date_string(); $time = $event->get_time_string(); $eid = $event->get_eid(); $tags[] = tag('tr', tag('td', tag('strong', create_event_link($subject, 'display_event', $eid))), tag('td', "{$date} {$time}"), tag('td', $desc)); } if (sizeof($tags) == 0) { $html = tag('div', tag('strong', __('No events matched your search criteria.'))); } else { $html = tag('table', attributes('class="phpc-main"'), tag('caption', __('Search Results')), tag('thead', tag('tr', tag('th', __('Subject')), tag('th', __('Date Time')), tag('th', __('Description'))))); foreach ($tags as $tag) { $html->add($tag); } } return $html; }
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); }
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)); }
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 process_form() { global $vars, $phpcdb, $phpc_cal, $phpcid, $phpc_script; if (!isset($vars['eid']) && !isset($vars['oid'])) { soft_error(__("Cannot create occurrence.")); } $start_ts = get_timestamp("start"); $end_ts = get_timestamp("end"); switch ($vars["time-type"]) { case 'normal': $time_type = 0; break; case 'full': $time_type = 1; break; case 'tba': $time_type = 2; break; default: soft_error(__("Unrecognized Time Type.")); } $duration = $end_ts - $start_ts; if ($duration < 0) { soft_error(__("An event cannot have an end earlier than its start.")); } verify_token(); if (!$phpc_cal->can_write()) { permission_error(__('You do not have permission to write to this calendar.')); } if (!isset($vars['oid'])) { $modify = false; if (!isset($vars["eid"])) { soft_error(__("EID not set.")); } $oid = $phpcdb->create_occurrence($vars["eid"], $time_type, $start_ts, $end_ts); } else { $modify = true; $oid = $vars["oid"]; $phpcdb->modify_occurrence($oid, $time_type, $start_ts, $end_ts); } if ($oid != 0) { if ($modify) { $message = __("Modified occurence: "); } else { $message = __("Created occurence: "); } return message_redirect(tag('', $message, create_event_link($oid, 'display_event', $oid)), "{$phpc_script}?action=display_event&phpcid={$phpcid}&oid={$oid}"); } else { return message_redirect(__('Error submitting occurrence.'), "{$phpc_script}?action=display_month&phpcid={$phpcid}"); } }
function process_form() { global $vars, $phpcdb, $phpc_cal, $phpcid, $phpc_script, $phpc_user; // When modifying events, this is the value of the checkbox that // determines if the date should change $modify_occur = !isset($vars['eid']) || !empty($vars['phpc-modify']); if ($modify_occur) { $start_ts = get_timestamp("start"); $end_ts = get_timestamp("end"); switch ($vars["time-type"]) { case 'normal': $time_type = 0; break; case 'full': $time_type = 1; break; case 'tba': $time_type = 2; break; default: soft_error(__("Unrecognized Time Type.")); } $duration = $end_ts - $start_ts; if ($duration < 0) { message(__("An event cannot have an end earlier than its start.")); return display_form(); } } verify_token(); if (0) { permission_error(__('You do not have permission to write to this calendar.')); } if ($phpc_cal->can_create_readonly() && !empty($vars['readonly'])) { $readonly = true; } else { $readonly = false; } $catid = empty($vars['catid']) ? false : $vars['catid']; if (!isset($vars['eid'])) { $modify = false; $eid = $phpcdb->create_event($phpcid, $phpc_user->get_uid(), $vars["subject"], $vars["description"], $readonly, $catid); } else { $modify = true; $eid = $vars['eid']; $phpcdb->modify_event($eid, $vars['subject'], $vars['description'], $readonly, $catid); if ($modify_occur) { $phpcdb->delete_occurrences($eid); } } if ($modify_occur) { $oid = $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences = 1; switch ($vars["repeats"]) { case "never": break; case 'daily': if (!isset($vars["every-day"])) { soft_error(__("Required field \"every-day\" is not set.")); } $ndays = $vars["every-day"]; if ($ndays < 1) { soft_error(__("every-day must be greater than 1")); } $daily_until = get_timestamp("daily-until"); while ($occurrences <= 730) { $start_ts = add_days($start_ts, $ndays); $end_ts = add_days($end_ts, $ndays); if (days_between($start_ts, $daily_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; case 'weekly': if (!isset($vars["every-week"])) { soft_error(__("Required field \"every-week\" is not set.")); } if ($vars["every-week"] < 1) { soft_error(__("every-week must be greater than 1")); } $ndays = $vars["every-week"] * 7; $weekly_until = get_timestamp("weekly-until"); while ($occurrences <= 730) { $start_ts = add_days($start_ts, $ndays); $end_ts = add_days($end_ts, $ndays); if (days_between($start_ts, $weekly_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; case 'monthly': if (!isset($vars["every-month"])) { soft_error(__("Required field \"every-month\" is not set.")); } if ($vars["every-month"] < 1) { soft_error(__("every-month must be greater than 1")); } $nmonths = $vars["every-month"]; $monthly_until = get_timestamp("monthly-until"); while ($occurrences <= 730) { $start_ts = add_months($start_ts, $nmonths); $end_ts = add_months($end_ts, $nmonths); if (days_between($start_ts, $monthly_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; case 'yearly': if (!isset($vars["every-year"])) { soft_error(__("Required field \"every-year\" is not set.")); } if ($vars["every-year"] < 1) { soft_error(__("every-month must be greater than 1")); } $nyears = $vars["every-year"]; $yearly_until = get_timestamp("yearly-until"); while ($occurrences <= 730) { $start_ts = add_years($start_ts, $nyears); $end_ts = add_years($end_ts, $nyears); if (days_between($start_ts, $yearly_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; default: soft_error(__("Invalid event type.")); } } if ($eid != 0) { if ($modify) { $message = __("Modified event: "); } else { $message = __("Created event: "); } /* before return message_redirect(tag($eid, $message, create_event_link('', 'display_event', $eid)), */ return message_redirect(tag('', $message, create_event_link('', 'display_event', '')), "{$phpc_script}?action=display_event&phpcid={$phpcid}&oid={$oid}"); /* <-- before last paremeter was &eid=$eid instead of &oid=$oid */ } else { return message_redirect(__('Error submitting event.'), "{$phpc_script}?action=display_month&phpcid={$phpcid}"); } }
function process_form() { global $vars, $phpcdb, $phpc_script, $phpc_user, $phpc_cal; // When modifying events, this is the value of the checkbox that // determines if the date should change $modify_occur = !isset($vars['eid']) || !empty($vars['phpc-modify']); if ($modify_occur) { $start_ts = get_timestamp("start"); $end_ts = get_timestamp("end"); switch ($vars["time-type"]) { case 'normal': $time_type = 0; break; case 'full': $time_type = 1; break; case 'tba': $time_type = 2; break; default: soft_error(__("Unrecognized Time Type.")); } $duration = $end_ts - $start_ts; if ($duration < 0) { throw new Exception(__("An event cannot have an end earlier than its start.")); } } verify_token(); if (!isset($vars['cid'])) { throw new Exception(__("Calendar ID is not set.")); } $cid = $vars['cid']; $calendar = $phpcdb->get_calendar($cid); if (!$calendar->can_write()) { permission_error(__('You do not have permission to write to this calendar.')); } if ($calendar->can_create_readonly() && !empty($vars['readonly'])) { $readonly = true; } else { $readonly = false; } $catid = empty($vars['catid']) ? false : $vars['catid']; if (!isset($vars['eid'])) { $modify = false; $eid = $phpcdb->create_event($cid, $phpc_user->get_uid(), $vars["subject"], $vars["description"], $readonly, $catid); } else { $modify = true; $eid = $vars['eid']; $phpcdb->modify_event($eid, $vars['subject'], $vars['description'], $readonly, $catid); if ($modify_occur) { $phpcdb->delete_occurrences($eid); } } foreach ($phpc_cal->get_fields() as $field) { $fid = $field['fid']; if (empty($vars["phpc-field-{$fid}"])) { if ($field['required']) { throw new Exception(sprintf(__('Field "%s" is required but was not set.'), $field['name'])); } continue; } $phpcdb->add_event_field($eid, $fid, $vars["phpc-field-{$fid}"]); } if ($modify_occur) { $occurrences = 0; $n = 1; $until = $start_ts; switch ($vars['repeats']) { case 'daily': check_input("every-day"); $n = $vars["every-day"]; $until = get_timestamp("daily-until"); break; case 'weekly': check_input("every-week"); $n = $vars["every-week"] * 7; $until = get_timestamp("weekly-until"); break; case 'monthly': check_input("every-month"); $n = $vars["every-month"]; $until = get_timestamp("monthly-until"); break; case 'yearly': check_input("every-year"); $n = $vars["every-year"]; $until = get_timestamp("yearly-until"); break; } if ($n < 1) { soft_error(__('Increment must be 1 or greater.')); } while ($occurrences <= 730 && days_between($start_ts, $until) >= 0) { $oid = $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; switch ($vars["repeats"]) { case 'daily': case 'weekly': $start_ts = add_days($start_ts, $n); $end_ts = add_days($end_ts, $n); break; case 'monthly': $start_ts = add_months($start_ts, $n); $end_ts = add_months($end_ts, $n); break; case 'yearly': $start_ts = add_years($start_ts, $n); $end_ts = add_years($end_ts, $n); break; default: break 2; } } } if ($eid != 0) { if ($modify) { $message = __("Modified event: "); } else { $message = __("Created event: "); } return message_redirect(tag('', $message, create_event_link($eid, 'display_event', $eid)), "{$phpc_script}?action=display_event&eid={$eid}"); } else { return message_redirect(__('Error submitting event.'), "{$phpc_script}?action=display_month&phpcid={$cid}"); } }