Current Path : /var/www/www-root/data/www/monolith-realty.ru/local/import/ |
Current File : /var/www/www-root/data/www/monolith-realty.ru/local/import/documents.php |
<?php header('Expires: 0'); header('Pragma: no-cache'); header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); header('Content-Type: application/json; charset=utf-8'); require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); CModule::IncludeModule('iblock'); if(!function_exists('pre')) { function pre($array) { echo '<pre>'; print_r($array); echo '</pre>'; } } function getFilePath($id) { if(!empty($id)) { return $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . CFile::GetPath($id); } } $token = 'yJNTQdseEIlDQMh6V9Kjys8IzVj2GMop'; if(!isset($_GET['token']) || $token !== htmlspecialchars($_GET['token'])) { if (!defined("ERROR_404")) define("ERROR_404", "Y"); \CHTTP::setStatus("404 Not Found"); require(\Bitrix\Main\Application::getDocumentRoot() . "/404.php"); die(); } $documentsIblockId = 62; $sectionsRes = CIBlockSection::GetList([], ['IBLOCK_ID' => $documentsIblockId], false, ['NAME', 'ID']); $arSections = []; while($sectionItem = $sectionsRes->Fetch()) { $arSections[$sectionItem['ID']] = $sectionItem['NAME']; } $pageNum = isset($_GET['page_num']) ? htmlspecialchars($_GET['page_num']) : 1; $pageSize = isset($_GET['page_size']) ? htmlspecialchars($_GET['page_size']) : 10; if($pageNum <= 0) { $pageNum = 1; } $res = CIBlockElement::GetList(['ACTIVE_FROM' => 'DESC'], ['IBLOCK_ID' => $documentsIblockId, 'ACTIVE' => 'Y'], false, //['nPageSize' => $pageSize, 'iNumPage' => $pageNum], ['nTopCount' => $pageSize, 'nOffset' => ($pageNum - 1) * $pageSize], ['ID', 'IBLOCK_SECTION_ID', 'NAME', 'ACTIVE_FROM', 'ACTIVE_TO', 'PROPERTY_FILE', 'DATE_CREATE']); $arResult = [ 'SECTIONS' => $arSections, 'ITEMS' => [], ]; while($item = $res->Fetch()) { $item['FILE'] = getFilePath($item['PROPERTY_FILE_VALUE']); $arResult['ITEMS'][] = $item; } echo json_encode($arResult);