function GetPos() { if (empty($this->__pos)) { return parent::GetPos(); } else { return $this->__pos[count($this->__pos) - 1]; } }
break; } } } // delete 'not-in-file' element prices if ($bAllLinesLoaded && $bIBlockIsCatalog && 'Y' == $bUpdatePrice && $outFileAction == "D") { $res = CPrice::GetList(array(), array("ELEMENT_IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid), false, false, array("ID")); while ($arr = $res->Fetch()) { CPrice::Delete($arr["ID"]); if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) { break; } } } if (!$bAllLinesLoaded) { $bAllDataLoaded = false; $INTERNAL_VARS_LIST = "tmpid,line_num,correct_lines,error_lines,killed_lines,arIBlockProperty,bThereIsGroups,arProductGroups,arIBlockPropertyValue,bDeactivationStarted,bUpdatePrice"; $SETUP_VARS_LIST = "IBLOCK_ID,URL_DATA_FILE,fields_type,first_names_r,delimiter_r,delimiter_other_r,first_names_f,metki_f,PATH2IMAGE_FILES,outFileAction,inFileAction,max_execution_time,IMAGE_RESIZE,USE_TRANSLIT,TRANSLIT_LANG,CLEAR_EMPTY_PRICE,CML2_LINK_IS_XML"; for ($i = 0; $i < $NUM_FIELDS; $i++) { $SETUP_VARS_LIST .= ",field_" . $i; } $CUR_FILE_POS = $csvFile->GetPos(); } } if ($bTmpUserCreated) { unset($USER); if (isset($USER_TMP)) { $USER = $USER_TMP; unset($USER_TMP); } }
} } unset($arLeads[$leadlID]); } } else { $leadlID = uniqid(); } // For compatibility only. Try sync product PRICE if (isset($arLead['PRODUCT_ROWS']) && count($arLead['PRODUCT_ROWS']) == 1 && !isset($arLead['PRODUCT_ROWS'][0]['PRICE']) && isset($arLead['OPPORTUNITY'])) { $arLead['PRODUCT_ROWS'][0]['PRICE'] = doubleval($arLead['OPPORTUNITY']); } if ($canBreak && count($arLeads) >= 20) { break; } $arLeads[$leadlID] = $arLead; $filePos = $csvFile->GetPos(); } $csvFile->CloseFile(); foreach ($arLeads as $arLead) { CCrmFieldMulti::PrepareFields($arLead); $isDuplicate = false; if ($dupCtrlType !== 'NO_CONTROL' && ($enableDupCtrlByPerson || $enableDupCtrlByOrganization || $enableDupCtrlByPhone || $enableDupCtrlByEmail)) { $fieldNames = array(); if ($enableDupCtrlByPerson) { $fieldNames[] = 'NAME'; $fieldNames[] = 'SECOND_NAME'; $fieldNames[] = 'LAST_NAME'; } if ($enableDupCtrlByOrganization) { $fieldNames[] = 'COMPANY_TITLE'; }
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; $this->repeatCurrentService = true; } } } $DB->Commit();
$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 ($arRes[$ind] == $lang) { $arArrayTmp["NAME"] = $arRes[$ind + 1]; }
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; }
} $dbLocation = CSaleLocation::GetList(array("ID" => "ASC"), array("LID" => $lang)); if ($arLocation = $dbLocation->Fetch()) { do { $arLocationMap[ToUpper($arLocation["CITY_NAME"])] = $arLocation["ID"]; } while ($arLocation = $dbLocation->Fetch()); $DB->StartTransaction(); include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php"; $csvFile = new CCSVData(); $csvFile->LoadFile(dirname(__FILE__) . "/data/" . $lang . "/zip.csv"); $csvFile->SetPos(IntVal($_SESSION["ZIP_POST"])); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); $csvFile->SetDelimiter(";"); $i = 0; while ($arRes = $csvFile->Fetch()) { $i++; if ($i >= 10000) { $_SESSION["ZIP_POST"] = $csvFile->GetPos(); break; } $CITY = ToUpper($arRes[1]); if (array_key_exists($CITY, $arLocationMap)) { $ID = $arLocationMap[$CITY]; CSaleLocation::AddLocationZIP($ID, $arRes[2]); } $_SESSION["ZIP_POST"] = $csvFile->GetPos(); } $_SESSION["ZIP_POST"] = $csvFile->GetPos(); $DB->Commit(); }
if (!$CCrmCompany->Add($arCompany)) { $arResult['error']++; $arResult['error_data'][] = array('message' => $arCompany['RESULT_MESSAGE'], 'data' => $arData); __CrmImportWriteDataToFile($errataFilePath, isset($_SESSION['CRM_IMPORT_FILE_HEADERS']) ? $_SESSION['CRM_IMPORT_FILE_HEADERS'] : null, $arData); } else { if (!empty($arCompany)) { $arResult['import']++; } } } $processedQty++; if ($processedQty == 20) { break; } } $_SESSION['CRM_IMPORT_FILE_POS'] = $csvFile->GetPos(); $_SESSION['CRM_IMPORT_FILE_FIRST_HEADER'] = false; $csvFile->CloseFile(); if ($arResult['error'] > 0) { $arResult['errata_url'] = SITE_DIR . 'bitrix/components/bitrix/crm.company.import/show_file.php?name=errata'; } if ($enableDupFile && $arResult['duplicate'] > 0) { $arResult['duplicate_url'] = SITE_DIR . 'bitrix/components/bitrix/crm.company.import/show_file.php?name=duplicate'; } Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo CUtil::PhpToJsObject($arResult); die; } } $strError = ''; $arResult['STEP'] = isset($_POST['step']) ? intval($_POST['step']) : 1;