Example #1
0
 public static function GetAttendeesList($Params = array(), &$strInvIds)
 {
     global $DB;
     $userKey = intVal($Params['userKey']);
     $bCache = CCalendar::CacheTime() > 0;
     if ($bCache) {
         $cache = new CPHPCache();
         $cacheId = 'attendees_list_' . $userKey;
         $cachePath = CCalendar::CachePath() . 'attendees_list';
         if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) {
             $res = $cache->GetVars();
             $strInvIds = $res["strInvIds"];
             $arUserMeeting = $res["arUserMeeting"];
         }
     }
     if (!$bCache || !isset($arUserMeeting)) {
         $strSql = "SELECT * FROM b_calendar_attendees WHERE USER_KEY='" . $userKey . "'";
         $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strInvIds = "";
         $arUserMeeting = array();
         while ($ev = $res->Fetch()) {
             $ev["STATUS"] = trim($ev["STATUS"]);
             $ev["DESCRIPTION"] = trim($ev["DESCRIPTION"]);
             $ev["COLOR"] = trim($ev["COLOR"]);
             $ev["TEXT_COLOR"] = trim($ev["TEXT_COLOR"]);
             $ev["ACCESSIBILITY"] = trim($ev["ACCESSIBILITY"]);
             $arUserMeeting[$ev['EVENT_ID']] = $ev;
             $strInvIds .= ',' . intVal($ev['EVENT_ID']);
         }
         $strInvIds = trim($strInvIds, " ,");
         if ($bCache) {
             $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath);
             $cache->EndDataCache(array("strInvIds" => $strInvIds, "arUserMeeting" => $arUserMeeting));
         }
     }
     return $arUserMeeting;
 }
Example #2
0
	function InstallEvents()
	{
		global $DB;

		$arCurPhpVer = Explode(".", PhpVersion());
		if (IntVal($arCurPhpVer[0]) < 5)
			return true;

		$sIn = "'CALENDAR_INVITATION'";
		$rs = $DB->Query("SELECT count(*) C FROM b_event_type WHERE EVENT_NAME IN (".$sIn.") ", false, "File: ".__FILE__."<br>Line: ".__LINE__);
		$ar = $rs->Fetch();

		if($ar["C"] <= 0)
			include($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/calendar/install/events.php");

		if (!IsModuleInstalled('intranet'))
		{
			COption::SetOptionString("intranet", "calendar_2", "Y");
			CModule::IncludeModule('calendar');
			CCalendar::ClearCache();
			CCalendar::CacheTime(0);

			$arTypes = CCalendarType::GetList();
			if (!$arTypes || !count($arTypes))
			{
				CCalendarType::Edit(array(
					'NEW' => true,
					'arFields' => array(
						'XML_ID' => 'events',
						'NAME' => GetMessage('CAL_DEFAULT_TYPE'),
						'ACCESS' => array(
							'G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_view')
						)
					)
				));
			}
		}

		return true;
	}
Example #3
0
 public static function GetList($Params = array())
 {
     global $DB;
     $access = new CAccess();
     $access->UpdateCodes();
     $arFilter = $Params['arFilter'];
     $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : array('XML_ID' => 'asc');
     $checkPermissions = $Params['checkPermissions'] !== false;
     $bCache = CCalendar::CacheTime() > 0;
     if ($bCache) {
         $cache = new CPHPCache();
         $cacheId = serialize(array('type_list', $arFilter, $arOrder));
         $cachePath = CCalendar::CachePath() . 'type_list';
         if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) {
             $res = $cache->GetVars();
             $arResult = $res["arResult"];
             $arTypeXmlIds = $res["arTypeXmlIds"];
         }
     }
     if (!$bCache || !isset($arTypeXmlIds)) {
         static $arFields = array("XML_ID" => array("FIELD_NAME" => "CT.XML_ID", "FIELD_TYPE" => "string"), "NAME" => array("FIELD_NAME" => "CT.NAME", "FIELD_TYPE" => "string"), "ACTIVE" => array("FIELD_NAME" => "CT.ACTIVE", "FIELD_TYPE" => "string"), "DESCRIPTION" => array("FIELD_NAME" => "CT.DESCRIPTION", "FIELD_TYPE" => "string"), "EXTERNAL_ID" => array("FIELD_NAME" => "CT.EXTERNAL_ID", "FIELD_TYPE" => "string"));
         $err_mess = "Function: CCalendarType::GetList<br>Line: ";
         $arSqlSearch = array();
         $strSqlSearch = "";
         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) {
                     continue;
                 }
                 if ($n == 'XML_ID') {
                     if (is_array($val)) {
                         $strXml = "";
                         foreach ($val as $xmlId) {
                             $strXml .= ",'" . CDatabase::ForSql($xmlId) . "'";
                         }
                         $arSqlSearch[] = "CT.XML_ID in (" . trim($strXml, ", ") . ")";
                     } else {
                         $arSqlSearch[] = GetFilterQuery("CT.XML_ID", $val, 'N');
                     }
                 }
                 if ($n == 'EXTERNAL_ID') {
                     $arSqlSearch[] = GetFilterQuery("CT.EXTERNAL_ID", $val, 'N');
                 } elseif (isset($arFields[$n])) {
                     $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val);
                 }
             }
         }
         $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, ",");
         }
         $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tCT.*\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_type CT\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strOrderBy}";
         $res = $DB->Query($strSql, false, $err_mess . __LINE__);
         $arResult = array();
         $arTypeXmlIds = array();
         while ($arRes = $res->Fetch()) {
             $arResult[] = $arRes;
             $arTypeXmlIds[] = $arRes['XML_ID'];
         }
         if ($bCache) {
             $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath);
             $cache->EndDataCache(array("arResult" => $arResult, "arTypeXmlIds" => $arTypeXmlIds));
         }
     }
     if ($checkPermissions && count($arTypeXmlIds) > 0) {
         $arPerm = self::GetArrayPermissions($arTypeXmlIds);
         $res = array();
         $arAccessCodes = array();
         foreach ($arResult as $type) {
             $typeXmlId = $type['XML_ID'];
             if (self::CanDo('calendar_type_view', $typeXmlId)) {
                 $type['PERM'] = array('view' => self::CanDo('calendar_type_view', $typeXmlId), 'add' => self::CanDo('calendar_type_add', $typeXmlId), 'edit' => self::CanDo('calendar_type_edit', $typeXmlId), 'edit_section' => self::CanDo('calendar_type_edit_section', $typeXmlId), 'access' => self::CanDo('calendar_type_access', $typeXmlId));
                 if (self::CanDo('calendar_type_access', $typeXmlId)) {
                     $type['ACCESS'] = array();
                     if (count($arPerm[$typeXmlId]) > 0) {
                         // Add codes to get they full names for interface
                         $arAccessCodes = array_merge($arAccessCodes, array_keys($arPerm[$typeXmlId]));
                         $type['ACCESS'] = $arPerm[$typeXmlId];
                     }
                 }
                 $res[] = $type;
             }
         }
         CCalendar::PushAccessNames($arAccessCodes);
         $arResult = $res;
     }
     return $arResult;
 }
 public static function GetList($Params = array())
 {
     global $DB, $USER;
     $arFilter = $Params['arFilter'];
     $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : array('SORT' => 'asc');
     $Params['joinTypeInfo'] = !!$Params['joinTypeInfo'];
     $checkPermissions = $Params['checkPermissions'] !== false;
     $bCache = CCalendar::CacheTime() > 0;
     if ($bCache) {
         $cache = new CPHPCache();
         $cacheId = serialize(array('section_list', $arFilter, $arOrder, $Params['joinTypeInfo'], CCalendar::IsIntranetEnabled()));
         $cachePath = CCalendar::CachePath() . 'section_list';
         if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) {
             $res = $cache->GetVars();
             $arResult = $res["arResult"];
             $arSectionIds = $res["arSectionIds"];
         }
     }
     if (!$bCache || !isset($arSectionIds)) {
         $arFields = self::GetFields();
         $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 == 'ID' || $n == 'XML_ID' || $n == 'OWNER_ID') {
                     $arSqlSearch[] = GetFilterQuery("CS." . $n, $val, 'N');
                 } elseif ($n == 'CAL_TYPE' && is_array($val)) {
                     $strType = "";
                     foreach ($val as $type) {
                         $strType .= ",'" . CDatabase::ForSql($type) . "'";
                     }
                     $arSqlSearch[] = "CS.CAL_TYPE in (" . trim($strType, ", ") . ")";
                     $arSqlSearch[] = "CT.ACTIVE='Y'";
                 } elseif (isset($arFields[$n])) {
                     $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val, isset($arFields[$n]["PROCENT"]) && $arFields[$n]["PROCENT"] == "N" ? "N" : "Y");
                 }
             }
         }
         $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, ",");
         }
         $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
         if (isset($arFilter['ADDITIONAL_IDS']) && is_array($arFilter['ADDITIONAL_IDS']) && count($arFilter['ADDITIONAL_IDS']) > 0) {
             $strTypes = "";
             foreach ($arFilter['ADDITIONAL_IDS'] as $adid) {
                 $strTypes .= "," . IntVal($adid);
             }
             $strSqlSearch = '(' . $strSqlSearch . ') OR ID in(' . trim($strTypes, ', ') . ')';
         }
         $select = 'CS.*';
         $from = 'b_calendar_section CS';
         // Fetch types info into selection
         if ($Params['joinTypeInfo']) {
             $select .= ", CT.NAME AS TYPE_NAME, CT.DESCRIPTION AS TYPE_DESC";
             $from .= "\n INNER JOIN b_calendar_type CT ON (CS.CAL_TYPE=CT.XML_ID)";
         }
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\t{$select}\n\t\t\t\tFROM\n\t\t\t\t\t{$from}\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__);
         $arResult = array();
         $arSectionIds = array();
         $isExchangeEnabled = CCalendar::IsExchangeEnabled();
         $isCalDAVEnabled = CCalendar::IsCalDAVEnabled();
         while ($arRes = $res->Fetch()) {
             $arRes['COLOR'] = CCalendar::Color($arRes['COLOR'], true);
             $arSectionIds[] = $arRes['ID'];
             if (isset($arRes['EXPORT']) && $arRes['EXPORT'] != "") {
                 $arRes['EXPORT'] = unserialize($arRes['EXPORT']);
                 if (is_array($arRes['EXPORT']) && $arRes['EXPORT']['ALLOW']) {
                     $arRes['EXPORT']['LINK'] = self::GetExportLink($arRes['ID'], $arRes['CAL_TYPE'], $arRes['OWNER_ID']);
                 }
             }
             if (!is_array($arRes['EXPORT'])) {
                 $arRes['EXPORT'] = array('ALLOW' => false, 'SET' => false, 'LINK' => false);
             }
             // Outlook js
             if (CCalendar::IsIntranetEnabled()) {
                 $arRes['OUTLOOK_JS'] = CCalendarSect::GetOutlookLink(array('ID' => intVal($arRes['ID']), 'XML_ID' => $arRes['XML_ID'], 'TYPE' => $arRes['CAL_TYPE'], 'NAME' => $arRes['NAME'], 'PREFIX' => CCalendar::GetOwnerName($arRes['CAL_TYPE'], $arRes['OWNER_ID']), 'LINK_URL' => CCalendar::GetOuterUrl()));
             }
             if ($arRes['CAL_TYPE'] == 'user') {
                 $arRes['IS_EXCHANGE'] = strlen($arRes["DAV_EXCH_CAL"]) > 0 && $isExchangeEnabled;
                 if ($arRes["CAL_DAV_CON"] && $isCalDAVEnabled) {
                     $arRes["CAL_DAV_CON"] = intVal($arRes["CAL_DAV_CON"]);
                     $resCon = CDavConnection::GetList(array("ID" => "ASC"), array("ID" => $arRes["CAL_DAV_CON"]));
                     if ($con = $resCon->Fetch()) {
                         $arRes['CAL_DAV_CON'] = $arRes["CAL_DAV_CON"];
                     } else {
                         $arRes['CAL_DAV_CON'] = false;
                     }
                 }
             } else {
                 $arRes['IS_EXCHANGE'] = false;
                 $arRes['CAL_DAV_CON'] = false;
             }
             $arResult[] = $arRes;
         }
         if ($bCache) {
             $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath);
             $cache->EndDataCache(array("arResult" => $arResult, "arSectionIds" => $arSectionIds));
         }
     }
     if ($checkPermissions && count($arSectionIds) > 0) {
         $userId = $Params['userId'] ? intVal($Params['userId']) : $USER->GetID();
         $arPerm = CCalendarSect::GetArrayPermissions($arSectionIds);
         $res = array();
         $arAccessCodes = array();
         $settings = CCalendar::GetSettings(array('request' => false));
         foreach ($arResult as $sect) {
             $sectId = $sect['ID'];
             $bOwner = $sect['CAL_TYPE'] == 'user' && $sect['OWNER_ID'] == $userId;
             $bManager = false;
             if (CModule::IncludeModule('intranet') && $sect['CAL_TYPE'] == 'user' && $settings['dep_manager_sub']) {
                 if (!$userId) {
                     $userId = CCalendar::GetUserId();
                 }
                 $bManager = in_array($userId, CCalendar::GetUserManagers($sect['OWNER_ID'], true));
             }
             if ($bOwner || $bManager || self::CanDo('calendar_view_time', $sectId)) {
                 $sect['PERM'] = array('view_time' => $bManager || $bOwner || self::CanDo('calendar_view_time', $sectId, $userId), 'view_title' => $bManager || $bOwner || self::CanDo('calendar_view_title', $sectId, $userId), 'view_full' => $bManager || $bOwner || self::CanDo('calendar_view_full', $sectId, $userId), 'add' => $bOwner || self::CanDo('calendar_add', $sectId, $userId), 'edit' => $bOwner || self::CanDo('calendar_edit', $sectId, $userId), 'edit_section' => $bOwner || self::CanDo('calendar_edit_section', $sectId, $userId), 'access' => $bOwner || self::CanDo('calendar_edit_access', $sectId, $userId));
                 if ($bOwner || self::CanDo('calendar_edit_access', $sectId, $userId)) {
                     $sect['ACCESS'] = array();
                     if (count($arPerm[$sectId]) > 0) {
                         // Add codes to get they full names for interface
                         $arAccessCodes = array_merge($arAccessCodes, array_keys($arPerm[$sectId]));
                         $sect['ACCESS'] = $arPerm[$sectId];
                     }
                 }
                 $res[] = $sect;
             }
         }
         CCalendar::PushAccessNames($arAccessCodes);
         $arResult = $res;
     }
     return $arResult;
 }
Example #5
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;
 }