function GetEvent($SourceId = NULL, $EventId = NULL, $OccurrenceId = NULL)
 {
     if (is_numeric($SourceId)) {
         $SourceId = (int) $SourceId;
         $CI =& get_instance();
         // Get the specific event
         $CI->load->helper('uri_tail');
         $CI->load->library('calendar_backend');
         $CI->load->library('calendar_source_my_calendar');
         $sources = new CalendarSourceMyCalendar();
         $calendar_data = new CalendarData();
         $sources->FetchEvent($calendar_data, $SourceId, $EventId);
         $events = $calendar_data->GetEvents();
         if (array_key_exists(0, $events)) {
             $event = $events[0];
             // Find the occurrence
             $found_occurrence = NULL;
             foreach ($event->Occurrences as $key => $occurrence) {
                 if ($occurrence->SourceOccurrenceId == $OccurrenceId) {
                     $found_occurrence =& $event->Occurrences[$key];
                     break;
                 }
             }
             if (NULL === $found_occurrence) {
                 return show_404();
             }
             if ($CI->input->post('evview_return')) {
                 // REDIRECT
                 $CI->load->helper('uri_tail');
                 RedirectUriTail(5);
             } else {
                 $data = array('Event' => &$event, 'Occurrence' => &$found_occurrence, 'ReadOnly' => $this->mReadOnly, 'Attendees' => $sources->GetOccurrenceAttendanceList($SourceId, $OccurrenceId), 'FailRedirect' => '/' . GetUriTail(5), 'Path' => $this->mPaths);
                 $CI->main_frame->SetTitleParameters(array('event' => $event->Name));
                 $this->SetupTabs('', $found_occurrence->StartTime);
                 return new FramesView('calendar/event', $data);
             }
         } else {
             $CI->messages->AddMessage('error', 'The event coud not be found');
             RedirectUriTail(5);
         }
     } else {
         show_404();
     }
 }
 /**
  * Any additional uri segments are used as the redirect address after
  *	successful login.
  */
 function facebook()
 {
     $this->load->library('facebook');
     $this->facebook->Enable();
     RedirectUriTail(2);
 }
 function publish($EventId = NULL)
 {
     if (!CheckPermissions('vip+pr')) {
         return;
     }
     if (is_numeric($EventId)) {
         $EventId = (int) $EventId;
         // Get the specific event
         $this->load->library('calendar_backend');
         $this->load->library('calendar_source_yorker');
         $source_yorker = new CalendarSourceYorker(0);
         $calendar_data = new CalendarData();
         $source_yorker->FetchEvent($calendar_data, $EventId);
         $events = $calendar_data->GetEvents();
         if (array_key_exists(0, $events)) {
             $event = $events[0];
             if ($this->input->post('evpub_cancel')) {
                 // REDIRECT
                 $this->messages->AddMessage('information', 'Event publication was cancelled.');
                 $this->load->helper('uri_tail');
                 RedirectUriTail(3);
             } elseif ($this->input->post('evpub_confirm')) {
                 // PUBLISH
                 $result = $this->events_model->OccurrenceDraftPublish($EventId, FALSE);
                 if ($result > 0) {
                     $this->messages->AddMessage('success', $result . ' occurrences were altered');
                 } else {
                     print_r($this->db->last_query());
                     exit;
                     $this->messages->AddMessage('error', 'No occurrences were altered');
                 }
                 $this->load->helper('uri_tail');
                 RedirectUriTail(3);
             } else {
                 $data = array('Event' => $event);
                 $this->main_frame->SetContentSimple('calendar/publish', $data);
                 $this->main_frame->Load();
             }
         } else {
             $this->messages->AddMessage('error', 'The event coud not be found');
             $this->load->helper('uri_tail');
             RedirectUriTail(3);
         }
     } else {
         show_404();
     }
 }