<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule('iblock');
$iblockId = 27; // Замените на ID вашего инфоблока
// Получение данных из AJAX-запроса
$cityToFind = $_POST['CITY'];
$companyToFind = $_POST['COMPANY'];
$specializationToFind = $_POST['SPECIALIZATION'];
$categoryToFind = $_POST['CATEGORY'];
$arFilter = [
"IBLOCK_ID" => $iblockId,
"ACTIVE" => "Y",
];
// Добавление фильтров на основе полученных данных
if (!empty($cityToFind)) {
$arFilter["PROPERTY_CITY"] = $cityToFind;
}
if (!empty($companyToFind)) {
$arFilter["PROPERTY_COMPANY"] = $companyToFind;
}
if (!empty($specializationToFind)) {
$arFilter["PROPERTY_SPECIALIZATION"] = $specializationToFind;
}
if (!empty($categoryToFind)) {
$arFilter["PROPERTY_CATEGORY"] = $categoryToFind;
}
$arSelect = ["ID", "NAME"];
$res = CIBlockElement::GetList([], $arFilter, false, false, $arSelect);
$arResult = [];
while ($ob = $res->GetNextElement()) {
$arFields = $ob->GetFields();
$arResult[] = [
"ID" => $arFields["ID"],
"NAME" => $arFields["NAME"],
];
}
// Отправка JSON-ответа
header('Content-Type: application/json');
echo json_encode($arResult);
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php");
?>