Example #1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  */
 public function getShowEvent()
 {
     $id = $this->params('id');
     $choosenDate = $this->params('choosendate');
     if (\OCP\User::isLoggedIn()) {
         $sDateFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'dateformat', 'd-m-Y');
         $sTimeFormat = $this->configInfo->getUserValue($this->userId, $this->appName, 'timeformat', '24');
         if ($sTimeFormat == 24) {
             $sTimeFormatRead = 'H:i';
         } else {
             $sTimeFormatRead = 'g:i a';
         }
         if ($sDateFormat === 'd-m-Y') {
             $sDateFormat = 'd.m.Y';
         }
     } else {
         if ($this->session->get('public_dateformat') != '') {
             $sDateFormat = $this->session->get('public_dateformat');
         } else {
             $sDateFormat = 'd.m.Y';
         }
         if ($this->session->get('public_timeformat') != '') {
             $sTimeFormatRead = $this->session->get('public_timeformat');
         } else {
             $sTimeFormatRead = 'H:i';
         }
     }
     $data = CalendarApp::getEventObject($id, false, false);
     if (!$data) {
         exit;
     }
     $object = VObject::parse($data['calendardata']);
     //FIXME Working with objectparser
     $vevent = $object->VEVENT;
     $object = Object::cleanByAccessClass($id, $object);
     $accessclass = $vevent->getAsString('CLASS');
     $permissions = CalendarApp::getPermissions($id, CalendarApp::EVENT, $accessclass);
     $dtstart = $vevent->DTSTART;
     if (isset($choosenDate) && $choosenDate !== '') {
         $choosenDate = $choosenDate;
     } else {
         $choosenDate = $dtstart->getDateTime()->format('Ymd');
     }
     $showdate = $dtstart->getDateTime()->format('Y-m-d H:i:s');
     $organzier = '';
     if ($vevent->ORGANIZER) {
         $organizerVal = $vevent->getAsString('ORGANIZER');
         $temp = explode('mailto:', $organizerVal);
         $organzier = $temp[1];
     }
     $attendees = '';
     if ($vevent->ATTENDEE) {
         $attendees = array();
         foreach ($vevent->ATTENDEE as $key => $param) {
             $temp1 = explode('mailto:', $param);
             $attendees[$key] = $temp1[1];
         }
     }
     $dtend = Object::getDTEndFromVEvent($vevent);
     $dtstartType = (string) $vevent->DTSTART->getValueType();
     $datetimedescr = '';
     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 ($startdate === $enddate) {
             $datetimedescr = (string) $this->l10n->t('On') . ' ' . $dtstart->getDateTime()->format($sDateFormat);
         } else {
             $datetimedescr = (string) $this->l10n->t('From') . ' ' . $dtstart->getDateTime()->format($sDateFormat) . ' ' . (string) $this->l10n->t('To') . ' ' . $dtend->getDateTime()->modify('-1 day')->format($sDateFormat);
         }
     }
     if ($dtstartType === '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));
         $startdate = $start_dt->format('d-m-Y');
         $starttime = $start_dt->format($sTimeFormatRead);
         $enddate = $end_dt->format('d-m-Y');
         $endtime = $end_dt->format($sTimeFormatRead);
         if ($startdate === $enddate) {
             $datetimedescr = (string) $this->l10n->t('On') . ' ' . $start_dt->format($sDateFormat) . ' ' . (string) $this->l10n->t('From') . ' ' . $starttime . ' ' . (string) $this->l10n->t('To') . ' ' . $endtime;
         } else {
             $datetimedescr = (string) $this->l10n->t('From') . ' ' . $start_dt->format($sDateFormat) . ' ' . $starttime . ' ' . (string) $this->l10n->t('To') . ' ' . $end_dt->format($sDateFormat) . ' ' . $endtime;
         }
         $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('\\,' => ',', '\\;' => ';'));
     $categoriesOut = '';
     if (is_array($categories)) {
         foreach ($categories as $category) {
             $bgColor = CalendarApp::genColorCodeFromText(trim($category), 80);
             $categoriesOut[] = array('name' => $category, 'bgcolor' => $bgColor, 'color' => CalendarApp::generateTextColor($bgColor));
         }
     }
     $last_modified = $vevent->__get('LAST-MODIFIED');
     if ($last_modified) {
         $lastmodified = $last_modified->getDateTime()->format('U');
     } else {
         $lastmodified = 0;
     }
     $addSingleDeleteButton = false;
     $repeatInfo = array();
     $repeat['repeat'] = '';
     if ((int) $data['repeating'] === 1) {
         $addSingleDeleteButton = true;
         $rrule = explode(';', $vevent->getAsString('RRULE'));
         $rrulearr = array();
         $repeat['repeat_rules'] = '';
         foreach ($rrule as $rule) {
             list($attr, $val) = explode('=', $rule);
             if ((string) $attr !== 'COUNT' && (string) $attr !== 'UNTIL') {
                 if ($repeat['repeat_rules'] === '') {
                     $repeat['repeat_rules'] = $attr . '=' . $val;
                 } else {
                     $repeat['repeat_rules'] .= ';' . $attr . '=' . $val;
                 }
             }
             if ((string) $attr === 'COUNT' || (string) $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);
             $rEnd_dt = new \DateTime($endbydate_day . '-' . $endbydate_month . '-' . $endbydate_year, new \DateTimeZone('UTC'));
             $repeat['date'] = $rEnd_dt->format($sDateFormat);
             //Switch it
         } 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';
     }
     if ($permissions !== $this->shareConnector->getAllAccess()) {
         $calendar_options[0]['id'] = $data['calendarid'];
     } else {
         $calendar_options = CalendarCalendar::allCalendars($this->userId);
     }
     $checkCatCache = '';
     if (\OCP\User::isLoggedIn()) {
         $category_options = CalendarApp::loadTags();
         foreach ($category_options['tagslist'] as $catInfo) {
             $checkCatCache[$catInfo['name']] = $catInfo['bgcolor'];
         }
     }
     $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($sDateFormat);
         }
     }
     //NEW Reminder
     $reminder_options = CalendarApp::getReminderOptions();
     $reminder_time_options = CalendarApp::getReminderTimeOptions();
     //reminder
     $sAlarm = '';
     $count = '';
     if ($vevent->VALARM) {
         $valarm = '';
         $sAlarm = '';
         $counter = 0;
         foreach ($vevent->getComponents() as $param) {
             if ($param->name === 'VALARM') {
                 $attr = $param->children();
                 foreach ($attr as $attrInfo) {
                     $valarm[$counter][$attrInfo->name] = $attrInfo->getValue();
                 }
                 $counter++;
             }
         }
         foreach ($valarm as $vInfo) {
             if ($vInfo['ACTION'] === 'DISPLAY' && strstr($vInfo['TRIGGER'], 'P')) {
                 if (substr_count($vInfo['TRIGGER'], 'PT') === 1 && !stristr($vInfo['TRIGGER'], 'TRIGGER')) {
                     $sAlarm[] = 'TRIGGER:' . $vInfo['TRIGGER'];
                 }
                 if (substr_count($vInfo['TRIGGER'], 'PT') === 1 && stristr($vInfo['TRIGGER'], 'TRIGGER')) {
                     $sAlarm[] = $vInfo['TRIGGER'];
                 }
                 if (substr_count($vInfo['TRIGGER'], '-P') === 1 && substr_count($vInfo['TRIGGER'], 'PT') === 0) {
                     $temp = explode('-P', (string) $vInfo['TRIGGER']);
                     $sAlarm[] = 'TRIGGER:-PT' . $temp[1];
                 }
                 if (substr_count($vInfo['TRIGGER'], '+P') === 1 && substr_count($vInfo['TRIGGER'], 'PT') === 0) {
                     $temp = explode('+P', $vInfo['TRIGGER']);
                     $sAlarm[] = 'TRIGGER:+PT' . $temp[1];
                 }
             }
             if ($vInfo['ACTION'] === 'DISPLAY' && !strstr($vInfo['TRIGGER'], 'P')) {
                 if (!strstr($vInfo['TRIGGER'], 'DATE-TIME')) {
                     $sAlarm[] = 'TRIGGER;VALUE=DATE-TIME:' . $vInfo['TRIGGER'];
                 } else {
                     $sAlarm[] = $vInfo['TRIGGER'];
                 }
             }
         }
     }
     if ($permissions & $this->shareConnector->getReadAccess()) {
         $bShareOnlyEvent = 0;
         if (Object::checkShareEventMode($id)) {
             $bShareOnlyEvent = 1;
         }
         $pCategoriesCol = '';
         $pCategories = '';
         if (is_array($categoriesOut) && count($categoriesOut) > 0) {
             $pCategoriesCol = $checkCatCache;
             $pCategories = $categoriesOut;
         }
         $pRepeatInfo = '';
         if ($repeat['repeat'] !== 'doesnotrepeat') {
             $pRepeatInfo = $repeatInfo;
         }
         $aCalendar = CalendarApp::getCalendar($data['calendarid'], false, false);
         $isBirthday = false;
         if ($aCalendar['uri'] === 'bdaycpltocal_' . $aCalendar['userid']) {
             $isBirthday = true;
         }
         $params = ['bShareOnlyEvent' => $bShareOnlyEvent, 'eventid' => $id, 'appname' => $this->appName, 'permissions' => $permissions, 'lastmodified' => $lastmodified, 'exDate' => $aOExdate, 'isBirthday' => $isBirthday, 'calendar_options' => $calendar_options, 'access_class_options' => $access_class_options, 'sReminderTrigger' => $sAlarm, 'cValarm' => $count, 'isShareApi' => $this->appConfig->getValue('core', 'shareapi_enabled', 'yes'), 'mailNotificationEnabled' => $this->appConfig->getValue('core', 'shareapi_allow_mail_notification', 'yes'), 'allowShareWithLink' => $this->appConfig->getValue('core', 'shareapi_allow_links', 'yes'), 'mailPublicNotificationEnabled' => $this->appConfig->getValue('core', 'shareapi_allow_public_notification', 'no'), 'title' => $summary, 'accessclass' => $accessclass, 'location' => $location, 'categoriesCol' => $pCategoriesCol, 'categories' => $pCategories, 'aCalendar' => $aCalendar, 'allday' => $allday, 'startdate' => $startdate, 'starttime' => $starttime, 'enddate' => $enddate, 'endtime' => $endtime, 'datetimedescr' => $datetimedescr, 'description' => $description, 'link' => $link, 'organzier' => $organzier, 'attendees' => $attendees, 'addSingleDeleteButton' => $addSingleDeleteButton, 'choosendate' => $choosenDate, 'showdate' => $showdate, 'repeat' => $repeat['repeat'], 'repeat_rules' => isset($repeat['repeat_rules']) ? $repeat['repeat_rules'] : '', 'repeatInfo' => $pRepeatInfo, 'sharetypeevent' => $this->shareConnector->getConstShareEvent(), 'sharetypeeventprefix' => $this->shareConnector->getConstSharePrefixEvent()];
         $response = new TemplateResponse($this->appName, 'part.showevent', $params, '');
         return $response;
     }
 }