CSV (new) use Bitrix\Main, Bitrix\Catalog; IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/catalog/import_setup_templ.php'); /** @global string $ACTION */ /** @global string $URL_DATA_FILE */ /** @global string $DATA_FILE_NAME */ /** @global int $IBLOCK_ID */ /** @global string $fields_type */ /** @global string $first_names_r */ /** @global string $delimiter_r */ /** @global string $delimiter_other_r */ /** @global string $first_names_f */ /** @global string $metki_f */ global $APPLICATION, $USER; $NUM_CATALOG_LEVELS = (int)Main\Config\Option::get('catalog', 'num_catalog_levels'); if ($NUM_CATALOG_LEVELS <= 0) $NUM_CATALOG_LEVELS = 3; $arSetupErrors = array(); global $arCatalogAvailProdFields, $defCatalogAvailProdFields, $arCatalogAvailPriceFields, $defCatalogAvailPriceFields, $arCatalogAvailValueFields, $defCatalogAvailValueFields, $arCatalogAvailQuantityFields, $defCatalogAvailQuantityFields, $arCatalogAvailGroupFields, $defCatalogAvailGroupFields, $defCatalogAvailCurrencies; //******************** ACTIONS **************************************// if (($ACTION == 'IMPORT_EDIT' || $ACTION == 'IMPORT_COPY') && $STEP == 1) { if (isset($arOldSetupVars['IBLOCK_ID'])) $IBLOCK_ID = $arOldSetupVars['IBLOCK_ID']; if (isset($arOldSetupVars['URL_DATA_FILE'])) $URL_DATA_FILE = $arOldSetupVars['URL_DATA_FILE']; if (isset($arOldSetupVars['DATA_FILE_NAME'])) $DATA_FILE_NAME = $arOldSetupVars['DATA_FILE_NAME']; } if ($STEP > 1) { if ($URL_DATA_FILE <> '' && file_exists($_SERVER["DOCUMENT_ROOT"].$URL_DATA_FILE) && is_file($_SERVER["DOCUMENT_ROOT"].$URL_DATA_FILE) && $APPLICATION->GetFileAccessPermission($URL_DATA_FILE)>="R") $DATA_FILE_NAME = $URL_DATA_FILE; if ($DATA_FILE_NAME == '') $arSetupErrors[] = GetMessage("CATI_NO_DATA_FILE"); if (empty($arSetupErrors)) { $IBLOCK_ID = (int)$IBLOCK_ID; $arIBlock = array(); if ($IBLOCK_ID <= 0) { $arSetupErrors[] = GetMessage("CATI_NO_IBLOCK"); } else { $arIBlock = CIBlock::GetArrayByID($IBLOCK_ID); if (false === $arIBlock) { $arSetupErrors[] = GetMessage("CATI_NO_IBLOCK"); } } } if (empty($arSetupErrors)) { if (!CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, 'iblock_admin_display')) $arSetupErrors[] = GetMessage("CATI_NO_IBLOCK_RIGHTS"); } if (!empty($arSetupErrors)) { $STEP = 1; } } if (($ACTION == 'IMPORT_EDIT' || $ACTION == 'IMPORT_COPY') && $STEP == 2) { if (isset($arOldSetupVars['fields_type'])) $fields_type = $arOldSetupVars['fields_type']; if (isset($arOldSetupVars['delimiter_r'])) $delimiter_r = $arOldSetupVars['delimiter_r']; if (isset($arOldSetupVars['delimiter_r_char'])) $delimiter_r_char = $arOldSetupVars['delimiter_r_char']; if (isset($arOldSetupVars['delimiter_other_r'])) $delimiter_other_r = $arOldSetupVars['delimiter_other_r']; if (isset($arOldSetupVars['first_names_r'])) $first_names_r = $arOldSetupVars['first_names_r']; if (isset($arOldSetupVars['first_names_f'])) $first_names_f = $arOldSetupVars['first_names_f']; if (isset($arOldSetupVars['metki_f'])) $metki_f = $arOldSetupVars['metki_f']; } if ($STEP > 2) { $csvFile = new CCSVData(); $csvFile->LoadFile($_SERVER["DOCUMENT_ROOT"].$DATA_FILE_NAME); if ($fields_type != "F" && $fields_type != "R") $arSetupErrors[] = GetMessage("CATI_NO_FILE_FORMAT"); $arDataFileFields = array(); if (empty($arSetupErrors)) { $fields_type = (($fields_type == "F") ? "F" : "R" ); $csvFile->SetFieldsType($fields_type); if (isset($first_names) && !empty($first_names)) { $first_names_r = $first_names; $first_names_f = $first_names; } if ($fields_type == "R") { $first_names_r = ($first_names_r == "Y" ? "Y" : "N"); $csvFile->SetFirstHeader(($first_names_r == "Y") ? true : false); $delimiter_r_char = ""; switch ($delimiter_r) { case "TAB": $delimiter_r_char = "\t"; break; case "ZPT": $delimiter_r_char = ","; break; case "SPS": $delimiter_r_char = " "; break; case "OTR": $delimiter_r_char = mb_substr($delimiter_other_r, 0, 1); break; case "TZP": $delimiter_r_char = ";"; break; } if (mb_strlen($delimiter_r_char) != 1) $arSetupErrors[] = GetMessage("CATI_NO_DELIMITER"); if (empty($arSetupErrors)) { $csvFile->SetDelimiter($delimiter_r_char); } } else { $first_names_f = ($first_names_f == "Y" ? "Y" : "N"); $csvFile->SetFirstHeader(($first_names_f == "Y") ? true : false); if ($metki_f == '') $arSetupErrors[] = GetMessage("CATI_NO_METKI"); if (empty($arSetupErrors)) { $arMetkiTmp = preg_split("/[\D]/i", $metki_f); $arMetki = array(); for ($i = 0, $intCount = count($arMetkiTmp); $i < $intCount; $i++) { $arMetkiTmp[$i] = intval($arMetkiTmp[$i]); if (0 < $arMetkiTmp[$i]) { $arMetki[] = $arMetkiTmp[$i]; } } if (!is_array($arMetki) || count($arMetki)<1) $arSetupErrors[] = GetMessage("CATI_NO_METKI"); if (empty($arSetupErrors)) { $csvFile->SetWidthMap($arMetki); } } } if (empty($arSetupErrors)) { $bFirstHeaderTmp = $csvFile->GetFirstHeader(); $csvFile->SetFirstHeader(false); if ($arRes = $csvFile->Fetch()) { for ($i = 0, $intCount = count($arRes); $i < $intCount; $i++) { $arDataFileFields[$i] = $arRes[$i]; } } else { $arSetupErrors[] = GetMessage("CATI_NO_DATA"); } $NUM_FIELDS = count($arDataFileFields); } } if (!empty($arSetupErrors)) { $STEP = 2; } } if (($ACTION == 'IMPORT_EDIT' || $ACTION == 'IMPORT_COPY') && $STEP == 3) { if (isset($arOldSetupVars['IBLOCK_ID']) && $IBLOCK_ID == $arOldSetupVars['IBLOCK_ID']) { for ($i = 0, $intCountDataFileFields = count($arDataFileFields); $i < $intCountDataFileFields; $i++) { if (isset($arOldSetupVars['field_'.$i])) ${'field_'.$i} = $arOldSetupVars['field_'.$i]; } if (isset($arOldSetupVars['USE_TRANSLIT'])) $USE_TRANSLIT = $arOldSetupVars['USE_TRANSLIT']; if (isset($arOldSetupVars['TRANSLIT_LANG'])) $TRANSLIT_LANG = $arOldSetupVars['TRANSLIT_LANG']; if (isset($arOldSetupVars['USE_UPDATE_TRANSLIT'])) $USE_UPDATE_TRANSLIT = $arOldSetupVars['USE_UPDATE_TRANSLIT']; } if (isset($arOldSetupVars['PATH2IMAGE_FILES'])) $PATH2IMAGE_FILES = $arOldSetupVars['PATH2IMAGE_FILES']; if (isset($arOldSetupVars['IMAGE_RESIZE'])) $IMAGE_RESIZE = $arOldSetupVars['IMAGE_RESIZE']; if (isset($arOldSetupVars['outFileAction'])) $outFileAction = $arOldSetupVars['outFileAction']; if (isset($arOldSetupVars['inFileAction'])) $inFileAction = $arOldSetupVars['inFileAction']; if (isset($arOldSetupVars['CLEAR_EMPTY_PRICE'])) $CLEAR_EMPTY_PRICE = $arOldSetupVars['CLEAR_EMPTY_PRICE']; if (isset($arOldSetupVars['CML2_LINK_IS_XML'])) $CML2_LINK_IS_XML = $arOldSetupVars['CML2_LINK_IS_XML']; if (isset($arOldSetupVars['max_execution_time'])) $max_execution_time = $arOldSetupVars['max_execution_time']; if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; } if ($STEP > 3) { $USE_TRANSLIT = (isset($USE_TRANSLIT) && 'Y' == $USE_TRANSLIT ? 'Y' : 'N'); $TRANSLIT_LANG = (isset($TRANSLIT_LANG) ? (string)$TRANSLIT_LANG : ''); $USE_UPDATE_TRANSLIT = (isset($USE_UPDATE_TRANSLIT) && $USE_UPDATE_TRANSLIT == 'N' ? 'N' : 'Y'); if ('Y' == $USE_TRANSLIT) { if (!empty($TRANSLIT_LANG)) { $rsTransLangs = CLanguage::GetByID($TRANSLIT_LANG); if (!($arTransLang = $rsTransLangs->Fetch())) { $TRANSLIT_LANG = ''; } } if (empty($TRANSLIT_LANG)) { $arSetupErrors[] = GetMessage("CATI_CODE_TRANSLIT_LANG_ERR"); } } $CLEAR_EMPTY_PRICE = (isset($CLEAR_EMPTY_PRICE) && 'Y' == $CLEAR_EMPTY_PRICE ? 'Y' : 'N'); $CML2_LINK_IS_XML = (isset($CML2_LINK_IS_XML) && 'Y' == $CML2_LINK_IS_XML ? 'Y' : 'N'); if (!empty($arSetupErrors)) { $STEP = 3; } } //******************** END ACTIONS **********************************// $aMenu = array( array( "TEXT"=>GetMessage("CATI_ADM_RETURN_TO_LIST"), "TITLE"=>GetMessage("CATI_ADM_RETURN_TO_LIST_TITLE"), "LINK"=>"/bitrix/admin/cat_import_setup.php?lang=".LANGUAGE_ID, "ICON"=>"btn_list", ) ); $context = new CAdminContextMenu($aMenu); $context->Show(); if (!empty($arSetupErrors)) ShowError(implode('
', $arSetupErrors)); $actionParams = ""; if ($adminSidePanelHelper->isSidePanel()) { $actionParams = "?IFRAME=Y&IFRAME_TYPE=SIDE_SLIDER"; } ?>
"edit1", "TAB" => GetMessage("CAT_ADM_CSV_IMP_TAB1"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_IMP_TAB1_TITLE")), array("DIV" => "edit2", "TAB" => GetMessage("CAT_ADM_CSV_IMP_TAB2"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_IMP_TAB2_TITLE")), array("DIV" => "edit3", "TAB" => GetMessage("CAT_ADM_CSV_IMP_TAB3"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_IMP_TAB3_TITLE")), array("DIV" => "edit4", "TAB" => GetMessage("CAT_ADM_CSV_IMP_TAB4"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_IMP_TAB4_TITLE")), ); $tabControl = new CAdminTabControl("tabControl", $aTabs, false, true); $tabControl->Begin(); $tabControl->BeginNextTab(); if ($STEP == 1) { ?> : " onclick="cmlBtnSelectClick();"> "cmlBtnSelectClick", "arResultDest" => array("FORM_NAME" => "dataload", "FORM_ELEMENT_NAME" => "URL_DATA_FILE"), "arPath" => array("PATH" => "/upload/catalog", "SITE" => SITE_ID), "select" => 'F',// F - file only, D - folder only, DF - files & dirs "operation" => 'O',// O - open, S - save "showUploadTab" => true, "showAddToMenuTab" => false, "fileFilter" => 'csv', "allowAllFiles" => true, "SaveConfig" => true ) ); ?> : 'Y','MIN_PERMISSION' => 'W'), "", "", 'class="adm-detail-iblock-types"', 'class="adm-detail-iblock-list"' ); ?> EndTab(); $tabControl->BeginNextTab(); if ($STEP == 2) { ?> : onClick="ChangeExtra(this);">
onClick="ChangeExtra(this);">
:
:
>
>
>
>
>
: > EndTab(); $tabControl->BeginNextTab(); if ($STEP == 3) { ?> $IBLOCK_ID), false, false, array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID', 'SKU_PROPERTY_ID') ); if ($arCatalog = $rsCatalogs->Fetch()) { $boolCatalog = true; $boolOffers = ((int)$arCatalog['PRODUCT_IBLOCK_ID'] > 0); } $arAvailFields = array(); $intCount = 0; $boolSep = true; $strVal = COption::GetOptionString("catalog", "allowed_product_fields", $defCatalogAvailProdFields); $arVal = explode(",", $strVal); foreach ($arCatalogAvailProdFields as &$arOneCatalogAvailProdFields_tmp) { $mxKey = array_search($arOneCatalogAvailProdFields_tmp['value'],$arVal); if (false !== $mxKey) { $arAvailFields[$intCount] = array( "value"=>$arOneCatalogAvailProdFields_tmp["value"], "name"=>$arOneCatalogAvailProdFields_tmp["name"], ); if ('IE_XML_ID' == $arOneCatalogAvailProdFields_tmp["value"] || 'IE_NAME' == $arOneCatalogAvailProdFields_tmp["value"]) $arAvailFields[$intCount]['STYLE'] = 'background-color:#FFCCCC;'; if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_ELEMENTS'); $boolSep = false; } $intCount++; } } if (isset($arOneCatalogAvailProdFields_tmp)) unset($arOneCatalogAvailProdFields_tmp); $properties = CIBlockProperty::GetList(array("SORT"=>"ASC", "NAME" => "ASC", "ID"=>"ASC"), array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y", 'CHECK_PERMISSIONS' => 'N')); while ($prop_fields = $properties->Fetch()) { $arAvailFields[$intCount] = array( "value"=>"IP_PROP".$prop_fields["ID"], "name"=>GetMessage("CATI_FI_PROPS").' "'.$prop_fields["NAME"].'"'.' ['.(''!= trim($prop_fields["CODE"]) ? $prop_fields["CODE"] : $prop_fields["ID"]).']', ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_ELEMENTS'); $boolSep = false; } $intCount++; } $boolSep = true; $strVal = COption::GetOptionString("catalog", "allowed_group_fields", $defCatalogAvailGroupFields); $arVal = explode(",", $strVal); for ($k_old = -1, $k = 0; $k < $NUM_CATALOG_LEVELS; $k++) { $strLevel = ' - '.str_replace('#LEVEL#', ($k+1), GetMessage('CAT_ADM_CSV_IMP_SECT_LEVEL')); foreach ($arCatalogAvailGroupFields as $arOnerCatalogAvailGroupFields) { $mxKey = array_search($arOnerCatalogAvailGroupFields['value'],$arVal); if (false !== $mxKey) { $arAvailFields[$intCount] = array( "value"=>$arOnerCatalogAvailGroupFields["value"].$k, "name"=> $arOnerCatalogAvailGroupFields["name"].$strLevel, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_SECTIONS'); $boolSep = false; } if ($k_old != $k) { $arAvailFields[$intCount]['SUB_SEP'] = str_replace('#LEVEL#',($k+1),GetMessage("CAT_ADM_CSV_IMP_SECTION_LEVEL")); $k_old = $k; } $intCount++; } } if (isset($arOnerCatalogAvailGroupFields)) unset($arOnerCatalogAvailGroupFields); /* if (!empty($arSectionProps)) { foreach ($arSectionProps as &$arOneSectionProp) { $arAvailFields[$intCount] = array( "value" => 'SP_'.$arOneSectionProp['FIELD_NAME'].'_'.$k, "name" => GetMessage('CAT_ADM_CSV_IMP_DESCR_SECT_PROP').' "'.($arOneSectionProp['EDIT_FORM_LABEL'] ? $arOneSectionProp['EDIT_FORM_LABEL'] : $arOneSectionProp['FIELD_NAME']).'"', ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_SECTIONS'); $boolSep = false; } if ($k_old != $k) { $arAvailFields[$intCount]['SUB_SEP'] = str_replace('#LEVEL#',($k+1),GetMessage("CAT_ADM_CSV_IMP_SECTION_LEVEL")); $k_old = $k; } $intCount++; } if (isset($arOneSectionProp)) unset($arOneSectionProp); } */ } if ($boolCatalog) { $boolUseStoreControl = Catalog\Config\State::isUsedInventoryManagement(); $arDisableFields = array( 'CP_QUANTITY' => true, 'CP_PURCHASING_PRICE' => true, 'CP_PURCHASING_CURRENCY' => true, ); $boolSep = true; $strVal = COption::GetOptionString("catalog", "allowed_product_fields", $defCatalogAvailPriceFields); $arVal = explode(",", $strVal); foreach ($arCatalogAvailPriceFields as $arOneCatalogAvailProdFields_tmp) { $mxKey = array_search($arOneCatalogAvailProdFields_tmp['value'],$arVal); if (false !== $mxKey) { $arAvailFields[$intCount] = array( "value"=>$arOneCatalogAvailProdFields_tmp["value"], "name"=>$arOneCatalogAvailProdFields_tmp["name"], ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_PRODUCT'); $boolSep = false; } if ($boolUseStoreControl && array_key_exists($arAvailFields[$intCount]['value'], $arDisableFields)) { $arAvailFields[$intCount]['DISABLE'] = true; } $intCount++; } } if (isset($arOneCatalogAvailProdFields_tmp)) unset($arOneCatalogAvailProdFields_tmp); $boolSep = true; $strVal = $defCatalogAvailQuantityFields; $arVal = explode(",", $strVal); foreach ($arCatalogAvailQuantityFields as $arOneCatalogAvailQuantityFields) { $mxKey = array_search($arOneCatalogAvailQuantityFields['value'],$arVal); if (false !== $mxKey) { $arAvailFields[$intCount] = array( "value"=>$arOneCatalogAvailQuantityFields["value"], "name"=>$arOneCatalogAvailQuantityFields["name"], ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_PRICES'); $boolSep = false; } $intCount++; } } if (isset($arOneCatalogAvailQuantityFields)) unset($arOneCatalogAvailQuantityFields); $strVal = COption::GetOptionString("catalog", "allowed_price_fields", $defCatalogAvailValueFields); $arVal = explode(",", $strVal); $db_prgr = CCatalogGroup::GetList(array("SORT" => "ASC"), array()); while ($prgr = $db_prgr->Fetch()) { foreach ($arCatalogAvailValueFields as $arOneCatalogAvailValueFields) { $mxKey = array_search($arOneCatalogAvailValueFields['value'],$arVal); if (false !== $mxKey) { $strName = ($prgr['NAME_LANG'] ? str_replace(array('#TYPE#','#NAME#'),array($prgr["NAME"],$prgr['NAME_LANG']),GetMessage('EST_PRICE_TYPE2')): str_replace("#TYPE#", $prgr["NAME"], GetMessage("EST_PRICE_TYPE")) ); $arAvailFields[$intCount] = array( "value" => $arOneCatalogAvailValueFields['value']."_".$prgr["ID"], "name" => $strName.": ".$arOneCatalogAvailValueFields["name"], ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_IMP_SEP_PRICES'); $boolSep = false; } $intCount++; } } if (isset($arOneCatalogAvailValueFields)) unset($arOneCatalogAvailValueFields); } } for ($i = 0, $intCountDataFileFields = count($arDataFileFields); $i < $intCountDataFileFields; $i++) { ?> ():