function GetCalendars($arParams = array())
{
$sectionId = isset($arParams['sectionId']) && $arParams['sectionId'] !== false ? $arParams['sectionId'] : 0;
$iblockId = isset($arParams['iblockId']) && $arParams['iblockId'] !== false ? $arParams['iblockId'] : $this->iblockId;
$xmlId = isset($arParams['xmlId']) && $arParams['xmlId'] !== false ? $arParams['xmlId'] : 0;
$forExport = isset($arParams['forExport']) ? $arParams['forExport'] : false;
$checkPermissions = $forExport ? 'N' : 'Y';
if (!isset($arParams['bOwner']) || $arParams['bOwner'] === true)
{
$bOwner = $this->bOwner;
$ownerType = isset($arParams['ownerType']) ? $arParams['ownerType'] : $this->ownerType;
$ownerId = isset($arParams['ownerId']) ? $arParams['ownerId'] : $this->ownerId;
}
else
{
$bOwner = $arParams['bOwner'];
$ownerType = false;
$ownerId = false;
}
$arFilter = Array(
"SECTION_ID" => $sectionId,
"IBLOCK_ID" => $iblockId,
"ACTIVE" => "Y",
"CHECK_PERMISSIONS" => $checkPermissions
);
if ($xmlId !== 0)
{
$arFilter['XML_ID'] = $xmlId;
if ($sectionId === 0)
unset($arFilter['SECTION_ID']);
}
$bCurUserOwner = true;
if ($bOwner)
{
if ($ownerType == 'USER')
{
$arFilter["CREATED_BY"] = $ownerId;
$bCurUserOwner = $this->userId == $ownerId;
}
elseif ($ownerType == 'GROUP')
{
$arFilter["SOCNET_GROUP_ID"] = $ownerId;
}
}
// get superpose calendars
if (CModule::IncludeModule('extranet') && $arParams['bSuperposed'])
{
if (CExtranet::IsExtranetSite())
{
$arUsersInMyGroupsID = CExtranet::GetMyGroupsUsers(SITE_ID);
$arPublicUsersID = CExtranet::GetPublicUsers();
$arUsersToFilter = array_merge($arUsersInMyGroupsID, $arPublicUsersID);
$arFilter["CREATED_BY"] = $arUsersToFilter;
}
else
{
$arFilter["CREATED_BY"] = CExtranet::GetIntranetUsers();
}
}
if (!$arParams['bSuperposed'] && !$arParams['bOnlyID'])
{
$outerUrl = $GLOBALS['APPLICATION']->GetCurPageParam('', array("action", "bx_event_calendar_request", "clear_cache", "bitrix_include_areas", "bitrix_show_mode", "back_url_admin", "SEF_APPLICATION_CUR_PAGE_URL"), false);
}
if ($ownerType != 'USER' && $ownerType != 'GROUP')
$ownerType = '';
$arSelectFields = array(
"IBLOCK_ID", "ID", "NAME", "DESCRIPTION", "IBLOCK_SECTION_ID", "DATE_CREATE", "XML_ID", "CREATED_BY",
"UF_".$ownerType."_CAL_STATUS",
"UF_".$ownerType."_CAL_COL",
);
if ($ownerType == 'USER')
{
$bExchange = CEventCalendar::IsExchangeEnabled();
$bCalDAV = CEventCalendar::IsCalDAVEnabled();
}
else
{
$bCalDAV = false;
$bExchange = false;
}
if ($bExchange)
{
$arSelectFields[] = 'UF_BXDAVEX_EXCH';
}
if ($bCalDAV)
{
$arSelectFields[] = 'UF_BXDAVEX_CDAV';
$arSelectFields[] = 'UF_BXDAVEX_CDAV_COL';
}
$rsData = CIBlockSection::GetList(Array('SORT' => 'ASC'), $arFilter, false, $arSelectFields);
$arCalendars = array();
while($arRes = $rsData->Fetch())
{
// Private status
$privateStatus = $arRes["UF_".$ownerType."_CAL_STATUS"];
if (!$privateStatus)
$privateStatus = 'full';
// Color
$color = $arRes["UF_".$ownerType."_CAL_COL"];
if (!$color)
$color = '#CEE669';
//$privateStatus = CECCalendar::GetPrivateStatus($iblockId, $arRes['ID'], $ownerType);
if ($privateStatus == 'private' && !$bCurUserOwner)
continue;
if ($arParams['bOnlyID']) // We need only IDs of the calendars
{
$arCalendars[] = intval($arRes['ID']);
continue;
}
$calendar = array(
"ID" => intval($arRes['ID']),
"IBLOCK_ID" => $iblockId,
"IBLOCK_SECTION_ID" => intval($arRes['IBLOCK_SECTION_ID']),
"NAME" => htmlspecialcharsex($arRes['NAME']),
"DESCRIPTION" => htmlspecialcharsex($arRes['DESCRIPTION']),
"COLOR" => $color, //CECCalendar::GetColor($iblockId, $arRes['ID'], $ownerType),
"PRIVATE_STATUS" => $privateStatus,
"DATE_CREATE" => date("d.m.Y H:i", MakeTimeStamp($arRes['DATE_CREATE'], getTSFormat()))
);
if (!$arParams['bSuperposed'])
{
$calendar["OUTLOOK_JS"] = CECCalendar::GetOutlookLink(array('ID' => intval($arRes['ID']), 'XML_ID' => $arRes['XML_ID'], 'IBLOCK_ID' => $iblockId, 'NAME' => htmlspecialcharsex($arRes['NAME']), 'PREFIX' => CEventCalendar::GetOwnerName(array('iblockId' => $iblockId, 'ownerType' => $ownerType, 'ownerId' => $ownerId)), 'LINK_URL' => $outerUrl));
$arExport = CECCalendar::GetExportParams($iblockId, $arRes['ID'], $ownerType, $ownerId);
$calendar["EXPORT"] = $arExport['ALLOW'];
$calendar["EXPORT_SET"] = $arExport['SET'];
$calendar["EXPORT_LINK"] = $arExport['LINK'];
}
$calendar['IS_EXCHANGE'] = $bExchange && $arRes["UF_BXDAVEX_EXCH"] <> '';
if ($bCalDAV && $arRes["UF_BXDAVEX_CDAV_COL"])
$calendar['CALDAV_CON'] = intval($arRes["UF_BXDAVEX_CDAV_COL"]);
$arCalendars[] = $calendar;
$this->arCalenderIndex[$calendar['ID']] = $calendar;
}
return $arCalendars;
}