public function Execute() { if (!CModule::IncludeModule("calendar")) { return CBPActivityExecutionStatus::Closed; } $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $documentService = $this->workflow->GetService("DocumentService"); $fromTs = CCalendar::Timestamp($this->CalendarFrom); $toTs = $this->CalendarTo == '' ? $fromTs : CCalendar::Timestamp($this->CalendarTo); $arFields = array("CAL_TYPE" => !$this->CalendarType ? 'user' : $this->CalendarType, "NAME" => trim($this->CalendarName) == '' ? GetMessage('EC_DEFAULT_EVENT_NAME') : $this->CalendarName, "DESCRIPTION" => $this->CalendarDesrc, "SKIP_TIME" => date('H:i', $fromTs) == '00:00' && date('H:i', $toTs) == '00:00', "IS_MEETING" => false, "RRULE" => false); if ($fromTs == $toTs && !$arFields["SKIP_TIME"]) { $toTs += 3600; } $arFields['DATE_FROM'] = CCalendar::Date($fromTs); $arFields['DATE_TO'] = CCalendar::Date($toTs); if ($this->CalendarSection && intVal($this->CalendarSection) > 0) { $arFields['SECTIONS'] = array(intVal($this->CalendarSection)); } if ($this->CalendarOwnerId || $arFields["CAL_TYPE"] != "user" && $arFields["CAL_TYPE"] != "group") { $arFields["OWNER_ID"] = $this->CalendarOwnerId; $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true)); } else { $arCalendarUser = CBPHelper::ExtractUsers($this->CalendarUser, $documentId); foreach ($arCalendarUser as $calendarUser) { $arFields["CAL_TYPE"] = "user"; $arFields["OWNER_ID"] = $calendarUser; $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true)); } } return CBPActivityExecutionStatus::Closed; }
public function GetListItemChangesSinceToken($listName, $viewFields = '', $query = '', $rowLimit = 0, $changeToken = '') { global $APPLICATION, $USER; if (!$listName_original = CIntranetUtils::checkGUID($listName)) { return new CSoapFault('Data error', 'Wrong GUID - '.$listName); } $listName = ToUpper(CIntranetUtils::makeGUID($listName_original)); $arSections = CCalendarSect::GetList(array('arFilter' => array('XML_ID' => $listName_original))); if (!$arSections || !is_array($arSections[0])) return new CSoapFault( 'List not found', 'List with '.$listName.' GUID not found!' ); $arSection = $arSections[0]; $userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1; if ($changeToken) { //$arMethodParams['timestampFrom'] = ConvertTimeStamp($changeToken, 'FULL'); // $arMethodParams['bLoadAll'] = false; // $arMethodParams['timestampFrom'] = ConvertTimeStamp($changeToken, 'FULL'); // if (!$arMethodParams['timestampFrom']) // { // return new CSoapFault( // 'Params error', // 'Wrong changeToken: '.$changeToken // ); // } } // else // { // $arMethodParams['bLoadAll'] = true; // } $fetchMeetings = $arSection['CAL_TYPE'] == 'user' && CCalendar::GetMeetingSection($arSection['OWNER_ID']) == $arSection['ID']; $arEvents = CCalendarEvent::GetList( array( 'arFilter' => array( 'CAL_TYPE' => $arSection['CAL_TYPE'], 'OWNER_ID' => $arSection['OWNER_ID'], 'SECTION' => $arSection['ID'], 'DELETED' => '' // We fetch all deleted and current events //'INCLUDE_INVITINGS' => 'N' ), 'getUserfields' => false, 'parseRecursion' => false, 'fetchAttendees' => false, 'fetchMeetings' => $fetchMeetings, 'userId' => $userId ) ); $last_change = 0; $data = new CXMLCreator('listitems'); $data->setAttribute('MinTimeBetweenSyncs', 0); $data->setAttribute('RecommendedTimeBetweenSyncs', 180); $data->setAttribute('TimeStamp', $this->__makeDateTime()); $data->setAttribute('EffectivePermMask', 'FullMask'); $data->addChild($obChanges = new CXMLCreator('Changes')); if (!$changeToken && !defined('OLD_OUTLOOK_VERSION')) { $obChanges->addChild($this->__getFieldsDefinition()); } $data->addChild($obData = new CXMLCreator('rs:data')); $count = 0; foreach ($arEvents as $event) { if ($event['DELETED'] != 'N' || ($event['IS_MEETING'] && $event['USER_MEETING']['STATUS'] == 'N')) { $obId = new CXMLCreator('Id'); $obId->setAttribute('ChangeType', 'Delete'); $obId->setData($event['ID']); $obChanges->addChild($obId); } elseif (!$changeToken || $changeToken < CCalendar::Timestamp($event['TIMESTAMP_X'], false)) { $obData->addChild($this->__getRow($event, $listName, $last_change)); $count++; } } $last_change = time(); $obData->setAttribute('ItemCount', $count); $data->setAttribute('xmlns:rs', 'urn:schemas-microsoft-com:rowset'); $data->setAttribute('xmlns:z', '#RowsetSchema'); if ($last_change > 0) $obChanges->setAttribute('LastChangeToken', $last_change); return array('GetListItemChangesSinceTokenResult' => $data); }
public static function DoSaveToDav($Params = array(), &$arFields, $oCurEvent = false) { $sectionId = $Params['sectionId']; $bExchange = $Params['bExchange']; $bCalDav = $Params['bCalDav']; if (isset($oCurEvent['DAV_XML_ID'])) { $arFields['DAV_XML_ID'] = $oCurEvent['DAV_XML_ID']; } if (isset($oCurEvent['DAV_EXCH_LABEL'])) { $arFields['DAV_EXCH_LABEL'] = $oCurEvent['DAV_EXCH_LABEL']; } if (isset($oCurEvent['CAL_DAV_LABEL'])) { $arFields['CAL_DAV_LABEL'] = $oCurEvent['CAL_DAV_LABEL']; } $oSect = CCalendarSect::GetById($sectionId); if ($oCurEvent) { if ($oCurEvent['SECT_ID'] != $sectionId) { $bCalDav = CCalendar::IsCalDAVEnabled() && $oCurEvent['CAL_TYPE'] == 'user' && strlen($oCurEvent['CAL_DAV_LABEL']) > 0; $bExchangeEnabled = CCalendar::IsExchangeEnabled() && $oCurEvent['CAL_TYPE'] == 'user'; if ($bExchangeEnabled || $bCalDav) { $res = CCalendar::DoDeleteToDav(array('bCalDav' => $bCalDav, 'bExchangeEnabled' => $bExchangeEnabled, 'sectionId' => $oCurEvent['SECT_ID']), $oCurEvent); if ($res !== true) { return CCalendar::ThrowError($res); } } } } $fromTs = CCalendar::Timestamp($arFields['DT_FROM']); $toTs = CCalendar::Timestamp($arFields['DT_TO']); if (!isset($arFields['DT_FROM_TS'])) { $arFields['DT_FROM_TS'] = $fromTs; } if (!isset($arFields['DT_TO_TS'])) { $arFields['DT_TO_TS'] = $toTs; } $arDavFields = $arFields; CCalendarEvent::CheckFields($arDavFields); if ($arDavFields['RRULE'] != '') { $arDavFields['RRULE'] = $arFields['RRULE']; } $arDavFields['DETAIL_TEXT'] = $arDavFields['DESCRIPTION']; $arDavFields['DETAIL_TEXT_TYPE'] = 'text'; $arDavFields['ACTIVE_FROM'] = $arDavFields['DT_FROM']; $arDavFields['ACTIVE_TO'] = $arDavFields['DT_TO']; $arDavFields['PROPERTY_LOCATION'] = $arDavFields['LOCATION']['NEW']; if ($arDavFields['PROPERTY_LOCATION'] !== '') { $arDavFields['PROPERTY_LOCATION'] = CCalendar::GetTextLocation($arDavFields['PROPERTY_LOCATION']); } $arDavFields['PROPERTY_IMPORTANCE'] = $arDavFields['IMPORTANCE']; $arDavFields['REMIND_SETTINGS'] = ''; if ($arFields['REMIND'] && is_array($arFields['REMIND']) && is_array($arFields['REMIND'][0])) { $arDavFields['REMIND_SETTINGS'] = floatVal($arFields['REMIND'][0]['count']) . '_' . $arFields['REMIND'][0]['type']; } // RRULE $arDavFields['PROPERTY_PERIOD_TYPE'] = 'NONE'; if (is_array($arFields['RRULE']) && isset($arFields['RRULE']['FREQ']) && in_array($arFields['RRULE']['FREQ'], array('HOURLY', 'DAILY', 'MONTHLY', 'YEARLY', 'WEEKLY'))) { $arDavFields['PROPERTY_PERIOD_TYPE'] = $arFields['RRULE']['FREQ']; // Interval $arDavFields['PROPERTY_PERIOD_COUNT'] = isset($arFields['RRULE']['INTERVAL']) && intVal($arFields['RRULE']['INTERVAL']) > 1 ? intVal($arFields['RRULE']['INTERVAL']) : 1; if ($arFields['RRULE']['FREQ'] == 'WEEKLY' && isset($arFields['RRULE']['BYDAY'])) { //PROPERTY_PERIOD_ADDITIONAL $BYDAYS = array(); $days = array('SU' => 0, 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6); $bydays = explode(',', $arFields['RRULE']['BYDAY']); foreach ($bydays as $day) { $BYDAYS[] = $days[$day]; } $arDavFields['PROPERTY_PERIOD_ADDITIONAL'] = implode(',', $BYDAYS); } $h24 = 60 * 60 * 24; if ($fromTs == $toTs) { $arDavFields['PROPERTY_EVENT_LENGTH'] = $h24; } else { $arDavFields['PROPERTY_EVENT_LENGTH'] = intVal($toTs - $fromTs); if ($arDavFields['PROPERTY_EVENT_LENGTH'] % $h24 == 0) { // We have dates without times $arDavFields['PROPERTY_EVENT_LENGTH'] += $h24; } } // Until date if (isset($arFields['RRULE']['UNTIL'])) { $periodTs = $arFields['RRULE']['UNTIL']; } else { $periodTs = CCalendar::GetMaxTimestamp(); } $arDavFields['ACTIVE_TO'] = CCalendar::Date($periodTs); } // **** Synchronize with CalDav **** if ($bCalDav && $oSect['CAL_DAV_CON'] > 0) { // New event or move existent event to DAV calendar if ($arFields['ID'] <= 0 || $oCurEvent && !$oCurEvent['CAL_DAV_LABEL']) { $DAVRes = CDavGroupdavClientCalendar::DoAddItem($oSect['CAL_DAV_CON'], $oSect['CAL_DAV_CAL'], $arDavFields); } else { // Edit existent event $DAVRes = CDavGroupdavClientCalendar::DoUpdateItem($oSect['CAL_DAV_CON'], $oSect['CAL_DAV_CAL'], $oCurEvent['DAV_XML_ID'], $oCurEvent['CAL_DAV_LABEL'], $arDavFields); } if (!is_array($DAVRes) || !array_key_exists("XML_ID", $DAVRes)) { return CCalendar::CollectCalDAVErros($DAVRes); } // // It's ok, we successfuly save event to caldav calendar - and save it to DB $arFields['DAV_XML_ID'] = $DAVRes['XML_ID']; $arFields['CAL_DAV_LABEL'] = $DAVRes['MODIFICATION_LABEL']; } elseif ($bExchange && $oSect['IS_EXCHANGE'] && strlen($oSect['DAV_EXCH_CAL']) > 0 && $oSect['DAV_EXCH_CAL'] !== 0) { $ownerId = $arFields['OWNER_ID']; // New event or move existent event to Exchange calendar if ($arFields['ID'] <= 0 || $oCurEvent && !$oCurEvent['DAV_EXCH_LABEL']) { $exchRes = CDavExchangeCalendar::DoAddItem($ownerId, $oSect['DAV_EXCH_CAL'], $arDavFields); } else { $exchRes = CDavExchangeCalendar::DoUpdateItem($ownerId, $oCurEvent['DAV_XML_ID'], $oCurEvent['DAV_EXCH_LABEL'], $arDavFields); } if (!is_array($exchRes) || !array_key_exists("XML_ID", $exchRes)) { return CCalendar::CollectExchangeErrors($exchRes); } // It's ok, we successfuly save event to exchange calendar - and save it to DB $arFields['DAV_XML_ID'] = $exchRes['XML_ID']; $arFields['DAV_EXCH_LABEL'] = $exchRes['MODIFICATION_LABEL']; } return true; }
$repeatHTML = GetMessage('EC_RRULE_EVERY_MONTH'); } else { $repeatHTML = GetMessage('EC_RRULE_EVERY_MONTH_1', array('#MONTH#' => $event['RRULE']['INTERVAL'])); } break; case 'YEARLY': if ($event['RRULE']['INTERVAL'] == 1) { $repeatHTML = GetMessage('EC_RRULE_EVERY_YEAR', array('#DAY#' => $event['FROM_MONTH_DAY'], '#MONTH#' => $event['FROM_MONTH'])); } else { $repeatHTML = GetMessage('EC_RRULE_EVERY_YEAR_1', array('#YEAR#' => $event['RRULE']['INTERVAL'], '#DAY#' => $event['FROM_MONTH_DAY'], '#MONTH#' => $event['FROM_MONTH'])); } break; } $repeatHTML .= '<br>' . GetMessage('EC_RRULE_FROM', array('#FROM_DATE#' => CCalendar::Date(CCalendar::Timestamp($event['~DATE_FROM']), false))); if ($event['RRULE']['UNTIL'] != CCalendar::GetMaxDate()) { $repeatHTML .= ' ' . GetMessage('EC_RRULE_UNTIL', array('#UNTIL_DATE#' => CCalendar::Date(CCalendar::Timestamp($event['RRULE']['UNTIL']), false))); } ?> <tr> <td class="bx-cal-view-text-cell-l"><?php echo GetMessage('EC_T_REPEAT'); ?> :</td> <td class="bx-cal-view-text-cell-r"><?php echo $repeatHTML; ?> </td> </tr> <?php } /* if ($event['RRULE']) */
private static function FormatICal($Section, $Events) { $res = 'BEGIN:VCALENDAR PRODID:-//Bitrix//Bitrix Calendar//EN VERSION:2.0 CALSCALE:GREGORIAN METHOD:PUBLISH X-WR-CALNAME:' . self::_ICalPaste($Section['NAME']) . ' X-WR-CALDESC:' . self::_ICalPaste($Section['DESCRIPTION']) . "\n"; $localTime = new DateTime(); $localOffset = $localTime->getOffset(); $h24 = CCalendar::GetDayLen(); foreach ($Events as $event) { //$fts = CCalendar::Timestamp($event['DT_FROM']); //$tts = CCalendar::Timestamp($event['DT_TO']); $fts = $event['DT_FROM_TS']; $tts = $event['DT_TO_TS']; if ($event['DT_SKIP_TIME'] == 'Y') { $dtStart = date("Ymd", $event['DT_FROM_TS']); if ($event['DT_LENGTH'] == $h24) { $dtEnd = $dtStart; } else { $dtEnd = date("Ymd", $event['DT_TO_TS'] - $h24); } } else { $dtStart = date("Ymd\\THis\\Z", $event['DT_FROM_TS'] - $localOffset); $dtEnd = date("Ymd\\THis\\Z", $event['DT_TO_TS'] - $localOffset); } $dtStamp = str_replace('T000000Z', '', date("Ymd\\THisZ", CCalendar::Timestamp($event['TIMESTAMP_X']) - $localOffset)); $uid = md5(uniqid(rand(), true) . $event['ID']) . '@bitrix'; $period = ''; $rrule = CCalendarEvent::ParseRRULE($event['RRULE']); if ($rrule && isset($rrule['FREQ']) && $rrule['FREQ'] != 'NONE') { $period = 'RRULE:FREQ=' . $rrule['FREQ'] . ';'; $period .= 'INTERVAL=' . $rrule['INTERVAL'] . ';'; if ($rrule['FREQ'] == 'WEEKLY') { $period .= 'BYDAY=' . implode(',', $rrule['BYDAY']) . ';'; } if ($event['DT_SKIP_TIME'] == 'Y') { if ($event['DT_LENGTH'] == $h24) { $dtEnd_ = $dtStart; } else { $dtEnd_ = date("Ymd", $event['DT_FROM_TS'] + $event['DT_LENGTH'] - $h24 - $localOffset); } } else { $dtEnd_ = date("Ymd\\THisZ", $event['DT_FROM_TS'] + $event['DT_LENGTH'] - $localOffset); } if (date("Ymd", $tts) != '20380101') { $period .= 'UNTIL=' . $dtEnd . ';'; } $period .= 'WKST=MO'; $dtEnd = $dtEnd_; $period .= "\n"; } $res .= 'BEGIN:VEVENT DTSTART;VALUE=DATE:' . $dtStart . ' DTEND;VALUE=DATE:' . $dtEnd . ' DTSTAMP:' . $dtStamp . ' UID:' . $uid . ' SUMMARY:' . self::_ICalPaste($event['NAME']) . ' DESCRIPTION:' . self::_ICalPaste($event['DESCRIPTION']) . "\n" . $period . ' CLASS:PRIVATE LOCATION:' . self::_ICalPaste(CCalendar::GetTextLocation($event['LOCATION'])) . ' SEQUENCE:0 STATUS:CONFIRMED TRANSP:TRANSPARENT END:VEVENT' . "\n"; } $res .= 'END:VCALENDAR'; if (!defined('BX_UTF') || BX_UTF !== true) { $res = $GLOBALS["APPLICATION"]->ConvertCharset($res, LANG_CHARSET, 'UTF-8'); } return $res; }
$fromLimit = CCalendar::Date($ts + $userOffset, false); $ts = CCalendar::Timestamp($fromLimit); $delta = 5184000; // 86400 * 30 * 2 ~ two month; $toLimit = CCalendar::Date($ts + $delta, false); $arEvents = CCalendar::GetNearestEventsList(array('bCurUserList' => true, 'userId' => $arParams['USER_ID'], 'fromLimit' => $fromLimit, 'toLimit' => $toLimit)); if ($arEvents == 'access_denied') { $arResult['ACCESS_DENIED'] = true; } elseif ($arEvents == 'inactive_feature') { $arResult['INACTIVE_FEATURE'] = true; } elseif (is_array($arEvents)) { $arSections = array(array("ID" => 'today', "NAME" => CMobile::PrepareStrToJson(GetMessage('EVENTS_GROUP_TODAY'))), array("ID" => 'tomorrow', "NAME" => CMobile::PrepareStrToJson(GetMessage('EVENTS_GROUP_TOMORROW'))), array("ID" => 'later', "NAME" => CMobile::PrepareStrToJson(GetMessage('EVENTS_GROUP_LATE')))); $url = '/mobile/calendar/view_event.php'; $arResult['EVENTS'] = array(); $oneDay = 86400; $todayStartTs = CCalendar::Timestamp(CCalendar::Date(time() + $userOffset, false)); $todayEndTs = $todayStartTs + $oneDay - 1; $tomorrowStartTs = $todayStartTs + $oneDay; $tomorrowEndTs = $tomorrowStartTs + $oneDay - 1; $today = CCalendar::Date(time(), false); $tomorrow = CCalendar::Date(time() + 86400, false); $bToday = false; $bTomorrow = false; $bLater = false; $use_sections = "YES"; $iconEvent = '/bitrix/templates/mobile_app/images/calendar/event.png'; $iconMeeting = '/bitrix/templates/mobile_app/images/calendar/meeting.png'; $iconInviting = '/bitrix/templates/mobile_app/images/calendar/meeting-q.png'; $dateFormat = GetMessage('MB_CAL_EVENT_DATE_FORMAT'); $timeFormat = IsAmPmMode() ? GetMessage('MB_CAL_EVENT_TIME_FORMAT_AMPM') : GetMessage('MB_CAL_EVENT_TIME_FORMAT'); $count = count($arEvents);
private static function FormatICal($section, $events) { global $APPLICATION; $res = 'BEGIN:VCALENDAR' . "\n" . 'PRODID:-//Bitrix//Bitrix Calendar//EN' . "\n" . 'VERSION:2.0' . "\n" . 'CALSCALE:GREGORIAN' . "\n" . 'METHOD:PUBLISH' . "\n" . 'X-WR-CALNAME:' . self::_ICalPaste($section['NAME']) . "\n" . 'X-WR-CALDESC:' . self::_ICalPaste($section['DESCRIPTION']) . "\n"; $localTime = new DateTime(); $localOffset = $localTime->getOffset(); foreach ($events as $event) { $fromTs = CCalendar::Timestamp($event['DATE_FROM']); $toTs = CCalendar::Timestamp($event['DATE_TO']); if ($event['DT_SKIP_TIME'] === "Y") { $dtStart = date("Ymd", $fromTs); $dtEnd = date("Ymd", $toTs + CCalendar::GetDayLen()); } else { $fromTsUTC = $fromTs - $event['TZ_OFFSET_FROM']; $toTsUTC = $toTs - $event['TZ_OFFSET_TO']; $dtStart = date("Ymd\\THis\\Z", $fromTsUTC); $dtEnd = date("Ymd\\THis\\Z", $toTsUTC); } $dtStamp = str_replace('T000000Z', '', date("Ymd\\THisZ", CCalendar::Timestamp($event['TIMESTAMP_X']) - $localOffset)); $uid = md5(uniqid(rand(), true) . $event['ID']) . '@bitrix'; $period = ''; $rrule = CCalendarEvent::ParseRRULE($event['RRULE']); if ($rrule && isset($rrule['FREQ']) && $rrule['FREQ'] != 'NONE') { $period = 'RRULE:FREQ=' . $rrule['FREQ'] . ';'; $period .= 'INTERVAL=' . $rrule['INTERVAL'] . ';'; if ($rrule['FREQ'] == 'WEEKLY') { $period .= 'BYDAY=' . implode(',', $rrule['BYDAY']) . ';'; } $until = date("Ymd", $event['DATE_TO_TS_UTC']); if ($until != '20380101') { $period .= 'UNTIL=' . $until . ';'; } $period .= 'WKST=MO'; $period .= "\n"; } $res .= 'BEGIN:VEVENT' . "\n"; if ($event['DT_SKIP_TIME'] === "Y") { $res .= 'DTSTART;VALUE=DATE:' . $dtStart . "\n" . 'DTEND;VALUE=DATE:' . $dtEnd . "\n"; } else { $res .= 'DTSTART;VALUE=DATE-TIME:' . $dtStart . "\n" . 'DTEND;VALUE=DATE-TIME:' . $dtEnd . "\n"; } $res .= 'DTSTAMP:' . $dtStamp . "\n" . 'UID:' . $uid . "\n" . 'SUMMARY:' . self::_ICalPaste($event['NAME']) . "\n" . 'DESCRIPTION:' . self::_ICalPaste($event['DESCRIPTION']) . "\n" . $period . "\n" . 'CLASS:PRIVATE' . "\n" . 'LOCATION:' . self::_ICalPaste(CCalendar::GetTextLocation($event['LOCATION'])) . "\n" . 'SEQUENCE:0' . "\n" . 'STATUS:CONFIRMED' . "\n" . 'TRANSP:TRANSPARENT' . "\n" . 'END:VEVENT' . "\n"; } $res .= 'END:VCALENDAR'; if (!defined('BX_UTF') || BX_UTF !== true) { $res = $APPLICATION->ConvertCharset($res, LANG_CHARSET, 'UTF-8'); } return $res; }
public static function ModifyEvent($calendarId, $arFields) { list($sectionId, $entityType, $entityId) = $calendarId; $userId = $entityType == 'user' ? $entityId : 0; self::$silentErrorMode = true; CCalendar::SetOffset(false, CCalendar::GetOffset($userId)); $entityType = strtolower($entityType); $eventId = isset($arFields["ID"]) && intval($arFields["ID"]) > 0 ? intval($arFields["ID"]) : 0; $arNewFields = array("DAV_XML_ID" => $arFields['XML_ID'], "CAL_DAV_LABEL" => isset($arFields['PROPERTY_BXDAVCD_LABEL']) && strlen($arFields['PROPERTY_BXDAVCD_LABEL']) > 0 ? $arFields['PROPERTY_BXDAVCD_LABEL'] : '', "DAV_EXCH_LABEL" => isset($arFields['PROPERTY_BXDAVEX_LABEL']) && strlen($arFields['PROPERTY_BXDAVEX_LABEL']) > 0 ? $arFields['PROPERTY_BXDAVEX_LABEL'] : '', "ID" => $eventId, 'NAME' => $arFields["NAME"] ? $arFields["NAME"] : GetMessage('EC_NONAME_EVENT'), 'CAL_TYPE' => $entityType, 'OWNER_ID' => $entityId, 'DESCRIPTION' => isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : '', 'SECTIONS' => $sectionId, 'ACCESSIBILITY' => isset($arFields['ACCESSIBILITY']) ? $arFields['ACCESSIBILITY'] : 'busy', 'IMPORTANCE' => isset($arFields['IMPORTANCE']) ? $arFields['IMPORTANCE'] : 'normal', "REMIND" => is_array($arFields['REMIND']) ? $arFields['REMIND'] : array(), "RRULE" => is_array($arFields['RRULE']) ? is_array($arFields['RRULE']) : array(), "VERSION" => isset($arFields['VERSION']) ? intVal($arFields['VERSION']) : 1, "PRIVATE_EVENT" => !!$arFields['PRIVATE_EVENT']); $arNewFields["DATE_FROM"] = $arFields['DATE_FROM']; $arNewFields["DATE_TO"] = $arFields['DATE_TO']; $arNewFields["TZ_FROM"] = $arFields['TZ_FROM']; $arNewFields["TZ_TO"] = $arFields['TZ_TO']; $arNewFields["SKIP_TIME"] = $arFields['SKIP_TIME']; if ($arNewFields["SKIP_TIME"]) { $arNewFields["DATE_TO"] = CCalendar::Date(CCalendar::Timestamp($arNewFields['DATE_TO']) - CCalendar::GetDayLen(), false); } if (!empty($arFields['PROPERTY_REMIND_SETTINGS'])) { $ar = explode("_", $arFields["PROPERTY_REMIND_SETTINGS"]); if (count($ar) == 2) { $arNewFields["REMIND"][] = array('type' => $ar[1], 'count' => floatVal($ar[0])); } } if (!empty($arFields['PROPERTY_ACCESSIBILITY'])) { $arNewFields["ACCESSIBILITY"] = $arFields['PROPERTY_ACCESSIBILITY']; } if (!empty($arFields['PROPERTY_IMPORTANCE'])) { $arNewFields["IMPORTANCE"] = $arFields['PROPERTY_IMPORTANCE']; } if (!empty($arFields['PROPERTY_LOCATION'])) { $arNewFields["LOCATION"] = CCalendar::UnParseTextLocation($arFields['PROPERTY_LOCATION']); } if (!empty($arFields['DETAIL_TEXT'])) { $arNewFields["DESCRIPTION"] = $arFields['DETAIL_TEXT']; } $arNewFields["DESCRIPTION"] = CCalendar::ClearExchangeHtml($arNewFields["DESCRIPTION"]); if (isset($arFields["PROPERTY_PERIOD_TYPE"]) && in_array($arFields["PROPERTY_PERIOD_TYPE"], array("DAILY", "WEEKLY", "MONTHLY", "YEARLY"))) { $arNewFields['RRULE']['FREQ'] = $arFields["PROPERTY_PERIOD_TYPE"]; $arNewFields['RRULE']['INTERVAL'] = $arFields["PROPERTY_PERIOD_COUNT"]; if (!isset($arNewFields['DT_LENGTH']) && !empty($arFields['PROPERTY_EVENT_LENGTH'])) { $arNewFields['DT_LENGTH'] = intval($arFields['PROPERTY_EVENT_LENGTH']); } else { $arNewFields['DT_LENGTH'] = $arFields['DT_TO_TS'] - $arFields['DT_FROM_TS']; } if ($arNewFields['RRULE']['FREQ'] == "WEEKLY" && !empty($arFields['PROPERTY_PERIOD_ADDITIONAL'])) { $arNewFields['RRULE']['BYDAY'] = array(); $bydays = explode(',', $arFields['PROPERTY_PERIOD_ADDITIONAL']); foreach ($bydays as $day) { $day = CCalendar::WeekDayByInd($day, false); if ($day !== false) { $arNewFields['RRULE']['BYDAY'][] = $day; } } $arNewFields['RRULE']['BYDAY'] = implode(',', $arNewFields['RRULE']['BYDAY']); } if (isset($arFields['PROPERTY_PERIOD_UNTIL'])) { $arNewFields['RRULE']['UNTIL'] = $arFields['PROPERTY_PERIOD_UNTIL']; } else { $arNewFields['RRULE']['UNTIL'] = $arFields['DT_TO_TS']; } } $eventId = CCalendar::SaveEvent(array('arFields' => $arNewFields, 'userId' => $userId, 'bAffectToDav' => false, 'bSilentAccessMeeting' => true)); self::$silentErrorMode = false; return $eventId; }
public static function EventAdd($arParams = array(), $nav = null, $server = null) { $userId = CCalendar::GetCurUserId(); $methodName = "calendar.event.add"; if (isset($arParams['from'])) { $from = CRestUtil::unConvertDate($arParams['from']); $arParams['from_ts'] = CCalendar::Timestamp($from); } if (isset($arParams['to'])) { $to = CRestUtil::unConvertDate($arParams['to']); $arParams['to_ts'] = CCalendar::Timestamp($to); } $necessaryParams = array('from_ts', 'to_ts', 'name', 'ownerId', 'type', 'section'); foreach ($necessaryParams as $param) { if (!isset($arParams[$param]) || empty($arParams[$param])) { throw new Exception(GetMessage('CAL_REST_PARAM_EXCEPTION', array('#PARAM_NAME#' => $param, '#REST_METHOD#' => $methodName))); } } $type = $arParams['type']; $ownerId = intval($arParams['ownerId']); $sectionId = $arParams['section']; $res = CCalendarSect::GetList(array('arFilter' => array('CAL_TYPE' => $type, 'OWNER_ID' => $ownerId, 'ID' => $sectionId))); if ($res && is_array($res) && isset($res[0])) { if (!$res[0]['PERM']['add']) { throw new Exception(GetMessage('CAL_REST_ACCESS_DENIED')); } } else { throw new Exception('CAL_REST_SECTION_ERROR'); } $arFields = array("CAL_TYPE" => $type, "OWNER_ID" => $ownerId, "NAME" => trim($arParams['name']), "DT_FROM_TS" => $arParams['from_ts'], "DT_TO_TS" => $arParams['to_ts'], "SECTIONS" => $sectionId); if (isset($arParams['skip_time'])) { $arFields["SKIP_TIME"] = $arParams['skip_time'] == 'Y'; } if (isset($arParams['description'])) { $arFields["DESCRIPTION"] = trim($arParams['description']); } if (isset($arParams['color'])) { $color = CCalendar::Color($arParams['color']); if ($color) { $arFields["COLOR"] = $color; } } if (isset($arParams['text_color'])) { $color = CCalendar::Color($arParams['text_color']); if ($color) { $arFields["TEXT_COLOR"] = $color; } } if (isset($arParams['accessibility'])) { $arFields["ACCESSIBILITY"] = $arParams['accessibility']; } if (isset($arParams['importance'])) { $arFields["IMPORTANCE"] = $arParams['importance']; } if (isset($arParams['private_event'])) { $arFields["PRIVATE_EVENT"] = $arParams['private_event'] == "Y"; } if (isset($arParams['rrule'])) { $arFields["RRULE"] = $arParams['rrule']; } if (isset($arParams['is_meeting'])) { $arFields["IS_MEETING"] = $arParams['is_meeting'] == "Y"; } if (isset($arParams['location'])) { $arFields["LOCATION"] = $arParams['location']; } if (isset($arParams['remind'])) { $arFields["REMIND"] = $arParams['remind']; } if ($arFields['IS_MEETING']) { $arFields['ATTENDEES'] = isset($arParams['attendees']) ? $arParams['attendees'] : false; $meeting = isset($arParams['meeting']) ? $arParams['meeting'] : array(); $arFields['MEETING_HOST'] = isset($arParams['host']) ? intVal($arParams['host']) : $userId; $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($arFields['MEETING_HOST']), 'TEXT' => $meeting['text'], 'OPEN' => (bool) $meeting['open'], 'NOTIFY' => (bool) $meeting['notify'], 'REINVITE' => (bool) $meeting['reinvite']); } $newId = CCalendar::SaveEvent(array('arFields' => $arFields)); if (!$newId) { throw new Exception(GetMessage("CAL_REST_EVENT_NEW_ERROR")); } return $newId; }
public static function GetAbsent($users = false, $Params = array()) { // Can be called from agent... So we have to create $USER if it is not exists $tempUser = CCalendar::TempUser(false, true); $curUserId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId(); $arUsers = array(); if ($users !== false && is_array($users)) { foreach ($users as $id) { if ($id > 0) { $arUsers[] = intVal($id); } } } if (!count($arUsers)) { $users = false; } $arFilter = array('DELETED' => 'N', 'ACCESSIBILITY' => 'absent'); if ($users) { $arFilter['CREATED_BY'] = $users; } if (isset($Params['fromLimit'])) { $arFilter['FROM_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['fromLimit'], false), true, false); } if (isset($Params['toLimit'])) { $arFilter['TO_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['toLimit'], false), true, false); } $arEvents = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'parseRecursion' => true, 'getUserfields' => false, 'userId' => $curUserId, 'preciseLimits' => true, 'checkPermissions' => false, 'skipDeclined' => true)); $bSocNet = CModule::IncludeModule("socialnetwork"); $result = array(); $settings = CCalendar::GetSettings(array('request' => false)); foreach ($arEvents as $event) { $userId = isset($event['USER_ID']) ? $event['USER_ID'] : $event['CREATED_BY']; if ($users !== false && !in_array($userId, $arUsers)) { continue; } if ($bSocNet && !CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $userId, "calendar")) { continue; } if ((!$event['CAL_TYPE'] != 'user' || $curUserId != $event['OWNER_ID']) && $curUserId != $event['CREATED_BY'] && !isset($arUserMeeting[$event['ID']])) { $sectId = $event['SECT_ID']; if (!$event['ACCESSIBILITY']) { $event['ACCESSIBILITY'] = 'busy'; } $private = $event['PRIVATE_EVENT'] && $event['CAL_TYPE'] == 'user'; $bManager = false; if (!$private && CCalendar::IsIntranetEnabled() && CModule::IncludeModule('intranet') && $event['CAL_TYPE'] == 'user' && $settings['dep_manager_sub']) { $bManager = in_array($curUserId, CCalendar::GetUserManagers($event['OWNER_ID'], true)); } if ($private || !CCalendarSect::CanDo('calendar_view_full', $sectId) && !$bManager) { $event = self::ApplyAccessRestrictions($event, $userId); } } $skipTime = $event['DT_SKIP_TIME'] === 'Y'; $fromTs = CCalendar::Timestamp($event['DATE_FROM'], false, !$skipTime); $toTs = CCalendar::Timestamp($event['DATE_TO'], false, !$skipTime); if ($event['DT_SKIP_TIME'] !== 'Y') { $fromTs -= $event['~USER_OFFSET_FROM']; $toTs -= $event['~USER_OFFSET_TO']; } $result[] = array('ID' => $event['ID'], 'NAME' => $event['NAME'], 'DATE_FROM' => CCalendar::Date($fromTs, !$skipTime, false), 'DATE_TO' => CCalendar::Date($toTs, !$skipTime, false), 'DT_FROM_TS' => $fromTs, 'DT_TO_TS' => $toTs, 'CREATED_BY' => $userId, 'DETAIL_TEXT' => '', 'USER_ID' => $userId); } // Sort by DATE_FROM_TS_UTC usort($result, array('CCalendar', '_NearestSort')); CCalendar::TempUser($tempUser, false); return $result; }
$arResult['ACCESS_DENIED'] = true; } elseif ($arEvents == 'inactive_feature') { $arResult['INACTIVE_FEATURE'] = true; } elseif (is_array($arEvents)) { if (strpos($arParams['DETAIL_URL'], '?') !== FALSE) { $arParams['DETAIL_URL'] = substr($arParams['DETAIL_URL'], 0, strpos($arParams['DETAIL_URL'], '?')); } $arParams['DETAIL_URL'] = str_replace('#user_id#', $curUserId, strtolower($arParams['DETAIL_URL'])); for ($i = 0, $l = count($arEvents); $i < $l; $i++) { $arEvents[$i]['_DETAIL_URL'] = $arParams['DETAIL_URL'] . '?EVENT_ID=' . $arEvents[$i]['ID'] . '&EVENT_DATE=' . $arEvents[$i]['DT_FROM']; if ($arEvents[$i]['IS_MEETING'] && $arEvents[$i]['MEETING_STATUS'] == 'Q') { $arEvents[$i]['_ADD_CLASS'] = ' calendar-not-confirmed'; $arEvents[$i]['_Q_ICON'] = '<span class="calendar-reminder" title="' . GetMessage('EC_NOT_CONFIRMED') . '">[?]</span>'; } else { $arEvents[$i]['_ADD_CLASS'] = ''; $arEvents[$i]['_Q_ICON'] = ''; } if ($arEvents[$i]['IMPORTANCE'] == 'high') { $arEvents[$i]['_ADD_CLASS'] = ' imortant-event'; } $fromTs = CCalendar::Timestamp($arEvents[$i]['DATE_FROM']); $toTs = CCalendar::Timestamp($arEvents[$i]['DATE_TO']); $arEvents[$i]['~FROM_TO_HTML'] = CCalendar::GetFromToHtml($fromTs, $toTs, $arEvents[$i]['DT_SKIP_TIME'] == 'Y', $arEvents[$i]['DT_LENGTH']); $arResult['ITEMS'][] = $arEvents[$i]; } array_splice($arResult['ITEMS'], intVal($arParams['EVENTS_COUNT'])); } if ($arParams['RETURN_ARRAY'] == 'Y') { return $arResult; } $this->IncludeComponentTemplate();
<?php define("PUBLIC_AJAX_MODE", true); define("NO_KEEP_STATISTIC", "Y"); define("NO_AGENT_STATISTIC", "Y"); define("NO_AGENT_CHECK", true); define("DisableEventsCheck", true); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); if (check_bitrix_sessid() && CModule::IncludeModule("calendar")) { if (isset($_REQUEST['bx_event_calendar_check_meeting_room']) && $_REQUEST['bx_event_calendar_check_meeting_room'] === 'Y') { $check = false; $settings = CCalendar::GetSettings(); $from = CCalendar::Date(CCalendar::Timestamp($_REQUEST['from'])); $to = CCalendar::Date(CCalendar::Timestamp($_REQUEST['to'])); $loc_new = CCalendar::ParseLocation(trim($_REQUEST['location'])); $params = array('dateFrom' => $from, 'dateTo' => $to, 'regularity' => 'NONE', 'members' => false); if ($loc_new['mrid'] == $settings['vr_iblock_id']) { $params['VMiblockId'] = $settings['vr_iblock_id']; $check = CCalendar::CheckVideoRoom($params); } else { $params['RMiblockId'] = $settings['rm_iblock_id']; $params['mrid'] = $loc_new['mrid']; $params['mrevid_old'] = 0; $check = CCalendar::CheckMeetingRoom($params); } ?> <script>top.BXCRES_Check = <?php echo CUtil::PhpToJSObject($check); ?> ;</script><?php
$arResult['UF_CRM_CAL_EVENT'] = $UF['UF_CRM_CAL_EVENT']; if (empty($arResult['UF_CRM_CAL_EVENT']['VALUE'])) { $arResult['UF_CRM_CAL_EVENT'] = false; } $arResult['UF_WEBDAV_CAL_EVENT'] = $UF['UF_WEBDAV_CAL_EVENT']; if (empty($arResult['UF_WEBDAV_CAL_EVENT']['VALUE'])) { $arResult['UF_WEBDAV_CAL_EVENT'] = false; } $arParams['ATTENDEES_SHOWN_COUNT'] = 4; $arParams['ATTENDEES_SHOWN_COUNT_MAX'] = 8; $arParams['AVATAR_SIZE'] = 30; if (!isset($arParams['EVENT_TEMPLATE_URL'])) { $editUrl = CCalendar::GetPath('user', '#USER_ID#'); $arParams['EVENT_TEMPLATE_URL'] = $editUrl . (strpos($editUrl, "?") === false ? '?' : '&') . 'EVENT_ID=#EVENT_ID#'; } $fromDateTs = CCalendar::Timestamp($arResult['EVENT']['DATE_FROM']); if ($arResult['EVENT']['DT_SKIP_TIME'] !== "Y") { $fromDateTs -= $arResult['EVENT']['~USER_OFFSET_FROM']; } $arResult['EVENT']['FROM_WEEK_DAY'] = FormatDate('D', $fromDateTs); $arResult['EVENT']['FROM_MONTH_DAY'] = FormatDate('j', $fromDateTs); if ($arResult['EVENT']['IS_MEETING']) { $arResult['ATTENDEES_INDEX'] = array(); $arResult['EVENT']['ACCEPTED_ATTENDEES'] = array(); $arResult['EVENT']['DECLINED_ATTENDEES'] = array(); foreach ($arResult['EVENT']['~ATTENDEES'] as $i => $att) { $arResult['ATTENDEES_INDEX'][$att["USER_ID"]] = array("STATUS" => $att['STATUS']); if ($att['STATUS'] != "Q") { $att['AVATAR_SRC'] = CCalendar::GetUserAvatar($att); $att['URL'] = CCalendar::GetUserUrl($att["USER_ID"], $arParams["PATH_TO_USER"]); }
if ($RRULE['INTERVAL'] == 1) { $repeatHTML = GetMessage('EC_RRULE_EVERY_MONTH'); } else { $repeatHTML = GetMessage('EC_RRULE_EVERY_MONTH_1', array('#MONTH#' => $RRULE['INTERVAL'])); } break; case 'YEARLY': if ($RRULE['INTERVAL'] == 1) { $repeatHTML = GetMessage('EC_RRULE_EVERY_YEAR', array('#DAY#' => 0, '#MONTH#' => 0)); } else { $repeatHTML = GetMessage('EC_RRULE_EVERY_YEAR_1', array('#YEAR#' => $RRULE['INTERVAL'], '#DAY#' => 0, '#MONTH#' => 0)); } break; } if ($RRULE['UNTIL'] != '' && $RRULE['UNTIL'] != CCalendar::GetMaxDate()) { $repeatHTML .= '<br>' . GetMessage('EC_RRULE_UNTIL', array('#UNTIL_DATE#' => CCalendar::Date(CCalendar::Timestamp($RRULE['UNTIL'])))); } ?> <tr> <td class="feed-calendar-view-text-cell-l"><?php echo GetMessage('EC_T_REPEAT'); ?> :</td> <td class="feed-calendar-view-text-cell-r"><?php echo $repeatHTML; ?> </td> </tr> <?php } /*if ($event['RRULE'] !== '')*/
function getTSFormat() { return CSite::GetDateFormat("FULL"); } } if (!CModule::IncludeModule("calendar") || !class_exists("CCalendar")) { return ShowError(GetMessage("EC_CALENDAR_MODULE_NOT_INSTALLED")); } // Limits if (strlen($arParams["INIT_DATE"]) > 0 && strpos($arParams["INIT_DATE"], '.') !== false) { $ts = CCalendar::Timestamp($arParams["INIT_DATE"]); } else { $ts = time(); } $fromLimit = CCalendar::Date($ts, false); $ts = CCalendar::Timestamp($fromLimit); $toLimit = CCalendar::Date(mktime(0, 0, 0, date("m", $ts) + $arParams["FUTURE_MONTH_COUNT"], date("d", $ts), date("Y", $ts)), false); $arResult['ITEMS'] = array(); $arEvents = CCalendar::GetNearestEventsList(array('bCurUserList' => $arParams['B_CUR_USER_LIST'], 'fromLimit' => $fromLimit, 'toLimit' => $toLimit, 'type' => $arParams['CALENDAR_TYPE'], 'sectionId' => $arParams['CALENDAR_SECTION_ID'])); if ($arEvents == 'access_denied') { $arResult['ACCESS_DENIED'] = true; } elseif ($arEvents == 'inactive_feature') { $arResult['INACTIVE_FEATURE'] = true; } elseif (is_array($arEvents)) { if (strpos($arParams['DETAIL_URL'], '?') !== FALSE) { $arParams['DETAIL_URL'] = substr($arParams['DETAIL_URL'], 0, strpos($arParams['DETAIL_URL'], '?')); } $arParams['DETAIL_URL'] = str_replace('#user_id#', $curUserId, strtolower($arParams['DETAIL_URL'])); for ($i = 0, $l = count($arEvents); $i < $l; $i++) { $arEvents[$i]['_DETAIL_URL'] = $arParams['DETAIL_URL'] . '?EVENT_ID=' . $arEvents[$i]['ID'] . '&EVENT_DATE=' . $arEvents[$i]['DT_FROM']; if ($arEvents[$i]['IS_MEETING'] && $arEvents[$i]['USER_MEETING']['STATUS'] == 'Q') {
public static function GetAbsent($users = false, $Params = array()) { global $DB; // Can be called from agent... So we have to create $USER if it is not exists $tempUser = CCalendar::TempUser(false, true); $curUserId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId(); $arUsers = array(); if ($users !== false && is_array($users)) { foreach ($users as $id) { if ($id > 0) { $arUsers[] = intVal($id); } } } if (!count($arUsers)) { $users = false; } // Part 1: select ordinary events $arFilter = array('CAL_TYPE' => 'user', 'DELETED' => 'N', 'ACCESSIBILITY' => 'absent'); if (isset($Params['fromLimit'])) { $arFilter['FROM_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['fromLimit'], false), true, false); } if (isset($Params['toLimit'])) { $arFilter['TO_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['toLimit'], false), true, false); } $arEvents = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'getUserfields' => false, 'parseRecursion' => true, 'fetchAttendees' => false, 'fetchMeetings' => true, 'userId' => $curUserId, 'checkPermissions' => false, 'preciseLimits' => true)); // Part 2: select attendees CTimeZone::Disable(); if (count($arUsers) > 0) { $userQ = ' AND CA.USER_ID in (' . implode(',', $arUsers) . ')'; } else { $userQ = ''; } $strSql = "\n\t\t\tSELECT\n\t\t\t\tCA.EVENT_ID as ID, CA.USER_ID, CA.STATUS, CA.ACCESSIBILITY,\n\t\t\t\tCE.CAL_TYPE,CE.OWNER_ID,CE.NAME," . $DB->DateToCharFunction("CE.DT_FROM") . " as DT_FROM," . $DB->DateToCharFunction("CE.DT_TO") . " as DT_TO, CE.DT_LENGTH, CE.PRIVATE_EVENT, CE.ACCESSIBILITY, CE.IMPORTANCE, CE.IS_MEETING, CE.MEETING_HOST, CE.MEETING, CE.LOCATION, CE.RRULE, CE.EXRULE, CE.RDATE, CE.EXDATE,\n\t\t\t\tCES.SECT_ID\n\t\t\tFROM b_calendar_attendees CA\n\t\t\tLEFT JOIN\n\t\t\t\tb_calendar_event CE ON(CA.EVENT_ID=CE.ID)\n\t\t\tLEFT JOIN\n\t\t\t\tb_calendar_event_sect CES ON (CA.EVENT_ID=CES.EVENT_ID)\n\t\t\tWHERE\n\t\t\t\t\tCE.ID IS NOT NULL\n\t\t\t\tAND\n\t\t\t\t\tCE.DELETED='N'\n\t\t\t\tAND\n\t\t\t\t\tSTATUS='Y'\n\t\t\t\tAND\n\t\t\t\t\tCA.ACCESSIBILITY='absent'\n\t\t\t\t{$userQ}\n\t\t\t"; if (isset($arFilter['FROM_LIMIT'])) { $strSql .= "AND "; if (strtoupper($DB->type) == "MYSQL") { $strSql .= "CE.DT_TO>=FROM_UNIXTIME('" . MkDateTime(FmtDate($arFilter['FROM_LIMIT'], "D.M.Y"), "d.m.Y") . "')"; } elseif (strtoupper($DB->type) == "MSSQL") { $strSql .= "CE.DT_TO>=" . $DB->CharToDateFunction($arFilter['FROM_LIMIT'], "SHORT"); } elseif (strtoupper($DB->type) == "ORACLE") { $strSql .= "CE.DT_TO>=TO_DATE('" . FmtDate($arFilter['FROM_LIMIT'], "D.M.Y") . " 00:00:00','dd.mm.yyyy hh24:mi:ss')"; } } if ($arFilter['TO_LIMIT']) { $strSql .= "AND "; if (strtoupper($DB->type) == "MYSQL") { $strSql .= "CE.DT_FROM<=FROM_UNIXTIME('" . MkDateTime(FmtDate($arFilter['TO_LIMIT'], "D.M.Y") . " 23:59:59", "d.m.Y H:i:s") . "')"; } elseif (strtoupper($DB->type) == "MSSQL") { $strSql .= "CE.DT_FROM<=dateadd(day, 1, " . $DB->CharToDateFunction($arFilter['TO_LIMIT'], "SHORT") . ")"; } elseif (strtoupper($DB->type) == "ORACLE") { $strSql .= "CE.DT_FROM<=TO_DATE('" . FmtDate($arFilter['TO_LIMIT'], "D.M.Y") . " 23:59:59','dd.mm.yyyy hh24:mi:ss')"; } } $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arEvents2 = array(); while ($event = $res->Fetch()) { $event = self::PreHandleEvent($event); if ($event['CAL_TYPE'] == 'user' && $event['IS_MEETING'] && $event['OWNER_ID'] == $event['USER_ID']) { continue; } if (self::CheckRecurcion($event)) { self::ParseRecursion($arEvents2, $event, array('fromLimit' => $arFilter["FROM_LIMIT"], 'toLimit' => $arFilter["TO_LIMIT"])); } else { self::HandleEvent($arEvents2, $event); } } CTimeZone::Enable(); $arEvents = array_merge($arEvents, $arEvents2); $bSocNet = CModule::IncludeModule("socialnetwork"); $result = array(); $settings = CCalendar::GetSettings(array('request' => false)); foreach ($arEvents as $event) { $userId = isset($event['USER_ID']) ? $event['USER_ID'] : $event['OWNER_ID']; if ($users !== false && !in_array($userId, $arUsers)) { continue; } if ($bSocNet && !CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $userId, "calendar")) { continue; } if ((!$event['CAL_TYPE'] != 'user' || $curUserId != $event['OWNER_ID']) && $curUserId != $event['CREATED_BY'] && !isset($arUserMeeting[$event['ID']])) { $sectId = $event['SECT_ID']; if (!$event['ACCESSIBILITY']) { $event['ACCESSIBILITY'] = 'busy'; } $private = $event['PRIVATE_EVENT'] && $event['CAL_TYPE'] == 'user'; $bManager = false; if (!$private && CCalendar::IsIntranetEnabled() && CModule::IncludeModule('intranet') && $event['CAL_TYPE'] == 'user' && $settings['dep_manager_sub']) { $bManager = in_array($curUserId, CCalendar::GetUserManagers($event['OWNER_ID'], true)); } if ($private || !CCalendarSect::CanDo('calendar_view_full', $sectId) && !$bManager) { if ($private) { $event['NAME'] = '[' . GetMessage('EC_ACCESSIBILITY_' . strtoupper($event['ACCESSIBILITY'])) . ']'; } else { if (!CCalendarSect::CanDo('calendar_view_title', $sectId)) { $event['NAME'] = '[' . GetMessage('EC_ACCESSIBILITY_' . strtoupper($event['ACCESSIBILITY'])) . ']'; } else { $event['NAME'] = $event['NAME'] . ' [' . GetMessage('EC_ACCESSIBILITY_' . strtoupper($event['ACCESSIBILITY'])) . ']'; } } } } $result[] = array('ID' => $event['ID'], 'NAME' => $event['NAME'], 'DATE_FROM' => $event['DT_FROM'], 'DATE_TO' => $event['DT_TO'], 'DT_FROM_TS' => $event['DT_FROM_TS'], 'DT_TO_TS' => $event['DT_TO_TS'], 'CREATED_BY' => $userId, 'DETAIL_TEXT' => '', 'USER_ID' => $userId); } // Sort by DT_FROM_TS usort($result, array('CCalendar', '_NearestSort')); CCalendar::TempUser($tempUser, false); return $result; }
public function Execute() { if (!CModule::IncludeModule("calendar")) return CBPActivityExecutionStatus::Closed; $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $documentService = $this->workflow->GetService("DocumentService"); $fromTs = CCalendar::Timestamp($this->CalendarFrom); $toTs = $this->CalendarTo == '' ? $fromTs : CCalendar::Timestamp($this->CalendarTo); $arFields = array( "CAL_TYPE" => !$this->CalendarType ? 'user' : $this->CalendarType, "NAME" => trim($this->CalendarName) == '' ? GetMessage('EC_DEFAULT_EVENT_NAME') : $this->CalendarName, "DESCRIPTION" => $this->CalendarDesrc, "SKIP_TIME" => date('H:i', $fromTs) == '00:00' && date('H:i', $toTs) == '00:00', "IS_MEETING" => false, "RRULE" => false ); if ($fromTs == $toTs && !$arFields["SKIP_TIME"]) $toTs += 3600 /* HOUR LENGTH*/; $arFields['DT_FROM_TS'] = $fromTs; $arFields['DT_TO_TS'] = $toTs; if ($this->CalendarOwnerId) { $arFields["OWNER_ID"] = $this->CalendarOwnerId; $eventId = CCalendar::SaveEvent( array( 'arFields' => $arFields, 'autoDetectSection' => true ) ); } else { $arCalendarUser = array(); $arCalendarUserTmp = $this->CalendarUser; $arCalendarUserTmp = (is_array($arCalendarUserTmp) ? $arCalendarUserTmp : array($arCalendarUserTmp)); $l = strlen("user_"); foreach ($arCalendarUserTmp as $user) { if (substr($user, 0, $l) == "user_") { $user = intval(substr($user, $l)); if ($user > 0) $arCalendarUser[] = $user; } else { $arDSUsers = $documentService->GetUsersFromUserGroup($user, $documentId); foreach ($arDSUsers as $v) { $user = intval($v); if ($user > 0) $arCalendarUser[] = $user; } } } foreach ($arCalendarUser as $calendarUser) { $arFields["CAL_TYPE"] = "user"; $arFields["OWNER_ID"] = $calendarUser; $eventId = CCalendar::SaveEvent( array( 'arFields' => $arFields, 'autoDetectSection' => true ) ); } } return CBPActivityExecutionStatus::Closed; }