function Fetch() { if (empty($this->__rows)) { $this->__last_pos = $this->GetPos(); return parent::Fetch(); } else { $this->__last_pos = array_pop($this->__pos); return array_pop($this->__rows); } }
if (intval($arMetkiTmp[$i]) > 0) { $arMetki[] = intval($arMetkiTmp[$i]); } } if (!is_array($arMetki) || count($arMetki) < 1) { $strImportErrorMessage .= GetMessage("CATI_NO_METKI") . "<br>"; } if ('' == $strImportErrorMessage) { $csvFile->SetWidthMap($arMetki); } } } if ('' == $strImportErrorMessage) { $bFirstHeaderTmp = $csvFile->GetFirstHeader(); $csvFile->SetFirstHeader(false); if ($arRes = $csvFile->Fetch()) { for ($i = 0, $intCount = count($arRes); $i < $intCount; $i++) { $arDataFileFields[$i] = $arRes[$i]; } } else { $strImportErrorMessage .= GetMessage("CATI_NO_DATA") . "<br>"; } global $NUM_FIELDS; $NUM_FIELDS = count($arDataFileFields); } } if ('' == $strImportErrorMessage) { $bFieldsPres = false; for ($i = 0; $i < $NUM_FIELDS; $i++) { if (strlen(${"field_" . $i}) > 0) { $bFieldsPres = true;
function __CrmImportPrepareFieldBindingTab(&$arResult, &$arRequireFields) { $resultMessages = array(); $arFields = array('' => ''); $arFieldsUpper = array(); foreach ($arResult['HEADERS'] as $arField) { //echo '"'.$arField['name'].'";'; $arFields[$arField['id']] = $arField['name']; $arFieldsUpper[$arField['id']] = strtoupper($arField['name']); if ($arField['mandatory'] == 'Y') { $arRequireFields[$arField['id']] = $arField['name']; } } require_once $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/main/classes/general/csv_data.php'; $csvFile = new CCSVData(); $csvFile->LoadFile($_SESSION['CRM_IMPORT_FILE']); $csvFile->SetFieldsType('R'); $csvFile->SetFirstHeader(false); $csvFile->SetDelimiter($_SESSION['CRM_IMPORT_FILE_SEPORATOR']); $iRow = 1; $arHeader = array(); $arRows = array(); while ($arData = $csvFile->Fetch()) { if ($iRow == 1) { foreach ($arData as $key => $value) { if ($_SESSION['CRM_IMPORT_FILE_SKIP_EMPTY'] && empty($value)) { continue; } if ($_SESSION['CRM_IMPORT_FILE_FIRST_HEADER']) { $arHeader[$key] = empty($value) ? GetMessage('CRM_COLUMN_HEADER') . ' ' . ($key + 1) : trim($value); } else { $arHeader[$key] = GetMessage('CRM_COLUMN_HEADER') . ' ' . ($key + 1); } } if (!$_SESSION['CRM_IMPORT_FILE_FIRST_HEADER']) { foreach ($arHeader as $key => $value) { $arRows[$iRow][$key] = $arData[$key]; } } } else { foreach ($arHeader as $key => $value) { $arRows[$iRow][$key] = $arData[$key]; } } if ($iRow > 5) { break; } $iRow++; } $_SESSION['CRM_IMPORT_FILE_HEADERS'] = $arHeader; $_SESSION['CRM_IMPORT_FILE_FLIPPED_HEADERS'] = array_flip($arHeader); if (count($arHeader) === 1) { $resultMessages[] = GetMessage('CRM_CSV_CUSTOM_SINGLE_HEADER_ERROR'); } $arResult['FIELDS']['tab_2'] = array(); if (count($arRequireFields) > 0) { ob_start(); ?> <div class="crm_import_require_fields"> <?php echo GetMessage('CRM_REQUIRE_FIELDS'); ?> : <b><?php echo implode('</b>, <b>', $arRequireFields); ?> </b>. </div> <?php $sVal = ob_get_contents(); ob_end_clean(); $arResult['FIELDS']['tab_2'][] = array('id' => 'IMPORT_REQUIRE_FIELDS', 'name' => '', 'colspan' => true, 'type' => 'custom', 'value' => $sVal); } foreach ($arHeader as $key => $value) { $arResult['FIELDS']['tab_2'][] = array('id' => 'IMPORT_FILE_FIELD_' . $key, 'name' => $value, 'items' => $arFields, 'type' => 'list', 'value' => isset($arFields[strtoupper($value)]) ? strtoupper($value) : array_search(strtoupper($value), $arFieldsUpper)); } $arResult['FIELDS']['tab_2'][] = array('id' => 'IMPORT_ASSOC_EXAMPLE', 'name' => GetMessage('CRM_SECTION_IMPORT_ASSOC_EXAMPLE'), 'type' => 'section'); ob_start(); ?> <div id="crm_import_example" class="crm_import_example"> <table cellspacing="0" cellpadding="0" class="crm_import_example_table"> <tr> <?php foreach ($arHeader as $key => $value) { ?> <th><?php echo htmlspecialcharsbx($value); ?> </th> <?php } ?> </tr> <?php foreach ($arRows as $arRow) { ?> <tr> <?php foreach ($arRow as $row) { ?> <td><?php echo htmlspecialcharsbx($row); ?> </td> <?php } ?> </tr> <?php } ?> </table> </div> <script type="text/javascript"> windowSizes = BX.GetWindowSize(document); if (windowSizes.innerWidth > 1024) BX('crm_import_example').style.width = '870px'; if (windowSizes.innerWidth > 1280) BX('crm_import_example').style.width = '1065px'; </script> <?php $sVal = ob_get_contents(); ob_end_clean(); $arResult['FIELDS']['tab_2'][] = array('id' => 'IMPORT_ASSOC_EXAMPLE_TABLE', 'name' => "", 'colspan' => true, 'type' => 'custom', 'value' => $sVal); return implode("\n", $resultMessages); }
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))
public static function import($arParams) { global $APPLICATION; // check fields $aMsg = array(); $arParams['SET_ID'] = intval($arParams['SET_ID']); $arParams['IMPORT_IF_FILE_EXISTS'] = isset($arParams['IMPORT_IF_FILE_EXISTS']) && $arParams['IMPORT_IF_FILE_EXISTS'] == 'Y' ? true : false; if (isset($arParams['FILE']) && GetFileExtension($arParams['FILE']) != 'zip') { $aMsg["FILE_EXT"] = array("id" => "FILE_EXT", "text" => GetMessage("MAIN_SMILE_IMPORT_FILE_EXT_ERROR")); } else { if (!isset($arParams['FILE']) || !file_exists($arParams['FILE'])) { $aMsg["FILE"] = array("id" => "FILE", "text" => GetMessage("MAIN_SMILE_IMPORT_FILE_ERROR")); } else { if ($arParams['SET_ID'] <= 0) { $aMsg["SET_ID"] = array("id" => "SET_ID", "text" => GetMessage("MAIN_SMILE_IMPORT_SET_ID_ERROR")); } } } if (!empty($aMsg)) { $e = new CAdminException($aMsg); $APPLICATION->ThrowException($e); return false; } $sUnpackDir = CTempFile::GetDirectoryName(1); CheckDirPath($sUnpackDir); /** @var IBXArchive $oArchiver */ $oArchiver = CBXArchive::GetArchive($arParams['FILE'], "ZIP"); $oArchiver->SetOptions(array("STEP_TIME" => 300)); if (!$oArchiver->Unpack($sUnpackDir)) { $aMsg["UNPACK"] = array("id" => "UNPACK", "text" => GetMessage("MAIN_SMILE_IMPORT_UNPACK_ERROR")); $e = new CAdminException($aMsg); $APPLICATION->ThrowException($e); return false; } $arSmiles = array(); if (file_exists($sUnpackDir . 'install.csv')) { $arLang = array(); $db_res = CLanguage::GetList($b = "sort", $o = "asc"); while ($res = $db_res->Fetch()) { if (file_exists($sUnpackDir . 'install_lang_' . $res["LID"] . '.csv')) { $arSmiles = array(); $csvFile = new CCSVData(); $csvFile->LoadFile($sUnpackDir . 'install_lang_' . $res["LID"] . '.csv'); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); while ($smile = $csvFile->Fetch()) { if (defined('BX_UTF') && BX_UTF && $res["LID"] == 'ru') { $smile[1] = $APPLICATION->ConvertCharset($smile[1], 'windows-1251', 'utf-8'); } $arLang[$smile[0]][$res["LID"]] = $smile[1]; } } } $csvFile = new CCSVData(); $csvFile->LoadFile($sUnpackDir . 'install.csv'); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); while ($smileRes = $csvFile->Fetch()) { $smile = array('TYPE' => $smileRes[0], 'CLICKABLE' => $smileRes[1] == 'Y' ? 'Y' : 'N', 'SORT' => intval($smileRes[2]), 'IMAGE' => $smileRes[3], 'IMAGE_WIDTH' => intval($smileRes[4]), 'IMAGE_HEIGHT' => intval($smileRes[5]), 'IMAGE_DEFINITION' => in_array($smileRes[6], array(self::IMAGE_SD, self::IMAGE_HD, self::IMAGE_UHD)) ? $smileRes[6] : ($smileRes[6] == 'Y' ? self::IMAGE_HD : self::IMAGE_SD), 'HIDDEN' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[7] : 'N', 'IMAGE_LANG' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[8] : $smileRes[7], 'TYPING' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[9] : $smileRes[8]); if (!in_array($smile['TYPE'], array(CSmile::TYPE_SMILE, CSmile::TYPE_ICON))) { continue; } $smile['IMAGE'] = GetFileName($smile['IMAGE']); $imgArray = CFile::GetImageSize($sUnpackDir . $smile['IMAGE']); if (!is_array($imgArray)) { continue; } $arInsert = array('TYPE' => $smile['TYPE'], 'SET_ID' => $arParams['SET_ID'], 'CLICKABLE' => $smile['CLICKABLE'], 'SORT' => $smile['SORT'], 'IMAGE' => $smile['IMAGE'], 'IMAGE_WIDTH' => $smile['IMAGE_WIDTH'], 'IMAGE_HEIGHT' => $smile['IMAGE_HEIGHT'], 'IMAGE_DEFINITION' => $smile['IMAGE_DEFINITION'], 'HIDDEN' => $smile['HIDDEN'], 'TYPING' => $smile['TYPING']); if (isset($arLang[$smile['IMAGE_LANG']])) { $arInsert['LANG'] = $arLang[$smile['IMAGE_LANG']]; } $arSmiles[] = $arInsert; } } else { $smileSet = CSmileSet::getById($arParams['SET_ID']); if ($handle = @opendir($sUnpackDir)) { $sort = 300; while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") { continue; } if (is_file($sUnpackDir . $file)) { $imgArray = CFile::GetImageSize($sUnpackDir . $file); if (is_array($imgArray)) { $smileHR = self::IMAGE_SD; $smileType = CSmile::TYPE_SMILE; $smileCode = GetFileNameWithoutExtension($file); if (strpos($file, 'smile_') !== false && strpos($file, 'smile_') == 0) { $smileCode = substr($smileCode, 6); } elseif (strpos($file, 'smile') !== false && strpos($file, 'smile') == 0) { $smileCode = substr($smileCode, 5); } elseif (strpos($file, 'icon_') !== false && strpos($file, 'icon_') == 0) { $smileType = CSmile::TYPE_ICON; $smileCode = substr($smileCode, 5); } else { if (strpos($file, 'icon') !== false && strpos($file, 'icon') == 0) { $smileType = CSmile::TYPE_ICON; $smileCode = substr($smileCode, 4); } } if (strrpos($smileCode, '_hr') !== false && strrpos($smileCode, '_hr') == strlen($smileCode) - 3) { $smileHR = self::IMAGE_HD; $smileCode = substr($smileCode, 0, strrpos($smileCode, '_hr')); } if ($pos = strpos($smileCode, '_hr_')) { $smileHR = self::IMAGE_HD; $smileCode = substr($smileCode, 0, $pos) . '_' . substr($smileCode, $pos + 4); } $arSmiles[] = array('TYPE' => $smileType, 'SET_ID' => $arParams['SET_ID'], 'CLICKABLE' => 'Y', 'SORT' => $sort, 'IMAGE' => $file, 'IMAGE_WIDTH' => intval($imgArray[0]), 'IMAGE_HEIGHT' => intval($imgArray[1]), 'IMAGE_DEFINITION' => $smileHR, 'TYPING' => ':' . (isset($smileSet['STRING_ID']) ? $smileSet['STRING_ID'] : $smileSet['ID']) . '/' . $smileCode . ':'); $sort = $sort + 5; } } } @closedir($handle); } } $importSmile = 0; foreach ($arSmiles as $smile) { $sUploadDir = ($smile['TYPE'] == CSmile::TYPE_ICON ? CSmile::PATH_TO_ICON : CSmile::PATH_TO_SMILE) . intval($smile["SET_ID"]) . '/'; if (file_exists($sUnpackDir . $smile['IMAGE']) && ($arParams['IMPORT_IF_FILE_EXISTS'] || !file_exists($_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE']))) { if (CheckDirPath($_SERVER["DOCUMENT_ROOT"] . $sUploadDir)) { $insertId = CSmile::add($smile); if ($insertId) { if ($arParams['IMPORT_IF_FILE_EXISTS'] && file_exists($_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE'])) { $importSmile++; } else { if (copy($sUnpackDir . $smile['IMAGE'], $_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE'])) { @chmod($_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE'], BX_FILE_PERMISSIONS); $importSmile++; } else { CSmile::delete($insertId); } } } $APPLICATION->ResetException(); } } } return $importSmile; }
include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php"; $csvFile = new CCSVData(); $csvFile->LoadFile(dirname(__FILE__) . "/data/" . $lang . "/loc.csv"); $csvFile->SetPos($_SESSION["LOC_POST"]); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); $csvFile->SetDelimiter(","); $arLocation = array(); $arLocationMap = array(); $arSysLangs = array(); $db_lang = CLangAdmin::GetList($b = "sort", $o = "asc", array("ACTIVE" => "Y")); while ($arLang = $db_lang->Fetch()) { $arSysLangs[] = $arLang["LID"]; } $i = 0; while ($arRes = $csvFile->Fetch()) { $i++; if ($i >= 1000) { $_SESSION["LOC_POST"] = $csvFile->GetPos(); break; } if (IntVal($CurCountryID) <= 0) { $dbCountry = CSaleLocation::GetCountryList(array("ID" => "DESC")); if ($arCountry = $dbCountry->Fetch()) { $CurCountryID = $arCountry["ID"]; } } $arArrayTmp = array(); for ($ind = 1; $ind < count($arRes); $ind += 2) { if (in_array($arRes[$ind], $arSysLangs)) { $arArrayTmp[$arRes[$ind]] = array("LID" => $arRes[$ind], "NAME" => $arRes[$ind + 1]);
} } if (!is_array($arMetki) || count($arMetki)<1) $strImportErrorMessage .= GetMessage("CATI_NO_METKI")."<br>"; if ('' == $strImportErrorMessage) $csvFile->SetWidthMap($arMetki); } } if ('' == $strImportErrorMessage) { $bFirstHeaderTmp = $csvFile->GetFirstHeader(); $csvFile->SetFirstHeader(false); if ($arRes = $csvFile->Fetch()) { for ($i = 0, $intCount = count($arRes); $i < $intCount; $i++) { $arDataFileFields[$i] = $arRes[$i]; } } else { $strImportErrorMessage .= GetMessage("CATI_NO_DATA")."<br>"; } global $NUM_FIELDS; $NUM_FIELDS = count($arDataFileFields); } }
function saleLocationImport($arParams) { global $DB; $arReturn = array('STEP' => false, 'ERROR' => '', 'AMOUNT' => 0, 'POS' => 0, 'MESSAGE' => ''); $step_length = intval($arParams["STEP_LENGTH"]); if ($step_length <= 0) { $step_length = 10; } define('ZIP_STEP_LENGTH', $step_length); define('LOC_STEP_LENGTH', $step_length); define('DLZIPFILE', $arParams["DLZIPFILE"]); $STEP = intval($arParams['STEP']); $CSVFILE = $arParams["CSVFILE"]; $LOADZIP = $arParams["LOADZIP"]; $bSync = $arParams["SYNC"] == "Y"; if (isset($arParams['TMP_PATH'])) { $sTmpFilePath = $arParams['TMP_PATH']; } else { $sTmpFilePath = CTempFile::GetDirectoryName(12, 'sale'); } if (strlen($CSVFILE) > 0 && !in_array($CSVFILE, array('loc_ussr.csv', 'loc_ua.csv', 'loc_kz.csv', 'loc_usa.csv', 'loc_cntr.csv', 'locations.csv'))) { //echo GetMessage('SL_IMPORT_ERROR_FILES'); $arReturn['ERROR'] = GetMessage('SL_IMPORT_ERROR_FILES'); } else { if ($STEP == 1 && strlen($CSVFILE) <= 0) { if ($LOADZIP == 'Y') { $STEP = 2; } else { $STEP = 3; } } switch ($STEP) { case 0: $arReturn['MESSAGE'] = GetMessage('WSL_IMPORT_FILES_LOADING'); $arReturn['STEP'] = 1; break; case 1: $time_limit = ini_get('max_execution_time'); if ($time_limit < LOC_STEP_LENGTH) { set_time_limit(LOC_STEP_LENGTH + 5); } $start_time = time(); $finish_time = $start_time + LOC_STEP_LENGTH; $file_url = $sTmpFilePath . $CSVFILE; if (!file_exists($file_url)) { $arReturn['ERROR'] = GetMessage('SL_IMPORT_ERROR_NO_LOC_FILE'); break; } $bFinish = true; $arSysLangs = array(); $db_lang = CLangAdmin::GetList($b = "sort", $o = "asc", array("ACTIVE" => "Y")); while ($arLang = $db_lang->Fetch()) { $arSysLangs[$arLang["LID"]] = $arLang["LID"]; } $arLocations = array(); if (!$bSync) { if (!is_set($_SESSION["LOC_POS"])) { CSaleLocation::DeleteAll(); } } else { $dbLocations = CSaleLocation::GetList(array(), array(), false, false, array("ID", "COUNTRY_ID", "REGION_ID", "CITY_ID")); while ($arLoc = $dbLocations->Fetch()) { $arLocations[$arLoc["ID"]] = $arLoc; } } if (count($arLocations) <= 0) { $bSync = false; } include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php"; $csvFile = new CCSVData(); $csvFile->LoadFile($file_url); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); $csvFile->SetDelimiter(","); $arRes = $csvFile->Fetch(); if (!is_array($arRes) || count($arRes) <= 0 || strlen($arRes[0]) != 2) { $strWarning .= GetMessage('SL_IMPORT_ERROR_WRONG_LOC_FILE') . "<br />"; } if (strlen($strWarning) <= 0) { $DefLang = $arRes[0]; if (!in_array($DefLang, $arSysLangs)) { $strWarning .= GetMessage('SL_IMPORT_ERROR_NO_LANG') . "<br />"; } } if (strlen($strWarning) > 0) { $arReturn['ERROR'] = $strWarning . "<br />"; break; } if (is_set($_SESSION["LOC_POS"])) { $csvFile->SetPos($_SESSION["LOC_POS"]); $CurCountryID = $_SESSION["CUR_COUNTRY_ID"]; $CurRegionID = $_SESSION["CUR_REGION_ID"]; $numCountries = $_SESSION["NUM_COUNTRIES"]; $numRegiones = $_SESSION["NUM_REGIONES"]; $numCities = $_SESSION["NUM_CITIES"]; $numLocations = $_SESSION["NUM_LOCATIONS"]; } else { $CurCountryID = 0; $CurRegionID = 0; $numCountries = 0; $numRegiones = 0; $numCities = 0; $numLocations = 0; } $tt = 0; while ($arRes = $csvFile->Fetch()) { $type = ToUpper($arRes[0]); $tt++; $arArrayTmp = array(); foreach ($arRes as $ind => $value) { if ($ind % 2 && isset($arSysLangs[$value])) { $arArrayTmp[$value] = array("LID" => $value, "NAME" => $arRes[$ind + 1]); if ($value == $DefLang) { $arArrayTmp["NAME"] = $arRes[$ind + 1]; } } } //country if (is_array($arArrayTmp) && strlen($arArrayTmp["NAME"]) > 0) { if ($type == "S") { $CurRegionID = null; $arRegionList = array(); $CurCountryID = null; $arContList = array(); $LLL = 0; if ($bSync) { $db_contList = CSaleLocation::GetList(array(), array("COUNTRY_NAME" => $arArrayTmp["NAME"], "LID" => $DefLang)); if ($arContList = $db_contList->Fetch()) { $LLL = IntVal($arContList["ID"]); $CurCountryID = IntVal($arContList["COUNTRY_ID"]); } } if (IntVal($CurCountryID) <= 0) { $CurCountryID = CSaleLocation::AddCountry($arArrayTmp); $CurCountryID = IntVal($CurCountryID); if ($CurCountryID > 0) { $numCountries++; if (IntVal($LLL) <= 0) { $LLL = CSaleLocation::AddLocation(array("COUNTRY_ID" => $CurCountryID)); if (IntVal($LLL) > 0) { $numLocations++; } } } } } elseif ($type == "R") { $CurRegionID = null; $arRegionList = array(); $LLL = 0; if ($bSync) { $db_rengList = CSaleLocation::GetList(array(), array("COUNTRY_ID" => $CurCountryID, "REGION_NAME" => $arArrayTmp["NAME"], "LID" => $DefLang)); if ($arRegionList = $db_rengList->Fetch()) { $LLL = $arRegionList["ID"]; $CurRegionID = IntVal($arRegionList["REGION_ID"]); } } if (IntVal($CurRegionID) <= 0) { $CurRegionID = CSaleLocation::AddRegion($arArrayTmp); $CurRegionID = IntVal($CurRegionID); if ($CurRegionID > 0) { $numRegiones++; if (IntVal($LLL) <= 0) { $LLL = CSaleLocation::AddLocation(array("COUNTRY_ID" => $CurCountryID, "REGION_ID" => $CurRegionID)); if (IntVal($LLL) > 0) { $numLocations++; } } } } } elseif ($type == "T" && IntVal($CurCountryID) > 0) { $city_id = 0; $LLL = 0; $arCityList = array(); if ($bSync) { $arFilter = array("COUNTRY_ID" => $CurCountryID, "CITY_NAME" => $arArrayTmp["NAME"], "LID" => $DefLang); if (IntVal($CurRegionID) > 0) { $arFilter["REGION_ID"] = $CurRegionID; } $db_cityList = CSaleLocation::GetList(array(), $arFilter); if ($arCityList = $db_cityList->Fetch()) { $LLL = $arCityList["ID"]; $city_id = IntVal($arCityList["CITY_ID"]); } } if ($city_id <= 0) { $city_id = CSaleLocation::AddCity($arArrayTmp); $city_id = IntVal($city_id); if ($city_id > 0) { $numCities++; } } if ($city_id > 0) { if (IntVal($LLL) <= 0) { $LLL = CSaleLocation::AddLocation(array("COUNTRY_ID" => $CurCountryID, "REGION_ID" => $CurRegionID, "CITY_ID" => $city_id)); if (intval($LLL) > 0) { $numLocations++; } } } } } if ($tt == 10) { $tt = 0; $cur_time = time(); if ($cur_time >= $finish_time) { $cur_step = $csvFile->GetPos(); $amount = $csvFile->iFileLength; $_SESSION["LOC_POS"] = $cur_step; $_SESSION["CUR_COUNTRY_ID"] = $CurCountryID; $_SESSION["CUR_REGION_ID"] = $CurRegionID; $_SESSION["NUM_COUNTRIES"] = $numCountries; $_SESSION["NUM_REGIONES"] = $numRegiones; $_SESSION["NUM_CITIES"] = $numCities; $_SESSION["NUM_LOCATIONS"] = $numLocations; $bFinish = false; //echo "<script>Import(1, {AMOUNT:".CUtil::JSEscape($amount).",POS:".CUtil::JSEscape($cur_step)."})</script>"; $arReturn['STEP'] = 1; $arReturn['AMOUNT'] = $amount; $arReturn['POS'] = $cur_step; break; } } } if ($bFinish) { unset($_SESSION["LOC_POS"]); $strOK = GetMessage('SL_IMPORT_LOC_STATS') . '<br />'; $strOK = str_replace('#NUMCOUNTRIES#', intval($numCountries), $strOK); $strOK = str_replace('#NUMREGIONES#', intval($numRegiones), $strOK); $strOK = str_replace('#NUMCITIES#', intval($numCities), $strOK); $strOK = str_replace('#NUMLOCATIONS#', intval($numLocations), $strOK); $arReturn['MESSAGE'] = $strOK; $arReturn['STEP'] = $LOADZIP == "Y" ? 2 : 3; //echo '<script>Import('.($LOADZIP == "Y" ? 2 : 3).')</script>'; } break; case 2: $time_limit = ini_get('max_execution_time'); if ($time_limit < ZIP_STEP_LENGTH) { set_time_limit(ZIP_STEP_LENGTH + 5); } $start_time = time(); $finish_time = $start_time + ZIP_STEP_LENGTH; if ($LOADZIP == "Y" && file_exists($sTmpFilePath . DLZIPFILE)) { $rsLocations = CSaleLocation::GetList(array(), array("LID" => 'ru'), false, false, array("ID", "CITY_NAME_LANG", "REGION_NAME_LANG")); $arLocationMap = array(); while ($arLocation = $rsLocations->Fetch()) { if (strlen($arLocation["REGION_NAME_LANG"]) > 0) { if (strlen($arLocation["CITY_NAME_LANG"]) > 0) { $arLocationMap[$arLocation["CITY_NAME_LANG"]][$arLocation["REGION_NAME_LANG"]] = $arLocation["ID"]; } } else { $arLocationMap[$arLocation["CITY_NAME_LANG"]] = $arLocation["ID"]; } } $DB->StartTransaction(); include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php"; $csvFile = new CCSVData(); $csvFile->LoadFile($sTmpFilePath . DLZIPFILE); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); $csvFile->SetDelimiter(";"); if (is_set($_SESSION, 'ZIP_POS')) { $numZIP = $_SESSION["NUM_ZIP"]; $csvFile->SetPos($_SESSION["ZIP_POS"]); } else { CSaleLocation::ClearAllLocationZIP(); unset($_SESSION["NUM_ZIP"]); $numZIP = 0; } $bFinish = true; $tt = 0; $REGION = ""; while ($arRes = $csvFile->Fetch()) { $tt++; $CITY = $arRes[1]; if (strlen($arRes[3]) > 0) { $REGION = $arRes[3]; } if (array_key_exists($CITY, $arLocationMap)) { if (strlen($REGION) > 0) { $ID = $arLocationMap[$CITY][$REGION]; } else { $ID = $arLocationMap[$CITY]; } } else { $ID = 0; } if ($ID) { CSaleLocation::AddLocationZIP($ID, $arRes[2]); $numZIP++; } if ($tt == 10) { $tt = 0; $cur_time = time(); if ($cur_time >= $finish_time) { $cur_step = $csvFile->GetPos(); $amount = $csvFile->iFileLength; $_SESSION["ZIP_POS"] = $cur_step; $_SESSION["NUM_ZIP"] = $numZIP; $bFinish = false; $arReturn['STEP'] = 2; $arReturn['AMOUNT'] = $amount; $arReturn['POS'] = $cur_step; break; } } } $DB->Commit(); if ($bFinish) { unset($_SESSION["ZIP_POS"]); $numCity = CSaleLocation::_GetZIPImportStats(); $strOK = GetMessage('SL_IMPORT_ZIP_STATS'); $strOK = str_replace('#NUMZIP#', intval($numZIP), $strOK); $strOK = str_replace('#NUMCITIES#', intval($numCity["CITY_CNT"]), $strOK); $arReturn['MESSAGE'] = $strOK; $arReturn['STEP'] = 3; $arReturn['PB_REMOVE'] = true; break; } } else { $arReturn['ERROR'] = GetMessage('SL_IMPORT_ERROR_NO_ZIP_FILE') . '<br>'; $arReturn['STEP'] = 3; break; } break; case 3: $arReturn['COMPLETE'] = true; break; } } return $arReturn; }
$_SESSION['CRM_IMPORT_FILE_SEPARATOR'] = ','; } elseif ($_POST['IMPORT_FILE_SEPARATOR'] == 'tab') { $_SESSION['CRM_IMPORT_FILE_SEPARATOR'] = "\t"; } elseif ($_POST['IMPORT_FILE_SEPARATOR'] == 'space') { $_SESSION['CRM_IMPORT_FILE_SEPARATOR'] = ' '; } require_once $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/main/classes/general/csv_data.php'; $csvFile = new CCSVData(); $csvFile->LoadFile($_SESSION['CRM_IMPORT_FILE']); $csvFile->SetFieldsType('R'); $csvFile->SetFirstHeader(false); $csvFile->SetDelimiter($_SESSION['CRM_IMPORT_FILE_SEPARATOR']); $iRow = 1; $arHeader = array(); $arRows = array(); while ($arData = $csvFile->Fetch()) { if ($iRow == 1) { foreach ($arData as $key => $value) { if ($_SESSION['CRM_IMPORT_FILE_SKIP_EMPTY'] && empty($value)) { continue; } if ($_SESSION['CRM_IMPORT_FILE_FIRST_HEADER']) { $arHeader[$key] = empty($value) ? GetMessage('CRM_COLUMN_HEADER') . ' ' . ($key + 1) : trim($value); } else { $arHeader[$key] = GetMessage('CRM_COLUMN_HEADER') . ' ' . ($key + 1); } } if (!$_SESSION['CRM_IMPORT_FILE_FIRST_HEADER']) { foreach ($arHeader as $key => $value) { $arRows[$iRow][$key] = $arData[$key]; }