Ejemplo n.º 1
0
 /**
  * @NoAdminRequired
  */
 public function deleteSingleRepeatingEvent()
 {
     $id = $this->params('id');
     $pStart = $this->params('viewstart');
     $pEnd = $this->params('viewend');
     $choosenDate = $this->params('choosendate');
     $choosenDate = date('Ymd', $choosenDate);
     $choosenDate1 = $choosenDate;
     $data = CalendarApp::getEventObject($id, false, false);
     $vcalendar = VObject::parse($data['calendardata']);
     $vevent = $vcalendar->VEVENT;
     $vevent->setDateTime('LAST-MODIFIED', 'now');
     $vevent->setDateTime('DTSTAMP', 'now');
     $dtstart = $vevent->DTSTART;
     $start_type = (string) $dtstart->getValueType();
     if ($start_type === 'DATE') {
         $dateTime = new \DateTime($choosenDate);
         if ($dateTime instanceof \DateTime) {
             $vevent->addProperty('EXDATE', $dateTime);
         }
     } else {
         $sTimezone = CalendarApp::getTimezone();
         $dStartTime = $vevent->DTSTART;
         $sTime = $dStartTime->getDateTime()->format('H:i');
         $dateTime = new \DateTime($choosenDate . ' ' . $sTime, new \DateTimeZone($sTimezone));
         if ($dateTime instanceof \DateTime) {
             $vevent->addProperty('EXDATE', $dateTime);
         }
     }
     Repeat::update($id);
     Object::edit($id, $vcalendar->serialize());
     $editedEvent = CalendarApp::getEventObject($id, false, false);
     if (stristr($pStart, '(')) {
         $temp = explode('(', $pStart);
         $pStart = $temp[0];
     }
     if (stristr($pEnd, '(')) {
         $temp = explode('(', $pEnd);
         $pEnd = $temp[0];
     }
     $start = new \DateTime($pStart);
     $end = new \DateTime($pEnd);
     $events = CalendarApp::generateEventOutput($editedEvent, $start, $end);
     $params = ['status' => 'success', 'data' => ['id' => $id, 'events' => $events]];
     $response = new JSONResponse();
     $response->setData($params);
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * @brief generates the output for an event which will be readable for our js
  * @param (mixed) $event - event object / array
  * @param (int) $start - DateTime object of start
  * @param (int) $end - DateTime object of end
  * @return (array) $output - readable output
  */
 public static function generateEventOutput(array $event, $start, $end, $list = false)
 {
     if (!isset($event['calendardata']) && !isset($event['vevent'])) {
         return false;
     }
     if (!isset($event['calendardata']) && isset($event['vevent'])) {
         $event['calendardata'] = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud's Internal iCal System\n" . $event['vevent']->serialize() . "END:VCALENDAR";
     }
     try {
         $object = VObject::parse($event['calendardata']);
         if (!$object) {
             \OCP\Util::writeLog(self::$appname, __METHOD__ . ' Error parsing event: ' . print_r($event, true), \OCP\Util::DEBUG);
             return array();
         }
         $output = array();
         if ($object->name === 'VEVENT') {
             $vevent = $object;
         } elseif (isset($object->VEVENT)) {
             $vevent = $object->VEVENT;
         } else {
             \OCP\Util::writeLog(self::$appname, __METHOD__ . ' Object contains not event: ' . print_r($event, true), \OCP\Util::DEBUG);
             return $output;
         }
         $id = $event['id'];
         $SUMMARY = !is_null($vevent->SUMMARY) && $vevent->SUMMARY->getValue() != '' ? strtr($vevent->SUMMARY->getValue(), array('\\,' => ',', '\\;' => ';')) : (string) self::$l10n->t('unnamed');
         if ($event['summary'] != '') {
             $SUMMARY = $event['summary'];
         }
         if (Object::getowner($id) !== \OCP\USER::getUser()) {
             // do not show events with private or unknown access class
             // \OCP\Util::writeLog('calendar','Sharee ID: ->'.$event['calendarid'].':'.$event['summary'], \OCP\Util::DEBUG);
             if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'CONFIDENTIAL') {
                 $SUMMARY = (string) self::$l10n->t('Busy');
             }
             if (isset($vevent->CLASS) && ($vevent->CLASS->getValue() === 'PRIVATE' || $vevent->CLASS->getValue() === '')) {
                 return $output;
             }
             $object = Object::cleanByAccessClass($id, $object);
         }
         $event['orgevent'] = '';
         if (array_key_exists('org_objid', $event) && $event['org_objid'] > 0) {
             $event['orgevent'] = array('calendarcolor' => '#000');
         }
         $event['isalarm'] = false;
         if (isset($vevent->VALARM)) {
             $event['isalarm'] = true;
         }
         $event['privat'] = false;
         if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'PRIVATE') {
             $event['privat'] = 'private';
         }
         if (isset($vevent->CLASS) && $vevent->CLASS->getValue() === 'CONFIDENTIAL') {
             $event['privat'] = 'confidential';
         }
         $allday = $vevent->DTSTART->getValueType() == 'DATE' ? true : false;
         $last_modified = @$vevent->__get('LAST-MODIFIED');
         $calid = '';
         if (array_key_exists('calendarid', $event)) {
             $calid = $event['calendarid'];
         }
         /*
         $eventPerm = '';
         
         if (array_key_exists('permissions', $event)) {
         	$eventPerm = Calendar::permissionReader($event['permissions']);
         }
         
         $location = (!is_null($vevent -> LOCATION) && $vevent -> LOCATION -> getValue() != '') ? $vevent -> getAsString('LOCATION') : '';
         */
         $bDay = false;
         if (array_key_exists('bday', $event)) {
             $bDay = $event['bday'];
         }
         $isEventShared = false;
         if (isset($event['shared']) && $event['shared'] === 1) {
             $isEventShared = $event['shared'];
         }
         $lastmodified = $last_modified ? $last_modified->getDateTime()->format('U') : 0;
         $staticoutput = array('id' => (int) $event['id'], 'title' => $SUMMARY, 'lastmodified' => $lastmodified, 'categories' => $vevent->getAsArray('CATEGORIES'), 'calendarid' => (int) $calid, 'bday' => $bDay, 'shared' => $isEventShared, 'privat' => $event['privat'], 'isrepeating' => false, 'isalarm' => $event['isalarm'], 'orgevent' => $event['orgevent'], 'allDay' => $allday);
         if (Object::isrepeating($id) && Repeat::is_cached_inperiod($event['id'], $start, $end)) {
             $cachedinperiod = Repeat::get_inperiod($id, $start, $end);
             foreach ($cachedinperiod as $cachedevent) {
                 $dynamicoutput = array();
                 if ($allday) {
                     $start_dt = new \DateTime($cachedevent['startdate'], new \DateTimeZone('UTC'));
                     $end_dt = new \DateTime($cachedevent['enddate'], new \DateTimeZone('UTC'));
                     $dynamicoutput['start'] = $start_dt->format('Y-m-d');
                     $dynamicoutput['end'] = $end_dt->format('Y-m-d');
                     $dynamicoutput['startlist'] = $start_dt->format('Y/m/d');
                     $dynamicoutput['endlist'] = $end_dt->format('Y/m/d');
                 } else {
                     $start_dt = new \DateTime($cachedevent['startdate'], new \DateTimeZone('UTC'));
                     $end_dt = new \DateTime($cachedevent['enddate'], new \DateTimeZone('UTC'));
                     $start_dt->setTimezone(new \DateTimeZone(self::$tz));
                     $end_dt->setTimezone(new \DateTimeZone(self::$tz));
                     $dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s');
                     $dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s');
                     $dynamicoutput['startlist'] = $start_dt->format('Y/m/d H:i:s');
                     $dynamicoutput['endlist'] = $end_dt->format('Y/m/d H:i:s');
                 }
                 $dynamicoutput['isrepeating'] = true;
                 $output[] = array_merge($staticoutput, $dynamicoutput);
             }
         } else {
             if (Object::isrepeating($id) || $event['repeating'] == 1) {
                 $object->expand($start, $end);
             }
             foreach ($object->getComponents() as $singleevent) {
                 if (!$singleevent instanceof \Sabre\VObject\Component\VEvent) {
                     continue;
                 }
                 $dynamicoutput = Object::generateStartEndDate($singleevent->DTSTART, Object::getDTEndFromVEvent($singleevent), $allday, self::$tz);
                 $output[] = array_merge($staticoutput, $dynamicoutput);
             }
         }
         return $output;
     } catch (\Exception $e) {
         $uid = 'unknown';
         if (isset($event['uri'])) {
             $uid = $event['uri'];
         }
         \OCP\Util::writeLog(self::$appname, 'Event (' . $uid . ') contains invalid data!', \OCP\Util::WARN);
     }
 }
 /**
  * @NoAdminRequired
  */
 public function reScanCal()
 {
     $calendars = CalendarCalendar::allCalendars($this->userId);
     foreach ($calendars as $calendar) {
         Repeat::cleancalendar($calendar['id']);
         Repeat::generatecalendar($calendar['id']);
     }
     $params = ['status' => 'success', 'data' => ['message' => (string) $this->l10n->t('Success')]];
     $response = new JSONResponse($params);
     return $response;
 }