Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
 private function getPublicEvent($itemSource, $shareOwner, $token)
 {
     $itemSource = CalendarApp::validateItemSource($itemSource, CalendarApp::SHAREEVENTPREFIX);
     $data = CalendarApp::getEventObject($itemSource, false, false);
     $object = VObject::parse($data['calendardata']);
     $vevent = $object->VEVENT;
     $object = Object::cleanByAccessClass($itemSource, $object);
     $accessclass = $vevent->getAsString('CLASS');
     if ($accessclass == 'PRIVATE') {
         header('HTTP/1.0 404 Not Found');
         $response = new TemplateResponse('core', '404', '', 'guest');
         return $response;
     }
     $permissions = CalendarApp::getPermissions($itemSource, CalendarApp::EVENT, $accessclass);
     $dtstart = $vevent->DTSTART;
     $dtend = Object::getDTEndFromVEvent($vevent);
     $dtstartType = $vevent->DTSTART->getValueType();
     if ($dtstartType == 'DATE') {
         $startdate = $dtstart->getDateTime()->format('d-m-Y');
         $starttime = '';
         $enddate = $dtend->getDateTime()->modify('-1 day')->format('d-m-Y');
         $endtime = '';
         $choosenDate = $choosenDate + 3600 * 24;
         $allday = true;
     }
     if ($dtstartType == 'DATE-TIME') {
         $startdate = $dtstart->getDateTime()->format('d-m-Y');
         $starttime = $dtstart->getDateTime()->format('H:i');
         $enddate = $dtend->getDateTime()->format('d-m-Y');
         $endtime = $dtend->getDateTime()->format('H:i');
         $allday = false;
     }
     $summary = strtr($vevent->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
     $location = strtr($vevent->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
     $categories = $vevent->getAsArray('CATEGORIES');
     $description = strtr($vevent->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
     $link = strtr($vevent->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
     $last_modified = $vevent->__get('LAST-MODIFIED');
     if ($last_modified) {
         $lastmodified = $last_modified->getDateTime()->format('U');
     } else {
         $lastmodified = 0;
     }
     $repeatInfo = array();
     $repeat['repeat'] = '';
     if ($data['repeating'] == 1) {
         $rrule = explode(';', $vevent->getAsString('RRULE'));
         $rrulearr = array();
         $repeat['repeat_rules'] = '';
         foreach ($rrule as $rule) {
             list($attr, $val) = explode('=', $rule);
             if ($attr != 'COUNT' && $attr !== 'UNTIL') {
                 if ($repeat['repeat_rules'] === '') {
                     $repeat['repeat_rules'] = $attr . '=' . $val;
                 } else {
                     $repeat['repeat_rules'] .= ';' . $attr . '=' . $val;
                 }
             }
             if ($attr === 'COUNT' || $attr !== 'UNTIL') {
                 $rrulearr[$attr] = $val;
             }
         }
         if (array_key_exists('COUNT', $rrulearr)) {
             $repeat['end'] = 'count';
             $repeat['count'] = $rrulearr['COUNT'];
         } elseif (array_key_exists('UNTIL', $rrulearr)) {
             $repeat['end'] = 'date';
             $endbydate_day = substr($rrulearr['UNTIL'], 6, 2);
             $endbydate_month = substr($rrulearr['UNTIL'], 4, 2);
             $endbydate_year = substr($rrulearr['UNTIL'], 0, 4);
             $repeat['date'] = $endbydate_day . '-' . $endbydate_month . '-' . $endbydate_year;
         } else {
             $repeat['end'] = 'never';
         }
         $repeat_end_options = CalendarApp::getEndOptions();
         if ($repeat['end'] === 'count') {
             $repeatInfo['end'] = $this->l10n->t('after') . ' ' . $repeat['count'] . ' ' . $this->l10n->t('Events');
         }
         if ($repeat['end'] === 'date') {
             $repeatInfo['end'] = $repeat['date'];
         }
         if ($repeat['end'] === 'never') {
             $repeatInfo['end'] = $repeat_end_options[$repeat['end']];
         }
     } else {
         $repeat['repeat'] = 'doesnotrepeat';
     }
     $calendar_options[0]['id'] = $data['calendarid'];
     $access_class_options = CalendarApp::getAccessClassOptions();
     $aOExdate = '';
     if ($vevent->EXDATE) {
         $timezone = CalendarApp::getTimezone();
         foreach ($vevent->EXDATE as $param) {
             $param = new \DateTime($param);
             $aOExdate[$param->format('U')] = $param->format('d-m-Y');
         }
     }
     $timezone = \OC::$server->getSession()->get('public_link_timezone');
     $sCat = '';
     if (is_array($categories) && count($categories) > 0) {
         $sCat = $categories;
     }
     $params = ['eventid' => $itemSource, 'appname' => $this->appName, 'permissions' => $permissions, 'lastmodified' => $lastmodified, 'exDate' => $aOExdate, 'sharingToken' => $token, 'token' => $token, 'calendar_options' => $calendar_options, 'access_class_options' => $access_class_options, 'title' => $summary, 'accessclass' => $accessclass, 'location' => $location, 'calendar' => $data['calendarid'], 'timezone' => $timezone, 'uidOwner' => $shareOwner, 'displayName' => \OCP\User::getDisplayName($shareOwner), 'allday' => $allday, 'startdate' => $startdate, 'starttime' => $starttime, 'enddate' => $enddate, 'endtime' => $endtime, 'description' => $description, 'link' => $link, 'repeat_rules' => isset($repeat['repeat_rules']) ? $repeat['repeat_rules'] : '', 'repeat' => $repeat['repeat'], 'repeatInfo' => $repeat['repeat'] != 'doesnotrepeat' ? $repeatInfo : '', 'categories' => $sCat];
     $response = new TemplateResponse($this->appName, 'publicevent', $params, 'base');
     return $response;
 }
Exemplo n.º 3
0
 private function getVobjectData($id, $choosenDate, $data)
 {
     $result = [];
     if (!$data) {
         return false;
     }
     $sDateFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'dateformat', 'd-m-Y');
     $object = VObject::parse($data['calendardata']);
     $vevent = $object->VEVENT;
     $object = Object::cleanByAccessClass($id, $object);
     $result['accessclass'] = $vevent->getAsString('CLASS');
     $result['permissions'] = CalendarApp::getPermissions($id, CalendarApp::EVENT, $result['accessclass']);
     $dtstart = $vevent->DTSTART;
     $result['dtstart'] = $dtstart;
     $dtend = Object::getDTEndFromVEvent($vevent);
     $dateStartType = (string) $vevent->DTSTART->getValueType();
     if ($dateStartType === 'DATE') {
         $result['startdate'] = $dtstart->getDateTime()->format($sDateFormat);
         $result['starttime'] = '';
         $result['enddate'] = $dtend->getDateTime()->modify('-1 day')->format($sDateFormat);
         $result['endtime'] = '';
         $result['choosenDate'] = $choosenDate + 3600 * 24;
         $result['allday'] = true;
     }
     if ($dateStartType === 'DATE-TIME') {
         $tz = CalendarApp::getTimezone();
         $start_dt = new \DateTime($data['startdate'], new \DateTimeZone('UTC'));
         $end_dt = new \DateTime($data['enddate'], new \DateTimeZone('UTC'));
         $start_dt->setTimezone(new \DateTimeZone($tz));
         $end_dt->setTimezone(new \DateTimeZone($tz));
         $result['startdate'] = $start_dt->format($sDateFormat);
         $result['starttime'] = $start_dt->format('H:i');
         $result['enddate'] = $end_dt->format($sDateFormat);
         $result['endtime'] = $end_dt->format('H:i');
         $result['allday'] = false;
         $result['choosenDate'] = $choosenDate;
     }
     $result['summary'] = strtr($vevent->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
     $result['location'] = strtr($vevent->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
     $result['categories'] = $vevent->getAsString('CATEGORIES');
     $result['description'] = strtr($vevent->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
     $result['link'] = strtr($vevent->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
     $last_modified = $vevent->__get('LAST-MODIFIED');
     if ($last_modified) {
         $result['lastmodified'] = $last_modified->getDateTime()->format('U');
     } else {
         $result['lastmodified'] = 0;
     }
     $result['addSingleDeleteButton'] = false;
     if ((int) $data['repeating'] === 1) {
         $result['addSingleDeleteButton'] = true;
         $rrule = explode(';', $vevent->getAsString('RRULE'));
         $result['rrule'] = $this->parseRrules($rrule);
     } else {
         $result['rrule']['repeat'] = 'doesnotrepeat';
     }
     //NEW Reminder
     $result['reminder_options'] = CalendarApp::getReminderOptions();
     $result['alarm'] = $this->parseValarm($vevent, $result['reminder_options']);
     return $result;
 }
Exemplo n.º 4
0
 /**
  *@PublicPage
  * @NoCSRFRequired
  * @UseSession
  */
 public function index($token)
 {
     if ($token) {
         $linkItem = Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $type = $linkItem['item_type'];
             $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], CalendarApp::SHARETODOPREFIX);
             $shareOwner = $linkItem['uid_owner'];
             $calendarName = $linkItem['item_target'];
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             // stupid copy and paste job
             if (isset($linkItem['share_with'])) {
                 // Authenticate share_with
                 $password = $this->params('password');
                 if (isset($password)) {
                     if ($linkItem['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
                         // Check Password
                         $newHash = '';
                         if (\OC::$server->getHasher()->verify($password, $linkItem['share_with'], $newHash)) {
                             $this->session->set('public_link_authenticated', $linkItem['id']);
                             if (!empty($newHash)) {
                             }
                         } else {
                             \OCP\Util::addStyle('files_sharing', 'authenticate');
                             $params = array('wrongpw' => true);
                             return new TemplateResponse('files_sharing', 'authenticate', $params, 'guest');
                         }
                     } else {
                         \OCP\Util::writeLog('share', 'Unknown share type ' . $linkItem['share_type'] . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
                         return false;
                     }
                 } else {
                     // Check if item id is set in session
                     if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== $linkItem['id']) {
                         // Prompt for password
                         \OCP\Util::addStyle('files_sharing', 'authenticate');
                         $params = array();
                         return new TemplateResponse('files_sharing', 'authenticate', $params, 'guest');
                     }
                 }
             }
             \OCP\Util::addStyle(CalendarApp::$appname, '3rdparty/fontello/css/animation');
             \OCP\Util::addStyle(CalendarApp::$appname, '3rdparty/fontello/css/fontello');
             \OCP\Util::addStyle($this->appName, 'style');
             \OCP\Util::addStyle($this->appName, 'share');
             \OCP\Util::addScript($this->appName, 'share');
             $data = TasksApp::getEventObject($itemSource, false, false);
             $l = \OC::$server->getL10N($this->appName);
             $object = VObject::parse($data['calendardata']);
             $vTodo = $object->VTODO;
             $id = $data['id'];
             $object = Object::cleanByAccessClass($id, $object);
             $accessclass = $vTodo->getAsString('CLASS');
             $permissions = TasksApp::getPermissions($id, TasksApp::TODO, $accessclass);
             if ($accessclass === 'PRIVATE') {
                 header('HTTP/1.0 404 Not Found');
                 $response = new TemplateResponse('core', '404', '', 'guest');
                 return $response;
             }
             $categories = $vTodo->getAsArray('CATEGORIES');
             $summary = strtr($vTodo->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
             $location = strtr($vTodo->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
             $description = strtr($vTodo->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
             $priorityOptionsArray = TasksApp::getPriorityOptionsFilterd();
             //$priorityOptions=$priorityOptionsArray[(string)$vTodo->priority];
             $priorityOptions = 0;
             $link = strtr($vTodo->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
             $TaskDate = '';
             $TaskTime = '';
             if ($vTodo->DUE) {
                 $dateDueType = $vTodo->DUE->getValueType();
                 if ($dateDueType == 'DATE') {
                     $TaskDate = $vTodo->DUE->getDateTime()->format('d.m.Y');
                     $TaskTime = '';
                 }
                 if ($dateDueType == 'DATE-TIME') {
                     $TaskDate = $vTodo->DUE->getDateTime()->format('d.m.Y');
                     $TaskTime = $vTodo->DUE->getDateTime()->format('H:i');
                 }
             }
             $TaskStartTime = '';
             $TaskStartDate = '';
             if ($vTodo->DTSTART) {
                 $dateStartType = $vTodo->DTSTART->getValueType();
                 if ($dateStartType === 'DATE') {
                     $TaskStartDate = $vTodo->DTSTART->getDateTime()->format('d.m.Y');
                     $TaskStartTime = '';
                 }
                 if ($dateStartType === 'DATE-TIME') {
                     $TaskStartDate = $vTodo->DTSTART->getDateTime()->format('d.m.Y');
                     $TaskStartTime = $vTodo->DTSTART->getDateTime()->format('H:i');
                 }
             }
             //PERCENT-COMPLETE
             $cptlStatus = (string) $this->l10n->t('needs action');
             $percentComplete = 0;
             if ($vTodo->{'PERCENT-COMPLETE'}) {
                 $percentComplete = $vTodo->{'PERCENT-COMPLETE'};
                 //$cptlStatus = (string)$this->l10n->t('in procress');
                 if ($percentComplete === '0') {
                     $cptlStatus = (string) $this->l10n->t('needs action');
                 }
                 if ($percentComplete > '0' && $percentComplete < '100') {
                     $cptlStatus = (string) $this->l10n->t('in procress');
                 }
             }
             if ($vTodo->{'COMPLETED'}) {
                 $cptlStatus = (string) $this->l10n->t('completed');
             }
             $timezone = \OC::$server->getSession()->get('public_link_timezone');
             $sCat = '';
             if (is_array($categories) && count($categories) > 0) {
                 $sCat = $categories;
             }
             $params = ['eventid' => $itemSource, 'permissions' => $permissions, 'priorityOptions' => $priorityOptions, 'percentComplete' => $percentComplete, 'cptlStatus' => $cptlStatus, 'TaskDate' => isset($TaskDate) ? $TaskDate : '', 'TaskTime' => isset($TaskTime) ? $TaskTime : '', 'TaskStartDate' => isset($TaskStartDate) ? $TaskStartDate : '', 'TaskStartTime' => isset($TaskStartTime) ? $TaskStartTime : '', 'title' => $summary, 'accessclass' => $accessclass, 'location' => $location, 'categories' => $sCat, 'calendar' => $data['calendarid'], 'aCalendar' => CalendarApp::getCalendar($data['calendarid'], false, false), 'calAppName' => CalendarApp::$appname, 'description' => $description, 'repeat_rules' => '', 'link' => $link, 'timezone' => $timezone, 'uidOwner' => $shareOwner, 'displayName' => \OCP\User::getDisplayName($shareOwner), 'sharingToken' => $token, 'token' => $token];
             $response = new TemplateResponse($this->appName, 'publicevent', $params, 'base');
             return $response;
         }
         //end isset
     }
     //end token
     $tmpl = new \OCP\Template('', '404', 'guest');
     $tmpl->printPage();
 }
Exemplo n.º 5
0
 /**
  * @NoAdminRequired
  */
 public function editTask()
 {
     //relatedto,hiddenfield, read_worker,$_POST,mytaskcal, mytaskmode
     $id = $this->params('tid');
     $hiddenPostField = $this->params('hiddenfield');
     $myTaskCal = $this->params('mytaskcal');
     $myTaskMode = $this->params('mytaskmode');
     $data = TasksApp::getEventObject($id, false, false);
     $object = VObject::parse($data['calendardata']);
     $calId = Object::getCalendarid($id);
     $orgId = $data['org_objid'];
     //Search for Main Task
     $mainTaskId = '';
     if ($data['relatedto'] !== '') {
         $mainTaskId = TasksApp::getEventIdbyUID($data['relatedto']);
     }
     //Search for Sub Tasks
     $subTaskIds = '';
     if ($data['relatedto'] === '') {
         $subTaskIds = TasksApp::getSubTasks($data['eventuid']);
     }
     if (isset($hiddenPostField) && $hiddenPostField === 'edititTask' && $id > 0) {
         $cid = $this->params('read_worker');
         $postRequestAll = $this->getParams();
         TasksApp::updateVCalendarFromRequest($postRequestAll, $object);
         TasksApp::edit($id, $object->serialize(), $orgId);
         if ($mainTaskId === '') {
             $mainTaskId = $id;
         }
         if ($calId !== intval($cid)) {
             Object::moveToCalendar($id, intval($cid));
             if ($subTaskIds !== '') {
                 $tempIds = explode(',', $subTaskIds);
                 foreach ($tempIds as $subIds) {
                     Object::moveToCalendar($subIds, intval($cid));
                 }
             }
         }
         $vcalendar1 = TasksApp::getVCalendar($id, true, true);
         $vtodo = $vcalendar1->VTODO;
         $aTask = TasksApp::getEventObject($id, true, true);
         $aCalendar = CalendarCalendar::find($aTask['calendarid']);
         $user_timezone = CalendarApp::getTimezone();
         $task_info = TasksApp::arrayForJSON($id, $vtodo, $user_timezone, $aCalendar, $aTask);
         $task_info['olduid'] = $data['eventuid'];
         $task_info['oldcalendarid'] = $data['calendarid'];
         $response = new JSONResponse();
         $response->setData($task_info);
         return $response;
     }
     $vtodo = $object->VTODO;
     $object = Object::cleanByAccessClass($id, $object);
     $accessclass = $vtodo->getAsString('CLASS');
     if (empty($accessclass)) {
         $accessclass = 'PUBLIC';
     }
     $permissions = TasksApp::getPermissions($id, TasksApp::TODO, $accessclass);
     $link = strtr($vtodo->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
     $TaskDate = '';
     $TaskTime = '';
     if ($vtodo->DUE) {
         $dateDueType = $vtodo->DUE->getValueType();
         if ($dateDueType === 'DATE') {
             $TaskDate = $vtodo->DUE->getDateTime()->format('d.m.Y');
             $TaskTime = '';
         }
         if ($dateDueType === 'DATE-TIME') {
             $TaskDate = $vtodo->DUE->getDateTime()->format('d.m.Y');
             $TaskTime = $vtodo->DUE->getDateTime()->format('H:i');
         }
     }
     $TaskStartDate = '';
     $TaskStartTime = '';
     if ($vtodo->DTSTART) {
         $dateStartType = $vtodo->DTSTART->getValueType();
         if ($dateStartType === 'DATE') {
             $TaskStartDate = $vtodo->DTSTART->getDateTime()->format('d.m.Y');
             $TaskStartTime = '';
         }
         if ($dateStartType === 'DATE-TIME') {
             $TaskStartDate = $vtodo->DTSTART->getDateTime()->format('d.m.Y');
             $TaskStartTime = $vtodo->DTSTART->getDateTime()->format('H:i');
         }
     }
     $priority = $vtodo->getAsString('PRIORITY');
     $calendarsArrayTmp = CalendarCalendar::allCalendars($this->userId, true);
     //Filter Importent Values
     $calendar_options = array();
     $checkArray = array();
     $checkShareArray = array();
     $bShareCalId = '';
     foreach ($calendarsArrayTmp as $calendar) {
         $isAktiv = $calendar['active'];
         if ($this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']) != '') {
             $isAktiv = $this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']);
         }
         if (!array_key_exists('active', $calendar)) {
             $isAktiv = 1;
         }
         if ((int) $isAktiv === 1 && $calendar['userid'] !== $this->userId || $mainTaskId !== '') {
             $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendar['id']);
             if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE && $mainTaskId === '') {
                 array_push($calendar_options, $calendar);
                 $checkShareArray[$calendar['id']] = $sharedCalendar['permissions'];
             }
         }
         if ($isAktiv === 1 && $calendar['userid'] === $this->userId) {
             array_push($calendar_options, $calendar);
             $checkShareArray[$calendar['id']] = \OCP\PERMISSION_ALL;
         }
     }
     if (!array_key_exists($calId, $checkShareArray)) {
         $bShareCalId = 'hide';
     }
     $priorityOptionsArray = TasksApp::getPriorityOptionsFilterd();
     $priorityOptions = TasksApp::generateSelectFieldArray('priority', (string) $vtodo->priority, $priorityOptionsArray, false);
     $access_class_options = CalendarApp::getAccessClassOptions();
     //NEW Reminder
     $reminder_options = CalendarApp::getReminderOptions();
     $reminder_advanced_options = CalendarApp::getAdvancedReminderOptions();
     $reminder_time_options = CalendarApp::getReminderTimeOptions();
     //reminder
     $vtodosharees = array();
     $sharedwithByVtodo = \OCP\Share::getItemShared(CalendarApp::SHARETODO, CalendarApp::SHARETODOPREFIX . $id);
     if (is_array($sharedwithByVtodo)) {
         foreach ($sharedwithByVtodo as $share) {
             if ($share['share_type'] == \OCP\Share::SHARE_TYPE_USER || $share['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) {
                 $vtodosharees[] = $share;
             }
         }
     }
     $percentCompleted = '0';
     if ($vtodo->{'PERCENT-COMPLETE'}) {
         $percentCompleted = $vtodo->getAsString('PERCENT-COMPLETE');
     }
     $aAlarm = $this->setAlarmTask($vtodo, $reminder_options);
     $params = ['id' => $id, 'calId' => $calId, 'orgId' => $orgId, 'permissions' => $permissions, 'priorityOptions' => $priorityOptions, 'access_class_options' => $access_class_options, 'calendar_options' => $calendar_options, 'calendar' => $calId, 'mymode' => $myTaskMode, 'mycal' => $myTaskCal, 'bShareCalId' => $bShareCalId, 'subtaskids' => $subTaskIds, 'cal_permissions' => $checkShareArray, 'accessclass' => $accessclass, 'reminder_options' => $reminder_options, 'reminder_rules' => array_key_exists('triggerRequest', $aAlarm) ? $aAlarm['triggerRequest'] : '', 'reminder' => $aAlarm['action'], 'reminder_time_options' => $reminder_time_options, 'reminder_advanced_options' => $reminder_advanced_options, 'reminder_advanced' => 'DISPLAY', 'remindertimeselect' => array_key_exists('reminder_time_select', $aAlarm) ? $aAlarm['reminder_time_select'] : '', 'remindertimeinput' => array_key_exists('reminder_time_input', $aAlarm) ? $aAlarm['reminder_time_input'] : '', 'reminderemailinput' => array_key_exists('email', $aAlarm) ? $aAlarm['email'] : '', 'reminderdate' => array_key_exists('reminderdate', $aAlarm) ? $aAlarm['reminderdate'] : '', 'remindertime' => array_key_exists('remindertime', $aAlarm) ? $aAlarm['remindertime'] : '', 'link' => $link, 'priority' => $priority, 'TaskDate' => $TaskDate, 'TaskTime' => $TaskTime, 'TaskStartDate' => $TaskStartDate, 'TaskStartTime' => $TaskStartTime, 'vtodosharees' => $vtodosharees, 'percentCompleted' => $percentCompleted, 'sharetodo' => CalendarApp::SHARETODO, 'sharetodoprefix' => CalendarApp::SHARETODOPREFIX, 'vtodo' => $vtodo];
     $response = new TemplateResponse($this->appName, 'event.edit', $params, '');
     return $response;
 }
Exemplo n.º 6
0
 public static function arrayForJSON($id, $vtodo, $user_timezone, $aCalendar, $aTask)
 {
     $output = array();
     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);
         $aTask['summary'] = strtr($vtodo->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
         if (isset($vtodo->CLASS) && ($vtodo->CLASS->getValue() === 'PRIVATE' || $vtodo->CLASS->getValue() === '')) {
             return $output;
         }
         if (isset($vtodo->CLASS) && $vtodo->CLASS->getValue() === 'CONFIDENTIAL') {
             $aTask['summary'] = (string) App::$l10n->t('Busy');
         }
         $vtodo = Object::cleanByAccessClass($id, $vtodo);
     }
     $aTask['id'] = $id;
     $aTask['privat'] = false;
     if (isset($vtodo->CLASS) && $vtodo->CLASS->getValue() === 'PRIVATE') {
         $aTask['privat'] = 'private';
     }
     if (isset($vtodo->CLASS) && $vtodo->CLASS->getValue() === 'CONFIDENTIAL') {
         $aTask['privat'] = 'confidential';
     }
     $aTask['bgcolor'] = $aCalendar['calendarcolor'];
     $aTask['displayname'] = $aCalendar['displayname'];
     $aTask['color'] = Calendar::generateTextColor($aCalendar['calendarcolor']);
     $aTask['permissions'] = $aCalendar['permissions'];
     $aTask['calendarid'] = $aCalendar['id'];
     $aTask['rightsoutput'] = Calendar::permissionReader($aCalendar['permissions']);
     if ($aTask['rightsoutput'] === 'full access') {
         $aTask['rightsoutput'] = '';
     }
     if (array_key_exists('calendarowner', $aCalendar) && $aCalendar['calendarowner'] !== '') {
         $aTask['summary'] .= ' (by ' . $aCalendar['calendarowner'] . ')';
     }
     $aTask['description'] = strtr($vtodo->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
     $aTask['description'] = nl2br($aTask['description']);
     $aTask['location'] = strtr($vtodo->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
     $aTask['url'] = strtr($vtodo->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
     $aTask['categories'] = $vtodo->getAsArray('CATEGORIES');
     $aTask['isOnlySharedTodo'] = false;
     if (array_key_exists('isOnlySharedTodo', $aCalendar) && $aCalendar['isOnlySharedTodo'] !== '') {
         $aTask['isOnlySharedTodo'] = true;
     }
     $aTask['orgevent'] = false;
     if (array_key_exists('org_objid', $aTask) && $aTask['org_objid'] > 0) {
         $aTask['orgevent'] = true;
         $aTask['permissions'] = self::getPermissions($aTask['org_objid'], self::TODO);
         $aTask['summary'] .= ' (' . self::$l10n->t('by') . ' ' . Object::getowner($aTask['org_objid']) . ')';
     }
     if (isset($aTask['isalarm'])) {
         $aTask['isalarm'] = $aTask['isalarm'];
     }
     if (isset($aTask['shared'])) {
         $aTask['shared'] = $aTask['shared'];
     }
     $aTask['sAlarm'] = '';
     if ($vtodo->VALARM) {
         $counter = 0;
         $valarm = '';
         foreach ($vtodo->getComponents() as $param) {
             if ($param->name === 'VALARM') {
                 $attr = $param->children();
                 foreach ($attr as $attrInfo) {
                     $valarm[$counter][$attrInfo->name] = (string) $attrInfo->getValue();
                 }
                 $counter++;
             }
         }
         foreach ($valarm as $vInfo) {
             if ($vInfo['ACTION'] === 'DISPLAY' && strstr($vInfo['TRIGGER'], 'P')) {
                 if (substr_count($vInfo['TRIGGER'], 'PT', 0, 2) === 1) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 2);
                     $aTask['sAlarm'][] = 'TRIGGER:+PT' . $TimeCheck;
                 }
                 if (substr_count($vInfo['TRIGGER'], '+PT', 0, 3) === 1) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 3);
                     $aTask['sAlarm'][] = 'TRIGGER:+PT' . $TimeCheck;
                 }
                 if (substr_count($vInfo['TRIGGER'], 'P', 0, 1) === 1 && substr_count($vInfo['TRIGGER'], 'PT', 0, 2) === 0 && substr_count($vInfo['TRIGGER'], 'T', strlen($vInfo['TRIGGER']) - 1, 1) === 0) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 1);
                     $aTask['sAlarm'][] = 'TRIGGER:+PT' . $TimeCheck;
                 }
                 if (substr_count($vInfo['TRIGGER'], 'P', 0, 1) === 1 && substr_count($vInfo['TRIGGER'], 'PT', 0, 2) === 0 && substr_count($vInfo['TRIGGER'], 'T', strlen($vInfo['TRIGGER']) - 1, 1) === 1) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 1);
                     $TimeCheck = substr($TimeCheck, 0, -1);
                     $aTask['sAlarm'][] = 'TRIGGER:+PT' . $TimeCheck;
                 }
                 if (substr_count($vInfo['TRIGGER'], '-PT', 0, 3) === 1) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 3);
                     $aTask['sAlarm'][] = 'TRIGGER:-PT' . $TimeCheck;
                 }
                 if (substr_count($vInfo['TRIGGER'], '-P', 0, 2) === 1 && substr_count($vInfo['TRIGGER'], '-PT', 0, 3) === 0 && substr_count($vInfo['TRIGGER'], 'T', strlen($vInfo['TRIGGER']) - 1, 1) === 0) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 2);
                     $aTask['sAlarm'][] = 'TRIGGER:-PT' . $TimeCheck;
                 }
                 if (substr_count($vInfo['TRIGGER'], '-P', 0, 2) === 1 && substr_count($vInfo['TRIGGER'], '-PT', 0, 3) === 0 && substr_count($vInfo['TRIGGER'], 'T', strlen($vInfo['TRIGGER']) - 1, 1) === 1) {
                     $TimeCheck = substr($vInfo['TRIGGER'], 2);
                     $TimeCheck = substr($TimeCheck, 0, -1);
                     $aTask['sAlarm'][] = 'TRIGGER:-PT' . $TimeCheck;
                 }
                 if ($vInfo['TRIGGER'] === 'PT0S') {
                     $aTask['sAlarm'] = '';
                 }
             }
             if ($vInfo['ACTION'] === 'DISPLAY' && !strstr($vInfo['TRIGGER'], 'P')) {
                 if (!strstr($vInfo['TRIGGER'], 'DATE-TIME')) {
                     $aTask['sAlarm'][] = 'TRIGGER;VALUE=DATE-TIME:' . $vInfo['TRIGGER'];
                 } else {
                     $aTask['sAlarm'][] = $vInfo['TRIGGER'];
                 }
             }
         }
     }
     //FIXME
     $today = strtotime(date('d.m.Y'));
     $tomorrow = $today + 3600 * 24;
     $yesterday = $today - 3600 * 24;
     $iTagAkt = date("w", $today);
     $firstday = 1;
     $iBackCalc = ($iTagAkt - $firstday) * 24 * 3600;
     $actWeekBeginn = $today - $iBackCalc;
     $iForCalc = 6 * 24 * 3600;
     $actWeekEnd = $actWeekBeginn + $iForCalc;
     $aTask['period'] = '';
     $aTask['startsearch'] = '';
     if ($vtodo->DTSTART) {
         $dateStartType = $vtodo->DTSTART->getValueType();
         $timestamp = strtotime($vtodo->DTSTART->getDateTime()->format('d.m.Y'));
         $aTask['startsearch'] = $vtodo->DTSTART->getDateTime()->format('d.m.Y');
         if ($dateStartType === 'DATE') {
             $aTask['startdate'] = $vtodo->DTSTART->getDateTime()->format('d.m.Y');
             if ($timestamp == $today) {
                 $aTask['startdate'] = self::$l10n->t('today');
                 $aTask['period'] = 'today';
             } elseif ($timestamp === $yesterday) {
                 $aTask['startdate'] = self::$l10n->t('yesterday');
                 $aTask['period'] = 'yesterday';
             } elseif ($timestamp === $tomorrow) {
                 $aTask['startdate'] = self::$l10n->t('tomorrow');
                 $aTask['period'] = 'tomorrow';
             } elseif ($timestamp >= $actWeekBeginn && $timestamp <= $actWeekEnd) {
                 $aTask['period'] = 'actweek';
             } elseif ($timestamp > $actWeekEnd) {
                 $aTask['period'] = 'comingsoon';
             } elseif ($timestamp < $actWeekBeginn) {
                 $aTask['period'] = 'missedactweek';
             }
         }
         if ($dateStartType === 'DATE-TIME') {
             $aTask['startdate'] = $vtodo->DTSTART->getDateTime()->format('d.m.Y H:i');
             if ($timestamp === $today) {
                 $aTask['startdate'] = self::$l10n->t('today') . ' ' . $vtodo->DTSTART->getDateTime()->format('H:i');
                 $aTask['period'] = 'today';
             } elseif ($timestamp === $yesterday) {
                 $aTask['startdate'] = self::$l10n->t('yesterday') . ' ' . $vtodo->DTSTART->getDateTime()->format('H:i');
                 $aTask['period'] = 'yesterday';
             } elseif ($timestamp === $tomorrow) {
                 $aTask['startdate'] = self::$l10n->t('tomorrow') . ' ' . $vtodo->DTSTART->getDateTime()->format('H:i');
                 $aTask['period'] = 'tomorrow';
             } elseif ($timestamp >= $actWeekBeginn && $timestamp <= $actWeekEnd) {
                 $aTask['period'] = 'actweek';
             } elseif ($timestamp > $actWeekEnd) {
                 $aTask['period'] = 'comingsoon';
             } elseif ($timestamp < $actWeekBeginn) {
                 $aTask['period'] = 'missedactweek';
             }
         }
     } else {
         $aTask['startdate'] = false;
     }
     //higher prior than startdate
     $aTask['perioddue'] = '';
     $aTask['duesearch'] = '';
     if ($vtodo->DUE) {
         $dateDueType = $vtodo->DUE->getValueType();
         $timestamp = strtotime($vtodo->DUE->getDateTime()->format('d.m.Y'));
         $aTask['duesearch'] = $vtodo->DUE->getDateTime()->format('d.m.Y');
         if ($dateDueType === 'DATE') {
             $aTask['due'] = $vtodo->DUE->getDateTime()->format('d.m.Y');
             if ($timestamp === $today) {
                 $aTask['due'] = self::$l10n->t('today');
                 $aTask['perioddue'] = 'today';
             } elseif ($timestamp === $yesterday) {
                 $aTask['due'] = self::$l10n->t('yesterday');
                 $aTask['perioddue'] = 'yesterday';
             } elseif ($timestamp === $tomorrow) {
                 $aTask['due'] = self::$l10n->t('tomorrow');
                 $aTask['perioddue'] = 'tomorrow';
             } elseif ($timestamp >= $actWeekBeginn && $timestamp <= $actWeekEnd) {
                 $aTask['perioddue'] = 'actweek';
             } elseif ($timestamp > $actWeekEnd) {
                 $aTask['perioddue'] = 'comingsoon';
             } elseif ($timestamp < $actWeekBeginn) {
                 $aTask['perioddue'] = 'missedactweek';
             }
         }
         if ($dateDueType === 'DATE-TIME') {
             $aTask['due'] = $vtodo->DUE->getDateTime()->format('d.m.Y H:i');
             if ($timestamp === $today) {
                 $aTask['due'] = self::$l10n->t('today') . ' ' . $vtodo->DUE->getDateTime()->format('H:i');
                 $aTask['perioddue'] = 'today';
             } elseif ($timestamp === $yesterday) {
                 $aTask['due'] = self::$l10n->t('yesterday') . ' ' . $vtodo->DUE->getDateTime()->format('H:i');
                 $aTask['perioddue'] = 'yesterday';
             } elseif ($timestamp === $tomorrow) {
                 $aTask['due'] = self::$l10n->t('tomorrow') . ' ' . $vtodo->DUE->getDateTime()->format('H:i');
                 $aTask['perioddue'] = 'tomorrow';
             } elseif ($timestamp >= $actWeekBeginn && $timestamp <= $actWeekEnd) {
                 $aTask['perioddue'] = 'actweek';
             } elseif ($timestamp > $actWeekEnd) {
                 $aTask['perioddue'] = 'comingsoon';
             } elseif ($timestamp < $actWeekBeginn) {
                 $aTask['perioddue'] = 'missedactweek';
             }
         }
         if ($vtodo->getAsString('RRULE') !== '') {
             $rrule = explode(';', $vtodo->getAsString('RRULE'));
             $aRrule = array();
             foreach ($rrule as $rule) {
                 list($attr, $val) = explode('=', $rule);
                 if ($attr === 'UNTIL') {
                     $aRrule['enddate'] = $val;
                 }
                 if ($attr === 'FREQ') {
                     $aRrule['freq'] = $val;
                 }
             }
         }
     } else {
         $aTask['due'] = false;
     }
     if ($aTask['due'] === false && $aTask['startdate'] === false) {
         $aTask['period'] = 'withoutdate';
         $aTask['perioddue'] = 'withoutdate';
     }
     $aTask['priority'] = '';
     $aTask['priorityDescr'] = '';
     $aTask['priorityLang'] = '';
     if (isset($vtodo->PRIORITY)) {
         $aTask['priority'] = $vtodo->getAsString('PRIORITY');
         if ($aTask['priority'] == 1 || $aTask['priority'] == 2 || $aTask['priority'] == 3 || $aTask['priority'] == 4) {
             $aTask['priorityDescr'] = (string) self::$l10n->t('priority %s ', array((string) self::$l10n->t('high')));
             $aTask['priorityLang'] = 'high';
         } elseif ($aTask['priority'] == 5) {
             $aTask['priorityDescr'] = (string) self::$l10n->t('priority %s ', array((string) self::$l10n->t('medium')));
             $aTask['priorityLang'] = 'medium';
         } elseif ($aTask['priority'] == 6 || $aTask['priority'] == 7 || $aTask['priority'] == 8 || $aTask['priority'] == 9) {
             $aTask['priorityDescr'] = (string) self::$l10n->t('priority %s ', array((string) self::$l10n->t('low')));
             $aTask['priorityLang'] = 'low';
         }
     }
     if (!isset($aCalendar['iscompleted'])) {
         $aCalendar['iscompleted'] = false;
     }
     $aTask['iscompleted'] = $aCalendar['iscompleted'];
     $completed = $vtodo->COMPLETED;
     if ($completed) {
         $completed = $completed->getDateTime();
         $completed->setTimezone(new \DateTimeZone($user_timezone));
         $timestamp = strtotime($vtodo->COMPLETED->getDateTime()->format('d.m.Y'));
         $aTask['completed'] = $completed->format('d.m.Y');
         if ($timestamp === $today) {
             $aTask['completed'] = self::$l10n->t('today') . ' ' . $completed->format('H:i');
         }
         if ($timestamp === $today - 3600 * 24) {
             $aTask['completed'] = self::$l10n->t('yesterday') . ' ' . $completed->format('H:i');
         }
         $aTask['iscompleted'] = true;
     } else {
         $aTask['completed'] = false;
     }
     $aTask['complete'] = $vtodo->getAsString('PERCENT-COMPLETE');
     $output = $aTask;
     return $output;
 }
Exemplo n.º 7
0
 /**
  * Returns information from a single calendar object, based on it's object
  * uri.
  *
  * The returned array must have the same keys as getCalendarObjects. The
  * 'calendardata' object is required here though, while it's not required
  * for getCalendarObjects.
  *
  * @param string $calendarId
  * @param string $objectUri
  * @return array
  */
 public function getCalendarObject($calendarId, $objectUri)
 {
     $data = Object::findWhereDAVDataIs($calendarId, $objectUri);
     if (is_array($data)) {
         $data = $this->OCAddETag($data);
         $object = VObject::parse($data['calendardata']);
         if (!$object) {
             return false;
         }
         $object = Object::cleanByAccessClass($data['id'], $object);
         $data['calendardata'] = $object->serialize();
         //$data = $this->OCAddETag($data);
         return $data;
     } else {
         return false;
     }
 }