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;
 }