File manager - Edit - /home/c14075/dragmet-ural.ru/www/bitrix/modules/ammina.regions/include.php
Back
<? IncludeModuleLangFile(__FILE__); CModule::IncludeModule("iblock"); CModule::IncludeModule("catalog"); CModule::IncludeModule("sale"); use Bitrix\Main\Localization\Loc, Bitrix\Main, Bitrix\Catalog, Bitrix\Sale; include_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/ammina.regions/mbfunc.php"); class CAmminaRegions { const LANG_DOMAIN = "DOMAIN"; const LANG_CITY = "CITY"; const LANG_REGION = "REGION"; const LANG_COUNTRY = "COUNTRY"; protected static $saleIncluded = null; protected static $isIMExists = -1; protected static $useSaleDiscount = null; private static $existPriceTypeDiscounts = false; static protected $MODULE_TEST_PERIOD = false; protected static $arAllowSeoMenuIdent = array( "mnu_IPROPERTY_TEMPLATES_SECTION_META_TITLE", "mnu_IPROPERTY_TEMPLATES_SECTION_META_KEYWORDS", "mnu_IPROPERTY_TEMPLATES_SECTION_META_DESCRIPTION", "mnu_IPROPERTY_TEMPLATES_SECTION_PAGE_TITLE", "mnu_IPROPERTY_TEMPLATES_ELEMENT_META_TITLE", "mnu_IPROPERTY_TEMPLATES_ELEMENT_META_KEYWORDS", "mnu_IPROPERTY_TEMPLATES_ELEMENT_META_DESCRIPTION", "mnu_IPROPERTY_TEMPLATES_ELEMENT_PAGE_TITLE", "mnu_IPROPERTY_TEMPLATES_SECTION_PICTURE_FILE_ALT", "mnu_IPROPERTY_TEMPLATES_SECTION_PICTURE_FILE_TITLE", "mnu_IPROPERTY_TEMPLATES_SECTION_PICTURE_FILE_NAME", "mnu_IPROPERTY_TEMPLATES_SECTION_DETAIL_PICTURE_FILE_ALT", "mnu_IPROPERTY_TEMPLATES_SECTION_DETAIL_PICTURE_FILE_TITLE", "mnu_IPROPERTY_TEMPLATES_SECTION_DETAIL_PICTURE_FILE_NAME", "mnu_IPROPERTY_TEMPLATES_ELEMENT_PREVIEW_PICTURE_FILE_ALT", "mnu_IPROPERTY_TEMPLATES_ELEMENT_PREVIEW_PICTURE_FILE_TITLE", "mnu_IPROPERTY_TEMPLATES_ELEMENT_PREVIEW_PICTURE_FILE_NAME", "mnu_IPROPERTY_TEMPLATES_ELEMENT_DETAIL_PICTURE_FILE_ALT", "mnu_IPROPERTY_TEMPLATES_ELEMENT_DETAIL_PICTURE_FILE_TITLE", "mnu_IPROPERTY_TEMPLATES_ELEMENT_DETAIL_PICTURE_FILE_NAME", ); protected static $arAllAllowLang = false; public static $defaultProductSettings = []; public static function OnBuildGlobalMenu(&$aGlobalMenu, &$aModuleMenu) { return; } public static function onMainGeoIpHandlersBuildList() { if (self::isTestPeriodEnd()) { return false; } return new \Bitrix\Main\EventResult( \Bitrix\Main\EventResult::SUCCESS, array( '\Ammina\Regions\GeoIPHandler' => "/bitrix/modules/ammina.regions/lib/geoip.php", ) ); } public static function isTestPeriodEnd() { if (self::$MODULE_TEST_PERIOD === false) { self::$MODULE_TEST_PERIOD = \Bitrix\Main\Loader::includeSharewareModule("ammina.regions"); } return self::$MODULE_TEST_PERIOD === \Bitrix\Main\Loader::MODULE_DEMO_EXPIRED; } public static function getTestPeriodInfo() { if (self::$MODULE_TEST_PERIOD === false) { self::$MODULE_TEST_PERIOD = \Bitrix\Main\Loader::includeSharewareModule("ammina.regions"); } return self::$MODULE_TEST_PERIOD; } public static function doCheckExistsDomain() { if ((defined("ADMIN_SECTION") && ADMIN_SECTION === true) || (defined("BX_CRONTAB") && BX_CRONTAB === true) || (defined("CHK_EVENT") && CHK_EVENT === true)) { return; } if (COption::GetOptionString("ammina.regions", "use_one_domain", "N") === "Y") { return; } $strDomain = amreg_strtolower( trim($_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")]) ); if (COption::GetOptionString("ammina.regions", "only_exists_domains", "Y") === "Y") { $oCache = new CPHPCache(); $strUniqString = 'ammina_region_domains_exists|' . SITE_ID; if ($oCache->InitCache(3600, $strUniqString, 'ammina/regions/domain.list')) { $res = $oCache->GetVars(); $arExistsDomains = $res['DOMAINS']; } if ($oCache->StartDataCache()) { $arExistsDomains = array(); $rDomains = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y" ), "select" => array( "ID", "IS_DEFAULT", "DOMAIN" ), "order" => array("ID" => "ASC") ) ); while ($arDomain = $rDomains->fetch()) { $arExistsDomains[amreg_strtolower(trim($arDomain['DOMAIN']))] = $arDomain; } $oCache->EndDataCache( array( "DOMAINS" => $arExistsDomains ) ); } if (is_array($arExistsDomains) && count($arExistsDomains) > 0 && !isset($arExistsDomains[$strDomain])) { $iToDomainRedirect = false; if (amreg_strpos($strDomain, 'www.') === 0) { $strDomain = amreg_substr($strDomain, 4); if (isset($arExistsDomains[$strDomain])) { $iToDomainRedirect = $arExistsDomains[$strDomain]['ID']; } } if ($iToDomainRedirect === false) { foreach ($arExistsDomains as $k => $v) { if ($v['IS_DEFAULT'] === "Y") { $iToDomainRedirect = $v['ID']; break; } } } if ($iToDomainRedirect === false && count($arExistsDomains) > 0) { $ak = array_keys($arExistsDomains); $iToDomainRedirect = $arExistsDomains[$ak[0]]['ID']; } if ($iToDomainRedirect !== false) { $strLink = \Ammina\Regions\DomainTable::doGetRedirectLinkByDomainId($iToDomainRedirect); if (amreg_strlen($strLink) > 0) { LocalRedirect($strLink, "301 Moved Permanently"); } } } } } public static function ConvertUrlToPathRegion($strUrl, $toDomainId = false, $toCityId = false) { if (COption::GetOptionString("ammina.regions", "use_one_domain", "N") === "Y" && COption::GetOptionString("ammina.regions", "use_path_domain", "N") === "Y" && file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.regions.php")) { $arRegionsUrl = @include($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.regions.php"); $arTemplates = explode("\n", COption::GetOptionString("ammina.regions", "pathdomain_list", "")); foreach ($arTemplates as $k => $v) { $arTemplates[$k] = trim($v); if (amreg_strlen($arTemplates[$k]) <= 0) { unset($arTemplates[$k]); } else { if (amreg_substr($arTemplates[$k], -1, 1) !== '/') { $arTemplates[$k] .= '/'; } } } if ($toDomainId <= 0) { if ($toCityId > 0) { $toDomainId = \Ammina\Regions\DomainTable::doFindDomainByCity($toCityId, SITE_ID); } } if ($toDomainId > 0) { $arReplace = array(); $arDomain = \Ammina\Regions\DomainTable::getRowById($toDomainId); if ($arDomain && amreg_strlen($arDomain['PATHCODE']) > 0) { foreach ($arTemplates as $k => $strTemplate) { $iLevel = 0; if (amreg_strpos($strTemplate, '*[') !== false) { $ar = explode("[", $strTemplate); $ar2 = explode("]", $ar[1]); $iLevel = $ar2[0]; $ar[1] = $ar2[1]; $strTemplate = implode("", $ar); } $strNewLink = str_replace(array('*', '//'), array($arDomain['PATHCODE'], '/'), $strTemplate); $strOriginalLink = str_replace(array('*', '//'), array('', '/'), $strTemplate); $arReplace[$k] = array( "FROM" => $strOriginalLink, "TO" => $strNewLink, "LEVEL" => $iLevel ); } } if (!empty($arReplace) && self::isAllowRegionUrl($strUrl, $arRegionsUrl['EXCLUDE'])) { foreach ($arReplace as $k => $v) { if (amreg_strpos($strUrl, $v['FROM']) !== false) { $bAllow = true; if ($v['LEVEL'] > 0) { $arAfter = explode("/", amreg_substr($strUrl, amreg_strpos($strUrl, $v['FROM']) + amreg_strlen($v['FROM']))); if (count($arAfter) > $v['LEVEL']) { $bAllow = false; } } if ($bAllow) { $strUrl = amreg_str_replace_limit($v["FROM"], $v['TO'], $strUrl, 2); break; } } } } } } return $strUrl; } public static function OnProlog() { if (self::isTestPeriodEnd()) { return false; } self::doCheckAmminaBxKey(); if (amreg_strpos($_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")], ':') !== false) { $ar = explode(":", $_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")]); unset($ar[count($ar) - 1]); $_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")] = implode(":", $ar); } CModule::IncludeModule("catalog"); CModule::IncludeModule("sale"); global $APPLICATION; if (isset($GLOBALS['ARG_SETAGENT_NEXT']) && is_array($GLOBALS['ARG_SETAGENT_NEXT'])) { foreach ($GLOBALS['ARG_SETAGENT_NEXT'] as $k => $v) { \CAgent::Update( $k, array( "NEXT_EXEC" => $v, ) ); } } if (!self::isAllowPageWork()) { return; } self::doCheckExistsDomain(); if (amreg_strlen($_REQUEST['argcity']) > 0) { $app = \Bitrix\Main\Application::getInstance(); $cookie = new \Bitrix\Main\Web\Cookie("ARG_CITY", $_REQUEST['argcity'], 3600 * 24 * 365 + time()); $cookie->setHttpOnly(false); $app->getContext()->getResponse()->addCookie($cookie); unset($_SESSION['BX_GEO_IP']); if (COption::GetOptionString("ammina.regions", "use_one_domain", "N") === "Y") { $strUrl = self::ConvertUrlToPathRegion($APPLICATION->GetCurPageParam("", array("argcity")), false, $_REQUEST['argcity']); } else { $strUrl = "http" . ($APPLICATION->IsHttps() ? "s" : "") . "://" . $_SERVER[COption::GetOptionString( "ammina.regions", "host_var_name", "HTTP_HOST" )] . self::ConvertUrlToPathRegion($APPLICATION->GetCurPageParam("", array("argcity")), false, $_REQUEST['argcity']); } LocalRedirect($strUrl); } $arDomain = false; if (COption::GetOptionString("ammina.regions", "use_one_domain", "N") === "Y") { $cityId = false; if (amreg_strlen($_REQUEST['argcity']) > 0) { $cityId = $_REQUEST['argcity']; } else { $app = \Bitrix\Main\Application::getInstance(); $cityId = intval($app->getContext()->getRequest()->getCookie("ARG_CITY")); } if ($cityId <= 0) { $cityId = \Ammina\Regions\BlockTable::getCityIdByIP(); } $iDomain = \Ammina\Regions\DomainTable::doFindDomainByCity($cityId, SITE_ID); if (isset($_SERVER['REQUIRED_AMMINA_REGION_CODE']) && isset($_SERVER['REQUIRED_AMMINA_DOMAIN_ID']) && COption::GetOptionString("ammina.regions", "use_path_domain", "N") === "Y" && file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.regions.php")) { $arRegionsUrl = @include($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.regions.php"); $bAllow = true; foreach ($arRegionsUrl['EXCLUDE'] as $exclude) { if (amreg_stripos($APPLICATION->GetCurPageParam("", array("argcity")), $exclude) === 0) { $bAllow = false; } } if ($bAllow && $_SERVER['REQUIRED_AMMINA_DOMAIN_ID'] != $iDomain) { $arRequiredDomain = \Ammina\Regions\DomainTable::getRowById(intval($_SERVER['REQUIRED_AMMINA_DOMAIN_ID'])); if ($arRequiredDomain) { $cityId = $arRequiredDomain['CITY_ID']; $app = \Bitrix\Main\Application::getInstance(); $cookie = new \Bitrix\Main\Web\Cookie("ARG_CITY", $cityId, 3600 * 24 * 365 + time()); $cookie->setHttpOnly(false); $app->getContext()->getResponse()->addCookie($cookie); unset($_SESSION['BX_GEO_IP']); //LocalRedirect(self::ConvertUrlToPathRegion($APPLICATION->GetCurPageParam(), $arRequiredDomain['ID'])); $iDomain = $arRequiredDomain['ID']; } } } $oCache = new CPHPCache(); if ($oCache->InitCache(3600, 'ammina_region_domains' . $iDomain, 'ammina/regions/onedomain')) { $res = $oCache->GetVars(); $arDomain = $res['DOMAIN']; $arDomainLocations = $res['LOCATIONS']; $arDomainVariables = $res['VARIABLES']; $GLOBALS['AMMINA_REGIONS'] = $res['GLOBAL_VAR']; $GLOBALS['AMR_TEMPLATES'] = $res['GLOBAL_TMPL']; $_SESSION['AMMINA_REGIONS'] = $res['GLOBAL_VAR']; } if ($oCache->StartDataCache()) { $arDomainLocations = false; $arDomainVariables = false; if ($iDomain > 0) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "ID" => $iDomain, "SITE_ID" => SITE_ID, ), ) )->fetch(); } else { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", "IS_DEFAULT" => "Y", ), ) )->fetch(); } if (!$arDomain) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", ), "order" => array("ID" => "ASC"), ) )->fetch(); } if ($arDomain) { list($arDomain, $arDomainLocations, $arDomainVariables) = self::doLoadDomainById($arDomain['ID']); } $oCache->EndDataCache( array( "DOMAIN" => $arDomain, "LOCATIONS" => $arDomainLocations, "VARIABLES" => $arDomainVariables, "GLOBAL_VAR" => $GLOBALS['AMMINA_REGIONS'], "GLOBAL_TMPL" => $GLOBALS['AMR_TEMPLATES'], ) ); } } else { $arHost = array( amreg_strtolower( $_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")] ) ); if (amreg_strpos( amreg_strtolower($_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")]), "www." ) === 0) { $arHost[] = amreg_substr( amreg_strtolower($_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")]), 4 ); } else { $arHost[] = "www." . amreg_strtolower( $_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")] ); } $oCache = new CPHPCache(); if ($oCache->InitCache(3600, 'ammina_region_domains' . implode("|", $arHost), 'ammina/regions/domain')) { $res = $oCache->GetVars(); $arDomain = $res['DOMAIN']; $arDomainLocations = $res['LOCATIONS']; $arDomainVariables = $res['VARIABLES']; $GLOBALS['AMMINA_REGIONS'] = $res['GLOBAL_VAR']; $GLOBALS['AMR_TEMPLATES'] = $res['GLOBAL_TMPL']; } if (empty($arDomain)) { $oCache->Clean('ammina_region_domains' . implode("|", $arHost), 'ammina/regions/domain'); } if ($oCache->StartDataCache()) { $arDomainLocations = false; $arDomainVariables = false; $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", "DOMAIN" => $arHost, ), ) )->fetch(); if (!$arDomain) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", "IS_DEFAULT" => "Y", ), ) )->fetch(); } if (!$arDomain) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", ), "order" => array("ID" => "ASC"), ) )->fetch(); } if ($arDomain) { list($arDomain, $arDomainLocations, $arDomainVariables) = self::doLoadDomainById($arDomain['ID']); } $oCache->EndDataCache( array( "DOMAIN" => $arDomain, "LOCATIONS" => $arDomainLocations, "VARIABLES" => $arDomainVariables, "GLOBAL_VAR" => $GLOBALS['AMMINA_REGIONS'], "GLOBAL_TMPL" => $GLOBALS['AMR_TEMPLATES'], ) ); } } $arGeoContentId = self::getAllGeocontentId(); foreach ($arGeoContentId as $id => $name) { ob_start(); $APPLICATION->IncludeComponent( "ammina:regions.geocontent", "", array( "CACHE_TIME" => "300", "CACHE_TYPE" => "A", "CONTENT_TYPE" => $id, "IP" => "", "SET_TAG_IDENT" => "N", "SET_TAG_TYPE" => "", "NO_FRAME_MODE" => "Y" ), null, array("HIDE_ICONS" => "Y") ); $GLOBALS['AMR_TEMPLATES']['#AMMINA_GC_' . $id . '#'] = ob_get_contents(); $GLOBALS['AMMINA_REGIONS']['GC_' . $id] = $GLOBALS['AMR_TEMPLATES']['#AMMINA_GC_' . $id . '#']; $GLOBALS['AMR_TEMPLATES']['#AMMINA_GC_' . $id . '_NOHTML#'] = htmlspecialchars( strip_tags($GLOBALS['AMR_TEMPLATES']['#AMMINA_GC_' . $id . '#']) ); $GLOBALS['AMMINA_REGIONS']['GC_' . $id . "_NOHTML"] = $GLOBALS['AMR_TEMPLATES']['#AMMINA_GC_' . $id . '_NOHTML#']; ob_end_clean(); } $curPage = $APPLICATION->GetCurPage(); if (amreg_strpos($curPage, "/bitrix/admin/") !== 0) { if (amreg_strlen($GLOBALS['AMMINA_REGIONS']['SYS_COUNTERS']) > 0) { Main\Page\Asset::getInstance()->addString($GLOBALS['AMMINA_REGIONS']['SYS_COUNTERS']); } if (amreg_strlen($GLOBALS['AMMINA_REGIONS']['SYS_HEAD_STRING']) > 0) { Main\Page\Asset::getInstance()->addString($GLOBALS['AMMINA_REGIONS']['SYS_HEAD_STRING']); } } \Ammina\Regions\DomainTable::doHackCurrency(); self::doCheckAdminPages(); self::doAddMailTemplateFields(); self::doCheckAdminOrderEditPageInterface(); self::doCheckAdminOrderRefreshCurrency(); if (amreg_strpos($APPLICATION->GetCurPage(), '/bitrix/admin/') !== 0) { header( "x-ammina-module: regions" . (in_array( self::getTestPeriodInfo(), array(\Bitrix\Main\Loader::MODULE_DEMO, \Bitrix\Main\Loader::MODULE_DEMO_EXPIRED) ) ? ", demo" : ""), false ); } } protected static function doCheckAdminOrderRefreshCurrency() { global $APPLICATION; if (self::isTestPeriodEnd()) { return false; } if (amreg_strpos( $APPLICATION->GetCurPage(), "/bitrix/admin/sale_order_edit.php" ) === 0 && $_REQUEST['ID'] > 0 && $_REQUEST['refresh_data_and_save'] === "Y") { $arOrder = CSaleOrder::GetByID($_REQUEST['ID']); if ($arOrder && $arOrder['CURRENCY'] != $GLOBALS['AMMINA_REGIONS']['SYS_CURRENCY']) { CSaleOrder::Update( $_REQUEST['ID'], array( "CURRENCY" => $GLOBALS['AMMINA_REGIONS']['SYS_CURRENCY'], ) ); } } } protected static function doLoadDomainById($DOMAIN_ID) { if (self::isTestPeriodEnd()) { return false; } $arResult = array(); $arDomain = false; $arDomainLocations = false; $arDomainVariables = false; if ($DOMAIN_ID > 0) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "ID" => $DOMAIN_ID, ), ) )->fetch(); } if (!$arDomain) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", "IS_DEFAULT" => "Y", ), ) )->fetch(); } if (!$arDomain) { $arDomain = \Ammina\Regions\DomainTable::getList( array( "filter" => array( "SITE_ID" => SITE_ID, "ACTIVE" => "Y", "IS_DEFAULT" => "Y", ), ) )->fetch(); } if ($arDomain) { $arDomain['NAME'] = \Ammina\Regions\DomainTable::getLangName($arDomain['ID']); if ($arDomain['CITY_ID'] > 0) { $arDomainLocations['CITY_ID'][] = $arDomain['CITY_ID']; } $rLocations = \Ammina\Regions\DomainLocationTable::getList( array( "filter" => array( "DOMAIN_ID" => $arDomain['ID'], ), ) ); while ($arLocation = $rLocations->fetch()) { if ($arLocation['COUNTRY_ID'] > 0) { $arDomainLocations['COUNTRY_ID'][] = $arLocation['COUNTRY_ID']; } if ($arLocation['REGION_ID'] > 0) { $arDomainLocations['REGION_ID'][] = $arLocation['REGION_ID']; } if ($arLocation['CITY_ID'] > 0) { $arDomainLocations['CITY_ID'][] = $arLocation['CITY_ID']; } } $arAllVariables = array(); $rAllVars = \Ammina\Regions\VariableTable::getList( array( "select" => array("ID", "CODE", "NAME") ) ); while ($arAllVars = $rAllVars->fetch()) { $arAllVariables[$arAllVars['ID']] = $arAllVars; } $rVariables = \Ammina\Regions\DomainVariableTable::getList( array( "filter" => array( "DOMAIN_ID" => $arDomain['ID'], ), "select" => array("*", "VARIABLE_NAME" => "VARIABLE.NAME", "VARIABLE_CODE" => "VARIABLE.CODE"), ) ); while ($arVariable = $rVariables->fetch()) { unset($arAllVariables[$arVariable['VARIABLE_ID']]); $arDomainVariables[] = $arVariable; if (is_array($arVariable['VALUE'])) { $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_' . $arVariable['VARIABLE_CODE'] . '#'] = implode( $arDomain['VARIABLE_SEPARATOR'], $arVariable['VALUE'] ); } else { $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_' . $arVariable['VARIABLE_CODE'] . '#'] = $arVariable['VALUE']; } $GLOBALS['AMR_TEMPLATES_NAME']['#AMMINA_REGIONS_' . $arVariable['VARIABLE_CODE'] . '#'] = $arVariable['VARIABLE_NAME']; if (!empty($arVariable['VARIABLE_CODE'])) { $GLOBALS['AMMINA_REGIONS'][$arVariable['VARIABLE_CODE']] = $arVariable['VALUE']; } } $GLOBALS['AMMINA_REGIONS']['SYS_CURRENT_DOMAIN_ID'] = $arDomain['ID']; foreach ($arAllVariables as $id => $arVariable) { $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_' . $arVariable['CODE'] . '#'] = ""; if (amreg_strlen($arVariable['CODE']) > 0) { $GLOBALS['AMMINA_REGIONS'][$arVariable['CODE']] = ""; } $GLOBALS['AMR_TEMPLATES_NAME']['#AMMINA_REGIONS_' . $arVariable['CODE'] . '#'] = $arVariable['NAME']; } } if (!is_array($arDomain['NAME_LANG'])) { $arDomain['NAME_LANG'] = array($arDomain['NAME_LANG']); } $arDomain['NAME'] = self::getLangFirstName(array_merge(array("ru" => $arDomain['NAME']), $arDomain['NAME_LANG'])); foreach ($arDomainVariables as $k => $v) { if (!empty($v['VALUE_LANG'])) { if (!is_array($arDomain['NAME_LANG'])) { $v['VALUE_LANG'] = array($v['VALUE_LANG']); } $arDomainVariables[$k]['VALUE'] = self::getLangFirstName(array_merge(array("ru" => $v['VALUE']), $v['VALUE_LANG'])); } } $arResult = array($arDomain, $arDomainLocations, $arDomainVariables); return $arResult; } protected static function doCheckAdminPages() { if (self::isTestPeriodEnd()) { return false; } global $APPLICATION; $isAdminSalePages = false; $ORDER_ID = false; $curPage = $APPLICATION->GetCurPageParam(); if (amreg_strpos($curPage, "/bitrix/admin/sale_order_edit.php") === 0 && $_REQUEST['ID'] > 0) { $isAdminSalePages = true; $ORDER_ID = $_REQUEST['ID']; } elseif (amreg_strpos($curPage, "/bitrix/admin/sale_order_view.php") === 0 && $_REQUEST['ID'] > 0) { $isAdminSalePages = true; $ORDER_ID = $_REQUEST['ID']; } elseif (amreg_strpos($curPage, "/bitrix/admin/sale_order_create.php") === 0 && $_REQUEST['ID'] > 0) { $isAdminSalePages = true; $ORDER_ID = $_REQUEST['ID']; } elseif (amreg_strpos($curPage, "/bitrix/admin/sale_order_print.php") === 0 && $_REQUEST['ORDER_ID'] > 0) { $isAdminSalePages = true; $ORDER_ID = $_REQUEST['ORDER_ID']; } elseif (amreg_strpos($curPage, "/bitrix/admin/sale_order_payment_edit.php") === 0 && $_REQUEST['order_id'] > 0) { $isAdminSalePages = true; $ORDER_ID = $_REQUEST['order_id']; } elseif (amreg_strpos($curPage, "/bitrix/admin/sale_order_shipment_edit.php") === 0 && $_REQUEST['order_id'] > 0) { $isAdminSalePages = true; $ORDER_ID = $_REQUEST['order_id']; } if ($isAdminSalePages && $ORDER_ID > 0) { $oOrder = Sale\Order::load($ORDER_ID); $oProps = $oOrder->getPropertyCollection(); $arProps = $oProps->getArray(); $strDomainInfo = ""; if (isset($arProps['properties']) && is_array($arProps['properties'])) { foreach ($arProps['properties'] as $arProp) { if ($arProp['CODE'] === "SYS_DOMAIN") { $strDomainInfo = $arProp['VALUE']; if (is_array($strDomainInfo)) { $strDomainInfo = implode("|", $strDomainInfo); } break; } } } $DOMAIN_ID = false; if (amreg_strlen($strDomainInfo) > 0) { if (amreg_strpos($strDomainInfo, '[') === 0) { $DOMAIN_ID = intval(amreg_substr($strDomainInfo, 1)); } else { $DOMAIN_ID = intval($strDomainInfo); } } if ($DOMAIN_ID > 0) { self::doLoadDomainById($DOMAIN_ID); } } } protected static function doCheckAdminOrderEditPageInterface() { if (self::isTestPeriodEnd()) { return false; } global $APPLICATION; $curPage = $APPLICATION->GetCurPageParam(); if (amreg_strpos($curPage, "/bitrix/admin/sale_order_edit.php") === 0) { \CJSCore::Init(array("jquery2")); \Bitrix\Main\Page\Asset::getInstance()->addJs("/bitrix/js/ammina.regions/admin/queryfield.js"); $APPLICATION->SetAdditionalCSS("/bitrix/themes/.default/ammina.regions.css"); $arPropSysDomain = array(); $rProp = CSaleOrderProps::GetList(array(), array("CODE" => "SYS_DOMAIN")); while ($arProp = $rProp->Fetch()) { $arPropSysDomain[] = $arProp['ID']; } if (!empty($arPropSysDomain) && is_array($arPropSysDomain)) { ob_start(); ?> <script type="text/javascript"> $(document).ready(function () { <? foreach ($arPropSysDomain as $propid) { ?> $("input[name='PROPERTIES[<?=$propid?>]']").data("action", "domain"); $("input[name='PROPERTIES[<?=$propid?>]']").data("min-length", "0"); $("input[name='PROPERTIES[<?=$propid?>]']").data("cnt", "30"); $("input[name='PROPERTIES[<?=$propid?>]']").attr("autocomplete", "off"); $("input[name='PROPERTIES[<?=$propid?>]']").wrap('<div class="bamregionsadm-area-item"></div>'); $("input[name='PROPERTIES[<?=$propid?>]']").amminaRegionsAdminQueryField(); <? } ?> }); </script> <? $cont = ob_get_clean(); \Bitrix\Main\Page\Asset::getInstance()->addString($cont); } } } protected static function doAddMailTemplateFields() { if (self::isTestPeriodEnd()) { return false; } global $APPLICATION; if (amreg_strpos($APPLICATION->GetCurPage(), "/bitrix/admin/message_edit.php") === 0) { CJSCore::Init(array("jquery2")); ob_start(); echo "<hr/>"; $rVariables = \Ammina\Regions\VariableTable::getList( array( "order" => array( "CODE" => "ASC", ), ) ); while ($arVariable = $rVariables->fetch()) { ?> <a title="<?= $arVariable['DESCRIPTION'] ?>" href="javascript:PutString('#AMMINA_REGIONS_<?= $arVariable["CODE"] ?>#')">#AMMINA_REGIONS_<?= $arVariable["CODE"] ?> #</a> - <?= $arVariable['NAME'] ?> <br/> <? } $cont = ob_get_contents(); ob_end_clean(); $cont = array("cont" => $cont); ob_start(); ?> <script type="text/javascript"> <!-- $(document).ready(function () { var argEmailTemplateExtFields = <?=CUtil::PhpToJSObject($cont)?>; $("#edit1_edit_table td:last").append(argEmailTemplateExtFields['cont']); }); --> </script> <? $cont = ob_get_contents(); ob_end_clean(); Main\Page\Asset::getInstance()->addString($cont); } } public static function getGlobalVariable($arValue, $arDefault = array(), $bConvertToArray = false) { if (self::isTestPeriodEnd()) { return false; } $arResult = $arDefault; if (!empty($arValue)) { $arResult = $arValue; } if (!is_array($arResult) && $bConvertToArray) { $arResult = array($arResult); } return $arResult; } public static function getAllGeocontentId() { $oCache = new CPHPCache(); $arResult = array(); if ($oCache->InitCache(3600 * 24, 'ammina_all_geocontentid', 'ammina/regions')) { $res = $oCache->GetVars(); $arResult = $res['IDS']; } if ($oCache->StartDataCache()) { $rTypes = \Ammina\Regions\ContentTypesTable::getList( array( "select" => array("ID", "NAME") ) ); while ($arType = $rTypes->fetch()) { $arResult[$arType['ID']] = $arType['NAME']; } $oCache->EndDataCache( array( "IDS" => $arResult, ) ); } return $arResult; } protected static function prepareContent(&$content) { if (self::isTestPeriodEnd()) { return false; } global $APPLICATION; if (self::isAllowPageByPath()) { if (isset($GLOBALS['AMR_TEMPLATES']) && is_array($GLOBALS['AMR_TEMPLATES'])) { foreach ($GLOBALS['AMR_TEMPLATES'] as $k => $v) { $content = str_replace($k, $v, $content); } } if (isset($GLOBALS['AMR_EXT_TEMPLATES']) && is_array($GLOBALS['AMR_EXT_TEMPLATES'])) { foreach ($GLOBALS['AMR_EXT_TEMPLATES'] as $k => $v) { $content = str_replace('#' . $k . '#', $v, $content); } } } if (in_array( $APPLICATION->GetCurPage(), array( "/bitrix/admin/iblock_element_edit.php", "/bitrix/admin/iblock_section_edit.php", "/bitrix/admin/cat_section_edit.php", "/bitrix/admin/cat_product_edit.php", "/bitrix/admin/iblock_edit.php" ) )) { //���� ��� ��������� ����������� ���� SEO $iOffset = 0; $cnt = 0; $iCurrentPosition = amreg_strpos($content, "BX.adminShowMenu(this, [{'TEXT':", $iOffset); while ($iCurrentPosition !== false) { //��������� ���������� ���������� ���� //������� ���� � ������ ������� ��������� $iCurrentEndPosition = amreg_strpos($content, "], '');", $iCurrentPosition + 1); $iStartBXBind = false; $iStartBXBindCurrent = amreg_strpos($content, "BX.bind(BX('", $iCurrentPosition - 200); while ($iStartBXBindCurrent !== false) { if ($iStartBXBindCurrent >= $iCurrentPosition) { break; } $iStartBXBind = $iStartBXBindCurrent; $iStartBXBindCurrent = amreg_strpos($content, "BX.bind(BX('", $iStartBXBindCurrent + 1); break; } if ($iCurrentEndPosition !== false && $iStartBXBind !== false) { $iEndBXBind = amreg_strpos($content, "'", $iStartBXBind + 12); $strObjName = amreg_substr($content, $iStartBXBind + 12, $iEndBXBind - $iStartBXBind - 12); if (in_array($strObjName, self::$arAllowSeoMenuIdent)) { $arNewMenu = array( "TEXT" => Loc::getMessage("ammina.regions_SEO_MENU_TITLE"), "MENU" => array(), ); $rVariables = \Ammina\Regions\VariableTable::getList( array( "order" => array( "CODE" => "ASC", ), ) ); while ($arVariable = $rVariables->fetch()) { $arNewMenu['MENU'][] = array( "TEXT" => $arVariable['NAME'], "ONCLICK" => "InheritedPropertiesTemplates.insertIntoInheritedPropertiesTemplate('#AMMINA_REGIONS_" . $arVariable["CODE"] . "#', '" . $strObjName . "', '" . amreg_substr( $strObjName, 4 ) . "')", ); } $arNewMenu['MENU'][] = array( "SEPARATOR" => "Y" ); $arGeoContentId = self::getAllGeocontentId(); foreach ($arGeoContentId as $id => $name) { $arNewMenu['MENU'][] = array( "TEXT" => Loc::getMessage( "ammina.regions_GEOCONTENT_SEO_NAME" ) . " [" . $id . "]: " . $name, "ONCLICK" => "InheritedPropertiesTemplates.insertIntoInheritedPropertiesTemplate('#AMMINA_GC_" . $id . "#', '" . Loc::getMessage( "ammina.regions_GEOCONTENT_SEO_NAME" ) . " [" . $id . "]: " . $name . "', '" . amreg_substr($strObjName, 4) . "')", ); $arNewMenu['MENU'][] = array( "TEXT" => Loc::getMessage( "ammina.regions_GEOCONTENT_NOHTML_SEO_NAME" ) . " [" . $id . "]: " . $name, "ONCLICK" => "InheritedPropertiesTemplates.insertIntoInheritedPropertiesTemplate('#AMMINA_GC_" . $id . "_NOHTML#', '" . Loc::getMessage( "ammina.regions_GEOCONTENT_NOHTML_SEO_NAME" ) . " [" . $id . "]: " . $name . "', '" . amreg_substr($strObjName, 4) . "')", ); } $content = amreg_substr($content, 0, $iCurrentEndPosition) . "," . CUtil::PhpToJSObject( $arNewMenu ) . amreg_substr($content, $iCurrentEndPosition); } } $iOffset = $iCurrentPosition + 1; $iCurrentPosition = amreg_strpos($content, "BX.adminShowMenu(this, [{'TEXT':", $iOffset); } } if (self::isAllowPageByPath()) { if (COption::GetOptionString('ammina.regions', 'normalize_utf8', 'Y') === "Y") { if (defined("BX_UTF") && BX_UTF === true) { if (mb_check_encoding($content, "windows-1251") && !mb_check_encoding($content, "utf-8")) { $content = mb_convert_encoding($content, "utf-8");; } } } if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.regions.php")) { $arRegionsUrl = @include($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.regions.php"); $checkCode = $GLOBALS['AMMINA_REGIONS']['SYS_PATHCODE']; if (!empty($arRegionsUrl['PATH']) && strlen($checkCode) > 0 && isset($arRegionsUrl['PATH'][$checkCode])) { $arLinksMatch = array(); $arLinksMatch2 = array(); preg_match_all('/<a\s[^<>]*href=[\'"]([^\'"]+)[\'"][^<>]*>/si' . BX_UTF_PCRE_MODIFIER, $content, $arLinksMatch); preg_match_all('/BX\.ajax\.insertToNode\([\'"]([^\'"]+)/si' . BX_UTF_PCRE_MODIFIER, $content, $arLinksMatch2); preg_match_all('/BX\.ajax\.history\.put\(window\.AJAX_PAGE_STATE\.getState\(\), [\'"]([^\'"]+)/si' . BX_UTF_PCRE_MODIFIER, $content, $arLinksMatch3); preg_match_all('/<a\s[^<>]*href=[\\\][\'"]([^\'"]+)[\\\][\'"][^<>]*>/si' . BX_UTF_PCRE_MODIFIER, $content, $arLinksMatch4); $arReplaceInContent = array(); foreach ($arRegionsUrl['PATH'][$checkCode] as $k => $v) { foreach ($arLinksMatch[1] as $k1 => $v1) { if (!self::isAllowRegionUrl($v1, $arRegionsUrl['EXCLUDE'])) { continue; } if (amreg_strpos($v1, $v['ORIGINAL']) !== false) { $bAllow = true; if ($v['LEVEL'] > 0) { $arAfter = explode("/", amreg_substr($v1, amreg_strpos($v1, $v['ORIGINAL']) + amreg_strlen($v['ORIGINAL']))); if (count($arAfter) > $v['LEVEL']) { $bAllow = false; } } if ($bAllow) { $arReplaceInContent[$arLinksMatch[0][$k1]] = self::strReplaceOne($v1, self::strReplaceOne($v['ORIGINAL'], $v['REGIONAL'], $v1), $arLinksMatch[0][$k1]); } } } foreach ($arLinksMatch2[1] as $k1 => $v1) { if (!self::isAllowRegionUrl($v1, $arRegionsUrl['EXCLUDE'])) { continue; } if (amreg_strpos($v1, $v['ORIGINAL']) !== false) { $bAllow = true; if ($v['LEVEL'] > 0) { $arAfter = explode("/", amreg_substr($v1, amreg_strpos($v1, $v['ORIGINAL']) + amreg_strlen($v['ORIGINAL']))); if (count($arAfter) > $v['LEVEL']) { $bAllow = false; } } if ($bAllow) { $arReplaceInContent[$arLinksMatch2[0][$k1]] = self::strReplaceOne($v1, self::strReplaceOne($v['ORIGINAL'], $v['REGIONAL'], $v1), $arLinksMatch2[0][$k1]); } } } foreach ($arLinksMatch3[1] as $k1 => $v1) { if (!self::isAllowRegionUrl($v1, $arRegionsUrl['EXCLUDE'])) { continue; } if (amreg_strpos($v1, $v['ORIGINAL']) !== false) { $bAllow = true; if ($v['LEVEL'] > 0) { $arAfter = explode("/", amreg_substr($v1, amreg_strpos($v1, $v['ORIGINAL']) + amreg_strlen($v['ORIGINAL']))); if (count($arAfter) > $v['LEVEL']) { $bAllow = false; } } if ($bAllow) { $arReplaceInContent[$arLinksMatch3[0][$k1]] = self::strReplaceOne($v1, self::strReplaceOne($v['ORIGINAL'], $v['REGIONAL'], $v1), $arLinksMatch3[0][$k1]); } } } foreach ($arLinksMatch4[1] as $k1 => $v1) { if (!self::isAllowRegionUrl($v1, $arRegionsUrl['EXCLUDE'])) { continue; } if (amreg_strpos($v1, $v['ORIGINAL']) !== false) { $bAllow = true; if ($v['LEVEL'] > 0) { $arAfter = explode("/", amreg_substr($v1, amreg_strpos($v1, $v['ORIGINAL']) + amreg_strlen($v['ORIGINAL']))); if (count($arAfter) > $v['LEVEL']) { $bAllow = false; } } if ($bAllow) { $arReplaceInContent[$arLinksMatch4[0][$k1]] = self::strReplaceOne($v1, self::strReplaceOne($v['ORIGINAL'], $v['REGIONAL'], $v1), $arLinksMatch4[0][$k1]); } } } } foreach ($arReplaceInContent as $k => $v) { $content = amreg_str_replace_limit($k, $v, $content, 2); } } } } } public static function onAfterAjaxResponse() { if (self::isTestPeriodEnd()) { return false; } $content = ob_get_clean(); self::prepareContent($content); echo $content; } public static function OnEndBufferContent(&$content) { if (self::isTestPeriodEnd()) { return false; } self::prepareContent($content); } public static function strReplaceOne(string $search, string $replace, string $subject) { return implode($replace, explode($search, $subject, 2)); } public static function isAllowRegionUrl($url, $excludeUrl) { $urlInfo = parse_url($url); if (isset($urlInfo['scheme']) || isset($urlInfo['host'])) { return false; } $path = '/'; if (isset($urlInfo['path'])) { $path = $urlInfo['path']; } if (amreg_strpos($path, '/bitrix/') === 0) { return false; } foreach ($excludeUrl as $exclude) { if (amreg_stripos($path, $exclude) === 0) { return false; } } return true; } /** * @param Main\ORM\Event $event * @param $arOldValues */ public static function OnSaleOrderBeforeSaved($oEntity, $arOldValues) { if (self::isTestPeriodEnd()) { return false; } global $APPLICATION; if (amreg_strpos($APPLICATION->GetCurPage(), "/bitrix/admin/") === 0) { return; } if ($oEntity instanceof Sale\Order) { list($iPropertySysDomain) = self::doGetPropertiesOrder($oEntity->getPersonTypeId()); if ($GLOBALS['AMMINA_REGIONS']['SYS_SALE_UID'] > 0) { $oEntity->setField('RESPONSIBLE_ID', $GLOBALS['AMMINA_REGIONS']['SYS_SALE_UID']); } if ($GLOBALS['AMMINA_REGIONS']['SYS_SALE_COMPANY_ID'] > 0) { $oEntity->setField('COMPANY_ID', $GLOBALS['AMMINA_REGIONS']['SYS_SALE_COMPANY_ID']); } $oProperties = $oEntity->getPropertyCollection(); if ($iPropertySysDomain > 0) { $oDomainProperty = $oProperties->getItemByOrderPropertyId($iPropertySysDomain); if ($oDomainProperty) { $oDomainProperty->setValue( "[" . $GLOBALS['AMMINA_REGIONS']['SYS_CURRENT_DOMAIN_ID'] . "] " . $GLOBALS['AMMINA_REGIONS']['SYS_NAME'] . " (" . $GLOBALS['AMMINA_REGIONS']['SYS_DOMAIN'] . ")" ); } else { $arGroup = Sale\Internals\OrderPropsGroupTable::getList( array( "filter" => array( "PERSON_TYPE_ID" => $oEntity->getPersonTypeId(), ), "order" => array("SORT" => "ASC"), ) )->fetch(); $iGroupId = $arGroup['ID']; $arFields = array( "ID" => $iPropertySysDomain, "PERSON_TYPE_ID" => $oEntity->getPersonTypeId(), "NAME" => Loc::getMessage("ammina.regions_ORDER_PROP_SYS_DOMAIN_NAME"), "TYPE" => "STRING", "REQUIRED" => "N", "DEFAULT_VALUE" => "", "SORT" => "10000", "USER_PROPS" => "N", "IS_LOCATION" => "N", "PROPS_GROUP_ID" => $iGroupId, "DESCRIPTION" => Loc::getMessage("ammina.regions_ORDER_PROP_SYS_DOMAIN_DESCRIPTION"), "IS_EMAIL" => "N", "IS_PROFILE_NAME" => "N", "IS_PAYER" => "N", "IS_LOCATION4TAX" => "N", "IS_FILTERED" => "Y", "CODE" => "SYS_DOMAIN", "IS_ZIP" => "N", "IS_PHONE" => "N", "IS_ADDRESS" => "N", "ACTIVE" => "Y", "UTIL" => "Y", "MULTIPLE" => "N", "ENTITY_REGISTRY_TYPE" => \Bitrix\Sale\Registry::REGISTRY_TYPE_ORDER, ); $oProp = $oProperties->createItem($arFields); $oProp->setValue( "[" . $GLOBALS['AMMINA_REGIONS']['SYS_CURRENT_DOMAIN_ID'] . "] " . $GLOBALS['AMMINA_REGIONS']['SYS_NAME'] . " (" . $GLOBALS['AMMINA_REGIONS']['SYS_DOMAIN'] . ")" ); } } } } public static function doCheckAmminaBxKey() { global $USER; if ($USER->IsAdmin()) { $nextTimePing = COption::GetOptionInt("ammina.regions", "ptmod", time()); if ($nextTimePing > (time() + 3600 * 24 * 14)) { $nextTimePing = time(); } if ($nextTimePing <= time()) { include_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/classes/general/update_client.php"); include_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/classes/general/update_client_partner.php"); $errorMessage = ''; $strHost = $_SERVER['SERVER_NAME']; if (amreg_strlen($strHost) <= 0) { $strHost = $_SERVER['HTTP_HOST']; } $strError = ""; $arClient = CUpdateClient::GetUpdatesList($strError); $arFields = array( "OPEN_HASH" => md5('BITRIX' . CUpdateClientPartner::GetLicenseKey() . 'LICENCE'), "HASH" => md5(CUpdateClientPartner::GetLicenseKey()), "LICENSE_TYPE" => $arClient['CLIENT'][0]['@']['LICENSE'], "LICENSE_DATE_FROM" => $arClient['CLIENT'][0]['@']['DATE_FROM'], "LICENSE_DATE_TO" => $arClient['CLIENT'][0]['@']['DATE_TO'], "UNIQ_ID" => COption::GetOptionString('main', 'server_uniq_id', ''), "PARTNER_ID" => COption::GetOptionString('main', '~PARAM_PARTNER_ID', ''), ); COption::SetOptionString('ammina.regions', 'baserequest', serialize($arFields)); $arFields['HOST'] = $strHost; $arFields['MODULE'] = 'ammina.regions'; $arFields['IS_HTTPS'] = \Bitrix\Main\Context::getCurrent()->getRequest()->isHttps(); if (!defined("BX_UTF") || BX_UTF !== true) { $arFields = $GLOBALS['APPLICATION']->ConvertCharsetArray($arFields, (amreg_strlen(LANG_CHARSET) > 0 ? LANG_CHARSET : SITE_CHARSET), "UTF-8"); } $strUrl = "https://www.amminabx.ru/api/checkclient.php"; $oHttpClient = new \Bitrix\Main\Web\HttpClient( array( 'redirect' => true, 'redirectMax' => 10, 'version' => '1.1', 'disableSslVerification' => true, 'waitResponse' => true, 'socketTimeout' => 10, 'streamTimeout' => 20, 'charset' => "UTF-8", ) ); $response = $oHttpClient->post($strUrl, $arFields); $arResponse = json_decode($response, true); if ($arResponse['result'] === "ok") { COption::SetOptionString("ammina.regions", "module_active_to", $arResponse['activeTo']); COption::SetOptionString("ammina.regions", "module_status", $arResponse['status']); COption::SetOptionString("ammina.regions", "module_renewal", $arResponse['renewal']); } elseif ($arResponse['status'] === "error") { COption::SetOptionString("ammina.regions", "module_active_to", ''); COption::SetOptionString("ammina.regions", "module_status", $arResponse['status']); } $status = $oHttpClient->getStatus(); if ($status === 200) { if (strlen(COption::GetOptionString("ammina.regions", "module_active_to", '')) > 0) { COption::SetOptionInt("ammina.regions", "ptmod", time() + 3600 * 6); } else { COption::SetOptionInt("ammina.regions", "ptmod", time() + 300); } } else { COption::SetOptionInt("ammina.regions", "ptmod", time() + 300); } } } } protected static function doGetPropertiesOrder($iPersonTypeId) { if (self::isTestPeriodEnd()) { return false; } $arResult = array(); if (self::isIMExists()) { $arProperty = Sale\Internals\OrderPropsTable::getList( array( "filter" => array( "PERSON_TYPE_ID" => $iPersonTypeId, "CODE" => "SYS_DOMAIN", ), ) )->fetch(); if ($arProperty) { $arResult[] = $arProperty['ID']; } else { $arGroup = Sale\Internals\OrderPropsGroupTable::getList( array( "filter" => array( "PERSON_TYPE_ID" => $iPersonTypeId, ), "order" => array("SORT" => "ASC"), ) )->fetch(); $iGroupId = $arGroup['ID']; $arFields = array( "PERSON_TYPE_ID" => $iPersonTypeId, "NAME" => Loc::getMessage("ammina.regions_ORDER_PROP_SYS_DOMAIN_NAME"), "TYPE" => "STRING", "REQUIRED" => "N", "DEFAULT_VALUE" => "", "SORT" => "10000", "USER_PROPS" => "N", "IS_LOCATION" => "N", "PROPS_GROUP_ID" => $iGroupId, "DESCRIPTION" => Loc::getMessage("ammina.regions_ORDER_PROP_SYS_DOMAIN_DESCRIPTION"), "IS_EMAIL" => "N", "IS_PROFILE_NAME" => "N", "IS_PAYER" => "N", "IS_LOCATION4TAX" => "N", "IS_FILTERED" => "Y", "CODE" => "SYS_DOMAIN", "IS_ZIP" => "N", "IS_PHONE" => "N", "IS_ADDRESS" => "N", "ACTIVE" => "Y", "UTIL" => "Y", "MULTIPLE" => "N", "ENTITY_REGISTRY_TYPE" => \Bitrix\Sale\Registry::REGISTRY_TYPE_ORDER, ); $oRes = Sale\Internals\OrderPropsTable::add($arFields); if ($oRes->isSuccess()) { $arResult[] = $oRes->getId(); } } } return $arResult; } public static function OnBeforeEventAdd(&$event, &$lid, &$arFields, &$message_id, &$files, &$languageId) { if (self::isTestPeriodEnd()) { return false; } if (isset($GLOBALS['AMR_TEMPLATES']) && is_array($GLOBALS['AMR_TEMPLATES'])) { foreach ($GLOBALS['AMR_TEMPLATES'] as $k => $v) { $arFields[amreg_substr($k, 1, amreg_strlen($k) - 2)] = $v; } if (isset($GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']) && strlen($GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']) > 0) { $arFields['DEFAULT_EMAIL_FROM'] = $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']; $arFields['SALE_EMAIL'] = $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']; } } } public static function OnEventBeforeAddBitrixMainEvent(\Bitrix\Main\Event $event) { if (self::isTestPeriodEnd()) { return; } $result = new Main\ORM\EventResult(); $data = $event->getParameter("fields"); $arUpdateFields = array( "C_FIELDS" => $data['C_FIELDS'] ); if (isset($GLOBALS['AMR_TEMPLATES']) && is_array($GLOBALS['AMR_TEMPLATES'])) { foreach ($GLOBALS['AMR_TEMPLATES'] as $k => $v) { $field = amreg_substr($k, 1, amreg_strlen($k) - 2); if (!isset($arUpdateFields['C_FIELDS'][$field])) { $arUpdateFields['C_FIELDS'][$field] = $v; } } if (isset($GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']) && strlen($GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']) > 0) { $arUpdateFields['C_FIELDS']['DEFAULT_EMAIL_FROM'] = $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']; $arUpdateFields['C_FIELDS']['SALE_EMAIL'] = $GLOBALS['AMR_TEMPLATES']['#AMMINA_REGIONS_SYS_DEFAULT_EMAIL#']; } } $result->modifyFields($arUpdateFields); return $result; } public static function OnGetOptimalPrice( $intProductID, $quantity, $arUserGroups, $renewal, $priceList, $siteID, $arDiscountCoupons ) { if (self::isTestPeriodEnd()) { return false; } global $APPLICATION; $intProductID = (int)$intProductID; if ($intProductID <= 0) { $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_CATALOG_PROD_ERR_PRODUCT_ID_ABSENT"), "NO_PRODUCT_ID"); return false; } $quantity = (float)$quantity; if ($quantity <= 0) { $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_CATALOG_PROD_ERR_QUANTITY_ABSENT"), "NO_QUANTITY"); return false; } if (!is_array($arUserGroups) && (int)$arUserGroups . '|' == (string)$arUserGroups . '|') { $arUserGroups = array((int)$arUserGroups); } if (!is_array($arUserGroups)) { $arUserGroups = array(); } if (!in_array(2, $arUserGroups)) { $arUserGroups[] = 2; } Main\Type\Collection::normalizeArrayValuesByInt($arUserGroups); $renewal = ($renewal === 'Y' ? 'Y' : 'N'); if ($siteID === false) { $siteID = SITE_ID; } if (!empty($GLOBALS['AMMINA_REGIONS']['SYS_CURRENCY'])) { Catalog\Product\Price\Calculation::setConfig( array( "CURRENCY" => $GLOBALS['AMMINA_REGIONS']['SYS_CURRENCY'], ) ); } $resultCurrency = Catalog\Product\Price\Calculation::getCurrency(); if (empty($resultCurrency)) { $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_CATALOG_PROD_ERR_NO_RESULT_CURRENCY")); return false; } $intIBlockID = (int)CIBlockElement::GetIBlockByID($intProductID); if ($intIBlockID <= 0) { $APPLICATION->ThrowException( Loc::getMessage( 'BT_MOD_CATALOG_PROD_ERR_ELEMENT_ID_NOT_FOUND', array('#ID#' => $intProductID) ), 'NO_ELEMENT' ); return false; } if (!isset($priceList) || !is_array($priceList)) { $priceList = array(); } if (empty($priceList)) { $priceTypeList = self::getAllowedPriceTypes($arUserGroups); if (empty($priceTypeList)) { return false; } $iterator = Catalog\PriceTable::getList( array( 'select' => array('ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'), 'filter' => array( '=PRODUCT_ID' => $intProductID, '@CATALOG_GROUP_ID' => $priceTypeList, array( 'LOGIC' => 'OR', '<=QUANTITY_FROM' => $quantity, '=QUANTITY_FROM' => null, ), array( 'LOGIC' => 'OR', '>=QUANTITY_TO' => $quantity, '=QUANTITY_TO' => null, ), ), ) ); while ($row = $iterator->fetch()) { $row['ELEMENT_IBLOCK_ID'] = $intIBlockID; $priceList[] = $row; } unset($row, $iterator); unset($priceTypeList); } else { foreach (array_keys($priceList) as $priceIndex) { $priceList[$priceIndex]['ELEMENT_IBLOCK_ID'] = $intIBlockID; } unset($priceIndex); } if (empty($priceList)) { return false; } $vat = CCatalogProduct::GetVATDataByID($intProductID); if (!empty($vat)) { $vat['RATE'] = (float)$vat['RATE'] * 0.01; } else { $vat = array('RATE' => 0.0, 'VAT_INCLUDED' => 'N'); } unset($iterator); $isNeedDiscounts = Catalog\Product\Price\Calculation::isAllowedUseDiscounts(); $resultWithVat = Catalog\Product\Price\Calculation::isIncludingVat(); if ($isNeedDiscounts) { if ($arDiscountCoupons === false) { $arDiscountCoupons = CCatalogDiscountCoupon::GetCoupons(); } } // $boolDiscountVat = ('N' != COption::GetOptionString('catalog', 'discount_vat', 'Y')); $boolDiscountVat = true; $minimalPrice = array(); if (self::$saleIncluded === null) { self::initSaleSettings(); } $isNeedleToMinimizeCatalogGroup = self::isNeedleToMinimizeCatalogGroup($priceList); foreach ($priceList as $priceData) { $priceData['VAT_RATE'] = $vat['RATE']; $priceData['VAT_INCLUDED'] = $vat['VAT_INCLUDED']; $currentPrice = (float)$priceData['PRICE']; if ($boolDiscountVat) { if ($priceData['VAT_INCLUDED'] === 'N') { $currentPrice *= (1 + $priceData['VAT_RATE']); } } else { if ($priceData['VAT_INCLUDED'] === 'Y') { $currentPrice /= (1 + $priceData['VAT_RATE']); } } if ($priceData['CURRENCY'] != $resultCurrency) { $currentPrice = CCurrencyRates::ConvertCurrency($currentPrice, $priceData['CURRENCY'], $resultCurrency); } $currentPrice = Catalog\Product\Price\Calculation::roundPrecision($currentPrice); $result = array( 'BASE_PRICE' => $currentPrice, 'COMPARE_PRICE' => $currentPrice, 'PRICE' => $currentPrice, 'CURRENCY' => $resultCurrency, 'DISCOUNT_LIST' => array(), 'RAW_PRICE' => $priceData, ); if ($isNeedDiscounts) { $arDiscounts = CCatalogDiscount::GetDiscount( $intProductID, $intIBlockID, $priceData['CATALOG_GROUP_ID'], $arUserGroups, $renewal, $siteID, $arDiscountCoupons ); $discountResult = CCatalogDiscount::applyDiscountList($currentPrice, $resultCurrency, $arDiscounts); unset($arDiscounts); if ($discountResult === false) { return false; } $result['PRICE'] = $discountResult['PRICE']; $result['COMPARE_PRICE'] = $discountResult['PRICE']; $result['DISCOUNT_LIST'] = $discountResult['DISCOUNT_LIST']; unset($discountResult); } elseif ($isNeedleToMinimizeCatalogGroup) { $calculateData = $priceData; $calculateData['PRICE'] = $currentPrice; $calculateData['CURRENCY'] = $resultCurrency; $possibleSalePrice = self::getPossibleSalePrice( $intProductID, $calculateData, $quantity, $siteID, $arUserGroups, $arDiscountCoupons ); unset($calculateData); if ($possibleSalePrice === null) { return false; } $result['COMPARE_PRICE'] = $possibleSalePrice; unset($possibleSalePrice); } if ($boolDiscountVat) { if (!$resultWithVat) { $result['PRICE'] /= (1 + $priceData['VAT_RATE']); $result['COMPARE_PRICE'] /= (1 + $priceData['VAT_RATE']); $result['BASE_PRICE'] /= (1 + $priceData['VAT_RATE']); } } else { if ($resultWithVat) { $result['PRICE'] *= (1 + $priceData['VAT_RATE']); $result['COMPARE_PRICE'] *= (1 + $priceData['VAT_RATE']); $result['BASE_PRICE'] *= (1 + $priceData['VAT_RATE']); } } $result['UNROUND_PRICE'] = $result['PRICE']; $result['UNROUND_BASE_PRICE'] = $result['BASE_PRICE']; if (Catalog\Product\Price\Calculation::isComponentResultMode()) { $result['BASE_PRICE'] = Catalog\Product\Price::roundPrice( $priceData['CATALOG_GROUP_ID'], $result['BASE_PRICE'], $resultCurrency ); $result['PRICE'] = Catalog\Product\Price::roundPrice( $priceData['CATALOG_GROUP_ID'], $result['PRICE'], $resultCurrency ); if ( empty($result['DISCOUNT_LIST']) || Catalog\Product\Price\Calculation::compare($result['BASE_PRICE'], $result['PRICE'], '<=') ) { $result['BASE_PRICE'] = $result['PRICE']; } $result['COMPARE_PRICE'] = $result['PRICE']; } if (empty($minimalPrice) || $minimalPrice['COMPARE_PRICE'] > $result['COMPARE_PRICE']) { $minimalPrice = $result; } unset($currentPrice, $result); } unset($priceData); unset($vat); $discountValue = ($minimalPrice['BASE_PRICE'] - $minimalPrice['PRICE']); $arResult = array( 'PRICE' => $minimalPrice['RAW_PRICE'], 'RESULT_PRICE' => array( 'PRICE_TYPE_ID' => $minimalPrice['RAW_PRICE']['CATALOG_GROUP_ID'], 'BASE_PRICE' => $minimalPrice['BASE_PRICE'], 'DISCOUNT_PRICE' => $minimalPrice['PRICE'], 'CURRENCY' => $resultCurrency, 'DISCOUNT' => $discountValue, 'PERCENT' => ( $minimalPrice['BASE_PRICE'] > 0 && $discountValue > 0 ? round((100 * $discountValue) / $minimalPrice['BASE_PRICE'], 0) : 0 ), 'VAT_RATE' => $minimalPrice['RAW_PRICE']['VAT_RATE'], 'VAT_INCLUDED' => ($resultWithVat ? 'Y' : 'N'), 'UNROUND_BASE_PRICE' => $minimalPrice['UNROUND_BASE_PRICE'], 'UNROUND_DISCOUNT_PRICE' => $minimalPrice['UNROUND_PRICE'], ), 'DISCOUNT_PRICE' => $minimalPrice['PRICE'], 'DISCOUNT' => array(), 'DISCOUNT_LIST' => array(), 'PRODUCT_ID' => $intProductID, ); if (!empty($minimalPrice['DISCOUNT_LIST'])) { reset($minimalPrice['DISCOUNT_LIST']); $arResult['DISCOUNT'] = current($minimalPrice['DISCOUNT_LIST']); $arResult['DISCOUNT_LIST'] = $minimalPrice['DISCOUNT_LIST']; } unset($minimalPrice); /* if ($eventOnResultExists === true || $eventOnResultExists === NULL) { foreach (GetModuleEvents('catalog', 'OnGetOptimalPriceResult', true) as $arEvent) { $eventOnResultExists = true; if (ExecuteModuleEventEx($arEvent, array(&$arResult)) === false) return false; } if ($eventOnResultExists === NULL) $eventOnResultExists = false; } */ if (function_exists("amminaRegionsUserGetOptimalPriceCustom")) { $arResult = amminaRegionsUserGetOptimalPriceCustom($arResult); } return $arResult; } /** * @param array $userGroups * * @return array */ private static function getAllowedPriceTypes(array $userGroups) { if (self::isTestPeriodEnd()) { return false; } static $priceTypeCache = array(); Main\Type\Collection::normalizeArrayValuesByInt($userGroups, true); if (empty($userGroups)) { return array(); } $cacheKey = 'U' . implode('_', $userGroups); if (!isset($priceTypeCache[$cacheKey])) { $priceTypeCache[$cacheKey] = array(); if (self::isIMExists()) { $arFilter = array('@GROUP_ID' => $userGroups, '=ACCESS' => Catalog\GroupAccessTable::ACCESS_BUY); if (!empty($GLOBALS['AMMINA_REGIONS']['SYS_PRICES'])) { $arFilter['CATALOG_GROUP_ID'] = $GLOBALS['AMMINA_REGIONS']['SYS_PRICES']; } $priceIterator = Catalog\GroupAccessTable::getList( array( 'select' => array('CATALOG_GROUP_ID'), 'filter' => $arFilter, 'order' => array('CATALOG_GROUP_ID' => 'ASC'), ) ); while ($priceType = $priceIterator->fetch()) { $priceTypeId = (int)$priceType['CATALOG_GROUP_ID']; $priceTypeCache[$cacheKey][$priceTypeId] = $priceTypeId; unset($priceTypeId); } unset($priceType, $priceIterator); } } return $priceTypeCache[$cacheKey]; } protected static function initSaleSettings() { if (self::isTestPeriodEnd()) { return false; } if (self::$saleIncluded === null) { self::$saleIncluded = Main\Loader::includeModule('sale'); } if (self::$saleIncluded && self::isIMExists()) { self::$useSaleDiscount = (string)Main\Config\Option::get('sale', 'use_sale_discount_only') === 'Y'; if (self::$useSaleDiscount) { //TODO: replace runtime to reference after sale 17.5.2 will be stable $row = Sale\Internals\DiscountEntitiesTable::getList( array( 'select' => array('ID'), 'filter' => array( '=MODULE_ID' => 'catalog', '=ENTITY' => 'PRICE', '=FIELD_ENTITY' => 'CATALOG_GROUP_ID', '=FIELD_TABLE' => 'CATALOG_GROUP_ID', '=ACTIVE_DISCOUNT.ACTIVE' => 'Y', ), 'runtime' => array( new Main\Entity\ReferenceField( 'ACTIVE_DISCOUNT', 'Bitrix\Sale\Internals\Discount', array('=this.DISCOUNT_ID' => 'ref.ID'), array('join_type' => 'LEFT') ), ), 'limit' => 1, ) )->fetch(); self::$existPriceTypeDiscounts = !empty($row); unset($row); } } } private static function isNeedleToMinimizeCatalogGroup(array $priceList) { if (self::isTestPeriodEnd()) { return false; } if (self::$saleIncluded === null) { self::initSaleSettings(); } if ( !self::$saleIncluded || !self::$useSaleDiscount || count($priceList) < 2 ) { return false; } return self::$existPriceTypeDiscounts; } private static function getPossibleSalePrice( $intProductID, array $priceData, $quantity, $siteID, array $userGroups, $coupons ) { if (self::isTestPeriodEnd()) { return false; } $possibleSalePrice = null; if (empty($priceData)) { return $possibleSalePrice; } if (self::isIMExists()) { $isCompatibilityUsed = Sale\Compatible\DiscountCompatibility::isUsed(); Sale\Compatible\DiscountCompatibility::stopUsageCompatible(); $freezeCoupons = (empty($coupons) && is_array($coupons)); if ($freezeCoupons) { Sale\DiscountCouponsManager::freezeCouponStorage(); } /** @var \Bitrix\Sale\Basket $basket */ static $basket = null, /** @var \Bitrix\Sale\BasketItem $basketItem */ $basketItem = null; if ($basket !== null) { if ($basket->getSiteId() != $siteID) { $basket = null; $basketItem = null; } } if ($basket === null) { $basket = Sale\Basket::create($siteID); $basketItem = $basket->createItem('catalog', $intProductID); } $fields = array( 'PRODUCT_ID' => $intProductID, 'QUANTITY' => $quantity, 'LID' => $siteID, 'PRODUCT_PRICE_ID' => $priceData['ID'], 'PRICE' => $priceData['PRICE'], 'BASE_PRICE' => $priceData['PRICE'], 'DISCOUNT_PRICE' => 0, 'CURRENCY' => $priceData['PRICE'], 'CAN_BUY' => 'Y', 'DELAY' => 'N', 'PRICE_TYPE_ID' => (int)$priceData['CATALOG_GROUP_ID'], ); /** @noinspection PhpInternalEntityUsedInspection */ $basketItem->setFieldsNoDemand($fields); $discount = Sale\Discount::buildFromBasket($basket, new Sale\Discount\Context\UserGroup($userGroups)); $discount->setExecuteModuleFilter(array('all', 'catalog')); $discount->calculate(); $calcResults = $discount->getApplyResult(true); if ($calcResults && !empty($calcResults['PRICES']['BASKET'])) { $possibleSalePrice = reset($calcResults['PRICES']['BASKET']); $possibleSalePrice = $possibleSalePrice['PRICE']; } if ($freezeCoupons) { Sale\DiscountCouponsManager::unFreezeCouponStorage(); } if ($isCompatibilityUsed === true) { Sale\Compatible\DiscountCompatibility::revertUsageCompatible(); } } return $possibleSalePrice; } public static function OnBeforeBasketItemSetFields(Main\Event $event) { /** * @var $oEntity \Bitrix\Sale\BasketItem */ $oEntity = $event->getParameter("ENTITY"); $oEntity->setField("PRODUCT_PROVIDER_CLASS", '\\Ammina\\Regions\\Catalog\\Product\\CatalogProvider'); return new \Bitrix\Main\EventResult( \Bitrix\Main\EventResult::SUCCESS ); } public static function OnSaleBasketItemRefreshData(Main\Event $event) { /** * @var $oEntity \Bitrix\Sale\BasketItem */ $oEntity = $event->getParameter("ENTITY"); $arFields = $oEntity->getFieldValues(); $arProduct = Catalog\ProductTable::getRowById($arFields['PRODUCT_ID']); if ($arProduct['QUANTITY_TRACE'] == Catalog\ProductTable::STATUS_DEFAULT) { $arProduct['QUANTITY_TRACE'] = self::$defaultProductSettings['QUANTITY_TRACE']; } if ($arProduct['CAN_BUY_ZERO'] == Catalog\ProductTable::STATUS_DEFAULT) { $arProduct['CAN_BUY_ZERO'] = self::$defaultProductSettings['CAN_BUY_ZERO']; } $arStoreData = self::getStoreQuantityForCurrentDomain($arFields['PRODUCT_ID']); if ($arStoreData['QUANTITY'] < $arFields['QUANTITY'] && $arProduct['CAN_BUY_ZERO'] == Catalog\ProductTable::STATUS_NO) { $oEntity->setField("CAN_BUY", 'N'); } else { $oEntity->setField("CAN_BUY", 'Y'); } return new \Bitrix\Main\EventResult( \Bitrix\Main\EventResult::SUCCESS ); } public static function getStoreQuantityForCurrentDomain($iProductID) { $arResult = array( "STORES" => array(), "QUANTITY" => 0, ); if (!empty($GLOBALS['AMMINA_REGIONS']['SYS_STORES']) && self::isIMExists()) { $rStores = CCatalogStoreProduct::GetList( array(), array( "PRODUCT_ID" => $iProductID, "STORE_ID" => $GLOBALS['AMMINA_REGIONS']['SYS_STORES'] ), false, false, array("ID", "STORE_ID", "PRODUCT_ID", "AMOUNT") ); while ($arStores = $rStores->Fetch()) { $arResult['STORES'][$arStores['STORE_ID']] += $arStores['AMOUNT']; $arResult['QUANTITY'] += $arStores['AMOUNT']; } } if (function_exists("amminaRegionsGetStoreQuantityForCurrentDomainCustom")) { $arResult = amminaRegionsGetStoreQuantityForCurrentDomainCustom($iProductID, $arResult); } return $arResult; } public static function doNormalizeBasketCatalogSkuOfferList($arOfferList) { foreach (array_keys($arOfferList) as $index) { foreach (array_keys($arOfferList[$index]) as $offerId) { $arStore = self::getStoreQuantityForCurrentDomain($offerId); if ($arStore['QUANTITY'] <= 0) { unset($arOfferList[$index][$offerId]); } } } return $arOfferList; } public static function isIMExists() { if (self::$isIMExists < 0) { self::$isIMExists = (CModule::IncludeModule("catalog") && CModule::IncludeModule("sale")); } return self::$isIMExists; } public static function getBaseDomain() { $strDomain = amreg_strtolower($_SERVER[COption::GetOptionString("ammina.regions", "host_var_name", "HTTP_HOST")]); if (amreg_strpos($strDomain, 'www.') === 0) { $strDomain = amreg_substr($strDomain, 4); } return COption::GetOptionString("ammina.regions", "base_domain", $strDomain); } public static function doCheckNotify() { global $APPLICATION; if (amreg_strpos($APPLICATION->GetCurPage(), "/bitrix/admin/") !== 0) { return; } $nextTime = intval(COption::GetOptionInt("ammina", "notify_next_time", 0)); if ($nextTime <= 0 || $nextTime <= time()) { $client = new \Bitrix\Main\Web\HttpClient( array( 'redirect' => true, 'redirectMax' => 10, 'socketTimeout' => 15, 'streamTimeout' => 15, 'disableSslVerification' => true, ) ); $strCode = $client->get("https://www.ammina.ru/local/notify/old.txt"); $iOldNumber = false; $status = intval($client->getStatus()); if ($status == 200) { $iOldNumber = intval($strCode); } if ($iOldNumber > 0) { $iFromNumber = intval(COption::GetOptionInt("ammina", "notify_old", 0)); $arShowed = array(); if ($iFromNumber <= 0) { $strContent = $client->get("https://www.ammina.ru/local/notify/req.json"); $status = intval($client->getStatus()); if ($status == 200) { $arData = @\Bitrix\Main\Web\Json::decode($strContent); foreach ($arData as $id) { $arShowed[] = $id; self::doShowNotify($id); } } $iFromNumber = $iOldNumber - 1; } for ($i = $iFromNumber + 1; $i <= $iOldNumber; $i++) { if (!in_array($i, $arShowed)) { self::doShowNotify($i); } } COption::SetOptionInt("ammina", "notify_old", $iOldNumber); } } COption::SetOptionInt("ammina", "notify_next_time", time() + 10800); } public static function doShowNotify($ID) { $client = new \Bitrix\Main\Web\HttpClient( array( 'redirect' => true, 'redirectMax' => 10, 'socketTimeout' => 15, 'streamTimeout' => 15, 'disableSslVerification' => true, ) ); $strContent = $client->get("https://www.ammina.ru/local/notify/" . $ID . ".json"); $status = intval($client->getStatus()); if ($status == 200) { $arData = @\Bitrix\Main\Web\Json::decode($strContent); if ($arData['ID'] > 0 && amreg_strlen($arData['TITLE']) > 0 && amreg_strlen($arData['TEXT']) > 0) { $bAllowNotify = true; if (isset($arData['MODULE']) && !empty($arData['MODULE']) && is_array($arData['MODULE']) && count( $arData['MODULE'] ) > 0) { $bAllowNotify = false; foreach ($arData['MODULE'] as $mod) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/" . $mod . "/")) { $bAllowNotify = true; } } } if (isset($arData['NOTMODULE']) && !empty($arData['NOTMODULE']) && is_array( $arData['NOTMODULE'] ) && count($arData['NOTMODULE']) > 0) { $bAllowNotify = false; foreach ($arData['NOTMODULE'] as $mod) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/" . $mod . "/")) { $bAllowNotify = false; } } } if ($bAllowNotify) { \CAdminNotify::Add( array( //'MODULE_ID' => "", //'TAG' => "", 'MESSAGE' => '<b>' . $arData['TITLE'] . '</b><br>' . $arData['TEXT'], 'ENABLE_CLOSE' => "Y", 'PUBLIC_SECTION' => "N", 'NOTIFY_TYPE' => "M" ) ); } } } } public static function doMathPageToRules($strRules, $strPage) { if (is_array($strRules)) { $arRules = $strRules; } else { $arRules = explode("\n", $strRules); } foreach ($arRules as $strRule) { $strRule = trim($strRule); if (amreg_strlen($strRule) > 0) { if (amreg_strpos($strRule, 'PREG:') === 0) { $strRule = trim(amreg_substr($strRule, 5)); $strPattern = "/" . $strRule . "/ui"; $aMatch = array(); if (preg_match($strPattern, $strPage, $aMatch)) { return true; } } elseif (amreg_strpos($strRule, 'PART:') === 0) { $strRule = trim(amreg_substr($strRule, 5)); if (amreg_stripos($strPage, $strRule) !== false) { return true; } } else { if (amreg_stripos($strPage, $strRule) === 0) { return true; } } } } return false; } public static function isAllowPageWork() { global $APPLICATION; if (self::isTestPeriodEnd()) { return false; } if (defined('AMMINA_REGIONS_STOP') && AMMINA_REGIONS_STOP === true) { return false; } if ((defined("BX_CRONTAB") && BX_CRONTAB === true) || (defined("CHK_EVENT") && CHK_EVENT === true)) { return false; } if (!isset($_SERVER['HTTP_HOST'])) { return false; } if (!self::isAllowPageByPath()) { return false; } return true; } public static function isAllowPageByPath() { global $APPLICATION; if (self::doMathPageToRules( array( "/bitrix/admin/", "/bitrix/services/", "/bitrix/activities/", "/bitrix/gadgets/", "/bitrix/panel/", "/bitrix/tools/", "/bitrix/wizards/", "/bitrix/components/bitrix/sender.", "/bitrix/components/bitrix/report.", "/bitrix/components/bitrix/rest.", "/bitrix/components/bitrix/b24connector.", "/bitrix/components/bitrix/bitrixcloud.", "/bitrix/components/bitrix/ui.", ), $APPLICATION->GetCurPage() )) { return false; } $arDisabledPages = explode("\n", COption::GetOptionString("ammina.regions", "disabled_pages", "")); foreach ($arDisabledPages as $k => $v) { $arDisabledPages[$k] = trim($v); if (amreg_strlen($arDisabledPages[$k]) <= 0) { unset($arDisabledPages[$k]); } } $arDisabledPages = array_values($arDisabledPages); if (count($arDisabledPages) > 0) { if (self::doMathPageToRules($arDisabledPages, $APPLICATION->GetCurPage())) { return false; } } return true; } static function OnBeforeOrderAccountNumberSet($orderId, $type) { global $AMMINA_REGIONS_STOP_ORDER_PREFIX; if ($AMMINA_REGIONS_STOP_ORDER_PREFIX === true) { return null; } if ($AMMINA_REGIONS_STOP_ORDER_PREFIX !== true) { $AMMINA_REGIONS_STOP_ORDER_PREFIX = true; $oOrder = Sale\Order::load($orderId); $strNumber = Sale\Internals\AccountNumberGenerator::generateForOrder($oOrder); if (amreg_strlen($strNumber) > 0) { if ($GLOBALS['AMMINA_REGIONS']['SYS_CURRENT_DOMAIN_ID'] > 0) { $arDomain = \Ammina\Regions\DomainTable::getList(array("filter" => array("ID" => $GLOBALS['AMMINA_REGIONS']['SYS_CURRENT_DOMAIN_ID'])))->fetch(); if ($arDomain) { if (amreg_strpos($strNumber, '#ORDER_PREFIX#') !== false) { $strNumber = str_replace("#ORDER_PREFIX#", $arDomain['ORDER_PREFIX'], $strNumber); } else { $strNumber = $arDomain['ORDER_PREFIX'] . "/" . $strNumber; } } } } $AMMINA_REGIONS_STOP_ORDER_PREFIX = false; return $strNumber; } return null; } public static function getListLangNames($arAllNames, $lang = LANGUAGE_ID) { $arResult = array(); $arCheckedSynonim = array(); $bComplete = false; $checkLang = $lang; while (!$bComplete) { if (amreg_strlen($checkLang) <= 0 || isset($arCheckedSynonim[$checkLang])) { $bComplete = true; } else { $arCheckedSynonim[$checkLang] = $checkLang; $arResult[] = $arAllNames[$checkLang]; $checkLang = \COption::GetOptionString("ammina.regions", "lang_syn_" . $checkLang, ""); } } if (!isset($arCheckedSynonim['ru'])) { $arResult[] = $arAllNames['ru']; } if (!isset($arCheckedSynonim['en'])) { $arResult[] = $arAllNames['en']; } return $arResult; } public static function getLangFirstName($arAllNames, $lang = LANGUAGE_ID) { return self::getFirstNotEmpty(self::getListLangNames($arAllNames, $lang)); } public static function getFirstNotEmpty($arData) { foreach ($arData as $val) { if (is_array($val)) { $checkval = trim(implode("", $val)); } else { $val = trim($val); $checkval = trim($val); } if (amreg_strlen($checkval) > 0) { return $val; } } return false; } public static function getAllAllowLang() { if (self::$arAllAllowLang === false) { $arAllowLangs = explode("|", \COption::GetOptionString("ammina.regions", "use_lang", "")); $b = 'sort'; $o = 'asc'; $rDbLang = \CLanguage::GetList($b, $o, array()); while ($arDbLang = $rDbLang->Fetch()) { if ($arDbLang['LID'] === "ru" || !in_array($arDbLang['LID'], $arAllowLangs)) { continue; } self::$arAllAllowLang[$arDbLang['LID']] = $arDbLang['LID']; } } return self::$arAllAllowLang; } } CAmminaRegions::doCheckNotify(); CModule::AddAutoloadClasses( "ammina.regions", array( "Ammina\\Regions\\CountryTable" => "lib/country.php", "Ammina\\Regions\\CountryLangTable" => "lib/country.lang.php", "Ammina\\Regions\\RegionTable" => "lib/region.php", "Ammina\\Regions\\RegionLangTable" => "lib/region.lang.php", "Ammina\\Regions\\CityTable" => "lib/city.php", "Ammina\\Regions\\CityLangTable" => "lib/city.lang.php", "Ammina\\Regions\\BlockTable" => "lib/block.php", "Ammina\\Regions\\ContentTypesTable" => "lib/content.types.php", "Ammina\\Regions\\ContentTable" => "lib/content.php", "Ammina\\Regions\\DomainTable" => "lib/domain.php", "Ammina\\Regions\\DomainLocationTable" => "lib/domain.location.php", "Ammina\\Regions\\DomainVariableTable" => "lib/domain.variable.php", "Ammina\\Regions\\VariableTable" => "lib/variable.php", "Ammina\\Regions\\PriceTable" => "lib/price.php", "Ammina\\Regions\\Import" => "lib/import.php", "Ammina\\Regions\\GeoIPHandler" => "lib/geoip.php", "Ammina\\Regions\\Agent\\Price" => "lib/agent/price.php", "Ammina\\Regions\\Agent\\DomainAvailable" => "lib/agent/domain.available.php", "Ammina\\Regions\\Agent\\SiteMapGenerate" => "lib/agent/sitemap.generate.php", "Ammina\\Regions\\IblockProp\\Domain" => "lib/iblock.prop/domain.php", "Ammina\\Regions\\IblockProp\\Country" => "lib/iblock.prop/country.php", "Ammina\\Regions\\IblockProp\\Region" => "lib/iblock.prop/region.php", "Ammina\\Regions\\IblockProp\\City" => "lib/iblock.prop/city.php", "Ammina\\Regions\\UserProp\\Domain" => "lib/user.prop/domain.php", "Ammina\\Regions\\UserProp\\Country" => "lib/user.prop/country.php", "Ammina\\Regions\\UserProp\\Region" => "lib/user.prop/region.php", "Ammina\\Regions\\UserProp\\City" => "lib/user.prop/city.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\Country" => "lib/helpers/admin/blocks/country.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\CountryMap" => "lib/helpers/admin/blocks/country.map.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\Region" => "lib/helpers/admin/blocks/region.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\City" => "lib/helpers/admin/blocks/city.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\CityMap" => "lib/helpers/admin/blocks/city.map.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\CityLoad" => "lib/helpers/admin/blocks/city.load.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\ContentTypes" => "lib/helpers/admin/blocks/content.types.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\Content" => "lib/helpers/admin/blocks/content.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\ContentExt" => "lib/helpers/admin/blocks/content.ext.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\Variable" => "lib/helpers/admin/blocks/variable.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\Domain" => "lib/helpers/admin/blocks/domain.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\DomainLocation" => "lib/helpers/admin/blocks/domain.location.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\DomainVariable" => "lib/helpers/admin/blocks/domain.variable.php", "Ammina\\Regions\\Helpers\\Admin\\Blocks\\Price" => "lib/helpers/admin/blocks/price.php", "CAmminaRegionsSaleCondCtrlDomain" => "lib/salecondition/domain.php", "Ammina\\Regions\\Rules\\Sale\\CompanyRules\\Domain" => "lib/rules/sale/company.rules/domain.php", "Ammina\\Regions\\Rules\\Sale\\DeliveryRestrictions\\Domain" => "lib/rules/sale/delivery.restrictions/domain.php", "Ammina\\Regions\\Rules\\Sale\\PaySystemRestrictions\\Domain" => "lib/rules/sale/paysystem.restrictions/domain.php", "Ammina\\Regions\\Catalog\\Product\\CatalogProvider" => "lib/catalog/product/catalog.provider.php", "morphos\\BaseInflection" => "lib/external/Morphos/BaseInflection.php", "morphos\\Cases" => "lib/external/Morphos/Cases.php", "morphos\\CasesHelper" => "lib/external/Morphos/CasesHelper.php", "morphos\\CurrenciesHelper" => "lib/external/Morphos/CurrenciesHelper.php", "morphos\\Currency" => "lib/external/Morphos/Currency.php", "morphos\\Gender" => "lib/external/Morphos/Gender.php", "morphos\\MoneySpeller" => "lib/external/Morphos/MoneySpeller.php", "morphos\\NamesInflection" => "lib/external/Morphos/NamesInflection.php", "morphos\\NounPluralization" => "lib/external/Morphos/NounPluralization.php", "morphos\\NumeralGenerator" => "lib/external/Morphos/NumeralGenerator.php", "morphos\\S" => "lib/external/Morphos/S.php", "morphos\\TimeSpeller" => "lib/external/Morphos/TimeSpeller.php", "morphos\\English\\CardinalNumeralGenerator" => "lib/external/Morphos/English/CardinalNumeralGenerator.php", "morphos\\English\\NounPluralization" => "lib/external/Morphos/English/NounPluralization.php", "morphos\\English\\OrdinalNumeralGenerator" => "lib/external/Morphos/English/OrdinalNumeralGenerator.php", "morphos\\English\\TimeSpeller" => "lib/external/Morphos/English/TimeSpeller.php", "morphos\\Russian\\CardinalNumeralGenerator" => "lib/external/Morphos/Russian/CardinalNumeralGenerator.php", "morphos\\Russian\\Cases" => "lib/external/Morphos/Russian/Cases.php", "morphos\\Russian\\CasesHelper" => "lib/external/Morphos/Russian/CasesHelper.php", "morphos\\Russian\\FirstNamesInflection" => "lib/external/Morphos/Russian/FirstNamesInflection.php", "morphos\\Russian\\GeographicalNamesInflection" => "lib/external/Morphos/Russian/GeographicalNamesInflection.php", "morphos\\Russian\\LastNamesInflection" => "lib/external/Morphos/Russian/LastNamesInflection.php", "morphos\\Russian\\MiddleNamesInflection" => "lib/external/Morphos/Russian/MiddleNamesInflection.php", "morphos\\Russian\\MoneySpeller" => "lib/external/Morphos/Russian/MoneySpeller.php", "morphos\\Russian\\NounDeclension" => "lib/external/Morphos/Russian/NounDeclension.php", "morphos\\Russian\\NounPluralization" => "lib/external/Morphos/Russian/NounPluralization.php", "morphos\\Russian\\OrdinalNumeralGenerator" => "lib/external/Morphos/Russian/OrdinalNumeralGenerator.php", "morphos\\Russian\\RussianLanguage" => "lib/external/Morphos/Russian/RussianLanguage.php", "morphos\\Russian\\TimeSpeller" => "lib/external/Morphos/Russian/TimeSpeller.php", "AMREG_Mobile_Detect" => "lib/external/mobiledetect/Mobile_Detect.php", ) ); include_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ammina.regions/lib/external/Morphos/English/functions.php'); include_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ammina.regions/lib/external/Morphos/Russian/functions.php'); if (CModule::IncludeModule('seo')) { CModule::AddAutoloadClasses( "ammina.regions", array( "Ammina\\Regions\\Sitemap\\DomainSitemapFile" => "lib/sitemap/domain.sitemap.file.php", ) ); } if (!function_exists("myPrint")) { function myPrint(&$Var, $bIsHtmlSpecialChars = true, $strFileName = false, $bAppend = false) { if (defined("WEBAVK_CRON_UNIQ_IDENT") && $strFileName === false) { $bIsHtmlSpecialChars = false; } $strContent = '<pre style="text-align:left;background-color:#222222;color:#ffffff;font-size:11px;">'; if ($bIsHtmlSpecialChars) { $strContent .= htmlspecialchars(print_r($Var, true)); } else { $strContent .= print_r($Var, true); } $strContent .= '</pre>'; if ($strFileName) { if ($bAppend) { file_put_contents($strFileName, file_get_contents($strFileName) . "\n" . $strContent); } else { file_put_contents($strFileName, $strContent); } } else { echo $strContent; } } } ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.26 |
proxy
|
phpinfo
|
Settings