<? if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

if (!empty($arResult["DETAIL_PICTURE"]["SRC"])) {
  $arResult["PICTURE"] = $arResult["DETAIL_PICTURE"]["SRC"];
}

if (!empty($arResult["DISPLAY_PROPERTIES"]["DATE"]["VALUE"])) {
  $arResult["DATE"] = CIBlockFormatProperties::DateFormat($arParams["ACTIVE_DATE_FORMAT"], MakeTimeStamp($arResult["DISPLAY_PROPERTIES"]["DATE"]["VALUE"], CSite::GetDateFormat()));
}


//для кого предназначено
$iblockId=46;

if (!empty($arResult['PROPERTIES']['FOR_EVENTS']['VALUE'])) {
    $arResult['FOR_EVENTS'] = [];
    foreach ($arResult['PROPERTIES']['FOR_EVENTS']['VALUE'] as $item) {
        $arSelect = array("ID", "IBLOCK_ID", "NAME", "PREVIEW_TEXT");//IBLOCK_ID и ID обязательно должны быть
        $arFilter = array("IBLOCK_ID" => $iblockId, "ID" => $item);
        $res = CIBlockElement::GetList(array("SORT"=>"ASC"), $arFilter, false, false, $arSelect);
        while ($ob = $res->GetNextElement()) {
            $arFields = $ob->GetFields();
            $arFields['PROPERTIES'] = $ob->GetProperties();
            $arResult['FOR_EVENTS'][] = $arFields;
        }
    }
}
//программы
$iblockId=47;

if (!empty($arResult['PROPERTIES']['PROGRAMM']['VALUE'])) {
    // получение дней
    $arResult['DAYS']=[];
    $property_enums = CIBlockPropertyEnum::GetList(Array("ID"=>"ASC", "SORT"=>"ASC"), Array("IBLOCK_ID"=>$iblockId, "CODE"=>"DAYS"));
    while ($enum_fields = $property_enums->GetNext()) {
        $arResult['DAYS'][$enum_fields["ID"]]['NAME']=$enum_fields["VALUE"];
    }

    foreach ($arResult['DAYS'] as $k=>$item) {
        $arSelect = array("ID", "IBLOCK_ID", "NAME", "PREVIEW_TEXT","PREVIEW_PICTURE");
        $arResult['DAYS'][$k]['ITEMS']=[];
        $arFilter = array("IBLOCK_ID" => $iblockId, "PROPERTY_DAYS" => $k);
        $res = CIBlockElement::GetList(array("SORT" => "ASC"), $arFilter, false, false, $arSelect);
        if ($res->SelectedRowsCount()>0) {
            while ($ob = $res->GetNextElement()) {
                $arFields = $ob->GetFields();
                if (in_array($arFields['ID'],$arResult['PROPERTIES']['PROGRAMM']['VALUE'])) {
                    $arFields['PREVIEW_PICTURE'] = CFile::GetPath($arFields['PREVIEW_PICTURE']);
                    $arFields['PROPERTIES'] = $ob->GetProperties();
                    $arResult['DAYS'][$k]['ITEMS'][] = $arFields;
                } //else unset($arResult['DAYS'][$k]);

            }
        } else unset($arResult['DAYS'][$k]);
    }

    foreach ($arResult['DAYS'] as $k=>$item) {
        if (empty($item['ITEMS'])){
            unset($arResult['DAYS'][$k]);
        }
    }






}


//спикеры и учатстнки
$iblockId=80;

if (!empty($arResult['PROPERTIES']['SPIKERS']['VALUE'])) {
    $arResult['SPIKERS'] = [];
    foreach ($arResult['PROPERTIES']['SPIKERS']['VALUE'] as $item) {
        $arSelect = array("ID", "IBLOCK_ID", "NAME","PREVIEW_PICTURE","PROPERTY_JOB","PROPERTY_PHOTO1921","PROPERTY_PHOTO768",
        "PROPERTY_PHOTO767");
        $arFilter = array("IBLOCK_ID" => $iblockId, "ID" => $item);
        $res = CIBlockElement::GetList(array("SORT"=>"ASC"), $arFilter, false, false, $arSelect);
        while ($ob = $res->GetNextElement()) {
            $arFields = $ob->GetFields();
            $arFields['PHOTO1921']=CFile::GetPath($arFields['PROPERTY_PHOTO1921_VALUE']);
            $arFields['PHOTO768']=CFile::GetPath($arFields['PROPERTY_PHOTO768_VALUE']);
            $arFields['PHOTO767']=CFile::GetPath($arFields['PROPERTY_PHOTO767_VALUE']);

            $arResult['SPIKERS'][] = $arFields;
        }
    }
}

// формы для онлайн и оффлайн мероприятий
$IblockId=71;// инфоблок
if ($arResult['PROPERTIES']['LINE']['VALUE']=="онлайн"){
    $id=516;
} else   $id=457;
$arFilter = Array(
    "IBLOCK_ID"=>$IblockId,
    "ACTIVE"=>"Y",
    "ID"=>$id

);
$arSelect = Array("ID", "IBLOCK_ID", "NAME","PREVIEW_TEXT","PROPERTY_TITLE","PROPERTY_TAG");//IBLOCK_ID и ID
// обязательно должны быть
// указаны,
$res = CIBlockElement::GetList(Array(), $arFilter, false,array('nTopCount'=>1), $arSelect);
while($ob = $res->GetNextElement()) {
    $arItem = $ob->GetFields();

    $arResult['FORM_TITLE'] = $arItem['~PROPERTY_TITLE_VALUE']['TEXT'];
    $arResult['FORM_TEXT'] = $arItem['PREVIEW_TEXT'];
    $arResult['FORM_TAG'] = $arItem['PROPERTY_TAG_VALUE'];




}



