Copyright 2003-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Автор: Mike Cochrane (mike@graftonhall.co.nz)
Наследование: extends Horde_Icalendar
Пример #1
0
 /**
  * Creates a task from a Horde_Icalendar_Vtodo object.
  *
  * @param Horde_Icalendar_Vtodo $vTodo  The iCalendar data to update from.
  */
 public function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)
 {
     /* Owner is always current user. */
     $this->owner = $GLOBALS['registry']->getAuth();
     try {
         $name = $vTodo->getAttribute('SUMMARY');
         if (!is_array($name)) {
             $this->name = $name;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // Not sure why we were mapping the ORGANIZER to the person the
     // task is assigned to? If anything, this needs to be mapped to
     // any ATTENDEE fields from the vTodo.
     // try {
     //     $assignee = $vTodo->getAttribute('ORGANIZER');
     //     if (!is_array($assignee)) { $this->assignee = $assignee; }
     // } catch (Horde_Icalendar_Exception $e) {}
     try {
         $organizer = $vTodo->getAttribute('ORGANIZER');
         if (!is_array($organizer)) {
             $this->organizer = $organizer;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // If an attendee matches our from_addr, add current user as assignee.
     try {
         $atnames = $vTodo->getAttribute('ATTENDEE');
         if (!is_array($atnames)) {
             $atnames = array($atnames);
         }
         $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
         $all_addrs = $identity->getAll('from_addr');
         foreach ($atnames as $index => $attendee) {
             if ($vTodo->getAttribute('VERSION') < 2) {
                 $addr_ob = new Horde_Mail_Rfc822_Address($attendee);
                 if (!$addr_ob->valid) {
                     continue;
                 }
                 $attendee = $addr_ob->bare_address;
                 $name = $addr_ob->personal;
             } else {
                 $attendee = str_ireplace('mailto:', '', $attendee);
                 $addr_ob = new Horde_Mail_Rfc822_Address($attendee);
                 if (!$addr_ob->valid) {
                     continue;
                 }
                 $attendee = $addr_ob->bare_address;
                 $name = isset($atparms[$index]['CN']) ? $atparms[$index]['CN'] : null;
             }
             if (in_array($attendee, $all_addrs) !== false) {
                 $this->assignee = $GLOBALS['conf']['assignees']['allow_external'] ? $attendee : $GLOBALS['registry']->getAuth();
                 $this->status = Nag::RESPONSE_ACCEPTED;
                 break;
             } elseif ($GLOBALS['conf']['assignees']['allow_external']) {
                 $this->assignee = $attendee;
             }
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // Default to current user as organizer
     if (empty($this->organizer) && !empty($this->assignee)) {
         $this->organizer = $identity->getValue('from_addr');
     }
     try {
         $uid = $vTodo->getAttribute('UID');
         if (!is_array($uid)) {
             $this->uid = $uid;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $relations = $vTodo->getAttribute('RELATED-TO');
         if (!is_array($relations)) {
             $relations = array($relations);
         }
         $params = $vTodo->getAttribute('RELATED-TO', true);
         foreach ($relations as $id => $relation) {
             if (empty($params[$id]['RELTYPE']) || Horde_String::upper($params[$id]['RELTYPE']) == 'PARENT') {
                 try {
                     $parent = $this->_storage->getByUID($relation, $this->tasklist);
                     $this->parent_id = $parent->id;
                 } catch (Horde_Exception_NotFound $e) {
                 }
                 break;
             }
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $start = $vTodo->getAttribute('DTSTART');
         if (!is_array($start)) {
             // Date-Time field
             $this->start = $start;
         } else {
             // Date field
             $this->start = mktime(0, 0, 0, (int) $start['month'], (int) $start['mday'], (int) $start['year']);
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $due = $vTodo->getAttribute('DUE');
         if (is_array($due)) {
             $this->due = mktime(0, 0, 0, (int) $due['month'], (int) $due['mday'], (int) $due['year']);
         } elseif (!empty($due)) {
             $this->due = $due;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // Recurrence.
     try {
         $rrule = $vTodo->getAttribute('RRULE');
         if (!is_array($rrule)) {
             $this->recurrence = new Horde_Date_Recurrence($this->due);
             if (strpos($rrule, '=') !== false) {
                 $this->recurrence->fromRRule20($rrule);
             } else {
                 $this->recurrence->fromRRule10($rrule);
             }
             // Completions. EXDATE represents completed tasks, just add the
             // exception.
             $exdates = $vTodo->getAttributeValues('EXDATE');
             if (is_array($exdates)) {
                 foreach ($exdates as $exdate) {
                     if (is_array($exdate)) {
                         $this->recurrence->addCompletion((int) $exdate['year'], (int) $exdate['month'], (int) $exdate['mday']);
                     }
                 }
             }
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // vCalendar 1.0 alarms
     try {
         $alarm = $vTodo->getAttribute('AALARM');
         if (!is_array($alarm) && !empty($alarm) && !empty($this->due)) {
             $this->alarm = intval(($this->due - $alarm) / 60);
             if ($this->alarm === 0) {
                 // We don't support alarms exactly at due date.
                 $this->alarm = 1;
             }
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // vCalendar 2.0 alarms
     foreach ($vTodo->getComponents() as $alarm) {
         if (!$alarm instanceof Horde_Icalendar_Valarm) {
             continue;
         }
         try {
             if ($alarm->getAttribute('ACTION') == 'NONE') {
                 continue;
             }
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             // @todo consider implementing different ACTION types.
             // $action = $alarm->getAttribute('ACTION');
             $trigger = $alarm->getAttribute('TRIGGER');
             $triggerParams = $alarm->getAttribute('TRIGGER', true);
         } catch (Horde_Icalendar_Exception $e) {
             continue;
         }
         if (!is_array($triggerParams)) {
             $triggerParams = array($triggerParams);
         }
         $haveTrigger = false;
         foreach ($triggerParams as $tp) {
             if (isset($tp['VALUE']) && $tp['VALUE'] == 'DATE-TIME') {
                 if (isset($tp['RELATED']) && $tp['RELATED'] == 'END') {
                     if ($this->due) {
                         $this->alarm = intval(($this->due - $trigger) / 60);
                         $haveTrigger = true;
                         break;
                     }
                 } else {
                     if ($this->start) {
                         $this->alarm = intval(($this->start - $trigger) / 60);
                         $haveTrigger = true;
                         break;
                     }
                 }
             } elseif (isset($tp['RELATED']) && $tp['RELATED'] == 'END' && $this->due && $this->start) {
                 $this->alarm = -intval($trigger / 60);
                 $this->alarm -= $this->due - $this->start;
                 $haveTrigger = true;
                 break;
             }
         }
         if (!$haveTrigger) {
             $this->alarm = -intval($trigger / 60);
         }
         break;
     }
     // Alarm snoozing/dismissal
     if ($this->alarm) {
         try {
             // If X-MOZ-LASTACK is set, this task is either dismissed or
             // snoozed.
             $vTodo->getAttribute('X-MOZ-LASTACK');
             try {
                 // If X-MOZ-SNOOZE-TIME is set, this task is snoozed.
                 $snooze = $vTodo->getAttribute('X-MOZ-SNOOZE-TIME');
                 $this->snooze = intval(($snooze - time()) / 60);
             } catch (Horde_Icalendar_Exception $e) {
                 // If X-MOZ-SNOOZE-TIME is not set, this event is dismissed.
                 $this->snooze = -1;
             }
         } catch (Horde_Icalendar_Exception $e) {
         }
     }
     try {
         $desc = $vTodo->getAttribute('DESCRIPTION');
         if (!is_array($desc)) {
             $this->desc = $desc;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $priority = $vTodo->getAttribute('PRIORITY');
         if (!is_array($priority)) {
             $this->priority = $priority;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $cat = $vTodo->getAttribute('CATEGORIES');
         if (!is_array($cat)) {
             $this->tags = $cat;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $status = $vTodo->getAttribute('STATUS');
         if (!is_array($status)) {
             $this->completed = !strcasecmp($status, 'COMPLETED');
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $class = $vTodo->getAttribute('CLASS');
         if (!is_array($class)) {
             $class = Horde_String::upper($class);
             $this->private = $class == 'PRIVATE' || $class == 'CONFIDENTIAL';
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
 }
Пример #2
0
 /**
  * Updates an attendee's response status for a specified task assignment.
  *
  * @param Horde_Icalendar_Vtodo $response  A Horde_Icalendar_Vtodo
  *                                          object, with a valid UID
  *                                          attribute that points to an
  *                                          existing task.  This is
  *                                          typically the vTodo portion
  *                                          of an iTip task-request
  *                                          response, with the attendee's
  *                                          response in an ATTENDEE
  *                                          parameter.
  * @param string $sender                    The email address of the
  *                                          person initiating the
  *                                          update. Attendees are only
  *                                          updated if this address
  *                                          matches.
  *
  * @throws Nag_Exception, Horde_Exception_PermissionDenied
  */
 public function updateAttendee($response, $sender = null)
 {
     try {
         $uid = $response->getAttribute('UID');
     } catch (Horde_Icalendar_Exception $e) {
         throw new Kronolith_Exception($e);
     }
     $task = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create('')->getByUID($uid);
     $taskId = $task->id;
     $owner = $task->owner;
     if (!Nag::hasPermission($task->tasklist, Horde_Perms::EDIT)) {
         throw new Horde_Exception_PermissionDenied();
     }
     try {
         $atnames = $response->getAttribute('ATTENDEE');
     } catch (Horde_Icalendar_Exception $e) {
         throw new Nag_Exception($e->getMessage());
     }
     if (!is_array($atnames)) {
         $atnames = array($atnames);
     }
     $atparms = $response->getAttribute('ATTENDEE', true);
     $found = false;
     $error = _("No attendees have been updated because none of the provided email addresses have been found in the event's attendees list.");
     foreach ($atnames as $index => $attendee) {
         if ($response->getAttribute('VERSION') < 2) {
             $addr_ob = new Horde_Mail_Rfc822_Address($attendee);
             if (!$addr_ob->valid) {
                 continue;
             }
             $attendee = $addr_ob->bare_address;
             $name = $addr_ob->personal;
         } else {
             $attendee = str_ireplace('mailto:', '', $attendee);
             $name = isset($atparms[$index]['CN']) ? $atparms[$index]['CN'] : null;
         }
         $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($task->assignee);
         $all_addrs = $identity->getAll('from_addr');
         if (in_array($attendee, $all_addrs)) {
             if (is_null($sender) || $sender == $attendee) {
                 $task->status = Nag::responseFromICal($atparms[$index]['PARTSTAT']);
                 $found = true;
                 break;
             } else {
                 $error = _("The attendee hasn't been updated because the update was not sent from the attendee.");
             }
         }
     }
     $task->save();
     if (!$found) {
         throw new Nag_Exception($error);
     }
 }
Пример #3
0
 /**
  * Creates a task from a Horde_Icalendar_Vtodo object.
  *
  * @param Horde_Icalendar_Vtodo $vTodo  The iCalendar data to update from.
  */
 public function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)
 {
     /* Owner is always current user. */
     $this->owner = $GLOBALS['registry']->getAuth();
     try {
         $name = $vTodo->getAttribute('SUMMARY');
         if (!is_array($name)) {
             $this->name = $name;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $assignee = $vTodo->getAttribute('ORGANIZER');
         if (!is_array($assignee)) {
             $this->assignee = $assignee;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $uid = $vTodo->getAttribute('UID');
         if (!is_array($uid)) {
             $this->uid = $uid;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $relations = $vTodo->getAttribute('RELATED-TO');
         if (!is_array($relations)) {
             $relations = array($relations);
         }
         $params = $vTodo->getAttribute('RELATED-TO', true);
         foreach ($relations as $id => $relation) {
             if (empty($params[$id]['RELTYPE']) || Horde_String::upper($params[$id]['RELTYPE']) == 'PARENT') {
                 $parent = $this->_storage->getByUID($relation);
                 $this->parent_id = $parent->id;
                 break;
             }
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $start = $vTodo->getAttribute('DTSTART');
         if (!is_array($start)) {
             // Date-Time field
             $this->start = $start;
         } else {
             // Date field
             $this->start = mktime(0, 0, 0, (int) $start['month'], (int) $start['mday'], (int) $start['year']);
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $due = $vTodo->getAttribute('DUE');
         if (is_array($due)) {
             $this->due = mktime(0, 0, 0, (int) $due['month'], (int) $due['mday'], (int) $due['year']);
         } elseif (!empty($due)) {
             $this->due = $due;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // vCalendar 1.0 alarms
     try {
         $alarm = $vTodo->getAttribute('AALARM');
         if (!is_array($alarm) && !empty($alarm) && !empty($this->due)) {
             $this->alarm = intval(($this->due - $alarm) / 60);
             if ($this->alarm === 0) {
                 // We don't support alarms exactly at due date.
                 $this->alarm = 1;
             }
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // @TODO: vCalendar 2.0 alarms
     try {
         $desc = $vTodo->getAttribute('DESCRIPTION');
         if (!is_array($desc)) {
             $this->desc = $desc;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $priority = $vTodo->getAttribute('PRIORITY');
         if (!is_array($priority)) {
             $this->priority = $priority;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $cat = $vTodo->getAttribute('CATEGORIES');
         if (!is_array($cat)) {
             $this->tags = $cat;
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $status = $vTodo->getAttribute('STATUS');
         if (!is_array($status)) {
             $this->completed = !strcasecmp($status, 'COMPLETED');
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $class = $vTodo->getAttribute('CLASS');
         if (!is_array($class)) {
             $class = Horde_String::upper($class);
             $this->private = $class == 'PRIVATE' || $class == 'CONFIDENTIAL';
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
 }
Пример #4
0
 /**
  * Set the organizer of the iTip event.
  *
  * @param string $organizer  The organizer of the event.
  * @param array  $parameters Additional parameters.
  *
  * @return NULL
  */
 private function setOrganizer($organizer, $parameters)
 {
     $this->_vevent->setAttribute('ORGANIZER', $organizer, $parameters);
 }