Example #1
0
 /**
  * Search for shared or otherwise not listed calendars the user has access
  *
  * @param string Search string
  * @param string Section/source to search
  * @return array List of calendars
  */
 public function search_calendars($query, $source)
 {
     if (!kolab_storage::setup()) {
         return array();
     }
     $this->calendars = array();
     $this->search_more_results = false;
     // find unsubscribed IMAP folders that have "event" type
     if ($source == 'folders') {
         foreach ((array) kolab_storage::search_folders('event', $query, array('other')) as $folder) {
             $calendar = new kolab_calendar($folder->name, $this->cal);
             $this->calendars[$calendar->id] = $calendar;
         }
     } else {
         if ($source == 'users') {
             $limit = $this->rc->config->get('autocomplete_max', 15) * 2;
             // we have slightly more space, so display twice the number
             foreach (kolab_storage::search_users($query, 0, array(), $limit, $count) as $user) {
                 $calendar = new kolab_user_calendar($user, $this->cal);
                 $this->calendars[$calendar->id] = $calendar;
                 // search for calendar folders shared by this user
                 foreach (kolab_storage::list_user_folders($user, 'event', false) as $foldername) {
                     $cal = new kolab_calendar($foldername, $this->cal);
                     $this->calendars[$cal->id] = $cal;
                     $calendar->subscriptions = true;
                 }
             }
             if ($count > $limit) {
                 $this->search_more_results = true;
             }
         }
     }
     // don't list the birthday calendar
     $this->rc->config->set('calendar_contact_birthdays', false);
     $this->rc->config->set('kolab_invitation_calendars', false);
     return $this->list_calendars();
 }
 /**
  * @param  integer Event's new start (unix timestamp)
  * @param  integer Event's new end (unix timestamp)
  * @param  string  Search query (optional)
  * @param  boolean Include virtual events (optional)
  * @param  array   Additional parameters to query storage
  * @return array A list of event records
  */
 public function list_events($start, $end, $search = null, $virtual = 1, $query = array())
 {
     // convert to DateTime for comparisons
     try {
         $start_dt = new DateTime('@' . $start);
     } catch (Exception $e) {
         $start_dt = new DateTime('@0');
     }
     try {
         $end_dt = new DateTime('@' . $end);
     } catch (Exception $e) {
         $end_dt = new DateTime('today +10 years');
     }
     $limit_changed = null;
     if (!empty($query)) {
         foreach ($query as $q) {
             if ($q[0] == 'changed' && $q[1] == '>=') {
                 try {
                     $limit_changed = new DateTime('@' . $q[2]);
                 } catch (Exception $e) {
                     /* ignore */
                 }
             }
         }
     }
     // aggregate all calendar folders the user shares (but are not subscribed)
     foreach (kolab_storage::list_user_folders($this->userdata, 'event', false) as $foldername) {
         $cal = new kolab_calendar($foldername, $this->cal);
         foreach ($cal->list_events($start, $end, $search, 1) as $event) {
             $this->events[$event['id']] = $event;
             $this->timeindex[$this->time_key($event)] = $event['id'];
         }
     }
     // get events from the user's free/busy feed (for quickview only)
     $fbview = $this->cal->rc->config->get('calendar_include_freebusy_data', 1);
     if ($fbview && ($fbview == 1 || !empty($_REQUEST['_quickview'])) && empty($search)) {
         $this->fetch_freebusy($limit_changed);
     }
     $events = array();
     foreach ($this->events as $event) {
         // list events in requested time window
         if ($event['start'] <= $end_dt && $event['end'] >= $start_dt && (!$limit_changed || !$event['changed'] || $event['changed'] >= $limit_changed)) {
             $events[] = $event;
         }
     }
     // avoid session race conditions that will loose temporary subscriptions
     $this->cal->rc->session->nowrite = true;
     return $events;
 }
 /**
  * Search for shared or otherwise not listed tasklists the user has access
  *
  * @param string Search string
  * @param string Section/source to search
  * @return array List of tasklists
  */
 public function search_lists($query, $source)
 {
     if (!kolab_storage::setup()) {
         return array();
     }
     $this->search_more_results = false;
     $this->lists = $this->folders = array();
     // find unsubscribed IMAP folders that have "event" type
     if ($source == 'folders') {
         foreach ((array) kolab_storage::search_folders('task', $query, array('other')) as $folder) {
             $this->folders[$folder->id] = $folder;
             $this->lists[$folder->id] = $this->folder_props($folder, array());
         }
     } else {
         if ($source == 'users') {
             $limit = $this->rc->config->get('autocomplete_max', 15) * 2;
             // we have slightly more space, so display twice the number
             foreach (kolab_storage::search_users($query, 0, array(), $limit * 10) as $user) {
                 $folders = array();
                 // search for tasks folders shared by this user
                 foreach (kolab_storage::list_user_folders($user, 'task', false) as $foldername) {
                     $folders[] = new kolab_storage_folder($foldername, 'task');
                 }
                 if (count($folders)) {
                     $userfolder = new kolab_storage_folder_user($user['kolabtargetfolder'], '', $user);
                     $this->folders[$userfolder->id] = $userfolder;
                     $this->lists[$userfolder->id] = $this->folder_props($userfolder, array());
                     foreach ($folders as $folder) {
                         $this->folders[$folder->id] = $folder;
                         $this->lists[$folder->id] = $this->folder_props($folder, array());
                         $count++;
                     }
                 }
                 if ($count >= $limit) {
                     $this->search_more_results = true;
                     break;
                 }
             }
         }
     }
     return $this->get_lists();
 }