1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
csv_new_run.php
См. документацию.
1<?php
2//<title>CSV Export (new)</title>
10
11use Bitrix\Main;
13
14IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/catalog/data_export.php');
15
17if ($MAX_EXECUTION_TIME <= 0)
19if (defined('BX_CAT_CRON') && BX_CAT_CRON == true)
20{
22 $firstStep = true;
23}
24if (defined("CATALOG_EXPORT_NO_STEP") && CATALOG_EXPORT_NO_STEP == true)
25{
27 $firstStep = true;
28}
29if ($MAX_EXECUTION_TIME == 0)
30 set_time_limit(0);
31if (!isset($firstStep))
32 $firstStep = true;
33
35$navParams = array('nTopCount' => $pageSize);
36
37$SETUP_VARS_LIST = 'IBLOCK_ID,SETUP_FILE_NAME,fields_type,delimiter_r,delimiter_other_r,first_line_names,field_needed,field_num,field_code,export_files,export_from_clouds,CML2_LINK_IS_XML,MAX_EXECUTION_TIME';
39
40global $USER;
43{
44 $bTmpUserCreated = true;
45 if (isset($USER))
46 $USER_TMP = $USER;
47 $USER = new CUser();
48}
49
50if (!function_exists('__CSVArrayMultiply'))
51{
52 function __CSVArrayMultiply($arTuple, $arTemp, &$csvFile, $currentFile): void
53 {
54 if (empty($arTuple))
55 {
57 $csvFile->SaveFile($_SERVER["DOCUMENT_ROOT"].$currentFile, $arTemp);
58 }
59 else
60 {
61 $head = array_shift($arTuple);
62 $arTemp[] = false;
63 if (is_array($head))
64 {
65 if (empty($head))
66 {
67 $arTemp[count($arTemp)-1] = "";
68 __CSVArrayMultiply($arTuple, $arTemp, $csvFile, $currentFile);
69 }
70 else
71 {
72 foreach ($head as &$value)
73 {
74 $arTemp[count($arTemp)-1] = $value;
75 __CSVArrayMultiply($arTuple, $arTemp, $csvFile, $currentFile);
76 }
77 if (isset($value))
78 unset($value);
79 }
80 }
81 else
82 {
83 $arTemp[count($arTemp)-1] = $head;
84 __CSVArrayMultiply($arTuple, $arTemp, $csvFile, $currentFile);
85 }
86 }
87 }
88}
89
90if (!function_exists('__CSVExportFile'))
91{
92 function __CSVExportFile($intFileID, $strExportPath, $strFilePath, $strExportFromClouds = 'Y'): string
93 {
94 if ('Y' != $strExportFromClouds)
95 $strExportFromClouds = 'N';
96
97 $arFile = CFile::GetFileArray($intFileID);
98 if ($arFile)
99 {
100 if ('N' == $strExportFromClouds && 0 < $arFile["HANDLER_ID"])
101 {
102 return serialize($arFile);
103 }
104 else
105 {
106 $arTempFile = CFile::MakeFileArray($intFileID);
107 if (isset($arTempFile["tmp_name"]) && $arTempFile["tmp_name"] != "")
108 {
109 $strFile = $arFile["SUBDIR"]."/".$arFile["FILE_NAME"];
110 $strNewFile = str_replace("//", "/", $strExportPath.$strFilePath.$strFile);
111 CheckDirPath($_SERVER['DOCUMENT_ROOT'].$strNewFile);
112
113 if (@copy($arTempFile["tmp_name"], $_SERVER['DOCUMENT_ROOT'].$strNewFile))
114 return $strFilePath.$strFile;
115 }
116 }
117 }
118 return '';
119 }
120}
121
122$strCatalogDefaultFolder = COption::GetOptionString("catalog", "export_default_path", CATALOG_DEFAULT_EXPORT_PATH);
123
124$NUM_CATALOG_LEVELS = (int)COption::GetOptionInt("catalog", "num_catalog_levels");
125if ($NUM_CATALOG_LEVELS <= 0)
127
130
131global
143
144if (!isset($arCatalogAvailProdFields))
154
167
169if ($IBLOCK_ID <= 0)
170{
171 $arRunErrors[] = GetMessage("CATI_NO_IBLOCK");
172}
173else
174{
175 $arIBlockres = CIBlock::GetList(array(), array("ID"=>$IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'));
176 if (!($arIBlock = $arIBlockres->Fetch()))
177 {
178 $arRunErrors[] = GetMessage("CATI_NO_IBLOCK");
179 }
180}
181
183$arSku = false;
185if (empty($arRunErrors))
186{
187 $rsCatalogs = CCatalog::GetList(
188 array(),
189 array('IBLOCK_ID' => $IBLOCK_ID),
190 false,
191 false,
192 array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID', 'SKU_PROPERTY_ID')
193 );
194 if ($arCatalog = $rsCatalogs->Fetch())
195 {
196 $boolCatalog = true;
197 $arCatalog['IBLOCK_ID'] = (int)$arCatalog['IBLOCK_ID'];
198 $arCatalog['PRODUCT_IBLOCK_ID'] = (int)$arCatalog['PRODUCT_IBLOCK_ID'];
199 $arCatalog['SKU_PROPERTY_ID'] = (int)$arCatalog['SKU_PROPERTY_ID'];
200 if ($arCatalog['PRODUCT_IBLOCK_ID'] > 0 && $arCatalog['SKU_PROPERTY_ID'] > 0)
201 {
203 $skuPropertyID = $arCatalog['SKU_PROPERTY_ID'];
204 }
205 }
206
207}
208
210if (empty($arSku))
211 $CML2_LINK_IS_XML = 'N';
212
213if (empty($arRunErrors))
214{
215 $currentFile = '';
216 $csvFile = new CCSVData();
217
218 if (!isset($fields_type) || ($fields_type != "F" && $fields_type != "R"))
219 {
220 $arRunErrors[] = GetMessage("CATI_NO_FORMAT");
221 }
222
223 $csvFile->SetFieldsType($fields_type);
224
225 $first_line_names = (isset($first_line_names) && $first_line_names == 'Y');
226 if (!$firstStep)
227 $first_line_names = false;
228 $csvFile->SetFirstHeader($first_line_names);
229
230 $delimiter_r_char = '';
231 if (isset($delimiter_r))
232 {
233 switch ($delimiter_r)
234 {
235 case "TAB":
236 $delimiter_r_char = "\t";
237 break;
238 case "ZPT":
239 $delimiter_r_char = ",";
240 break;
241 case "SPS":
242 $delimiter_r_char = " ";
243 break;
244 case "OTR":
245 $delimiter_r_char = (isset($delimiter_other_r)? mb_substr($delimiter_other_r, 0, 1) : '');
246 break;
247 case "TZP":
248 $delimiter_r_char = ";";
249 break;
250 }
251 }
252
253 if (mb_strlen($delimiter_r_char) != 1)
254 {
255 $arRunErrors[] = GetMessage("CATI_NO_DELIMITER");
256 }
257
258 if (empty($arRunErrors))
259 {
260 $csvFile->SetDelimiter($delimiter_r_char);
261 }
262
263 if (!isset($export_files) || $export_files != 'Y')
264 $export_files = 'N';
265 if (!isset($export_from_clouds) || $export_from_clouds != 'Y')
266 $export_from_clouds = 'N';
267
268 if (!isset($SETUP_FILE_NAME) || $SETUP_FILE_NAME == '')
269 {
270 $arRunErrors[] = GetMessage("CATI_NO_SAVE_FILE");
271 }
273 {
274 $arRunErrors[] = GetMessage("CES_ERROR_BAD_EXPORT_FILENAME");
275 }
276 else
277 {
279 if (mb_strtolower(mb_substr($SETUP_FILE_NAME, mb_strlen($SETUP_FILE_NAME) - 4)) != ".csv")
280 $SETUP_FILE_NAME .= ".csv";
281 if (0 !== mb_strpos($SETUP_FILE_NAME, $strCatalogDefaultFolder))
282 {
283 $arRunErrors[] = GetMessage('CES_ERROR_PATH_WITHOUT_DEFAUT');
284 }
285 else
286 {
287 CheckDirPath($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME);
288
289 $currentFile = $SETUP_FILE_NAME;
290
291 if ($firstStep)
292 {
293 if (!($fp = fopen($_SERVER["DOCUMENT_ROOT"].$currentFile, "wb")))
294 {
295 $arRunErrors[] = GetMessage("CATI_CANNOT_CREATE_FILE");
296 }
297 @fclose($fp);
298 }
299 else
300 {
301 if (!($fp = fopen($_SERVER["DOCUMENT_ROOT"].$currentFile, "ab")))
302 {
303 $arRunErrors[] = GetMessage("BX_CATALOG_EXPORT_CSV_ERR_CANNOT_OPEN_FILE_FOR_CONTINUE_EXPORT");
304 }
305 @fclose($fp);
306 }
307
308 if ($export_files == 'Y')
309 {
310 $strExportPath = GetDirPath($SETUP_FILE_NAME);
311 $strFilePath = str_replace($strExportPath, '', mb_substr($SETUP_FILE_NAME, 0, -4)).'_files/';
312 if ($firstStep)
313 {
314 if (!CheckDirPath($_SERVER['DOCUMENT_ROOT'].$strExportPath.$strFilePath))
315 {
317 'CATI_NO_RIGHTS_EXPORT_FILES_PATH',
318 ['#PATH#' => $strExportPath.$strFilePath]
319 );
320 $export_files = 'N';
321 }
322 }
323 }
324 }
325 }
326
327 $bFieldsPres = (!empty($field_needed) && is_array($field_needed) && in_array('Y', $field_needed));
328 if ($bFieldsPres && (empty($field_code) || !is_array($field_code)))
329 {
330 $bFieldsPres = false;
331 }
332 if (!$bFieldsPres)
333 {
334 $arRunErrors[] = GetMessage("CATI_NO_FIELDS");
335 }
336
337 if (empty($arRunErrors))
338 {
339 $intCount = 0; // count of all available fields, props, section fields, prices
340 $arSortFields = array(); // array for order
341 $selectArray = array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID"); // selected element fields
342 $bNeedGroups = false; // sections need?
343 $bNeedPrices = false; // prices need?
344 $bNeedProducts = false; // product properties need?
345 $bNeedProps = false; // element props need?
346 $arGroupProps = array(); // section fields array (no user props)
347 $allSectionFields = []; // section fields for select
348 $arElementProps = array(); // element props
349 $arCatalogGroups = array(); // prices
350 $bNeedCounts = false; // price ranges
351 $arCountFields = array(); // price ranges fields
352 $arValueCodes = array();
353 $arNeedFields = array(); // result order
354
355 // Prepare arrays for product loading
356 $strAvailProdFields = COption::GetOptionString("catalog", "allowed_product_fields", $defCatalogAvailProdFields);
357 $arAvailProdFields = explode(",", $strAvailProdFields);
358 $arAvailProdFields_names = array();
359 foreach ($arCatalogAvailProdFields as &$arOneCatalogAvailProdFields)
360 {
361 if (in_array($arOneCatalogAvailProdFields['value'],$arAvailProdFields))
362 {
363 $arAvailProdFields_names[$arOneCatalogAvailProdFields['value']] = array(
364 "field" => $arOneCatalogAvailProdFields["field"],
365 "important" => $arOneCatalogAvailProdFields["important"],
366 );
367 $mxSelKey = array_search($arOneCatalogAvailProdFields['value'], $field_code);
368 if (!(false === $mxSelKey || empty($field_needed[$mxSelKey]) || 'Y' != $field_needed[$mxSelKey]))
369 {
370 $arSortFields[$arOneCatalogAvailProdFields['value']] = array(
371 'CODE' => $arOneCatalogAvailProdFields['value'],
372 'ID' => $intCount,
373 'SORT' => (!empty($field_num[$mxSelKey]) && 0 < (int)$field_num[$mxSelKey] ? (int)$field_num[$mxSelKey] : ($intCount+1)*10),
374 );
375 $selectArray[] = $arOneCatalogAvailProdFields["field"];
376 }
377 $intCount++;
378 }
379 }
380 unset($arOneCatalogAvailProdFields);
381
382 $rsProps = CIBlockProperty::GetList(array("SORT"=>"ASC", "ID"=>"ASC"), array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y", 'CHECK_PERMISSIONS' => 'N'));
383 while ($arProp = $rsProps->Fetch())
384 {
385 $mxSelKey = array_search('IP_PROP'.$arProp['ID'], $field_code);
386 if (!(false === $mxSelKey || empty($field_needed[$mxSelKey]) || 'Y' != $field_needed[$mxSelKey]))
387 {
388 $arSortFields['IP_PROP'.$arProp['ID']] = array(
389 'CODE' => 'IP_PROP'.$arProp['ID'],
390 'ID' => $intCount,
391 'SORT' => (!empty($field_num[$mxSelKey]) && 0 < (int)$field_num[$mxSelKey] ? (int)$field_num[$mxSelKey] : ($intCount+1)*10),
392 );
393 $bNeedProps = true;
394 $arElementProps[] = $arProp['ID'];
395 }
396 $intCount++;
397 }
398 if ($bNeedProps)
399 $arElementProps = array_values(array_unique($arElementProps));
400
401 // Prepare arrays for groups loading
402 $strAvailGroupFields = COption::GetOptionString("catalog", "allowed_group_fields", $defCatalogAvailGroupFields);
403 $arAvailGroupFields = explode(",", $strAvailGroupFields);
404 $arAvailGroupFields_names = array();
405 foreach ($arCatalogAvailGroupFields as &$arOneCatalogAvailGroupFields)
406 {
407 if (in_array($arOneCatalogAvailGroupFields['value'],$arAvailGroupFields))
408 {
409 $arAvailGroupFields_names[$arOneCatalogAvailGroupFields['value']] = array(
410 "field" => $arOneCatalogAvailGroupFields["field"],
411 "important" => $arOneCatalogAvailGroupFields["important"],
412 );
413 }
414 }
415 unset($arOneCatalogAvailGroupFields);
416
417 if (!empty($arAvailGroupFields_names))
418 {
419 $arAvailGroupFieldsList = array_keys($arAvailGroupFields_names);
420 for ($i = 0; $i < $NUM_CATALOG_LEVELS; $i++)
421 {
422 foreach ($arAvailGroupFieldsList as &$strKey)
423 {
424 $mxSelKey = array_search($strKey.$i, $field_code);
425 if (!(false === $mxSelKey || empty($field_needed[$mxSelKey]) || 'Y' != $field_needed[$mxSelKey]))
426 {
427 $arSortFields[$strKey.$i] = array(
428 'CODE' => $strKey.$i,
429 'ID' => $intCount,
430 'SORT' => (!empty($field_num[$mxSelKey]) && 0 < (int)$field_num[$mxSelKey] ? (int)$field_num[$mxSelKey] : ($intCount+1)*10),
431 );
432 $bNeedGroups = true;
433 $arGroupProps[$i][] = $strKey;
434 $allSectionFields[] = $arAvailGroupFields_names[$strKey]['field'];
435 }
436 $intCount++;
437 }
438 if (isset($strKey))
439 unset($strKey);
440 if (!empty($arGroupProps[$i]))
441 $arGroupProps[$i] = array_values(array_unique($arGroupProps[$i]));
442 }
443 unset($arAvailGroupFieldsList);
444 }
445 if (!empty($allSectionFields))
446 {
447 $allSectionFields[] = 'ID';
448 $allSectionFields = array_values(array_unique($allSectionFields));
449 }
450
451 if ($boolCatalog)
452 {
453 // Prepare arrays for product loading (for catalog)
454 $strAvailPriceFields = COption::GetOptionString("catalog", "allowed_product_fields", $defCatalogAvailPriceFields);
455 $arAvailPriceFields = explode(",", $strAvailPriceFields);
456 $arAvailPriceFields_names = array();
457 foreach ($arCatalogAvailPriceFields as &$arOneCatalogAvailPriceFields)
458 {
459 if (in_array($arOneCatalogAvailPriceFields['value'],$arAvailPriceFields))
460 {
461 $iblockField = (isset($arOneCatalogAvailPriceFields["field_orig"])
462 ? $arOneCatalogAvailPriceFields["field_orig"]
463 : $arOneCatalogAvailPriceFields["field"]
464 );
465 $arAvailPriceFields_names[$arOneCatalogAvailPriceFields['value']] = array(
466 "field" => $arOneCatalogAvailPriceFields["field"],
467 'iblock_field' => 'CATALOG_'.$iblockField,
468 "important" => $arOneCatalogAvailPriceFields["important"]
469 );
470
471 $mxSelKey = array_search($arOneCatalogAvailPriceFields['value'], $field_code);
472 if (!(false === $mxSelKey || empty($field_needed[$mxSelKey]) || 'Y' != $field_needed[$mxSelKey]))
473 {
474 $arSortFields[$arOneCatalogAvailPriceFields['value']] = array(
475 'CODE' => $arOneCatalogAvailPriceFields['value'],
476 'ID' => $intCount,
477 'SORT' => (!empty($field_num[$mxSelKey]) && 0 < (int)$field_num[$mxSelKey] ? (int)$field_num[$mxSelKey] : ($intCount+1)*10),
478 );
479 $bNeedProducts = true;
480 $selectArray[] = 'CATALOG_'.$iblockField;
481 }
482 $intCount++;
483 }
484 }
485 unset($arOneCatalogAvailPriceFields);
486
487 // Prepare arrays for price loading
488 $strAvailCountFields = $defCatalogAvailQuantityFields;
489 $arAvailCountFields = explode(",", $strAvailCountFields);
490 $arAvailCountFields_names = array();
491 foreach ($arCatalogAvailQuantityFields as &$arOneCatalogAvailQuantityFields)
492 {
493 if (in_array($arOneCatalogAvailQuantityFields['value'], $arAvailCountFields))
494 {
495 $arAvailCountFields_names[$arOneCatalogAvailQuantityFields['value']] = array(
496 "field" => $arOneCatalogAvailQuantityFields["field"],
497 "important" => $arOneCatalogAvailQuantityFields["important"]
498 );
499 $mxSelKey = array_search($arOneCatalogAvailQuantityFields['value'], $field_code);
500 if (!(false === $mxSelKey || empty($field_needed[$mxSelKey]) || 'Y' != $field_needed[$mxSelKey]))
501 {
502 $arSortFields[$arOneCatalogAvailQuantityFields['value']] = array(
503 'CODE' => $arOneCatalogAvailQuantityFields['value'],
504 'ID' => $intCount,
505 'SORT' => (!empty($field_num[$mxSelKey]) && 0 < (int)$field_num[$mxSelKey] ? (int)$field_num[$mxSelKey] : ($intCount+1)*10),
506 );
507 $bNeedCounts = true;
508 $arCountFields[] = $arOneCatalogAvailQuantityFields['value'];
509 }
510 $intCount++;
511 }
512 }
513 unset($arOneCatalogAvailQuantityFields);
514
515 $strAvailValueFields = COption::GetOptionString("catalog", "allowed_price_fields", $defCatalogAvailValueFields);
516 $arAvailValueFields = explode(",", $strAvailValueFields);
517 $arAvailValueFields_names = array();
518 foreach ($arCatalogAvailValueFields as &$arOneCatalogAvailValueFields)
519 {
520 if (in_array($arOneCatalogAvailValueFields['value'],$arAvailValueFields))
521 {
522 $arValueCodes[] = $arOneCatalogAvailValueFields['value'].'_';
523 $arAvailValueFields_names[$arOneCatalogAvailValueFields['value']] = array(
524 "field" => $arOneCatalogAvailValueFields["field"],
525 "important" => $arOneCatalogAvailValueFields["important"]
526 );
527 }
528 }
529 unset($arOneCatalogAvailValueFields);
530 if (!empty($arValueCodes))
531 $arValueCodes = array_values(array_unique($arValueCodes));
532
533 if (!empty($arAvailValueFields_names))
534 {
535 $arAvailValueFieldsList = array_keys($arAvailValueFields_names);
536 $rsPriceTypes = CCatalogGroup::GetList(array("SORT" => "ASC"), array());
537 while ($arPriceType = $rsPriceTypes->Fetch())
538 {
539 foreach ($arAvailValueFieldsList as &$strKey)
540 {
541 $mxSelKey = array_search($strKey.'_'.$arPriceType['ID'], $field_code);
542 if (!(false === $mxSelKey || empty($field_needed[$mxSelKey]) || 'Y' != $field_needed[$mxSelKey]))
543 {
544 $arSortFields[$strKey.'_'.$arPriceType['ID']] = array(
545 'CODE' => $strKey.'_'.$arPriceType['ID'],
546 'ID' => $intCount,
547 'SORT' => (!empty($field_num[$mxSelKey]) && 0 < (int)$field_num[$mxSelKey] ? (int)$field_num[$mxSelKey] : ($intCount+1)*10),
548 );
549 $bNeedPrices = true;
550 $arCatalogGroups[] = intval($arPriceType['ID']);
551 }
552 $intCount++;
553 }
554 if (isset($strKey))
555 unset($strKey);
556 }
557 unset($arAvailValueFieldsList);
558 if ($bNeedPrices)
559 {
560 $arCatalogGroups = array_values(array_unique($arCatalogGroups));
561 sort($arCatalogGroups);
562 }
563 }
564 if (!$bNeedPrices)
565 {
566 $bNeedCounts = false;
567 $arCountFields = array();
568 }
569 }
570 Main\Type\Collection::sortByColumn($arSortFields, 'SORT', '', null, true);
571
572 $arCacheSections = array();
573 $arCacheChains = array();
574 $arCacheResultSections = array();
575
576 $arNeedFields = array_keys($arSortFields);
577
578 if ($first_line_names)
579 {
580 $csvFile->SaveFile($_SERVER["DOCUMENT_ROOT"].$currentFile, $arNeedFields);
581 $first_line_names = false;
582 }
583
584 $arUserTypeFormat = false;
585
586 $filter = array('IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
587
588 do
589 {
590 if (isset($CUR_ELEMENT_ID) && $CUR_ELEMENT_ID > 0)
591 $filter['>ID'] = $CUR_ELEMENT_ID;
592
593 $existItems = false;
594
595 $dbIBlockElement = CIBlockElement::GetList(
596 array('ID' => 'ASC'),
597 $filter,
598 false,
599 false,
600 $selectArray
601 );
602 while ($obIBlockElement = $dbIBlockElement->GetNextElement())
603 {
604 $arIBlockElement = $obIBlockElement->GetFields();
605
606 $finalExport = false; // items exist
607 $existItems = true;
608
609 $id = (int)$arIBlockElement['ID'];
610 $CUR_ELEMENT_ID = $id;
611
612 if (isset($arIBlockElement["PREVIEW_PICTURE"]))
613 {
614 if ('Y' == $export_files)
615 {
616 $arIBlockElement["~PREVIEW_PICTURE"] = __CSVExportFile($arIBlockElement['PREVIEW_PICTURE'], $strExportPath, $strFilePath);
617 }
618 else
619 {
620 $arIBlockElement["PREVIEW_PICTURE"] = CFile::GetFileArray($arIBlockElement["PREVIEW_PICTURE"]);
621 if ($arIBlockElement["PREVIEW_PICTURE"])
622 $arIBlockElement["~PREVIEW_PICTURE"] = $arIBlockElement["PREVIEW_PICTURE"]["SRC"];
623 }
624 }
625 if (isset($arIBlockElement["DETAIL_PICTURE"]))
626 {
627 if ('Y' == $export_files)
628 {
629 $arIBlockElement["~DETAIL_PICTURE"] = __CSVExportFile($arIBlockElement['DETAIL_PICTURE'], $strExportPath, $strFilePath);
630 }
631 else
632 {
633 $arIBlockElement["DETAIL_PICTURE"] = CFile::GetFileArray($arIBlockElement["DETAIL_PICTURE"]);
634 if ($arIBlockElement["DETAIL_PICTURE"])
635 $arIBlockElement["~DETAIL_PICTURE"] = $arIBlockElement["DETAIL_PICTURE"]["SRC"];
636 }
637 }
638 $arProperties = ($bNeedProps ? $obIBlockElement->GetProperties() : array());
639
640 if ($arUserTypeFormat === false)
641 {
643 foreach ($arProperties as $prop_id => $arProperty)
644 {
645 if (in_array($arProperty["ID"], $arElementProps))
646 {
647 $arUserTypeFormat[$arProperty["ID"]] = false;
648 $arProperty["USER_TYPE"] = (string)$arProperty["USER_TYPE"];
649 if ($arProperty["USER_TYPE"] != '')
650 {
651 $arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]);
652 if (isset($arUserType["GetPublicViewHTML"]))
653 $arUserTypeFormat[$arProperty["ID"]] = $arUserType["GetPublicViewHTML"];
654 }
655 }
656 }
657 }
658
659 $arPropsValues = array();
660 foreach ($arProperties as $prop_id => $arProperty)
661 {
662 if (in_array($arProperty["ID"], $arElementProps))
663 {
664 if ($arUserTypeFormat[$arProperty["ID"]])
665 {
666 $exportMode = ($CML2_LINK_IS_XML == 'Y' && $arProperty['ID'] == $skuPropertyID ? 'EXTERNAL_ID' : 'CSV_EXPORT');
667 if ($arProperty['MULTIPLE'] == 'Y' && is_array($arProperty["~VALUE"]))
668 {
669 $arValues = array();
670 foreach ($arProperty["~VALUE"] as $value)
671 $arValues[] = call_user_func_array($arUserTypeFormat[$arProperty["ID"]],
672 array(
673 $arProperty,
674 array("VALUE" => $value),
675 array("MODE" => $exportMode)
676 ));
677 }
678 else
679 {
680 $arValues = call_user_func_array($arUserTypeFormat[$arProperty["ID"]],
681 array(
682 $arProperty,
683 array("VALUE" => $arProperty["~VALUE"]),
684 array("MODE" => $exportMode),
685 ));
686 }
687 }
688 elseif ($arProperty["PROPERTY_TYPE"] == "F")
689 {
690 if (is_array($arProperty["~VALUE"]))
691 {
692 $arValues = array();
693 foreach ($arProperty["~VALUE"] as $file_id)
694 {
695 if ('Y' == $export_files)
696 {
697 $arValues[] = __CSVExportFile($file_id, $strExportPath, $strFilePath);
698 }
699 else
700 {
701 $file = CFile::GetFileArray($file_id);
702 if ($file)
703 $arValues[] = $file["SRC"];
704 }
705 }
706 }
707 elseif ($arProperty["~VALUE"] > 0)
708 {
709 if ('Y' == $export_files)
710 {
711 $arValues = __CSVExportFile($arProperty["~VALUE"], $strExportPath, $strFilePath);
712 }
713 else
714 {
715 $file = CFile::GetFileArray($arProperty["~VALUE"]);
716 if ($file)
717 $arValues = $file["SRC"];
718 else
719 $arValues = "";
720 }
721 }
722 else
723 {
724 $arValues = "";
725 }
726 }
727 else
728 {
729 $arValues = $arProperty["~VALUE"];
730 }
731 $arPropsValues[$arProperty["ID"]] = $arValues;
732 }
733 }
734
735 $arResSections = array();
736 if ($bNeedGroups)
737 {
738 $i = 0;
739 $rsSections = CIBlockElement::GetElementGroups($arIBlockElement["ID"], false, array('ID', 'ADDITIONAL_PROPERTY_ID'));
740 while ($arSection = $rsSections->Fetch())
741 {
742 if (0 < intval($arSection['ADDITIONAL_PROPERTY_ID']))
743 continue;
744 if (!isset($arCacheChains[$arSection['ID']]))
745 {
746 $arPath = array();
747 $j = 0;
748 $rsPath = CIBlockSection::GetNavChain(
750 $arSection["ID"],
751 $allSectionFields,
752 true
753 );
754 foreach ($rsPath as $arPathSection)
755 {
756 if (!empty($arGroupProps[$j]))
757 {
758 foreach ($arGroupProps[$j] as &$key)
759 {
760 $field = $arAvailGroupFields_names[$key]['field'];
761 if ('IC_PICTURE' == $key || 'IC_DETAIL_PICTURE' == $key)
762 {
763 if ('Y' == $export_files)
764 {
765 $arPathSection[$field] = __CSVExportFile($arPathSection[$field], $strExportPath, $strFilePath);
766 }
767 else
768 {
769 $arPathSection[$field] = CFile::GetFileArray($arPathSection[$field]);
770 if ($arPathSection[$field])
771 {
772 $arPathSection[$field] = $arPathSection[$field]["SRC"];
773 }
774 else
775 {
776 $arPathSection[$field] = '';
777 }
778 }
779 }
780 $arPath['~'.$key.$j] = $arPathSection[$field];
781 }
782 if (isset($key))
783 unset($key);
784 $arPathSection['IBLOCK_SECTION_ID'] = intval($arPathSection['IBLOCK_SECTION_ID']);
785 $arCacheChains[$arPathSection['ID']] = $arPathSection['IBLOCK_SECTION_ID'];
786 $arCacheSections[$arPathSection['ID']] = $arPath;
787 }
788 $j++;
789 }
790 unset($arPathSection, $rsPath);
791 }
792
793 $arPath = array();
794 if (!isset($arCacheResultSections[$arSection['ID']]))
795 {
796 $intCurSect = $arSection['ID'];
797 while (isset($arCacheChains[$intCurSect]))
798 {
799 $arPath = array_merge($arPath, $arCacheSections[$intCurSect]);
800 $intCurSect = $arCacheChains[$intCurSect];
801 }
802 $arCacheResultSections[$arSection['ID']] = $arPath;
803 }
804 else
805 {
806 $arPath = $arCacheResultSections[$arSection['ID']];
807 }
808 $arResSections[$i] = $arPath;
809 $i++;
810 }
811 if (empty($arResSections))
812 $arResSections[] = array();
813 }
814 else
815 {
816 $arResSections[] = array();
817 }
818
819 $arResPrices = array();
820 if ($boolCatalog && $bNeedPrices)
821 {
822 $arResPricesMap = array();
823 $mapIndex = -1;
824
825 $dbProductPrice = Catalog\PriceTable::getList(array(
826 'select' => array('ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO', 'EXTRA_ID'),
827 'filter' => array('=PRODUCT_ID' => $arIBlockElement["ID"], '@CATALOG_GROUP_ID' => $arCatalogGroups)
828 ));
829 while ($arProductPrice = $dbProductPrice->fetch())
830 {
831 if (!isset($arResPricesMap[$arProductPrice["QUANTITY_FROM"]."-".$arProductPrice["QUANTITY_TO"]]))
832 {
833 $mapIndex++;
834 $arResPricesMap[$arProductPrice["QUANTITY_FROM"]."-".$arProductPrice["QUANTITY_TO"]] = $mapIndex;
835 }
836 $intDiap = $arResPricesMap[$arProductPrice["QUANTITY_FROM"]."-".$arProductPrice["QUANTITY_TO"]];
837 foreach ($arAvailValueFields_names as $key => $value)
838 {
839 $arResPrices[$intDiap][$value['field'].'_'.$arProductPrice["CATALOG_GROUP_ID"]] = $arProductPrice[$value['field']];
840 }
841 $arResPrices[$intDiap]['QUANTITY_FROM'] = $arProductPrice["QUANTITY_FROM"];
842 $arResPrices[$intDiap]['QUANTITY_TO'] = $arProductPrice["QUANTITY_TO"];
843 }
844 if (empty($arResPrices))
845 $arResPrices[] = array();
846 }
847 else
848 {
849 $arResPrices[] = array();
850 }
851
852 $arResProducts = array();
853 if ($boolCatalog && $bNeedProducts)
854 {
855 foreach ($arAvailPriceFields_names as $key => $value)
856 {
857 $arResProducts[$value['field']] = $arIBlockElement[$value['iblock_field']];
858 }
859 }
860
861 foreach ($arResSections as $arPath)
862 {
863 foreach ($arResPrices as $arPrice)
864 {
865 $arTuple = array();
866 foreach ($arNeedFields as $field_name)
867 {
868 if (strncmp($field_name, "IE_", 3) == 0)
869 $arTuple[] = $arIBlockElement["~".mb_substr($field_name, 3)];
870 elseif (strncmp($field_name, "IP_PROP", 7) == 0)
871 $arTuple[] = $arPropsValues[intval(mb_substr($field_name, 7))];
872 elseif (strncmp($field_name, "IC_", 3) == 0)
873 {
874 $strKey = $field_name;
875 $arTuple[] = (isset($arPath['~'.$strKey]) ? $arPath['~'.$strKey] : '');
876 }
877 elseif (strncmp($field_name, 'CV_', 3) == 0)
878 {
879 $strKey = mb_substr($field_name, 3);
880 $arTuple[] = (isset($arPrice[$strKey]) ? $arPrice[$strKey] : '');
881 }
882 elseif (strncmp($field_name, 'CP_', 3) == 0)
883 {
884 $arTuple[] = (!empty($arResProducts) ? $arResProducts[mb_substr($field_name, 3)] : '');
885 }
886 }
887 __CSVArrayMultiply($arTuple, [], $csvFile, $currentFile);
888 }
889 }
890
891 if ($MAX_EXECUTION_TIME > 0 && (microtime(true) - START_EXEC_TIME) >= $MAX_EXECUTION_TIME)
892 break;
893 }
894 unset($arIBlockElement, $dbIBlockElement);
895 }
896 while ($MAX_EXECUTION_TIME == 0 && $existItems);
897 }
898
899 if (empty($arRunErrors))
900 {
901 $csvFile->CloseFile();
902 unset($csvFile);
903 }
904}
905
906if (!empty($arRunErrors))
907 $strExportErrorMessage = implode('<br />',$arRunErrors);
908
910{
911 if (isset($USER_TMP))
912 {
913 $USER = $USER_TMP;
914 unset($USER_TMP);
915 }
916}
const BX_CATALOG_FILENAME_REG
Определения include.php:51
const CATALOG_DEFAULT_EXPORT_PATH
Определения include.php:14
static sortByColumn(array &$array, $columns, $callbacks='', $defaultValueIfNotSetValue=null, $preserveKeys=false)
Определения collection.php:24
static IsUserExists()
Определения catalog.php:1812
Определения csv_data.php:10
const FIELDS_PRICE
Определения csv_settings.php:9
static getDefaultSettings($type, $extFormat=false)
Определения csv_settings.php:335
const FIELDS_CURRENCY
Определения csv_settings.php:12
static getSettingsFields($type, $extFormat=false)
Определения csv_settings.php:14
const FIELDS_PRICE_EXT
Определения csv_settings.php:10
const FIELDS_ELEMENT
Определения csv_settings.php:7
const FIELDS_CATALOG
Определения csv_settings.php:8
const FIELDS_SECTION
Определения csv_settings.php:11
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения cataloggroup.php:218
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения catalog.php:15
static GetFileArray($fileId, $uploadDir=false)
Определения file.php:1207
static MakeFileArray($path, $mimetype=false, $skipInternal=false, $external_id="")
Определения file.php:2005
$arValues
Определения component_props.php:25
else $SETUP_FILE_NAME
Определения ebay_mip_run.php:56
$arPath
Определения file_edit.php:72
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54
const BX_CAT_CRON
Определения cron_frame.php:16
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $arCatalogAvailPriceFields
Определения cron_frame.php:84
global $defCatalogAvailValueFields
Определения cron_frame.php:97
global $arCatalogAvailQuantityFields
Определения cron_frame.php:88
if(! $ar_profile) $strFile
Определения cron_frame.php:59
global $defCatalogAvailProdFields
Определения cron_frame.php:93
global $defCatalogAvailQuantityFields
Определения cron_frame.php:99
global $arCatalogAvailProdFields
Определения cron_frame.php:82
global $defCatalogAvailCurrencies
Определения cron_frame.php:103
if($ar_profile["DEFAULT_PROFILE"] !='Y') $firstStep
Определения cron_frame.php:80
global $arCatalogAvailGroupFields
Определения cron_frame.php:90
global $arCatalogAvailValueFields
Определения cron_frame.php:86
global $defCatalogAvailPriceFields
Определения cron_frame.php:95
global $defCatalogAvailGroupFields
Определения cron_frame.php:101
$arSku
Определения csv_new_run.php:183
$IBLOCK_ID
Определения csv_new_run.php:168
if(!($arIBlock=$arIBlockres->Fetch())) $boolCatalog
Определения csv_new_run.php:182
$SETUP_VARS_LIST
Определения csv_new_run.php:37
$arRunErrors
Определения csv_new_run.php:129
global $USER
Определения csv_new_run.php:40
$strExportErrorMessage
Определения csv_new_run.php:128
if(empty($arRunErrors)) $CML2_LINK_IS_XML
Определения csv_new_run.php:209
$NUM_CATALOG_LEVELS
Определения csv_new_run.php:124
$bTmpUserCreated
Определения csv_new_run.php:41
$skuPropertyID
Определения csv_new_run.php:184
$pageSize
Определения csv_new_run.php:34
$navParams
Определения csv_new_run.php:35
$MAX_EXECUTION_TIME
Определения csv_new_run.php:16
if(!CCatalog::IsUserExists()) if(!function_exists( '__CSVArrayMultiply')) if(!function_exists('__CSVExportFile')) $strCatalogDefaultFolder
Определения csv_new_run.php:122
$INTERNAL_VARS_LIST
Определения csv_new_run.php:38
const START_EXEC_TIME
Определения start.php:12
CheckDirPath($path)
Определения tools.php:2707
GetDirPath($sPath)
Определения tools.php:3245
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$value
Определения Param.php:39
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$rsProps
Определения yandex_run.php:584
$arCatalog
Определения yandex_run.php:674
if(empty($arRunErrors)) $arUserTypeFormat
Определения yandex_run.php:788
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644