Exemple #1
0
 /**
  * Purge old events.
  *
  * @throws Kronolith_Exception
  * @throws Horde_Exception_NotFound
  */
 public function execute()
 {
     /* Get the current time minus the number of days specified in
      * 'purge_events_keep'.  An event will be deleted if it has an end
      * time prior to this time. */
     $del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
     $del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep');
     /* Need to have Horde_Perms::DELETE on a calendar to delete events
      * from it */
     $calendars = Kronolith::listInternalCalendars(true, Horde_Perms::DELETE);
     /* Start building the search */
     $kronolith_driver = Kronolith::getDriver();
     $query = new StdClass();
     $query->start = null;
     $query->end = $del_time;
     $query->status = null;
     $query->calendars = array(Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']) => array_keys($calendars));
     $query->creator = $GLOBALS['registry']->getAuth();
     /* Perform the search */
     $days = Kronolith::search($query);
     $count = 0;
     foreach ($days as $events) {
         foreach ($events as $event) {
             /* Delete if no recurrence, or if we are past the last occurence */
             if (!$event->recurs() || $event->recurrence->nextRecurrence($del_time) == false) {
                 if ($event->calendar != $kronolith_driver->calendar) {
                     $kronolith_driver->open($event->calendar);
                 }
                 try {
                     $kronolith_driver->deleteEvent($event->id, true);
                     ++$count;
                 } catch (Exception $e) {
                     Horde::log($e, 'ERR');
                     throw $e;
                 }
             }
         }
     }
     $GLOBALS['notification']->push(sprintf(ngettext("Deleted %d event older than %d days.", "Deleted %d events older than %d days.", $count), $count, $GLOBALS['prefs']->getValue('purge_events_keep')));
 }
Exemple #2
0
 /* Make a new empty event object with default values. */
 $event = Kronolith::getDriver($search_calendar[0], $search_calendar[1])->getEvent();
 $event->title = $event->location = $event->status = $event->description = null;
 /* Set start on today, stop on tomorrow. */
 $event->start = new Horde_Date(mktime(0, 0, 0));
 $event->end = new Horde_Date($event->start);
 $event->end->mday++;
 /* We need to set the event to initialized, otherwise we will end up with
  * a default end date. */
 $event->initialized = true;
 if (Horde_Util::getFormData('actionID') == 'search_calendar') {
     $event->readForm();
     if (Horde_Util::getFormData('status') == Kronolith::STATUS_NONE) {
         $event->status = null;
     }
     $events = Kronolith::search($event, $search_calendar[1] == '__any' ? null : $search_calendar[0] . '|' . $search_calendar[1]);
 }
 $optgroup = $GLOBALS['browser']->hasFeature('optgroup');
 $current_user = $GLOBALS['registry']->getAuth();
 $calendars = array();
 foreach (Kronolith::listInternalCalendars(false, Horde_Perms::READ) as $id => $cal) {
     if ($cal->get('owner') && $cal->get('owner') == $current_user) {
         $calendars[_("My Calendars:")]['|' . $id] = $cal->get('name');
     } else {
         $calendars[_("Shared Calendars:")]['|' . $id] = Kronolith::getLabel($cal);
     }
 }
 foreach ($GLOBALS['calendar_manager']->get(Kronolith::ALL_EXTERNAL_CALENDARS) as $id => $cal) {
     $app = $GLOBALS['registry']->get('name', $GLOBALS['registry']->hasInterface($cal->api()));
     if (!$cal->display()) {
         continue;