Your IP : 18.191.62.85


Current Path : /home/bitrix/ext_www/easy-comfort.com.ua/local/components/webprofy/search.b2b.result/
Upload File :
Current File : /home/bitrix/ext_www/easy-comfort.com.ua/local/components/webprofy/search.b2b.result/component.php

<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true){
	die();
}
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @var CBitrixComponent $this */
/** @var array $arParams */
/** @var array $arResult */
/** @var string $componentName */
/** @var string $componentPath */
/** @var string $componentTemplate */
/** @var string $parentComponentName */
/** @var string $parentComponentPath */
/** @var string $parentComponentTemplate */
$this->setFrameMode(false);

if(!\Bitrix\Main\Loader::includeModule("search")){
	ShowError(GetMessage("SEARCH_MODULE_UNAVAILABLE"));
	return;
}

CJSCore::Init(array('popup', 'currency'));
$currencyFormat = CCurrencyLang::GetFormatDescription('RUB');

?>
<script>
	BX.Currency.setCurrencyFormat('RUB', <? echo CUtil::PhpToJSObject($currencyFormat, false, true); ?>);
</script>
<?

CPageOption::SetOptionString("main", "nav_page_in_session", "N");

if(!isset($arParams["CACHE_TIME"])){
	$arParams["CACHE_TIME"] = 3600;
}

if($arParams["DEFAULT_SORT"] !== "date"){
	$arParams["DEFAULT_SORT"] = "rank";
}

if(strlen($arParams["FILTER_NAME"]) <= 0 || !preg_match("/^[A-Za-z_][A-Za-z01-9_]*$/", $arParams["FILTER_NAME"])){
	$arFILTERCustom = array();
}else{
	$arFILTERCustom = $GLOBALS[$arParams["FILTER_NAME"]];
	if(!is_array($arFILTERCustom)){
		$arFILTERCustom = array();
	}
}

$exFILTER = CSearchParameters::ConvertParamsToFilter($arParams, "arrFILTER");

//options
if(isset($_REQUEST['qf'])){
	$q = trim($_REQUEST["qf"]);
}else{
	$q = false;
}

/*************************************************************************
 * Operations with cache
 *************************************************************************/
$arrDropdown = array();

$obCache = new CPHPCache;

if(
	$arParams["CACHE_TYPE"] == "N"
	|| ($arParams["CACHE_TYPE"] == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "N")
){
	$arParams["CACHE_TIME"] = 0;
}

if($q !== false){
	$arResult["REQUEST"]["~QUERY"] = $q;
	$arResult["REQUEST"]["QUERY"] = htmlspecialcharsex($q);
}else{
	$arResult["REQUEST"]["~QUERY"] = false;
	$arResult["REQUEST"]["QUERY"] = false;
}


$arResult["URL"] = $APPLICATION->GetCurPage()."?qf=".urlencode($q);

$templatePage = "";
if($this->InitComponentTemplate($templatePage)){
	$template = &$this->GetTemplate();
	$arResult["FOLDER_PATH"] = $folderPath = $template->GetFolder();

	if(strlen($folderPath) > 0){
		if($q){
			$arFilter = array(
				"SITE_ID" => SITE_ID,
				"QUERY" => $arResult["REQUEST"]["~QUERY"],
			);
			$arFilter = array_merge($arFILTERCustom, $arFilter);

			$arQueries = preg_split('/\r\n|[\r\n]/', $q);
			$arResult['QUERIES'] = $arQueries;
			$arResult['SUCCESSFUL'] = $countSuccessful = 0;

			$arSort = array(
				'CUSTOM_RANK' => 'DESC',
				'TITLE_RANK' => 'DESC',
				'RANK' => 'DESC',
				'DATE_CHANGE' => 'DESC'
			);

			$PARAM2 = array();
			$PARAM2[] = $arParams['IBLOCK_ID'];

			$arCat = CCatalog::GetByID($arParams['IBLOCK_ID']);
			/*if ($arCat['OFFERS_IBLOCK_ID']) {
				$PARAM2[] = $arCat['OFFERS_IBLOCK_ID'];
			}*/

			$aParamsEx = array(
				0 => array(
					'=MODULE_ID' => 'iblock',
					//'PARAM1' => $arParams['IBLOCK_TYPE'],
					'PARAM2' => $PARAM2,
				),
				'STEMMING' => false
			);

			foreach($arQueries as $query){
				$arSearchParams = array(
					'SITE_ID' => SITE_ID,
					'QUERY' => $query,
					'TAGS' => '',
				);
				$obSearch = new CSearch();
				$obSearch->Search($arSearchParams, $aSort, $aParamsEx);
				$arResult["SEARCH"] = array();
				$arSearchResult = array();
				if($obSearch->errorno == 0){
					$obSearch->NavStart($arSearchParams["PAGE_RESULT_COUNT"], false);
					$ar = $obSearch->GetNext();
					$arReturn = array();
					while($ar){
						$arReturn[$ar["ID"]] = $ar["ITEM_ID"];
						$ar["CHAIN_PATH"] = $APPLICATION->GetNavChain($ar["URL"], 0, $folderPath."/chain_template.php", true, false);
						$ar["URL"] = htmlspecialcharsbx($ar["URL"]);
						$ar["TAGS"] = array();
						if(!empty($ar["~TAGS_FORMATED"])){
							foreach($ar["~TAGS_FORMATED"] as $name => $tag){
								if($arSearchParams["TAGS_INHERIT"] == "Y"){
									$arTags = $arResult["REQUEST"]["~TAGS_ARRAY"];
									$arTags[$tag] = $tag;
									$tags = implode(",", $arTags);
								}else{
									$tags = $tag;
								}
								$ar["TAGS"][] = array(
									"URL" => $APPLICATION->GetCurPageParam("tags=".urlencode($tags), array("tags")),
									"TAG_NAME" => htmlspecialcharsex($name),
								);
							}
						}
						$arSearchResult[] = $ar;
						$ar = $obSearch->GetNext();
					}
				}
				$arItem['QUERY'] = $query;
				$arItem['RESULTS'] = $arSearchResult;
				if(count($arItem['RESULTS']) !== 0){
					$arResult['SUCCESSFUL'] = ++$countSuccessful;
				}
				unset($arResult["SEARCH"]);
				$arResult['ITEMS'][] = $arItem;
			}
			$arResult['SUCCESSFUL_PERCENT'] = $arResult['SUCCESSFUL'] * 100 / count($arResult['ITEMS']);
		}

		$this->ShowComponentTemplate();
	}
}else{
	$this->__ShowError(str_replace("#PAGE#", $templatePage, str_replace("#NAME#", $this->__templateName, "Can not find '#NAME#' template with page '#PAGE#'")));
}
?>