Esempio n. 1
0
 /**
  *
  * @license    http://www.gnu.org/copyleft/gpl.html GPL
  * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
  * @sponsor    Caixa Econômica Federal
  * @author     Cristiano Corrêa Schmidt
  * @return     void
  * @access     public
  */
 public function createCalendarToSchedulable(&$uri, &$result, &$data, $original)
 {
     foreach ($data as $i => $concept) {
         if ($concept['concept'] === 'calendarToSchedulable') {
             if (Config::module('useCaldav', 'expressoCalendar')) {
                 ob_start();
                 $calendarToschedulable = Controller::read(array('concept' => 'calendarToSchedulable', 'id' => $concept['id']));
                 if ($calendarToschedulable) {
                     $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $calendarToschedulable['schedulable']), null, array('deepness' => '2'));
                     $calendar = Controller::read(array('concept' => 'calendar', 'id' => $calendarToschedulable['calendar']), array('timezone', 'name', 'location'));
                     $ical = Controller::format(array('service' => 'iCal'), array($schedulable), array('defaultTZI' => $calendar['timezone']));
                     DAViCalAdapter::putIcal($ical, array('uid' => $schedulable['uid'], 'location' => $calendar['location']));
                 }
                 ob_end_clean();
             }
         }
     }
 }
Esempio n. 2
0
 public function analize($data, $params = false)
 {
     $vcalendar = new icalCreatorVcalendar();
     $vcalendar->parse(trim($data));
     $vcalendar->sort();
     $return = array();
     $method = $vcalendar->getProperty('method', FALSE, FALSE);
     while ($component = $vcalendar->getComponent()) {
         $interation = array();
         $uid = $component->getProperty('uid', false, false);
         //Resgata o uid do componente
         switch (strtoupper($component->objName)) {
             case 'VEVENT':
                 switch ($method) {
                     case 'PUBLISH':
                         $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');
                         break;
                     case 'REQUEST':
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable) {
                             //Caso o evento exista
                             $isOrganizer = false;
                             $isParticipant = false;
                             foreach ($schedulable['participants'] as $value) {
                                 if ($value['user']['id'] == $params['owner']) {
                                     $isParticipant = true;
                                     if ($value['isOrganizer']) {
                                         $isOrganizer = true;
                                     }
                                     if (!self::_existInMyCalendars($schedulable['id'], $params['owner']) || $value['status'] == STATUS_UNANSWERED || $value['status'] == STATUS_DECLINED) {
                                         $interation = ICAL_ACTION_UPDATE;
                                         $interation = strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ? ICAL_ACTION_IMPORT_REQUIRED : array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');
                                         break;
                                     } else {
                                         if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) {
                                             //Organizador esta requisitando que você atualize o evento
                                             $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE;
                                         } else {
                                             $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE;
                                         }
                                     }
                                 }
                             }
                             if (!$isParticipant) {
                                 if (self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                     $interation = self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] ? ICAL_ACTION_UPDATE : ICAL_ACTION_NONE;
                                 } else {
                                     $interation = self::_checkParticipantByPermissions($schedulable);
                                 }
                             }
                         } else {
                             $interation = array('action' => ICAL_ACTION_IMPORT_REQUIRED, 'type' => 'calendarIds');
                         }
                         if ($interation != ICAL_ACTION_NONE && $interation != ICAL_ACTION_ORGANIZER_NONE && $interation != ICAL_ACTION_ORGANIZER_UPDATE && $interation != ICAL_ACTION_NONE && $interation != ICAL_ACTION_UPDATE && !is_array($interation)) {
                             if ($params['owner'] != Config::me("uidNumber")) {
                                 $sig = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=', 'user', $params['owner']), array('=', 'isOwner', '1'))));
                                 $calendars = array();
                                 foreach ($sig as $val) {
                                     $calendars[] = $val['calendar'];
                                 }
                                 $calendarsPermission = Controller::find(array('concept' => 'calendarToPermission'), array('calendar'), array('filter' => array('AND', array('=', 'user', Config::me("uidNumber")), array('IN', 'calendar', $calendars))));
                                 foreach ($calendarsPermission as $val) {
                                     $ids[] = $val['calendar'];
                                 }
                                 $interation = array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => $ids);
                             }
                         }
                         break;
                     case 'REFRESH':
                         break;
                     case 'CANCEL':
                         $interation = ICAL_ACTION_DELETE;
                         break;
                     case 'ADD':
                         break;
                     case 'REPLY':
                         if ($schedulable = self::_getSchedulable($uid)) {
                             while ($property = $component->getProperty('attendee', FALSE, TRUE)) {
                                 if ($attendee = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'], true)) {
                                     $interation = constant('STATUS_' . strtoupper($property['params']['PARTSTAT'])) == $attendee['status'] ? ICAL_ACTION_NONE : ICAL_ACTION_REPLY;
                                 }
                             }
                         } else {
                             $interation = ICAL_NOT_FOUND;
                         }
                         break;
                     case 'COUNTER':
                         $interation = ICAL_ACTION_SUGGESTION;
                         break;
                     case 'DECLINECOUNTER':
                         $interation = ICAL_ACTION_NONE;
                         break;
                     default:
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable && (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) {
                             //Caso o evento exista
                             $interation = ICAL_ACTION_UPDATE;
                         } else {
                             if ($schedulable) {
                                 $interation = ICAL_ACTION_NONE;
                             } else {
                                 // Importar evento
                                 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');
                             }
                         }
                         break;
                 }
                 $return[$uid] = $interation;
                 break;
             case 'VTODO':
                 switch ($method) {
                     case 'PUBLISH':
                         $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                         break;
                     case 'REQUEST':
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable) {
                             //Caso o evento exista
                             $isOrganizer = false;
                             $isParticipant = false;
                             foreach ($schedulable['participants'] as $value) {
                                 if ($value['user']['id'] == $params['owner']) {
                                     $isParticipant = true;
                                     if ($value['isOrganizer']) {
                                         $isOrganizer = true;
                                     }
                                     if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                         $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                                         break;
                                     }
                                 } else {
                                     ///Atualiza o Caldadav mesmo que o expresso não prescisse de atualização, pois os calendarios do caldav são independentes um de cada usuario diferente do expresso que so tem 1 evento e é compartilhado entre os usuarios
                                     if (Config::module('useCaldav', 'expressoCalendar')) {
                                         //Ignorar Put dos eventos ja vindos do caldav
                                         require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
                                         $calendars = self::schedulable2calendarToObject($schedulable['id'], isset($params['owner']) ? $params['owner'] : false);
                                         //Busca os calendarios do usuario logado que contenham o evento
                                         if (is_array($calendars)) {
                                             foreach ($calendars as $calendar) {
                                                 DAViCalAdapter::putIcal($data, array('uid' => $schedulable['uid'], 'location' => $calendar['calendar_location']));
                                             }
                                         }
                                     }
                                     if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) {
                                         //Organizador esta requisitando que você atualize o evento
                                         $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE;
                                     } else {
                                         $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE;
                                     }
                                 }
                             }
                             if (!$isParticipant) {
                                 $interation = self::_checkParticipantByPermissions($schedulable);
                             }
                         } else {
                             $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                         }
                         break;
                     case 'REFRESH':
                         break;
                     case 'CANCEL':
                         $interation = ICAL_ACTION_DELETE;
                         break;
                     case 'ADD':
                         break;
                     case 'REPLY':
                         $interation = ICAL_ACTION_REPLY;
                         break;
                     case 'COUNTER':
                         $interation = ICAL_ACTION_SUGGESTION;
                         break;
                     case 'DECLINECOUNTER':
                         $interation = ICAL_ACTION_NONE;
                         break;
                     default:
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable && (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) {
                             //Caso o evento exista
                             $interation = ICAL_ACTION_UPDATE;
                         } else {
                             if ($schedulable) {
                                 $interation = ICAL_ACTION_NONE;
                             } else {
                                 // Importar evento
                                 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                             }
                         }
                         break;
                 }
                 $return[$uid] = $interation;
                 break;
             case 'VTIMEZONE':
                 break;
         }
     }
     return $return;
 }
Esempio n. 3
0
 static function putEvent(&$uri, &$result, &$criteria, $original)
 {
     if (Config::module('useCaldav', 'expressoCalendar')) {
         //Ignorar Put dos eventos ja vindos do caldav
         require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
         $eventID = isset($result['id']) ? $result['id'] : $uri['id'];
         $event = Controller::read(array('concept' => 'schedulable', 'id' => $eventID));
         $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $eventID)));
         if (is_array($participants) && count($participants) > 0) {
             foreach ($participants as $ii => $vv) {
                 if ($vv['isExternal'] == 1) {
                     $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL'));
                 } else {
                     $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user']));
                 }
             }
         }
         $event['URI']['concept'] = 'schedulable';
         $event['participants'] = $participants;
         $ical = Controller::format(array('service' => 'iCal'), array($event));
         $calendars = self::schedulable2calendarToObject($original['properties']['id']);
         //Busca os calendarios do usuario logado que contenham o evento
         if (is_array($calendars)) {
             foreach ($calendars as $calendar) {
                 DAViCalAdapter::putIcal($ical, array('uid' => $event['uid'], 'location' => $calendar['calendar_location']));
             }
         }
     }
 }