1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblocksection.php
См. документацию.
1<?php
2
6
8
10{
11 public string $LAST_ERROR = '';
12 protected static $arSectionCodeCache = array();
13 protected static $arSectionPathCache = array();
14 protected static $arSectionNavChainCache = array();
15
16 protected ?array $iblock;
17 protected ?string $iblockLanguage;
18
19 protected string $currentDateTimeFunction;
20
21 public function __construct()
22 {
23 $this->iblock = null;
24 $this->iblockLanguage = null;
25
27 $helper = $connection->getSqlHelper();
28 $this->currentDateTimeFunction = $helper->getCurrentDateTimeFunction();
29 unset($helper, $connection);
30 }
31
32 public function setIblock(?int $iblockId): void
33 {
34 $iblock = null;
35 $language = null;
36 if ($iblockId !== null)
37 {
38 $iblock = CIBlock::GetArrayByID($iblockId);
39 if (!is_array($iblock))
40 {
41 $iblock = null;
42 }
43 else
44 {
45 $iblock['ID'] = (int)$iblock['ID'];
46 $language = static::getIblockLanguage($iblock['ID']);
47 }
48 }
49 $this->iblock = $iblock;
50 $this->iblockLanguage = $language;
51 }
52
53 public static function GetFilter($arFilter=Array())
54 {
55 global $DB;
56 $arIBlockFilter = Array();
57 $arSqlSearch = Array();
58 $bSite = false;
59 foreach($arFilter as $key => $val)
60 {
61 $res = CIBlock::MkOperationFilter($key);
62 $key = $res["FIELD"];
63 $cOperationType = $res["OPERATION"];
64
65 $key = mb_strtoupper($key);
66 switch($key)
67 {
68 case "ACTIVE":
69 case "GLOBAL_ACTIVE":
70 $arSqlSearch[] = CIBlock::FilterCreate("BS.".$key, $val, "string_equal", $cOperationType);
71 break;
72 case "IBLOCK_ACTIVE":
73 $arIBlockFilter[] = CIBlock::FilterCreate("B.ACTIVE", $val, "string_equal", $cOperationType);
74 break;
75 case "LID":
76 case "SITE_ID":
77 $str = CIBlock::FilterCreate("BS.SITE_ID", $val, "string_equal", $cOperationType);
78 if($str <> '')
79 {
80 $arIBlockFilter[] = $str;
81 $bSite = true;
82 }
83 break;
84 case "IBLOCK_NAME":
85 $arIBlockFilter[] = CIBlock::FilterCreate("B.NAME", $val, "string", $cOperationType);
86 break;
87 case "IBLOCK_EXTERNAL_ID":
88 case "IBLOCK_XML_ID":
89 $arIBlockFilter[] = CIBlock::FilterCreate("B.XML_ID", $val, "string", $cOperationType);
90 break;
91 case "IBLOCK_TYPE":
92 $arIBlockFilter[] = CIBlock::FilterCreate("B.IBLOCK_TYPE_ID", $val, "string", $cOperationType);
93 break;
94 case "TIMESTAMP_X":
95 case "DATE_CREATE":
96 $arSqlSearch[] = CIBlock::FilterCreate("BS.".$key, $val, "date", $cOperationType);
97 break;
98 case "IBLOCK_CODE":
99 $arIBlockFilter[] = CIBlock::FilterCreate("B.CODE", $val, "string", $cOperationType);
100 break;
101 case "IBLOCK_ID":
102 $arSqlSearch[] = CIBlock::FilterCreate("BS.".$key, $val, "number", $cOperationType);
103 $arIBlockFilter[] = CIBlock::FilterCreate("B.ID", $val, "number", $cOperationType);
104 break;
105 case "NAME":
106 case "XML_ID":
107 case "TMP_ID":
108 case "CODE":
109 $arSqlSearch[] = CIBlock::FilterCreate("BS.".$key, $val, "string", $cOperationType);
110 break;
111 case "EXTERNAL_ID":
112 $arSqlSearch[] = CIBlock::FilterCreate("BS.XML_ID", $val, "string", $cOperationType);
113 break;
114 case "ID":
115 case "DEPTH_LEVEL":
116 case "MODIFIED_BY":
117 case "CREATED_BY":
118 case "SOCNET_GROUP_ID":
119 case "PICTURE":
120 case "DETAIL_PICTURE":
121 $arSqlSearch[] = CIBlock::FilterCreate("BS.".$key, $val, "number", $cOperationType);
122 break;
123 case "SECTION_ID":
124 if(!is_array($val) && (int)$val<=0)
125 $arSqlSearch[] = CIBlock::FilterCreate("BS.IBLOCK_SECTION_ID", "", "number", $cOperationType, false);
126 else
127 $arSqlSearch[] = CIBlock::FilterCreate("BS.IBLOCK_SECTION_ID", $val, "number", $cOperationType);
128 break;
129 case "RIGHT_MARGIN":
130 $arSqlSearch[] = "BS.RIGHT_MARGIN ".($cOperationType=="N"?">":"<=").(int)$val;
131 break;
132 case "LEFT_MARGIN":
133 $arSqlSearch[] = "BS.LEFT_MARGIN ".($cOperationType=="N"?"<":">=").(int)$val;
134 break;
135 case "LEFT_BORDER":
136 $arSqlSearch[] = CIBlock::FilterCreate("BS.LEFT_MARGIN", $val, "number", $cOperationType);
137 break;
138 case "RIGHT_BORDER":
139 $arSqlSearch[] = CIBlock::FilterCreate("BS.RIGHT_MARGIN", $val, "number", $cOperationType);
140 break;
141 case "HAS_ELEMENT":
142 $arSqlSearch[] = "EXISTS (
143 SELECT BS1.ID
144 FROM b_iblock_section BS1
145 INNER JOIN b_iblock_section_element BSE1 ON BSE1.IBLOCK_SECTION_ID = BS1.ID
146 AND BSE1.ADDITIONAL_PROPERTY_ID IS NULL
147 INNER JOIN b_iblock_element BE1 ON BE1.ID = BSE1.IBLOCK_ELEMENT_ID
148 WHERE BE1.ID = ".intval($val)."
149 AND BS1.LEFT_MARGIN >= BS.LEFT_MARGIN
150 AND BS1.RIGHT_MARGIN <= BS.RIGHT_MARGIN
151 )";
152 break;
153 }
154 }
155
156 static $IBlockFilter_cache = array();
157 if($bSite)
158 {
159 if(is_array($arIBlockFilter) && count($arIBlockFilter)>0)
160 {
161 $sIBlockFilter = "";
162 foreach($arIBlockFilter as $val)
163 if($val <> '')
164 $sIBlockFilter .= " AND ".$val;
165
166 if(!array_key_exists($sIBlockFilter, $IBlockFilter_cache))
167 {
168 $strSql =
169 "SELECT DISTINCT B.ID ".
170 "FROM b_iblock B, b_iblock_site BS ".
171 "WHERE B.ID = BS.IBLOCK_ID ".
172 $sIBlockFilter;
173
174 $arIBLOCKFilter = array();
175 $dbRes = $DB->Query($strSql);
176 while($arRes = $dbRes->Fetch())
177 $arIBLOCKFilter[] = $arRes["ID"];
178 $IBlockFilter_cache[$sIBlockFilter] = $arIBLOCKFilter;
179 }
180 else
181 {
182 $arIBLOCKFilter = $IBlockFilter_cache[$sIBlockFilter];
183 }
184
185 if(count($arIBLOCKFilter) > 0)
186 $arSqlSearch[] = "B.ID IN (".implode(", ", $arIBLOCKFilter).") ";
187 }
188 }
189 else
190 {
191 foreach($arIBlockFilter as $val)
192 if($val <> '')
193 $arSqlSearch[] = $val;
194 }
195
196 return $arSqlSearch;
197 }
198
199 public static function GetTreeList($arFilter = array(), $arSelect = array())
200 {
201 return CIBlockSection::GetList(array("left_margin"=>"asc"), $arFilter, false, $arSelect);
202 }
203
204 public static function GetNavChain($IBLOCK_ID, $SECTION_ID, $arSelect = array(), $arrayResult = false)
205 {
206 global $DB;
207
208 $arrayResult = ($arrayResult === true);
209
210 $IBLOCK_ID = (int)$IBLOCK_ID;
211
213 "ID" => "BS.ID",
214 "CODE" => "BS.CODE",
215 "XML_ID" => "BS.XML_ID",
216 "EXTERNAL_ID" => "BS.XML_ID",
217 "IBLOCK_ID" => "BS.IBLOCK_ID",
218 "IBLOCK_SECTION_ID" => "BS.IBLOCK_SECTION_ID",
219 "SORT" => "BS.SORT",
220 "NAME" => "BS.NAME",
221 "ACTIVE" => "BS.ACTIVE",
222 "GLOBAL_ACTIVE" => "BS.GLOBAL_ACTIVE",
223 "PICTURE" => "BS.PICTURE",
224 "DESCRIPTION" => "BS.DESCRIPTION",
225 "DESCRIPTION_TYPE" => "BS.DESCRIPTION_TYPE",
226 "LEFT_MARGIN" => "BS.LEFT_MARGIN",
227 "RIGHT_MARGIN" => "BS.RIGHT_MARGIN",
228 "DEPTH_LEVEL" => "BS.DEPTH_LEVEL",
229 "SEARCHABLE_CONTENT" => "BS.SEARCHABLE_CONTENT",
230 "MODIFIED_BY" => "BS.MODIFIED_BY",
231 "CREATED_BY" => "BS.CREATED_BY",
232 "DETAIL_PICTURE" => "BS.DETAIL_PICTURE",
233 "TMP_ID" => "BS.TMP_ID",
234
235 "LIST_PAGE_URL" => "B.LIST_PAGE_URL",
236 "SECTION_PAGE_URL" => "B.SECTION_PAGE_URL",
237 "IBLOCK_TYPE_ID" => "B.IBLOCK_TYPE_ID",
238 "IBLOCK_CODE" => "B.CODE",
239 "IBLOCK_EXTERNAL_ID" => "B.XML_ID",
240 "SOCNET_GROUP_ID" => "BS.SOCNET_GROUP_ID",
241 );
242
243 $arSqlSelect = array();
244 foreach($arSelect as $field)
245 {
246 $field = mb_strtoupper($field);
247 if (isset($arFields[$field]))
248 $arSqlSelect[$field] = $arFields[$field]." AS ".$field;
249 }
250
251 if (isset($arSqlSelect["DESCRIPTION"]))
252 $arSqlSelect["DESCRIPTION_TYPE"] = $arFields["DESCRIPTION_TYPE"]." AS DESCRIPTION_TYPE";
253
254 if (isset($arSqlSelect["LIST_PAGE_URL"]) || isset($arSqlSelect["SECTION_PAGE_URL"]))
255 {
256 $arSqlSelect["ID"] = $arFields["ID"]." AS ID";
257 $arSqlSelect["CODE"] = $arFields["CODE"]." AS CODE";
258 $arSqlSelect["EXTERNAL_ID"] = $arFields["EXTERNAL_ID"]." AS EXTERNAL_ID";
259 $arSqlSelect["IBLOCK_TYPE_ID"] = $arFields["IBLOCK_TYPE_ID"]." AS IBLOCK_TYPE_ID";
260 $arSqlSelect["IBLOCK_ID"] = $arFields["IBLOCK_ID"]." AS IBLOCK_ID";
261 $arSqlSelect["IBLOCK_CODE"] = $arFields["IBLOCK_CODE"]." AS IBLOCK_CODE";
262 $arSqlSelect["IBLOCK_EXTERNAL_ID"] = $arFields["IBLOCK_EXTERNAL_ID"]." AS IBLOCK_EXTERNAL_ID";
263 $arSqlSelect["GLOBAL_ACTIVE"] = $arFields["GLOBAL_ACTIVE"]." AS GLOBAL_ACTIVE";
264 //$arr["LANG_DIR"],
265 }
266
267 if (!empty($arSelect))
268 {
269 $field = "IBLOCK_SECTION_ID";
270 $arSqlSelect[$field] = $arFields[$field]." AS ".$field;
271 $strSelect = implode(", ", $arSqlSelect);
272 }
273 else
274 {
275 $strSelect = "
276 BS.*,
277 B.LIST_PAGE_URL,
278 B.SECTION_PAGE_URL,
279 B.IBLOCK_TYPE_ID,
280 B.CODE as IBLOCK_CODE,
281 B.XML_ID as IBLOCK_EXTERNAL_ID,
282 BS.XML_ID as EXTERNAL_ID
283 ";
284 }
285
286 $key = md5($strSelect);
287 if (!isset(self::$arSectionNavChainCache[$key]))
288 self::$arSectionNavChainCache[$key] = array();
289
290 $sectionPath = array();
291 do
292 {
293 $SECTION_ID = (int)$SECTION_ID;
294
295 if (!isset(self::$arSectionNavChainCache[$key][$SECTION_ID]))
296 {
297 $rsSection = $DB->Query("
298 SELECT
299 ".$strSelect."
300 FROM
301 b_iblock_section BS
302 INNER JOIN b_iblock B ON B.ID = BS.IBLOCK_ID
303 WHERE BS.ID=".$SECTION_ID."
304 ".($IBLOCK_ID > 0 ? "AND BS.IBLOCK_ID=".$IBLOCK_ID : "")."
305 ");
306 self::$arSectionNavChainCache[$key][$SECTION_ID] = $rsSection->Fetch();
307 }
308
309 if (self::$arSectionNavChainCache[$key][$SECTION_ID])
310 {
311 $sectionPath[] = self::$arSectionNavChainCache[$key][$SECTION_ID];
312 $SECTION_ID = self::$arSectionNavChainCache[$key][$SECTION_ID]["IBLOCK_SECTION_ID"];
313 }
314 else
315 {
316 $SECTION_ID = 0;
317 }
318 }
319 while ($SECTION_ID > 0);
320
321 $sectionPath = array_reverse($sectionPath);
322 if ($arrayResult)
323 return $sectionPath;
324
325 $res = new CDBResult;
326 $res->InitFromArray($sectionPath);
327 $res = new CIBlockResult($res);
328 $res->bIBlockSection = true;
329 return $res;
330 }
331
333 // Function returns section by ID
335 public static function GetByID($ID)
336 {
337 return CIBlockSection::GetList(Array(), Array("ID"=>(int)$ID));
338 }
339
341 // New section
343 public function Add($arFields, $bResort=true, $bUpdateSearch=true, $bResizePictures=false)
344 {
345 global $USER, $DB, $APPLICATION;
346
347 if (array_key_exists('EXTERNAL_ID', $arFields))
348 {
349 $arFields['XML_ID'] = $arFields['EXTERNAL_ID'];
350 unset($arFields['EXTERNAL_ID']);
351 }
352 unset($arFields["GLOBAL_ACTIVE"]);
353 unset($arFields["DEPTH_LEVEL"]);
354 unset($arFields["LEFT_MARGIN"]);
355 unset($arFields["RIGHT_MARGIN"]);
356
357 $strWarning = '';
358
359 if ($this->iblock !== null && $this->iblock['ID'] === (int)$arFields["IBLOCK_ID"])
360 {
362 }
363 else
364 {
365 $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]);
366 }
367
368 if($bResizePictures && is_array($arIBlock))
369 {
370 $arDef = $arIBlock["FIELDS"]["SECTION_PICTURE"]["DEFAULT_VALUE"];
371
372 if(
373 $arDef["FROM_DETAIL"] === "Y"
374 && is_array($arFields["DETAIL_PICTURE"])
375 && $arFields["DETAIL_PICTURE"]["size"] > 0
376 && (
377 $arDef["UPDATE_WITH_DETAIL"] === "Y"
378 || $arFields["PICTURE"]["size"] <= 0
379 )
380 )
381 {
382 $arNewPreview = $arFields["DETAIL_PICTURE"];
383 $arNewPreview["COPY_FILE"] = "Y";
384 $arNewPreview["description"] = $arFields["PICTURE"]["description"];
385 $arFields["PICTURE"] = $arNewPreview;
386 }
387
388 if(
389 array_key_exists("PICTURE", $arFields)
390 && is_array($arFields["PICTURE"])
391 && $arDef["SCALE"] === "Y"
392 )
393 {
394 $arNewPicture = CIBlock::ResizePicture($arFields["PICTURE"], $arDef);
395 if(is_array($arNewPicture))
396 {
397 $arNewPicture["description"] = $arFields["PICTURE"]["description"];
398 $arFields["PICTURE"] = $arNewPicture;
399 }
400 elseif($arDef["IGNORE_ERRORS"] !== "Y")
401 {
402 unset($arFields["PICTURE"]);
403 $strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE").": ".$arNewPicture."<br>";
404 }
405 }
406
407 if(
408 array_key_exists("PICTURE", $arFields)
409 && is_array($arFields["PICTURE"])
410 && $arDef["USE_WATERMARK_FILE"] === "Y"
411 )
412 {
413 if(
414 $arFields["PICTURE"]["tmp_name"] <> ''
415 && (
416 $arFields["PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"]
417 || ($arFields["PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PICTURE"]["copy"])
418 )
419 )
420 {
421 $tmp_name = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"]));
422 CheckDirPath($tmp_name);
423 copy($arFields["PICTURE"]["tmp_name"], $tmp_name);
424 $arFields["PICTURE"]["copy"] = true;
425 $arFields["PICTURE"]["tmp_name"] = $tmp_name;
426 }
427
428 CIBlock::FilterPicture($arFields["PICTURE"]["tmp_name"], array(
429 "name" => "watermark",
430 "position" => $arDef["WATERMARK_FILE_POSITION"],
431 "type" => "file",
432 "size" => "real",
433 "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100),
434 "file" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_FILE"]),
435 ));
436 }
437
438 if(
439 array_key_exists("PICTURE", $arFields)
440 && is_array($arFields["PICTURE"])
441 && $arDef["USE_WATERMARK_TEXT"] === "Y"
442 )
443 {
444 if(
445 $arFields["PICTURE"]["tmp_name"] <> ''
446 && (
447 $arFields["PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"]
448 || ($arFields["PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PICTURE"]["copy"])
449 )
450 )
451 {
452 $tmp_name = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"]));
453 CheckDirPath($tmp_name);
454 copy($arFields["PICTURE"]["tmp_name"], $tmp_name);
455 $arFields["PICTURE"]["copy"] = true;
456 $arFields["PICTURE"]["tmp_name"] = $tmp_name;
457 }
458
459 CIBlock::FilterPicture($arFields["PICTURE"]["tmp_name"], array(
460 "name" => "watermark",
461 "position" => $arDef["WATERMARK_TEXT_POSITION"],
462 "type" => "text",
463 "coefficient" => $arDef["WATERMARK_TEXT_SIZE"],
464 "text" => $arDef["WATERMARK_TEXT"],
465 "font" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]),
466 "color" => $arDef["WATERMARK_TEXT_COLOR"],
467 ));
468 }
469
470 $arDef = $arIBlock["FIELDS"]["SECTION_DETAIL_PICTURE"]["DEFAULT_VALUE"];
471
472 if(
473 array_key_exists("DETAIL_PICTURE", $arFields)
474 && is_array($arFields["DETAIL_PICTURE"])
475 && $arDef["SCALE"] === "Y"
476 )
477 {
478 $arNewPicture = CIBlock::ResizePicture($arFields["DETAIL_PICTURE"], $arDef);
479 if(is_array($arNewPicture))
480 {
481 $arNewPicture["description"] = $arFields["DETAIL_PICTURE"]["description"];
482 $arFields["DETAIL_PICTURE"] = $arNewPicture;
483 }
484 elseif($arDef["IGNORE_ERRORS"] !== "Y")
485 {
486 unset($arFields["DETAIL_PICTURE"]);
487 $strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE").": ".$arNewPicture."<br>";
488 }
489 }
490
491 if(
492 array_key_exists("DETAIL_PICTURE", $arFields)
493 && is_array($arFields["DETAIL_PICTURE"])
494 && $arDef["USE_WATERMARK_FILE"] === "Y"
495 )
496 {
497 if(
498 $arFields["DETAIL_PICTURE"]["tmp_name"] <> ''
499 && (
500 $arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PICTURE"]["tmp_name"]
501 || ($arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])
502 )
503 )
504 {
505 $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
506 CheckDirPath($tmp_name);
507 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name);
508 $arFields["DETAIL_PICTURE"]["copy"] = true;
509 $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name;
510 }
511
512 CIBlock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array(
513 "name" => "watermark",
514 "position" => $arDef["WATERMARK_FILE_POSITION"],
515 "type" => "file",
516 "size" => "real",
517 "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100),
518 "file" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_FILE"]),
519 ));
520 }
521
522 if(
523 array_key_exists("DETAIL_PICTURE", $arFields)
524 && is_array($arFields["DETAIL_PICTURE"])
525 && $arDef["USE_WATERMARK_TEXT"] === "Y"
526 )
527 {
528 if(
529 $arFields["DETAIL_PICTURE"]["tmp_name"] <> ''
530 && (
531 $arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PICTURE"]["tmp_name"]
532 || ($arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])
533 )
534 )
535 {
536 $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
537 CheckDirPath($tmp_name);
538 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name);
539 $arFields["DETAIL_PICTURE"]["copy"] = true;
540 $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name;
541 }
542
543 CIBlock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array(
544 "name" => "watermark",
545 "position" => $arDef["WATERMARK_TEXT_POSITION"],
546 "type" => "text",
547 "coefficient" => $arDef["WATERMARK_TEXT_SIZE"],
548 "text" => $arDef["WATERMARK_TEXT"],
549 "font" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]),
550 "color" => $arDef["WATERMARK_TEXT_COLOR"],
551 ));
552 }
553 }
554
555 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($arFields["IBLOCK_ID"], 0);
556 if (array_key_exists("PICTURE", $arFields))
557 {
558 if (!is_array($arFields["PICTURE"]))
559 {
560 unset($arFields["PICTURE"]);
561 }
562 elseif (
563 ($arFields["PICTURE"]["name"] ?? '') === ''
564 && ($arFields["PICTURE"]["del"] ?? '') === ''
565 )
566 {
567 unset($arFields["PICTURE"]);
568 }
569 else
570 {
571 $arFields["PICTURE"]["MODULE_ID"] = "iblock";
572 if (isset($arFields["PICTURE"]["name"]))
573 {
575 $ipropTemplates
576 , "SECTION_PICTURE_FILE_NAME"
577 , $arFields
578 , $arFields["PICTURE"]
579 );
580 }
581 }
582 }
583
584 if (array_key_exists("DETAIL_PICTURE", $arFields))
585 {
586 if (!is_array($arFields["DETAIL_PICTURE"]))
587 {
588 unset($arFields["DETAIL_PICTURE"]);
589 }
590 elseif (
591 ($arFields["DETAIL_PICTURE"]["name"] ?? '') === ''
592 && ($arFields["DETAIL_PICTURE"]["del"] ?? '') === ''
593 )
594 {
595 unset($arFields["DETAIL_PICTURE"]);
596 }
597 else
598 {
599 $arFields["DETAIL_PICTURE"]["MODULE_ID"] = "iblock";
600 if (isset($arFields["DETAIL_PICTURE"]["name"]))
601 {
603 $ipropTemplates
604 , "SECTION_DETAIL_PICTURE_FILE_NAME"
605 , $arFields
606 , $arFields["DETAIL_PICTURE"]
607 );
608 }
609 }
610 }
611
612 $arFields["IBLOCK_SECTION_ID"] = isset($arFields["IBLOCK_SECTION_ID"])? intval($arFields["IBLOCK_SECTION_ID"]): 0;
613 if($arFields["IBLOCK_SECTION_ID"] == 0)
614 $arFields["IBLOCK_SECTION_ID"] = false;
615
616 if(is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y")
617 $arFields["ACTIVE"] = "N";
618 else
619 $arFields["ACTIVE"] = "Y";
620
621 if(!array_key_exists("DESCRIPTION_TYPE", $arFields) || $arFields["DESCRIPTION_TYPE"]!="html")
622 $arFields["DESCRIPTION_TYPE"]="text";
623
624 if(!isset($arFields["DESCRIPTION"]))
625 $arFields["DESCRIPTION"] = false;
626
627 $arFields["SEARCHABLE_CONTENT"] =
628 mb_strtoupper(
629 $arFields["NAME"]."\r\n".
630 ($arFields["DESCRIPTION_TYPE"]=="html" ?
631 HTMLToTxt($arFields["DESCRIPTION"]) :
632 $arFields["DESCRIPTION"]
633 )
634 );
635
636 unset($arFields["DATE_CREATE"]);
637 $arFields["~DATE_CREATE"] = $DB->CurrentTimeFunction();
638 if(is_object($USER))
639 {
640 $user_id = intval($USER->GetID());
641 if(!isset($arFields["CREATED_BY"]) || intval($arFields["CREATED_BY"]) <= 0)
642 $arFields["CREATED_BY"] = $user_id;
643 if(!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0)
644 $arFields["MODIFIED_BY"] = $user_id;
645 }
646
647 $IBLOCK_ID = intval($arFields["IBLOCK_ID"]);
648
649 if(!$this->CheckFields($arFields))
650 {
651 $Result = false;
652 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
653 }
654 elseif($IBLOCK_ID && !$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("IBLOCK_".$IBLOCK_ID."_SECTION", 0, $arFields))
655 {
656 $Result = false;
657 $err = $APPLICATION->GetException();
658 if(is_object($err))
659 $this->LAST_ERROR .= str_replace("<br><br>", "<br>", $err->GetString()."<br>");
660 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
661 }
662 else
663 {
664 if (!isset($arFields['TIMESTAMP_X']))
665 {
667 }
668
669 if(array_key_exists("PICTURE", $arFields))
670 {
671 $SAVED_PICTURE = $arFields["PICTURE"];
672 CFile::SaveForDB($arFields, "PICTURE", "iblock");
673 }
674
675 if(array_key_exists("DETAIL_PICTURE", $arFields))
676 {
677 $SAVED_DETAIL_PICTURE = $arFields["DETAIL_PICTURE"];
678 CFile::SaveForDB($arFields, "DETAIL_PICTURE", "iblock");
679 }
680
681 $arFields['SORT'] = (int)($arFields['SORT'] ?? 500);
682
683 CIBlock::_transaction_lock($IBLOCK_ID);
684
685 unset($arFields["ID"]);
686 $ID = intval($DB->Add("b_iblock_section", $arFields, Array("DESCRIPTION","SEARCHABLE_CONTENT"), "iblock"));
687 $arFields["ID"] = $ID;
688 unset($arFields['~TIMESTAMP_X']);
689
690 if(array_key_exists("PICTURE", $arFields))
691 $arFields["PICTURE"] = $SAVED_PICTURE;
692 if(array_key_exists("DETAIL_PICTURE", $arFields))
693 $arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE;
694
695 if ($bResort)
696 {
698 }
699
700 $GLOBALS["USER_FIELD_MANAGER"]->Update("IBLOCK_".$IBLOCK_ID."_SECTION", $ID, $arFields);
701
702 if($bUpdateSearch)
704
705 if(
706 CIBlock::GetArrayByID($IBLOCK_ID, "SECTION_PROPERTY") === "Y"
707 && isset($arFields["SECTION_PROPERTY"])
708 && is_array($arFields["SECTION_PROPERTY"])
709 )
710 {
711 foreach($arFields["SECTION_PROPERTY"] as $PROPERTY_ID => $arLink)
712 {
713 $arLink['INVALIDATE'] = 'N';
714 CIBlockSectionPropertyLink::Add($ID, $PROPERTY_ID, $arLink);
715 }
716 unset($arLink);
717 unset($PROPERTY_ID);
718 }
719
720 if($arIBlock["FIELDS"]["LOG_SECTION_ADD"]["IS_REQUIRED"] == "Y")
721 {
722 $USER_ID = is_object($USER)? intval($USER->GetID()) : 0;
723 $arEvents = GetModuleEvents("main", "OnBeforeEventLog", true);
724 if(empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID))===false)
725 {
726 $rsSection = CIBlockSection::GetList(array(), array("=ID"=>$ID), false, array("LIST_PAGE_URL", "NAME", "CODE"));
727 $arSection = $rsSection->GetNext();
728 $res = array(
729 "ID" => $ID,
730 "CODE" => $arSection["CODE"],
731 "NAME" => $arSection["NAME"],
732 "SECTION_NAME" => $arIBlock["SECTION_NAME"],
733 "USER_ID" => $USER_ID,
734 "IBLOCK_PAGE_URL" => $arSection["LIST_PAGE_URL"],
735 );
737 "IBLOCK",
738 "IBLOCK_SECTION_ADD",
739 "iblock",
740 $arIBlock["ID"],
741 serialize($res)
742 );
743 }
744 }
745
746 if($arIBlock["RIGHTS_MODE"] === "E")
747 {
748 $obSectionRights = new CIBlockSectionRights($arIBlock["ID"], $ID);
749 $obSectionRights->ChangeParents(array(), array($arFields["IBLOCK_SECTION_ID"]));
750
751 if(array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"]))
752 $obSectionRights->SetRights($arFields["RIGHTS"]);
753 }
754
755 if (array_key_exists("IPROPERTY_TEMPLATES", $arFields))
756 {
757 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($arIBlock["ID"], $ID);
758 $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
759 }
760
761 $Result = $ID;
762
763 /************* QUOTA *************/
765 /************* QUOTA *************/
766 }
767
768 $arFields["RESULT"] = &$Result;
769
770 foreach (GetModuleEvents("iblock", "OnAfterIBlockSectionAdd", true) as $arEvent)
772
773 CIBlock::clearIblockTagCache($arIBlock['ID']);
774
775 return $Result;
776 }
777
779 // Update section properties
781 public function Update($ID, $arFields, $bResort=true, $bUpdateSearch=true, $bResizePictures=false)
782 {
783 global $USER, $DB, $APPLICATION;
784
785 $ID = (int)$ID;
786
787 $iterator = CIBlockSection::GetList(Array(), Array("ID"=>$ID, "CHECK_PERMISSIONS"=>"N"));
788 $db_record = $iterator->Fetch();
789 unset($iterator);
790 if (empty($db_record))
791 {
792 return false;
793 }
794
795 if (array_key_exists('EXTERNAL_ID', $arFields))
796 {
797 $arFields['XML_ID'] = $arFields['EXTERNAL_ID'];
798 unset($arFields['EXTERNAL_ID']);
799 }
800
801 unset($arFields["GLOBAL_ACTIVE"]);
802 unset($arFields["DEPTH_LEVEL"]);
803 unset($arFields["LEFT_MARGIN"]);
804 unset($arFields["RIGHT_MARGIN"]);
805 unset($arFields["IBLOCK_ID"]);
806 unset($arFields["DATE_CREATE"]);
807 unset($arFields["CREATED_BY"]);
808
809 $strWarning = '';
810
811 if ($this->iblock !== null && $this->iblock['ID'] === (int)$db_record["IBLOCK_ID"])
812 {
814 }
815 else
816 {
817 $arIBlock = CIBlock::GetArrayByID($db_record["IBLOCK_ID"]);
818 }
819
820 if($bResizePictures)
821 {
822 $arDef = $arIBlock["FIELDS"]["SECTION_PICTURE"]["DEFAULT_VALUE"];
823
824 if(
825 $arDef["DELETE_WITH_DETAIL"] === "Y"
826 && $arFields["DETAIL_PICTURE"]["del"] === "Y"
827 )
828 {
829 $arFields["PICTURE"]["del"] = "Y";
830 }
831
832 if(
833 $arDef["FROM_DETAIL"] === "Y"
834 && (
835 $arFields["PICTURE"]["size"] <= 0
836 || $arDef["UPDATE_WITH_DETAIL"] === "Y"
837 )
838 && is_array($arFields["DETAIL_PICTURE"])
839 && $arFields["DETAIL_PICTURE"]["size"] > 0
840 )
841 {
842 if(
843 $arFields["PICTURE"]["del"] !== "Y"
844 && $arDef["UPDATE_WITH_DETAIL"] !== "Y"
845 )
846 {
847 $arOldSection = $db_record;
848 }
849 else
850 {
851 $arOldSection = false;
852 }
853
854 if(!$arOldSection || !$arOldSection["PICTURE"])
855 {
856 $arNewPreview = $arFields["DETAIL_PICTURE"];
857 $arNewPreview["COPY_FILE"] = "Y";
858 $arNewPreview["description"] = $arFields["PICTURE"]["description"];
859 $arFields["PICTURE"] = $arNewPreview;
860 }
861 }
862
863 if(
864 array_key_exists("PICTURE", $arFields)
865 && is_array($arFields["PICTURE"])
866 && $arFields["PICTURE"]["size"] > 0
867 && $arDef["SCALE"] === "Y"
868 )
869 {
870 $arNewPicture = CIBlock::ResizePicture($arFields["PICTURE"], $arDef);
871 if(is_array($arNewPicture))
872 {
873 $arNewPicture["description"] = $arFields["PICTURE"]["description"];
874 $arFields["PICTURE"] = $arNewPicture;
875 }
876 elseif($arDef["IGNORE_ERRORS"] !== "Y")
877 {
878 unset($arFields["PICTURE"]);
879 $strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE").": ".$arNewPicture."<br>";
880 }
881 }
882
883 if(
884 array_key_exists("PICTURE", $arFields)
885 && is_array($arFields["PICTURE"])
886 && $arDef["USE_WATERMARK_FILE"] === "Y"
887 )
888 {
889 if(
890 $arFields["PICTURE"]["tmp_name"] <> ''
891 && (
892 $arFields["PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"]
893 || ($arFields["PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PICTURE"]["copy"])
894 )
895 )
896 {
897 $tmp_name = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"]));
898 CheckDirPath($tmp_name);
899 copy($arFields["PICTURE"]["tmp_name"], $tmp_name);
900 $arFields["PICTURE"]["copy"] = true;
901 $arFields["PICTURE"]["tmp_name"] = $tmp_name;
902 }
903
904 CIBlock::FilterPicture($arFields["PICTURE"]["tmp_name"], array(
905 "name" => "watermark",
906 "position" => $arDef["WATERMARK_FILE_POSITION"],
907 "type" => "file",
908 "size" => "real",
909 "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100),
910 "file" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_FILE"]),
911 ));
912 }
913
914 if(
915 array_key_exists("PICTURE", $arFields)
916 && is_array($arFields["PICTURE"])
917 && $arDef["USE_WATERMARK_TEXT"] === "Y"
918 )
919 {
920 if(
921 $arFields["PICTURE"]["tmp_name"] <> ''
922 && (
923 $arFields["PICTURE"]["tmp_name"] === $arFields["DETAIL_PICTURE"]["tmp_name"]
924 || ($arFields["PICTURE"]["COPY_FILE"] == "Y" && !$arFields["PICTURE"]["copy"])
925 )
926 )
927 {
928 $tmp_name = CTempFile::GetFileName(basename($arFields["PICTURE"]["tmp_name"]));
929 CheckDirPath($tmp_name);
930 copy($arFields["PICTURE"]["tmp_name"], $tmp_name);
931 $arFields["PICTURE"]["copy"] = true;
932 $arFields["PICTURE"]["tmp_name"] = $tmp_name;
933 }
934
935 CIBlock::FilterPicture($arFields["PICTURE"]["tmp_name"], array(
936 "name" => "watermark",
937 "position" => $arDef["WATERMARK_TEXT_POSITION"],
938 "type" => "text",
939 "coefficient" => $arDef["WATERMARK_TEXT_SIZE"],
940 "text" => $arDef["WATERMARK_TEXT"],
941 "font" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]),
942 "color" => $arDef["WATERMARK_TEXT_COLOR"],
943 ));
944 }
945
946 $arDef = $arIBlock["FIELDS"]["SECTION_DETAIL_PICTURE"]["DEFAULT_VALUE"];
947
948 if(
949 array_key_exists("DETAIL_PICTURE", $arFields)
950 && is_array($arFields["DETAIL_PICTURE"])
951 && $arDef["SCALE"] === "Y"
952 )
953 {
954 $arNewPicture = CIBlock::ResizePicture($arFields["DETAIL_PICTURE"], $arDef);
955 if(is_array($arNewPicture))
956 {
957 $arNewPicture["description"] = $arFields["DETAIL_PICTURE"]["description"];
958 $arFields["DETAIL_PICTURE"] = $arNewPicture;
959 }
960 elseif($arDef["IGNORE_ERRORS"] !== "Y")
961 {
962 unset($arFields["DETAIL_PICTURE"]);
963 $strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE").": ".$arNewPicture."<br>";
964 }
965 }
966
967 if(
968 array_key_exists("DETAIL_PICTURE", $arFields)
969 && is_array($arFields["DETAIL_PICTURE"])
970 && $arDef["USE_WATERMARK_FILE"] === "Y"
971 )
972 {
973 if(
974 $arFields["DETAIL_PICTURE"]["tmp_name"] <> ''
975 && (
976 $arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PICTURE"]["tmp_name"]
977 || ($arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])
978 )
979 )
980 {
981 $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
982 CheckDirPath($tmp_name);
983 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name);
984 $arFields["DETAIL_PICTURE"]["copy"] = true;
985 $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name;
986 }
987
988 CIBlock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array(
989 "name" => "watermark",
990 "position" => $arDef["WATERMARK_FILE_POSITION"],
991 "type" => "file",
992 "size" => "real",
993 "alpha_level" => 100 - min(max($arDef["WATERMARK_FILE_ALPHA"], 0), 100),
994 "file" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_FILE"]),
995 "fill" => "resize",
996 ));
997 }
998
999 if(
1000 array_key_exists("DETAIL_PICTURE", $arFields)
1001 && is_array($arFields["DETAIL_PICTURE"])
1002 && $arDef["USE_WATERMARK_TEXT"] === "Y"
1003 )
1004 {
1005 if(
1006 $arFields["DETAIL_PICTURE"]["tmp_name"] <> ''
1007 && (
1008 $arFields["DETAIL_PICTURE"]["tmp_name"] === $arFields["PICTURE"]["tmp_name"]
1009 || ($arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && !$arFields["DETAIL_PICTURE"]["copy"])
1010 )
1011 )
1012 {
1013 $tmp_name = CTempFile::GetFileName(basename($arFields["DETAIL_PICTURE"]["tmp_name"]));
1014 CheckDirPath($tmp_name);
1015 copy($arFields["DETAIL_PICTURE"]["tmp_name"], $tmp_name);
1016 $arFields["DETAIL_PICTURE"]["copy"] = true;
1017 $arFields["DETAIL_PICTURE"]["tmp_name"] = $tmp_name;
1018 }
1019
1020 CIBlock::FilterPicture($arFields["DETAIL_PICTURE"]["tmp_name"], array(
1021 "name" => "watermark",
1022 "position" => $arDef["WATERMARK_TEXT_POSITION"],
1023 "type" => "text",
1024 "coefficient" => $arDef["WATERMARK_TEXT_SIZE"],
1025 "text" => $arDef["WATERMARK_TEXT"],
1026 "font" => $_SERVER["DOCUMENT_ROOT"].Rel2Abs("/", $arDef["WATERMARK_TEXT_FONT"]),
1027 "color" => $arDef["WATERMARK_TEXT_COLOR"],
1028 ));
1029 }
1030 }
1031
1032 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($db_record["IBLOCK_ID"], $db_record["ID"]);
1033 if (array_key_exists("PICTURE", $arFields))
1034 {
1035 if (!is_array($arFields["PICTURE"]))
1036 {
1037 unset($arFields["PICTURE"]);
1038 }
1039 elseif (
1040 ($arFields["PICTURE"]["name"] ?? '') === ''
1041 && ($arFields["PICTURE"]["del"] ?? '') === ''
1042 && !array_key_exists("description", $arFields["PICTURE"])
1043 )
1044 {
1045 unset($arFields["PICTURE"]);
1046 }
1047 else
1048 {
1049 $arFields["PICTURE"]["old_file"] = $db_record["PICTURE"];
1050 $arFields["PICTURE"]["MODULE_ID"] = "iblock";
1052 $ipropTemplates
1053 ,"SECTION_PICTURE_FILE_NAME"
1054 ,array_merge($db_record, $arFields)
1055 ,$arFields["PICTURE"]
1056 );
1057 }
1058 }
1059
1060 if (array_key_exists("DETAIL_PICTURE", $arFields))
1061 {
1062 if (!is_array($arFields["DETAIL_PICTURE"]))
1063 {
1064 unset($arFields["DETAIL_PICTURE"]);
1065 }
1066 elseif (
1067 ($arFields["DETAIL_PICTURE"]["name"] ?? '') === ''
1068 && ($arFields["DETAIL_PICTURE"]["del"] ?? '') === ''
1069 && !array_key_exists("description", $arFields["DETAIL_PICTURE"])
1070 )
1071 {
1072 unset($arFields["DETAIL_PICTURE"]);
1073 }
1074 else
1075 {
1076 $arFields["DETAIL_PICTURE"]["old_file"] = $db_record["DETAIL_PICTURE"];
1077 $arFields["DETAIL_PICTURE"]["MODULE_ID"] = "iblock";
1078 $arFields["DETAIL_PICTURE"]["name"] = \Bitrix\Iblock\Template\Helper::makeFileName(
1079 $ipropTemplates
1080 ,"SECTION_DETAIL_PICTURE_FILE_NAME"
1081 ,array_merge($db_record, $arFields)
1082 ,$arFields["DETAIL_PICTURE"]
1083 );
1084 }
1085 }
1086
1087 if(is_set($arFields, "ACTIVE") && $arFields["ACTIVE"]!="Y")
1088 $arFields["ACTIVE"]="N";
1089
1090 if(is_set($arFields, "DESCRIPTION_TYPE") && $arFields["DESCRIPTION_TYPE"]!="html")
1091 $arFields["DESCRIPTION_TYPE"] = "text";
1092
1093 if(isset($arFields["IBLOCK_SECTION_ID"]))
1094 {
1095 $arFields["IBLOCK_SECTION_ID"] = intval($arFields["IBLOCK_SECTION_ID"]);
1096 if($arFields["IBLOCK_SECTION_ID"] <= 0)
1097 $arFields["IBLOCK_SECTION_ID"] = false;
1098 }
1099
1100 $DESC_tmp = is_set($arFields, "DESCRIPTION")? $arFields["DESCRIPTION"]: $db_record["DESCRIPTION"];
1101 $DESC_TYPE_tmp = is_set($arFields, "DESCRIPTION_TYPE")? $arFields["DESCRIPTION_TYPE"]: $db_record["DESCRIPTION_TYPE"];
1102
1103 $arFields["SEARCHABLE_CONTENT"] = mb_strtoupper(
1104 (is_set($arFields, "NAME")? $arFields["NAME"]: $db_record["NAME"])."\r\n".
1105 ($DESC_TYPE_tmp=="html"? HTMLToTxt($DESC_tmp): $DESC_tmp)
1106 );
1107
1108 if(is_object($USER))
1109 {
1110 if(!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0)
1111 $arFields["MODIFIED_BY"] = intval($USER->GetID());
1112 }
1113
1114 if(!$this->CheckFields($arFields, $ID))
1115 {
1116 $Result = false;
1117 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
1118 }
1119 elseif(!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("IBLOCK_".$db_record["IBLOCK_ID"]."_SECTION", $ID, $arFields))
1120 {
1121 $Result = false;
1122 $err = $APPLICATION->GetException();
1123 if(is_object($err))
1124 $this->LAST_ERROR .= str_replace("<br><br>", "<br>", $err->GetString()."<br>");
1125 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
1126 }
1127 else
1128 {
1129 if(array_key_exists("PICTURE", $arFields))
1130 {
1131 $SAVED_PICTURE = $arFields["PICTURE"];
1132 CFile::SaveForDB($arFields, "PICTURE", "iblock");
1133 }
1134
1135 if(array_key_exists("DETAIL_PICTURE", $arFields))
1136 {
1137 $SAVED_DETAIL_PICTURE = $arFields["DETAIL_PICTURE"];
1138 CFile::SaveForDB($arFields, "DETAIL_PICTURE", "iblock");
1139 }
1140
1141 if (!isset($arFields['TIMESTAMP_X']))
1142 {
1143 $arFields['~TIMESTAMP_X'] = $this->currentDateTimeFunction;
1144 }
1145
1146 unset($arFields["ID"]);
1147 $strUpdate = $DB->PrepareUpdate("b_iblock_section", $arFields, "iblock");
1148 $arFields["ID"] = $ID;
1149 unset($arFields['~TIMESTAMP_X']);
1150
1151 if(array_key_exists("PICTURE", $arFields))
1152 $arFields["PICTURE"] = $SAVED_PICTURE;
1153 if(array_key_exists("DETAIL_PICTURE", $arFields))
1154 $arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE;
1155
1156 CIBlock::_transaction_lock($db_record["IBLOCK_ID"]);
1157
1158 if($strUpdate <> '')
1159 {
1160 $strSql = "UPDATE b_iblock_section SET ".$strUpdate." WHERE ID = ".$ID;
1161 $arBinds=Array();
1162 if(array_key_exists("DESCRIPTION", $arFields))
1163 $arBinds["DESCRIPTION"] = $arFields["DESCRIPTION"];
1164 if(array_key_exists("SEARCHABLE_CONTENT", $arFields))
1165 $arBinds["SEARCHABLE_CONTENT"] = $arFields["SEARCHABLE_CONTENT"];
1166 $DB->QueryBind($strSql, $arBinds);
1167 }
1168
1169 if($bResort)
1170 {
1171 $this->recountTreeAfterUpdate($arFields, $db_record);
1172 }
1173
1174 unset(self::$arSectionCodeCache[$ID]);
1175 self::$arSectionPathCache = array();
1176 self::$arSectionNavChainCache = array();
1177
1178 if($arIBlock["RIGHTS_MODE"] === "E")
1179 {
1180 $obSectionRights = new CIBlockSectionRights($arIBlock["ID"], $ID);
1181 //Check if parent changed with extended rights mode
1182 if(
1183 isset($arFields["IBLOCK_SECTION_ID"])
1184 && $arFields["IBLOCK_SECTION_ID"] != $db_record["IBLOCK_SECTION_ID"]
1185 )
1186 {
1187 $obSectionRights->ChangeParents(array($db_record["IBLOCK_SECTION_ID"]), array($arFields["IBLOCK_SECTION_ID"]));
1188 }
1189
1190 if(array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"]))
1191 $obSectionRights->SetRights($arFields["RIGHTS"]);
1192 }
1193
1194 if (array_key_exists("IPROPERTY_TEMPLATES", $arFields))
1195 {
1196 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($arIBlock["ID"], $ID);
1197 $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
1198 }
1199
1200 $uf_updated = $GLOBALS["USER_FIELD_MANAGER"]->Update("IBLOCK_".$db_record["IBLOCK_ID"]."_SECTION", $ID, $arFields);
1201 if($uf_updated)
1202 {
1203 $DB->Query("UPDATE b_iblock_section SET TIMESTAMP_X = ".$DB->CurrentTimeFunction()." WHERE ID = ".$ID);
1204 }
1205
1206 if(
1207 CIBlock::GetArrayByID($db_record["IBLOCK_ID"], "SECTION_PROPERTY") === "Y"
1208 && array_key_exists("SECTION_PROPERTY", $arFields)
1209 && is_array($arFields["SECTION_PROPERTY"])
1210 )
1211 {
1212 CIBlockSectionPropertyLink::DeleteBySection($ID, array_keys($arFields["SECTION_PROPERTY"]));
1213 foreach($arFields["SECTION_PROPERTY"] as $PROPERTY_ID => $arLink)
1214 CIBlockSectionPropertyLink::Set($ID, $PROPERTY_ID, $arLink);
1215 }
1216 if (
1217 CIBlock::GetArrayByID($db_record["IBLOCK_ID"], "PROPERTY_INDEX") === "Y"
1218 && isset($arFields['IBLOCK_SECTION_ID'])
1219 && $arFields['IBLOCK_SECTION_ID'] != $db_record['IBLOCK_SECTION_ID']
1220 )
1221 {
1222 Iblock\PropertyIndex\Manager::markAsInvalid($db_record["IBLOCK_ID"]);
1223 }
1224
1225 if($bUpdateSearch)
1227
1228 if($arIBlock["FIELDS"]["LOG_SECTION_EDIT"]["IS_REQUIRED"] == "Y")
1229 {
1230 $USER_ID = is_object($USER)? intval($USER->GetID()) : 0;
1231 $arEvents = GetModuleEvents("main", "OnBeforeEventLog", true);
1232 if(empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID))===false)
1233 {
1234 $rsSection = CIBlockSection::GetList(array(), array("=ID"=>$ID), false, array("LIST_PAGE_URL", "NAME", "CODE"));
1235 $arSection = $rsSection->GetNext();
1236 $res = array(
1237 "ID" => $ID,
1238 "CODE" => $arSection["CODE"],
1239 "NAME" => $arSection["NAME"],
1240 "SECTION_NAME" => $arIBlock["SECTION_NAME"],
1241 "USER_ID" => $USER_ID,
1242 "IBLOCK_PAGE_URL" => $arSection["LIST_PAGE_URL"],
1243 );
1245 "IBLOCK",
1246 "IBLOCK_SECTION_EDIT",
1247 "iblock",
1248 $arIBlock["ID"],
1249 serialize($res)
1250 );
1251 }
1252 }
1253
1254 $Result = true;
1255
1256 /*********** QUOTA ***************/
1258 /*********** QUOTA ***************/
1259 }
1260
1261 $arFields["ID"] = $ID;
1262 $arFields["IBLOCK_ID"] = $db_record["IBLOCK_ID"];
1263 $arFields["RESULT"] = &$Result;
1264
1265 foreach (GetModuleEvents("iblock", "OnAfterIBlockSectionUpdate", true) as $arEvent)
1267
1268 CIBlock::clearIblockTagCache($arIBlock['ID']);
1269
1270 return $Result;
1271 }
1272
1274 // Function delete section by its ID
1276 public static function Delete($ID, $bCheckPermissions = true)
1277 {
1278 global $DB, $APPLICATION, $USER;
1279
1280 $ID = (int)$ID;
1281 if ($ID <= 0)
1282 {
1283 return false;
1284 }
1285
1286 $APPLICATION->ResetException();
1287 foreach (GetModuleEvents("iblock", "OnBeforeIBlockSectionDelete", true) as $arEvent)
1288 {
1289 if(ExecuteModuleEventEx($arEvent, array($ID))===false)
1290 {
1291 $err = GetMessage("MAIN_BEFORE_DEL_ERR").' '.$arEvent['TO_NAME'];
1292 if($ex = $APPLICATION->GetException())
1293 $err .= ': '.$ex->GetString();
1294 $APPLICATION->ThrowException($err);
1295 return false;
1296 }
1297 }
1298
1299 $s = CIBlockSection::GetList(Array(), Array("ID"=>$ID, "CHECK_PERMISSIONS"=>($bCheckPermissions? "Y": "N")));
1300 if($s = $s->Fetch())
1301 {
1302 CIBlock::_transaction_lock($s["IBLOCK_ID"]);
1303
1304 $iblockelements = CIBlockElement::GetList(
1305 array(),
1306 array("SECTION_ID" => $ID, "SHOW_HISTORY" => "Y", "IBLOCK_ID" => $s["IBLOCK_ID"]),
1307 false,
1308 false,
1309 array("ID", "IBLOCK_ID", "WF_PARENT_ELEMENT_ID", "IBLOCK_SECTION_ID")
1310 );
1311 while($iblockelement = $iblockelements->Fetch())
1312 {
1313 $elementId = (int)$iblockelement["ID"];
1314 $strSql = "
1315 SELECT IBLOCK_SECTION_ID
1316 FROM b_iblock_section_element
1317 WHERE
1318 IBLOCK_ELEMENT_ID = ".$elementId."
1319 AND IBLOCK_SECTION_ID<>".$ID."
1320 AND ADDITIONAL_PROPERTY_ID IS NULL
1321 ORDER BY
1322 IBLOCK_SECTION_ID
1323 ";
1324 $db_section_element = $DB->Query($strSql);
1325 if($ar_section_element = $db_section_element->Fetch())
1326 {
1327 if ((int)$iblockelement["IBLOCK_SECTION_ID"] == $ID)
1328 {
1329 $DB->Query("
1330 UPDATE b_iblock_element
1331 SET IBLOCK_SECTION_ID=".$ar_section_element["IBLOCK_SECTION_ID"]."
1332 WHERE ID=".$elementId."
1333 ");
1334 }
1335 }
1336 elseif((int)$iblockelement["WF_PARENT_ELEMENT_ID"]<=0)
1337 {
1338 if(!CIBlockElement::Delete($iblockelement["ID"]))
1339 return false;
1340 }
1341 else
1342 {
1343 $DB->Query("
1344 UPDATE b_iblock_element
1345 SET IBLOCK_SECTION_ID=NULL, IN_SECTIONS='N'
1346 WHERE ID=".$elementId."
1347 ");
1348 }
1349 unset($elementId);
1350 }
1351
1352 $iblocksections = CIBlockSection::GetList(
1353 array(),
1354 array("SECTION_ID"=>$ID, "CHECK_PERMISSIONS"=>($bCheckPermissions? "Y": "N")),
1355 false,
1356 array("ID")
1357 );
1358 while($iblocksection = $iblocksections->Fetch())
1359 {
1360 if(!CIBlockSection::Delete($iblocksection["ID"], $bCheckPermissions))
1361 return false;
1362 }
1363
1364 CFile::Delete($s["PICTURE"]);
1365 CFile::Delete($s["DETAIL_PICTURE"]);
1366
1367 static $arDelCache;
1368 if(!is_array($arDelCache))
1369 $arDelCache = Array();
1370 if (!isset($arDelCache[$s["IBLOCK_ID"]]))
1371 {
1372 $arDelCache[$s["IBLOCK_ID"]] = [];
1373 $db_ps = $DB->Query("SELECT ID,IBLOCK_ID,VERSION,MULTIPLE FROM b_iblock_property WHERE PROPERTY_TYPE='G' AND (LINK_IBLOCK_ID=".$s["IBLOCK_ID"]." OR LINK_IBLOCK_ID=0 OR LINK_IBLOCK_ID IS NULL)");
1374 while($ar_ps = $db_ps->Fetch())
1375 {
1376 if($ar_ps["VERSION"]==2)
1377 {
1378 if($ar_ps["MULTIPLE"]=="Y")
1379 $strTable = "b_iblock_element_prop_m".$ar_ps["IBLOCK_ID"];
1380 else
1381 $strTable = "b_iblock_element_prop_s".$ar_ps["IBLOCK_ID"];
1382 }
1383 else
1384 {
1385 $strTable = "b_iblock_element_property";
1386 }
1387 if (!isset($arDelCache[$s["IBLOCK_ID"]][$strTable]))
1388 {
1389 $arDelCache[$s["IBLOCK_ID"]][$strTable] = [];
1390 }
1391 $arDelCache[$s["IBLOCK_ID"]][$strTable][] = $ar_ps["ID"];
1392 }
1393 }
1394
1395 if (!empty($arDelCache[$s["IBLOCK_ID"]]))
1396 {
1397 foreach($arDelCache[$s["IBLOCK_ID"]] as $strTable=>$arProps)
1398 {
1399 if(strncmp("b_iblock_element_prop_s", $strTable, 23)==0)
1400 {
1401 $tableFields = $DB->GetTableFields($strTable);
1402 foreach($arProps as $prop_id)
1403 {
1404 $strSql = "UPDATE ".$strTable." SET PROPERTY_".$prop_id."=null";
1405 if (isset($tableFields["DESCRIPTION_".$prop_id]))
1406 $strSql .= ",DESCRIPTION_".$prop_id."=null";
1407 $strSql .= " WHERE PROPERTY_".$prop_id."=".$s["ID"];
1408 if(!$DB->Query($strSql))
1409 return false;
1410 }
1411 }
1412 elseif(strncmp("b_iblock_element_prop_m", $strTable, 23)==0)
1413 {
1414 $tableFields = $DB->GetTableFields(str_replace("prop_m", "prop_s", $strTable));
1415 $strSql = "SELECT IBLOCK_PROPERTY_ID, IBLOCK_ELEMENT_ID FROM ".$strTable." WHERE IBLOCK_PROPERTY_ID IN (".implode(", ", $arProps).") AND VALUE_NUM=".$s["ID"];
1416 $rs = $DB->Query($strSql);
1417 while($ar = $rs->Fetch())
1418 {
1419 $strSql = "
1420 UPDATE ".str_replace("prop_m", "prop_s", $strTable)."
1421 SET PROPERTY_".$ar["IBLOCK_PROPERTY_ID"]."=null
1422 ".(isset($tableFields["DESCRIPTION_".$ar["IBLOCK_PROPERTY_ID"]])? ",DESCRIPTION_".$ar["IBLOCK_PROPERTY_ID"]."=null": "")."
1423 WHERE IBLOCK_ELEMENT_ID = ".$ar["IBLOCK_ELEMENT_ID"]."
1424 ";
1425 if(!$DB->Query($strSql))
1426 return false;
1427 }
1428 $strSql = "DELETE FROM ".$strTable." WHERE IBLOCK_PROPERTY_ID IN (".implode(", ", $arProps).") AND VALUE_NUM=".$s["ID"];
1429 if(!$DB->Query($strSql))
1430 return false;
1431 }
1432 else
1433 {
1434 $strSql = "DELETE FROM ".$strTable." WHERE IBLOCK_PROPERTY_ID IN (".implode(", ", $arProps).") AND VALUE_NUM=".$s["ID"];
1435 if(!$DB->Query($strSql))
1436 return false;
1437 }
1438 }
1439 }
1440
1441 CIBlockSectionPropertyLink::DeleteBySection($ID);
1442 $DB->Query("DELETE FROM b_iblock_section_element WHERE IBLOCK_SECTION_ID=".$ID);
1443
1444 if(CModule::IncludeModule("search"))
1445 CSearch::DeleteIndex("iblock", "S".$ID);
1446
1447 $GLOBALS["USER_FIELD_MANAGER"]->Delete("IBLOCK_".$s["IBLOCK_ID"]."_SECTION", $ID);
1448
1449 //Delete the hole in the tree
1451
1452 $obSectionRights = new CIBlockSectionRights($s["IBLOCK_ID"], $ID);
1453 $obSectionRights->DeleteAllRights();
1454
1455 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\SectionTemplates($s["IBLOCK_ID"], $ID);
1456 $ipropTemplates->delete();
1457
1458 /************* QUOTA *************/
1460 /************* QUOTA *************/
1461
1462 $arIBlockFields = CIBlock::GetArrayByID($s["IBLOCK_ID"], "FIELDS");
1463 if($arIBlockFields["LOG_SECTION_DELETE"]["IS_REQUIRED"] == "Y")
1464 {
1465 $USER_ID = is_object($USER)? intval($USER->GetID()) : 0;
1466 $arEvents = GetModuleEvents("main", "OnBeforeEventLog", true);
1467 if(empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID))===false)
1468 {
1469 $rsSection = CIBlockSection::GetList(
1470 array(),
1471 array("=ID"=>$ID, "CHECK_PERMISSIONS"=>($bCheckPermissions? "Y": "N")),
1472 false,
1473 array("LIST_PAGE_URL", "NAME", "CODE")
1474 );
1475 $arSection = $rsSection->GetNext();
1476 $res = array(
1477 "ID" => $ID,
1478 "CODE" => $arSection["CODE"],
1479 "NAME" => $arSection["NAME"],
1480 "SECTION_NAME" => CIBlock::GetArrayByID($s["IBLOCK_ID"], "SECTION_NAME"),
1481 "USER_ID" => $USER_ID,
1482 "IBLOCK_PAGE_URL" => $arSection["LIST_PAGE_URL"],
1483 );
1485 "IBLOCK",
1486 "IBLOCK_SECTION_DELETE",
1487 "iblock",
1488 $s["IBLOCK_ID"],
1489 serialize($res)
1490 );
1491 }
1492 }
1493
1494 $res = $DB->Query("DELETE FROM b_iblock_section WHERE ID=".$ID);
1495
1496 if($res)
1497 {
1498 foreach (GetModuleEvents("iblock", "OnAfterIBlockSectionDelete", true) as $arEvent)
1499 ExecuteModuleEventEx($arEvent, array($s));
1500
1501 CIBlock::clearIblockTagCache($s['IBLOCK_ID']);
1502 }
1503
1504 return $res;
1505 }
1506
1507 return true;
1508 }
1509
1511 // Check function called from Add and Update
1513 public function CheckFields(&$arFields, $ID=false)
1514 {
1515 global $DB, $APPLICATION;
1516 $this->LAST_ERROR = "";
1517
1518 if(($ID===false || array_key_exists("NAME", $arFields)) && (string)$arFields["NAME"] === '')
1519 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION")."<br>";
1520
1521 $pictureIsArray = isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]);
1522 if (
1523 $pictureIsArray
1524 && array_key_exists("bucket", $arFields["PICTURE"])
1525 && is_object($arFields["PICTURE"]["bucket"])
1526 )
1527 {
1528 //This is trusted image from xml import
1529 }
1530 elseif(
1531 $pictureIsArray
1532 && isset($arFields["PICTURE"]["name"])
1533 )
1534 {
1535 $error = CFile::CheckImageFile($arFields["PICTURE"]);
1536 if ($error <> '')
1537 $this->LAST_ERROR .= $error."<br>";
1538 }
1539
1540 $detailPictureIsArray = isset($arFields["DETAIL_PICTURE"]) && is_array($arFields["DETAIL_PICTURE"]);
1541 if(
1542 $detailPictureIsArray
1543 && array_key_exists("bucket", $arFields["DETAIL_PICTURE"])
1544 && is_object($arFields["DETAIL_PICTURE"]["bucket"])
1545 )
1546 {
1547 //This is trusted image from xml import
1548 }
1549 elseif(
1550 $detailPictureIsArray
1551 && isset($arFields["DETAIL_PICTURE"]["name"])
1552 )
1553 {
1554 $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]);
1555 if ($error <> '')
1556 $this->LAST_ERROR .= $error."<br>";
1557 }
1558
1559 $arIBlock = false;
1560 $arThis = false;
1561
1562 if($ID === false)
1563 {
1564 if(!array_key_exists("IBLOCK_ID", $arFields))
1565 {
1566 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
1567 }
1568 else
1569 {
1570 $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]);
1571 if(!$arIBlock)
1572 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
1573 }
1574 }
1575 else
1576 {
1577 $rsThis = $DB->Query("SELECT ID, IBLOCK_ID, DETAIL_PICTURE, PICTURE FROM b_iblock_section WHERE ID = ".intval($ID));
1578 $arThis = $rsThis->Fetch();
1579 if(!$arThis)
1580 {
1581 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_ID", array("#ID#" => intval($ID)))."<br>";
1582 }
1583 else
1584 {
1585 $arIBlock = CIBlock::GetArrayByID($arThis["IBLOCK_ID"]);
1586 if(!$arIBlock)
1587 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
1588 }
1589 }
1590
1591 $arParent = false;
1592 $IBLOCK_SECTION_ID = (int)($arFields['IBLOCK_SECTION_ID'] ?? 0);
1593
1594 if ($IBLOCK_SECTION_ID > 0 && $ID !== false && $this->LAST_ERROR === '')
1595 {
1596 if ($IBLOCK_SECTION_ID === (int)$ID)
1597 {
1598 $this->LAST_ERROR .= GetMessage('IBLOCK_BAD_BLOCK_SECTION_RECURSE') . '<br>';
1599 }
1600 }
1601
1602 if ($IBLOCK_SECTION_ID > 0 && $this->LAST_ERROR === '')
1603 {
1604 $sqlCheck = 'select ID, IBLOCK_ID from b_iblock_section where ID = ' . $IBLOCK_SECTION_ID;
1605 $rsParent = $DB->Query($sqlCheck);
1606 $arParent = $rsParent->Fetch();
1607 if (!$arParent)
1608 {
1609 $this->LAST_ERROR = GetMessage('IBLOCK_BAD_BLOCK_SECTION_PARENT') . '<br>';
1610 }
1611 }
1612
1613 if($arParent && $arIBlock)
1614 {
1615 if($arParent["IBLOCK_ID"] != $arIBlock["ID"])
1616 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_ID_PARENT")."<br>";
1617 }
1618
1619 if($arParent && ($this->LAST_ERROR == ''))
1620 {
1621 $rch = $DB->Query("
1622 SELECT 'x'
1623 FROM
1624 b_iblock_section bsto
1625 ,b_iblock_section bsfrom
1626 WHERE
1627 bsto.ID = ".$arParent["ID"]."
1628 AND bsfrom.ID = ".intval($ID)."
1629 AND bsto.LEFT_MARGIN >= bsfrom.LEFT_MARGIN
1630 AND bsto.LEFT_MARGIN <= bsfrom.RIGHT_MARGIN
1631 ");
1632 if($rch->Fetch())
1633 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_RECURSE")."<br>";
1634 }
1635
1636 if($arIBlock)
1637 {
1638 if(
1639 array_key_exists("CODE", $arFields)
1640 && (string)$arFields['CODE'] !== ''
1641 && is_array($arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"])
1642 && $arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y"
1643 )
1644 {
1645 $res = $DB->Query("
1646 SELECT ID
1647 FROM b_iblock_section
1648 WHERE IBLOCK_ID = ".$arIBlock["ID"]."
1649 AND CODE = '".$DB->ForSQL((string)$arFields['CODE'])."'
1650 AND ID <> ".(int)$ID
1651 );
1652 if($res->Fetch())
1653 $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_SECTION_CODE")."<br>";
1654 }
1655
1656 foreach($arIBlock["FIELDS"] as $FIELD_ID => $field)
1657 {
1658 if(!preg_match("/^SECTION_(.+)$/", $FIELD_ID, $match))
1659 continue;
1660
1661 $FIELD_ID = $match[1];
1662
1663 if($field["IS_REQUIRED"] === "Y")
1664 {
1665 switch($FIELD_ID)
1666 {
1667 case "NAME":
1668 case "DESCRIPTION_TYPE":
1669 //We should never check for this fields
1670 break;
1671 case "PICTURE":
1672 $field["NAME"] = GetMessage("IBLOCK_FIELD_PICTURE");
1673 case "DETAIL_PICTURE":
1674 if($arThis && $arThis[$FIELD_ID] > 0)
1675 {//There was an picture so just check that it is not deleted
1676 if(
1677 array_key_exists($FIELD_ID, $arFields)
1678 && is_array($arFields[$FIELD_ID])
1679 && $arFields[$FIELD_ID]["del"] === "Y"
1680 )
1681 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
1682 }
1683 else
1684 {//There was NO picture so it MUST be present
1685 if(!array_key_exists($FIELD_ID, $arFields))
1686 {
1687 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
1688 }
1689 elseif(is_array($arFields[$FIELD_ID]))
1690 {
1691 if(
1692 $arFields[$FIELD_ID]["del"] === "Y"
1693 || (array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0)
1694 || $arFields[$FIELD_ID]["size"] <= 0
1695 )
1696 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
1697 }
1698 else
1699 {
1700 if(intval($arFields[$FIELD_ID]) <= 0)
1701 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
1702 }
1703 }
1704 break;
1705 default:
1706 if($ID===false || array_key_exists($FIELD_ID, $arFields))
1707 {
1708 if(is_array($arFields[$FIELD_ID]))
1709 $val = implode("", $arFields[$FIELD_ID]);
1710 else
1711 $val = $arFields[$FIELD_ID];
1712 if($val == '')
1713 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
1714 }
1715 break;
1716 }
1717 }
1718 }
1719 }
1720
1721 $APPLICATION->ResetException();
1722 if($ID===false)
1723 $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionAdd", true);
1724 else
1725 {
1726 $arFields["ID"] = $ID;
1727 $arFields["IBLOCK_ID"] = $arIBlock["ID"];
1728 $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionUpdate", true);
1729 }
1730
1731 /****************************** QUOTA ******************************/
1732 if(empty($this->LAST_ERROR) && (COption::GetOptionInt("main", "disk_space") > 0))
1733 {
1734 $quota = new CDiskQuota();
1735 if(!$quota->checkDiskQuota($arFields))
1736 $this->LAST_ERROR = $quota->LAST_ERROR;
1737 }
1738 /****************************** QUOTA ******************************/
1739
1740 foreach ($db_events as $arEvent)
1741 {
1742 $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
1743 if($bEventRes===false)
1744 {
1745 if($err = $APPLICATION->GetException())
1746 $this->LAST_ERROR .= $err->GetString()."<br>";
1747 else
1748 {
1749 $APPLICATION->ThrowException("Unknown error");
1750 $this->LAST_ERROR .= "Unknown error.<br>";
1751 }
1752 break;
1753 }
1754 }
1755
1756 if($this->LAST_ERROR <> '')
1757 return false;
1758
1759 return true;
1760 }
1761
1762 public static function TreeReSort($IBLOCK_ID, $ID=0, $cnt=0, $depth=0, $ACTIVE="Y")
1763 {
1764 global $DB;
1765 $IBLOCK_ID = (int)$IBLOCK_ID;
1766
1767 if($ID==0)
1768 {
1769 CIBlock::_transaction_lock($IBLOCK_ID);
1770 }
1771
1772 if($ID > 0)
1773 {
1774 $DB->Query("
1775 UPDATE
1776 b_iblock_section
1777 SET
1778 TIMESTAMP_X=".($DB->type=="ORACLE"?"NULL":"TIMESTAMP_X")."
1779 ,RIGHT_MARGIN=".(int)$cnt."
1780 ,LEFT_MARGIN=".(int)$cnt."
1781 WHERE
1782 ID=".(int)$ID
1783 );
1784 }
1785
1786 $strSql = "
1787 SELECT BS.ID, BS.ACTIVE
1788 FROM b_iblock_section BS
1789 WHERE BS.IBLOCK_ID = ".$IBLOCK_ID."
1790 AND ".($ID>0? "BS.IBLOCK_SECTION_ID=".(int)$ID: "BS.IBLOCK_SECTION_ID IS NULL")."
1791 ORDER BY BS.SORT, BS.NAME
1792 ";
1793
1794 $cnt++;
1795 $res = $DB->Query($strSql);
1796 while($arr = $res->Fetch())
1797 $cnt = CIBlockSection::TreeReSort($IBLOCK_ID, $arr["ID"], $cnt, $depth+1, ($ACTIVE=="Y" && $arr["ACTIVE"]=="Y" ? "Y" : "N"));
1798
1799 if($ID==0)
1800 {
1801 return true;
1802 }
1803
1804 $DB->Query("
1805 UPDATE
1806 b_iblock_section
1807 SET
1808 TIMESTAMP_X=".($DB->type=="ORACLE"?"NULL":"TIMESTAMP_X")."
1809 ,RIGHT_MARGIN=".(int)$cnt."
1810 ,DEPTH_LEVEL=".(int)$depth."
1811 ,GLOBAL_ACTIVE='".$ACTIVE."'
1812 WHERE
1813 ID=".(int)$ID
1814 );
1815
1816 return $cnt+1;
1817 }
1818
1819 public static function ReSort($IBLOCK_ID, $ID=0, $cnt=0, $depth=0, $ACTIVE="Y")
1820 {
1821 $cnt = self::TreeReSort($IBLOCK_ID, $ID, $cnt, $depth, $ACTIVE);
1822 $obIBlockRights = new CIBlockRights($IBLOCK_ID);
1823 $obIBlockRights->Recalculate();
1824
1825 return $cnt;
1826 }
1827
1828 public function UpdateSearch($ID, $bOverWrite=false)
1829 {
1830 if(!CModule::IncludeModule("search")) return;
1831
1832 global $DB;
1833 $ID = intval($ID);
1834
1835 static $arGroups = array();
1836 static $arSITE = array();
1837
1838 $strSql = "
1839 SELECT BS.ID, BS.NAME, BS.DESCRIPTION_TYPE, BS.DESCRIPTION, BS.XML_ID as EXTERNAL_ID,
1840 BS.CODE, BS.IBLOCK_ID, B.IBLOCK_TYPE_ID,
1841 ".$DB->DateToCharFunction("BS.TIMESTAMP_X")." as LAST_MODIFIED,
1842 B.CODE as IBLOCK_CODE, B.XML_ID as IBLOCK_EXTERNAL_ID, B.SECTION_PAGE_URL,
1843 B.ACTIVE as ACTIVE1,
1844 BS.GLOBAL_ACTIVE as ACTIVE2,
1845 B.INDEX_SECTION, B.RIGHTS_MODE
1846 FROM b_iblock_section BS, b_iblock B
1847 WHERE BS.IBLOCK_ID=B.ID
1848 AND BS.ID=".$ID;
1849
1850 $dbrIBlockSection = $DB->Query($strSql);
1851
1852 if($arIBlockSection = $dbrIBlockSection->Fetch())
1853 {
1854 $IBLOCK_ID = $arIBlockSection["IBLOCK_ID"];
1855 $SECTION_URL =
1856 "=ID=".$arIBlockSection["ID"].
1857 "&EXTERNAL_ID=".$arIBlockSection["EXTERNAL_ID"].
1858 "&IBLOCK_TYPE_ID=".$arIBlockSection["IBLOCK_TYPE_ID"].
1859 "&IBLOCK_ID=".$arIBlockSection["IBLOCK_ID"].
1860 "&IBLOCK_CODE=".$arIBlockSection["IBLOCK_CODE"].
1861 "&IBLOCK_EXTERNAL_ID=".$arIBlockSection["IBLOCK_EXTERNAL_ID"].
1862 "&CODE=".$arIBlockSection["CODE"];
1863
1864 if($arIBlockSection["ACTIVE1"]!="Y" || $arIBlockSection["ACTIVE2"]!="Y" || $arIBlockSection["INDEX_SECTION"]!="Y")
1865 {
1866 CSearch::DeleteIndex("iblock", "S".$arIBlockSection["ID"]);
1867 return;
1868 }
1869
1870 if(!array_key_exists($IBLOCK_ID, $arGroups))
1871 {
1873 $strSql =
1874 "SELECT GROUP_ID ".
1875 "FROM b_iblock_group ".
1876 "WHERE IBLOCK_ID= ".$IBLOCK_ID." ".
1877 " AND PERMISSION>='" . CIBlockRights::PUBLIC_READ . "' ".
1878 "ORDER BY GROUP_ID";
1879
1880 $dbrIBlockGroup = $DB->Query($strSql);
1881 while($arIBlockGroup = $dbrIBlockGroup->Fetch())
1882 {
1883 $arGroups[$IBLOCK_ID][] = $arIBlockGroup["GROUP_ID"];
1884 if($arIBlockGroup["GROUP_ID"]==2) break;
1885 }
1886 }
1887
1888 if(!array_key_exists($IBLOCK_ID, $arSITE))
1889 {
1890 $arSITE[$IBLOCK_ID] = array();
1891 $strSql =
1892 "SELECT SITE_ID ".
1893 "FROM b_iblock_site ".
1894 "WHERE IBLOCK_ID= ".$IBLOCK_ID;
1895
1896 $dbrIBlockSite = $DB->Query($strSql);
1897 while($arIBlockSite = $dbrIBlockSite->Fetch())
1898 $arSITE[$IBLOCK_ID][] = $arIBlockSite["SITE_ID"];
1899 }
1900
1901 $BODY =
1902 ($arIBlockSection["DESCRIPTION_TYPE"]=="html" ?
1903 CSearch::KillTags($arIBlockSection["DESCRIPTION"])
1904 :
1905 $arIBlockSection["DESCRIPTION"]
1906 );
1907
1908 $BODY .= $GLOBALS["USER_FIELD_MANAGER"]->OnSearchIndex("IBLOCK_".$arIBlockSection["IBLOCK_ID"]."_SECTION", $arIBlockSection["ID"]);
1909
1910 if($arIBlockSection["RIGHTS_MODE"] !== "E")
1911 $arPermissions = $arGroups[$IBLOCK_ID];
1912 else
1913 {
1914 $obSectionRights = new CIBlockSectionRights($IBLOCK_ID, $arIBlockSection["ID"]);
1915 $arPermissions = $obSectionRights->GetGroups(array("section_read"));
1916 }
1917
1918 CSearch::Index("iblock", "S".$ID, array(
1919 "LAST_MODIFIED" => $arIBlockSection["LAST_MODIFIED"],
1920 "TITLE" => $arIBlockSection["NAME"],
1921 "PARAM1" => $arIBlockSection["IBLOCK_TYPE_ID"],
1922 "PARAM2" => $IBLOCK_ID,
1923 "SITE_ID" => $arSITE[$IBLOCK_ID],
1924 "PERMISSIONS" => $arPermissions,
1925 "URL" => $SECTION_URL,
1926 "BODY" => $BODY,
1927 ), $bOverWrite);
1928 }
1929 }
1930
1938 public static function GetMixedList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt = false, $arSelectedFields = false)
1939 {
1940 $arResult = [];
1941
1942 if (!is_array($arOrder))
1943 {
1944 $arOrder = ['SORT' => 'ASC'];
1945 }
1946
1947 if (!is_array($arSelectedFields))
1948 {
1949 $arSelectedFields = [];
1950 };
1951 $emptySelect = empty($arSelectedFields) || in_array('*', $arSelectedFields);
1952
1953 if (!empty($arFilter))
1954 {
1955 $arFilter = array_change_key_case($arFilter, CASE_UPPER);
1956 }
1957
1958 $arFilter = static::normalizeMixedFilter($arFilter);
1959
1960 if (static::checkLoadSections($arFilter))
1961 {
1962 $arSectionFilter = $arFilter;
1963
1964 $sectionFields = [
1965 'ID' => true,
1966 'CODE' => true,
1967 'XML_ID' => true,
1968 'EXTERNAL_ID' => true,
1969 'IBLOCK_ID' => true,
1970 'IBLOCK_SECTION_ID' => true,
1971 'TIMESTAMP_X' => true,
1972 'TIMESTAMP_X_UNIX' => true,
1973 'SORT' => true,
1974 'NAME' => true,
1975 'ACTIVE' => true,
1976 'GLOBAL_ACTIVE' => true,
1977 'PICTURE' => true,
1978 'DESCRIPTION' => true,
1979 'DESCRIPTION_TYPE' => true,
1980 'LEFT_MARGIN' => true,
1981 'RIGHT_MARGIN' => true,
1982 'DEPTH_LEVEL' => true,
1983 'SEARCHABLE_CONTENT' => true,
1984 'MODIFIED_BY' => true,
1985 'DATE_CREATE' => true,
1986 'DATE_CREATE_UNIX' => true,
1987 'CREATED_BY' => true,
1988 'DETAIL_PICTURE' => true,
1989 'TMP_ID' => true,
1990
1991 'LIST_PAGE_URL' => true,
1992 'SECTION_PAGE_URL' => true,
1993 'IBLOCK_TYPE_ID' => true,
1994 'IBLOCK_CODE' => true,
1995 'IBLOCK_EXTERNAL_ID' => true,
1996 'SOCNET_GROUP_ID' => true,
1997 ];
1998
1999 if ($emptySelect)
2000 {
2001 $sectionSelect = array_keys($sectionFields);
2002 }
2003 else
2004 {
2005 $sectionSelect = [];
2006 foreach ($arSelectedFields as $field)
2007 {
2008 if (!isset($sectionFields[$field]))
2009 {
2010 continue;
2011 }
2012 $sectionSelect[$field] = $field;
2013 }
2014 unset($field);
2015 if (!empty($sectionSelect))
2016 {
2017 $sectionSelect = array_values($sectionSelect);
2018 }
2019 }
2020
2021 $obSection = new CIBlockSection;
2022 $rsSection = $obSection->GetList($arOrder, $arSectionFilter, $bIncCnt, $sectionSelect);
2023 while ($arSection = $rsSection->Fetch())
2024 {
2025 $arSection['TYPE'] = Iblock\Grid\RowType::SECTION;
2026 $arResult[] = $arSection;
2027 }
2028 unset($arSection);
2029 unset($rsSection);
2030 unset($obSection);
2031 }
2032
2033 if (static::checkLoadElements($arFilter))
2034 {
2035 $arElementFilter = $arFilter;
2036 $arElementFilter['SHOW_NEW'] = ($arFilter['SHOW_NEW'] ?? 'Y') === 'N' ? 'N' : 'Y';
2037
2038 if ($emptySelect)
2039 {
2040 $arSelectedFields = ["*"];
2041 }
2042
2043 $obElement = new CIBlockElement;
2044
2045 $rsElement = $obElement->GetList($arOrder, $arElementFilter, false, false, $arSelectedFields);
2046 while ($arElement = $rsElement->Fetch())
2047 {
2048 $arElement['TYPE'] = Iblock\Grid\RowType::ELEMENT;
2049 $arResult[] = $arElement;
2050 }
2051 unset($arElement);
2052 unset($rsElement);
2053 unset($obElement);
2054 }
2055
2056 $rsResult = new CDBResult;
2057 $rsResult->InitFromArray($arResult);
2058 unset($arResult);
2059
2060 return $rsResult;
2061 }
2062
2064 // GetSectionElementsCount($ID, $arFilter=Array())
2066 public static function GetSectionElementsCount($ID, $arFilter=Array())
2067 {
2068 global $DB;
2069
2070 $arJoinProps = array();
2071 $bJoinFlatProp = false;
2072 $arSqlSearch = array();
2073
2074 if(array_key_exists("PROPERTY", $arFilter))
2075 {
2076 $val = $arFilter["PROPERTY"];
2077 foreach($val as $propID=>$propVAL)
2078 {
2079 $res = CIBlock::MkOperationFilter($propID);
2080 $propID = $res["FIELD"];
2081 $cOperationType = $res["OPERATION"];
2082 if($db_prop = CIBlockProperty::GetPropertyArray($propID, CIBlock::_MergeIBArrays($arFilter["IBLOCK_ID"], $arFilter["IBLOCK_CODE"])))
2083 {
2084
2085 $bSave = false;
2086 if(array_key_exists($db_prop["ID"], $arJoinProps))
2087 $iPropCnt = $arJoinProps[$db_prop["ID"]];
2088 elseif($db_prop["VERSION"]!=2 || $db_prop["MULTIPLE"]=="Y")
2089 {
2090 $bSave = true;
2091 $iPropCnt=count($arJoinProps);
2092 }
2093
2094 if(!is_array($propVAL))
2095 $propVAL = Array($propVAL);
2096
2097 if($db_prop["PROPERTY_TYPE"]=="N" || $db_prop["PROPERTY_TYPE"]=="G" || $db_prop["PROPERTY_TYPE"]=="E")
2098 {
2099 if($db_prop["VERSION"]==2 && $db_prop["MULTIPLE"]=="N")
2100 {
2101 $r = CIBlock::FilterCreate("FPS.PROPERTY_".$db_prop["ORIG_ID"], $propVAL, "number", $cOperationType);
2102 $bJoinFlatProp = $db_prop["IBLOCK_ID"];
2103 }
2104 else
2105 $r = CIBlock::FilterCreate("FPV".$iPropCnt.".VALUE_NUM", $propVAL, "number", $cOperationType);
2106 }
2107 else
2108 {
2109 if($db_prop["VERSION"]==2 && $db_prop["MULTIPLE"]=="N")
2110 {
2111 $r = CIBlock::FilterCreate("FPS.PROPERTY_".$db_prop["ORIG_ID"], $propVAL, "string", $cOperationType);
2112 $bJoinFlatProp = $db_prop["IBLOCK_ID"];
2113 }
2114 else
2115 $r = CIBlock::FilterCreate("FPV".$iPropCnt.".VALUE", $propVAL, "string", $cOperationType);
2116 }
2117
2118 if($r <> '')
2119 {
2120 if($bSave)
2121 {
2122 $db_prop["iPropCnt"] = $iPropCnt;
2123 $arJoinProps[$db_prop["ID"]] = $db_prop;
2124 }
2125 $arSqlSearch[] = $r;
2126 }
2127 }
2128 }
2129 }
2130
2131 $strSqlSearch = "";
2132 foreach($arSqlSearch as $r)
2133 if($r <> '')
2134 $strSqlSearch .= "\n\t\t\t\tAND (".$r.") ";
2135
2136 $strSqlSearchProp = "";
2137 foreach($arJoinProps as $propID=>$db_prop)
2138 {
2139 if($db_prop["VERSION"]==2)
2140 $strTable = "b_iblock_element_prop_m".$db_prop["IBLOCK_ID"];
2141 else
2142 $strTable = "b_iblock_element_property";
2143 $i = $db_prop["iPropCnt"];
2144 $strSqlSearchProp .= "
2145 INNER JOIN b_iblock_property FP".$i." ON FP".$i.".IBLOCK_ID=BS.IBLOCK_ID AND
2146 ".(intval($propID)>0?" FP".$i.".ID=".intval($propID)." ":" FP".$i.".CODE='".$DB->ForSQL($propID, 200)."' ")."
2147 INNER JOIN ".$strTable." FPV".$i." ON FP".$i.".ID=FPV".$i.".IBLOCK_PROPERTY_ID AND FPV".$i.".IBLOCK_ELEMENT_ID=BE.ID
2148 ";
2149 }
2150 if($bJoinFlatProp)
2151 $strSqlSearchProp .= "
2152 INNER JOIN b_iblock_element_prop_s".$bJoinFlatProp." FPS ON FPS.IBLOCK_ELEMENT_ID = BE.ID
2153 ";
2154
2155 $allElements = (isset($arFilter['CNT_ALL']) && $arFilter['CNT_ALL'] == 'Y');
2156 $activeElements = (isset($arFilter['CNT_ACTIVE']) && $arFilter['CNT_ACTIVE'] == 'Y');
2157
2158 $strHint = $DB->type=="MYSQL"?"STRAIGHT_JOIN":"";
2159 $strSql = "
2160 SELECT ".$strHint." COUNT(DISTINCT BE.ID) as CNT
2161 FROM b_iblock_section BS
2162 INNER JOIN b_iblock_section BSTEMP ON (BSTEMP.IBLOCK_ID=BS.IBLOCK_ID
2163 AND BSTEMP.LEFT_MARGIN >= BS.LEFT_MARGIN
2164 AND BSTEMP.RIGHT_MARGIN <= BS.RIGHT_MARGIN)
2165 INNER JOIN b_iblock_section_element BSE ON BSE.IBLOCK_SECTION_ID=BSTEMP.ID
2166 INNER JOIN b_iblock_element BE ON BE.ID=BSE.IBLOCK_ELEMENT_ID AND BE.IBLOCK_ID=BS.IBLOCK_ID
2167 ".$strSqlSearchProp."
2168 WHERE BS.ID=".intval($ID)."
2169 AND ((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL )
2170 ".($allElements ?" OR BE.WF_NEW='Y' ":"").")
2171 ".($activeElements ?
2172 " AND BE.ACTIVE='Y'
2173 AND (BE.ACTIVE_TO >= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_TO IS NULL)
2174 AND (BE.ACTIVE_FROM <= ".$DB->CurrentTimeFunction()." OR BE.ACTIVE_FROM IS NULL)"
2175 :"")."
2176 ".$strSqlSearch;
2177 //echo "<pre>",htmlspecialcharsbx($strSql),"</pre>";
2178 $res = $DB->Query($strSql);
2179 $res = $res->Fetch();
2180
2181 return (int)($res['CNT'] ?? 0);
2182 }
2183
2184 protected static function _check_rights_sql($min_permission, $permissionsBy = null)
2185 {
2186 global $DB, $USER;
2187 $min_permission = (mb_strlen($min_permission) == 1) ? $min_permission : CIBlockRights::PUBLIC_READ;
2188
2189 if ($permissionsBy !== null)
2190 $permissionsBy = (int)$permissionsBy;
2191 if ($permissionsBy < 0)
2192 $permissionsBy = null;
2193
2194 if ($permissionsBy !== null)
2195 {
2196 $iUserID = $permissionsBy;
2197 $strGroups = implode(',', CUser::GetUserGroup($permissionsBy));
2198 $bAuthorized = false;
2199 }
2200 else
2201 {
2202 if (is_object($USER))
2203 {
2204 $iUserID = (int)$USER->GetID();
2205 $strGroups = $USER->GetGroups();
2206 $bAuthorized = $USER->IsAuthorized();
2207 }
2208 else
2209 {
2210 $iUserID = 0;
2211 $strGroups = "2";
2212 $bAuthorized = false;
2213 }
2214 }
2215
2216 $stdPermissions = "
2217 SELECT IBLOCK_ID
2218 FROM b_iblock_group IBG
2219 WHERE IBG.GROUP_ID IN (".$strGroups.")
2220 AND IBG.PERMISSION >= '".$DB->ForSQL($min_permission)."'
2221 ";
2222 if(!defined("ADMIN_SECTION"))
2223 $stdPermissions .= "
2224 AND (IBG.PERMISSION='" . CIBlockRights::FULL_ACCESS . "' OR B.ACTIVE='Y')
2225 ";
2226
2227 if($min_permission >= CIBlockRights::FULL_ACCESS)
2228 $operation = 'section_rights_edit';
2229 elseif($min_permission >= CIBlockRights::EDIT_ACCESS)
2230 $operation = 'section_edit';
2231 elseif($min_permission >= CIBlockRights::PUBLIC_READ)
2232 $operation = 'section_read';
2233 else
2234 $operation = '';
2235
2236 if($operation)
2237 {
2238 $acc = new CAccess;
2239 $acc->UpdateCodes($permissionsBy !== null ? array('USER_ID' => $permissionsBy) : false);
2240 }
2241
2242 if($operation == "section_read")
2243 {
2244 $extPermissions = "
2245 SELECT SR.SECTION_ID
2246 FROM b_iblock_section_right SR
2247 INNER JOIN b_iblock_right IBR ON IBR.ID = SR.RIGHT_ID
2248 ".($iUserID > 0? "LEFT": "INNER")." JOIN b_user_access UA ON UA.ACCESS_CODE = IBR.GROUP_CODE AND UA.USER_ID = ".$iUserID."
2249 WHERE SR.SECTION_ID = BS.ID
2250 AND IBR.OP_SREAD = 'Y'
2251 ".($bAuthorized || $iUserID > 0? "
2252 AND (UA.USER_ID IS NOT NULL
2253 ".($bAuthorized? "OR IBR.GROUP_CODE = 'AU'": "")."
2254 ".($iUserID > 0? "OR (IBR.GROUP_CODE = 'CR' AND BS.CREATED_BY = ".$iUserID.")": "")."
2255 )": "")."
2256 ";
2257
2258 $strResult = "(
2259 B.ID IN ($stdPermissions)
2260 OR (B.RIGHTS_MODE = 'E' AND EXISTS ($extPermissions))
2261 )";
2262 }
2263 elseif($operation)
2264 {
2265 $extPermissions = "
2266 SELECT SR.SECTION_ID
2267 FROM b_iblock_section_right SR
2268 INNER JOIN b_iblock_right IBR ON IBR.ID = SR.RIGHT_ID
2269 INNER JOIN b_task_operation T ON T.TASK_ID = IBR.TASK_ID
2270 INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
2271 ".($iUserID > 0? "LEFT": "INNER")." JOIN b_user_access UA ON UA.ACCESS_CODE = IBR.GROUP_CODE AND UA.USER_ID = ".$iUserID."
2272 WHERE SR.SECTION_ID = BS.ID
2273 AND O.NAME = '".$operation."'
2274 ".($bAuthorized || $iUserID > 0? "
2275 AND (UA.USER_ID IS NOT NULL
2276 ".($bAuthorized? "OR IBR.GROUP_CODE = 'AU'": "")."
2277 ".($iUserID > 0? "OR (IBR.GROUP_CODE = 'CR' AND BS.CREATED_BY = ".$iUserID.")": "")."
2278 )": "")."
2279 ";
2280
2281 $strResult = "(
2282 B.ID IN ($stdPermissions)
2283 OR (B.RIGHTS_MODE = 'E' AND EXISTS ($extPermissions))
2284 )";
2285 }
2286 else
2287 {
2288 $strResult = "(
2289 B.ID IN ($stdPermissions)
2290 )";
2291 }
2292
2293 return $strResult;
2294 }
2295
2296 public static function GetCount($arFilter = [])
2297 {
2298 global $DB, $USER;
2299
2300 $arSqlSearch = CIBlockSection::GetFilter($arFilter);
2301
2302 $bCheckPermissions = !array_key_exists("CHECK_PERMISSIONS", $arFilter) || $arFilter["CHECK_PERMISSIONS"]!=="N";
2303 $bIsAdmin = is_object($USER) && $USER->IsAdmin();
2304 $permissionsBy = null;
2305 if ($bCheckPermissions && isset($arFilter['PERMISSIONS_BY']))
2306 {
2307 $permissionsBy = (int)$arFilter['PERMISSIONS_BY'];
2308 if ($permissionsBy < 0)
2309 $permissionsBy = null;
2310 }
2311 if ($bCheckPermissions && ($permissionsBy !== null || !$bIsAdmin))
2312 {
2313 $arSqlSearch[] = self::_check_rights_sql(
2314 $arFilter['MIN_PERMISSION'] ?? CIBlockRights::PUBLIC_READ,
2315 $permissionsBy
2316 );
2317 }
2318 unset($permissionsBy);
2319
2320 $strSqlSearch = "";
2321 foreach($arSqlSearch as $i=>$strSearch)
2322 if($strSearch <> '')
2323 $strSqlSearch .= "\n\t\t\tAND (".$strSearch.") ";
2324
2325 $strSql = "
2326 SELECT COUNT(DISTINCT BS.ID) as C
2327 FROM b_iblock_section BS
2328 INNER JOIN b_iblock B ON BS.IBLOCK_ID = B.ID
2329 WHERE 1=1
2330 ".$strSqlSearch."
2331 ";
2332
2333 $res = $DB->Query($strSql);
2334 $res_cnt = $res->Fetch();
2335
2336 return (int)($res_cnt["C"] ?? 0);
2337 }
2338
2339 public static function UserTypeRightsCheck($entity_id)
2340 {
2341 if(preg_match("/^IBLOCK_(\d+)_SECTION$/", $entity_id, $match))
2342 {
2343 return CIBlock::GetPermission($match[1]);
2344 }
2345 else
2346 return "D";
2347 }
2348
2349 public static function RecalcGlobalActiveFlag($arSection, $distance = 0)
2350 {
2351 global $DB;
2352
2353 $distance = (int)$distance;
2354 $arSection['LEFT_MARGIN'] += $distance;
2355 $arSection['RIGHT_MARGIN'] += $distance;
2356
2357 //Make all children globally active
2358 $DB->Query("
2359 UPDATE b_iblock_section SET
2360 TIMESTAMP_X=".($DB->type=="ORACLE"?"NULL":"TIMESTAMP_X")."
2361 ,GLOBAL_ACTIVE = 'Y'
2362 WHERE
2363 IBLOCK_ID = ".$arSection["IBLOCK_ID"]."
2364 AND LEFT_MARGIN >= ".intval($arSection["LEFT_MARGIN"])."
2365 AND RIGHT_MARGIN <= ".intval($arSection["RIGHT_MARGIN"])."
2366 ");
2367 //Select those who is not active
2368 $strSql = "
2369 SELECT ID, LEFT_MARGIN, RIGHT_MARGIN
2370 FROM b_iblock_section
2371 WHERE IBLOCK_ID = ".$arSection["IBLOCK_ID"]."
2372 AND LEFT_MARGIN >= ".intval($arSection["LEFT_MARGIN"])."
2373 AND RIGHT_MARGIN <= ".intval($arSection["RIGHT_MARGIN"])."
2374 AND ACTIVE = 'N'
2375 ORDER BY LEFT_MARGIN
2376 ";
2377 $arUpdate = array();
2378 $prev_right = 0;
2379 $rsChildren = $DB->Query($strSql);
2380 while($arChild = $rsChildren->Fetch())
2381 {
2382 if($arChild["RIGHT_MARGIN"] > $prev_right)
2383 {
2384 $prev_right = $arChild["RIGHT_MARGIN"];
2385 $arUpdate[] = "(LEFT_MARGIN >= ".$arChild["LEFT_MARGIN"]." AND RIGHT_MARGIN <= ".$arChild["RIGHT_MARGIN"].")\n";
2386 }
2387 }
2388 if(count($arUpdate) > 0)
2389 {
2390 $DB->Query("
2391 UPDATE b_iblock_section SET
2392 TIMESTAMP_X=".($DB->type=="ORACLE"?"NULL":"TIMESTAMP_X")."
2393 ,GLOBAL_ACTIVE = 'N'
2394 WHERE
2395 IBLOCK_ID = ".$arSection["IBLOCK_ID"]."
2396 AND (".implode(" OR ", $arUpdate).")
2397 ");
2398 }
2399 }
2400
2401 public static function getSectionCodePath($sectionId)
2402 {
2403 if (!isset(self::$arSectionPathCache[$sectionId]))
2404 {
2405 self::$arSectionPathCache[$sectionId] = '';
2406 $res = CIBlockSection::GetNavChain(0, $sectionId, ['ID', 'CODE'], true);
2407 foreach ($res as $a)
2408 {
2409 $a['CODE'] = (string)$a['CODE'];
2410 self::$arSectionCodeCache[$a['ID']] = rawurlencode($a['CODE']);
2411 self::$arSectionPathCache[$sectionId] .= rawurlencode($a['CODE']) . '/';
2412 }
2413 unset($a, $res);
2414 self::$arSectionPathCache[$sectionId] = rtrim(self::$arSectionPathCache[$sectionId], '/');
2415 }
2416 return self::$arSectionPathCache[$sectionId];
2417 }
2418
2419 public static function getSectionCode($sectionId): string
2420 {
2421 global $DB;
2422
2423 $sectionId = (int)$sectionId;
2424 if (!isset(self::$arSectionCodeCache[$sectionId]))
2425 {
2426 self::$arSectionCodeCache[$sectionId] = '';
2427 $res = $DB->Query("SELECT IBLOCK_ID, CODE FROM b_iblock_section WHERE ID = ".$sectionId);
2428 $a = $res->Fetch();
2429 unset($res);
2430 if ($a)
2431 {
2432 self::$arSectionCodeCache[$sectionId] = rawurlencode((string)$a['CODE']);
2433 }
2434 }
2435
2436 return self::$arSectionCodeCache[$sectionId];
2437 }
2438
2439 protected static function normalizeMixedFilter(array $filter): array
2440 {
2441 $modifyList = [
2442 // common keys
2443 'ID_1' => '>=ID',
2444 'ID_2' => '<=ID',
2445 'NAME' => '?NAME',
2446 'TIMESTAMP_X_1' => '>=TIMESTAMP_X',
2447 'TIMESTAMP_X_2' => '<=TIMESTAMP_X',
2448 'DATE_CREATE_1' => '>=DATE_CREATE',
2449 'DATE_CREATE_2' => '<=DATE_CREATE',
2450 'CODE' => 'CODE',
2451 'EXTERNAL_ID' => 'XML_ID',
2452 'MODIFIED_USER_ID' => 'MODIFIED_BY',
2453 'CREATED_USER_ID' => 'CREATED_BY',
2454 'DESCRIPTION' => '?SEARCHABLE_CONTENT',
2455
2456 // specific section keys
2457 // none
2458
2459 // specific element keys
2460 'DATE_ACTIVE_FROM_1' => '>=DATE_ACTIVE_FROM',
2461 'DATE_ACTIVE_FROM_2' => '<=DATE_ACTIVE_FROM',
2462 'DATE_ACTIVE_TO_1' => '>=DATE_ACTIVE_TO',
2463 'DATE_ACTIVE_TO_2' => '<=DATE_ACTIVE_TO',
2464 ];
2465
2466 $result = [];
2467 foreach ($filter as $field => $value)
2468 {
2469 $newField = $modifyList[$field] ?? $field;
2470 $result[$newField] = $value;
2471 }
2472
2473 if (isset($result['CHECK_PERMISSIONS']))
2474 {
2475 $result['MIN_PERMISSION'] = $result['MIN_PERMISSION'] ?? CIBlockRights::PUBLIC_READ;
2476 }
2477 if (isset($result['SECTION_ID']))
2478 {
2479 if ((string)$result['SECTION_ID'] === '')
2480 {
2481 unset($result['SECTION_ID']);
2482 }
2483 else
2484 {
2485 $result['SECTION_ID'] = (int)$result['SECTION_ID'];
2486 if ($result['SECTION_ID'] < 0)
2487 {
2488 unset($result['SECTION_ID']);
2489 }
2490 }
2491 }
2492
2493 return $result;
2494 }
2495
2503 {
2504 $result = array();
2505 $filter = array_filter($filter, [__CLASS__, 'clearNull']);
2506 if (!empty($filter))
2507 {
2508 $prepared = array();
2509 foreach ($filter as $index => $value)
2510 {
2511 if ($index == 'ID' && (is_int($value) || is_string($value)))
2512 {
2513 $result['=ID'] = $value;
2514 break;
2515 }
2516 elseif (
2517 preg_match('/^(>=|<=|>|<|=|!=|)ID$/', $index, $prepared)
2518 && $value instanceof \CIBlockElement
2519 )
2520 {
2521 if ($index == 'ID')
2522 $index = '=ID';
2523 $result[$index] = $value;
2524 }
2525 elseif (($index === 'SUBQUERY' || $index === '=SUBQUERY') && is_array($value))
2526 {
2527 $result[$index] = $value;
2528 }
2529 }
2530 unset($index, $value);
2531 $catalogIncluded = Loader::includeModule('catalog');
2532 foreach($filter as $index => $value)
2533 {
2534 $op = CIBlock::MkOperationFilter($index);
2535 if (
2536 strncmp($op['FIELD'], 'PROPERTY_', 9) == 0
2537 || ($catalogIncluded && \CProductQueryBuilder::isValidField($op['FIELD']))
2538 )
2539 {
2540 $result[$index] = $value;
2541 }
2542 }
2543 unset($op);
2544 }
2545 return $result;
2546 }
2547
2552 public static function checkLoadSections(array $filter): bool
2553 {
2554 $result = true;
2555 if (!empty($filter))
2556 {
2557 $blackList = [
2558 'TAGS' => true,
2559 'SHOW_COUNTER' => true,
2560 'IBLOCK_SECTION_ID' => true,
2561 'SHOW_COUNTER_START' => true,
2562 'CHECK_BP_PERMISSIONS' => true,
2563 'CHECK_BP_VIRTUAL_PERMISSIONS' => true,
2564 'ACTIVE_FROM' => true,
2565 'ACTIVE_TO' => true,
2566 'DATE_ACTIVE_FROM' => true,
2567 'DATE_ACTIVE_TO' => true,
2568 'ACTIVE_DATE' => true,
2569 'RATING_USER_ID' => true,
2570 'WF_STATUS_ID' => true,
2571 'WF_LOCK_STATUS' => true,
2572 'WF_LAST_STATUS_ID' => true,
2573 'WF_PARENT_ELEMENT_ID' => true,
2574 'WF_COMMENTS' => true,
2575 'SEARCHABLE_CONTENT' => true,
2576 'INCLUDE_SUBSECTIONS' => true,
2577 ];
2578 $catalogIncluded = Loader::includeModule('catalog');
2579 foreach($filter as $index => $value)
2580 {
2581 if (
2582 ($index === '=ID' && (is_int($value) || is_string($value)))
2583 || $value instanceof \CIBlockElement
2584 )
2585 {
2586 $result = false;
2587 break;
2588 }
2589 $op = CIBlock::MkOperationFilter($index);
2590 $field = $op['FIELD'];
2591 if ($field === 'SUBQUERY' && is_array($value))
2592 {
2593 $result = false;
2594 break;
2595 }
2596 if (
2597 strncmp($field, 'PROPERTY_', 9) === 0
2598 || isset($blackList[$field])
2599 || ($catalogIncluded && \CProductQueryBuilder::isRealFilterField($field))
2600 )
2601 {
2602 $result = false;
2603 break;
2604 }
2605 }
2606 unset($field, $op);
2607 }
2608 return $result;
2609 }
2610
2611 protected static function checkLoadElements(array $filter): bool
2612 {
2613 $result = true;
2614 if (!empty($filter))
2615 {
2616 $blackList = [
2617 'GLOBAL_ACTIVE' => true,
2618 'DEPTH_LEVEL' => true,
2619 'SOCNET_GROUP_ID' => true,
2620 'RIGHT_MARGIN' => true,
2621 'LEFT_MARGIN' => true,
2622 'LEFT_BORDER' => true,
2623 'RIGHT_BORDER' => true,
2624 'HAS_ELEMENT' => true,
2625 ];
2626 foreach($filter as $index => $value)
2627 {
2628 $op = CIBlock::MkOperationFilter($index);
2629 if (isset($blackList[$op['FIELD']]))
2630 {
2631 $result = false;
2632 break;
2633 }
2634 }
2635 unset($op);
2636 }
2637
2638 return $result;
2639 }
2640
2645 protected static function getPreparedFilterById(array $filter): array
2646 {
2647 $result = array();
2648 if (isset($filter['ID_1']) || isset($filter['ID_2']))
2649 {
2650 if (isset($filter['ID_1']))
2651 $result['>=ID'] = $filter['ID_1'];
2652 if (isset($filter['ID_2']))
2653 $result['<=ID'] = $filter['ID_2'];
2654 }
2655 else
2656 {
2657 $prepared = array();
2658 foreach (array_keys($filter) as $index)
2659 {
2660 if ($filter[$index] === null || is_object($filter[$index]))
2661 continue;
2662 if (preg_match('/^(>=|<=|>|<|=|!=)ID$/', $index, $prepared))
2663 $result[$index] = $filter[$index];
2664 }
2665 unset($index);
2666 unset($prepared);
2667 }
2668 return $result;
2669 }
2670
2675 protected static function clearNull($value): bool
2676 {
2677 return $value !== null;
2678 }
2679
2683 public static function recountTreeAfterAdd(array $arFields): void
2684 {
2685 global $DB;
2686
2687 $ID = (int)($arFields['ID'] ?? 0);
2688 $IBLOCK_ID = (int)($arFields['IBLOCK_ID'] ?? 0);
2689 if ($ID <= 0 || $IBLOCK_ID <= 0)
2690 {
2691 return;
2692 }
2693
2694 $arParent = false;
2695 if ($arFields["IBLOCK_SECTION_ID"] !== false)
2696 {
2697 $strSql = "
2698 SELECT BS.ID, BS.ACTIVE, BS.GLOBAL_ACTIVE, BS.DEPTH_LEVEL, BS.LEFT_MARGIN, BS.RIGHT_MARGIN
2699 FROM b_iblock_section BS
2700 WHERE BS.IBLOCK_ID = ".$IBLOCK_ID."
2701 AND BS.ID = ".$arFields["IBLOCK_SECTION_ID"]."
2702 ";
2703 $rsParent = $DB->Query($strSql);
2704 $arParent = $rsParent->Fetch();
2705 }
2706
2707 $NAME = $arFields["NAME"];
2708 $SORT = (int)$arFields["SORT"];
2709
2710 //Find rightmost child of the parent
2711 $strSql = "
2712 SELECT BS.ID, BS.RIGHT_MARGIN, BS.GLOBAL_ACTIVE, BS.DEPTH_LEVEL
2713 FROM b_iblock_section BS
2714 WHERE BS.IBLOCK_ID = ".$IBLOCK_ID."
2715 AND ".($arFields["IBLOCK_SECTION_ID"] !== false ? "BS.IBLOCK_SECTION_ID=".$arFields["IBLOCK_SECTION_ID"] : "BS.IBLOCK_SECTION_ID IS NULL")."
2716 AND (
2717 (BS.SORT < ".$SORT.")
2718 OR (BS.SORT = ".$SORT." AND BS.NAME < '".$DB->ForSQL($NAME)."')
2719 )
2720 AND BS.ID <> ".$ID."
2721 ORDER BY BS.SORT DESC, BS.NAME DESC
2722 ";
2723 $rsChild = $DB->Query($strSql);
2724
2725 if ($arChild = $rsChild->Fetch())
2726 {
2727 //We found the left neighbour
2728 $arUpdate = array(
2729 "LEFT_MARGIN" => (int)$arChild["RIGHT_MARGIN"] + 1,
2730 "RIGHT_MARGIN" => (int)$arChild["RIGHT_MARGIN"] + 2,
2731 "DEPTH_LEVEL" => (int)$arChild["DEPTH_LEVEL"],
2732 );
2733
2734 //in case we adding active section
2735 if ($arFields["ACTIVE"] != "N")
2736 {
2737 //Look up GLOBAL_ACTIVE of the parent
2738 //if none then take our own
2739 if ($arParent)//We must inherit active from the parent
2740 {
2741 $arUpdate["GLOBAL_ACTIVE"] = $arParent["GLOBAL_ACTIVE"] == "Y" ? "Y" : "N";
2742 }
2743 else //No parent was found take our own
2744 {
2745 $arUpdate["GLOBAL_ACTIVE"] = "Y";
2746 }
2747 }
2748 else
2749 {
2750 $arUpdate["GLOBAL_ACTIVE"] = "N";
2751 }
2752 }
2753 else
2754 {
2755 //If we have parent, when take its left_margin
2756 if ($arParent)
2757 {
2758 $arUpdate = array(
2759 "LEFT_MARGIN" => (int)$arParent["LEFT_MARGIN"] + 1,
2760 "RIGHT_MARGIN" => (int)$arParent["LEFT_MARGIN"] + 2,
2761 "GLOBAL_ACTIVE" => ($arParent["GLOBAL_ACTIVE"] == "Y") && ($arFields["ACTIVE"] != "N") ? "Y" : "N",
2762 "DEPTH_LEVEL" => (int)$arParent["DEPTH_LEVEL"] + 1,
2763 );
2764 }
2765 else
2766 {
2767 //We are only one/leftmost section in the iblock.
2768 $arUpdate = array(
2769 "LEFT_MARGIN" => 1,
2770 "RIGHT_MARGIN" => 2,
2771 "GLOBAL_ACTIVE" => $arFields["ACTIVE"] != "N" ? "Y" : "N",
2772 "DEPTH_LEVEL" => 1,
2773 );
2774 }
2775 }
2776
2777 $DB->Query("
2778 UPDATE b_iblock_section SET
2779 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2780 ,LEFT_MARGIN = ".$arUpdate["LEFT_MARGIN"]."
2781 ,RIGHT_MARGIN = ".$arUpdate["RIGHT_MARGIN"]."
2782 ,DEPTH_LEVEL = ".$arUpdate["DEPTH_LEVEL"]."
2783 ,GLOBAL_ACTIVE = '".$arUpdate["GLOBAL_ACTIVE"]."'
2784 WHERE
2785 ID = ".$ID."
2786 ");
2787
2788 $DB->Query("
2789 UPDATE b_iblock_section SET
2790 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2791 ,LEFT_MARGIN = LEFT_MARGIN + 2
2792 ,RIGHT_MARGIN = RIGHT_MARGIN + 2
2793 WHERE
2794 IBLOCK_ID = ".$IBLOCK_ID."
2795 AND LEFT_MARGIN >= ".$arUpdate["LEFT_MARGIN"]."
2796 AND ID <> ".$ID."
2797 ");
2798
2799 if ($arParent)
2800 {
2801 $DB->Query("
2802 UPDATE b_iblock_section SET
2803 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2804 ,RIGHT_MARGIN = RIGHT_MARGIN + 2
2805 WHERE
2806 IBLOCK_ID = ".$IBLOCK_ID."
2807 AND LEFT_MARGIN <= ".$arParent["LEFT_MARGIN"]."
2808 AND RIGHT_MARGIN >= ".$arParent["RIGHT_MARGIN"]."
2809 ");
2810 }
2811 }
2812
2817 public static function recountTreeAfterUpdate(array $arFields, array $db_record): void
2818 {
2819 global $DB;
2820
2821 if (empty($arFields) || empty($db_record))
2822 {
2823 return;
2824 }
2825
2826 $ID = $arFields['ID'];
2827
2828 $move_distance = 0;
2829
2830 //Move inside the tree
2831 if ((isset($arFields["SORT"]) && $arFields["SORT"] != $db_record["SORT"])
2832 || (isset($arFields["NAME"]) && $arFields["NAME"] != $db_record["NAME"])
2833 || (isset($arFields["IBLOCK_SECTION_ID"]) && $arFields["IBLOCK_SECTION_ID"] != $db_record["IBLOCK_SECTION_ID"]))
2834 {
2835 //First "delete" from the tree
2836 $distance = (int)$db_record["RIGHT_MARGIN"] - (int)$db_record["LEFT_MARGIN"] + 1;
2837 $DB->Query("
2838 UPDATE b_iblock_section SET
2839 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2840 ,LEFT_MARGIN = -LEFT_MARGIN
2841 ,RIGHT_MARGIN = -RIGHT_MARGIN
2842 WHERE
2843 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2844 AND LEFT_MARGIN >= ".(int)$db_record["LEFT_MARGIN"]."
2845 AND LEFT_MARGIN <= ".(int)$db_record["RIGHT_MARGIN"]."
2846 ");
2847
2848 $DB->Query("
2849 UPDATE b_iblock_section SET
2850 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2851 ,RIGHT_MARGIN = RIGHT_MARGIN - ".$distance."
2852 WHERE
2853 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2854 AND RIGHT_MARGIN > ".$db_record["RIGHT_MARGIN"]."
2855 ");
2856
2857 $DB->Query("
2858 UPDATE b_iblock_section SET
2859 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2860 ,LEFT_MARGIN = LEFT_MARGIN - ".$distance."
2861 WHERE
2862 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2863 AND LEFT_MARGIN > ".$db_record["LEFT_MARGIN"]."
2864 ");
2865
2866 //Next insert into the the tree almost as we do when inserting the new one
2867
2868 $PARENT_ID = (int)($arFields["IBLOCK_SECTION_ID"] ?? $db_record["IBLOCK_SECTION_ID"]);
2869 $NAME = $arFields["NAME"] ?? $db_record["NAME"];
2870 $SORT = (int)($arFields["SORT"] ?? $db_record["SORT"]);
2871
2872 $arParents = array();
2873 $strSql = "
2874 SELECT BS.ID, BS.ACTIVE, BS.GLOBAL_ACTIVE, BS.DEPTH_LEVEL, BS.LEFT_MARGIN, BS.RIGHT_MARGIN
2875 FROM b_iblock_section BS
2876 WHERE BS.IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2877 AND BS.ID in (".(int)$db_record["IBLOCK_SECTION_ID"].", ".$PARENT_ID.")
2878 ";
2879 $rsParents = $DB->Query($strSql);
2880 while ($arParent = $rsParents->Fetch())
2881 {
2882 $arParents[$arParent["ID"]] = $arParent;
2883 }
2884
2885 //Find rightmost child of the parent
2886 $strSql = "
2887 SELECT BS.ID, BS.RIGHT_MARGIN, BS.DEPTH_LEVEL
2888 FROM b_iblock_section BS
2889 WHERE BS.IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2890 AND ".($PARENT_ID > 0 ? "BS.IBLOCK_SECTION_ID=".$PARENT_ID : "BS.IBLOCK_SECTION_ID IS NULL")."
2891 AND (
2892 (BS.SORT < ".$SORT.")
2893 OR (BS.SORT = ".$SORT." AND BS.NAME < '".$DB->ForSQL($NAME)."')
2894 )
2895 AND BS.ID <> ".$ID."
2896 ORDER BY BS.SORT DESC, BS.NAME DESC
2897 ";
2898 $rsChild = $DB->Query($strSql);
2899 if ($arChild = $rsChild->Fetch())
2900 {
2901 //We found the left neighbour
2902 $arUpdate = array(
2903 "LEFT_MARGIN" => (int)$arChild["RIGHT_MARGIN"] + 1,
2904 "DEPTH_LEVEL" => (int)$arChild["DEPTH_LEVEL"],
2905 );
2906 }
2907 else
2908 {
2909 //If we have parent, when take its left_margin
2910 if (isset($arParents[$PARENT_ID]) && $arParents[$PARENT_ID])
2911 {
2912 $arUpdate = array(
2913 "LEFT_MARGIN" => (int)$arParents[$PARENT_ID]["LEFT_MARGIN"] + 1,
2914 "DEPTH_LEVEL" => (int)$arParents[$PARENT_ID]["DEPTH_LEVEL"] + 1,
2915 );
2916 }
2917 else
2918 {
2919 //We are only one/leftmost section in the iblock.
2920 $arUpdate = array(
2921 "LEFT_MARGIN" => 1,
2922 "DEPTH_LEVEL" => 1,
2923 );
2924 }
2925 }
2926
2927 $move_distance = (int)$db_record["LEFT_MARGIN"] - $arUpdate["LEFT_MARGIN"];
2928
2929 $DB->Query("
2930 UPDATE b_iblock_section SET
2931 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2932 ,LEFT_MARGIN = LEFT_MARGIN + ".$distance."
2933 ,RIGHT_MARGIN = RIGHT_MARGIN + ".$distance."
2934 WHERE
2935 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2936 AND LEFT_MARGIN >= ".$arUpdate["LEFT_MARGIN"]."
2937 ");
2938
2939 $DB->Query("
2940 UPDATE b_iblock_section SET
2941 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2942 ,LEFT_MARGIN = -LEFT_MARGIN - ".$move_distance."
2943 ,RIGHT_MARGIN = -RIGHT_MARGIN - ".$move_distance."
2944 ".($arUpdate["DEPTH_LEVEL"] != (int)$db_record["DEPTH_LEVEL"] ? ",DEPTH_LEVEL = DEPTH_LEVEL - ".($db_record["DEPTH_LEVEL"] - $arUpdate["DEPTH_LEVEL"]) : "")."
2945 WHERE
2946 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2947 AND LEFT_MARGIN <= ".(-(int)$db_record["LEFT_MARGIN"])."
2948 AND LEFT_MARGIN >= ".(-(int)$db_record["RIGHT_MARGIN"])."
2949 ");
2950
2951 if (isset($arParents[$PARENT_ID]))
2952 {
2953 $DB->Query("
2954 UPDATE b_iblock_section SET
2955 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
2956 ,RIGHT_MARGIN = RIGHT_MARGIN + ".$distance."
2957 WHERE
2958 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
2959 AND LEFT_MARGIN <= ".$arParents[$PARENT_ID]["LEFT_MARGIN"]."
2960 AND RIGHT_MARGIN >= ".$arParents[$PARENT_ID]["RIGHT_MARGIN"]."
2961 ");
2962 }
2963 }
2964
2965 //Check if parent was changed
2966 if (isset($arFields["IBLOCK_SECTION_ID"]) && $arFields["IBLOCK_SECTION_ID"] != $db_record["IBLOCK_SECTION_ID"])
2967 {
2968 $rsSection = CIBlockSection::GetList(
2969 array(),
2970 array("ID" => $ID, "CHECK_PERMISSIONS" => "N"),
2971 false,
2972 array(
2973 "ID", "IBLOCK_ID", "IBLOCK_SECTION_ID",
2974 "LEFT_MARGIN", "RIGHT_MARGIN",
2975 "ACTIVE", "GLOBAL_ACTIVE"
2976 )
2977 );
2978
2979 $arSection = $rsSection->Fetch();
2980 unset($rsSection);
2981
2982 $strSql = "
2983 SELECT ID, GLOBAL_ACTIVE
2984 FROM b_iblock_section
2985 WHERE IBLOCK_ID = ".$arSection["IBLOCK_ID"]."
2986 AND ID = ".(int)$arFields["IBLOCK_SECTION_ID"]."
2987 ";
2988 $rsParent = $DB->Query($strSql);
2989 $arParent = $rsParent->Fetch();
2990
2991 $arFields['ACTIVE'] ??= null;
2992 //If new parent is not globally active
2993 //or we are not active either
2994 //we must be not globally active too
2995 if (
2996 ($arParent && $arParent['GLOBAL_ACTIVE'] === 'N')
2997 || $arFields['ACTIVE'] === 'N'
2998 )
2999 {
3000 $DB->Query("
3001 UPDATE b_iblock_section SET
3002 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
3003 ,GLOBAL_ACTIVE = 'N'
3004 WHERE
3005 IBLOCK_ID = ".$arSection["IBLOCK_ID"]."
3006 AND LEFT_MARGIN >= ".(int)$arSection["LEFT_MARGIN"]."
3007 AND RIGHT_MARGIN <= ".(int)$arSection["RIGHT_MARGIN"]."
3008 ");
3009 }
3010 //New parent is globally active
3011 //And we WAS NOT active
3012 //But is going to be
3013 elseif (
3014 $arSection['ACTIVE'] === 'N'
3015 && $arFields['ACTIVE'] === 'Y'
3016 )
3017 {
3018 static::RecalcGlobalActiveFlag($arSection);
3019 }
3020 //New parent is globally active
3021 //And we WAS active but NOT globally active
3022 //But is going to be
3023 elseif (
3024 (!$arParent || $arParent['GLOBAL_ACTIVE'] === 'Y')
3025 && $arSection['GLOBAL_ACTIVE'] === 'N'
3026 && (
3027 $arSection['ACTIVE'] === 'Y'
3028 || $arFields['ACTIVE'] === 'Y'
3029 )
3030 )
3031 {
3032 static::RecalcGlobalActiveFlag($arSection);
3033 }
3034 //Otherwise we may not to change anything
3035 }
3036 //Parent not changed
3037 //but we are going to change activity flag
3038 elseif (isset($arFields["ACTIVE"]) && $arFields["ACTIVE"] != $db_record["ACTIVE"])
3039 {
3040 //Make all children globally inactive
3041 if ($arFields["ACTIVE"] == "N")
3042 {
3043 $DB->Query("
3044 UPDATE b_iblock_section SET
3045 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
3046 ,GLOBAL_ACTIVE = 'N'
3047 WHERE
3048 IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
3049 AND LEFT_MARGIN >= ".(int)$db_record["LEFT_MARGIN"]."
3050 AND RIGHT_MARGIN <= ".(int)$db_record["RIGHT_MARGIN"]."
3051 ");
3052 }
3053 else
3054 {
3055 //Check for parent activity
3056 $strSql = "
3057 SELECT ID, GLOBAL_ACTIVE
3058 FROM b_iblock_section
3059 WHERE IBLOCK_ID = ".$db_record["IBLOCK_ID"]."
3060 AND ID = ".(int)$db_record["IBLOCK_SECTION_ID"]."
3061 ";
3062 $rsParent = $DB->Query($strSql);
3063 $arParent = $rsParent->Fetch();
3064
3065 //Parent is active
3066 //and we changed
3067 //so need to recalc
3068 if (!$arParent || $arParent["GLOBAL_ACTIVE"] == "Y")
3069 {
3070 static::RecalcGlobalActiveFlag($db_record, -$move_distance);
3071 }
3072 }
3073 }
3074 }
3075
3079 public static function recountTreeOnDelete(array $arFields): void
3080 {
3081 global $DB;
3082
3083 $id = (int)($arFields['ID'] ?? 0);
3084 if ($id <= 0)
3085 {
3086 return;
3087 }
3088
3089 $ss = $DB->Query("
3090 SELECT
3091 IBLOCK_ID,
3092 LEFT_MARGIN,
3093 RIGHT_MARGIN
3094 FROM
3095 b_iblock_section
3096 WHERE
3097 ID = " . $id . "
3098 ")->Fetch();
3099 if (empty($ss))
3100 {
3101 return;
3102 }
3103
3104 if (($ss["RIGHT_MARGIN"] > 0) && ($ss["LEFT_MARGIN"] > 0))
3105 {
3106 $DB->Query("
3107 UPDATE b_iblock_section SET
3108 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
3109 ,RIGHT_MARGIN = RIGHT_MARGIN - 2
3110 WHERE
3111 IBLOCK_ID = ".$ss["IBLOCK_ID"]."
3112 AND RIGHT_MARGIN > ".$ss["RIGHT_MARGIN"]."
3113 ");
3114
3115 $DB->Query("
3116 UPDATE b_iblock_section SET
3117 TIMESTAMP_X=".($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X")."
3118 ,LEFT_MARGIN = LEFT_MARGIN - 2
3119 WHERE
3120 IBLOCK_ID = ".$ss["IBLOCK_ID"]."
3121 AND LEFT_MARGIN > ".$ss["LEFT_MARGIN"]."
3122 ");
3123 }
3124 }
3125
3126 public function generateMnemonicCode(string $name, int $iblockId, array $options = []): ?string
3127 {
3128 if ($name === '' || $iblockId <= 0)
3129 {
3130 return null;
3131 }
3132
3133 if ($this->iblock !== null && $this->iblock['ID'] === $iblockId)
3134 {
3136 $language = $this->iblockLanguage;
3137 }
3138 else
3139 {
3140 $iblock = CIBlock::GetArrayByID($iblockId);
3141 if (empty($iblock))
3142 {
3143 $iblock = null;
3144 $language = null;
3145 }
3146 else
3147 {
3148 $iblock['ID'] = (int)$iblock['ID'];
3149 $language = static::getIblockLanguage($iblock['ID']);
3150 }
3151 }
3152
3153 if (empty($iblock))
3154 {
3155 return null;
3156 }
3157
3158 $result = null;
3159 if (isset($iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']))
3160 {
3161 if ($iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']['TRANSLITERATION'] === 'Y'
3162 && $iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']['USE_GOOGLE'] === 'N'
3163 )
3164 {
3165 $config = $iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE'];
3166 $config['LANGUAGE_ID'] = $language;
3167 $config = array_merge($config, $options);
3168
3169 if ($config['LANGUAGE_ID'] !== null)
3170 {
3171 $settings = [
3172 'max_len' => $config['TRANS_LEN'],
3173 'change_case' => $config['TRANS_CASE'],
3174 'replace_space' => $config['TRANS_SPACE'],
3175 'replace_other' => $config['TRANS_OTHER'],
3176 'delete_repeat_replace' => ($config['TRANS_EAT'] == 'Y'),
3177 ];
3178
3179 $result = CUtil::translit($name, $config['LANGUAGE_ID'], $settings);
3180 }
3181 }
3182 }
3183
3184 return $result;
3185 }
3186
3187 public function isExistsMnemonicCode(string $code, ?int $sectionId, int $iblockId): bool
3188 {
3189 if ($code === '')
3190 {
3191 return false;
3192 }
3193 $filter = [
3194 '=IBLOCK_ID' => $iblockId,
3195 '=CODE' => $code,
3196 ];
3197 if ($sectionId !== null)
3198 {
3199 $filter['!=ID'] = $sectionId;
3200 }
3201
3203 'select' => ['ID'],
3204 'filter' => $filter,
3205 'limit' => 1,
3206 ])->fetch();
3207
3208 return !empty($row);
3209 }
3210
3211 public function createMnemonicCode(array $section, array $options = []): ?string
3212 {
3213 if (!isset($section['NAME']) || $section['NAME'] === '')
3214 {
3215 return null;
3216 }
3217 $iblockId = $section['IBLOCK_ID'] ?? 0;
3218 if ($iblockId !== null)
3219 {
3220 $iblockId = (int)$iblockId;
3221 }
3222 if ($iblockId <= 0)
3223 {
3224 return null;
3225 }
3226
3227 if ($this->iblock !== null && $this->iblock['ID'] === $iblockId)
3228 {
3230 }
3231 else
3232 {
3233 $iblock = CIBlock::GetArrayByID($iblockId);
3234 }
3235
3236 if (empty($iblock))
3237 {
3238 return null;
3239 }
3240
3241 $code = null;
3242 if (isset($iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']))
3243 {
3244 $code = $this->generateMnemonicCode($section['NAME'], $iblockId, $options);
3245 if ($code === null)
3246 {
3247 return null;
3248 }
3249
3250 if ($iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']['TRANSLITERATION'] === 'Y'
3251 && (
3252 $iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] === 'Y'
3253 || ($options['CHECK_UNIQUE'] ?? 'N') === 'Y'
3254 )
3255 )
3256 {
3257 $id = (int)($section['ID'] ?? null);
3258 if ($id <= 0)
3259 {
3260 $id = null;
3261 }
3262 if (!$this->isExistsMnemonicCode($code, $id, $iblockId))
3263 {
3264 return $code;
3265 }
3266
3267 $checkSimilar = ($options['CHECK_SIMILAR'] ?? 'N') === 'Y';
3268
3269 $list = [];
3271 'select' => ['ID', 'CODE'],
3272 'filter' => [
3273 '=IBLOCK_ID' => $iblockId,
3274 '%=CODE' => $code . '%',
3275 ],
3276 ]);
3277 while ($row = $iterator->fetch())
3278 {
3279 if ($checkSimilar && $id === (int)$row['ID'])
3280 {
3281 return null;
3282 }
3283 $list[$row['CODE']] = true;
3284 }
3285 unset($iterator, $row);
3286
3287 if (isset($list[$code]))
3288 {
3289 $code .= '_';
3290 $i = 1;
3291 while (isset($list[$code . $i]))
3292 {
3293 $i++;
3294 }
3295
3296 $code .= $i;
3297 }
3298 unset($list);
3299 }
3300 }
3301
3302 return $code;
3303 }
3304
3305 protected static function getIblockLanguage(int $iblockId): ?string
3306 {
3307 $result = [];
3308 $iterator = Iblock\IblockSiteTable::getList([
3309 'select' => ['LANGUAGE_ID' => 'SITE.LANGUAGE_ID'],
3310 'filter' => ['=IBLOCK_ID' => $iblockId]
3311 ]);
3312 while ($row = $iterator->fetch())
3313 {
3314 $result[$row['LANGUAGE_ID']] = true;
3315 }
3316 unset($iterator, $row);
3317
3318 return count($result) === 1 ? key($result) : null;
3319 }
3320
3321 public function getLastError(): string
3322 {
3323 return $this->LAST_ERROR;
3324 }
3325}
$connection
Определения actionsdefinitions.php:38
global $APPLICATION
Определения include.php:80
if($strVal !='') $sectionFields
Определения options.php:1848
if($canUseYandexMarket) $strWarning
Определения options.php:74
$arResult
Определения generate_coupon.php:16
const ELEMENT
Определения rowtype.php:7
const SECTION
Определения rowtype.php:8
static markAsInvalid($iblockId)
Определения manager.php:125
static makeFileName(\Bitrix\Iblock\InheritedProperty\BaseTemplate $ipropTemplates, string $templateName, array $fields, array $file)
Определения helper.php:136
static getConnection($name="")
Определения application.php:638
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
static getList(array $parameters=array())
Определения datamanager.php:431
Определения access.php:15
InitFromArray($arr)
Определения dbresult.php:1013
getLastError()
Определения iblocksection.php:3321
static GetTreeList($arFilter=array(), $arSelect=array())
Определения iblocksection.php:199
__construct()
Определения iblocksection.php:21
static $arSectionCodeCache
Определения iblocksection.php:12
setIblock(?int $iblockId)
Определения iblocksection.php:32
createMnemonicCode(array $section, array $options=[])
Определения iblocksection.php:3211
isExistsMnemonicCode(string $code, ?int $sectionId, int $iblockId)
Определения iblocksection.php:3187
static UserTypeRightsCheck($entity_id)
Определения iblocksection.php:2339
static getSectionCodePath($sectionId)
Определения iblocksection.php:2401
static TreeReSort($IBLOCK_ID, $ID=0, $cnt=0, $depth=0, $ACTIVE="Y")
Определения iblocksection.php:1762
static getIblockLanguage(int $iblockId)
Определения iblocksection.php:3305
static GetNavChain($IBLOCK_ID, $SECTION_ID, $arSelect=array(), $arrayResult=false)
Определения iblocksection.php:204
CheckFields(&$arFields, $ID=false)
Определения iblocksection.php:1513
static GetByID($ID)
Определения iblocksection.php:335
static recountTreeAfterAdd(array $arFields)
Определения iblocksection.php:2683
static GetFilter($arFilter=Array())
Определения iblocksection.php:53
string $iblockLanguage
Определения iblocksection.php:17
static clearNull($value)
Определения iblocksection.php:2675
static GetCount($arFilter=[])
Определения iblocksection.php:2296
static $arSectionPathCache
Определения iblocksection.php:13
static getSectionCode($sectionId)
Определения iblocksection.php:2419
string $currentDateTimeFunction
Определения iblocksection.php:19
static recountTreeOnDelete(array $arFields)
Определения iblocksection.php:3079
static getElementInherentFilter(array $filter)
Определения iblocksection.php:2502
static recountTreeAfterUpdate(array $arFields, array $db_record)
Определения iblocksection.php:2817
static GetSectionElementsCount($ID, $arFilter=Array())
Определения iblocksection.php:2066
string $LAST_ERROR
Определения iblocksection.php:11
static GetMixedList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt=false, $arSelectedFields=false)
Определения iblocksection.php:1938
static ReSort($IBLOCK_ID, $ID=0, $cnt=0, $depth=0, $ACTIVE="Y")
Определения iblocksection.php:1819
array $iblock
Определения iblocksection.php:16
static normalizeMixedFilter(array $filter)
Определения iblocksection.php:2439
static Delete($ID, $bCheckPermissions=true)
Определения iblocksection.php:1276
Update($ID, $arFields, $bResort=true, $bUpdateSearch=true, $bResizePictures=false)
Определения iblocksection.php:781
static getPreparedFilterById(array $filter)
Определения iblocksection.php:2645
Add($arFields, $bResort=true, $bUpdateSearch=true, $bResizePictures=false)
Определения iblocksection.php:343
static $arSectionNavChainCache
Определения iblocksection.php:14
static checkLoadSections(array $filter)
Определения iblocksection.php:2552
static RecalcGlobalActiveFlag($arSection, $distance=0)
Определения iblocksection.php:2349
generateMnemonicCode(string $name, int $iblockId, array $options=[])
Определения iblocksection.php:3126
static checkLoadElements(array $filter)
Определения iblocksection.php:2611
static _check_rights_sql($min_permission, $permissionsBy=null)
Определения iblocksection.php:2184
UpdateSearch($ID, $bOverWrite=false)
Определения iblocksection.php:1828
static DeleteIndex($MODULE_ID, $ITEM_ID=false, $PARAM1=false, $PARAM2=false, $SITE_ID=false)
Определения search.php:2922
static KillTags($str)
Определения search.php:2092
static Index($MODULE_ID, $ITEM_ID, $arFields, $bOverWrite=false, $SEARCH_SESS_ID='')
Определения search.php:1302
Определения dbresult.php:88
Определения quota.php:6
static recalculateDb(bool $mode=true)
Определения quota.php:29
static Log($SEVERITY, $AUDIT_TYPE_ID, $MODULE_ID, $ITEM_ID, $DESCRIPTION=false, $SITE_ID=false)
Определения event_log.php:32
Определения iblockelement.php:9
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения iblockelement.php:658
Определения iblockresult.php:3
Определения iblock_rights.php:7
Определения iblocksection.php:5
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt=false, $arSelect=array(), $arNavStartParams=false)
Определения iblocksection.php:14
static isValidField(string $field)
Определения querybuilder.php:95
static isRealFilterField(string $field)
Определения querybuilder.php:150
$options
Определения commerceml2.php:49
$str
Определения commerceml2.php:63
$arFields
Определения dblapprove.php:5
$arr
Определения file_new.php:624
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$arGroups
Определения options.php:1766
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$iblockId
Определения iblock_catalog_edit.php:30
$filter
Определения iblock_catalog_list.php:54
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
$IBLOCK_ID
Определения csv_new_run.php:168
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
CheckDirPath($path)
Определения tools.php:2707
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
Определения tools.php:2587
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
$GLOBALS['____1690880296']
Определения license.php:1
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$config
Определения quickway.php:69
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
else $a
Определения template.php:137
$val
Определения options.php:1793
$arRes
Определения options.php:104
$error
Определения subscription_card_product.php:20
$rs
Определения action.php:82
$arFilter
Определения user_search.php:106
$dbRes
Определения yandex_detail.php:168
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$iterator
Определения yandex_run.php:610