예제 #1
0
 public function Show($Params = array())
 {
     global $APPLICATION, $USER;
     $arType = false;
     foreach (self::$arTypes as $t) {
         if (self::$type == $t['XML_ID']) {
             $arType = $t;
         }
     }
     if (!$arType) {
         return $APPLICATION->ThrowException('[EC_WRONG_TYPE]' . GetMessage('EC_WRONG_TYPE'));
     }
     if (!CCalendarType::CanDo('calendar_type_view', self::$type)) {
         return $APPLICATION->ThrowException(GetMessage("EC_ACCESS_DENIED"));
     }
     $arStartupEvent = false;
     $showNewEventDialog = false;
     //Show new event dialog
     if (isset($_GET['EVENT_ID'])) {
         if ($_GET['EVENT_ID'] == 'NEW') {
             $showNewEventDialog = true;
         } elseif (substr($_GET['EVENT_ID'], 0, 4) == 'EDIT') {
             $arStartupEvent = self::GetStartUpEvent(intval(substr($_GET['EVENT_ID'], 4)));
             if ($arStartupEvent) {
                 $arStartupEvent['EDIT'] = true;
             }
             if ($arStartupEvent['DT_FROM']) {
                 $ts = self::Timestamp($arStartupEvent['DT_FROM']);
                 $init_month = date('m', $ts);
                 $init_year = date('Y', $ts);
             }
         } elseif ($arStartupEvent = self::GetStartUpEvent($_GET['EVENT_ID'])) {
             if ($arStartupEvent['DT_FROM']) {
                 $ts = self::Timestamp($arStartupEvent['DT_FROM']);
                 $init_month = date('m', $ts);
                 $init_year = date('Y', $ts);
             }
         }
     }
     if (!$init_month && !$init_year && strlen($Params["initDate"]) > 0 && strpos($Params["initDate"], '.') !== false) {
         $ts = self::Timestamp($Params["initDate"]);
         $init_month = date('m', $ts);
         $init_year = date('Y', $ts);
     }
     if (!isset($init_month)) {
         $init_month = date("m");
     }
     if (!isset($init_year)) {
         $init_year = date("Y");
     }
     $id = 'EC' . rand();
     $weekHolidays = array();
     if (isset(self::$settings['week_holidays'])) {
         $days = array('MO' => 0, 'TU' => 1, 'WE' => 2, 'TH' => 3, 'FR' => 4, 'SA' => 5, 'SU' => 6);
         foreach (self::$settings['week_holidays'] as $day) {
             $weekHolidays[] = $days[$day];
         }
     } else {
         $weekHolidays = array(5, 6);
     }
     $yearHolidays = array();
     if (isset(self::$settings['year_holidays'])) {
         foreach (explode(',', self::$settings['year_holidays']) as $date) {
             $date = trim($date);
             $ardate = explode('.', $date);
             if (count($ardate) == 2 && $ardate[0] && $ardate[1]) {
                 $yearHolidays[] = intVal($ardate[0]) . '.' . (intVal($ardate[1]) - 1);
             }
         }
     }
     $yearWorkdays = array();
     if (isset(self::$settings['year_workdays'])) {
         foreach (explode(',', self::$settings['year_workdays']) as $date) {
             $date = trim($date);
             $ardate = explode('.', $date);
             if (count($ardate) == 2 && $ardate[0] && $ardate[1]) {
                 $yearWorkdays[] = intVal($ardate[0]) . '.' . (intVal($ardate[1]) - 1);
             }
         }
     }
     $bShowBanner = self::IsPersonal() && self::$userSettings['showBanner'];
     $bExchange = CCalendar::IsExchangeEnabled() && self::$type == 'user';
     $bExchangeConnected = $bExchange && CDavExchangeCalendar::IsExchangeEnabledForUser(self::$ownerId);
     $bCalDAV = CCalendar::IsCalDAVEnabled() && self::$type == "user";
     $bWebservice = CCalendar::IsWebserviceEnabled();
     $bExtranet = CCalendar::IsExtranetEnabled();
     if (!self::$bIntranet && !$bExchange && !$bCalDAV) {
         $bShowBanner = false;
     }
     $dd = self::GetMeetingRoomList(array('RMiblockId' => self::$settings['rm_iblock_id'], 'pathToMR' => self::$pathesForSite['path_to_rm'], 'VMiblockId' => self::$settings['vr_iblock_id'], 'pathToVR' => self::$pathesForSite['path_to_vr']));
     $JSConfig = array('id' => $id, 'type' => self::$type, 'userId' => self::$userId, 'userName' => self::GetUserName(self::$userId), 'ownerId' => self::$ownerId, 'perm' => $arType['PERM'], 'permEx' => self::$perm, 'bTasks' => self::$bTasks, 'sectionControlsDOMId' => self::$SectionsControlsDOMId, 'week_holidays' => $weekHolidays, 'year_holidays' => $yearHolidays, 'year_workdays' => $yearWorkdays, 'week_start' => self::GetWeekStart(), 'week_days' => CCalendarSceleton::GetWeekDaysEx(self::GetWeekStart()), 'init_month' => $init_month, 'init_year' => $init_year, 'pathToUser' => self::$pathToUser, 'path' => self::$path, 'page' => self::$actionUrl, 'settings' => self::$settings, 'userSettings' => self::$userSettings, 'bShowBanner' => $bShowBanner, 'bAnonym' => self::$bAnonym, 'bIntranet' => self::$bIntranet, 'bWebservice' => $bWebservice, 'bExtranet' => $bExtranet, 'bSocNet' => self::$bSocNet, 'bExchange' => $bExchangeConnected, 'startupEvent' => $arStartupEvent, 'canAddToSuperpose' => self::$bCanAddToSuperpose, 'workTime' => array(self::$settings['work_time_start'], self::$settings['work_time_end']), 'meetingRooms' => self::GetMeetingRoomList(array('RMiblockId' => self::$settings['rm_iblock_id'], 'pathToMR' => self::$pathesForSite['path_to_rm'], 'VMiblockId' => self::$settings['vr_iblock_id'], 'pathToVR' => self::$pathesForSite['path_to_vr'])), 'allowResMeeting' => self::$allowReserveMeeting, 'allowVideoMeeting' => self::$allowVideoMeeting, 'plannerSettings' => CCalendarPlanner::GetUserOptions(), 'bAMPM' => self::$bAMPM, 'bWideDate' => self::$bWideDate, 'WDControllerCID' => 'UFWD' . $id);
     $lastSection = CUserOptions::GetOption("calendar", "last_section", false, self::$userId);
     if (isset($lastSection[self::$type . '_' . self::$ownerId])) {
         $JSConfig['lastSection'] = $lastSection[self::$type . '_' . self::$ownerId];
     }
     // Access permissons for type
     if (CCalendarType::CanDo('calendar_type_access', self::$type)) {
         $JSConfig['TYPE_ACCESS'] = $arType['ACCESS'];
     }
     if ($bCalDAV) {
         self::InitCalDavParams($JSConfig);
     }
     // If enabled superposed sections - fetch it
     $arAddSections = array();
     if (self::$bSuperpose) {
         $arAddSections = self::GetDisplayedSuperposed(self::$userId);
     }
     if (!is_array($arAddSections)) {
         $arAddSections = array();
     }
     $arSectionIds = array();
     $hiddenSections = CCalendarSect::Hidden(self::$userId);
     $arDisplayedSPSections = array();
     foreach ($arAddSections as $sect) {
         $arDisplayedSPSections[] = $sect;
     }
     self::$userMeetingSection = CCalendar::GetCurUserMeetingSection();
     //  **** GET SECTIONS ****
     $arSections = self::GetSectionList(array('ADDITIONAL_IDS' => $arDisplayedSPSections));
     $bReadOnly = !self::$perm['edit'] && !self::$perm['section_edit'];
     if (self::$type == 'user' && self::$ownerId != self::$userId) {
         $bReadOnly = true;
     }
     if (!$USER->IsAuthorized()) {
         $bReadOnly = true;
     }
     $bCreateDefault = true;
     if (self::$type == 'user') {
         $bCreateDefault = self::$ownerId == self::$userId;
     }
     $noEditAccessedCalendars = true;
     $additonalMeetingsId = array();
     foreach ($arSections as $i => $section) {
         $arSections[$i]['~IS_MEETING_FOR_OWNER'] = $section['CAL_TYPE'] == 'user' && $section['OWNER_ID'] != self::$userId && CCalendar::GetMeetingSection($section['OWNER_ID']) == $section['ID'];
         if (!in_array($section['ID'], $hiddenSections)) {
             $arSectionIds[] = $section['ID'];
             // It's superposed calendar of the other user and it's need to show user's meetings
             if ($arSections[$i]['~IS_MEETING_FOR_OWNER']) {
                 $additonalMeetingsId[] = array('ID' => $section['OWNER_ID'], 'SECTION_ID' => $section['ID']);
             }
         }
         // We check access only for main sections because we can't edit superposed section
         if ($arSections[$i]['CAL_TYPE'] == self::$type && $arSections[$i]['OWNER_ID'] == self::$ownerId) {
             if ($noEditAccessedCalendars && $section['PERM']['edit']) {
                 $noEditAccessedCalendars = false;
             }
             if ($bReadOnly && ($section['PERM']['edit'] || $section['PERM']['edit_section'])) {
                 $bReadOnly = false;
             }
         }
         if (self::$bSuperpose && in_array($section['ID'], $arAddSections)) {
             $arSections[$i]['SUPERPOSED'] = true;
         }
         if ($bCreateDefault && $section['CAL_TYPE'] == self::$type && $section['OWNER_ID'] == self::$ownerId) {
             $bCreateDefault = false;
         }
     }
     if ($noEditAccessedCalendars && !$bCreateDefault) {
         $bReadOnly = true;
     }
     if (self::$bSuperpose && $bReadOnly && count($arAddSections) <= 0) {
         self::$bSuperpose = false;
     }
     self::$bReadOnly = $bReadOnly;
     if (!$bReadOnly && $showNewEventDialog) {
         $JSConfig['showNewEventDialog'] = true;
         $JSConfig['bChooseMR'] = isset($_GET['CHOOSE_MR']) && $_GET['CHOOSE_MR'] == "Y";
     }
     if (!in_array($JSConfig['lastSection'], $arSectionIds)) {
         $JSConfig['lastSection'] = $arSectionIds[0];
     }
     //  **** GET EVENTS ****
     // NOTICE: Attendees for meetings selected inside this method and returns as array by link '$arAttendees'
     $arAttendees = array();
     // List of attendees for each event Array([ID] => Array(), ..,);
     $arEvents = self::GetEventList(array('type' => self::$type, 'section' => $arSectionIds, 'fromLimit' => self::Date(mktime(0, 0, 0, $init_month - 1, 20, $init_year), false), 'toLimit' => self::Date(mktime(0, 0, 0, $init_month + 1, 10, $init_year), false), 'additonalMeetingsId' => $additonalMeetingsId), $arAttendees);
     $arTaskIds = array();
     //  **** GET TASKS ****
     if (self::$bTasks && !in_array('tasks', $hiddenSections)) {
         $arTasks = self::GetTaskList(array('fromLimit' => self::Date(mktime(0, 0, 0, $init_month - 1, 20, $init_year), false), 'toLimit' => self::Date(mktime(0, 0, 0, $init_month + 1, 10, $init_year), false)), $arTaskIds);
         if (count($arTasks) > 0) {
             $arEvents = array_merge($arEvents, $arTasks);
         }
     }
     // We don't have any section
     if ($bCreateDefault) {
         $defCalendar = CCalendarSect::CreateDefault(array('type' => CCalendar::GetType(), 'ownerId' => CCalendar::GetOwnerId()));
         $arSectionIds[] = $defCalendar['ID'];
         $arSections[] = $defCalendar;
         self::$userMeetingSection = $defCalendar['ID'];
     }
     if (CCalendarType::CanDo('calendar_type_edit', self::$type)) {
         $JSConfig['new_section_access'] = CCalendarSect::GetDefaultAccess(self::$type, self::$ownerId);
     }
     if ($bReadOnly && (!count($arSections) || count($arSections) == 1 && !self::$bIntranet)) {
         $bShowSections = false;
     } else {
         $bShowSections = true;
     }
     $arColors = array('#CEE669', '#E6A469', '#98AEF6', '#7DDEC2', '#B592EC', '#D98E85', '#F6EA68', '#DDBFEB', '#FF8D89', '#FFCEFF', '#3ABF54', '#BF793A', '#1C1CD8', '#4BB798', '#855CC5', '#B25D52', '#FFBD26', '#C48297', '#E53D37', '#7DF5FF');
     // Build calendar base html and dialogs
     CCalendarSceleton::Build(array('id' => $id, 'type' => self::$type, 'ownerId' => self::$ownerId, 'bShowSections' => $bShowSections, 'bShowSuperpose' => self::$bSuperpose, 'bShowBanner' => $bShowBanner, 'bOutlook' => self::$bIntranet && self::$bWebservice, 'bExtranet' => $bExtranet, 'bReadOnly' => $bReadOnly, 'bShowTasks' => self::$bTasks, 'arTaskIds' => $arTaskIds, 'bSocNet' => self::$bSocNet, 'bIntranet' => self::$bIntranet, 'bCalDAV' => $bCalDAV, 'bExchange' => $bExchange, 'bExchangeConnected' => $bExchangeConnected, 'inPersonalCalendar' => self::IsPersonal(), 'colors' => $arColors, 'bAMPM' => self::$bAMPM));
     $JSConfig['arCalColors'] = $arColors;
     $JSConfig['events'] = $arEvents;
     $JSConfig['attendees'] = $arAttendees;
     $JSConfig['sections'] = $arSections;
     $JSConfig['sectionsIds'] = $arSectionIds;
     $JSConfig['hiddenSections'] = $hiddenSections;
     $JSConfig['readOnly'] = $bReadOnly;
     $JSConfig['accessNames'] = self::GetAccessNames();
     $JSConfig['bSuperpose'] = self::$bSuperpose;
     $JSConfig['additonalMeetingsId'] = $additonalMeetingsId;
     // Append Javascript files and CSS files, and some base configs
     CCalendarSceleton::InitJS($JSConfig);
 }
예제 #2
0
 public static function Edit($Params = array())
 {
     global $DB, $CACHE_MANAGER;
     $arFields = $Params['arFields'];
     // Get current user id
     $userId = isset($Params['userId']) && intVal($Params['userId']) > 0 ? intVal($Params['userId']) : CCalendar::GetCurUserId();
     if (!$userId && isset($arFields['CREATED_BY'])) {
         $userId = intVal($arFields['CREATED_BY']);
     }
     $path = !empty($Params['path']) ? $Params['path'] : CCalendar::GetPath($arFields['CAL_TYPE'], $arFields['OWNER_ID'], true);
     if ($userId < 0) {
         return false;
     }
     if (!self::CheckFields($arFields)) {
         return false;
     }
     if ($arFields['CAL_TYPE'] == 'user') {
         $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']);
     }
     $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
     $arFields['TIMESTAMP_X'] = CCalendar::Date(mktime(), true, false);
     if ($bNew) {
         if (!isset($arFields['CREATED_BY'])) {
             $arFields['CREATED_BY'] = $userId;
         }
         if (!isset($arFields['DATE_CREATE'])) {
             $arFields['DATE_CREATE'] = $arFields['TIMESTAMP_X'];
         }
     }
     $attendees = is_array($arFields['ATTENDEES']) ? $arFields['ATTENDEES'] : array();
     if (!isset($arFields['OWNER_ID']) || !$arFields['OWNER_ID']) {
         $arFields['OWNER_ID'] = 0;
     }
     if (!isset($arFields['LOCATION']['OLD']) && !$bNew) {
         // Select meeting info about event
         if (isset($Params['currentEvent'])) {
             $oldEvent = $Params['currentEvent'];
         } else {
             $oldEvent = CCalendarEvent::GetById($arFields['ID']);
         }
         if ($oldEvent) {
             $arFields['LOCATION']['OLD'] = $oldEvent['LOCATION'];
         }
     }
     $offset = CCalendar::GetOffset();
     $arFields['LOCATION'] = CCalendar::SetLocation($arFields['LOCATION']['OLD'], $arFields['LOCATION']['NEW'], array('dateFrom' => CCalendar::Date($arFields['DT_FROM_TS'] + $offset), 'dateTo' => CCalendar::Date($arFields['DT_TO_TS'] + $offset), 'name' => $arFields['NAME'], 'persons' => count($attendees), 'attendees' => $attendees, 'bRecreateReserveMeetings' => $arFields['LOCATION']['RE_RESERVE'] !== 'N'));
     $bSendInvitations = false;
     if (!isset($arFields['IS_MEETING']) && isset($arFields['ATTENDEES']) && is_array($arFields['ATTENDEES']) && empty($arFields['ATTENDEES'])) {
         $arFields['IS_MEETING'] = false;
     }
     $attendeesCodes = array();
     if ($arFields['IS_MEETING'] && is_array($arFields['MEETING'])) {
         if (!empty($arFields['ATTENDEES_CODES'])) {
             $attendeesCodes = $arFields['ATTENDEES_CODES'];
             $arFields['ATTENDEES_CODES'] = implode(',', $arFields['ATTENDEES_CODES']);
         }
         // Organizer
         $bSendInvitations = $Params['bSendInvitations'] !== false;
         $arFields['~MEETING'] = array('HOST_NAME' => $arFields['MEETING']['HOST_NAME'], 'TEXT' => $arFields['MEETING']['TEXT'], 'OPEN' => $arFields['MEETING']['OPEN'], 'NOTIFY' => $arFields['MEETING']['NOTIFY'], 'REINVITE' => $arFields['MEETING']['REINVITE']);
         $arFields['MEETING'] = serialize($arFields['~MEETING']);
     }
     $arReminders = array();
     if ($arFields['REMIND'] && is_array($arFields['REMIND'])) {
         foreach ($arFields['REMIND'] as $remind) {
             if (in_array($remind['type'], array('min', 'hour', 'day'))) {
                 $arReminders[] = array('type' => $remind['type'], 'count' => floatVal($remind['count']));
             }
         }
     }
     $arFields['REMIND'] = count($arReminders) > 0 ? serialize($arReminders) : '';
     $AllFields = self::GetFields();
     $dbFields = array();
     foreach ($arFields as $field => $val) {
         if (isset($AllFields[$field]) && $field != "ID") {
             $dbFields[$field] = $arFields[$field];
         }
     }
     CTimeZone::Disable();
     if ($bNew) {
         $ID = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE'));
     } else {
         $ID = $arFields['ID'];
         $strUpdate = $DB->PrepareUpdate("b_calendar_event", $dbFields);
         $strSql = "UPDATE b_calendar_event SET " . $strUpdate . " WHERE ID=" . IntVal($arFields['ID']);
         $DB->QueryBind($strSql, array('DESCRIPTION' => $arFields['DESCRIPTION'], 'MEETING' => $arFields['MEETING'], 'RDATE' => $arFields['RDATE'], 'EXDATE' => $arFields['EXDATE']));
     }
     CTimeZone::Enable();
     if ($bNew && !isset($dbFields['DAV_XML_ID'])) {
         $strSql = "UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array('DAV_XML_ID' => $ID)) . " WHERE ID=" . IntVal($ID);
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     // Clean links
     // Del link from table
     if (!$bNew) {
         $arAffectedSections = CCalendarEvent::GetCurrentSectionIds($ID);
         $DB->Query("DELETE FROM b_calendar_event_sect WHERE EVENT_ID=" . IntVal($ID), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     } else {
         $arAffectedSections = array();
     }
     $strSections = "0";
     foreach ($arFields['SECTIONS'] as $sect) {
         if (IntVal($sect) > 0) {
             $strSections .= "," . IntVal($sect);
             $arAffectedSections[] = IntVal($sect);
         }
     }
     if (count($arAffectedSections) > 0) {
         CCalendarSect::UpdateModificationLabel($arAffectedSections);
     }
     // We don't have any section for this event
     // and we have to create default one.
     if ($strSections == "0") {
         $defCalendar = CCalendarSect::CreateDefault(array('type' => CCalendar::GetType(), 'ownerId' => CCalendar::GetOwnerId()));
         $strSections .= "," . IntVal($defCalendar['ID']);
     }
     // Add links
     $strSql = "INSERT INTO b_calendar_event_sect(EVENT_ID, SECT_ID) " . "SELECT " . intVal($ID) . ", ID " . "FROM b_calendar_section " . "WHERE ID in (" . $strSections . ")";
     $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     $bPull = CModule::IncludeModule("pull");
     if ($arFields['IS_MEETING']) {
         if (isset($arFields['ATTENDEES'])) {
             self::InviteAttendees($ID, $arFields, $arFields['ATTENDEES'], is_array($Params['attendeesStatuses']) ? $Params['attendeesStatuses'] : array(), $bSendInvitations, $userId);
             if ($bPull) {
                 // TODO: CACHE IT!
                 $attendees = self::GetAttendees($ID);
                 $attendees = $attendees[$ID];
                 foreach ($attendees as $user) {
                     CPullStack::AddByUser($user['USER_ID'], array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => $attendees, 'NEW' => $bNew ? 'Y' : 'N')));
                 }
             }
         }
     } else {
         if ($bPull) {
             CPullStack::AddByUser($userId, array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => array(), 'NEW' => $bNew ? 'Y' : 'N')));
         }
     }
     // Clean old reminders and add new reminders
     self::UpdateReminders(array('id' => $ID, 'reminders' => $arReminders, 'arFields' => $arFields, 'userId' => $userId, 'path' => $path, 'bNew' => $bNew));
     if ($arFields['CAL_TYPE'] == 'user' && $arFields['IS_MEETING'] && !empty($attendeesCodes)) {
         CCalendarLiveFeed::OnEditCalendarEventEntry($ID, $arFields, $attendeesCodes);
     }
     CCalendar::ClearCache('event_list');
     return $ID;
 }
예제 #3
0
 public static function GetList($Params = array())
 {
     global $DB, $USER_FIELD_MANAGER;
     $getUF = $Params['getUserfields'] !== false;
     $checkPermissions = $Params['checkPermissions'] !== false;
     $bCache = CCalendar::CacheTime() > 0;
     $Params['setDefaultLimit'] = $Params['setDefaultLimit'] === true;
     $userId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId();
     CTimeZone::Disable();
     if ($bCache) {
         $cache = new CPHPCache();
         $cacheId = 'event_list_' . md5(serialize($Params));
         if ($checkPermissions) {
             $cacheId .= 'chper' . CCalendar::GetCurUserId() . '|';
         }
         if (CCalendar::IsSocNet() && CCalendar::IsSocnetAdmin()) {
             $cacheId .= 'socnetAdmin|';
         }
         $cacheId .= CCalendar::GetOffset();
         $cachePath = CCalendar::CachePath() . 'event_list';
         if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) {
             $res = $cache->GetVars();
             $arResult = $res["arResult"];
             $arAttendees = $res["arAttendees"];
         }
     }
     if (!$bCache || !isset($arResult)) {
         $arFilter = $Params['arFilter'];
         if ($getUF) {
             $obUserFieldsSql = new CUserTypeSQL();
             $obUserFieldsSql->SetEntity("CALENDAR_EVENT", "CE.ID");
             $obUserFieldsSql->SetSelect(array("UF_*"));
             $obUserFieldsSql->SetFilter($arFilter);
         }
         $fetchMeetings = $Params['fetchMeetings'];
         $Params['fetchAttendees'] = $Params['fetchAttendees'] !== false;
         $skipDeclined = $Params['skipDeclined'] === true;
         if ($Params['setDefaultLimit'] !== false) {
             if (!isset($arFilter["FROM_LIMIT"])) {
                 // default 3 month back
                 $arFilter["FROM_LIMIT"] = CCalendar::Date(time() - 31 * 3 * 24 * 3600, false);
             }
             if (!isset($arFilter["TO_LIMIT"])) {
                 // default one year into the future
                 $arFilter["TO_LIMIT"] = CCalendar::Date(time() + 365 * 24 * 3600, false);
             }
         }
         $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : array('SORT' => 'asc');
         $arFields = self::GetFields();
         if ($arFilter["DELETED"] === false) {
             unset($arFilter["DELETED"]);
         } elseif (!isset($arFilter["DELETED"])) {
             $arFilter["DELETED"] = "N";
         }
         $ownerId = isset($arFilter['OWNER_ID']) ? $arFilter['OWNER_ID'] : CCalendar::GetOwnerId();
         $arSqlSearch = array();
         if (is_array($arFilter)) {
             $filter_keys = array_keys($arFilter);
             for ($i = 0, $l = count($filter_keys); $i < $l; $i++) {
                 $n = strtoupper($filter_keys[$i]);
                 $val = $arFilter[$filter_keys[$i]];
                 if (is_string($val) && strlen($val) <= 0 || strval($val) == "NOT_REF") {
                     continue;
                 }
                 if ($n == 'FROM_LIMIT') {
                     $ts = CCalendar::Timestamp($val, false);
                     if ($ts > 0) {
                         $arSqlSearch[] = "CE.DATE_TO_TS_UTC>=" . $ts;
                     }
                 } elseif ($n == 'TO_LIMIT') {
                     $ts = CCalendar::Timestamp($val, false);
                     if ($ts > 0) {
                         $arSqlSearch[] = "CE.DATE_FROM_TS_UTC<=" . ($ts + 86399);
                     }
                 } elseif ($n == 'OWNER_ID' && intVal($val) > 0) {
                     $arSqlSearch[] = "CE.OWNER_ID=" . intVal($val);
                 }
                 if ($n == 'NAME') {
                     $arSqlSearch[] = "CE.NAME='" . CDatabase::ForSql($val) . "'";
                 } elseif ($n == 'CREATED_BY') {
                     if (is_array($val)) {
                         $val = array_map(intVal, $val);
                         $arSqlSearch[] = 'CE.CREATED_BY IN (\'' . implode('\',\'', $val) . '\')';
                     } else {
                         if (intVal($val) > 0) {
                             $arSqlSearch[] = "CE.CREATED_BY=" . intVal($val);
                         }
                     }
                 } elseif ($n == 'SECTION') {
                     if (!is_array($val)) {
                         $val = array($val);
                     }
                     $q = "";
                     if (is_array($val)) {
                         $sval = '';
                         foreach ($val as $sectid) {
                             if (intVal($sectid) > 0) {
                                 $sval .= intVal($sectid) . ',';
                             }
                         }
                         $sval = trim($sval, ' ,');
                         if ($sval != '') {
                             $q = 'CES.SECT_ID in (' . $sval . ')';
                         }
                     }
                     if ($q != "") {
                         $arSqlSearch[] = $q;
                     }
                 } elseif ($n == 'DAV_XML_ID' && is_array($val)) {
                     array_walk($val, array($DB, 'ForSql'));
                     $arSqlSearch[] = 'CE.DAV_XML_ID IN (\'' . implode('\',\'', $val) . '\')';
                 } elseif (isset($arFields[$n])) {
                     $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val, 'N');
                 }
             }
         }
         if ($getUF) {
             $r = $obUserFieldsSql->GetFilter();
             if (strlen($r) > 0) {
                 $arSqlSearch[] = "(" . $r . ")";
             }
         }
         if ($skipDeclined) {
             //$arSqlSearch[] = "(CE.IS_MEETING<>1 OR CE.MEETING_STATUS<>'N')";
         }
         $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
         $strOrderBy = '';
         foreach ($arOrder as $by => $order) {
             if (isset($arFields[strtoupper($by)])) {
                 $strOrderBy .= $arFields[strtoupper($by)]["FIELD_NAME"] . ' ' . (strtolower($order) == 'desc' ? 'desc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS LAST" : "") : 'asc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS FIRST" : "")) . ',';
             }
         }
         if (strlen($strOrderBy) > 0) {
             $strOrderBy = "ORDER BY " . rtrim($strOrderBy, ",");
         }
         $selectList = "";
         foreach ($arFields as $field) {
             $selectList .= $field['FIELD_NAME'] . ", ";
         }
         $strSql = "\n\t\t\t\tSELECT " . $selectList . "CES.SECT_ID, CES.REL\n\t\t\t\t\t" . ($getUF ? $obUserFieldsSql->GetSelect() : '') . "\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_event CE\n\t\t\t\tLEFT JOIN b_calendar_event_sect CES ON (CE.ID=CES.EVENT_ID)\n\t\t\t\t" . ($getUF ? $obUserFieldsSql->GetJoin("CE.ID") : '') . "\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strOrderBy}";
         $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($getUF) {
             $res->SetUserFields($USER_FIELD_MANAGER->GetUserFields("CALENDAR_EVENT"));
         }
         $arResult = array();
         $arMeetingIds = array();
         $arEvents = array();
         $bIntranet = CCalendar::IsIntranetEnabled();
         $defaultMeetingSection = false;
         while ($event = $res->Fetch()) {
             $event['IS_MEETING'] = intVal($event['IS_MEETING']) > 0;
             if ($event['IS_MEETING'] && $event['CAL_TYPE'] == 'user' && $event['OWNER_ID'] == $userId && !$event['SECT_ID']) {
                 if (!$defaultMeetingSection) {
                     $defaultMeetingSection = CCalendar::GetMeetingSection($userId);
                     if (!$defaultMeetingSection || !CCalendarSect::GetById($defaultMeetingSection, false)) {
                         $sectRes = CCalendarSect::GetSectionForOwner($event['CAL_TYPE'], $userId);
                         $defaultMeetingSection = $sectRes['sectionId'];
                     }
                 }
                 self::ConnectEventToSection($event['ID'], $defaultMeetingSection);
                 $event['SECT_ID'] = $defaultMeetingSection;
             }
             $arEvents[] = $event;
             if ($bIntranet && $event['IS_MEETING']) {
                 $arMeetingIds[] = $event['ID'];
             }
         }
         if ($Params['fetchAttendees'] && count($arMeetingIds) > 0) {
             $arAttendees = self::GetAttendees($arMeetingIds);
         } else {
             $arAttendees = array();
         }
         foreach ($arEvents as $event) {
             $event["ACCESSIBILITY"] = trim($event["ACCESSIBILITY"]);
             if ($bIntranet && $event['IS_MEETING']) {
                 if (isset($event['MEETING']) && $event['MEETING'] != "") {
                     $event['MEETING'] = unserialize($event['MEETING']);
                     if (!is_array($event['MEETING'])) {
                         $event['MEETING'] = array();
                     }
                 }
                 //					if ($arUserMeeting[$event['ID']])
                 //					{
                 //						$status = $arUserMeeting[$event['ID']]['STATUS'];
                 //						if ($skipDeclined && $status == "N")
                 //							continue;
                 //
                 //						if ($status == "Y" || $userId == $ownerId)
                 //						{
                 //							$event['USER_MEETING'] = array(
                 //								'ATTENDEE_ID' => $ownerId,
                 //								'ACCESSIBILITY' => $arUserMeeting[$event['ID']]['ACCESSIBILITY'],
                 //								'COLOR' => $arUserMeeting[$event['ID']]['COLOR'],
                 //								'TEXT_COLOR' => $arUserMeeting[$event['ID']]['TEXT_COLOR'],
                 //								'DESCRIPTION' => $arUserMeeting[$event['ID']]['DESCRIPTION'],
                 //								'STATUS' => $status,
                 //								'REMIND' => array()
                 //							);
                 //
                 //							if (isset($arUserMeeting[$event['ID']]['REMIND']) && $arUserMeeting[$event['ID']]['REMIND'] != "")
                 //							{
                 //								$event['USER_MEETING']['REMIND'] = unserialize($arUserMeeting[$event['ID']]['REMIND']);
                 //								if (!is_array($event['USER_MEETING']['REMIND']))
                 //									$event['USER_MEETING']['REMIND'] = array();
                 //							}
                 //						}
                 //						else if (is_array($arFilter['SECTION']) && !in_array($event['SECT_ID'], $arFilter['SECTION']))
                 //						{
                 //							continue;
                 //						}
                 //					}
             }
             if (isset($event['REMIND']) && $event['REMIND'] != "") {
                 $event['REMIND'] = unserialize($event['REMIND']);
                 if (!is_array($event['REMIND'])) {
                     $event['REMIND'] = array();
                 }
             }
             if ($bIntranet && $event['IS_MEETING'] && isset($arAttendees[$event['ID']]) && count($arAttendees[$event['ID']]) > 0) {
                 $event['~ATTENDEES'] = $arAttendees[$event['ID']];
             }
             $checkPermissionsForEvent = $userId != $event['CREATED_BY'];
             // It's creator
             // It's event in user's calendar
             if ($checkPermissionsForEvent && $event['CAL_TYPE'] == 'user' && $userId == $event['OWNER_ID']) {
                 $checkPermissionsForEvent = false;
             }
             if ($checkPermissionsForEvent && $event['IS_MEETING'] && $event['USER_MEETING'] && $event['USER_MEETING']['ATTENDEE_ID'] == $userId) {
                 $checkPermissionsForEvent = false;
             }
             if ($checkPermissionsForEvent && $event['IS_MEETING'] && is_array($event['~ATTENDEES'])) {
                 foreach ($event['~ATTENDEES'] as $att) {
                     if ($att['USER_ID'] == $userId) {
                         $checkPermissionsForEvent = false;
                         break;
                     }
                 }
             }
             if ($checkPermissions && $checkPermissionsForEvent) {
                 $event = self::ApplyAccessRestrictions($event, $userId);
             }
             if ($event === false) {
                 continue;
             }
             $event = self::PreHandleEvent($event);
             if ($Params['parseRecursion'] && self::CheckRecurcion($event)) {
                 self::ParseRecursion($arResult, $event, array('fromLimit' => $arFilter["FROM_LIMIT"], 'toLimit' => $arFilter["TO_LIMIT"], 'instanceCount' => isset($Params['maxInstanceCount']) ? $Params['maxInstanceCount'] : false, 'preciseLimits' => isset($Params['preciseLimits']) ? $Params['preciseLimits'] : false));
             } else {
                 self::HandleEvent($arResult, $event);
             }
         }
         if ($bCache) {
             $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath);
             $cache->EndDataCache(array("arResult" => $arResult, "arAttendees" => $arAttendees));
         }
     }
     CTimeZone::Enable();
     //self::$lastAttendeesList = $arAttendees;
     if (!is_array(self::$lastAttendeesList)) {
         self::$lastAttendeesList = $arAttendees;
     } elseif (is_array($arAttendees)) {
         foreach ($arAttendees as $eventId => $att) {
             self::$lastAttendeesList[$eventId] = $att;
         }
     }
     return $arResult;
 }