function events($EventId = FALSE, $OccurrenceId = FALSE)
 {
     show_404();
     if (FALSE !== $EventId && !is_numeric($EventId)) {
         show_404();
     }
     if (FALSE !== $OccurrenceId && !is_numeric($OccurrenceId)) {
         show_404();
     }
     if (!CheckPermissions('vip+pr')) {
         return;
     }
     $this->load->model('calendar/events_model');
     $this->load->model('calendar/recurrence_model');
     $this->load->helper('text');
     if (FALSE === $EventId) {
         // Quick thingy to add atandard english calendar rules to current
         // organisation. Note they aren't created with occurrences.
         if (FALSE) {
             $rules = $this->RuleCollectionStdEngland();
             foreach ($rules as $info) {
                 $name = $info[0];
                 $rule = $info[1];
                 /// @todo Update for new recurrence system
                 $rule_id = $this->recurrence_model->AddRule($rule);
                 if (FALSE === $rule_id) {
                     $this->messages->AddMessage('warning', 'RRule named ' . $name . ' could not be added');
                 } else {
                     $new_event = array('name' => $name, 'recurrence_rule_id' => $rule_id);
                     try {
                         $result = $this->events_model->EventCreate($new_event);
                         $this->messages->AddMessage('success', 'added ' . $name);
                     } catch (Exception $e) {
                         $this->messages->AddMessage('error', 'while creating event ' . $name . ': ' . $e->getMessage());
                     }
                 }
             }
         }
         $fields = array('event_id' => 'events.event_id', 'name' => 'events.event_name', 'description' => 'events.event_description');
         $results = $this->events_model->EventsGet($fields, FALSE, TRUE);
         $events = array();
         if (FALSE !== $results) {
             foreach ($results as $result) {
                 if (!array_key_exists($result['event_id'], $events)) {
                     $events[$result['event_id']] = $result;
                 }
             }
         }
         $op = '<OL>';
         foreach ($events as $event) {
             if (array_key_exists('event_recurrence_rule', $event) && NULL != $event['event_recurrence_rule']) {
                 $event['description'] = $event['event_recurrence_rule']->ToString() . ' - ' . $event['description'];
             }
             $op .= '<LI><A HREF="' . vip_url('calendar/events/' . $event['event_id']) . '">' . $event['name'] . '</A> - ' . $event['description'] . '</LI>';
         }
         $op .= '</OL>';
         $this->main_frame->SetTitle('Events');
         $this->main_frame->SetContent(new SimpleView($op));
     } else {
         $special_condition = 'events.event_id=' . $EventId;
         if (FALSE === $OccurrenceId) {
             $filter = new EventOccurrenceFilter();
             $filter->DisableSource('subscribed');
             $filter->SetSpecialCondition($special_condition);
             $fields = array('occurrence_id' => 'event_occurrences.event_occurrence_id', 'start' => 'event_occurrences.event_occurrence_start_time', 'end' => 'event_occurrences.event_occurrence_end_time', 'status' => $filter->ExpressionPublicState());
             $results = $filter->GenerateOccurrences($fields);
             $occurrences = array();
             foreach ($results as $result) {
                 if (!array_key_exists($result['occurrence_id'], $occurrences)) {
                     $occurrences[$result['occurrence_id']] = $result;
                 }
             }
             $op = '<H4>Existing occurrences</H4>';
             $op .= '<OL>';
             foreach ($occurrences as $occurrence) {
                 $operations = array();
                 if ($occurrence['status'] === 'draft') {
                     $operations[] = 'publish';
                     $operations[] = 'trash';
                 }
                 if ($occurrence['status'] === 'movedraft') {
                     $operations[] = 'publishmove';
                     $operations[] = 'restoremove';
                     $operations[] = 'cancelmove';
                 }
                 if ($occurrence['status'] === 'trashed') {
                     $operations[] = 'untrash';
                 }
                 if ($occurrence['status'] === 'published') {
                     $operations[] = 'cancel';
                     $operations[] = 'postpone';
                 }
                 if ($occurrence['status'] === 'cancelled') {
                     $operations[] = 'uncancel';
                     $operations[] = 'postpone';
                 }
                 $links = array();
                 foreach ($operations as $operation) {
                     $links[] = '<A HREF="' . vip_url('calendar/occop/' . $operation . '/' . $EventId . '/' . $occurrence['occurrence_id']) . '">' . $operation . '</A>';
                 }
                 $op .= '<LI>' . $occurrence['status'] . ' <A HREF="' . vip_url('calendar/events/' . $EventId . '/' . $occurrence['occurrence_id']) . '">' . $occurrence['start'] . ' -> ' . $occurrence['end'] . '</A> ' . ' (' . implode(', ', $links) . ') </LI>';
             }
             $op .= '</OL>';
             // Get event information
             $events = $this->events_model->EventsGet(array('events.*'), $EventId, TRUE);
             // If theres a recurrence rule, use it to generate the next two
             // years occurrences
             if (isset($events[0]['event_recurrence_rule'])) {
                 $op .= '<H4>Generated occurrences in next 5 years</H4>';
                 $op .= '<P><em>' . $events[0]['event_recurrence_rule']->ToString() . '</em></P>';
                 $occurrences_calculated = array_keys($events[0]['event_recurrence_rule']->FindTimes(time(), strtotime('+5years')));
                 foreach ($occurrences_calculated as $key => $timestamp) {
                     $occurrences_calculated[$key] = date(DATE_RFC822, $timestamp);
                 }
                 $op .= '<pre>' . ascii_to_entities(var_export($occurrences_calculated, true)) . '</pre>';
             }
             $op .= '<H4>Event information</H4>';
             $op .= '<pre>' . ascii_to_entities(var_export($events, true)) . '</pre>';
             $op .= '<H4>RSVP list</H4>';
             $rsvps = $this->events_model->GetEventRsvp($EventId);
             $op .= '<pre>' . ascii_to_entities(var_export($rsvps, true)) . '</pre>';
             $this->main_frame->SetTitle('Events');
             $this->main_frame->SetContent(new SimpleView($op));
         } else {
             $special_condition .= ' AND event_occurrences.event_occurrence_id=' . $OccurrenceId;
             $filter = new EventOccurrenceFilter();
             $filter->DisableSource('subscribed');
             $filter->SetRange(strtotime('-1year'), strtotime('+1year'));
             $filter->SetSpecialCondition($special_condition);
             $result = $filter->GenerateOccurrences(array('occurrence_id' => 'event_occurrences.event_occurrence_id', 'start' => 'event_occurrences.event_occurrence_start_time', 'end' => 'event_occurrences.event_occurrence_end_time', 'active_id' => 'event_occurrences.event_occurrence_active_occurrence_id', 'rescheduled_start' => 'active_occurrence.event_occurrence_start_time', 'rescheduled_end' => 'active_occurrence.event_occurrence_end_time', 'status' => $filter->ExpressionPublicState(), 'cancelled' => $filter->ExpressionPublicCancelled(), 'postponed' => $filter->ExpressionPublicPostponed(), 'rescheduled' => $filter->ExpressionPublicRescheduled(), 'ts' => 'event_occurrences.event_occurrence_last_modified'));
             $rsvps = $this->events_model->GetOccurrenceRsvp($OccurrenceId);
             $op = '<pre>' . ascii_to_entities(var_export($result, true)) . '</pre><pre>' . ascii_to_entities(var_export($rsvps, true)) . '</pre>';
             $this->main_frame->SetContent(new SimpleView($op));
         }
     }
     // Load the main frame
     $this->main_frame->Load();
 }