예제 #1
0
 /**
  * @brief updates an VCalendar Object from the request data
  * @param array $request
  * @param object $vcalendar
  * @return object updated $vcalendar
  */
 public function updateVCalendarFromRequest($request, $vcalendar)
 {
     $accessclass = $request["accessclass"];
     $title = $request["title"];
     $location = $request["location"];
     $categories = $request["categories"];
     $allday = isset($request["allday"]);
     $link = $request["link"];
     $from = $request["from"];
     $to = $request["to"];
     $checkDateFrom = strtotime($from);
     $checkWeekDay = date("D", $checkDateFrom);
     $weekDay = Utility::getWeeklyOptionsCheck($checkWeekDay);
     if (!$allday) {
         $fromtime = $request['fromtime'];
         $totime = $request['totime'];
     }
     $vevent = $vcalendar->VEVENT;
     /*REMINDER NEW*/
     if ($request['reminder'] != 'none') {
         if ($vevent->VALARM) {
             $valarm = $vevent->VALARM;
         } else {
             $valarm = new VObject('VALARM');
             $vevent->add($valarm);
         }
         if ($request['reminder'] == 'OWNDEF' && ($request['reminderAdvanced'] == 'DISPLAY' || $request['reminderAdvanced'] == 'EMAIL')) {
             $valarm->setString('ATTENDEE', '');
             if ($request['remindertimeselect'] !== 'ondate') {
                 $valarm->setString('TRIGGER', $request['sReminderRequest']);
             }
             if ($request['remindertimeselect'] === 'ondate') {
                 $temp = explode('TRIGGER;VALUE=DATE-TIME:', $request['sReminderRequest']);
                 $datetime_element = new \Sabre\VObject\Property\ICalendar\DateTime(new \Sabre\VObject\Component\VCalendar(), 'TRIGGER');
                 $datetime_element->setDateTime(new \DateTime($temp[1]), false);
                 $valarm->__set('TRIGGER', $datetime_element);
                 $valarm->TRIGGER['VALUE'] = 'DATE-TIME';
             }
             if ($request['reminderAdvanced'] === 'EMAIL') {
                 //ATTENDEE:mailto:sebastian.doell@libasys.de
                 $valarm->setString('ATTENDEE', 'mailto:' . $request['reminderemailinput']);
             }
             $valarm->setString('DESCRIPTION', 'owncloud');
             $valarm->setString('ACTION', $request['reminderAdvanced']);
         } else {
             $valarm->setString('ATTENDEE', '');
             $valarm->setString('TRIGGER', $request['reminder']);
             $valarm->setString('DESCRIPTION', 'owncloud');
             $valarm->setString('ACTION', 'DISPLAY');
         }
     }
     if ($request['reminder'] == 'none') {
         if ($vevent->VALARM) {
             $vevent->setString('VALARM', '');
         }
     }
     $description = $request["description"];
     $repeat = $request["repeat"];
     //FIXME
     $firstDayOfWeek = ';WKST=' . strtoupper(\OCP\Config::getUserValue($this->userId, 'calendarplus', 'firstday', 'mo'));
     if ($repeat != 'doesnotrepeat' && !array_key_exists('sRuleRequest', $request)) {
         $rrule = '';
         $interval = $request['interval'];
         $end = $request['end'];
         $byoccurrences = $request['byoccurrences'];
         switch ($repeat) {
             case 'daily':
                 $rrule .= 'FREQ=DAILY' . $firstDayOfWeek;
                 break;
             case 'weekly':
                 $rrule .= 'FREQ=WEEKLY' . $firstDayOfWeek;
                 if (array_key_exists('rWeekday', $request)) {
                     $rrule .= ';BYDAY=' . $request['rWeekday'];
                 }
                 break;
             case 'everymonth':
                 $rrule .= 'FREQ=MONTHLY';
                 break;
             case 'everyyear':
                 $rrule .= 'FREQ=YEARLY';
                 break;
             case 'everyweek':
                 $rrule .= 'FREQ=WEEKLY';
                 break;
             case 'weekday':
                 $rrule .= 'FREQ=WEEKLY' . $firstDayOfWeek;
                 $rrule .= ';BYDAY=MO,TU,WE,TH,FR';
                 break;
             case 'biweekly':
                 $rrule .= 'FREQ=WEEKLY' . $firstDayOfWeek;
                 $interval = $interval * 2;
                 break;
             case 'monthly':
                 $rrule .= 'FREQ=MONTHLY' . $firstDayOfWeek;
                 if ($request['advanced_month_select'] == 'monthday') {
                     if (array_key_exists('rMonthday', $request)) {
                         $rrule .= ';BYMONTHDAY=' . $request['rMonthday'];
                     }
                 } elseif ($request['advanced_month_select'] == 'weekday') {
                     $rrule .= ';BYDAY=' . $request['rWeekday'];
                 }
                 break;
             case 'yearly':
                 $rrule .= 'FREQ=YEARLY' . $firstDayOfWeek;
                 if ($request['advanced_year_select'] == 'bydate') {
                 } elseif ($request['advanced_year_select'] == 'byyearday') {
                     list($_day, $_month, $_year) = explode('-', $from);
                     $byyearday = date('z', mktime(0, 0, 0, $_month, $_day, $_year)) + 1;
                     if (array_key_exists('byyearday', $request)) {
                         foreach ($request['byyearday'] as $yearday) {
                             $byyearday .= ',' . $yearday;
                         }
                     }
                     $rrule .= ';BYYEARDAY=' . $byyearday;
                 } elseif ($request['advanced_year_select'] == 'byweekno') {
                     //Fix
                     $days = array_flip(Utility::getWeeklyOptions(Utility::$l10n));
                     $byweekno = '';
                     foreach ($request['byweekno'] as $weekno) {
                         if ($byweekno == '') {
                             $byweekno = $weekno;
                         } else {
                             $byweekno .= ',' . $weekno;
                         }
                     }
                     $rrule .= ';BYWEEKNO=' . $byweekno;
                     $byday = '';
                     foreach ($request['weeklyoptions'] as $day) {
                         if ($byday == '') {
                             $byday .= $days[$day];
                         } else {
                             $byday .= ',' . $days[$day];
                         }
                     }
                     $rrule .= ';BYDAY=' . $byday;
                 } elseif ($request['advanced_year_select'] == 'bydaymonth') {
                     //FIXED Removed Weekly Options
                     if (array_key_exists('rMonth', $request)) {
                         $rrule .= ';BYMONTH=' . $request['rMonth'];
                     }
                     if (array_key_exists('rMonthday', $request)) {
                         $rrule .= ';BYMONTHDAY=' . $request['rMonthday'];
                     }
                 }
                 break;
             default:
                 break;
         }
         if ($interval != '') {
             $rrule .= ';INTERVAL=' . $interval;
         }
         if ($end === 'count') {
             $rrule .= ';COUNT=' . $byoccurrences;
         }
         if ($end === 'date') {
             if (stristr($request['bydate'], '-')) {
                 $bydate_day = substr($request['bydate'], 0, 2);
                 $bydate_month = substr($request['bydate'], 3, 2);
                 $bydate_year = substr($request['bydate'], 6, 4);
             } else {
                 $bydate_month = substr($request['bydate'], 0, 2);
                 $bydate_day = substr($request['bydate'], 3, 2);
                 $bydate_year = substr($request['bydate'], 6, 4);
             }
             $timeAdjust = '';
             if (!$allday) {
                 $timeAdjust = 'T215900Z';
             }
             $rrule .= ';UNTIL=' . $bydate_year . $bydate_month . $bydate_day . $timeAdjust;
         }
         $vevent->setString('RRULE', $rrule);
         $repeat = "true";
     } else {
         if (array_key_exists('sRuleRequest', $request)) {
             $end = $request['end'];
             $byoccurrences = $request['byoccurrences'];
             $rrule = $request['sRuleRequest'];
             if ($end == 'count') {
                 $rrule .= ';COUNT=' . $byoccurrences;
             }
             if ($end == 'date') {
                 if (stristr($request['bydate'], '-')) {
                     $bydate_day = substr($request['bydate'], 0, 2);
                     $bydate_month = substr($request['bydate'], 3, 2);
                     $bydate_year = substr($request['bydate'], 6, 4);
                 } else {
                     $bydate_month = substr($request['bydate'], 0, 2);
                     $bydate_day = substr($request['bydate'], 3, 2);
                     $bydate_year = substr($request['bydate'], 6, 4);
                 }
                 $rrule .= ';UNTIL=' . $bydate_year . $bydate_month . $bydate_day . 'T235000Z';
             }
             $vevent->setString('RRULE', $rrule);
             $repeat = "true";
             if (!$vcalendar->VTIMEZONE && $request['repeat'] != 'doesnotrepeat') {
                 $tz = Utility::getTimezone();
                 $ex = explode('/', $tz, 2);
                 $aTzTimes = $this->getTzDaylightStandard();
                 if (isset($ex[1]) && array_key_exists($ex[0], $aTzTimes)) {
                     $summerTime = $aTzTimes[$ex[0]]['daylight'];
                     $winterTime = $aTzTimes[$ex[0]]['standard'];
                     $dateOffsetSummer = new \DateTime($summerTime, new \DateTimeZone('UTC'));
                     $dateOffsetSummer->setTimezone(new \DateTimeZone($tz));
                     $offsetSummer = $dateOffsetSummer->format('O');
                     $offsetSummerTZ = $dateOffsetSummer->format('T');
                     $dateOffsetWinter = new \DateTime($winterTime, new \DateTimeZone('UTC'));
                     $dateOffsetWinter->setTimezone(new \DateTimeZone($tz));
                     $offsetWinter = $dateOffsetWinter->format('O');
                     $offsetWinterTZ = $dateOffsetWinter->format('T');
                     $vcalendar->add('VTIMEZONE', ['TZID' => $tz, 'DAYLIGHT' => ['TZOFFSETFROM' => $offsetWinter, 'RRULE' => 'FREQ=YEARLY;BYMONTH=' . $aTzTimes[$ex[0]]['daylightstart'] . ';BYDAY=-1SU', 'DTSTART' => $summerTime, 'TZNAME' => $offsetSummerTZ, 'TZOFFSETTO' => $offsetSummer], 'STANDARD' => ['TZOFFSETFROM' => $offsetSummer, 'RRULE' => 'FREQ=YEARLY;BYMONTH=' . $aTzTimes[$ex[0]]['daylightend'] . ';BYDAY=-1SU', 'DTSTART' => $winterTime, 'TZNAME' => $offsetWinterTZ, 'TZOFFSETTO' => $offsetWinter]]);
                 }
             }
         } else {
             $repeat = "false";
         }
     }
     if ($request["repeat"] == 'doesnotrepeat') {
         $vevent->setString('RRULE', '');
     }
     $vevent->setDateTime('LAST-MODIFIED', 'now');
     $vevent->setDateTime('DTSTAMP', 'now');
     $vevent->setString('SUMMARY', $title);
     $oldStartTime = $vevent->DTSTART;
     //  if($request["repeat"] == 'doesnotrepeat') {
     if ($allday) {
         $start = new \DateTime($from);
         $end = new \DateTime($to . ' +1 day');
         $vevent->setDateTime('DTSTART', $start);
         $vevent->DTSTART['VALUE'] = 'DATE';
         $vevent->setDateTime('DTEND', $end);
         $vevent->DTEND['VALUE'] = 'DATE';
     } else {
         $timezone = Utility::getTimezone();
         $timezone = new \DateTimeZone($timezone);
         $start = new \DateTime($from . ' ' . $fromtime, $timezone);
         $end = new \DateTime($to . ' ' . $totime, $timezone);
         $vevent->setDateTime('DTSTART', $start);
         $vevent->setDateTime('DTEND', $end);
     }
     //}else{
     //}
     if ($vevent->EXDATE) {
         $calcStartOld = $oldStartTime->getDateTime()->format('U');
         $calcStartNew = $start->format('U');
         $timeDiff = $calcStartNew - $calcStartOld;
         if ($timeDiff != 0) {
             $delta = new \DateInterval('P0D');
             $dMinutes = (int) ($timeDiff / 60);
             //$dTage=(int) ($dMinutes/(3600*24));
             //$delta->d = $dTage;
             $delta->i = $dMinutes;
         }
     }
     unset($vevent->DURATION);
     $vevent->setString('CLASS', $accessclass);
     $vevent->setString('LOCATION', $location);
     $vevent->setString('DESCRIPTION', $description);
     $vevent->setString('CATEGORIES', $categories);
     $vevent->setString('URL', $link);
     return $vcalendar;
 }
예제 #2
0
 /**
  * @brief updates an VCalendar Object from the request data
  * @param array $request
  * @param object $vcalendar
  * @return object updated $vcalendar
  */
 public static function updateVCalendarFromRequest($request, $vcalendar)
 {
     $accessclass = $request["accessclass"];
     $title = $request["title"];
     $location = $request["location"];
     $categories = $request["categories"];
     $allday = isset($request["allday"]);
     $link = $request["link"];
     $from = $request["from"];
     $to = $request["to"];
     $checkDateFrom = strtotime($from);
     $checkWeekDay = date("D", $checkDateFrom);
     $weekDay = self::getWeeklyOptionsCheck($checkWeekDay);
     if (!$allday) {
         $fromtime = $request['fromtime'];
         $totime = $request['totime'];
     }
     $vevent = $vcalendar->VEVENT;
     /*REMINDER NEW*/
     if ($request['reminder'] != 'none') {
         //$aTimeTransform=self::getReminderTimeParsingOptions();
         if ($vevent->VALARM) {
             $valarm = $vevent->VALARM;
         } else {
             $valarm = new VObject('VALARM');
             $vevent->add($valarm);
         }
         //sReminderRequest
         if ($request['reminder'] == 'OWNDEF' && ($request['reminderAdvanced'] == 'DISPLAY' || $request['reminderAdvanced'] == 'EMAIL')) {
             $valarm->setString('ATTENDEE', '');
             if ($request['remindertimeselect'] !== 'ondate') {
                 //$tTime=$aTimeTransform[$request['remindertimeselect']]['timehistory'].intval($request['remindertimeinput']).$aTimeTransform[$request['remindertimeselect']]['timedescr']	;
                 $valarm->setString('TRIGGER', $request['sReminderRequest']);
             }
             if ($request['remindertimeselect'] === 'ondate') {
                 $temp = explode('TRIGGER;VALUE=DATE-TIME:', $request['sReminderRequest']);
                 $datetime_element = new \Sabre\VObject\Property\ICalendar\DateTime(new \Sabre\VObject\Component\VCalendar(), 'TRIGGER');
                 $datetime_element->setDateTime(new \DateTime($temp[1]), false);
                 $valarm->__set('TRIGGER', $datetime_element);
                 $valarm->TRIGGER['VALUE'] = 'DATE-TIME';
             }
             if ($request['reminderAdvanced'] == 'EMAIL') {
                 //ATTENDEE:mailto:sebastian.doell@libasys.de
                 $valarm->setString('ATTENDEE', 'mailto:' . $request['reminderemailinput']);
             }
             $valarm->setString('DESCRIPTION', 'owncloud');
             $valarm->setString('ACTION', $request['reminderAdvanced']);
         } else {
             $valarm->setString('ATTENDEE', '');
             $valarm->setString('TRIGGER', $request['reminder']);
             $valarm->setString('DESCRIPTION', 'owncloud');
             $valarm->setString('ACTION', 'DISPLAY');
         }
     }
     if ($request['reminder'] == 'none') {
         if ($vevent->VALARM) {
             $vevent->setString('VALARM', '');
         }
     }
     /*	
             $valarm = new VObject('VALARM');
             $vevent->add($valarm);
     		$valarm->addProperty('TRIGGER','-PT45M');
     		$valarm->addProperty('ACTION','DISPLAY');
     		$valarm->addProperty('DESCRIPTION','owncloud alarm');*/
     //ORGANIZER;CN=email@email.com;EMAIL=email@email.com:MAILTO:email@email.com
     //$vevent->addProperty('ORGANIZER;CN='.$email.';EMAIL='.$email,'MAILTO:'.$email);
     //ATTENDEE;CN="Ryan Gr�nborg";CUTYPE=INDIVIDUAL;EMAIL="*****@*****.**";PARTSTAT=ACCEPTED:mailto:ryan@tv-glad.org
     //ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE; CN="Full Name":MAILTO:user@domain.com
     //ATTENDEE;CN="admin";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:/oc50/remote.php/caldav/principals/admin/
     //$vevent->addProperty('ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=admin','MAILTO:'.$email);
     //$vevent->addProperty('ATTENDEE;CN="admin";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED','http://127.0.0.1/oc50/remote.php/caldav/principals/admin/');
     //$vevent->addProperty('ATTENDEE;CN="sebastian";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED','http://127.0.0.1/oc50/remote.php/caldav/principals/sebastian/');
     $description = $request["description"];
     $repeat = $request["repeat"];
     $firstDayOfWeek = ';WKST=' . (\OCP\Config::getUserValue(\OCP\USER::getUser(), App::$appname, 'firstday', 'mo') == 'mo' ? 'MO' : 'SU');
     if ($repeat != 'doesnotrepeat' && !array_key_exists('sRuleRequest', $request)) {
         $rrule = '';
         $interval = $request['interval'];
         $end = $request['end'];
         $byoccurrences = $request['byoccurrences'];
         switch ($repeat) {
             case 'daily':
                 $rrule .= 'FREQ=DAILY' . $firstDayOfWeek;
                 break;
             case 'weekly':
                 $rrule .= 'FREQ=WEEKLY' . $firstDayOfWeek;
                 if (array_key_exists('rWeekday', $request)) {
                     $rrule .= ';BYDAY=' . $request['rWeekday'];
                 }
                 break;
             case 'everymonth':
                 $rrule .= 'FREQ=MONTHLY';
                 break;
             case 'everyyear':
                 $rrule .= 'FREQ=YEARLY';
                 break;
             case 'everyweek':
                 $rrule .= 'FREQ=WEEKLY';
                 break;
             case 'weekday':
                 $rrule .= 'FREQ=WEEKLY' . $firstDayOfWeek;
                 $rrule .= ';BYDAY=MO,TU,WE,TH,FR';
                 break;
             case 'biweekly':
                 $rrule .= 'FREQ=WEEKLY' . $firstDayOfWeek;
                 $interval = $interval * 2;
                 break;
             case 'monthly':
                 $rrule .= 'FREQ=MONTHLY' . $firstDayOfWeek;
                 if ($request['advanced_month_select'] == 'monthday') {
                     if (array_key_exists('rMonthday', $request)) {
                         $rrule .= ';BYMONTHDAY=' . $request['rMonthday'];
                     }
                 } elseif ($request['advanced_month_select'] == 'weekday') {
                     $rrule .= ';BYDAY=' . $request['rWeekday'];
                 }
                 break;
             case 'yearly':
                 $rrule .= 'FREQ=YEARLY' . $firstDayOfWeek;
                 if ($request['advanced_year_select'] == 'bydate') {
                 } elseif ($request['advanced_year_select'] == 'byyearday') {
                     list($_day, $_month, $_year) = explode('-', $from);
                     $byyearday = date('z', mktime(0, 0, 0, $_month, $_day, $_year)) + 1;
                     if (array_key_exists('byyearday', $request)) {
                         foreach ($request['byyearday'] as $yearday) {
                             $byyearday .= ',' . $yearday;
                         }
                     }
                     $rrule .= ';BYYEARDAY=' . $byyearday;
                 } elseif ($request['advanced_year_select'] == 'byweekno') {
                     //Fix
                     $days = array_flip(self::getWeeklyOptions(App::$l10n));
                     $byweekno = '';
                     foreach ($request['byweekno'] as $weekno) {
                         if ($byweekno == '') {
                             $byweekno = $weekno;
                         } else {
                             $byweekno .= ',' . $weekno;
                         }
                     }
                     $rrule .= ';BYWEEKNO=' . $byweekno;
                     $byday = '';
                     foreach ($request['weeklyoptions'] as $day) {
                         if ($byday == '') {
                             $byday .= $days[$day];
                         } else {
                             $byday .= ',' . $days[$day];
                         }
                     }
                     $rrule .= ';BYDAY=' . $byday;
                 } elseif ($request['advanced_year_select'] == 'bydaymonth') {
                     //FIXED Removed Weekly Options
                     if (array_key_exists('rMonth', $request)) {
                         $rrule .= ';BYMONTH=' . $request['rMonth'];
                     }
                     if (array_key_exists('rMonthday', $request)) {
                         $rrule .= ';BYMONTHDAY=' . $request['rMonthday'];
                     }
                 }
                 break;
             default:
                 break;
         }
         if ($interval != '') {
             $rrule .= ';INTERVAL=' . $interval;
         }
         if ($end == 'count') {
             $rrule .= ';COUNT=' . $byoccurrences;
         }
         if ($end == 'date') {
             list($bydate_day, $bydate_month, $bydate_year) = explode('-', $request['bydate']);
             $rrule .= ';UNTIL=' . $bydate_year . $bydate_month . $bydate_day;
         }
         $vevent->setString('RRULE', $rrule);
         $repeat = "true";
         //\OCP\Util::writeLog('calendar','VTIMEZONE'.$vtimezone ->TZID, \OCP\Util::DEBUG);
         /**BEGIN:VTIMEZONE
         			TZID:Europe/Berlin
         			BEGIN:DAYLIGHT
         			TZOFFSETFROM:+0100
         			RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
         			DTSTART:19810329T020000
         			TZNAME:MESZ
         			TZOFFSETTO:+0200
         			END:DAYLIGHT
         			BEGIN:STANDARD
         			TZOFFSETFROM:+0200
         			RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
         			DTSTART:19961027T030000
         			TZNAME:MEZ
         			TZOFFSETTO:+0100
         			END:STANDARD
         			END:VTIMEZONE**/
     } else {
         if (array_key_exists('sRuleRequest', $request)) {
             $end = $request['end'];
             $byoccurrences = $request['byoccurrences'];
             $rrule = $request['sRuleRequest'];
             if ($end == 'count') {
                 $rrule .= ';COUNT=' . $byoccurrences;
             }
             if ($end == 'date') {
                 list($bydate_day, $bydate_month, $bydate_year) = explode('-', $request['bydate']);
                 $rrule .= ';UNTIL=' . $bydate_year . $bydate_month . $bydate_day;
             }
             $vevent->setString('RRULE', $rrule);
             $repeat = "true";
             if (!$vcalendar->VTIMEZONE && $request['repeat'] != 'doesnotrepeat') {
                 $tz = App::getTimezone();
                 $ex = explode('/', $tz, 2);
                 $aTzTimes = App::getTzDaylightStandard();
                 if (isset($ex[1]) && array_key_exists($ex[0], $aTzTimes)) {
                     $summerTime = $aTzTimes[$ex[0]]['daylight'];
                     $winterTime = $aTzTimes[$ex[0]]['standard'];
                     $dateOffsetSummer = new \DateTime($summerTime, new \DateTimeZone('UTC'));
                     $dateOffsetSummer->setTimezone(new \DateTimeZone($tz));
                     $offsetSummer = $dateOffsetSummer->format('O');
                     $offsetSummerTZ = $dateOffsetSummer->format('T');
                     $dateOffsetWinter = new \DateTime($winterTime, new \DateTimeZone('UTC'));
                     $dateOffsetWinter->setTimezone(new \DateTimeZone($tz));
                     $offsetWinter = $dateOffsetWinter->format('O');
                     $offsetWinterTZ = $dateOffsetWinter->format('T');
                     $vcalendar->add('VTIMEZONE', ['TZID' => $tz, 'DAYLIGHT' => ['TZOFFSETFROM' => $offsetWinter, 'RRULE' => 'FREQ=YEARLY;BYMONTH=' . $aTzTimes[$ex[0]]['daylightstart'] . ';BYDAY=-1SU', 'DTSTART' => $summerTime, 'TZNAME' => $offsetSummerTZ, 'TZOFFSETTO' => $offsetSummer], 'STANDARD' => ['TZOFFSETFROM' => $offsetSummer, 'RRULE' => 'FREQ=YEARLY;BYMONTH=' . $aTzTimes[$ex[0]]['daylightend'] . ';BYDAY=-1SU', 'DTSTART' => $winterTime, 'TZNAME' => $offsetWinterTZ, 'TZOFFSETTO' => $offsetWinter]]);
                 }
             }
         } else {
             $repeat = "false";
         }
     }
     if ($request["repeat"] == 'doesnotrepeat') {
         $vevent->setString('RRULE', '');
     }
     $vevent->setDateTime('LAST-MODIFIED', 'now');
     $vevent->setDateTime('DTSTAMP', 'now');
     $vevent->setString('SUMMARY', $title);
     $oldStartTime = $vevent->DTSTART;
     //  if($request["repeat"] == 'doesnotrepeat') {
     if ($allday) {
         $start = new \DateTime($from);
         $end = new \DateTime($to . ' +1 day');
         $vevent->setDateTime('DTSTART', $start);
         $vevent->DTSTART['VALUE'] = 'DATE';
         $vevent->setDateTime('DTEND', $end);
         $vevent->DTEND['VALUE'] = 'DATE';
     } else {
         $timezone = App::getTimezone();
         $timezone = new \DateTimeZone($timezone);
         $start = new \DateTime($from . ' ' . $fromtime, $timezone);
         $end = new \DateTime($to . ' ' . $totime, $timezone);
         $vevent->setDateTime('DTSTART', $start);
         $vevent->setDateTime('DTEND', $end);
     }
     //}else{
     //}
     if ($vevent->EXDATE) {
         $calcStartOld = $oldStartTime->getDateTime()->format('U');
         $calcStartNew = $start->format('U');
         $timeDiff = $calcStartNew - $calcStartOld;
         if ($timeDiff != 0) {
             $delta = new \DateInterval('P0D');
             $dMinutes = (int) ($timeDiff / 60);
             //$dTage=(int) ($dMinutes/(3600*24));
             //$delta->d = $dTage;
             $delta->i = $dMinutes;
             \OCP\Util::writeLog(App::$appname, 'edit: ->' . $dMinutes, \OCP\Util::DEBUG);
             /*
             					if ($allday) {
             						$start_type = \Sabre\VObject\Property\DateTime::DATE;
             					}else{
             						$start_type = \Sabre\VObject\Property\DateTime::LOCALTZ;
             					}	
             					$calcStart=new \DateTime($oldStartTime);
             					$aExt=$vevent->EXDATE;
             					$vevent->setString('EXDATE','');
             					 $timezone = App::getTimezone();
             					foreach($aExt as $param){
             						$dateTime = new \DateTime($param->getValue());
             						$datetime_element = new \Sabre\VObject\Property\DateTime('EXDATE');
             						$datetime_element -> setDateTime($dateTime->add($delta),$start_type);
             					    $vevent->addProperty('EXDATE;TZID='.$timezone,(string) $datetime_element);
             						//$output.=$dateTime->format('Ymd\THis').':'.$datetime_element.'success';
             					}*/
         }
     }
     unset($vevent->DURATION);
     $vevent->setString('CLASS', $accessclass);
     $vevent->setString('LOCATION', $location);
     $vevent->setString('DESCRIPTION', $description);
     $vevent->setString('CATEGORIES', $categories);
     $vevent->setString('URL', $link);
     /*if($repeat == "true") {
     			$vevent->RRULE = $repeat;
     		}*/
     return $vcalendar;
 }
예제 #3
0
 /**
  * Sets or unsets the Date and Time for a property.
  * When $datetime is set to 'now', use the current time
  * When $datetime is null, unset the property
  *
  * @param string property name
  * @param DateTime $datetime
  * @param int $dateType
  * @return void
  */
 public function setDateTime($name, $datetime, $floating = false)
 {
     if ($datetime == 'now') {
         $datetime = new \DateTime();
     }
     if ($datetime instanceof \DateTime) {
         $tThis = $this;
         if (!$tThis instanceof \Sabre\VObject\Component) {
             $tThis = new \Sabre\VObject\Component\VCalendar();
         }
         $datetime_element = new \Sabre\VObject\Property\ICalendar\DateTime($tThis, $name);
         $datetime_element->setDateTime($datetime, $floating);
         $this->vobject->__set($name, $datetime_element);
     } else {
         $this->vobject->__unset($name);
     }
 }
예제 #4
0
 /**
  * @NoAdminRequired
  */
 public function moveEvent()
 {
     $id = $this->params('id');
     $aCheckPermissions = $this->checkPermissions($id, $this->shareConnector->getUpdateAccess());
     if ($aCheckPermissions['status'] === 'success') {
         $vcalendar = CalendarApp::getVCalendar($id, false, false);
         $vevent = $vcalendar->VEVENT;
         $allday = $this->params('allDay');
         $delta = new \DateInterval('P0D');
         $delta->d = $this->params('dayDelta');
         $delta->i = $this->params('minuteDelta');
         $lastModified = $this->params('lastmodified');
         CalendarApp::isNotModified($vevent, $lastModified);
         $dtstart = $vevent->DTSTART;
         $dtend = Object::getDTEndFromVEvent($vevent);
         $start_type = (string) $dtstart->getValueType();
         $end_type = $dtend->getValueType();
         if ($allday && $start_type !== 'DATE') {
             $start_type = $end_type = 'DATE';
             $dtend->setDateTime($dtend->getDateTime()->modify('+1 day'));
         }
         if (!$allday && $start_type === 'DATE') {
             $start_type = $end_type = 'DATE-TIME';
         }
         if ($vevent->EXDATE) {
             $aExt = $vevent->EXDATE;
             $vevent->setString('EXDATE', '');
             $timezone = CalendarApp::getTimezone();
             foreach ($aExt as $param) {
                 $dateTime = new \DateTime($param->getValue());
                 $datetime_element = new \Sabre\VObject\Property\ICalendar\DateTime(new \Sabre\VObject\Component\VCalendar(), 'EXDATE');
                 $datetime_element->setDateTime($dateTime->add($delta));
                 $vevent->addProperty('EXDATE;TZID=' . $timezone, (string) $datetime_element);
             }
         }
         $dtstart->setDateTime($dtstart->getDateTime()->add($delta));
         $dtend->setDateTime($dtend->getDateTime()->add($delta));
         unset($vevent->DURATION);
         $vevent->setDateTime('LAST-MODIFIED', 'now');
         $vevent->setDateTime('DTSTAMP', 'now');
         Object::edit($id, $vcalendar->serialize());
         $this->repeatController->updateEvent($id);
         $lastmodified = $vevent->__get('LAST-MODIFIED')->getDateTime();
         $params = ['status' => $aCheckPermissions['status'], 'lastmodified' => (int) $lastmodified->format('U')];
     } else {
         $params = ['status' => $aCheckPermissions['status'], 'msg' => $aCheckPermissions['msg']];
     }
     $response = new JSONResponse();
     $response->setData($params);
     return $response;
 }
예제 #5
0
파일: app.php 프로젝트: ejouvin/tasksplus
 public static function updateVCalendarFromRequest($request, $vcalendar)
 {
     $cid = $request["read_worker"];
     $accessclass = $request["accessclass"];
     $summary = $request['tasksummary'];
     $categories = $request["taskcategories"];
     $priority = $request['priority'];
     $description = $request['noticetxt'];
     $location = $request['tasklocation'];
     $link = $request['link'];
     $dueDate = $request['sWV'];
     $dueTime = $request['sWV_time'];
     $startDate = $request['startdate'];
     $startTime = $request['startdate_time'];
     $start = '';
     $relatedTo = isset($request['relatedto']) ? $request['relatedto'] : '';
     if ($startTime !== '' && $startDate !== '') {
         $start = $startDate . ' ' . $startTime;
     }
     if ($startTime === '' && $startDate !== '') {
         $start = $startDate;
     }
     $percentComplete = $request['percCompl'];
     $due = '';
     //$percent_complete = $request['percent_complete'];
     //$completed = $request['completed'];
     if ($dueTime !== '' && $dueDate !== '') {
         $due = $dueDate . ' ' . $dueTime;
     }
     if ($dueTime === '' && $dueDate !== '') {
         $due = $dueDate;
     }
     $vtodo = $vcalendar->VTODO;
     $vtodo->setDateTime('LAST-MODIFIED', 'now');
     $vtodo->setDateTime('DTSTAMP', 'now');
     $vtodo->SUMMARY = $summary;
     $vtodo->setString('URL', $link);
     //PERCENT-COMPLETE
     $vtodo->setString('PERCENT-COMPLETE', $percentComplete);
     if ((int) $percentComplete === 0) {
         $vtodo->setString('STATUS', 'NEEDS-ACTION');
     }
     if ((int) $percentComplete > 0 && (int) $percentComplete < 100) {
         $vtodo->setString('STATUS', 'IN-PROCESS');
     }
     if ((int) $percentComplete === 100) {
         $vtodo->setString('STATUS', 'COMPLETED');
         $sTimezone = CalendarApp::getTimezone();
         $timezone = new \DateTimeZone($sTimezone);
         $completed = new \DateTime('now', $timezone);
         $vtodo->setDateTime('COMPLETED', $completed);
     }
     if ($relatedTo !== '') {
         $vtodo->setString('RELATED-TO', $relatedTo);
     }
     $vtodo->setString('LOCATION', $location);
     $vtodo->setString('DESCRIPTION', $description);
     $vtodo->setString('CATEGORIES', $categories);
     $vtodo->setString('PRIORITY', $priority);
     //FIXME
     $vtodo->setString('CLASS', $accessclass);
     $CALINFO = Calendar::find($cid);
     if ($CALINFO['userid'] !== \OCP\User::getUser() && $accessclass !== 'PUBLIC') {
         $vtodo->setString('CLASS', 'PUBLIC');
     }
     if ($due) {
         if ($dueTime) {
             $sTimezone = CalendarApp::getTimezone();
             $timezone = new \DateTimeZone($sTimezone);
             $due = new \DateTime($due, $timezone);
             $vtodo->setDateTime('DUE', $due);
         } else {
             $due1 = new \DateTime($due);
             $vtodo->setDateTime('DUE', $due1);
             $vtodo->DUE['VALUE'] = 'DATE';
         }
     } else {
         unset($vtodo->DUE);
     }
     if ($start) {
         if ($startTime) {
             $sTimezone = CalendarApp::getTimezone();
             $timezone = new \DateTimeZone($sTimezone);
             $start = new \DateTime($start, $timezone);
             $vtodo->setDateTime('DTSTART', $start);
         } else {
             $start1 = new \DateTime($start);
             $vtodo->setDateTime('DTSTART', $start1);
             $vtodo->DTSTART['VALUE'] = 'DATE';
         }
     } else {
         unset($vtodo->DTSTART);
     }
     //Alarm New
     /*REMINDER NEW*/
     if ($request['reminder'] !== 'none') {
         //$aTimeTransform=self::getReminderTimeParsingOptions();
         if ($vtodo->VALARM) {
             $valarm = $vtodo->VALARM;
         } else {
             $valarm = new VObject('VALARM');
             $vtodo->add($valarm);
         }
         //sReminderRequest
         if ($request['reminder'] === 'OWNDEF' && ($request['reminderAdvanced'] === 'DISPLAY' || $request['reminderAdvanced'] === 'EMAIL')) {
             $valarm->setString('ATTENDEE', '');
             if ($request['remindertimeselect'] !== 'ondate') {
                 $valarm->setString('TRIGGER', $request['sReminderRequest']);
             }
             if ($request['remindertimeselect'] === 'ondate') {
                 $temp = explode('TRIGGER;VALUE=DATE-TIME:', $request['sReminderRequest']);
                 $datetime_element = new \Sabre\VObject\Property\ICalendar\DateTime(new \Sabre\VObject\Component\VCalendar(), 'TRIGGER');
                 $datetime_element->setDateTime(new \DateTime($temp[1]), false);
                 $valarm->__set('TRIGGER', $datetime_element);
                 $valarm->TRIGGER['VALUE'] = 'DATE-TIME';
             }
             if ($request['reminderAdvanced'] === 'EMAIL') {
                 $valarm->setString('ATTENDEE', 'mailto:' . $request['reminderemailinput']);
             }
             $valarm->setString('DESCRIPTION', 'owncloud');
             $valarm->setString('ACTION', $request['reminderAdvanced']);
         } else {
             $valarm->setString('ATTENDEE', '');
             $valarm->setString('TRIGGER', $request['reminder']);
             $valarm->setString('DESCRIPTION', 'owncloud');
             $valarm->setString('ACTION', 'DISPLAY');
         }
     }
     if ($request['reminder'] === 'none') {
         if ($vtodo->VALARM) {
             $vtodo->setString('VALARM', '');
         }
     }
     return $vcalendar;
 }