CSV IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/catalog/export_setup_templ.php'); global $APPLICATION, $USER; $NUM_CATALOG_LEVELS = intval(COption::GetOptionString("catalog", "num_catalog_levels", 3)); if (0 >= $NUM_CATALOG_LEVELS) $NUM_CATALOG_LEVELS = 3; $arSetupErrors = array(); global $arCatalogAvailProdFields, $defCatalogAvailProdFields, $arCatalogAvailPriceFields, $defCatalogAvailPriceFields, $arCatalogAvailValueFields, $defCatalogAvailValueFields, $arCatalogAvailQuantityFields, $defCatalogAvailQuantityFields, $arCatalogAvailGroupFields, $defCatalogAvailGroupFields, $defCatalogAvailCurrencies; $strCatalogDefaultFolder = COption::GetOptionString("catalog", "export_default_path", CATALOG_DEFAULT_EXPORT_PATH); $STEP = intval($STEP); if (0 >= $STEP) $STEP = 1; $ACTION = strval($ACTION); //******************** ACTIONS **************************************// if (($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) { if (isset($arOldSetupVars['IBLOCK_ID'])) $IBLOCK_ID = $arOldSetupVars['IBLOCK_ID']; } if ($STEP>1) { $IBLOCK_ID = intval($IBLOCK_ID); if ($IBLOCK_ID <= 0) { $arSetupErrors[] = GetMessage("CATI_NO_IBLOCK"); } else { $rsIBlocks = CIBlock::GetList(array(),array('IBLOCK_ID' => $IBLOCK_ID,'CHECK_PERMISSIONS' => 'N')); if (!($arIBlock = $rsIBlocks->Fetch())) { $arSetupErrors[] = GetMessage("CATI_NO_IBLOCK"); } elseif (!CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, 'iblock_admin_display')) { $arSetupErrors[] = str_replace('#IBLOCK_ID#', $IBLOCK_ID, GetMessage('CET_ERROR_IBLOCK_PERM')); } } if (!empty($arSetupErrors)) { $STEP = 1; } } if (($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_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 ($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_line_names'])) $first_line_names = $arOldSetupVars['first_line_names']; if (isset($arOldSetupVars['SETUP_FILE_NAME'])) $SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME']; if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; if ($arOldSetupVars['IBLOCK_ID'] == $IBLOCK_ID) { if (isset($arOldSetupVars['field_needed'])) $field_needed = $arOldSetupVars['field_needed']; if (isset($arOldSetupVars['field_num'])) $field_num = $arOldSetupVars['field_num']; if (isset($arOldSetupVars['field_code'])) $field_code = $arOldSetupVars['field_code']; } } if ($STEP>2) { if (!isset($fields_type) || ($fields_type!="F" && $fields_type!="R")) { $arSetupErrors[] = GetMessage("CATI_NO_FORMAT"); } $delimiter_r_char = ''; if (isset($delimiter_r)) { 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 = (isset($delimiter_other_r)? 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 (!isset($SETUP_FILE_NAME) || $SETUP_FILE_NAME == '') { $arSetupErrors[] = GetMessage("CATI_NO_SAVE_FILE"); } if (empty($arSetupErrors)) { $SETUP_FILE_NAME = str_replace('//','/',$strCatalogDefaultFolder.Rel2Abs("/", $SETUP_FILE_NAME)); if (preg_match(BX_CATALOG_FILENAME_REG, $SETUP_FILE_NAME)) { $arSetupErrors[] = GetMessage("CES_ERROR_BAD_EXPORT_FILENAME"); } elseif ($strCatalogDefaultFolder == $SETUP_FILE_NAME) { $arSetupErrors[] = GetMessage("CATI_NO_SAVE_FILE"); } } if (empty($arSetupErrors)) { if (mb_strtolower(mb_substr($SETUP_FILE_NAME, mb_strlen($SETUP_FILE_NAME) - 4)) != ".csv") $SETUP_FILE_NAME .= ".csv"; if (HasScriptExtension($SETUP_FILE_NAME)) { $arSetupErrors[] = GetMessage("CES_ERROR_BAD_EXPORT_FILENAME_EXTENTIONS"); } } if (empty($arSetupErrors)) { if ($APPLICATION->GetFileAccessPermission($SETUP_FILE_NAME) < "W") { $arSetupErrors[] = str_replace("#FILE#", $SETUP_FILE_NAME, GetMessage('CATI_NO_RIGHTS_FILE')); } else { CheckDirPath($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME); if (!($fp = fopen($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, "wb"))) { $arSetupErrors[] = GetMessage("CATI_CANNOT_CREATE_FILE"); } else { fclose($fp); unlink($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME); } } } $bFieldsPres = (!empty($field_needed) && is_array($field_needed) && in_array('Y', $field_needed)); if ($bFieldsPres && (empty($field_code) || !is_array($field_code))) { $bFieldsPres = false; } if (!$bFieldsPres) { $arSetupErrors[] = GetMessage("CATI_NO_FIELDS"); } // We can't link more than 30 tables $tableLinksCount = 10; for ($i = 0, $intCount = count($field_code); $i < $intCount; $i++) { if (mb_substr($field_code[$i], 0, mb_strlen("CR_PRICE_")) == "CR_PRICE_" && $field_needed[$i]=="Y") { $tableLinksCount++; } elseif (mb_substr($field_code[$i], 0, mb_strlen("IP_PROP")) == "IP_PROP" && $field_needed[$i]=="Y") { $tableLinksCount+=2; } } if ($tableLinksCount>30) { $arSetupErrors[] = GetMessage("CATI_TOO_MANY_TABLES"); } if (($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && (!isset($SETUP_PROFILE_NAME) || $SETUP_PROFILE_NAME == '')) { $arSetupErrors[] = GetMessage("CET_ERROR_NO_NAME"); } if (!empty($arSetupErrors)) { $STEP = 2; } } //******************** END ACTIONS **********************************// $aMenu = array( array( "TEXT"=>GetMessage("CATI_ADM_RETURN_TO_LIST"), "TITLE"=>GetMessage("CATI_ADM_RETURN_TO_LIST_TITLE"), "LINK"=>"/bitrix/admin/cat_export_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_EXP_TAB1"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_EXP_TAB1_TITLE")), array("DIV" => "edit2", "TAB" => GetMessage("CAT_ADM_CSV_EXP_TAB2"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_EXP_TAB2_TITLE")), array("DIV" => "edit3", "TAB" => GetMessage("CAT_ADM_CSV_EXP_TAB3"), "ICON" => "store", "TITLE" => GetMessage("CAT_ADM_CSV_EXP_TAB3_TITLE")), ); $tabControl = new CAdminTabControl("tabControl", $aTabs, false, true); $tabControl->Begin(); $tabControl->BeginNextTab(); if ($STEP==1) { ?> : 'Y','MIN_PERMISSION' => 'W'), '', '', 'class="adm-detail-iblock-types"', 'class="adm-detail-iblock-list"' ); ?> EndTab(); $tabControl->BeginNextTab(); if ($STEP == 2) { ?> : >
>
>
>
> > $arOneCatalogAvailProdFields_tmp["value"], "name"=>$arOneCatalogAvailProdFields_tmp["name"], 'sort' => ($intCount+1)*10, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_EXP_SEP_ELEMENTS'); $boolSep = false; } $intCount++; } } if (isset($arOneCatalogAvailProdFields_tmp)) unset($arOneCatalogAvailProdFields_tmp); $properties = CIBlockProperty::GetList(array("SORT"=>"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"]).']', 'sort' => ($intCount+1)*10, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_EXP_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++) { foreach ($arCatalogAvailGroupFields as &$arOnerCatalogAvailGroupFields) { $mxKey = array_search($arOnerCatalogAvailGroupFields['value'],$arVal); if (false !== $mxKey) { $arAvailFields[$intCount] = array( "value"=>$arOnerCatalogAvailGroupFields["value"].$k, "name"=> $arOnerCatalogAvailGroupFields["name"], 'sort' => ($intCount+1)*10, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_EXP_SEP_SECTIONS'); $boolSep = false; } if ($k_old != $k) { $arAvailFields[$intCount]['SUB_SEP'] = str_replace('#LEVEL#',($k+1),GetMessage("CAT_ADM_CSV_EXP_SECTION_LEVEL")); $k_old = $k; } $intCount++; } } if (isset($arOnerCatalogAvailGroupFields)) unset($arOnerCatalogAvailGroupFields); } if ($boolCatalog) { $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"], 'sort' => ($intCount+1)*10, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_EXP_SEP_PRODUCT'); $boolSep = false; } $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"], 'sort' => ($intCount+1)*10, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_EXP_SEP_PRICES'); $boolSep = false; } $intCount++; } } if (isset($arOneCatalogAvailQuantityFields)) unset($arOneCatalogAvailQuantityFields); $strVal = COption::GetOptionString("catalog", "allowed_currencies", $defCatalogAvailCurrencies); $arVal = explode(",", $strVal); $lcur = CCurrency::GetList('sort', 'asc'); $arCurList = array(); while ($lcur_res = $lcur->Fetch()) { if (in_array($lcur_res["CURRENCY"], $arVal)) { $arCurList[] = array( 'ID' => $lcur_res["CURRENCY"], 'DESCR' => str_replace('#CURRENCY#', $lcur_res["CURRENCY"], GetMessage('CATI_FI_PRICE_CURRENCY')), ); } } if (!empty($arCurList)) { $db_prgr = CCatalogGroup::GetList(array("SORT" => "ASC"), array()); while ($prgr = $db_prgr->Fetch()) { foreach ($arCurList as &$arCurrency) { $strName = ($prgr['NAME_LANG'] ? str_replace(array('#TYPE#','#NAME#'),array($prgr["NAME"],$prgr['NAME_LANG']),GetMessage('CATI_FI_PRICE_TYPE3')): str_replace("#TYPE#", $prgr["NAME"], GetMessage("CATI_FI_PRICE_TYPE2")) ); $arAvailFields[$intCount] = array( "value" => "CR_PRICE_".$prgr["ID"]."_".$arCurrency['ID'], "name" => $strName.' '.$arCurrency['DESCR'], 'sort' => ($intCount+1)*10, ); if ($boolSep) { $arAvailFields[$intCount]['SEP'] = GetMessage('CAT_ADM_CSV_EXP_SEP_PRICES'); $boolSep = false; } $intCount++; } unset($arCurrency); } } } $intCountAvailFields = $intCount; $intCountChecked = 0; $arCheckID = array(); $boolAll = true; if (!empty($field_code) && is_array($field_code)) { foreach ($arAvailFields as $i => $arOneAvailField) { $intSort = 0; $key = array_search($arOneAvailField['value'], $field_code); if (false !== $key) { if (isset($field_needed[$key]) && 'Y' == $field_needed[$key]) { $boolAll = false; $arCheckID[] = $arOneAvailField['value']; $intCountChecked++; } if (isset($field_num[$key]) && 0 < intval($field_num[$key])) $intSort = intval($field_num[$key]); } if (0 < $intSort) $arAvailFields[$i]['sort'] = $intSort; } } if ($boolAll) $intCountChecked = $intCountAvailFields; ?> $arOneAvailField) { if (!empty($arOneAvailField['SEP'])) { ?>
  
value="Y" onclick="checkOne(this,);"> ";?> ";?> ";?> "> ";?>
: ">
: EndTab(); $tabControl->BeginNextTab(); if ($STEP == 3) { $FINITE = true; } $tabControl->EndTab(); $tabControl->Buttons(); ?> "> 1) { ?> 1) { ?>">" name="submit_btn">End(); ?>