185 $step_length = (int)(
$arParams[
'STEP_LENGTH'] ?? 0);
187 if ($step_length <= 0)
190 define(
'ZIP_STEP_LENGTH', $step_length);
191 define(
'LOC_STEP_LENGTH', $step_length);
192 define(
'DLZIPFILE',
$arParams[
"DLZIPFILE"]);
195 $CSVFILE = (string)(
$arParams[
'CSVFILE'] ??
'');
202 $sTmpFilePath = CTempFile::GetDirectoryName(12,
'sale');
208 $arReturn[
'ERROR'] =
GetMessage(
'SL_IMPORT_ERROR_FILES');
212 if (
$STEP == 1 && $CSVFILE ==
'')
214 if ($LOADZIP ==
'Y')
$STEP = 2;
221 $arReturn[
'MESSAGE'] =
GetMessage(
'WSL_IMPORT_FILES_LOADING');
222 $arReturn[
'STEP'] = 1;
227 $time_limit = ini_get(
'max_execution_time');
228 if ($time_limit < LOC_STEP_LENGTH) set_time_limit(LOC_STEP_LENGTH + 5);
233 $file_url = $sTmpFilePath.$CSVFILE;
235 if (!file_exists($file_url))
237 $arReturn[
'ERROR'] =
GetMessage(
'SL_IMPORT_ERROR_NO_LOC_FILE');
243 $arSysLangs = Array();
245 while ($arLang = $db_lang->Fetch())
247 $arSysLangs[$arLang[
"LID"]] = $arLang[
"LID"];
250 $arLocations =
array();
254 if (!
is_set($_SESSION[
"LOC_POS"]))
266 array(
"ID",
"COUNTRY_ID",
"REGION_ID",
"CITY_ID"));
268 while ($arLoc = $dbLocations->Fetch())
270 $arLocations[$arLoc[
"ID"]] = $arLoc;
274 if (empty($arLocations))
279 include_once(
$_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/main/classes/general/csv_data.php");
284 $csvFile->LoadFile($file_url);
285 $csvFile->SetFieldsType(
"R");
286 $csvFile->SetFirstHeader(
false);
287 $csvFile->SetDelimiter(
",");
289 $arRes = $csvFile->Fetch();
298 if (!in_array($DefLang, $arSysLangs))
311 if (
is_set($_SESSION[
"LOC_POS"]))
313 $csvFile->SetPos($_SESSION[
"LOC_POS"]);
315 $CurCountryID = $_SESSION[
"CUR_COUNTRY_ID"];
316 $CurRegionID = $_SESSION[
"CUR_REGION_ID"];
317 $numCountries = $_SESSION[
"NUM_COUNTRIES"];
318 $numRegiones = $_SESSION[
"NUM_REGIONES"];
319 $numCities = $_SESSION[
"NUM_CITIES"];
320 $numLocations = $_SESSION[
"NUM_LOCATIONS"];
333 while (
$arRes = $csvFile->Fetch())
337 $arArrayTmp =
array();
338 foreach(
$arRes as $ind => $value)
340 if ($ind%2 && isset($arSysLangs[$value]))
342 $arArrayTmp[$value] =
array(
344 "NAME" =>
$arRes[$ind + 1]
347 if ($value == $DefLang)
349 $arArrayTmp[
"NAME"] =
$arRes[$ind + 1];
355 if (is_array($arArrayTmp) && $arArrayTmp[
"NAME"] <>
'')
360 $arRegionList = Array();
361 $CurCountryID =
null;
362 $arContList =
array();
369 "COUNTRY_NAME" => $arArrayTmp[
"NAME"],
373 if ($arContList = $db_contList->Fetch())
375 $LLL = intval($arContList[
"ID"]);
376 $CurCountryID = intval($arContList[
"COUNTRY_ID"]);
380 if (intval($CurCountryID) <= 0)
383 $CurCountryID = intval($CurCountryID);
387 if(intval($LLL) <= 0)
390 if (intval($LLL)>0) $numLocations++;
398 $arRegionList = Array();
405 "COUNTRY_ID" => $CurCountryID,
406 "REGION_NAME"=>$arArrayTmp[
"NAME"],
410 if ($arRegionList = $db_rengList->Fetch())
412 $LLL = $arRegionList[
"ID"];
413 $CurRegionID = intval($arRegionList[
"REGION_ID"]);
417 if (intval($CurRegionID) <= 0)
420 $CurRegionID = intval($CurRegionID);
421 if ($CurRegionID > 0)
424 if (intval($LLL) <= 0)
427 if (intval($LLL)>0) $numLocations++;
436 $arCityList = Array();
441 "COUNTRY_ID" => $CurCountryID,
442 "CITY_NAME" => $arArrayTmp[
"NAME"],
445 if(intval($CurRegionID) > 0)
452 if ($arCityList = $db_cityList->Fetch())
454 $LLL = $arCityList[
"ID"];
455 $city_id = intval($arCityList[
"CITY_ID"]);
462 $city_id = intval($city_id);
469 if (intval($LLL) <= 0)
473 "COUNTRY_ID" => $CurCountryID,
474 "REGION_ID" => $CurRegionID,
475 "CITY_ID" => $city_id
478 if (intval($LLL) > 0) $numLocations++;
489 if ($cur_time >= $finish_time)
491 $cur_step = $csvFile->GetPos();
492 $amount = $csvFile->iFileLength;
494 $_SESSION[
"LOC_POS"] = $cur_step;
495 $_SESSION[
"CUR_COUNTRY_ID"] = $CurCountryID;
496 $_SESSION[
"CUR_REGION_ID"] = $CurRegionID;
497 $_SESSION[
"NUM_COUNTRIES"] = $numCountries;
498 $_SESSION[
"NUM_REGIONES"] = $numRegiones;
499 $_SESSION[
"NUM_CITIES"] = $numCities;
500 $_SESSION[
"NUM_LOCATIONS"] = $numLocations;
506 $arReturn[
'STEP'] = 1;
508 $arReturn[
'POS'] = $cur_step;
517 unset($_SESSION[
"LOC_POS"]);
520 $strOK = str_replace(
'#NUMCOUNTRIES#', intval($numCountries),
$strOK);
521 $strOK = str_replace(
'#NUMREGIONES#', intval($numRegiones),
$strOK);
522 $strOK = str_replace(
'#NUMCITIES#', intval($numCities),
$strOK);
523 $strOK = str_replace(
'#NUMLOCATIONS#', intval($numLocations),
$strOK);
525 $arReturn[
'MESSAGE'] =
$strOK;
526 $arReturn[
'STEP'] = $LOADZIP ==
"Y" ? 2 : 3;
533 $time_limit = ini_get(
'max_execution_time');
534 if ($time_limit < ZIP_STEP_LENGTH) set_time_limit(ZIP_STEP_LENGTH + 5);
539 if ($LOADZIP ==
"Y" && file_exists($sTmpFilePath.DLZIPFILE))
543 array(
"LID" =>
'ru'),
546 array(
"ID",
"CITY_NAME_LANG",
"REGION_NAME_LANG"));
547 $arLocationMap =
array();
559 $DB->StartTransaction();
561 include_once(
$_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/main/classes/general/csv_data.php");
564 $csvFile->LoadFile($sTmpFilePath.DLZIPFILE);
565 $csvFile->SetFieldsType(
"R");
566 $csvFile->SetFirstHeader(
false);
567 $csvFile->SetDelimiter(
";");
569 if (
is_set($_SESSION,
'ZIP_POS'))
571 $numZIP = $_SESSION[
"NUM_ZIP"];
572 $csvFile->SetPos($_SESSION[
"ZIP_POS"]);
578 unset($_SESSION[
"NUM_ZIP"]);
585 while (
$arRes = $csvFile->Fetch())
592 if (array_key_exists($CITY, $arLocationMap))
595 $ID = $arLocationMap[$CITY][$REGION];
597 $ID = $arLocationMap[$CITY];
616 if ($cur_time >= $finish_time)
618 $cur_step = $csvFile->GetPos();
619 $amount = $csvFile->iFileLength;
621 $_SESSION[
"ZIP_POS"] = $cur_step;
622 $_SESSION[
"NUM_ZIP"] = $numZIP;
626 $arReturn[
'STEP'] = 2;
628 $arReturn[
'POS'] = $cur_step;
638 unset($_SESSION[
"ZIP_POS"]);
643 $strOK = str_replace(
'#NUMZIP#', intval($numZIP),
$strOK);
644 $strOK = str_replace(
'#NUMCITIES#', intval($numCity[
"CITY_CNT"]),
$strOK);
646 $arReturn[
'MESSAGE'] =
$strOK;
647 $arReturn[
'STEP'] = 3;
648 $arReturn[
'PB_REMOVE'] =
true;
654 $arReturn[
'ERROR'] =
GetMessage(
'SL_IMPORT_ERROR_NO_ZIP_FILE').
'<br>';
655 $arReturn[
'STEP'] = 3;
662 $arReturn[
'COMPLETE'] =
true;
static includeModule($moduleName)
static GetList($arOrder=array("SORT"=>"ASC", "COUNTRY_NAME_LANG"=>"ASC", "CITY_NAME_LANG"=>"ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)