Example #1
0
	/**
	 * @return array
	 */
	public function AjaxEventDelete()
	{
		$mResult = false;
		$oAccount = $this->getDefaultAccountFromParam();
		
		$sCalendarId = $this->getParamValue('calendarId');
		$sId = $this->getParamValue('uid');

		$iAllEvents = (int) $this->getParamValue('allEvents');
		
		if ($iAllEvents && $iAllEvents === 1)
		{
			$oEvent = new \CEvent();
			$oEvent->IdCalendar = $sCalendarId;
			$oEvent->Id = $sId;
			
			$sRecurrenceId = $this->getParamValue('recurrenceId');

			$mResult = $this->oApiCalendar->UpdateExclusion($oAccount, $oEvent, $sRecurrenceId, true);
		}
		else
		{
			$mResult = $this->oApiCalendar->DeleteEvent($oAccount, $sCalendarId, $sId);
		}
		
		return $this->DefaultResponse($oAccount, __FUNCTION__, $mResult);
	}
Example #2
0
 public function Execute()
 {
     CApi::Log('---------- Start cron script', ELogLevel::Full, 'cron-');
     $oTimeZoneUTC = new \DateTimeZone('UTC');
     $oNowDT_UTC = new \DateTime('now', $oTimeZoneUTC);
     $iNowTS_UTC = $oNowDT_UTC->getTimestamp();
     $oStartDT_UTC = clone $oNowDT_UTC;
     $oStartDT_UTC->sub(new DateInterval('PT30M'));
     if (file_exists($this->sCurRunFilePath)) {
         $handle = fopen($this->sCurRunFilePath, 'r');
         $sCurRunFileTS = fread($handle, 10);
         if (!empty($sCurRunFileTS) && is_numeric($sCurRunFileTS)) {
             $oStartDT_UTC = new \DateTime("@{$sCurRunFileTS}");
         }
     }
     $iStartTS_UTC = $oStartDT_UTC->getTimestamp();
     if ($iNowTS_UTC >= $iStartTS_UTC) {
         CApi::Log('Start time: ' . $oStartDT_UTC->format('r'), ELogLevel::Full, 'cron-');
         CApi::Log('End time: ' . $oNowDT_UTC->format('r'), ELogLevel::Full, 'cron-');
         $aEvents = $this->GetReminders($iStartTS_UTC, $iNowTS_UTC);
         foreach ($aEvents as $sEmail => $aUserCalendars) {
             foreach ($aUserCalendars as $sCalendarUri => $aUserEvents) {
                 foreach ($aUserEvents as $aUserEvent) {
                     $aSubEvents = $aUserEvent['data'];
                     if (isset($aSubEvents, $aSubEvents['vcal'])) {
                         $vCal = $aSubEvents['vcal'];
                         foreach ($aSubEvents as $mKey => $aEvent) {
                             if ($mKey !== 'vcal') {
                                 $oAccount = $this->getAccount($sEmail);
                                 $oCalendar = $this->getCalendar($oAccount, $sCalendarUri);
                                 if ($oCalendar) {
                                     $sEventId = $aEvent['uid'];
                                     $sEventStart = $aEvent['start'];
                                     $iEventStartTS = $aEvent['startTS'];
                                     $sEventName = $aEvent['subject'];
                                     $sEventText = $aEvent['description'];
                                     $bAllDay = $aEvent['allDay'];
                                     $sDate = $aUserEvent['time'];
                                     $sSubject = $this->getSubject($oAccount, $sEventStart, $iEventStartTS, $sEventName, $sDate, $iNowTS_UTC, $bAllDay);
                                     $aAccounts = array();
                                     $aAccounts[] = $oAccount;
                                     $aCalendarUsers = $this->oApiCalendarManager->getCalendarUsers($oAccount, $oCalendar);
                                     if (0 < count($aCalendarUsers)) {
                                         foreach ($aCalendarUsers as $aCalendarUser) {
                                             $oCalendarAccount = $this->getAccount($aCalendarUser['email']);
                                             if ($oCalendarAccount) {
                                                 $aAccounts[] = $oCalendarAccount;
                                             }
                                         }
                                     }
                                     foreach ($aAccounts as $oAccountItem) {
                                         $bIsMessageSent = $this->sendMessage($oAccountItem, $sSubject, $sEventName, $sDate, $oCalendar->DisplayName, $sEventText, $oCalendar->Color);
                                         if ($bIsMessageSent) {
                                             $this->oApiCalendarManager->updateReminder($oAccountItem->Email, $sCalendarUri, $sEventId, $vCal->serialize());
                                             CApi::Log('Send reminder for event: \'' . $sEventName . '\' started on \'' . $sDate . '\' to \'' . $oAccountItem->Email . '\'', \ELogLevel::Full, 'cron-');
                                         } else {
                                             CApi::Log('Send reminder for event: FAILED!', ELogLevel::Full, 'cron-');
                                         }
                                     }
                                 } else {
                                     CApi::Log('Calendar ' . $sCalendarUri . ' not found!', ELogLevel::Full, 'cron-');
                                 }
                             }
                         }
                     }
                 }
             }
         }
         file_put_contents($this->sCurRunFilePath, $iNowTS_UTC);
     }
     CApi::Log('---------- End cron script', ELogLevel::Full, 'cron-');
 }