Example #1
0
 private static function addVtimezone()
 {
     $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');
         $sTimeZone = "BEGIN:VTIMEZONE\nTZID:" . $tz . "\n";
         $sTimeZone .= "BEGIN:DAYLIGHT\n";
         $sTimeZone .= "TZOFFSETFROM:" . $offsetWinter . "\n";
         $sTimeZone .= "RRULE:FREQ=YEARLY;BYMONTH=" . $aTzTimes[$ex[0]]['daylightstart'] . ";BYDAY=-1SU\n";
         $sTimeZone .= "DTSTART:" . $summerTime . "\n";
         $sTimeZone .= "TZNAME:" . $offsetSummerTZ . "\n";
         $sTimeZone .= "TZOFFSETTO:" . $offsetSummer . "\n";
         $sTimeZone .= "END:DAYLIGHT\n";
         $sTimeZone .= "BEGIN:STANDARD\n";
         $sTimeZone .= "TZOFFSETFROM:" . $offsetSummer . "\n";
         $sTimeZone .= "RRULE:FREQ=YEARLY;BYMONTH=" . $aTzTimes[$ex[0]]['daylightend'] . ";BYDAY=-1SU\n";
         $sTimeZone .= "DTSTART:" . $winterTime . "\n";
         $sTimeZone .= "TZNAME:" . $offsetWinterTZ . "\n";
         $sTimeZone .= "TZOFFSETTO:" . $offsetWinter . "\n";
         $sTimeZone .= "END:STANDARD\n";
         $sTimeZone .= "END:VTIMEZONE\n";
         return $sTimeZone;
     }
 }
Example #2
0
 private function addVtimezone()
 {
     $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');
         $sTimeZone = 'BEGIN:VTIMEZONE' . "\n";
         $sTimeZone .= 'TZID:' . $tz . "\n";
         $sTimeZone .= 'DAYLIGHT:' . $offsetWinter . ',FREQ=YEARLY\\;BYMONTH=' . $aTzTimes[$ex[0]]['daylightstart'] . '\\;BYDAY=-1SU,' . $summerTime . ',' . $offsetSummerTZ . ',' . $offsetSummer . "\n";
         $sTimeZone .= 'STANDARD:' . $offsetSummer . ',FREQ=YEARLY\\;BYMONTH=' . $aTzTimes[$ex[0]]['daylightend'] . '\\;BYDAY=-1SU,' . $winterTime . ',' . $offsetWinterTZ . ',' . $offsetWinter . "\n";
         $sTimeZone .= 'END:VTIMEZONE' . "\n";
         return $sTimeZone;
     }
 }
Example #3
0
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
namespace OCA\CalendarPlus;

Alarm::$tz = App::getTimezone();
class Alarm
{
    private $nowTime = 0;
    private $activeAlarms = array();
    private $aCalendars = array();
    private $aEventSource = array();
    /**
     * @brief timezone of the user
     */
    public static $tz;
    public function __construct()
    {
        $timeNow = time();
        //test
        $checkOffset = new \DateTime(date('d.m.Y', $timeNow), new \DateTimeZone(self::$tz));
Example #4
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="ryan@tv-glad.org";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;
 }