403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/catalog/tools/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/catalog/tools/iblock_subelement_generator.php
<?php
/** @global CMain $APPLICATION */
/**	@global CUser $USER */

use Bitrix\Main;
use Bitrix\Catalog;
use Bitrix\Catalog\Access\ActionDictionary;
use Bitrix\Catalog\Access\AccessController;
use Bitrix\Currency;
use Bitrix\Highloadblock as HL;

require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
IncludeModuleLangFile(__FILE__);

if (!Main\Loader::includeModule('catalog'))
{
	die();
}
Main\Loader::includeModule('fileman');

Main\Page\Asset::getInstance()->addJs('/bitrix/js/catalog/tbl_edit.js');

$arJSDescription = array(
	'js' => '/bitrix/js/catalog/sub_generator.js',
	'css' => '/bitrix/panel/catalog/sub-generator.css',
	'lang' => '/bitrix/modules/catalog/lang/'.LANGUAGE_ID.'/tools/iblock_subelement_generator.php'
);
CJSCore::RegisterExt('iblock_generator', $arJSDescription);
CJSCore::Init([
	'iblock_generator',
	'file_input',
]);

const IB_SEG_ROW_PREFIX = 'IB_SEG_';

$request = Main\Context::getCurrent()->getRequest();

$subIBlockId = (int)$request->get('subIBlockId');
if ($subIBlockId <= 0)
{
	die();
}
$subPropValue = (int)$request->get('subPropValue');
$subTmpId = (int)$request->get('subTmpId');
$iBlockId = (int)$request->get('iBlockId');
$arSKUInfo = CCatalogSku::GetInfoByOfferIBlock($subIBlockId);
$parentProductName = trim($_POST['PRODUCT_NAME']);

$useStoreControl = Catalog\Config\State::isUsedInventoryManagement();

$accessController = AccessController::getCurrent();

$allowProductAdd = $accessController->check(ActionDictionary::ACTION_PRODUCT_ADD);
$elementAdd =
	CIBlockSectionRights::UserHasRightTo($subIBlockId, 0, 'section_element_bind')
	&& $allowProductAdd
;

if (empty($arSKUInfo))
{
	ShowError("SKU error!");
}

$APPLICATION->SetTitle(GetMessage("IB_SEG_MAIN_TITLE"));

/**
 * @param $intRangeID
 * @param $strPrefix
 * @return string
 */
function __AddCellPriceType($intRangeID, $strPrefix): string
{
	$priceTypeCellOption = '';
	foreach (Catalog\GroupTable::getTypeList() as $arCatalogGroup)
	{
		$priceTypeCellOption .= "<option value=".$arCatalogGroup['ID'].">".htmlspecialcharsbx($arCatalogGroup["NAME"])."</option>";
	}

	return <<<"PRICETYPECELL"
	<td width="30%">
		<span class="adm-select-wrap">
			<select id="IB_SEG_PRICE_TYPE" class="adm-select" style="width: 169px; max-width: 300px;" name="{$strPrefix}PRICETYPE[{$intRangeID}]" />
				$priceTypeCellOption
			</select>
		</span>
	</td>
PRICETYPECELL;
}

/**
 * @param $intRangeID
 * @param $strPrefix
 * @return string
 */
function __AddCellPrice($intRangeID, $strPrefix): string
{
	return <<<"PRICECELL"
	<td width="30%">
		<input type="text"  name="{$strPrefix}PRICE[{$intRangeID}]" />
	</td>
PRICECELL;
}

/**
 * @param $intRangeID
 * @param $strPrefix
 * @return string
 */
function __AddCellCurrency($intRangeID, $strPrefix): string
{
	$currencySelectbox = CCurrency::SelectBox("{$strPrefix}CURRENCY[{$intRangeID}]", '', "", true, "", "class=\"adm-select\" style=\"width: 169px;\"");

	return <<<"CURRENCYCELL"
	<td width="30%">
		<span class="adm-select-wrap">
			$currencySelectbox
		</span>
	</td>
CURRENCYCELL;
}

function __showPopup($element_id, $items)
{
	echo
		'<script>
			var currentWindow = top.window;
			if (top.BX.SidePanel && top.BX.SidePanel.Instance && top.BX.SidePanel.Instance.getTopSlider())
			{
				currentWindow = top.BX.SidePanel.Instance.getTopSlider().getWindow();
			}
			currentWindow.BX.ready(function(){
				currentWindow.BX.bind(currentWindow.BX("'.$element_id.'"), "click", function() {
					currentWindow.BX.adminShowMenu(this, '.CAdminPopup::PhpToJavaScript($items).');
				});
			});
		</script>';
}
/**
 * @param $intRangeID
 * @param $strPrefix
 * @return string
 */
function __AddRangeRow($intRangeID, $strPrefix): string
{
	return '<tr id="'.$strPrefix.$intRangeID.'">'.__AddCellPriceType($intRangeID, $strPrefix).__AddCellPrice($intRangeID, $strPrefix).__AddCellCurrency($intRangeID, $strPrefix).'</tr>';
}

/**
 * @param $arr
 * @param int $index
 * @return array
 */
function arraysCombination (&$arr, $index = 0): array
{
	static $line = array();
	static $keys;
	static $max;
	static $results;
	if($index == 0)
	{
		$keys = array_keys($arr);
		$max = count($arr);
		$results = array();
	}
	if($index < $max)
	{
		$values = $arr[$keys[$index]];
		foreach($values as $key => $value)
		{
			$line[$keys[$index]] = $value;
			arraysCombination($arr, $index + 1);
			array_pop($line);
		}
	}
	else
	{
		$results[] = $line;
	}
	if($index == 0)
		return $results;
	return array();
}

$boolHighLoad = null;
$arResult = array();
$arAllProperties = array();
$arAllParentProperties = array();
$arFileProperties = array();
$arFilePropertiesExt = array();
$arDirProperties = array();
$dbIBlockProperty = CIBlockProperty::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("IBLOCK_ID" => $subIBlockId, "ACTIVE" => 'Y'));
while($arIBlockProperty = $dbIBlockProperty->Fetch())
{
	$arIBlockProperty['ID'] = (int)$arIBlockProperty['ID'];
	$propertyType = $arIBlockProperty["PROPERTY_TYPE"];
	$userType = (string)$arIBlockProperty["USER_TYPE"];
	$isMultiply = ($arIBlockProperty["MULTIPLE"] == 'Y');
	$arAllProperties[] = $arIBlockProperty;

	if ('L' != $propertyType && 'F' != $propertyType && !('S' == $propertyType && 'directory' == $userType))
		continue;
	if ('S' == $propertyType && 'directory' == $userType)
	{
		if (empty($arIBlockProperty['USER_TYPE_SETTINGS']['TABLE_NAME']))
			continue;
		if (null === $boolHighLoad)
			$boolHighLoad = CModule::IncludeModule('highloadblock');
		if (!$boolHighLoad)
			continue;
	}

	if ('F' == $propertyType)
	{
		$arFileProperties[] = $arIBlockProperty;
		$arFilePropertiesExt[$arIBlockProperty['ID']] = $arIBlockProperty;
	}
	elseif ('L' == $propertyType)
	{
		$arIBlockProperty['VALUE'] = array();
		$dbIBlockPropertyEnum = CIBlockPropertyEnum::GetList(array("SORT" => "ASC"), array("PROPERTY_ID" => $arIBlockProperty["ID"]));
		while($arIBlockPropertyEnum = $dbIBlockPropertyEnum->Fetch())
		{
			$arIBlockProperty['VALUE'][] = $arIBlockPropertyEnum;
		}
		if (!empty($arIBlockProperty['VALUE']))
		{
			$arResult[] = $arIBlockProperty;
		}
	}
	else
	{
		$arIBlockProperty['VALUE'] = array();
		$arConvert = array();
		if (isset($arIBlockProperty["USER_TYPE_SETTINGS"]["TABLE_NAME"]) && !empty($arIBlockProperty["USER_TYPE_SETTINGS"]["TABLE_NAME"]))
		{
			$hlblock = HL\HighloadBlockTable::getList(array('filter' => array('=TABLE_NAME' => $arIBlockProperty['USER_TYPE_SETTINGS']['TABLE_NAME'])))->fetch();
			if (!empty($hlblock) && is_array($hlblock))
			{
				$entity = HL\HighloadBlockTable::compileEntity($hlblock);
				$entity_data_class = $entity->getDataClass();
				$fieldsList = $entity_data_class::getEntity()->getFields();
				$order = array();
				if (isset($fieldsList['UF_SORT']))
					$order['UF_SORT'] = 'ASC';
				$order['UF_NAME'] = 'ASC';
				$order['ID'] = 'ASC';
				$rsData = $entity_data_class::getList(array('order' => $order));
				while($arData = $rsData->fetch())
				{
					$arData["VALUE"] = $arData["UF_NAME"];
					$arData["PROPERTY_ID"] = $arIBlockProperty["ID"];
					$arData["SORT"] = (isset($arData['UF_SORT']) ? $arData['UF_SORT'] : $arData['ID']);
					$arIBlockProperty['VALUE'][] = $arData;
					$arConvert[$arData["ID"]] = $arData["UF_XML_ID"];
				}
				unset($order, $fieldsList);
			}
		}
		if (!empty($arIBlockProperty['VALUE']))
		{
			$arResult[] = $arIBlockProperty;
			$arDirProperties[$arIBlockProperty['ID']] = $arIBlockProperty;
			$arDirProperties[$arIBlockProperty['ID']]['CONVERT'] = $arConvert;
		}
	}
}

$dbParentIBlockProperty = CIBlockProperty::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("IBLOCK_ID" => $iBlockId, "ACTIVE" => 'Y'));
while($arParentIBlockProperty = $dbParentIBlockProperty->Fetch())
{
	if($arParentIBlockProperty['PROPERTY_TYPE'] == 'L' || $arParentIBlockProperty['PROPERTY_TYPE'] == 'S')
		$arAllParentProperties[] = $arParentIBlockProperty;
}

$errorMessage = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST' && $elementAdd && check_bitrix_sessid())
{
	$arImageCombinationResult = $arPropertyValueCombinationResult = array();
	if (isset($_FILES['PROP']) && is_array($_FILES['PROP']))
	{
		CFile::ConvertFilesToPost($_FILES['PROP'], $arImageCombinationResult);
		// this code for fill description
		if (!empty($arImageCombinationResult) && is_array($arImageCombinationResult))
		{
			$fileDescription = array();
			if (!empty($_POST['DESCRIPTION_PROP']) && is_array($_POST['DESCRIPTION_PROP']))
				$fileDescription = $_POST['DESCRIPTION_PROP'];
			elseif (!empty($_POST['PROP_descr']) && is_array($_POST['PROP_descr']))
				$fileDescription = $_POST['PROP_descr'];
			if (!empty($fileDescription))
			{
				foreach ($arImageCombinationResult as $fieldCode => $fieldValues)
				{
					if (empty($fieldValues) || !is_array($fieldValues))
						continue;
					if (empty($fileDescription[$fieldCode]))
						continue;
					foreach ($fieldValues as $valueCode => $valueData)
					{
						if (empty($valueData) || !is_array($valueData))
							continue;
						if (!isset($fileDescription[$fieldCode][$valueCode]))
							continue;
						if (array_key_exists('tmp_name', $valueData))
						{
							$arImageCombinationResult[$fieldCode][$valueCode]['description'] = $fileDescription[$fieldCode][$valueCode];
						}
						else
						{
							foreach ($valueData as $valueIndex => $value)
							{
								if (empty($value) || !is_array($value))
									continue;
								if (!isset($fileDescription[$fieldCode][$valueCode][$valueIndex]))
									continue;
								if (!array_key_exists('tmp_name', $value))
									continue;
								$arImageCombinationResult[$fieldCode][$valueCode][$valueIndex]['description'] = $fileDescription[$fieldCode][$valueCode][$valueIndex];
							}
							unset($valueIndex, $value);
						}
					}
					unset($valueCode, $valueData);
				}
				unset($fieldCode, $fieldValues);
			}
		}
	}

	if (isset($_POST["PROP"]) && is_array($_POST["PROP"]))
	{
		foreach($_POST["PROP"] as $propKey => $arTmpProperty)
		{
			$rowId = 0;
			if (is_array($arTmpProperty))
			{
				foreach($arTmpProperty as $eachPropertyValue)
				{
					$arPropertyValueCombinationResult[$rowId][$propKey] = $eachPropertyValue;
					$rowId++;
				}
			}
		}
	}
	$arCombinationResult = $arPropertyValue = $arPriceGroup = array();
	$idNewElement = false;
	$obIBlockElement = new CIBlockElement();
	$arPropertyValues = (isset($_POST["PROPERTY_VALUE"]) && is_array($_POST["PROPERTY_VALUE"])) ? $_POST["PROPERTY_VALUE"] : array();
	$arPropertyChecks = (isset($_POST["PROPERTY_CHECK"]) && is_array($_POST["PROPERTY_CHECK"])) ? $_POST["PROPERTY_CHECK"] : array();
	$title = trim((string)$request->getPost('IB_SEG_TITLE'));
	if ($title === '')
	{
		$title = '{=this.property.CML2_LINK.NAME} ';
	}
	if (isset($_POST['IB_SEG_PRICETYPE']) && is_array($_POST['IB_SEG_PRICETYPE']))
	{
		foreach($_POST['IB_SEG_PRICETYPE'] as $key => $priceTypeId)
		{
			$arPriceGroup[$priceTypeId] = array("TYPE" => $_POST['IB_SEG_PRICETYPE'][$key], "PRICE" => $_POST['IB_SEG_PRICE'][$key], "CURRENCY" => $_POST['IB_SEG_CURRENCY'][$key]);
		}
	}
	foreach($arPropertyValues as $propertyId => $arValues)
	{
		if(isset($arPropertyChecks[$propertyId]))
			$arPropertyValue[$propertyId]= array_intersect_key($arValues, $arPropertyChecks[$propertyId]);
	}
	$arCombinationResult = arraysCombination($arPropertyValue);

	if ($request->getPost('AJAX_MODE') === 'Y')
	{
		$APPLICATION->RestartBuffer();

		echo CUtil::PhpToJSObject(array($arPropertyValue));
		exit;
	}
	$dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $subPropValue));

	$arIBlockElement = $dbIBlockElement->Fetch();

	if ((string)$request->getPost('save') !== '')
	{
		$parentElementId = (0 < $subPropValue ? $subPropValue : -$subTmpId);
		$parentElement = new \Bitrix\Iblock\Template\Entity\Element($parentElementId);
		if($parentElementId < 0)
		{
			$arFields = array(
				"NAME" => htmlspecialcharsbx($_POST['PRODUCT_NAME_HIDDEN']),
			);
			$parentElement->setFields($arFields);
		}

		$productData = array(
			'WEIGHT' => $_POST['IB_SEG_WEIGHT'],
			'LENGTH' => $_POST['IB_SEG_BASE_LENGTH'],
			'WIDTH' => $_POST['IB_SEG_BASE_WIDTH'],
			'HEIGHT' => $_POST['IB_SEG_BASE_HEIGHT'],
			'VAT_ID' => $_POST['IB_SEG_VAT_ID'],
			'VAT_INCLUDED' => $_POST['IB_SEG_VAT_INCLUDED'],
			'MEASURE' => $_POST['IB_SEG_MEASURE']
		);
		if (!$useStoreControl)
			$productData['QUANTITY'] = $_POST['IB_SEG_QUANTITY'];
		if ($accessController->check(ActionDictionary::ACTION_PRODUCT_PURCHASE_INFO_VIEW) && !$useStoreControl)
		{
			if (!empty($_POST['IB_SEG_PURCHASING_CURRENCY']) && $_POST['IB_SEG_PURCHASING_PRICE'] !== '')
			{
				$productData['PURCHASING_PRICE'] = $_POST['IB_SEG_PURCHASING_PRICE'];
				$productData['PURCHASING_CURRENCY'] = $_POST['IB_SEG_PURCHASING_CURRENCY'];
			}
		}

		foreach($arCombinationResult as $arPropertySaveValues)
		{
			$imageRowId = null;
			foreach($arPropertyValueCombinationResult as $keyRow => $propertyValueCombinationResult)
			{
				$compare = true;
				foreach ($arPropertySaveValues as $srcKey => $srcValue)
				{
					if (!isset($propertyValueCombinationResult[$srcKey]) || ($propertyValueCombinationResult[$srcKey] != $srcValue && $propertyValueCombinationResult[$srcKey] != '-1'))
					{
						$compare = false;
						break;
					}
				}
				unset($srcValue, $srcKey);
				if ($compare)
				{
					$imageRowId = $keyRow;
					break;
				}
			}

			$arPropertySaveValues[$arSKUInfo['SKU_PROPERTY_ID']] = $parentElementId;

			if (!empty($arPropertyPopup) && is_array($arPropertyPopup))
			{
				foreach ($arPropertyPopup as $action => $acValue)
				{
					if ($action != 'CODE')
						continue;
					foreach ($arAllProperties as $key => $value)
					{
						if ($value["CODE"] != $acValue["CODE"])
							continue;
						$arReplace['#'.$acValue["CODE"].'#'] = $arPropertySaveValues[$arAllProperties[$key]['ID']];
					}
					unset($key, $value);
				}
				unset($action, $acValue);
			}

			$arIBlockElementAdd = array("NAME" => null, "IBLOCK_ID" => $subIBlockId, "ACTIVE" => "Y");
			if (0 >= $subPropValue)
				$arIBlockElementAdd['TMP_ID'] = $subTmpId;

			if (is_array($arImageCombinationResult) && $imageRowId !== null)
			{
				foreach($arImageCombinationResult as $propertyId => $arImageType)
				{
					if(CFile::CheckImageFile($arImageType[$imageRowId]) == '')
					{
						switch($propertyId)
						{
							case 'DETAIL' :
								$arIBlockElementAdd['DETAIL_PICTURE'] = $arImageType[$imageRowId];
								break;
							case 'ANNOUNCE' :
								$arIBlockElementAdd['PREVIEW_PICTURE'] = $arImageType[$imageRowId];
								break;
							default :
								$arPropertySaveValues[$propertyId] = $arImageType[$imageRowId];
						}
					}
				}
			}

			if (!empty($arDirProperties))
			{
				foreach ($arDirProperties as $arOneConvert)
				{
					if (isset($arPropertySaveValues[$arOneConvert['ID']]))
					{
						$arPropertySaveValues[$arOneConvert['ID']] = $arOneConvert['CONVERT'][$arPropertySaveValues[$arOneConvert['ID']]];
					}
				}
			}
			if ($imageRowId !== null)
			{
				foreach ($arPropertyValueCombinationResult[$imageRowId] as $srcKey => $srcValue)
				{
					if ($srcValue == '-1')
						continue;
					if (!isset($arFilePropertiesExt[$srcKey]) && $srcKey != 'DETAIL' && $srcKey != 'ANNOUNCE')
						continue;
					switch ($srcKey)
					{
						case 'ANNOUNCE':
							$arIBlockElementAdd['PREVIEW_PICTURE'] = CIBlock::makeFileArray(
								$srcValue,
								false
							);
							if ($arIBlockElementAdd['PREVIEW_PICTURE']['error'] == 0)
								$arIBlockElementAdd['PREVIEW_PICTURE']['COPY_FILE'] = 'Y';
							break;
						case 'DETAIL':
							$arIBlockElementAdd['DETAIL_PICTURE'] = CIBlock::makeFileArray(
								$srcValue,
								false
							);
							if ($arIBlockElementAdd['DETAIL_PICTURE']['error'] == 0)
								$arIBlockElementAdd['DETAIL_PICTURE']['COPY_FILE'] = 'Y';
							break;
						default:
							if (is_array($srcValue))
							{
								$arPropertySaveValues[$srcKey] = array();
								foreach ($srcValue as $fileID => $fileValue)
								{
									$arPropertySaveValues[$srcKey][$fileID] = CIBlock::makeFilePropArray(
										$srcValue[$fileID],
										false
									);
								}
							}
							else
							{
								$arPropertySaveValues[$srcKey] = CIBlock::makeFilePropArray(
									$srcValue,
									false
								);
							}
							break;
					}
				}
			}

			$arPropertySaveValues["CML2_LINK"] = $parentElement;
			$arIBlockElementAdd['PROPERTY_VALUES'] = $arPropertySaveValues;
			$sku = new \Bitrix\Iblock\Template\Entity\Element(0);
			$sku->setFields($arIBlockElementAdd);
			$arIBlockElementAdd["NAME"] = htmlspecialcharsback(\Bitrix\Iblock\Template\Engine::process($sku, $title));
			unset($arIBlockElementAdd['PROPERTY_VALUES']["CML2_LINK"]);
			$idNewElement = $obIBlockElement->Add($arIBlockElementAdd, false, true, true);
			if($idNewElement)
			{
				$productData['ID'] = $idNewElement;
				CCatalogProduct::Add($productData, false);
				foreach($arPriceGroup as $price)
					CPrice::Add(array("PRODUCT_ID" => $idNewElement, "CURRENCY" => $price["CURRENCY"], "PRICE" => $price["PRICE"], "CATALOG_GROUP_ID" => $price["TYPE"]));
				$element = new \Bitrix\Iblock\InheritedProperty\ElementValues($subIBlockId, $idNewElement);
				$template = new \Bitrix\Iblock\InheritedProperty\BaseTemplate($element);
				$template->set(array(
					"MY_TEMPLATE" => $title,
				));
				CCatalogMeasureRatio::add(array('PRODUCT_ID' => $idNewElement, 'RATIO' => 1, 'IS_DEFAULT' => 'Y'));
			}
			else
			{
				$errorMessage .= $obIBlockElement->LAST_ERROR;
				break;
			}
		}
		unset($productData);

		if($idNewElement)
		{
			?>
			<script>
				var currentWindow = top.window;
				if (top.BX.SidePanel && top.BX.SidePanel.Instance && top.BX.SidePanel.Instance.getTopSlider())
				{
					currentWindow = top.BX.SidePanel.Instance.getTopSlider().getWindow();
				}
				currentWindow.BX.closeWait();
				if (!!currentWindow.BX.WindowManager.Get())
				{
					currentWindow.BX.WindowManager.Get().AllowClose();
					currentWindow.BX.WindowManager.Get().Close();
					if (!!currentWindow.ReloadSubList)
						currentWindow.ReloadSubList();
				}
			</script>
			<?php
			die();
		}
		if ($ex = $APPLICATION->GetException())
		{
			$errorMessage .= $ex->GetString()."<br>";
		}
	}
}

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");

$arPropertyPopup = array();
foreach($arResult as $key => $property)
{
	$arPropertyPopup[] = array(
			"TEXT" => htmlspecialcharsbx($property["NAME"]),
			"ONCLICK" => "obPropertyTable.addPropertyTable('".$key."')",
	);
}
if(count($arPropertyPopup) > 0)
	__showPopup("mnu_ADD_PROPERTY",	$arPropertyPopup);

$arPropertyPopupIB1 = array();
foreach($arResult as $key => $property)
{
	$arPropertyPopupIB1[$property["CODE"]] = array(
			"TEXT" => $property["NAME"],
			"ONCLICK" => "obPropertyTable.addPropertyInTitle('{=this.property.".$property["ID"]."}')",
			"CODE" => $property["CODE"],
	);
}
if(!empty($arPropertyPopupIB1))
	__showPopup("IB_SEG_ADD_PROP_IN_TITLE",	$arPropertyPopupIB1);

$arPropertyPopupIB2 = array("NAME" => array(
		"TEXT" => GetMessage("IB_SEG_TITLE"),
		"ONCLICK" => "obPropertyTable.addPropertyInTitle('{=this.property.CML2_LINK.NAME}')",
		"CODE" => 'NAME',
));
foreach($arAllParentProperties as $key => $property)
{
	$arPropertyPopupIB2[$property["CODE"]] = array(
			"TEXT" => $property["NAME"],
			"ONCLICK" => "obPropertyTable.addPropertyInTitle('{=this.property.CML2_LINK.property.".$property["CODE"]."}')",
			"CODE" => $property["CODE"],
	);
}
if(!empty($arPropertyPopupIB2))
	__showPopup("IB_SEG_ADD_PROP_IN_TITLE2", $arPropertyPopupIB2);

if($errorMessage)
{
	CAdminMessage::ShowMessage($errorMessage);
}
else
{
	$arCellTemplates = array();
	$arCellTemplates[] = CUtil::JSEscape(__AddCellPriceType('tmp_xxx', 'PREFIX'));
	$arCellTemplates[] = CUtil::JSEscape(__AddCellPrice('tmp_xxx', 'PREFIX'));
	$arCellTemplates[] = CUtil::JSEscape(__AddCellCurrency('tmp_xxx', 'PREFIX'));

	$aTabs = array(
		array("DIV" => "edit", "TAB" => GetMessage("IB_SEG_TAB_TITLE")),
	);

	CAdminMessage::ShowMessage($errorMessage);
	?>
	<form enctype="multipart/form-data" method="POST" action="<?= $APPLICATION->GetCurPage() ?>" name="iblock_generator_form" id="iblock_generator_form">
	<input type="hidden" name="lang" value="<?= LANGUAGE_ID ?>">
	<input type="hidden" name="subIBlockId" value="<?= $subIBlockId ?>">
	<input type="hidden" name="subPropValue" value="<?= $subPropValue ?>">
	<input type="hidden" name="iBlockId" value="<?= $iBlockId ?>">
	<input type="hidden" name="subTmpId" value="<?= $subTmpId ?>">
	<input type="hidden" name="PRODUCT_NAME_HIDDEN" value="<?= htmlspecialcharsbx($parentProductName) ?>">
	<?=bitrix_sessid_post();

	$tabControl = new CAdminTabControl("tabControl", $aTabs, true, true);
	$tabControl->Begin();
	$tabControl->BeginNextTab();
	?>
<script>
	BX('edit_edit_table').className += ' adm-shop-page-table';

	var CellTPL = [];
	<?php
	foreach ($arCellTemplates as $key => $value)
	{
		?>CellTPL[<?= $key; ?>] = '<?= $value; ?>';
	<?php
	}
	?>

	var CellAttr = [];
	<?php
	foreach ($arCellTemplates as $key => $value)
	{
		?>CellAttr[<?= $key; ?>] = '<?= $value; ?>';
	<?php
	}
	?>
	var obPricesTable = new JCCatTblEdit({
		'PREFIX': 'IB_SEG_',
		'TABLE_PROP_ID': 'generator_price_table',
		'PROP_COUNT_ID': 'generator_price_table_max_id'
	});
	obPricesTable.SetCells(CellTPL, CellAttr);

	var obPropertyTable = new JCIBlockGenerator({
		'PREFIX': 'IB_SEG_',
		'TABLE_PROP_ID': 'generator_property_table',
		'PROP_COUNT_ID': 'generator_price_table_max_id',
		'AR_ALL_PROPERTIES': <?=CUtil::PhpToJSObject($arResult)?>,
		'IMAGE_TABLE_ID': "adm-shop-table",
		'AR_FILE_PROPERTIES': <?=CUtil::PhpToJSObject($arFileProperties)?>,
		'subIBlockId': <?= $subIBlockId; ?>
	});

	function addProperty(arFileProperties)
	{
		var fileProperties = eval(arFileProperties),
			id = 0;
		if(BX('ib_seg_max_property_id'))
		{
			id = BX('ib_seg_max_property_id').value;
			if(id >= obPropertyTable.AR_FILE_PROPERTIES.length + 2)
			{
				return;
			}
			BX('ib_seg_max_property_id').value = Number(BX('ib_seg_max_property_id').value) + 1;
		}
		obPropertyTable.SELECTED_PROPERTIES[id] = 'DETAIL';

		var propertySpan = BX('ib_seg_property_span');
		if(propertySpan)
		{
			var options = [];
			for(var key in fileProperties)
			{
				if(fileProperties.hasOwnProperty(key))
					options[options.length] = BX.create('OPTION', {
							'props': {'value':fileProperties[key]["ID"], 'selected':(fileProperties[key]["ID"] == 'DETAIL')},
							'text': fileProperties[key]["NAME"]
						}
					);
			}
			var span = BX.create('span', {
				props: {
					className: 'adm-select-wrap'
				}
			});
			var content = BX.create('select', {
				props: {
					name:"SELECTED_PROPERTY[]",
					id:"SELECTED_PROPERTY[]",
					className:"adm-select ib_seg_add_property_but"
				},
				style : {
					width : '130px'
				},
				children : options,
				'events': {
					change : function()
					{
						obPropertyTable.SELECTED_PROPERTIES[id] = this.value;
					}
				}
			});
			span.appendChild(content);
			propertySpan.appendChild(span);
		}
	}

	BX.message({
		'PROPERTY_VALUES_EMPTY': '<?=GetMessageJS('IB_SEG_PROPERTY_VALUES_EMPTY'); ?>'
	});
</script>
<tr><td colspan="2" class="adm-detail-content-cell">
	<div class="adm-detail-content-item-block-view-tab"><div class="adm-shop-block-wrap">
	<table width="100%" border="0" cellspacing="7" cellpadding="0">
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage("IB_SEG_TITLE") ?>:</td>
			<td class="adm-detail-content-cell-r" style="white-space: nowrap !important;">
				<input type="text" style="width: 637px;" class="adm-input" id="IB_SEG_TITLE" name="IB_SEG_TITLE" >
				<input type="button" id="IB_SEG_ADD_PROP_IN_TITLE" title="..." value="<?=htmlspecialcharsbx(GetMessage("IB_SEG_SKU_PROPERTIES")); ?>">
				<input type="button" id="IB_SEG_ADD_PROP_IN_TITLE2" title="..." value="<?=htmlspecialcharsbx(GetMessage("IB_SEG_PARENT_PROPERTIES")); ?>">
				<a class="adm-input-help-icon" onmouseover="BX.hint(this, '<?=htmlspecialcharsbx(CUtil::JSEscape(GetMessage('IB_SEG_TOOLTIP_TITLE'))); ?>')" href="#"></a>
			</td>
		</tr>
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage("IB_SEG_WEIGHT") ?>:</td>
			<td class="adm-detail-content-cell-r">
				<input type="text" style="width: 120px; margin-right: 10px" class="adm-input" name="IB_SEG_WEIGHT">
				<?= GetMessage("IB_SEG_BASE_LENGTH") ?>:
				<input type="text" id="CAT_BASE_LENGTH" name="IB_SEG_BASE_LENGTH" style="width: 120px;  margin-right: 10px">
				<?= GetMessage("IB_SEG_BASE_WIDTH") ?>:
				<input type="text" id="CAT_BASE_WIDTH" name="IB_SEG_BASE_WIDTH" style="width: 120px;  margin-right: 10px">
				<?= GetMessage("IB_SEG_BASE_HEIGHT") ?>:
				<input type="text" id="CAT_BASE_HEIGHT" name="IB_SEG_BASE_HEIGHT" style="width: 120px;">
				<a class="adm-input-help-icon" onmouseover="BX.hint(this, '<?=htmlspecialcharsbx(CUtil::JSEscape(GetMessage('IB_SEG_TOOLTIP_WEIGHT'))); ?>')" href="#"></a>
			</td>
		</tr>
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage((!$useStoreControl ? 'IB_SEG_QUANTITY' : 'IB_SEG_MEASURE')); ?></td>
			<td class="adm-detail-content-cell-r"><?php
			if (!$useStoreControl)
			{
				?><input type="text" style="width: 120px; margin-right: 10px" class="adm-input" name="IB_SEG_QUANTITY">
				<?= GetMessage('IB_SEG_MEASURE');
			}
			?> <span class="adm-select-wrap" style="vertical-align: middle !important;"><select name="IB_SEG_MEASURE" class="adm-select" style="width: 169px;"><?php
			$measureIterator = CCatalogMeasure::getList(
				array(), array(), false, false, array("ID", "CODE", "MEASURE_TITLE", "SYMBOL_INTL", "IS_DEFAULT")
			);
			while($measure = $measureIterator->Fetch())
			{
				?><option value="<?=$measure['ID']?>"<?= ($measure['IS_DEFAULT'] == 'Y' ? ' selected' : '') ?>><?php
				echo htmlspecialcharsEx($measure['MEASURE_TITLE']); ?></option><?php
			}
			unset($measure, $measureIterator);
			?></select></span></td>
		</tr>
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage("IB_SEG_VAT") ?>:</td>
			<td class="adm-detail-content-cell-r">
				<span class="adm-select-wrap" style="vertical-align: middle !important;">
				<?php
					$arVATRef = CatalogGetVATArray(array(), true);
					echo SelectBoxFromArray('IB_SEG_VAT_ID', $arVATRef, '', "", (!$elementAdd ? "disabled readonly" : '').'class="adm-select" style="width: 169px;"');
				?>
				</span>
			</td>
		</tr>
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage("IB_SEG_VAT_INCLUDED") ?></td>
			<td class="adm-detail-content-cell-r">
				<input type="hidden" name="IB_SEG_VAT_INCLUDED" id="IB_SEG_VAT_INCLUDED_N" value="N"><?php
				$vatInclude = (Main\Config\Option::get('catalog', 'default_product_vat_included') === 'Y');
				?><input class="adm-designed-checkbox" type="checkbox" name="IB_SEG_VAT_INCLUDED" id="IB_SEG_VAT_INCLUDED" value="Y"<?= ($vatInclude ? ' checked' : '') ?>>
				<label class="adm-designed-checkbox-label" for="IB_SEG_VAT_INCLUDED"></label>
			</td>
		</tr>
		<?php
		if ($accessController->check(ActionDictionary::ACTION_PRODUCT_PURCHASE_INFO_VIEW) && !$useStoreControl)
		{
			$baseCurrency = Currency\CurrencyManager::getBaseCurrency();
		?>
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage("IB_SEG_PURCHASING_PRICE") ?></td>
			<td class="adm-detail-content-cell-r">
				<input type="text" name="IB_SEG_PURCHASING_PRICE" value="">
				<span class="adm-select-wrap" style="vertical-align: middle !important;"><select name="IB_SEG_PURCHASING_CURRENCY" class="adm-select" style="width: 169px;">
				<option value=""><?=htmlspecialcharsbx(GetMessage('IB_SEG_EMPTY_VALUE'))?></option>
				<?php
				foreach (Currency\CurrencyManager::getCurrencyList() as $id => $title)
				{
					?><option value="<?=$id; ?>"<?=($id == $baseCurrency ? ' selected' : ''); ?>><?=htmlspecialcharsbx($title); ?></option><?php
				}
				unset($id, $title);
				?>
				</select></span>
			</td>
		</tr>
		<?php
		}
		$priceTypeList = Catalog\GroupTable::getTypeList();
		if (!empty($priceTypeList)):
		?>
		<tr>
			<td class="adm-detail-content-cell-l"><?= GetMessage("IB_SEG_PRICE_SHORT") ?>:</td>
			<td class="adm-detail-content-cell-r">
				<table class="internal" id="generator_price_table" style="width: auto;">
					<tr class="heading">
						<td><?= GetMessage("IB_SEG_PRICE_TYPE") ?>:</td>
						<td><?= GetMessage("IB_SEG_PRICE") ?>:</td>
						<td><?= GetMessage("IB_SEG_CURRENCY") ?>:</td>
					</tr>
					<tbody>
					<?php
						$intCount = 0;
						echo __AddRangeRow($intCount, IB_SEG_ROW_PREFIX);
					?>
					</tbody>
				</table>
				<span class="adm-btn adm-btn-add" style="margin-top: 12px;" onclick="obPricesTable.addRow();"><?= GetMessage("IB_SEG_PRICE_ROW_ADD") ?></span>
				<input type="hidden" value="1" id="generator_price_table_max_id">
			</td>
		</tr>
		<?php
		endif;
		?>
	</table>
	</div></div>
</td></tr>
<tr>
	<td colspan="2" class="adm-detail-content-cell" style="padding-bottom: 0;">
		<div class="adm-shop-toolbar">
			<span class="adm-btn adm-btn-add" id="mnu_ADD_PROPERTY"><?= GetMessage("IB_SEG_PROPERTY_ADD") ?></span><span class="adm-btn adm-btn-download" id="mnu_ADD_ALL_PROPERTY" onclick="obPropertyTable.loadAllProperties()"><?= GetMessage("IB_SEG_PROPERTY_ADD_ALL") ?></span><a class="adm-input-help-icon" onmouseover="BX.hint(this, '<?=htmlspecialcharsbx(CUtil::JSEscape(GetMessage('IB_SEG_TOOLTIP_PROPERTIES'))); ?>')" href="#"></a>
		</div>
	</td>
</tr>
<tr>
	<td colspan="2" class="adm-detail-content-cell" style="padding-top: 0;">
		<div class="adm-detail-content-item-block-view-tab">
			<div class="adm-detail-title-view-tab"><?= GetMessage("IB_SEG_SELECTED_PROPERTIES") ?></div>
			<input type="hidden" value="0" id="generator_property_table_max_id">
			<div class="adm-shop-table-block" id="generator_property_table">
				<script>
					<?php
					foreach($arResult as $key => $arProperty)
					{
					?>
					obPropertyTable.addPropertyTable(<?=$key?>);
					<?php
					}
					?>
				</script>
			</div>
		</div>
	</td>
</tr>
<tr>
	<td colspan="2" class="adm-detail-content-cell">
		<div class="adm-detail-content-item-block-view-tab">
			<div class="adm-detail-title-view-tab"><?= GetMessage("IB_SEG_PICTURES") ?></div>
			<div class="adm-shop-block-wrap">
				<div class="adm-shop-select-bar" id="ib_seg_select_prop_bar">
					<input type="hidden" value="0" id="ib_seg_max_property_id">
					<input type="hidden" value="0" id="ib_seg_max_image_row_id">
					<?php
					$arFileProperties[] = [
						'ID' => 'DETAIL',
						'NAME' => GetMessage('IB_SEG_DETAIL'),
						'SELECTED' => 'Y',
					];
					$arFileProperties[] = [
						'ID' => 'ANNOUNCE',
						'NAME' => GetMessage('IB_SEG_ANNOUNCE'),
					];
					?>
					<span class="adm-btn" onclick="obPropertyTable.addPropertyImages();" id="ib_seg_add_images_button"><?= GetMessage("IB_SEG_ADD_PICTURES") ?></span>
						<span class="adm-shop-bar-btn-wrap" id="ib_seg_property_span">
							<script>
								addProperty(<?=CUtil::PhpToJSObject($arFileProperties)?>);
							</script>
						</span>
					<span id="ib_seg_property_add_button_span">
						<span id="ib_seg_property_add_button_span_click" class="adm-btn adm-btn-add" onclick="addProperty(<?=CUtil::PhpToJSObject($arFileProperties)?>)"></span>
					</span>
				</div>
				<table class="internal adm-shop-page-internal" id="adm-shop-table">
				</table>
			</div>
		</div>
	</td>
</tr>
	<?php
	$tabControl->EndTab();
	$tabControl->End();
	?>
	</form>
	<?php
}
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");

Youez - 2016 - github.com/yon3zu
LinuXploit