<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
/** @var CBitrixComponent $this */
/** @var array $arParams */
/** @var array $arResult */
/** @var string $componentPath */
/** @var string $componentName */
/** @var string $componentTemplate */
/** @global CDatabase $DB */
/** @global CUser $USER */
/** @global CMain $APPLICATION */

use Bitrix\Main\Context,
	Bitrix\Main\Type\DateTime,
	Bitrix\Main\Loader,
	Bitrix\Iblock;

if($this->StartResultCache(60*60*24, md5(var_export($_POST, true))))
{
	if(CModule::IncludeModule('iblock'))
	{
		$arResult = ['DOCUMENTS' => []];

		$filter = ["ACTIVE" => "Y", "IBLOCK_ID" => 18];
		$rules_res = CIBlockElement::GetList(["ACTIVE_FROM" => "DESC", "SORT" => "DESC"], $filter, false, []);
		
		while ($rules_ob_element = $rules_res->GetNextElement())
		{
			$rules_ar_res = $rules_ob_element->GetFields();
			$rules_ar_res['PROPERTIES'] = $rules_ob_element->GetProperties();

			$f = CFile::GetByID($rules_ar_res['PROPERTIES']['FILE']['VALUE']);

			$arResult['DOCUMENTS'][] = [
				"NAME" => $rules_ar_res['NAME'], 
				"ACTIVE_FROM" => $rules_ar_res['ACTIVE_FROM'], 
				"FILENAME" => $f->Fetch()['ORIGINAL_NAME'], 
				"URL" => CFile::GetPath($rules_ar_res['PROPERTIES']['FILE']['VALUE']), 
			];
		}

		$this->IncludeComponentTemplate();
	}
}