1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblock.php
См. документацию.
1<?php
2
8
10{
11 protected const TABLE_PREFIX_SINGLE_PROPERTY_VALUES = 'b_iblock_element_prop_s';
12 protected const TABLE_PREFIX_MULTIPLE_PROPERTY_VALUES = 'b_iblock_element_prop_m';
13 protected const TABLE_COMMON_PROPERTY_VALUES = 'b_iblock_element_property';
14
15 public string $LAST_ERROR = '';
16 protected static array $disabledCacheTag = [];
17 protected static int $enableClearTagCache = 0;
18
19 protected static ?bool $catalogIncluded = null;
20 protected static ?bool $workflowIncluded = null;
21
22 private static array $urlElementDataCache = [];
23
24 private static array $urlSectionDataCache = [];
25
26 private static array $productIblockDataCache = [];
27
28 private static array $urlParentCache = [];
29
30 public static function clearUrlDataCache(): void
31 {
32 self::$productIblockDataCache = [];
33 self::$urlParentCache = [];
34 self::$urlElementDataCache = [];
35 self::$urlSectionDataCache = [];
36 }
37
38 public static function fillUrlElementDataCache(int $id): void
39 {
40 if ($id <= 0)
41 {
42 return;
43 }
44 if (isset(self::$urlElementDataCache[$id]))
45 {
46 return;
47 }
48
50 'select' => [
51 'ID',
52 'IBLOCK_ID',
53 'CODE',
54 'XML_ID',
55 'IBLOCK_SECTION_ID',
56 ],
57 'filter' => [
58 '=ID' => $id,
59 ]
60 ]);
61 if ($element !== null)
62 {
63 $element['ID'] = (int)$element['ID'];
64 $element['IBLOCK_ID'] = (int)$element['IBLOCK_ID'];
65 $element['CODE'] = (string)$element['CODE'];
66 $element['XML_ID'] = (string)$element['XML_ID'];
67 $element['IBLOCK_SECTION_ID'] = (int)$element['IBLOCK_SECTION_ID'];
68 $element['IBLOCK_SECTION_CODE'] = '';
69 $sectionId = $element['IBLOCK_SECTION_ID'];
70 if ($sectionId > 0)
71 {
72 if (!isset(self::$urlSectionDataCache[$sectionId]))
73 {
74 self::$urlSectionDataCache[$sectionId] = false;
76 'select' => [
77 'ID',
78 'CODE',
79 ],
80 'filter' => [
81 '=ID' => $sectionId,
82 '=IBLOCK_ID' => $element['IBLOCK_ID'],
83 ]
84 ]);
85 if ($section !== null)
86 {
87 $section['ID'] = (int)$section['ID'];
88 $section['CODE'] = (string)$section['CODE'];
89 self::$urlSectionDataCache[$sectionId] = $section;
90 }
91 }
92 if (!empty(self::$urlSectionDataCache[$sectionId]))
93 {
94 $element['IBLOCK_SECTION_CODE'] = self::$urlSectionDataCache[$sectionId]['CODE'];
95 }
96 }
97
98 self::$urlElementDataCache[$id] = $element;
99 }
100 else
101 {
102 self::$urlElementDataCache[$id] = false;
103 }
104 }
105
106 private static function getUrlElementData(int $id): ?array
107 {
108 if ($id <= 0)
109 {
110 return null;
111 }
112
113 if (!isset(self::$urlElementDataCache[$id]))
114 {
115 static::fillUrlElementDataCache($id);
116 }
117
118 return (
119 !empty(self::$urlElementDataCache[$id])
120 ? self::$urlElementDataCache[$id]
121 : null
122 );
123 }
124
125 private static function getProductIblockData(int $iblockId): ?array
126 {
127 if ($iblockId <= 0)
128 {
129 return null;
130 }
131 if (self::$catalogIncluded === null)
132 {
133 self::$catalogIncluded = Loader::includeModule('catalog');
134 }
135 if (!self::$catalogIncluded)
136 {
137 return null;
138 }
139
140 if (!isset(self::$productIblockDataCache[$iblockId]))
141 {
143 if (is_array($iblock))
144 {
145 $productIblock = CIBlock::GetArrayByID($iblock['PRODUCT_IBLOCK_ID']);
146 if (is_array($productIblock))
147 {
148 $iblock['PRODUCT_IBLOCK'] = [
149 'ID' => (int)$productIblock['ID'],
150 'IBLOCK_TYPE_ID' => $productIblock['IBLOCK_TYPE_ID'],
151 'CODE' => (string)$productIblock['CODE'],
152 'XML_ID' => (string)$productIblock['XML_ID'],
153 'DETAIL_PAGE_URL' => (string)$productIblock['DETAIL_PAGE_URL'],
154 ];
155 }
156 else
157 {
158 $iblock = false;
159 }
160 }
161 self::$productIblockDataCache[$iblockId] = $iblock;
162 }
163
164 return (
165 !empty(self::$productIblockDataCache[$iblockId])
166 ? self::$productIblockDataCache[$iblockId]
167 : null
168 );
169 }
170
171 private static function getProductId(int $elementId, int $iblockId): ?int
172 {
173 if ($elementId <= 0 || $iblockId <= 0)
174 {
175 return null;
176 }
177 if (self::$catalogIncluded === null)
178 {
179 self::$catalogIncluded = Loader::includeModule('catalog');
180 }
181 if (!self::$catalogIncluded)
182 {
183 return null;
184 }
185
186 if (!isset(self::$urlParentCache[$elementId]))
187 {
188 $list = CCatalogSku::getProductList($elementId, $iblockId);
189 self::$urlParentCache[$elementId] = $list[$elementId]['ID'] ?? false;
190 }
191
192 return (
193 !empty(self::$urlParentCache[$elementId])
194 ? self::$urlParentCache[$elementId]
195 : null
196 );
197 }
198
199 public static function ShowPanel($IBLOCK_ID=0, $ELEMENT_ID=0, $SECTION_ID="", $type="news", $bGetIcons=false, $componentName="", $arLabels=array())
200 {
202 global $APPLICATION;
204 global $USER;
205
206 if (($USER->IsAuthorized() || $APPLICATION->ShowPanel===true) && $APPLICATION->ShowPanel!==false)
207 {
208 if (CModule::IncludeModule("iblock") && $type <> '')
209 {
210 $arButtons = CIBlock::GetPanelButtons($IBLOCK_ID, $ELEMENT_ID, $SECTION_ID, array(
211 "LABELS" => $arLabels,
212 ));
213
214 $mode = $APPLICATION->GetPublicShowMode();
215
216 if($bGetIcons)
217 {
218 return CIBlock::GetComponentMenu($mode, $arButtons);
219 }
220 else
221 {
222 CIBlock::AddPanelButtons($mode, $componentName, $arButtons);
223 }
224 }
225 }
226 return null;
227 }
228
229 public static function AddPanelButtons($mode, $componentName, $arButtons)
230 {
232 global $APPLICATION;
233
234 $arImages = array(
235 "add_element" => (defined("PANEL_ADD_ELEMENT_BTN")) ? PANEL_ADD_ELEMENT_BTN : "/bitrix/images/iblock/icons/new_element.gif",
236 "edit_element" => (defined("PANEL_EDIT_ELEMENT_BTN")) ? PANEL_EDIT_ELEMENT_BTN : "/bitrix/images/iblock/icons/edit_element.gif",
237 "edit_iblock" => (defined("PANEL_EDIT_IBLOCK_BTN")) ? PANEL_EDIT_IBLOCK_BTN : "/bitrix/images/iblock/icons/edit_iblock.gif",
238 "history_element" => (defined("PANEL_HISTORY_ELEMENT_BTN")) ? PANEL_HISTORY_ELEMENT_BTN : "/bitrix/images/iblock/icons/history.gif",
239 "edit_section" => (defined("PANEL_EDIT_SECTION_BTN")) ? PANEL_EDIT_SECTION_BTN : "/bitrix/images/iblock/icons/edit_section.gif",
240 "add_section" => (defined("PANEL_ADD_SECTION_BTN")) ? PANEL_ADD_SECTION_BTN : "/bitrix/images/iblock/icons/new_section.gif",
241 "element_list" => "/bitrix/themes/.default/icons/iblock/mnu_iblock_el.gif",
242 "section_list" => "/bitrix/themes/.default/icons/iblock/mnu_iblock_sec.gif",
243 );
244
246
247 if (!empty($arButtons[$mode]) && is_array($arButtons[$mode]))
248 {
249 //Try to detect component via backtrace
250 if ($componentName === '')
251 {
252 $arTrace = debug_backtrace();
253 foreach($arTrace as $arCallInfo)
254 {
255 if (isset($arCallInfo["file"]))
256 {
257 $file = mb_strtolower(str_replace("\\", "/", $arCallInfo["file"]));
258 if(preg_match("#.*/bitrix/components/(.+?)/(.+?)/#", $file, $match))
259 {
260 $componentName = $match[1].":".$match[2];
261 break;
262 }
263 }
264 }
265 }
266 if ($componentName !== '')
267 {
269 if(is_array($arComponentDescription) && mb_strlen($arComponentDescription["NAME"]))
271 }
272 else
273 {
274 $componentName = Loc::getMessage("IBLOCK_PANEL_UNKNOWN_COMPONENT");
275 }
276
277 $arPanelButton = array(
278 "SRC" => "/bitrix/images/iblock/icons/iblock.gif",
279 "ALT" => $componentName,
280 "TEXT" => $componentName,
281 "MAIN_SORT" => 300,
282 "SORT" => 30,
283 "MENU" => array(),
284 "MODE" => $mode,
285 );
286
287 foreach($arButtons[$mode] as $i=>$arSubButton)
288 {
289 if (isset($arImages[$i]))
290 $arSubButton['IMAGE'] = $arImages[$i];
291
292 if($arSubButton["DEFAULT"])
293 $arPanelButton["HREF"] = $arSubButton["ACTION"];
294
295 $arPanelButton["MENU"][] = $arSubButton;
296 }
297
298 if (!empty($arButtons["submenu"]) && is_array($arButtons["submenu"]))
299 {
300 $arSubMenu = array(
301 "SRC" => "/bitrix/images/iblock/icons/iblock.gif",
302 "ALT" => Loc::getMessage("IBLOCK_PANEL_CONTROL_PANEL_ALT"),
303 "TEXT" => Loc::getMessage("IBLOCK_PANEL_CONTROL_PANEL"),
304 "MENU" => array(),
305 "MODE" => $mode,
306 );
307
308 foreach($arButtons["submenu"] as $i=>$arSubButton)
309 {
310 if (isset($arImages[$i]))
311 $arSubButton['IMAGE'] = $arImages[$i];
312 $arSubMenu["MENU"][] = $arSubButton;
313 }
314
315 $arPanelButton["MENU"][] = array("SEPARATOR" => "Y");
316 $arPanelButton["MENU"][] = $arSubMenu;
317 }
318 $APPLICATION->AddPanelButton($arPanelButton);
319 }
320
321 if (!empty($arButtons["intranet"]) && is_array($arButtons["intranet"]) && CModule::IncludeModule("intranet"))
322 {
324 global $INTRANET_TOOLBAR;
325 foreach($arButtons["intranet"] as $arButton)
326 $INTRANET_TOOLBAR->AddButton($arButton);
327 }
328 }
329
330 public static function GetComponentMenu($mode, $arButtons)
331 {
332 $arImages = array(
333 "add_element" => "/bitrix/images/iblock/icons/new_element.gif",
334 "edit_element" => "/bitrix/images/iblock/icons/edit_element.gif",
335 "edit_iblock" => "/bitrix/images/iblock/icons/edit_iblock.gif",
336 "history_element" => "/bitrix/images/iblock/icons/history.gif",
337 "edit_section" => "/bitrix/images/iblock/icons/edit_section.gif",
338 "add_section" => "/bitrix/images/iblock/icons/new_section.gif",
339 "element_list" => "/bitrix/themes/.default/icons/iblock/mnu_iblock_el.gif",
340 "section_list" => "/bitrix/themes/.default/icons/iblock/mnu_iblock_sec.gif",
341 );
342
343 $arResult = array();
344 foreach($arButtons[$mode] as $i=>$arButton)
345 {
346 if (!isset($arButton['SEPARATOR']))
347 {
348 $arButton['URL'] = $arButton['ACTION'] ?? null;
349 unset($arButton['ACTION']);
350 $arButton['IMAGE'] = $arImages[$i] ?? null;
351 }
352 $arResult[] = $arButton;
353 }
354 return $arResult;
355 }
356
357 public static function GetPanelButtons($IBLOCK_ID=0, $ELEMENT_ID=0, $SECTION_ID=0, $arOptions=array())
358 {
360 global $APPLICATION;
361
362 $windowParams = array('width' => 700, 'height' => 400, 'resize' => false);
363
364 $arButtons = array(
365 "view" => array(),
366 "edit" => array(),
367 "configure" => array(),
368 "submenu" => array(),
369 );
370
371 $bSectionButtons = !(isset($arOptions['SECTION_BUTTONS']) && $arOptions['SECTION_BUTTONS'] === false);
372 $bSessID = !(isset($arOptions['SESSID']) && $arOptions['SESSID'] === false);
373
374 $IBLOCK_ID = (int)$IBLOCK_ID;
375 $ELEMENT_ID = (int)$ELEMENT_ID;
376 $SECTION_ID = (int)$SECTION_ID;
377
378 if(($ELEMENT_ID > 0) && (($IBLOCK_ID <= 0) || ($bSectionButtons && $SECTION_ID == 0)))
379 {
380 $rsIBlockElement = CIBlockElement::GetList(array(), array(
381 "ID" => $ELEMENT_ID,
382 "ACTIVE_DATE" => "Y",
383 "ACTIVE" => "Y",
384 "CHECK_PERMISSIONS" => "Y",
385 ), false, false, array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID"));
386 if($arIBlockElement = $rsIBlockElement->Fetch())
387 {
388 $IBLOCK_ID = $arIBlockElement["IBLOCK_ID"];
389 $SECTION_ID = $arIBlockElement["IBLOCK_SECTION_ID"];
390 }
391 }
392
393 if($IBLOCK_ID <= 0)
394 return $arButtons;
395
396 $bCatalog = false;
397 $useCatalogButtons = (($ELEMENT_ID <= 0 || isset($arOptions['SHOW_CATALOG_BUTTONS'])) && !empty($arOptions['USE_CATALOG_BUTTONS']) && is_array($arOptions['USE_CATALOG_BUTTONS']));
398 $catalogButtons = array();
399 if ($useCatalogButtons || (isset($arOptions["CATALOG"]) && $arOptions["CATALOG"] == true))
400 {
401 if (self::$catalogIncluded === null)
402 self::$catalogIncluded = \Bitrix\Main\Loader::includeModule('catalog');
403 $bCatalog = self::$catalogIncluded;
404 if (!self::$catalogIncluded)
405 $useCatalogButtons = false;
406 }
407
408 if ($useCatalogButtons)
409 {
410 if (isset($arOptions['USE_CATALOG_BUTTONS']['add_product']) && $arOptions['USE_CATALOG_BUTTONS']['add_product'] == true)
411 $catalogButtons['add_product'] = true;
412 if (isset($arOptions['USE_CATALOG_BUTTONS']['add_sku']) && $arOptions['USE_CATALOG_BUTTONS']['add_sku'] == true)
413 $catalogButtons['add_sku'] = true;
414 if (empty($catalogButtons))
415 $useCatalogButtons = false;
416 }
417
418 $return_url = array(
419 "add_element" => "",
420 "edit_element" => "",
421 "edit_iblock" => "",
422 "history_element" => "",
423 "edit_section" => "",
424 "add_section" => "",
425 "delete_section" => "",
426 "delete_element" => "",
427 "element_list" => "",
428 "section_list" => "",
429 );
430
431 if(isset($arOptions['RETURN_URL']))
432 {
433 if(is_array($arOptions["RETURN_URL"]))
434 {
435 foreach($arOptions["RETURN_URL"] as $key => $url)
436 if(!empty($url) && array_key_exists($key, $return_url))
437 $return_url[$key] = $url;
438 }
439 elseif(!empty($arOptions["RETURN_URL"]))
440 {
441 foreach($return_url as $key => $url)
442 $return_url[$key] = $arOptions["RETURN_URL"];
443 }
444 }
445
446 $str = "";
447 foreach($return_url as $key => $url)
448 {
449 if(empty($url))
450 {
451 if(empty($str))
452 {
453 $str = \Bitrix\Main\Context::getCurrent()->getServer()->getRequestUri();
454 if(defined("BX_AJAX_PARAM_ID"))
456 }
457
458 $return_url[$key] = $str;
459 }
460 }
461
463 if (self::$workflowIncluded === null)
464 self::$workflowIncluded = \Bitrix\Main\Loader::includeModule('workflow');
465 $bWorkflow = self::$workflowIncluded && ($arIBlock["WORKFLOW"] !== "N");
466 $s = $bWorkflow? "&WF=Y": "";
467
468 $arLabels = ($arOptions["LABELS"] ?? []);
469 $labelList = [
470 'ELEMENT_EDIT_TEXT' => 'ELEMENT_EDIT',
471 'ELEMENT_EDIT_TITLE' => 'ELEMENT_EDIT',
472 'ELEMENT_ADD_TEXT' => 'ELEMENT_ADD',
473 'ELEMENT_ADD_TITLE' => 'ELEMENT_ADD',
474 'ELEMENT_DELETE_TEXT' => 'ELEMENT_DELETE',
475 'ELEMENT_DELETE_TITLE' => 'ELEMENT_DELETE',
476 'SECTION_EDIT_TEXT' => 'SECTION_EDIT',
477 'SECTION_EDIT_TITLE' => 'SECTION_EDIT',
478 'SECTION_ADD_TEXT' => 'SECTION_ADD',
479 'SECTION_ADD_TITLE' => 'SECTION_ADD',
480 'SECTION_DELETE_TEXT' => 'SECTION_DELETE',
481 'SECTION_DELETE_TITLE' => 'SECTION_DELETE',
482 'ELEMENTS_NAME_TEXT' => 'ELEMENTS_NAME',
483 'ELEMENTS_NAME_TITLE' => 'ELEMENTS_NAME',
484 'SECTIONS_NAME_TEXT' => 'SECTIONS_NAME',
485 'SECTIONS_NAME_TITLE' => 'SECTIONS_NAME',
486 ];
487 foreach ($labelList as $phraseId => $iblockPhrase)
488 {
489 if (
490 isset($arLabels[$phraseId])
491 && is_string($arLabels[$phraseId])
492 && $arLabels[$phraseId] !== ''
493 )
494 {
495 continue;
496 }
497 $arLabels[$phraseId] = $arIBlock[$iblockPhrase];
498 }
499
500 if($ELEMENT_ID > 0 && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ELEMENT_ID, "element_edit"))
501 {
502 $url = "/bitrix/admin/".CIBlock::GetAdminElementEditLink($IBLOCK_ID, $ELEMENT_ID, array(
503 "force_catalog" => $bCatalog,
504 "filter_section" => $SECTION_ID,
505 "bxpublic" => "Y",
506 "from_module" => "iblock",
507 "return_url" => $return_url["edit_element"],
508 )).$s;
509
510 $action = $APPLICATION->GetPopupLink(
511 array(
512 "URL" => $url,
513 "PARAMS" => $windowParams,
514 )
515 );
516
517 $arButton = array(
518 "TEXT" => $arLabels["ELEMENT_EDIT_TEXT"],
519 "TITLE" => $arLabels["ELEMENT_EDIT_TITLE"],
520 "ACTION" => 'javascript:'.$action,
521 "ACTION_URL" => $url,
522 "ONCLICK" => $action,
523 "DEFAULT" => $APPLICATION->GetPublicShowMode() !== 'configure',
524 "ICON" => "bx-context-toolbar-edit-icon",
525 "ID" => "bx-context-toolbar-edit-element"
526 );
527 $arButtons["edit"]["edit_element"] = $arButton;
528 $arButtons["configure"]["edit_element"] = $arButton;
529
530 $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
531 $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')";
532 unset($arButton["ONCLICK"]);
533 $arButtons["submenu"]["edit_element"] = $arButton;
534
535 if($bWorkflow)
536 {
537 $url = "/bitrix/admin/iblock_history_list.php?type=".$arIBlock["IBLOCK_TYPE_ID"]."&lang=".LANGUAGE_ID."&IBLOCK_ID=".$IBLOCK_ID."&ELEMENT_ID=".$ELEMENT_ID."&filter_section=".$SECTION_ID."&return_url=".UrlEncode($return_url["history_element"]);
538 $arButton = array(
539 "TEXT" => Loc::getMessage("IBLOCK_PANEL_HISTORY_BUTTON"),
540 "TITLE" => Loc::getMessage("IBLOCK_PANEL_HISTORY_BUTTON"),
541 "ACTION" => "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
542 "ONCLICK" => "jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
543 "ID" => "bx-context-toolbar-history-element"
544 );
545 $arButtons["submenu"]["history_element"] = $arButton;
546 }
547 }
548
549 if(CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_element_bind"))
550 {
551 $params = array(
552 "force_catalog" => $bCatalog,
553 "filter_section" => $SECTION_ID,
554 "IBLOCK_SECTION_ID" => $SECTION_ID,
555 "bxpublic" => "Y",
556 "from_module" => "iblock",
557 "return_url" => $return_url["add_element"],
558 );
559
560 if ($useCatalogButtons)
561 {
562 CCatalogAdminTools::setProductFormParams();
563 CCatalogAdminTools::setCatalogPanelButtons($arButtons, $IBLOCK_ID, $catalogButtons, $params, $windowParams);
564 }
565 else
566 {
567 $url = "/bitrix/admin/".CIBlock::GetAdminElementEditLink($IBLOCK_ID, null, $params);
568 $action = $APPLICATION->GetPopupLink(
569 array(
570 "URL" => $url,
571 "PARAMS" => $windowParams,
572 )
573 );
574 $arButton = array(
575 "TEXT" => $arLabels["ELEMENT_ADD_TEXT"],
576 "TITLE" => $arLabels["ELEMENT_ADD_TITLE"],
577 "ACTION" => 'javascript:'.$action,
578 "ACTION_URL" => $url,
579 "ONCLICK" => $action,
580 "ICON" => "bx-context-toolbar-create-icon",
581 "ID" => "bx-context-toolbar-add-element",
582 );
583 $arButtons["edit"]["add_element"] = $arButton;
584 $arButtons["configure"]["add_element"] = $arButton;
585 $arButtons["intranet"][] = array(
586 'TEXT' => $arButton["TEXT"],
587 'TITLE' => $arButton["TITLE"],
588 'ICON' => 'add',
589 'ONCLICK' => $arButton["ACTION"],
590 'SORT' => 1000,
591 );
592
593 $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
594 $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')";
595 unset($arButton["ONCLICK"]);
596 $arButtons["submenu"]["add_element"] = $arButton;
597 }
598 }
599
600 if($ELEMENT_ID > 0 && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ELEMENT_ID, "element_delete"))
601 {
602 //Delete Element
603 if(!empty($arButtons["edit"]))
604 $arButtons["edit"][] = array("SEPARATOR" => "Y", "HREF" => "");
605 if(!empty($arButtons["configure"]))
606 $arButtons["configure"][] = array("SEPARATOR" => "Y", "HREF" => "");
607 if(!empty($arButtons["submenu"]))
608 $arButtons["submenu"][] = array("SEPARATOR" => "Y", "HREF" => "");
609
611 if($bSessID)
612 $url .= '&'.bitrix_sessid_get();
613 $url .= '&ID='.(preg_match('/^iblock_list_admin\.php/', $url)? "E": "").$ELEMENT_ID."&return_url=".UrlEncode($return_url["delete_element"]);
614 $url = "/bitrix/admin/".$url;
615 $arButton = array(
616 "TEXT" => $arLabels["ELEMENT_DELETE_TEXT"],
617 "TITLE" => $arLabels["ELEMENT_DELETE_TITLE"],
618 "ACTION"=>"javascript:if(confirm('".CUtil::JSEscape(Loc::getMessage("IBLOCK_PANEL_ELEMENT_DEL_CONF"))."'))jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
619 "ACTION_URL" => $url,
620 "ONCLICK"=>"if(confirm('".CUtil::JSEscape(Loc::getMessage("IBLOCK_PANEL_ELEMENT_DEL_CONF"))."'))jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
621 "ICON" => "bx-context-toolbar-delete-icon",
622 "ID" => "bx-context-toolbar-delete-element"
623 );
624 $arButtons["edit"]["delete_element"] = $arButton;
625 $arButtons["configure"]["delete_element"] = $arButton;
626 $arButtons["submenu"]["delete_element"] = $arButton;
627 }
628
629 if($ELEMENT_ID <= 0 && $bSectionButtons)
630 {
631 $rsIBTYPE = CIBlockType::GetByID($arIBlock["IBLOCK_TYPE_ID"]);
632 if(($arIBTYPE = $rsIBTYPE->Fetch()) && ($arIBTYPE["SECTIONS"] == "Y"))
633 {
634 if($SECTION_ID > 0 && CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_edit"))
635 {
636 if(!empty($arButtons["edit"]))
637 $arButtons["edit"][] = array("SEPARATOR" => "Y", "HREF" => "");
638 if(!empty($arButtons["configure"]))
639 $arButtons["configure"][] = array("SEPARATOR" => "Y", "HREF" => "");
640 if(!empty($arButtons["submenu"]))
641 $arButtons["submenu"][] = array("SEPARATOR" => "Y", "HREF" => "");
642
643 $url = "/bitrix/admin/".CIBlock::GetAdminSectionEditLink($IBLOCK_ID, $SECTION_ID, array(
644 "force_catalog" => $bCatalog,
645 "filter_section" => $SECTION_ID,
646 "bxpublic" => "Y",
647 "from_module" => "iblock",
648 "return_url" => $return_url["edit_section"],
649 ));
650
651 $action = $APPLICATION->GetPopupLink(
652 array(
653 "URL" => $url,
654 "PARAMS" => $windowParams,
655 )
656 );
657
658 $arButton = array(
659 "TEXT" => $arLabels["SECTION_EDIT_TEXT"],
660 "TITLE" => $arLabels["SECTION_EDIT_TITLE"],
661 "ACTION" => 'javascript:'.$action,
662 "ACTION_URL" => $url,
663 "ICON" => "bx-context-toolbar-edit-icon",
664 "ONCLICK" => $action,
665 "DEFAULT" => $APPLICATION->GetPublicShowMode() !== 'configure',
666 "ID" => "bx-context-toolbar-edit-section"
667 );
668 $arButtons["edit"]["edit_section"] = $arButton;
669 $arButtons["configure"]["edit_section"] = $arButton;
670
671 $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
672 $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')";
673 unset($arButton["ONCLICK"]);
674 $arButtons["submenu"]["edit_section"] = $arButton;
675 }
676
677 if(CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_section_bind"))
678 {
679 $url = "/bitrix/admin/".CIBlock::GetAdminSectionEditLink($IBLOCK_ID, null, array(
680 "force_catalog" => $bCatalog,
681 "IBLOCK_SECTION_ID" => $SECTION_ID,
682 "filter_section" => $SECTION_ID,
683 "bxpublic" => "Y",
684 "from_module" => "iblock",
685 "return_url" => $return_url["add_section"],
686 ));
687
688 $action = $APPLICATION->GetPopupLink(
689 array(
690 "URL" => $url,
691 "PARAMS" => $windowParams,
692 )
693 );
694
695 $arButton = array(
696 "TEXT" => $arLabels["SECTION_ADD_TEXT"],
697 "TITLE" => $arLabels["SECTION_ADD_TITLE"],
698 "ACTION" => 'javascript:'.$action,
699 "ACTION_URL" => $url,
700 "ICON" => "bx-context-toolbar-create-icon",
701 "ID" => "bx-context-toolbar-add-section",
702 "ONCLICK" => $action
703 );
704
705 $arButtons["edit"]["add_section"] = $arButton;
706 $arButtons["configure"]["add_section"] = $arButton;
707
708 $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
709 $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')";
710 unset($arButton["ONCLICK"]);
711 $arButtons["submenu"]["add_section"] = $arButton;
712 }
713
714 //Delete section
715 if($SECTION_ID > 0 && CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_delete"))
716 {
717 $url = CIBlock::GetAdminSectionListLink($IBLOCK_ID, Array('action'=>'delete'));
718 if($bSessID)
719 $url .= '&'.bitrix_sessid_get();
720 $url .= '&ID[]='.(preg_match('/^iblock_list_admin\.php/', $url)? "S": "").$SECTION_ID."&return_url=".UrlEncode($return_url["delete_section"]);
721 $url = "/bitrix/admin/".$url;
722
723 $arButton = array(
724 "TEXT" => $arLabels["SECTION_DELETE_TEXT"],
725 "TITLE" => $arLabels["SECTION_DELETE_TITLE"],
726 "ACTION" => "javascript:if(confirm('".CUtil::JSEscape(Loc::getMessage("IBLOCK_PANEL_SECTION_DEL_CONF"))."'))jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
727 "ACTION_URL" => $url,
728 "ONCLICK" => "if(confirm('".CUtil::JSEscape(Loc::getMessage("IBLOCK_PANEL_SECTION_DEL_CONF"))."'))jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
729 "ICON" => "bx-context-toolbar-delete-icon",
730 "ID" => "bx-context-toolbar-delete-section"
731 );
732 $arButtons["edit"]["delete_section"] = $arButton;
733 $arButtons["configure"]["delete_section"] = $arButton;
734 $arButtons["submenu"]["delete_section"] = $arButton;
735 }
736 }
737 }
738
739 if( ($IBLOCK_ID > 0) && CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, "iblock_admin_display") )
740 {
741 if(!empty($arButtons["submenu"]))
742 $arButtons["submenu"][] = array("SEPARATOR" => "Y", "HREF" => "");
743
744 if($SECTION_ID > 0)
745 $url = "/bitrix/admin/".CIBlock::GetAdminElementListLink($IBLOCK_ID , array('find_section_section'=>$SECTION_ID));
746 else
747 $url = "/bitrix/admin/".CIBlock::GetAdminElementListLink($IBLOCK_ID , array(
748 'find_el_y'=>'Y', 'clear_filter'=>'Y', 'apply_filter'=>'Y'));
749
750 $arButton = array(
751 "TEXT" => (($arLabels["ELEMENTS_NAME_TEXT"] ?? '') <> ''? $arLabels["ELEMENTS_NAME_TEXT"] : $arIBlock["ELEMENTS_NAME"]),
752 "TITLE" => (($arLabels["ELEMENTS_NAME_TITLE"] ?? '') <> ''? $arLabels["ELEMENTS_NAME_TITLE"] : $arIBlock["ELEMENTS_NAME"]),
753 "ACTION" => "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
754 "ACTION_URL" => $url,
755 "ONCLICK" => "jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
756 "ID" => "bx-context-toolbar-elements-list"
757 );
758 $arButtons["submenu"]["element_list"] = $arButton;
759
760 $arButtons["intranet"]["element_list"] = array(
761 'TEXT' => $arButton["TEXT"],
762 'TITLE' => $arButton["TITLE"],
763 'ICON' => 'settings',
764 'ONCLICK' => $arButton["ACTION"],
765 'SORT' => 1010,
766 );
767
768 $url = "/bitrix/admin/".CIBlock::GetAdminSectionListLink($IBLOCK_ID, array('find_section_section'=>$SECTION_ID));
769 $arButton = array(
770 "TEXT" => (($arLabels["SECTIONS_NAME_TEXT"] ?? '') <> ''? $arLabels["SECTIONS_NAME_TEXT"] : $arIBlock["SECTIONS_NAME"]),
771 "TITLE" => (($arLabels["SECTIONS_NAME_TITLE"] ?? '') <> ''? $arLabels["SECTIONS_NAME_TITLE"] : $arIBlock["SECTIONS_NAME"]),
772 "ACTION" => "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
773 "ACTION_URL" => $url,
774 "ONCLICK" => "jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
775 "ID" => "bx-context-toolbar-sections-list"
776 );
777 $arButtons["submenu"]["section_list"] = $arButton;
778
779 if(CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, "iblock_edit"))
780 {
781 $url = "/bitrix/admin/iblock_edit.php?type=".$arIBlock["IBLOCK_TYPE_ID"]."&lang=".LANGUAGE_ID."&ID=".$IBLOCK_ID."&return_url=".UrlEncode($return_url["edit_iblock"]);
782 $arButton = array(
783 "TEXT" => Loc::getMessage("IBLOCK_PANEL_EDIT_IBLOCK_BUTTON", array("#IBLOCK_NAME#"=>$arIBlock["NAME"])),
784 "TITLE" => Loc::getMessage("IBLOCK_PANEL_EDIT_IBLOCK_BUTTON", array("#IBLOCK_NAME#"=>$arIBlock["NAME"])),
785 "ACTION" => "javascript:jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
786 "ACTION_URL" => $url,
787 "ONCLICK" => "jsUtils.Redirect([], '".CUtil::JSEscape($url)."')",
788 "ID" => "bx-context-toolbar-edit-iblock"
789 );
790 $arButtons["submenu"]["edit_iblock"] = $arButton;
791 }
792 }
793
794 return $arButtons;
795 }
796
801 public static function GetSite($iblock_id)
802 {
804 global $DB;
805
806 $strSql = "SELECT L.*, BS.* FROM b_iblock_site BS, b_lang L WHERE L.LID=BS.SITE_ID AND BS.IBLOCK_ID=".intval($iblock_id);
807 return $DB->Query($strSql);
808 }
809
811 // Block by ID
813 public static function GetByID($ID)
814 {
815 return CIBlock::GetList(Array(), Array("ID"=>$ID));
816 }
817
823 public static function GetArrayByID($ID, $FIELD = "")
824 {
826 global $DB;
827 $ID = (int)$ID;
828 if ($ID <= 0)
829 return false;
830
831 if(CACHED_b_iblock === false)
832 {
833 $res = $DB->Query("
834 SELECT b_iblock.*,".$DB->DateToCharFunction("TIMESTAMP_X")." TIMESTAMP_X
835 from b_iblock
836 WHERE ID = ".$ID
837 );
838 $arResult = $res->Fetch();
839 if($arResult)
840 {
841 $arMessages = CIBlock::GetMessages($ID);
842 $arResult = array_merge($arResult, $arMessages);
843 $arResult["FIELDS"] = CIBlock::GetFields($ID);
844 }
845 }
846 else
847 {
848 global $CACHE_MANAGER;
849
850 $bucket_size = intval(CACHED_b_iblock_bucket_size);
851 if($bucket_size<=0) $bucket_size = 20;
852
853 $bucket = intval($ID/$bucket_size);
854 $cache_id = $bucket_size."iblock".$bucket;
855
856 if($CACHE_MANAGER->Read(CACHED_b_iblock, $cache_id, "b_iblock"))
857 {
858 $arIBlocks = $CACHE_MANAGER->Get($cache_id);
859 }
860 else
861 {
862 $arIBlocks = array();
863 $res = $DB->Query("
864 SELECT b_iblock.*,".$DB->DateToCharFunction("TIMESTAMP_X")." TIMESTAMP_X
865 from b_iblock
866 WHERE ID between ".($bucket*$bucket_size)." AND ".(($bucket+1)*$bucket_size-1)
867 );
868 while($arIBlock = $res->Fetch())
869 {
870 $arMessages = CIBlock::GetMessages($arIBlock["ID"]);
871 $arIBlock = array_merge($arIBlock, $arMessages);
872 $arIBlock["FIELDS"] = CIBlock::GetFields($arIBlock["ID"]);
873 $arIBlocks[$arIBlock["ID"]] = $arIBlock;
874 }
875
876 $CACHE_MANAGER->Set($cache_id, $arIBlocks);
877 }
878
879 if(isset($arIBlocks[$ID]))
880 {
881 $arResult = $arIBlocks[$ID];
882
883 if(!array_key_exists("ELEMENT_DELETE", $arResult))
884 {
885 $arMessages = CIBlock::GetMessages($ID);
886 $arResult = array_merge($arResult, $arMessages);
888 }
889
890 if (
891 !array_key_exists("FIELDS", $arResult)
892 || !is_array($arResult["FIELDS"]["IBLOCK_SECTION"]["DEFAULT_VALUE"])
893 )
894 {
895 $arResult["FIELDS"] = CIBlock::GetFields($ID);
897 }
898 }
899 else
900 {
901 $arResult = false;
902 }
903 }
904 if (empty($arResult))
905 return false;
906
907 if ($FIELD)
908 {
909 if (array_key_exists($FIELD, $arResult))
910 return $arResult[$FIELD];
911 else
912 return null;
913 }
914 else
915 {
916 return $arResult;
917 }
918 }
919
920 public static function CleanCache($ID)
921 {
923 global $CACHE_MANAGER;
924
925 $ID = intval($ID);
926 if(CACHED_b_iblock !== false)
927 {
928 $bucket_size = intval(CACHED_b_iblock_bucket_size);
929 if($bucket_size<=0) $bucket_size = 20;
930
931 $bucket = intval($ID/$bucket_size);
932 $cache_id = $bucket_size."iblock".$bucket;
933
934 $CACHE_MANAGER->Clean($cache_id, "b_iblock");
935 }
937 Iblock\IblockSiteTable::cleanCache();
938 }
939
941 // New block
943 function Add($arFields)
944 {
946 global $CACHE_MANAGER;
948 global $DB;
949 $SAVED_PICTURE = null;
950
951 //Default Yes
952 $arFields["ACTIVE"] = isset($arFields["ACTIVE"]) && $arFields["ACTIVE"] === "N"? "N": "Y";
953 $arFields["WORKFLOW"] = isset($arFields["WORKFLOW"]) && $arFields["WORKFLOW"] === "N"? "N": "Y";
954 $arFields["INDEX_ELEMENT"] = isset($arFields["INDEX_ELEMENT"]) && $arFields["INDEX_ELEMENT"] === "N"? "N": "Y";
955 //Default No
956 $arFields["BIZPROC"] = isset($arFields["BIZPROC"]) && $arFields["BIZPROC"] === "Y"? "Y": "N";
957 $arFields["INDEX_SECTION"] = isset($arFields["INDEX_SECTION"]) && $arFields["INDEX_SECTION"] === "Y"? "Y": "N";
958 $arFields["FULLTEXT_INDEX"] = isset($arFields["FULLTEXT_INDEX"]) && $arFields["FULLTEXT_INDEX"] === "Y" ? "Y" : "N";
959
960 if(!isset($arFields["SECTION_CHOOSER"]))
961 $arFields["SECTION_CHOOSER"] = "L";
962 elseif($arFields["SECTION_CHOOSER"] !== "D" && $arFields["SECTION_CHOOSER"] !== "P")
963 $arFields["SECTION_CHOOSER"] = "L";
964
965 if(!isset($arFields["DESCRIPTION_TYPE"]) || $arFields["DESCRIPTION_TYPE"] !== "html")
966 $arFields["DESCRIPTION_TYPE"] = "text";
967
968 $arFields["VERSION"] = isset($arFields["VERSION"]) && intval($arFields["VERSION"]) === 2? "2": "1";
969
970 if(isset($arFields["RIGHTS_MODE"]))
971 $arFields["RIGHTS_MODE"] = $arFields["RIGHTS_MODE"] === "E"? "E": "S";
972 elseif(isset($arFields["RIGHTS"]))
973 $arFields["RIGHTS_MODE"] = "E";
974 else
975 $arFields["RIGHTS_MODE"] = "S";
976
977 if (array_key_exists("PICTURE", $arFields))
978 {
979 if(
980 !is_array($arFields["PICTURE"])
981 || (
982 ($arFields["PICTURE"]["name"] ?? '') === ''
983 && ($arFields["PICTURE"]["del"] ?? '' ) === ''
984 )
985 )
986 {
987 unset($arFields["PICTURE"]);
988 }
989 else
990 {
991 $arFields["PICTURE"]["MODULE_ID"] = "iblock";
992 }
993 }
994
995 if(array_key_exists("SITE_ID", $arFields))
996 {
997 $arFields["LID"] = $arFields["SITE_ID"];
998 unset($arFields["SITE_ID"]);
999 }
1000
1001 if(array_key_exists("EXTERNAL_ID", $arFields))
1002 {
1003 $arFields["XML_ID"] = $arFields["EXTERNAL_ID"];
1004 unset($arFields["EXTERNAL_ID"]);
1005 }
1006
1007 if(array_key_exists("SECTION_PROPERTY", $arFields))
1008 $arFields["SECTION_PROPERTY"] = "Y";
1009
1010 unset($arFields["ID"]);
1011
1012 if(!$this->CheckFields($arFields))
1013 {
1014 $Result = false;
1015 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
1016 }
1017 else
1018 {
1019 $arLID = array();
1020 if(array_key_exists("LID", $arFields))
1021 {
1022 if(is_array($arFields["LID"]))
1023 {
1024 foreach($arFields["LID"] as $site_id)
1025 $arLID[$site_id] = $DB->ForSQL($site_id);
1026 }
1027 else
1028 {
1029 $arLID[$arFields["LID"]] = $DB->ForSQL($arFields["LID"]);
1030 }
1031 }
1032
1033 if(empty($arLID))
1034 unset($arFields["LID"]);
1035 else
1036 $arFields["LID"] = end($arLID);
1037
1038 if(array_key_exists("PICTURE", $arFields))
1039 {
1040 $SAVED_PICTURE = $arFields["PICTURE"];
1041 CFile::SaveForDB($arFields, "PICTURE", "iblock");
1042 }
1043
1044 $ID = $DB->Add("b_iblock", $arFields, array("DESCRIPTION"), "iblock");
1045
1046 if(array_key_exists("PICTURE", $arFields))
1047 {
1048 $arFields["PICTURE"] = $SAVED_PICTURE;
1049 }
1050
1051 $this->SetMessages($ID, $arFields);
1052
1053 if(array_key_exists("FIELDS", $arFields) && is_array($arFields["FIELDS"]))
1054 $this->SetFields($ID, $arFields["FIELDS"]);
1055
1056 if($arFields["RIGHTS_MODE"] === "E")
1057 {
1058 if(
1059 !array_key_exists("RIGHTS", $arFields)
1060 && array_key_exists("GROUP_ID", $arFields)
1061 && is_array($arFields["GROUP_ID"])
1062 )
1063 {
1064 $obIBlockRights = new CIBlockRights($ID);
1065 $obIBlockRights->SetRights($obIBlockRights->ConvertGroups($arFields["GROUP_ID"]));
1066 }
1067 elseif(
1068 array_key_exists("RIGHTS", $arFields)
1069 && is_array($arFields["RIGHTS"])
1070 )
1071 {
1072 $obIBlockRights = new CIBlockRights($ID);
1073 $obIBlockRights->SetRights($arFields["RIGHTS"]);
1074 }
1075 }
1076 else
1077 {
1078 if(array_key_exists("GROUP_ID", $arFields) && is_array($arFields["GROUP_ID"]))
1079 $this->SetPermission($ID, $arFields["GROUP_ID"]);
1080 }
1081
1082 if (array_key_exists("IPROPERTY_TEMPLATES", $arFields))
1083 {
1084 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\IblockTemplates($ID);
1085 $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
1086 }
1087
1088 if(!empty($arLID))
1089 {
1090 $DB->Query("
1091 DELETE FROM b_iblock_site WHERE IBLOCK_ID = ".$ID."
1092 ");
1093
1094 $DB->Query("
1095 INSERT INTO b_iblock_site(IBLOCK_ID, SITE_ID)
1096 SELECT ".$ID.", LID
1097 FROM b_lang
1098 WHERE LID IN ('".implode("', '", $arLID)."')
1099 ");
1100 }
1101
1102 if($arFields["VERSION"] == 2)
1103 {
1104 if ($this->_Add($ID))
1105 {
1106 $Result = $ID;
1107 $arFields["ID"] = &$ID;
1108 }
1109 else
1110 {
1111 $this->LAST_ERROR = Loc::getMessage("IBLOCK_TABLE_CREATION_ERROR");
1112 $Result = false;
1113 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
1114 }
1115 }
1116 else
1117 {
1118 $Result = $ID;
1119 $arFields["ID"] = &$ID;
1120 }
1121
1122 if ($arFields["FULLTEXT_INDEX"] === "Y")
1123 {
1125 }
1126
1128
1129 $this->CleanCache($ID);
1130 }
1131
1132 $arFields["RESULT"] = &$Result;
1133
1134 foreach(GetModuleEvents("iblock", "OnAfterIBlockAdd", true) as $arEvent)
1136
1137 if(defined("BX_COMP_MANAGED_CACHE") && self::isEnabledClearTagCache())
1138 $CACHE_MANAGER->ClearByTag("iblock_id_new");
1139
1140 return $Result;
1141 }
1142
1144 // Update
1147 {
1149 global $DB;
1150 $ID = (int)$ID;
1151 if ($ID <= 0)
1152 {
1153 return false;
1154 }
1155 $SAVED_PICTURE = null;
1156
1157 if(is_set($arFields, "EXTERNAL_ID"))
1158 $arFields["XML_ID"] = $arFields["EXTERNAL_ID"];
1159
1160 if (array_key_exists("PICTURE", $arFields))
1161 {
1162 if (
1163 !is_array($arFields["PICTURE"])
1164 || (
1165 ($arFields["PICTURE"]["name"] ?? '') === ''
1166 && ($arFields["PICTURE"]["del"] ?? '') === ''
1167 )
1168 )
1169 {
1170 unset($arFields["PICTURE"]);
1171 }
1172 else
1173 {
1174 $pic_res = $DB->Query("SELECT PICTURE FROM b_iblock WHERE ID=".$ID);
1175 if($pic_res = $pic_res->Fetch())
1176 {
1177 $arFields["PICTURE"]["old_file"] = $pic_res["PICTURE"];
1178 }
1179 $arFields["PICTURE"]["MODULE_ID"] = "iblock";
1180 }
1181 }
1182
1183 if(is_set($arFields, "ACTIVE") && $arFields["ACTIVE"]!="Y")
1184 $arFields["ACTIVE"]="N";
1185
1186 if(is_set($arFields, "WORKFLOW") && $arFields["WORKFLOW"]!="N")
1187 $arFields["WORKFLOW"]="Y";
1188
1189 if(is_set($arFields, "BIZPROC") && $arFields["BIZPROC"]!="Y")
1190 $arFields["BIZPROC"]="N";
1191
1192 if(is_set($arFields, "SECTION_CHOOSER") && $arFields["SECTION_CHOOSER"]!="D" && $arFields["SECTION_CHOOSER"]!="P")
1193 $arFields["SECTION_CHOOSER"]="L";
1194
1195 if(is_set($arFields, "INDEX_SECTION") && $arFields["INDEX_SECTION"]!="Y")
1196 $arFields["INDEX_SECTION"]="N";
1197
1198 if(is_set($arFields, "INDEX_ELEMENT") && $arFields["INDEX_ELEMENT"]!="Y")
1199 $arFields["INDEX_ELEMENT"]="N";
1200
1201 if(is_set($arFields, "DESCRIPTION_TYPE") && $arFields["DESCRIPTION_TYPE"]!="html")
1202 $arFields["DESCRIPTION_TYPE"] = "text";
1203
1204 if(is_set($arFields, "SITE_ID"))
1205 $arFields["LID"] = $arFields["SITE_ID"];
1206
1207 if(is_set($arFields, "SECTION_PROPERTY"))
1208 $arFields["SECTION_PROPERTY"] = "Y";
1209
1210 if(is_set($arFields, "PROPERTY_INDEX") && $arFields["PROPERTY_INDEX"]!="I" && $arFields["PROPERTY_INDEX"]!="Y")
1211 $arFields["SECTION_PROPERTY"] = "N";
1212
1213 $iblockDataBeforeUpdate = CIBlock::GetArrayByID($ID);
1214 $RIGHTS_MODE = $iblockDataBeforeUpdate["RIGHTS_MODE"];
1215
1216 if(!$this->CheckFields($arFields, $ID))
1217 {
1218 $Result = false;
1219 $arFields["RESULT_MESSAGE"] = &$this->LAST_ERROR;
1220 }
1221 else
1222 {
1223 $arLID = array();
1224 $str_LID = "";
1225 if(is_set($arFields, "LID"))
1226 {
1227 if(is_array($arFields["LID"]))
1228 $arLID = $arFields["LID"];
1229 else
1230 $arLID[] = $arFields["LID"];
1231
1232 $arFields["LID"] = false;
1233 $str_LID = "''";
1234 foreach($arLID as $v)
1235 {
1236 $arFields["LID"] = $v;
1237 $str_LID .= ", '".$DB->ForSql($v)."'";
1238 }
1239 }
1240
1241 unset($arFields["ID"]);
1242 unset($arFields["VERSION"]);
1243
1244 if(array_key_exists("PICTURE", $arFields))
1245 {
1246 $SAVED_PICTURE = $arFields["PICTURE"];
1247 CFile::SaveForDB($arFields, "PICTURE", "iblock");
1248 }
1249
1250 $strUpdate = $DB->PrepareUpdate("b_iblock", $arFields, "iblock");
1251
1252 if(array_key_exists("PICTURE", $arFields))
1253 $arFields["PICTURE"] = $SAVED_PICTURE;
1254
1255 $arBinds=Array();
1256 if(is_set($arFields, "DESCRIPTION"))
1257 $arBinds["DESCRIPTION"] = $arFields["DESCRIPTION"];
1258
1259 if($strUpdate <> '')
1260 {
1261 $strSql = "UPDATE b_iblock SET ".$strUpdate." WHERE ID=".$ID;
1262 $DB->QueryBind($strSql, $arBinds);
1263 }
1264
1265 $this->SetMessages($ID, $arFields);
1266 if(isset($arFields["FIELDS"]) && is_array($arFields["FIELDS"]))
1267 $this->SetFields($ID, $arFields["FIELDS"]);
1268
1269 if(array_key_exists("RIGHTS_MODE", $arFields))
1270 {
1271 if($arFields["RIGHTS_MODE"] === "E" && $RIGHTS_MODE !== "E")
1272 {
1274 }
1275 elseif($arFields["RIGHTS_MODE"] !== "E" && $RIGHTS_MODE === "E")
1276 {
1277 $obIBlockRights = new CIBlockRights($ID);
1278 $obIBlockRights->DeleteAllRights();
1279 }
1280
1281 if($arFields["RIGHTS_MODE"] === "E")
1282 $RIGHTS_MODE = "E";
1283 }
1284
1285 if($RIGHTS_MODE === "E")
1286 {
1287 if(
1288 !array_key_exists("RIGHTS", $arFields)
1289 && array_key_exists("GROUP_ID", $arFields)
1290 && is_array($arFields["GROUP_ID"])
1291 )
1292 {
1293 $obIBlockRights = new CIBlockRights($ID);
1294 $obIBlockRights->SetRights($obIBlockRights->ConvertGroups($arFields["GROUP_ID"]));
1295 }
1296 elseif(
1297 array_key_exists("RIGHTS", $arFields)
1298 && is_array($arFields["RIGHTS"])
1299 )
1300 {
1301 $obIBlockRights = new CIBlockRights($ID);
1302 $obIBlockRights->SetRights($arFields["RIGHTS"]);
1303 }
1304 }
1305 else
1306 {
1307 if(array_key_exists("GROUP_ID", $arFields) && is_array($arFields["GROUP_ID"]))
1308 CIBlock::SetPermission($ID, $arFields["GROUP_ID"]);
1309 }
1310
1311 if (array_key_exists("IPROPERTY_TEMPLATES", $arFields))
1312 {
1313 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\IblockTemplates($ID);
1314 $ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
1315 }
1316
1317 if(!empty($arLID))
1318 {
1319 $strSql = "DELETE FROM b_iblock_site WHERE IBLOCK_ID=".$ID;
1320 $DB->Query($strSql);
1321
1322 $strSql =
1323 "INSERT INTO b_iblock_site(IBLOCK_ID, SITE_ID) ".
1324 "SELECT ".$ID.", LID ".
1325 "FROM b_lang ".
1326 "WHERE LID IN (".$str_LID.") ";
1327 $DB->Query($strSql);
1328 }
1329
1330 if (
1331 isset($arFields["FULLTEXT_INDEX"])
1332 && $arFields["FULLTEXT_INDEX"] === "Y"
1333 && $iblockDataBeforeUpdate["FULLTEXT_INDEX"] === "N"
1334 )
1335 {
1337 }
1338 if (
1339 isset($arFields["FULLTEXT_INDEX"])
1340 && $arFields["FULLTEXT_INDEX"] === "N"
1341 && $iblockDataBeforeUpdate["FULLTEXT_INDEX"] === "Y"
1342 )
1343 {
1345 }
1346
1347 if(CModule::IncludeModule("search"))
1348 {
1349 $dbAfter = $DB->Query("SELECT ACTIVE FROM b_iblock WHERE ID=".$ID);
1350 $arAfter = $dbAfter->Fetch();
1351 if($arAfter["ACTIVE"] != "Y")
1352 CSearch::DeleteIndex("iblock", false, false, $ID);
1353 }
1354
1356
1357 $Result = true;
1358 }
1359
1360 $this->CleanCache($ID);
1361
1362 $arFields["ID"] = $ID;
1363 $arFields["RESULT"] = &$Result;
1364
1365 foreach (GetModuleEvents("iblock", "OnAfterIBlockUpdate", true) as $arEvent)
1367
1369
1370 return $Result;
1371 }
1372
1374 // Function deletes iblock by ID
1376 public static function Delete($ID)
1377 {
1379 global $DB;
1381 global $APPLICATION;
1383 global $USER_FIELD_MANAGER;
1384
1385 $ID = (int)$ID;
1386 if ($ID <= 0)
1387 {
1388 return false;
1389 }
1390
1391 $APPLICATION->ResetException();
1392 foreach(GetModuleEvents("iblock", "OnBeforeIBlockDelete", true) as $arEvent)
1393 {
1394 if(ExecuteModuleEventEx($arEvent, array($ID)) === false)
1395 {
1396 $err = Loc::getMessage("MAIN_BEFORE_DEL_ERR").' '.$arEvent['TO_NAME'];
1397 $ex = $APPLICATION->GetException();
1398 if(is_object($ex))
1399 $err .= ': '.$ex->GetString();
1400 $APPLICATION->throwException($err);
1401 return false;
1402 }
1403 }
1404
1405 foreach (GetModuleEvents("iblock", "OnIBlockDelete", true) as $arEvent)
1406 ExecuteModuleEventEx($arEvent, array($ID));
1407
1408 $iblockSections = CIBlockSection::GetList(Array(), Array(
1409 "IBLOCK_ID" => $ID,
1410 "DEPTH_LEVEL" => 1,
1411 "CHECK_PERMISSIONS" => "N",
1412 ), false, Array("ID"));
1413 while($iblockSection = $iblockSections->Fetch())
1414 {
1415 if(!CIBlockSection::Delete($iblockSection["ID"], false))
1416 return false;
1417 }
1418
1419 $iblockElements = CIBlockElement::GetList(Array(), Array(
1420 "IBLOCK_ID" => $ID,
1421 "SHOW_NEW" => "Y",
1422 "CHECK_PERMISSIONS" => "N",
1423 ), false, false, array("IBLOCK_ID", "ID"));
1424 while($iblockElement = $iblockElements->Fetch())
1425 {
1426 if(!CIBlockElement::Delete($iblockElement["ID"]))
1427 return false;
1428 }
1429
1430 $props = CIBlockProperty::GetList(array(), array(
1431 "IBLOCK_ID" => $ID,
1432 "CHECK_PERMISSIONS" =>"N",
1433 ));
1434 while($property = $props->Fetch())
1435 {
1436 if(!CIBlockProperty::Delete($property["ID"]))
1437 return false;
1438 }
1439
1440 CFile::Delete(self::GetArrayByID($ID , "PICTURE"));
1441
1442 $seq = new CIBlockSequence($ID);
1443 $seq->Drop(true);
1444
1445 $obIBlockRights = new CIBlockRights($ID);
1446 $obIBlockRights->DeleteAllRights();
1447
1448 $ipropTemplates = new \Bitrix\Iblock\InheritedProperty\IblockTemplates($ID);
1449 $ipropTemplates->delete();
1450
1451 CIBlockSectionPropertyLink::DeleteByIBlock($ID);
1452
1453 $DB->Query("delete from b_iblock_offers_tmp where PRODUCT_IBLOCK_ID=".$ID);
1454 $DB->Query("delete from b_iblock_offers_tmp where OFFERS_IBLOCK_ID=".$ID);
1455
1456 if(!$DB->Query("DELETE FROM b_iblock_messages WHERE IBLOCK_ID = ".$ID))
1457 return false;
1458
1459 if(!$DB->Query("DELETE FROM b_iblock_fields WHERE IBLOCK_ID = ".$ID))
1460 return false;
1461
1462 $USER_FIELD_MANAGER->OnEntityDelete("IBLOCK_".$ID."_SECTION");
1463
1464 if(!$DB->Query("DELETE FROM b_iblock_group WHERE IBLOCK_ID=".$ID))
1465 return false;
1466 if(!$DB->Query("DELETE FROM b_iblock_rss WHERE IBLOCK_ID=".$ID))
1467 return false;
1468 if(!$DB->Query("DELETE FROM b_iblock_site WHERE IBLOCK_ID=".$ID))
1469 return false;
1470 if(!$DB->Query("DELETE FROM b_iblock WHERE ID=".$ID))
1471 return false;
1472
1474
1475 if ($DB->TableExists('b_iblock_element_prop_s' . $ID))
1476 {
1477 $DB->DDL('DROP TABLE b_iblock_element_prop_s' . $ID, true);
1478 }
1479 if ($DB->TableExists('b_iblock_element_prop_m' . $ID))
1480 {
1481 $DB->DDL('DROP TABLE b_iblock_element_prop_m' . $ID, true);
1482 }
1483
1485
1486 foreach(GetModuleEvents("iblock", "OnAfterIBlockDelete", true) as $arEvent)
1487 ExecuteModuleEventEx($arEvent, array($ID));
1488
1490
1492
1493 return true;
1494 }
1495
1497 // Check function called from Add and Update
1499 function CheckFields(&$arFields, $ID=false)
1500 {
1502 global $APPLICATION;
1503 $this->LAST_ERROR = "";
1504
1505 if ($ID !== false)
1506 {
1507 $ID = (int)$ID;
1508 if ($ID <= 0)
1509 {
1510 return false;
1511 }
1512 }
1513
1514 $NAME = $arFields["NAME"] ?? "";
1515 if(
1516 ($ID===false || array_key_exists("NAME", $arFields))
1517 && (string)$NAME === ''
1518 )
1519 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_NAME")."<br>";
1520
1521 if($ID===false && !is_set($arFields, "IBLOCK_TYPE_ID"))
1522 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_BLOCK_TYPE")."<br>";
1523
1524 if($ID===false)
1525 {
1526 //For new record take default values
1527 $WORKFLOW = array_key_exists("WORKFLOW", $arFields)? $arFields["WORKFLOW"]: "Y";
1528 $BIZPROC = array_key_exists("BIZPROC", $arFields)? $arFields["BIZPROC"]: "N";
1529 }
1530 else
1531 {
1532 //For existing one read old values
1534 if (!is_array($arIBlock))
1535 {
1536 $this->LAST_ERROR .= Loc::getMessage('IBLOCK_ERR_IBLOCK_IS_ABSENT') . '<br>';
1537 }
1538 $WORKFLOW = array_key_exists("WORKFLOW", $arFields)? $arFields["WORKFLOW"]: $arIBlock["WORKFLOW"];
1539 $BIZPROC = array_key_exists("BIZPROC", $arFields)? $arFields["BIZPROC"]: $arIBlock["BIZPROC"];
1540 if($BIZPROC != "Y") $BIZPROC = "N";//This is cache compatibility issue
1541 }
1542
1543 if($WORKFLOW == "Y" && $BIZPROC == "Y")
1544 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_WORKFLOW_AND_BIZPROC")."<br>";
1545
1546 if(is_set($arFields, "IBLOCK_TYPE_ID"))
1547 {
1548 $r = CIBlockType::GetByID($arFields["IBLOCK_TYPE_ID"]);
1549 if(!$r->Fetch())
1550 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_BLOCK_TYPE_ID")."<br>";
1551 }
1552
1553 if(
1554 isset($arFields["PICTURE"])
1555 && is_array($arFields["PICTURE"])
1556 && array_key_exists("bucket", $arFields["PICTURE"])
1557 && is_object($arFields["PICTURE"]["bucket"])
1558 )
1559 {
1560 //This is trusted image from xml import
1561 }
1562 elseif(
1563 isset($arFields["PICTURE"])
1564 && is_array($arFields["PICTURE"])
1565 && isset($arFields["PICTURE"]["name"])
1566 )
1567 {
1568 $error = CFile::CheckImageFile($arFields["PICTURE"]);
1569 if ($error <> '')
1570 $this->LAST_ERROR .= $error."<br>";
1571 }
1572
1573 if(
1574 ($ID===false && !is_set($arFields, "LID")) ||
1575 (is_set($arFields, "LID")
1576 && (
1577 (is_array($arFields["LID"]) && count($arFields["LID"])<=0)
1578 ||
1579 (!is_array($arFields["LID"]) && $arFields["LID"] == '')
1580 )
1581 )
1582 )
1583 {
1584 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_SITE_ID_NA")."<br>";
1585 }
1586 elseif(is_set($arFields, "LID"))
1587 {
1588 if(!is_array($arFields["LID"]))
1589 $arFields["LID"] = Array($arFields["LID"]);
1590
1591 foreach($arFields["LID"] as $v)
1592 {
1593 $r = CSite::GetByID($v);
1594 if(!$r->Fetch())
1595 $this->LAST_ERROR .= "'".$v."' - ".Loc::getMessage("IBLOCK_BAD_SITE_ID")."<br>";
1596 }
1597 }
1598
1599 if (is_set($arFields, "API_CODE"))
1600 {
1601 if ($arFields['API_CODE'] == '')
1602 {
1603 $arFields['API_CODE'] = false;
1604 }
1605 else
1606 {
1607 if (!preg_match('/^[a-z][a-z0-9]{0,49}$/i', $arFields['API_CODE']))
1608 {
1609 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_FIELD_API_CODE_FORMAT_ERROR").'<br>';
1610 }
1611 else
1612 {
1613 // check for uniqueness
1615 ->where('API_CODE', $arFields['API_CODE'])
1616 ->whereNot('ID', $ID)
1617 );
1618
1619 if ($count > 0)
1620 {
1621 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_FIELD_API_CODE_UNIQUE_ERROR").'<br>';
1622 }
1623 }
1624 }
1625 }
1626
1627 if (is_set($arFields, "REST_ON"))
1628 {
1629 if ($arFields['REST_ON'] !== 'Y')
1630 {
1631 $arFields['REST_ON'] = 'N';
1632 }
1633 else
1634 {
1635 if (!$arFields['API_CODE'])
1636 {
1637 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_REST_ON_WO_API_CODE").'<br>';
1638 }
1639 }
1640 }
1641
1642 if (
1643 isset($arFields["FULLTEXT_INDEX"])
1644 && $arFields["FULLTEXT_INDEX"] !== "Y"
1645 && $arFields["FULLTEXT_INDEX"] !== "N"
1646 )
1647 {
1648 $this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FULLTEXT_INDEX") . '<br>';
1649 }
1650
1651 unset($arFields['TIMESTAMP_X']);
1653 $helper = $connection->getSqlHelper();
1654 $arFields['~TIMESTAMP_X'] = $helper->getCurrentDateTimeFunction();
1655 unset($helper, $connection);
1656
1657 $APPLICATION->ResetException();
1658 if($ID===false)
1659 $db_events = GetModuleEvents("iblock", "OnBeforeIBlockAdd", true);
1660 else
1661 {
1662 $arFields["ID"] = $ID;
1663 $db_events = GetModuleEvents("iblock", "OnBeforeIBlockUpdate", true);
1664 }
1665
1666 foreach($db_events as $arEvent)
1667 {
1668 $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
1669 if($bEventRes===false)
1670 {
1671 if($err = $APPLICATION->GetException())
1672 $this->LAST_ERROR .= $err->GetString()."<br>";
1673 else
1674 {
1675 $APPLICATION->ThrowException("Unknown error");
1676 $this->LAST_ERROR .= "Unknown error.<br>";
1677 }
1678 break;
1679 }
1680 }
1681
1682 /****************************** QUOTA ******************************/
1683 if(empty($this->LAST_ERROR) && (COption::GetOptionInt("main", "disk_space") > 0))
1684 {
1685 $quota = new CDiskQuota();
1686 if(!$quota->checkDiskQuota($arFields))
1687 $this->LAST_ERROR = $quota->LAST_ERROR;
1688 }
1689 /****************************** QUOTA ******************************/
1690
1691 if($this->LAST_ERROR <> '')
1692 return false;
1693
1694 return true;
1695 }
1696
1697 public static function SetPermission($IBLOCK_ID, $arGROUP_ID)
1698 {
1700 global $DB;
1701 $IBLOCK_ID = (int)$IBLOCK_ID;
1702 static $letters = array(
1703 'E' => true,
1704 'R' => true,
1705 'S' => true,
1706 'T' => true,
1707 'U' => true,
1708 'W' => true,
1709 'X' => true
1710 );
1711
1712 $arToDelete = array();
1713 $arToInsert = array();
1714
1715 if(is_array($arGROUP_ID))
1716 {
1717 foreach($arGROUP_ID as $group_id => $perm)
1718 {
1719 $group_id = (int)$group_id;
1720 if ($group_id > 0 && isset($letters[$perm]))
1721 {
1722 $arToInsert[$group_id] = $perm;
1723 }
1724 }
1725 }
1726
1727 $rs = $DB->Query("
1728 SELECT GROUP_ID, PERMISSION
1729 FROM b_iblock_group
1730 WHERE IBLOCK_ID = ".$IBLOCK_ID."
1731 ");
1732 while($ar = $rs->Fetch())
1733 {
1734 $group_id = (int)$ar["GROUP_ID"];
1735
1736 if(isset($arToInsert[$group_id]) && $arToInsert[$group_id] === $ar["PERMISSION"])
1737 {
1738 unset($arToInsert[$group_id]); //This already in DB
1739 }
1740 else
1741 {
1742 $arToDelete[] = $group_id;
1743 }
1744 }
1745
1746 if(!empty($arToDelete))
1747 {
1748 $DB->Query("
1749 DELETE FROM b_iblock_group
1750 WHERE IBLOCK_ID = ".$IBLOCK_ID."
1751 AND GROUP_ID in (".implode(", ", $arToDelete).")
1752 "); //And this should be deleted
1753 }
1754
1755 if(!empty($arToInsert))
1756 {
1757 foreach($arToInsert as $group_id => $perm)
1758 {
1759 $DB->Query("
1760 INSERT INTO b_iblock_group(IBLOCK_ID, GROUP_ID, PERMISSION)
1761 SELECT ".$IBLOCK_ID.", ID, '".$perm."'
1762 FROM b_group
1763 WHERE ID = ".$group_id."
1764 ");
1765 }
1766 }
1767
1768 if(!empty($arToDelete) || !empty($arToInsert))
1769 {
1770 if(CModule::IncludeModule("search"))
1771 {
1773 if(isset($arGroups[2]))
1774 CSearch::ChangePermission("iblock", array(2), false, false, $IBLOCK_ID);
1775 else
1776 CSearch::ChangePermission("iblock", $arGroups, false, false, $IBLOCK_ID);
1777 }
1778 }
1779 }
1780
1781 public static function SetMessages($ID, $arFields)
1782 {
1784 global $DB;
1785 $ID = intval($ID);
1786 if($ID > 0)
1787 {
1788 $arMessages = array(
1789 "ELEMENT_NAME",
1790 "ELEMENTS_NAME",
1791 "ELEMENT_ADD",
1792 "ELEMENT_EDIT",
1793 "ELEMENT_DELETE",
1794 "SECTION_NAME",
1795 "SECTIONS_NAME",
1796 "SECTION_ADD",
1797 "SECTION_EDIT",
1798 "SECTION_DELETE",
1799 );
1800 $arUpdate = array();
1801 foreach($arMessages as $MESSAGE_ID)
1802 {
1803 if(array_key_exists($MESSAGE_ID, $arFields))
1804 $arUpdate[] = $MESSAGE_ID;
1805 }
1806 if(count($arUpdate) > 0)
1807 {
1808 $res = $DB->Query("
1809 DELETE FROM b_iblock_messages
1810 WHERE IBLOCK_ID = ".$ID."
1811 AND MESSAGE_ID in ('".implode("', '", $arUpdate)."')
1812 ");
1813 if($res)
1814 {
1815 foreach($arUpdate as $MESSAGE_ID)
1816 {
1817 $MESSAGE_TEXT = trim($arFields[$MESSAGE_ID]);
1818 if($MESSAGE_TEXT <> '')
1819 $DB->Add("b_iblock_messages", array(
1820 "ID" => 1, //FAKE field for not use sequence
1821 "IBLOCK_ID" => $ID,
1822 "MESSAGE_ID" => $MESSAGE_ID,
1823 "MESSAGE_TEXT" => $MESSAGE_TEXT,
1824 ));
1825 }
1826 }
1827 }
1828 }
1829 }
1830
1831 public static function GetMessages($ID, $type="")
1832 {
1834 global $DB;
1835 $ID = intval($ID);
1836 $arMessages = array(
1837 "ELEMENT_NAME" => Loc::getMessage("IBLOCK_MESS_ELEMENT_NAME"),
1838 "ELEMENTS_NAME" => "",
1839 "ELEMENT_ADD" => Loc::getMessage("IBLOCK_MESS_ELEMENT_ADD"),
1840 "ELEMENT_EDIT" => Loc::getMessage("IBLOCK_MESS_ELEMENT_EDIT"),
1841 "ELEMENT_DELETE" => Loc::getMessage("IBLOCK_MESS_ELEMENT_DELETE"),
1842 "SECTION_NAME" => Loc::getMessage("IBLOCK_MESS_SECTION_NAME"),
1843 "SECTIONS_NAME" => "",
1844 "SECTION_ADD" => Loc::getMessage("IBLOCK_MESS_SECTION_ADD"),
1845 "SECTION_EDIT" => Loc::getMessage("IBLOCK_MESS_SECTION_EDIT"),
1846 "SECTION_DELETE" => Loc::getMessage("IBLOCK_MESS_SECTION_DELETE"),
1847 );
1848 $res = $DB->Query("
1849 SELECT
1850 B.IBLOCK_TYPE_ID
1851 ,M.IBLOCK_ID
1852 ,M.MESSAGE_ID
1853 ,M.MESSAGE_TEXT
1854 FROM
1855 b_iblock B
1856 LEFT JOIN b_iblock_messages M ON B.ID = M.IBLOCK_ID
1857 WHERE
1858 B.ID = ".$ID."
1859 ");
1860
1861 while($ar = $res->Fetch())
1862 {
1863 $type = $ar["IBLOCK_TYPE_ID"];
1864 if($ar["MESSAGE_ID"])
1865 $arMessages[$ar["MESSAGE_ID"]] = $ar["MESSAGE_TEXT"];
1866 }
1867 if(($arMessages["ELEMENTS_NAME"] == '') || ($arMessages["SECTIONS_NAME"] == ''))
1868 {
1869 if($type)
1870 {
1871 $arType = CIBlockType::GetByIDLang($type, LANGUAGE_ID);
1872 if($arType)
1873 {
1874 if($arMessages["ELEMENTS_NAME"] == '')
1875 $arMessages["ELEMENTS_NAME"] = $arType["ELEMENT_NAME"];
1876 if($arMessages["SECTIONS_NAME"] == '')
1877 $arMessages["SECTIONS_NAME"] = $arType["SECTION_NAME"];
1878 }
1879 }
1880 }
1881 if($arMessages["ELEMENTS_NAME"] == '')
1882 $arMessages["ELEMENTS_NAME"] = Loc::getMessage("IBLOCK_MESS_ELEMENTS_NAME");
1883 if($arMessages["SECTIONS_NAME"] == '')
1884 $arMessages["SECTIONS_NAME"] = Loc::getMessage("IBLOCK_MESS_SECTIONS_NAME");
1885 return $arMessages;
1886 }
1887
1888 public static function GetFieldsDefaults()
1889 {
1890/*************
1891REQ
1892+ IBLOCK_SECTION_ID int(11),
1893 ACTIVE char(1) not null default 'Y',
1894+ ACTIVE_FROM datetime,
1895+ ACTIVE_TO datetime,
1896 SORT int(11) not null default '500',
1897 NAME varchar(255) not null,
1898+ PREVIEW_PICTURE int(18),
1899+ PREVIEW_TEXT text,
1900 PREVIEW_TEXT_TYPE varchar(4) not null default 'text',
1901+ DETAIL_PICTURE int(18),
1902+ DETAIL_TEXT longtext,
1903 DETAIL_TEXT_TYPE varchar(4) not null default 'text',
1904+ XML_ID varchar(255),
1905+ CODE varchar(255),
1906+ TAGS varchar(255),
1907**************/
1908 static $res = false;
1909 if (!$res)
1910 {
1911 $defaultValues = static::getFieldsDefaultValues();
1912
1913 $res = [
1914 'IBLOCK_SECTION' => [
1915 'NAME' => Loc::getMessage('IBLOCK_FIELD_SECTIONS'),
1916 'IS_REQUIRED' => false,
1917 'DEFAULT_VALUE' => serialize($defaultValues['IBLOCK_SECTION']),
1918 'VISIBLE' => 'Y',
1919 ],
1920 'ACTIVE' => [
1921 'NAME' => Loc::getMessage('IBLOCK_FIELD_ACTIVE'),
1922 'IS_REQUIRED' => 'Y',
1923 'DEFAULT_VALUE' => $defaultValues['ACTIVE'],
1924 'VISIBLE' => 'Y',
1925 ],
1926 'ACTIVE_FROM' => [
1927 'NAME' => Loc::getMessage('IBLOCK_FIELD_ACTIVE_PERIOD_FROM'),
1928 'IS_REQUIRED' => false,
1929 'DEFAULT_VALUE' => $defaultValues['ACTIVE_FROM'],
1930 'VISIBLE' => 'Y',
1931 ],
1932 'ACTIVE_TO' => [
1933 'NAME' => Loc::getMessage('IBLOCK_FIELD_ACTIVE_PERIOD_TO'),
1934 'IS_REQUIRED' => false,
1935 'DEFAULT_VALUE' => $defaultValues['ACTIVE_TO'],
1936 'VISIBLE' => 'Y',
1937 ],
1938 'SORT' => [
1939 'NAME' => Loc::getMessage('IBLOCK_FIELD_SORT'),
1940 'IS_REQUIRED' => false,
1941 'DEFAULT_VALUE' => $defaultValues['SORT'],
1942 'VISIBLE' => 'Y',
1943 ],
1944 'NAME' => [
1945 'NAME' => Loc::getMessage('IBLOCK_FIELD_NAME'),
1946 'IS_REQUIRED' => 'Y',
1947 'DEFAULT_VALUE' => $defaultValues['NAME'],
1948 'VISIBLE' => 'Y',
1949 ],
1950 'PREVIEW_PICTURE' => [
1951 'NAME' => Loc::getMessage('IBLOCK_FIELD_PREVIEW_PICTURE'),
1952 'IS_REQUIRED' => false,
1953 'DEFAULT_VALUE' => serialize($defaultValues['PREVIEW_PICTURE']),
1954 'VISIBLE' => 'Y',
1955 ],
1956 'PREVIEW_TEXT_TYPE' => [
1957 'NAME' => Loc::getMessage('IBLOCK_FIELD_PREVIEW_TEXT_TYPE'),
1958 'IS_REQUIRED' => 'Y',
1959 'DEFAULT_VALUE' => $defaultValues['PREVIEW_TEXT_TYPE'],
1960 'VISIBLE' => 'Y',
1961 ],
1962 'PREVIEW_TEXT' => [
1963 'NAME' => Loc::getMessage('IBLOCK_FIELD_PREVIEW_TEXT'),
1964 'IS_REQUIRED' => false,
1965 'DEFAULT_VALUE' => $defaultValues['PREVIEW_TEXT'],
1966 'VISIBLE' => 'Y',
1967 ],
1968 'DETAIL_PICTURE' => [
1969 'NAME' => Loc::getMessage('IBLOCK_FIELD_DETAIL_PICTURE'),
1970 'IS_REQUIRED' => false,
1971 'DEFAULT_VALUE' => serialize($defaultValues['DETAIL_PICTURE']),
1972 'VISIBLE' => 'Y',
1973 ],
1974 'DETAIL_TEXT_TYPE' => [
1975 'NAME' => Loc::getMessage('IBLOCK_FIELD_DETAIL_TEXT_TYPE'),
1976 'IS_REQUIRED' => 'Y',
1977 'DEFAULT_VALUE' => $defaultValues['DETAIL_TEXT_TYPE'],
1978 'VISIBLE' => 'Y',
1979 ],
1980 'DETAIL_TEXT' => [
1981 'NAME' => Loc::getMessage('IBLOCK_FIELD_DETAIL_TEXT'),
1982 'IS_REQUIRED' => false,
1983 'DEFAULT_VALUE' => $defaultValues['DETAIL_TEXT'],
1984 'VISIBLE' => 'Y',
1985 ],
1986 'XML_ID' => [
1987 'NAME' => Loc::getMessage('IBLOCK_FIELD_XML_ID'),
1988 'IS_REQUIRED' => 'Y',
1989 'DEFAULT_VALUE' => $defaultValues['XML_ID'],
1990 'VISIBLE' => 'Y',
1991 ],
1992 'CODE' => [
1993 'NAME' => Loc::getMessage('IBLOCK_FIELD_CODE'),
1994 'IS_REQUIRED' => false,
1995 'DEFAULT_VALUE' => serialize($defaultValues['CODE']),
1996 'VISIBLE' => 'Y',
1997 ],
1998 'TAGS' => [
1999 'NAME' => Loc::getMessage('IBLOCK_FIELD_TAGS'),
2000 'IS_REQUIRED' => false,
2001 'DEFAULT_VALUE' => $defaultValues['TAGS'],
2002 'VISIBLE' => 'Y',
2003 ],
2004 'SECTION_NAME' => [
2005 'NAME' => Loc::getMessage('IBLOCK_FIELD_NAME'),
2006 'IS_REQUIRED' => 'Y',
2007 'DEFAULT_VALUE' => $defaultValues['SECTION_NAME'],
2008 'VISIBLE' => 'Y',
2009 ],
2010 'SECTION_PICTURE' => [
2011 'NAME' => Loc::getMessage('IBLOCK_FIELD_PREVIEW_PICTURE'),
2012 'IS_REQUIRED' => false,
2013 'DEFAULT_VALUE' => serialize($defaultValues['SECTION_PICTURE']),
2014 'VISIBLE' => 'Y',
2015 ],
2016 'SECTION_DESCRIPTION_TYPE' => [
2017 'NAME' => Loc::getMessage('IBLOCK_FIELD_SECTION_DESCRIPTION_TYPE'),
2018 'IS_REQUIRED' => 'Y',
2019 'DEFAULT_VALUE' => $defaultValues['SECTION_DESCRIPTION_TYPE'],
2020 'VISIBLE' => 'Y',
2021 ],
2022 'SECTION_DESCRIPTION' => [
2023 'NAME' => Loc::getMessage('IBLOCK_FIELD_SECTION_DESCRIPTION'),
2024 'IS_REQUIRED' => false,
2025 'DEFAULT_VALUE' => $defaultValues['SECTION_DESCRIPTION'],
2026 'VISIBLE' => 'Y',
2027 ],
2028 'SECTION_DETAIL_PICTURE' => [
2029 'NAME' => Loc::getMessage('IBLOCK_FIELD_DETAIL_PICTURE'),
2030 'IS_REQUIRED' => false,
2031 'DEFAULT_VALUE' => serialize($defaultValues['SECTION_DETAIL_PICTURE']),
2032 'VISIBLE' => 'Y',
2033 ],
2034 'SECTION_XML_ID' => [
2035 'NAME' => Loc::getMessage('IBLOCK_FIELD_XML_ID'),
2036 'IS_REQUIRED' => false,
2037 'DEFAULT_VALUE' => $defaultValues['SECTION_XML_ID'],
2038 'VISIBLE' => 'Y',
2039 ],
2040 'SECTION_CODE' => [
2041 'NAME' => Loc::getMessage('IBLOCK_FIELD_CODE'),
2042 'IS_REQUIRED' => false,
2043 'DEFAULT_VALUE' => serialize($defaultValues['SECTION_CODE']),
2044 'VISIBLE' => 'Y',
2045 ],
2046 'LOG_SECTION_ADD' => [
2047 'NAME' => 'LOG_SECTION_ADD',
2048 'IS_REQUIRED' => false,
2049 'DEFAULT_VALUE' => $defaultValues['LOG_SECTION_ADD'],
2050 'VISIBLE' => 'Y',
2051 ],
2052 'LOG_SECTION_EDIT' => [
2053 'NAME' => 'LOG_SECTION_EDIT',
2054 'IS_REQUIRED' => false,
2055 'DEFAULT_VALUE' => $defaultValues['LOG_SECTION_EDIT'],
2056 'VISIBLE' => 'Y',
2057 ],
2058 'LOG_SECTION_DELETE' => [
2059 'NAME' => 'LOG_SECTION_DELETE',
2060 'IS_REQUIRED' => false,
2061 'DEFAULT_VALUE' => $defaultValues['LOG_SECTION_DELETE'],
2062 'VISIBLE' => 'Y',
2063 ],
2064 'LOG_ELEMENT_ADD' => [
2065 'NAME' => 'LOG_ELEMENT_ADD',
2066 'IS_REQUIRED' => false,
2067 'DEFAULT_VALUE' => $defaultValues['LOG_ELEMENT_ADD'],
2068 'VISIBLE' => 'Y',
2069 ],
2070 'LOG_ELEMENT_EDIT' => [
2071 'NAME' => 'LOG_ELEMENT_EDIT',
2072 'IS_REQUIRED' => false,
2073 'DEFAULT_VALUE' => $defaultValues['LOG_ELEMENT_EDIT'],
2074 'VISIBLE' => 'Y',
2075 ],
2076 'LOG_ELEMENT_DELETE' => [
2077 'NAME' => 'LOG_ELEMENT_DELETE',
2078 'IS_REQUIRED' => false,
2079 'DEFAULT_VALUE' => $defaultValues['LOG_ELEMENT_DELETE'],
2080 'VISIBLE' => 'Y',
2081 ],
2082 'XML_IMPORT_START_TIME' => [
2083 'NAME' => 'XML_IMPORT_START_TIME',
2084 'IS_REQUIRED' => false,
2085 'DEFAULT_VALUE' => $defaultValues['XML_IMPORT_START_TIME'],
2086 'VISIBLE' => 'N',
2087 ],
2088 'DETAIL_TEXT_TYPE_ALLOW_CHANGE' => [
2089 'NAME' => 'DETAIL_TEXT_TYPE_ALLOW_CHANGE',
2090 'IS_REQUIRED' => false,
2091 'DEFAULT_VALUE' => $defaultValues['DETAIL_TEXT_TYPE_ALLOW_CHANGE'],
2092 'VISIBLE' => 'N',
2093 ],
2094 'PREVIEW_TEXT_TYPE_ALLOW_CHANGE' => [
2095 'NAME' => 'PREVIEW_TEXT_TYPE_ALLOW_CHANGE',
2096 'IS_REQUIRED' => false,
2097 'DEFAULT_VALUE' => $defaultValues['PREVIEW_TEXT_TYPE_ALLOW_CHANGE'],
2098 'VISIBLE' => 'N',
2099 ],
2100 'SECTION_DESCRIPTION_TYPE_ALLOW_CHANGE' => [
2101 'NAME' => 'SECTION_DESCRIPTION_TYPE_ALLOW_CHANGE',
2102 'IS_REQUIRED' => false,
2103 'DEFAULT_VALUE' => $defaultValues['SECTION_DESCRIPTION_TYPE_ALLOW_CHANGE'],
2104 'VISIBLE' => 'N',
2105 ],
2106 ];
2107 }
2108
2109 return $res;
2110 }
2111
2116 public static function getFieldDefaultSettings(string $fieldName): ?array
2117 {
2118 if ($fieldName === '')
2119 {
2120 return null;
2121 }
2122
2123 $fields = static::GetFieldsDefaults();
2124
2125 return ($fields[$fieldName] ?? null);
2126 }
2127
2128 public static function SetFields($ID, $arFields)
2129 {
2131 global $DB;
2132 $ID = (int)$ID;
2133 if ($ID > 0)
2134 {
2136 $defaultValues = static::getFieldsDefaultValues();
2137
2138 foreach (array_keys($arFields) as $fieldId)
2139 {
2140 if (!is_array($arFields[$fieldId]))
2141 {
2142 unset($arFields[$fieldId]);
2143 }
2144 if (isset($fields[$fieldId]['IS_REQUIRED']))
2145 {
2146 $arFields[$fieldId]['IS_REQUIRED'] ??= $fields[$fieldId]['IS_REQUIRED'];
2147 }
2148 if (isset($defaultValues[$fieldId]))
2149 {
2150 if (is_array($defaultValues[$fieldId]))
2151 {
2152 $value = $arFields[$fieldId]['DEFAULT_VALUE'] ?? [];
2153 if (!is_array($value))
2154 {
2155 $value = [];
2156 }
2157 $value = array_intersect_key($value, $defaultValues[$fieldId]);
2158 $value = array_merge($defaultValues[$fieldId], $value);
2159 $arFields[$fieldId]['DEFAULT_VALUE'] = $value;
2160 }
2161 elseif ($defaultValues[$fieldId] === false)
2162 {
2163 $arFields[$fieldId]['DEFAULT_VALUE'] ??= $defaultValues[$fieldId];
2164 }
2165 }
2166 }
2167
2168 if (isset($arFields['PREVIEW_PICTURE']))
2169 {
2170 $arFields['PREVIEW_PICTURE']['DEFAULT_VALUE'] = serialize(static::preparePreviewPictureFieldSettings(
2171 $arFields['PREVIEW_PICTURE']['DEFAULT_VALUE']
2172 ));
2173 }
2174
2175 if (isset($arFields['DETAIL_PICTURE']))
2176 {
2177 $arFields['DETAIL_PICTURE']['DEFAULT_VALUE'] = serialize(static::prepareDetailPictureFieldSettings(
2178 $arFields['DETAIL_PICTURE']['DEFAULT_VALUE']
2179 ));
2180 }
2181
2182 if (isset($arFields['CODE']))
2183 {
2184 $arFields['CODE']['DEFAULT_VALUE'] = serialize(static::prepareCodeFieldSettings(
2185 $arFields['CODE']['DEFAULT_VALUE']
2186 ));
2187 }
2188
2189 if (isset($arFields['SECTION_PICTURE']))
2190 {
2191 $arFields['SECTION_PICTURE']['DEFAULT_VALUE'] = serialize(static::preparePreviewPictureFieldSettings(
2192 $arFields['SECTION_PICTURE']['DEFAULT_VALUE']
2193 ));
2194 }
2195
2196 if (isset($arFields['SECTION_DETAIL_PICTURE']))
2197 {
2198 $arFields['SECTION_DETAIL_PICTURE']['DEFAULT_VALUE'] = serialize(static::prepareDetailPictureFieldSettings(
2199 $arFields['SECTION_DETAIL_PICTURE']['DEFAULT_VALUE']
2200 ));
2201 }
2202 if (isset($arFields['SECTION_CODE']))
2203 {
2204 $arFields['SECTION_CODE']['DEFAULT_VALUE'] = serialize(static::prepareCodeFieldSettings(
2205 $arFields['SECTION_CODE']['DEFAULT_VALUE']
2206 ));
2207 }
2208 if (isset($arFields['SORT']))
2209 {
2210 $arFields['SORT']['DEFAULT_VALUE'] = (int)($arFields['SORT']['DEFAULT_VALUE'] ?? 500);
2211 }
2212 if (isset($arFields['IBLOCK_SECTION']))
2213 {
2214 $arFields['IBLOCK_SECTION']['DEFAULT_VALUE'] = serialize([
2215 'KEEP_IBLOCK_SECTION_ID' =>
2216 $arFields['IBLOCK_SECTION']['DEFAULT_VALUE']['KEEP_IBLOCK_SECTION_ID'] === 'Y'
2217 ? 'Y'
2218 : 'N'
2219 ,
2220 ]);
2221 }
2222
2223 $res = $DB->Query("
2224 SELECT * FROM b_iblock_fields
2225 WHERE IBLOCK_ID = " . $ID . "
2226 ");
2227 while ($ar = $res->Fetch())
2228 {
2229 $arUpdate = [];
2230 $fieldId = $ar['FIELD_ID'];
2231 if (isset($arFields[$fieldId]) && isset($fields[$fieldId]))
2232 {
2233 if ($fields[$fieldId]["IS_REQUIRED"] === false)
2234 {
2235 $IS_REQUIRED = ($arFields[$fieldId]["IS_REQUIRED"] ?? 'N');
2236 }
2237 else
2238 {
2239 $IS_REQUIRED = $fields[$fieldId]["IS_REQUIRED"];
2240 }
2241 $IS_REQUIRED = ($IS_REQUIRED === "Y"? "Y": "N");
2242 if ($ar["IS_REQUIRED"] !== $IS_REQUIRED)
2243 {
2244 $arUpdate['IS_REQUIRED'] = $IS_REQUIRED;
2245 }
2246 if (
2247 isset($arFields[$fieldId]["DEFAULT_VALUE"])
2248 && $ar["DEFAULT_VALUE"] !== $arFields[$fieldId]["DEFAULT_VALUE"]
2249 )
2250 {
2251 $arUpdate['DEFAULT_VALUE'] = $arFields[$fieldId]["DEFAULT_VALUE"];
2252 }
2253 unset($fields[$fieldId]);
2254 }
2255 elseif (isset($fields[$fieldId]))
2256 {
2257 $IS_REQUIRED = $fields[$fieldId]["IS_REQUIRED"];
2258 $IS_REQUIRED = ($IS_REQUIRED === "Y"? "Y": "N");
2259 if ($ar["IS_REQUIRED"] !== $IS_REQUIRED)
2260 {
2261 $arUpdate = [
2262 "IS_REQUIRED" => $IS_REQUIRED,
2263 "DEFAULT_VALUE" => "",
2264 ];
2265 }
2266 unset($fields[$fieldId]);
2267 }
2268 else
2269 {
2270 $DB->Query("DELETE FROM b_iblock_fields WHERE IBLOCK_ID = ".$ID." AND FIELD_ID = '".$DB->ForSQL($fieldId)."'");
2271 }
2272
2273 if (!empty($arUpdate))
2274 {
2275 $strUpdate = $DB->PrepareUpdate("b_iblock_fields", $arUpdate);
2276 if ($strUpdate != "")
2277 {
2278 $strSql = "UPDATE b_iblock_fields SET " . $strUpdate
2279 . " WHERE IBLOCK_ID = " . $ID
2280 . " AND FIELD_ID = '" . $DB->ForSQL($fieldId) . "'";
2281 $arBinds = [];
2282 if (isset($arUpdate["DEFAULT_VALUE"]))
2283 {
2284 $arBinds["DEFAULT_VALUE"] = $arUpdate["DEFAULT_VALUE"];
2285 }
2286 $DB->QueryBind($strSql, $arBinds);
2287 }
2288 }
2289 }
2290 foreach($fields as $FIELD_ID => $arDefaults)
2291 {
2292 if(array_key_exists($FIELD_ID, $arFields))
2293 {
2294 if($arDefaults["IS_REQUIRED"] === false)
2295 $IS_REQUIRED = $arFields[$FIELD_ID]["IS_REQUIRED"];
2296 else
2297 $IS_REQUIRED = $arDefaults["IS_REQUIRED"];
2298 $DEFAULT_VALUE = $arFields[$FIELD_ID]["DEFAULT_VALUE"];
2299 }
2300 else
2301 {
2302 $IS_REQUIRED = $arDefaults["IS_REQUIRED"];
2303 $DEFAULT_VALUE = false;
2304 }
2305 $IS_REQUIRED = ($IS_REQUIRED === "Y"? "Y": "N");
2306 $arAdd = [
2307 "IBLOCK_ID" => $ID,
2308 "FIELD_ID" => $FIELD_ID,
2309 "IS_REQUIRED" => $IS_REQUIRED,
2310 "DEFAULT_VALUE" => $DEFAULT_VALUE,
2311 ];
2312 $arInsert = $DB->PrepareInsert("b_iblock_fields", $arAdd);
2313 $DB->Query("INSERT INTO b_iblock_fields (".$arInsert[0].") VALUES (".$arInsert[1].")");
2314 }
2315
2317 }
2318 }
2319
2320 public static function GetFields($ID)
2321 {
2323 global $DB;
2324 $ID = (int)$ID;
2325 $fields = static::GetFieldsDefaults();
2326 $defaultValues = static::getFieldsDefaultValues();
2327
2328 $res = $DB->Query("
2329 SELECT
2330 F.*
2331 FROM
2332 b_iblock B
2333 LEFT JOIN b_iblock_fields F ON B.ID = F.IBLOCK_ID
2334 WHERE
2335 B.ID = ".$ID."
2336 ");
2337 while ($ar = $res->Fetch())
2338 {
2339 $fieldId = $ar['FIELD_ID'];
2340 if (isset($fields[$fieldId]))
2341 {
2342 if ($fields[$fieldId]['IS_REQUIRED'] === false)
2343 {
2344 $fields[$fieldId]['IS_REQUIRED'] = $ar['IS_REQUIRED'] === 'Y' ? 'Y' : 'N';
2345 }
2346 $fields[$fieldId]['DEFAULT_VALUE'] = $ar['DEFAULT_VALUE'];
2347 }
2348 }
2349 unset($res);
2350
2351 foreach ($fields as $FIELD_ID => $default)
2352 {
2353 if ($default['IS_REQUIRED'] === false)
2354 {
2355 $fields[$FIELD_ID]['IS_REQUIRED'] = 'N';
2356 }
2357
2358 if (isset($defaultValues[$FIELD_ID]) && is_array($defaultValues[$FIELD_ID]))
2359 {
2360 $a = &$fields[$FIELD_ID]['DEFAULT_VALUE'];
2361
2362 if (is_string($a) && $a !== '')
2363 {
2365 {
2366 $a = unserialize($a, ['allowed_classes' => false]);
2367 }
2368 }
2369 if (!is_array($a))
2370 {
2371 $a = [];
2372 }
2373 $a = array_merge($defaultValues[$FIELD_ID], $a);
2374
2375 if (array_key_exists('TRANS_LEN', $a))
2376 {
2377 $trans_len = (int)$a['TRANS_LEN'];
2378 if ($trans_len > 255)
2379 {
2380 $trans_len = 255;
2381 }
2382 elseif ($trans_len < 1)
2383 {
2384 $trans_len = 100;
2385 }
2386 $a['TRANS_LEN'] = $trans_len;
2387 }
2388 }
2389 }
2390
2391 return $fields;
2392 }
2393
2394 public static function GetProperties($ID, $arOrder = array(), $arFilter = array())
2395 {
2396 $props = new CIBlockProperty();
2397 $arFilter["IBLOCK_ID"] = $ID;
2398 return $props->GetList($arOrder, $arFilter);
2399 }
2400
2401 public static function GetGroupPermissions($ID)
2402 {
2404 global $DB;
2405 $arRes = array();
2406 $ID = (int)$ID;
2407 if ($ID <= 0)
2408 return $arRes;
2409
2410 $dbres = $DB->Query("
2411 SELECT GROUP_ID, PERMISSION
2412 FROM b_iblock_group
2413 WHERE IBLOCK_ID = ".$ID."
2414 ");
2415 while($res = $dbres->Fetch())
2416 $arRes[$res["GROUP_ID"]] = $res["PERMISSION"];
2417 unset($res);
2418 unset($dbres);
2419
2420 return $arRes;
2421 }
2422
2423 public static function GetPermission($IBLOCK_ID, $FOR_USER_ID = false)
2424 {
2426 global $DB;
2428 global $USER;
2429 static $CACHE = array();
2430 $USER_ID = is_object($USER)? intval($USER->GetID()): 0;
2431
2432 if($FOR_USER_ID > 0 && $FOR_USER_ID != $USER_ID)
2433 {
2434 $arGroups = CUser::GetUserGroup($FOR_USER_ID);
2435 if(
2436 in_array(1, $arGroups)
2437 && COption::GetOptionString("main", "controller_member", "N") != "Y"
2438 && COption::GetOptionString("main", "~controller_limited_admin", "N") != "Y"
2439 )
2440 return "X";
2441 $USER_GROUPS = implode(",", $arGroups);
2442 }
2443 elseif(is_object($USER))
2444 {
2445 if($USER->IsAdmin())
2446 return "X";
2447 $USER_GROUPS = $USER->GetGroups();
2448 }
2449 else
2450 {
2451 $USER_GROUPS = "2";
2452 }
2453
2454 $IBLOCK_ID = intval($IBLOCK_ID);
2455 $CACHE_KEY = $IBLOCK_ID."|".$USER_GROUPS;
2456
2457 if(!array_key_exists($CACHE_KEY, $CACHE))
2458 {
2459 //Deny by default
2460 $CACHE[$CACHE_KEY] = "D";
2461 //Now check database
2462 $strSql = "
2463 SELECT MAX(IBG.PERMISSION) as P
2464 FROM b_iblock_group IBG
2465 WHERE IBG.IBLOCK_ID=".$IBLOCK_ID."
2466 AND IBG.GROUP_ID IN (".$USER_GROUPS.")
2467 ";
2468 $res = $DB->Query($strSql);
2469 if($r = $res->Fetch())
2470 {
2471 if($r['P'] <> '')
2472 {
2473 //Overwrite default value
2474 $CACHE[$CACHE_KEY] = $r["P"];
2475 }
2476 }
2477 }
2478
2479 return $CACHE[$CACHE_KEY];
2480 }
2481
2482 public static function OnBeforeLangDelete($lang)
2483 {
2485 global $DB;
2487 global $APPLICATION;
2488
2489 $r = $DB->Query("
2490 SELECT IBLOCK_ID
2491 FROM b_iblock_site
2492 WHERE SITE_ID='".$DB->ForSQL($lang, 2)."'
2493 ORDER BY IBLOCK_ID
2494 ");
2495 $arIBlocks = array();
2496 while($a = $r->Fetch())
2497 $arIBlocks[] = $a["IBLOCK_ID"];
2498 if(count($arIBlocks) > 0)
2499 {
2500 $APPLICATION->ThrowException(Loc::getMessage("IBLOCK_SITE_LINKS_EXISTS", array("#ID_LIST#" => implode(", ", $arIBlocks))));
2501 return false;
2502 }
2503 else
2504 {
2505 return true;
2506 }
2507 }
2508
2509 public static function OnLangDelete($lang)
2510 {
2511 return true;
2512 }
2513
2514 public static function OnGroupDelete($group_id)
2515 {
2517 global $DB;
2518
2519 return $DB->Query("DELETE FROM b_iblock_group WHERE GROUP_ID=".intval($group_id), true);
2520 }
2521
2522 public static function MkOperationFilter($key): array
2523 {
2524 static $operations = [
2525 '!><' => 'NB', //not between
2526 '!=' => 'NI', //not Identical
2527 '!%' => 'NS', //not substring
2528 '><' => 'B', //between
2529 '>=' => 'GE', //greater or equal
2530 '<=' => 'LE', //less or equal
2531 '=' => 'I', //Identical
2532 '%' => 'S', //substring
2533 '?' => '?', //logical
2534 '>' => 'G', //greater
2535 '<' => 'L', //less
2536 '!' => 'N', // not field LIKE val
2537 '*' => 'FT', // partial full text match
2538 '*=' => 'FTI', // identical full text match
2539 '*%' => 'FTL', // partial full text match based on LIKE
2540 ];
2541
2542 $key = (string)$key;
2543 $result = [
2544 'FIELD' => $key,
2545 'OPERATION' => 'E',
2546 'PREFIX' => '',
2547 ];
2548 if ($key === '')
2549 {
2550 return $result; // zero key
2551 }
2552
2553 for ($i = 3; $i > 0; $i--)
2554 {
2555 $op = mb_substr($key, 0, $i);
2556 if ($op && isset($operations[$op]))
2557 {
2558 $result['FIELD'] = mb_substr($key, $i);
2559 $result['OPERATION'] = $operations[$op];
2560 $result['PREFIX'] = $op;
2561 break;
2562 }
2563 }
2564
2565 return $result; // field LIKE val
2566 }
2567
2568 public static function FilterCreate($field_name, $values, $type, $cOperationType=false, $bSkipEmpty = true)
2569 {
2570 return CIBlock::FilterCreateEx($field_name, $values, $type, $bFullJoin, $cOperationType, $bSkipEmpty);
2571 }
2572
2573 public static function ForLIKE($str)
2574 {
2576 global $DB;
2577
2578 return str_replace("%", "\\%", str_replace("_", "\\_", $DB->ForSQL($str)));
2579 }
2580
2581 public static function FilterCreateEx($fname, $vals, $type, &$bFullJoin, $cOperationType=false, $bSkipEmpty = true)
2582 {
2584 global $DB;
2585
2586 if(!is_array($vals))
2587 $vals=Array($vals);
2588
2589 if(count($vals)<1)
2590 return "";
2591
2592 if(is_bool($cOperationType))
2593 {
2594 if($cOperationType===true)
2595 $cOperationType = "N";
2596 else
2597 $cOperationType = "E";
2598 }
2599
2600 if($cOperationType=="E") // most req operation
2601 $strOperation = "=";
2602 elseif($cOperationType=="G")
2603 $strOperation = ">";
2604 elseif($cOperationType=="GE")
2605 $strOperation = ">=";
2606 elseif($cOperationType=="LE")
2607 $strOperation = "<=";
2608 elseif($cOperationType=="L")
2609 $strOperation = "<";
2610 elseif($cOperationType=='B')
2611 $strOperation = array('BETWEEN', 'AND');
2612 elseif($cOperationType=='NB')
2613 $strOperation = array('BETWEEN', 'AND');
2614 else
2615 $strOperation = "=";
2616
2617 if($cOperationType=='B' || $cOperationType=='NB')
2618 {
2619 if(count($vals)==2 && !is_array($vals[0]))
2620 $vals = array($vals);
2621 }
2622
2623 $bNegative = mb_substr($cOperationType, 0, 1) == "N";
2624 $bFullJoin = false;
2625 $bWasLeftJoin = false;
2626
2627 $arIn = Array(); //This will gather equality number conditions
2628 $bWasNull = false;
2629 $res = Array();
2630 foreach($vals as $val)
2631 {
2632 if(
2633 !$bSkipEmpty
2634 || (is_array($strOperation) && is_array($val))
2635 || (is_bool($val) && $val===false)
2636 || (string)$val <> ''
2637 )
2638 {
2639 switch ($type)
2640 {
2641 case "string_equal":
2642 if($cOperationType=="?")
2643 {
2644 if((string)$val <> '')
2645 $res[] = GetFilterQuery($fname, $val, "N");
2646 }
2647 elseif($cOperationType=="S" || $cOperationType=="NS")
2648 $res[] = ($cOperationType=="NS"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname)." LIKE ".CIBlock::_Upper("'%".CIBlock::ForLIKE($val)."%'").")";
2649 elseif(($cOperationType=="B" || $cOperationType=="NB") && is_array($val) && count($val)==2)
2650 $res[] = ($cOperationType=="NB"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname)." ".$strOperation[0]." '".CIBlock::_Upper($DB->ForSql($val[0]))."' ".$strOperation[1]." '".CIBlock::_Upper($DB->ForSql($val[1]))."')";
2651 else
2652 {
2653 if((string)$val == '')
2654 $res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL OR ".$DB->Length($fname)."<=0)";
2655 else
2656 $res[] = ($cOperationType=="N"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname).$strOperation.CIBlock::_Upper("'".$DB->ForSql($val)."'").")";
2657 }
2658 break;
2659 case "string":
2660 if($cOperationType=="?")
2661 {
2662 if((string)$val <> '')
2663 {
2664 $sr = GetFilterQuery($fname, $val, "Y", array(), ($fname=="BE.SEARCHABLE_CONTENT" || $fname=="BE.DETAIL_TEXT" ? "Y" : "N"));
2665 if($sr != "0")
2666 $res[] = $sr;
2667 }
2668 }
2669 elseif(($cOperationType=="B" || $cOperationType=="NB") && is_array($val) && count($val)==2)
2670 {
2671 $res[] = ($cOperationType=="NB"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname)." ".$strOperation[0]." '".CIBlock::_Upper($DB->ForSql($val[0]))."' ".$strOperation[1]." '".CIBlock::_Upper($DB->ForSql($val[1]))."')";
2672 }
2673 elseif($cOperationType=="S" || $cOperationType=="NS")
2674 $res[] = ($cOperationType=="NS"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname)." LIKE ".CIBlock::_Upper("'%".CIBlock::ForLIKE($val)."%'").")";
2675 elseif($cOperationType=="FTL")
2676 {
2677 $sqlWhere = new CSQLWhere();
2678 $condition = $sqlWhere->matchLike($fname, $val);
2679 if ($condition != '')
2680 $res[] = $condition;
2681 }
2682 else
2683 {
2684 if((string)$val == '')
2685 $res[] = ($bNegative? "NOT": "")."(".$fname." IS NULL OR ".$DB->Length($fname)."<=0)";
2686 else
2687 if($strOperation=="=" && $cOperationType!="I" && $cOperationType!="NI")
2688 $res[] = ($cOperationType=="N"?" ".$fname." IS NULL OR NOT ":"")."(".($DB->type=="ORACLE"?CIBlock::_Upper($fname)." LIKE ".CIBlock::_Upper("'".$DB->ForSqlLike($val)."'")." ESCAPE '\\'" : $fname." LIKE '".$DB->ForSqlLike($val)."'").")";
2689 else
2690 $res[] = ($bNegative? " ".$fname." IS NULL OR NOT ": "")."(".($DB->type=="ORACLE"?CIBlock::_Upper($fname)." ".$strOperation." ".CIBlock::_Upper("'".$DB->ForSql($val)."'")." " : $fname." ".$strOperation." '".$DB->ForSql($val)."'").")";
2691 }
2692 break;
2693 case "date":
2694 if(!is_array($val) && $val == '')
2695 {
2696 $res[] = ($cOperationType == "N" ? "NOT" : "") . "(" . $fname . " IS NULL)";
2697 }
2698 elseif (($cOperationType=="B" || $cOperationType=="NB") && is_array($val) && count($val)==2)
2699 {
2700 if (
2701 static::isCorrectFullFormatDate($DB->ForSql($val[0])) &&
2702 static::isCorrectFullFormatDate($DB->ForSql($val[1]))
2703 )
2704 {
2705 $res[] = ($cOperationType == 'NB' ? ' ' . $fname . ' IS NULL OR NOT ' : '')
2706 . '('
2707 . $fname
2708 . ' '
2709 . $strOperation[0]
2710 . ' '
2711 . $DB->CharToDateFunction($DB->ForSql($val[0]), "FULL")
2712 . ' '
2713 . $strOperation[1]
2714 . ' '
2715 . $DB->CharToDateFunction($DB->ForSql($val[1]), "FULL")
2716 . ')';
2717 }
2718 }
2719 else
2720 {
2721 if (static::isCorrectFullFormatDate($DB->ForSql($val)))
2722 {
2723 $res[] = ($bNegative ? " " . $fname . " IS NULL OR NOT " : "")
2724 . "("
2725 . $fname
2726 . " "
2727 . $strOperation
2728 . " "
2729 . $DB->CharToDateFunction($DB->ForSql($val), "FULL")
2730 . ")";
2731 }
2732 }
2733 break;
2734 case "number":
2735 if($val === '' || $val === null || $val === false)
2736 {
2737 $res[] = $fname." IS ".($bNegative? "NOT NULL": " NULL");
2738 $bWasNull = true;
2739 }
2740 elseif($cOperationType=="B" || $cOperationType=="NB")
2741 {
2742 if(is_array($val))
2743 {
2744 if(count($val)==2)
2745 {
2746 $res[] =
2747 ($cOperationType == 'NB' ? ' ' . $fname . ' IS NULL OR NOT ' : '')
2748 . '(' . $fname . ' ' . $strOperation[0]
2749 . ' ' . self::getNumberValueForSql($val[0])
2750 . ' ' . $strOperation[1]
2751 . ' ' . self::getNumberValueForSql($val[1])
2752 . ')'
2753 ;
2754 }
2755 else
2756 {
2757 $res[] =
2758 ($cOperationType == 'NB' ? ' ' . $fname . ' IS NULL OR NOT ' : '')
2759 . '(' . $fname . ' = ' . self::getNumberValueForSql(array_pop($val[0])) . ')'
2760 ;
2761 }
2762 }
2763 else
2764 {
2765 $res[] =
2766 ($cOperationType=='NB' ? ' ' . $fname . ' IS NULL OR NOT ' : '')
2767 . '(' . $fname . ' = ' . self::getNumberValueForSql($val) . ')'
2768 ;
2769 }
2770 }
2771 elseif($bNegative)
2772 {
2773 $parsedValue = self::getNumberValueForSql($val);
2774 $res[] = " ".$fname." IS NULL OR NOT (".$fname." ".$strOperation." ".$parsedValue.")";
2775 if($strOperation == '=')
2776 {
2777 $arIn[] = $parsedValue;
2778 }
2779 unset($parsedValue);
2780 }
2781 else
2782 {
2783 $parsedValue = self::getNumberValueForSql($val);
2784 $res[] = "(".$fname." ".$strOperation." ".$parsedValue.")";
2785 if($strOperation == '=')
2786 {
2787 $arIn[] = $parsedValue;
2788 }
2789 }
2790 break;
2791 case "number_above":
2792 if($val === '' || $val === null || $val === false)
2793 $res[] = ($cOperationType=="N"?"NOT":"")."(".$fname." IS NULL)";
2794 else
2795 $res[] = ($cOperationType=="N"?" ".$fname." IS NULL OR NOT ":"")."(".$fname." ".$strOperation." '".$DB->ForSql($val)."')";
2796 break;
2797 case "fulltext":
2798 if($cOperationType=="FT" || $cOperationType=="FTI")
2799 {
2800 $sqlWhere = new CSQLWhere();
2801 $condition = $sqlWhere->match($fname, $val, $cOperationType=="FT");
2802 if ($condition != '')
2803 $res[] = $condition;
2804 }
2805 elseif($cOperationType=="FTL")
2806 {
2807 $sqlWhere = new CSQLWhere();
2808 $condition = $sqlWhere->matchLike($fname, $val);
2809 if ($condition != '')
2810 $res[] = $condition;
2811 }
2812 elseif($cOperationType=="?")
2813 {
2814 if((string)$val <> '')
2815 {
2816 $sr = GetFilterQuery($fname, $val, "Y", array(), ($fname=="BE.SEARCHABLE_CONTENT" || $fname=="BE.DETAIL_TEXT" ? "Y" : "N"));
2817 if($sr != "0")
2818 $res[] = $sr;
2819 }
2820 }
2821 elseif(($cOperationType=="B" || $cOperationType=="NB") && is_array($val) && count($val)==2)
2822 {
2823 $res[] = ($cOperationType=="NB"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname)." ".$strOperation[0]." '".CIBlock::_Upper($DB->ForSql($val[0]))."' ".$strOperation[1]." '".CIBlock::_Upper($DB->ForSql($val[1]))."')";
2824 }
2825 elseif($cOperationType=="S" || $cOperationType=="NS")
2826 $res[] = ($cOperationType=="NS"?" ".$fname." IS NULL OR NOT ":"")."(".CIBlock::_Upper($fname)." LIKE ".CIBlock::_Upper("'%".CIBlock::ForLIKE($val)."%'").")";
2827 else
2828 {
2829 if((string)$val == '')
2830 $res[] = ($bNegative? "NOT": "")."(".$fname." IS NULL OR ".$DB->Length($fname)."<=0)";
2831 else
2832 if($strOperation=="=" && $cOperationType!="I" && $cOperationType!="NI")
2833 $res[] = ($cOperationType=="N"?" ".$fname." IS NULL OR NOT ":"")."(".($DB->type=="ORACLE"?CIBlock::_Upper($fname)." LIKE ".CIBlock::_Upper("'".$DB->ForSqlLike($val)."'")." ESCAPE '\\'" : $fname." LIKE '".$DB->ForSqlLike($val)."'").")";
2834 else
2835 $res[] = ($bNegative? " ".$fname." IS NULL OR NOT ": "")."(".($DB->type=="ORACLE"?CIBlock::_Upper($fname)." ".$strOperation." ".CIBlock::_Upper("'".$DB->ForSql($val)."'")." " : $fname." ".$strOperation." '".$DB->ForSql($val)."'").")";
2836 }
2837 break;
2838 }
2839
2840 if((is_array($val) || (string)$val <> '') && !$bNegative)
2841 $bFullJoin = true;
2842 else
2843 $bWasLeftJoin = true;
2844 }
2845 }
2846
2847 $strResult = "";
2848
2849 $cntIn = count($arIn);
2850 if(
2851 !$bWasNull
2852 && $cntIn > 1
2853 && (
2854 $cntIn < 2000
2855 || $DB->type == "MYSQL"
2856 )
2857 )
2858 {
2859 if($bNegative)
2860 $res = array($fname." IS NULL OR NOT (".$fname." IN (".implode(", ", $arIn)."))");
2861 else
2862 $res = array($fname." IN (".implode(", ", $arIn).")");
2863 }
2864
2865 foreach($res as $i=>$val)
2866 {
2867 if($i>0)
2868 $strResult .= ($bNegative? " AND ": " OR ");
2869 $strResult .= "(".$val.")";
2870 }
2871
2872 if($strResult!="")
2873 $strResult = "(".$strResult.")";
2874
2875 if($bFullJoin && $bWasLeftJoin && !$bNegative)
2876 $bFullJoin = false;
2877
2878 return $strResult;
2879 }
2880
2887 private static function getNumberValueForSql(mixed $value): string|float
2888 {
2889 $value = (float)$value;
2890 if (is_nan($value) || is_infinite($value))
2891 {
2892 return "'" . $value . "'";
2893 }
2894
2895 return $value;
2896 }
2897
2898 public static function isCorrectFullFormatDate($value): bool
2899 {
2900 $result = true;
2901
2902 // get user time
2903 if ($value instanceof Main\Type\DateTime && !$value->isUserTimeEnabled())
2904 {
2905 $value = clone $value;
2906 $value->toUserTime();
2907 }
2908
2909 // format
2910 if (($context = Main\Context::getCurrent()) && ($culture = $context->getCulture()) !== null)
2911 {
2912 $format = $culture->getFormatDatetime();
2913 }
2914 else
2915 {
2916 $format = CLang::GetDateFormat('FULL');
2917 }
2918
2919 $formatDate = CDatabase::FormatDate($value, $format, "YYYY-MM-DD HH:MI:SS");
2920
2921 if ($formatDate === false || $formatDate === '')
2922 {
2923 $result = false;
2924 }
2925
2926 return $result;
2927 }
2928
2929 public static function _MergeIBArrays($iblock_id, $iblock_code = false, $iblock_id2 = false, $iblock_code2 = false)
2930 {
2931 if(!is_array($iblock_id))
2932 {
2933 if(is_numeric($iblock_id) || $iblock_id <> '')
2934 $iblock_id = Array($iblock_id);
2935 elseif(is_array($iblock_id2))
2936 $iblock_id = $iblock_id2;
2937 elseif(is_numeric($iblock_id2) || $iblock_id2 <> '')
2938 $iblock_id = Array($iblock_id2);
2939 }
2940
2941 if(!is_array($iblock_code))
2942 {
2943 if(is_numeric($iblock_code) || $iblock_code <> '')
2944 $iblock_code = Array($iblock_code);
2945 elseif(is_array($iblock_code2))
2946 $iblock_code = $iblock_code2;
2947 elseif(is_numeric($iblock_code2) || $iblock_code2 <> '')
2948 $iblock_code = Array($iblock_code2);
2949 }
2950
2951 if(is_array($iblock_code) && is_array($iblock_id))
2952 return array_merge($iblock_code, $iblock_id);
2953
2954 if(is_array($iblock_code))
2955 return $iblock_code;
2956
2957 if(is_array($iblock_id))
2958 return $iblock_id;
2959
2960 return array();
2961 }
2962
2963 public static function OnSearchGetURL($arFields)
2964 {
2966 global $DB;
2967 static $arIBlockCache = array();
2968
2969 if($arFields["MODULE_ID"] !== "iblock" || mb_substr($arFields["URL"], 0, 1) !== "=")
2970 return $arFields["URL"];
2971
2972 $IBLOCK_ID = intval($arFields["PARAM2"]);
2973
2974 if(!array_key_exists($IBLOCK_ID, $arIBlockCache))
2975 {
2976 $res = $DB->Query("
2977 SELECT
2978 DETAIL_PAGE_URL,
2979 SECTION_PAGE_URL,
2980 CODE as IBLOCK_CODE,
2981 XML_ID as IBLOCK_EXTERNAL_ID,
2982 IBLOCK_TYPE_ID
2983 FROM
2984 b_iblock
2985 WHERE ID = ".$IBLOCK_ID."
2986 ");
2987 $arIBlockCache[$IBLOCK_ID] = $res->Fetch();
2988 }
2989
2990 if(!is_array($arIBlockCache[$IBLOCK_ID]))
2991 return "";
2992
2993 $arFields["URL"] = LTrim($arFields["URL"], " =");
2994 parse_str($arFields["URL"], $arr);
2995 $arr = $arIBlockCache[$IBLOCK_ID] + $arr;
2996 $arr["LANG_DIR"] = $arFields["DIR"];
2997
2998 if(mb_substr($arFields["ITEM_ID"], 0, 1) !== 'S')
2999 return CIBlock::ReplaceDetailUrl($arIBlockCache[$IBLOCK_ID]["DETAIL_PAGE_URL"], $arr, false, "E");
3000 else
3001 return CIBlock::ReplaceDetailUrl($arIBlockCache[$IBLOCK_ID]["SECTION_PAGE_URL"], $arr, false, "S");
3002 }
3003
3004 public static function ReplaceSectionUrl($url, $arr, $server_name = false, $arrType = false)
3005 {
3006 $url = str_replace(
3007 [
3008 '#ID#',
3009 '#CODE#',
3010 ],
3011 [
3012 '#SECTION_ID#',
3013 '#SECTION_CODE#',
3014 ],
3015 (string)$url
3016 );
3017
3018 return CIBlock::ReplaceDetailUrl($url, $arr, $server_name, $arrType);
3019 }
3020
3031 public static function _GetProductUrl($OF_ELEMENT_ID, $OF_IBLOCK_ID, $server_name = false, $arrType = false)
3032 {
3034 [
3035 'ID' => $OF_ELEMENT_ID,
3036 'IBLOCK_ID' => $OF_IBLOCK_ID,
3037 ],
3038 (bool)$server_name
3039 );
3040 }
3041
3042 protected static function getProductUrlValue(array $element, bool $serverName): string
3043 {
3044 $result = '';
3045
3046 $id = (int)($element['ID'] ?? 0);
3047 $iblockId = (int)($element['IBLOCK_ID'] ?? 0);
3048
3049 if ($iblockId <= 0 || $id <= 0)
3050 {
3051 return $result;
3052 }
3053
3054 if (self::$catalogIncluded === null)
3055 {
3056 self::$catalogIncluded = Loader::includeModule('catalog');
3057 }
3058 if (!self::$catalogIncluded)
3059 {
3060 return $result;
3061 }
3062
3063 $iblock = static::getProductIblockData($iblockId);
3064 if ($iblock === null)
3065 {
3066 return $result;
3067 }
3068
3069 $parentId = (int)($element['PROPERTY_' . $iblock['SKU_PROPERTY_ID'] . '_VALUE'] ?? self::getProductId($id, $iblockId));
3070 if ($parentId <= 0)
3071 {
3072 return $result;
3073 }
3074
3075 $parent = self::getUrlElementData($parentId);
3076 if ($parent === null)
3077 {
3078 return $result;
3079 }
3080
3082 $iblock['PRODUCT_IBLOCK']['DETAIL_PAGE_URL'],
3083 [
3084 'LANG_DIR' => (string)($element['LANG_DIR'] ?? ''),
3085 'ID' => $parent['ID'],
3086 'ELEMENT_ID' => $parent['ID'],
3087 'CODE' => $parent['CODE'],
3088 'ELEMENT_CODE' => $parent['CODE'],
3089 'EXTERNAL_ID' => $parent['XML_ID'],
3090 'IBLOCK_TYPE_ID' => $iblock['PRODUCT_IBLOCK']['IBLOCK_TYPE_ID'],
3091 'IBLOCK_ID' => $parent['IBLOCK_ID'],
3092 'IBLOCK_CODE' => $iblock['PRODUCT_IBLOCK']['CODE'],
3093 'IBLOCK_EXTERNAL_ID' => $iblock['PRODUCT_IBLOCK']['XML_ID'],
3094 'IBLOCK_SECTION_ID' => $parent['IBLOCK_SECTION_ID'],
3095 'SECTION_CODE' => $parent['IBLOCK_SECTION_CODE'],
3096 ],
3097 $serverName,
3098 'E'
3099 );
3100 }
3101
3102 public static function ReplaceDetailUrl($url, $arr, $server_name = false, $arrType = false)
3103 {
3104 $url = (string)$url;
3105
3106 if ($server_name)
3107 {
3108 $url = str_replace('#LANG#', (string)($arr['LANG_DIR'] ?? ''), $url);
3109 if (
3110 (defined('ADMIN_SECTION') && ADMIN_SECTION === true)
3111 || !defined('BX_STARTED')
3112 )
3113 {
3114 static $cache = array();
3115 if (isset($arr['LID']))
3116 {
3117 if (!isset($cache[$arr['LID']]))
3118 {
3119 $db_lang = CLang::GetByID($arr['LID']);
3120 $arLang = $db_lang->Fetch();
3121 if (!empty($arLang))
3122 {
3123 $arLang['DIR'] = (string)$arLang['DIR'];
3124 $arLang['SERVER_NAME'] = (string)$arLang['SERVER_NAME'];
3125 }
3126 $cache[$arr['LID']] = $arLang;
3127 }
3128 $arLang = $cache[$arr['LID']];
3129 if (!empty($arLang))
3130 {
3131 $url = str_replace(
3132 [
3133 '#SITE_DIR#',
3134 '#SERVER_NAME#',
3135 ],
3136 [
3137 $arLang['DIR'],
3138 $arLang['SERVER_NAME'],
3139 ],
3140 $url
3141 );
3142 }
3143 }
3144 }
3145 else
3146 {
3147 $url = str_replace(
3148 [
3149 '#SITE_DIR#',
3150 '#SERVER_NAME#',
3151 ],
3152 [
3153 SITE_DIR,
3154 SITE_SERVER_NAME,
3155 ],
3156 $url
3157 );
3158 }
3159 }
3160
3161 $id = (int)($arr['ID'] ?? 0);
3162 $preparedId = $id > 0 ? $id : '';
3163
3164 static $arSearch = [
3165 /*Thees come from GetNext*/
3166 '#SITE_DIR#',
3167 '#ID#',
3168 '#CODE#',
3169 '#EXTERNAL_ID#',
3170 '#IBLOCK_TYPE_ID#',
3171 '#IBLOCK_ID#',
3172 '#IBLOCK_CODE#',
3173 '#IBLOCK_EXTERNAL_ID#',
3174 /*And thees was born during components 2 development*/
3175 '#ELEMENT_ID#',
3176 '#ELEMENT_CODE#',
3177 '#SECTION_ID#',
3178 '#SECTION_CODE#',
3179 '#SECTION_CODE_PATH#',
3180 ];
3181 $iblockId = (int)($arr['IBLOCK_ID'] ?? 0);
3182 $preparedCode = rawurlencode(
3183 (string)($arr['~CODE'] ?? ($arr['CODE'] ?? ''))
3184 );
3185 $iblockSectionId = (int)($arr['IBLOCK_SECTION_ID'] ?? 0);
3186 $arReplace = [
3187 (string)($arr['LANG_DIR'] ?? ''),
3188 $preparedId,
3189 $preparedCode,
3190 rawurlencode(
3191 (string)($arr['~EXTERNAL_ID'] ?? ($arr['EXTERNAL_ID'] ?? ''))
3192 ),
3193 rawurlencode(
3194 (string)($arr['~IBLOCK_TYPE_ID'] ?? ($arr['IBLOCK_TYPE_ID'] ?? ''))
3195 ),
3196 ($iblockId > 0 ? $iblockId : ''),
3197 rawurlencode(
3198 (string)($arr['~IBLOCK_CODE'] ?? ($arr['IBLOCK_CODE'] ?? ''))
3199 ),
3200 rawurlencode(
3201 (string)($arr['~IBLOCK_EXTERNAL_ID'] ?? ($arr['IBLOCK_EXTERNAL_ID'] ?? ''))
3202 ),
3203 ];
3204
3205 if ($arrType === "E")
3206 {
3207 if (strpos($url, '#PRODUCT_URL#') !== false)
3208 {
3209 $url = str_replace(
3210 '#PRODUCT_URL#',
3211 self::getProductUrlValue($arr, $server_name),
3212 $url
3213 );
3214 }
3215
3216 $arReplace[] = $preparedId;
3217 $arReplace[] = rawurlencode(
3218 (string)($arr['~CODE'] ?? ($arr['CODE'] ?? ''))
3219 );
3220
3221 #Deal with symbol codes
3222 $SECTION_CODE = '';
3223 $SECTION_CODE_PATH = '';
3224 if ($iblockSectionId > 0)
3225 {
3226 if (strpos($url, '#SECTION_CODE#') !== false)
3227 {
3228 $SECTION_CODE = CIBlockSection::getSectionCode($iblockSectionId);
3229 }
3230
3231 if (strpos($url, '#SECTION_CODE_PATH#') !== false)
3232 {
3233 $SECTION_CODE_PATH = CIBlockSection::getSectionCodePath($iblockSectionId);
3234 }
3235 }
3236
3237 $arReplace[] = $iblockSectionId > 0 ? $iblockSectionId: '';
3238 $arReplace[] = $SECTION_CODE;
3239 $arReplace[] = $SECTION_CODE_PATH;
3240 }
3241 elseif ($arrType === "S")
3242 {
3243 $SECTION_CODE_PATH = '';
3244 if (
3245 $id > 0
3246 && strpos($url, '#SECTION_CODE_PATH#') !== false
3247 )
3248 {
3249 $SECTION_CODE_PATH = CIBlockSection::getSectionCodePath($id);
3250 }
3251 $arReplace[] = '';
3252 $arReplace[] = '';
3253 $arReplace[] = $preparedId;
3254 $arReplace[] = $preparedCode;
3255 $arReplace[] = $SECTION_CODE_PATH;
3256 }
3257 else
3258 {
3259 $elementId = (int)($arr['ELEMENT_ID'] ?? 0);
3260 $preparedElementId = $elementId > 0 ? $elementId : '';
3261 $arReplace[] = $preparedElementId;
3262 $arReplace[] = rawurlencode((string)($arr['~ELEMENT_CODE'] ?? ($arr['ELEMENT_CODE'] ?? '')));
3263 $arReplace[] = $iblockSectionId > 0 ? $iblockSectionId : '';
3264 $arReplace[] = rawurlencode((string)($arr['~SECTION_CODE'] ?? ($arr['SECTION_CODE'] ?? '')));
3265 $arReplace[] = '';
3266 }
3267
3268 $url = str_replace($arSearch, $arReplace, $url);
3269
3270 return preg_replace("'(?<!:)/+'s", "/", $url);
3271 }
3272
3273 public static function OnSearchReindex($NS=Array(), $oCallback=NULL, $callback_method="")
3274 {
3276 global $USER_FIELD_MANAGER;
3278 global $DB;
3279
3280 $strNSJoin1 = "";
3281 $strNSFilter1 = "";
3282 $strNSFilter2 = "";
3283 $strNSFilter3 = "";
3284 $arResult = Array();
3285 if($NS["MODULE"]=="iblock" && $NS["ID"] <> '')
3286 {
3287 $arrTmp = explode(".", $NS["ID"]);
3288 $strNSFilter1 = " AND B.ID>=".intval($arrTmp[0])." ";
3289 if(mb_substr($arrTmp[1], 0, 1) != 'S')
3290 {
3291 $strNSFilter2 = " AND BE.ID>".intval($arrTmp[1])." ";
3292 }
3293 else
3294 {
3295 $strNSFilter2 = false;
3296 $strNSFilter3 = " AND BS.ID>".intval(mb_substr($arrTmp[1], 1))." ";
3297 }
3298 }
3299 if($NS["SITE_ID"]!="")
3300 {
3301 $strNSJoin1 .= " INNER JOIN b_iblock_site BS ON BS.IBLOCK_ID=B.ID ";
3302 $strNSFilter1 .= " AND BS.SITE_ID='".$DB->ForSQL($NS["SITE_ID"])."' ";
3303 }
3304 $strSql = "
3305 SELECT B.ID, B.IBLOCK_TYPE_ID, B.INDEX_ELEMENT, B.INDEX_SECTION, B.RIGHTS_MODE,
3306 B.IBLOCK_TYPE_ID, B.CODE as IBLOCK_CODE, B.XML_ID as IBLOCK_EXTERNAL_ID,
3307 B.SOCNET_GROUP_ID
3308 FROM b_iblock B
3309 ".$strNSJoin1."
3310 WHERE B.ACTIVE = 'Y'
3311 AND (B.INDEX_ELEMENT='Y' OR B.INDEX_SECTION='Y')
3312 ".$strNSFilter1."
3313 ORDER BY B.ID
3314 ";
3315
3316 $dbrIBlock = $DB->Query($strSql);
3317 while($arIBlock = $dbrIBlock->Fetch())
3318 {
3319 $IBLOCK_ID = $arIBlock["ID"];
3320
3321 $arGroups = Array();
3322
3323 $strSql =
3324 "SELECT GROUP_ID ".
3325 "FROM b_iblock_group ".
3326 "WHERE IBLOCK_ID= ".$IBLOCK_ID." ".
3327 " AND PERMISSION>='R' ".
3328 " AND GROUP_ID>1 ".
3329 "ORDER BY GROUP_ID";
3330
3331 $dbrIBlockGroup = $DB->Query($strSql);
3332 while($arIBlockGroup = $dbrIBlockGroup->Fetch())
3333 {
3334 $arGroups[] = $arIBlockGroup["GROUP_ID"];
3335 if($arIBlockGroup["GROUP_ID"]==2) break;
3336 }
3337
3338 $arSITE = Array();
3339 $strSql =
3340 "SELECT SITE_ID ".
3341 "FROM b_iblock_site ".
3342 "WHERE IBLOCK_ID= ".$IBLOCK_ID;
3343
3344 $dbrIBlockSite = $DB->Query($strSql);
3345 while($arIBlockSite = $dbrIBlockSite->Fetch())
3346 $arSITE[] = $arIBlockSite["SITE_ID"];
3347
3348 if($arIBlock["INDEX_ELEMENT"]=='Y' && ($strNSFilter2 !== false))
3349 {
3350 $strSql =
3351 "SELECT BE.ID, BE.NAME, BE.TAGS, ".
3352 " ".$DB->DateToCharFunction("BE.ACTIVE_FROM")." as DATE_FROM, ".
3353 " ".$DB->DateToCharFunction("BE.ACTIVE_TO")." as DATE_TO, ".
3354 " ".$DB->DateToCharFunction("BE.TIMESTAMP_X")." as LAST_MODIFIED, ".
3355 " BE.PREVIEW_TEXT_TYPE, BE.PREVIEW_TEXT, ".
3356 " BE.DETAIL_TEXT_TYPE, BE.DETAIL_TEXT, ".
3357 " BE.XML_ID as EXTERNAL_ID, BE.CODE, ".
3358 " BE.IBLOCK_SECTION_ID ".
3359 "FROM b_iblock_element BE ".
3360 "WHERE BE.IBLOCK_ID=".$IBLOCK_ID." ".
3361 " AND BE.ACTIVE='Y' ".
3362 CIBlockElement::WF_GetSqlLimit("BE.", "N").
3363 $strNSFilter2.
3364 "ORDER BY BE.ID ";
3365
3366 //For MySQL, we have to solve client out of memory
3367 //problem by limiting the query
3368 if($DB->type=="MYSQL")
3369 {
3370 $limit = 1000;
3371 $strSql .= " LIMIT ".$limit;
3372 }
3373 else
3374 {
3375 $limit = false;
3376 }
3377
3378 $dbrIBlockElement = $DB->Query($strSql);
3379 while($arIBlockElement = $dbrIBlockElement->Fetch())
3380 {
3381 $DETAIL_URL =
3382 "=ID=".urlencode($arIBlockElement["ID"]).
3383 "&EXTERNAL_ID=".urlencode($arIBlockElement["EXTERNAL_ID"]).
3384 "&CODE=".urlencode($arIBlockElement["CODE"]).
3385 "&IBLOCK_SECTION_ID=".urlencode($arIBlockElement["IBLOCK_SECTION_ID"]).
3386 "&IBLOCK_TYPE_ID=".urlencode($arIBlock["IBLOCK_TYPE_ID"]).
3387 "&IBLOCK_ID=".urlencode($IBLOCK_ID).
3388 "&IBLOCK_CODE=".urlencode($arIBlock["IBLOCK_CODE"]).
3389 "&IBLOCK_EXTERNAL_ID=".urlencode($arIBlock["IBLOCK_EXTERNAL_ID"]);
3390
3391 $BODY =
3392 ($arIBlockElement["PREVIEW_TEXT_TYPE"]=="html" ?
3393 CSearch::KillTags($arIBlockElement["PREVIEW_TEXT"]) :
3394 $arIBlockElement["PREVIEW_TEXT"]
3395 )."\r\n".
3396 ($arIBlockElement["DETAIL_TEXT_TYPE"]=="html" ?
3397 CSearch::KillTags($arIBlockElement["DETAIL_TEXT"]) :
3398 $arIBlockElement["DETAIL_TEXT"]
3399 );
3400
3401 $dbrProperties = CIBlockElement::GetProperty($IBLOCK_ID, $arIBlockElement["ID"], "sort", "asc", array("ACTIVE"=>"Y", "SEARCHABLE"=>"Y"));
3402 while($arProperties = $dbrProperties->Fetch())
3403 {
3404 $BODY .= "\r\n";
3405
3406 if($arProperties["USER_TYPE"] <> '')
3407 $UserType = CIBlockProperty::GetUserType($arProperties["USER_TYPE"]);
3408 else
3409 $UserType = array();
3410
3411 if(array_key_exists("GetSearchContent", $UserType))
3412 {
3413 $BODY .= CSearch::KillTags(
3414 call_user_func_array($UserType["GetSearchContent"],
3415 array(
3417 array("VALUE" => $arProperties["VALUE"]),
3418 array(),
3419 )
3420 )
3421 );
3422 }
3423 elseif(array_key_exists("GetPublicViewHTML", $UserType))
3424 {
3425 $BODY .= CSearch::KillTags(
3426 call_user_func_array($UserType["GetPublicViewHTML"],
3427 array(
3429 array("VALUE" => $arProperties["VALUE"]),
3430 array(),
3431 )
3432 )
3433 );
3434 }
3435 elseif($arProperties["PROPERTY_TYPE"]=='L')
3436 {
3437 $BODY .= $arProperties["VALUE_ENUM"];
3438 }
3439 elseif($arProperties["PROPERTY_TYPE"]=='F')
3440 {
3441 $arFile = CIBlockElement::__GetFileContent($arProperties["VALUE"]);
3442 if(is_array($arFile))
3443 {
3444 $BODY .= $arFile["CONTENT"];
3445 $arIBlockElement["TAGS"] .= ",".$arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
3446 }
3447 }
3448 else
3449 {
3450 $BODY .= $arProperties["VALUE"];
3451 }
3452 }
3453
3454 if($arIBlock["RIGHTS_MODE"] !== "E")
3455 $arPermissions = $arGroups;
3456 else
3457 {
3458 $obElementRights = new CIBlockElementRights($IBLOCK_ID, $arIBlockElement["ID"]);
3459 $arPermissions = $obElementRights->GetGroups(array("element_read"));
3460 }
3461
3462 $Result = array(
3463 "ID" => $arIBlockElement["ID"],
3464 "LAST_MODIFIED" => ($arIBlockElement["DATE_FROM"] <> ''? $arIBlockElement["DATE_FROM"]: $arIBlockElement["LAST_MODIFIED"]),
3465 "TITLE" => $arIBlockElement["NAME"],
3466 "BODY" => $BODY,
3467 "TAGS" => $arIBlockElement["TAGS"],
3468 "SITE_ID" => $arSITE,
3469 "PARAM1" => $arIBlock["IBLOCK_TYPE_ID"],
3470 "PARAM2" => $IBLOCK_ID,
3471 "DATE_FROM" => ($arIBlockElement["DATE_FROM"] <> ''? $arIBlockElement["DATE_FROM"] : false),
3472 "DATE_TO" => ($arIBlockElement["DATE_TO"] <> ''? $arIBlockElement["DATE_TO"] : false),
3473 "PERMISSIONS" => $arPermissions,
3474 "URL" => $DETAIL_URL
3475 );
3476
3477 if ($arIBlock["SOCNET_GROUP_ID"] > 0)
3478 $Result["PARAMS"] = array(
3479 "socnet_group" => $arIBlock["SOCNET_GROUP_ID"],
3480 );
3481
3482 if($oCallback)
3483 {
3484 $res = call_user_func(array($oCallback, $callback_method), $Result);
3485 if(!$res)
3486 return $IBLOCK_ID.".".$arIBlockElement["ID"];
3487 }
3488 else
3489 {
3490 $arResult[] = $Result;
3491 }
3492
3493 if($limit !== false)
3494 {
3495 $limit--;
3496 if($limit <= 0)
3497 return $IBLOCK_ID.".".$arIBlockElement["ID"];
3498 }
3499 }
3500 }
3501
3502 if($arIBlock["INDEX_SECTION"]=='Y')
3503 {
3504 $strSql =
3505 "SELECT BS.ID, BS.NAME, ".
3506 " ".$DB->DateToCharFunction("BS.TIMESTAMP_X")." as LAST_MODIFIED, ".
3507 " BS.DESCRIPTION_TYPE, BS.DESCRIPTION, BS.XML_ID as EXTERNAL_ID, BS.CODE, ".
3508 " BS.IBLOCK_ID ".
3509 "FROM b_iblock_section BS ".
3510 "WHERE BS.IBLOCK_ID=".$IBLOCK_ID." ".
3511 " AND BS.GLOBAL_ACTIVE='Y' ".
3512 $strNSFilter3.
3513 "ORDER BY BS.ID ";
3514
3515 $dbrIBlockSection = $DB->Query($strSql);
3516 while($arIBlockSection = $dbrIBlockSection->Fetch())
3517 {
3518 $DETAIL_URL =
3519 "=ID=".$arIBlockSection["ID"].
3520 "&EXTERNAL_ID=".$arIBlockSection["EXTERNAL_ID"].
3521 "&CODE=".$arIBlockSection["CODE"].
3522 "&IBLOCK_TYPE_ID=".$arIBlock["IBLOCK_TYPE_ID"].
3523 "&IBLOCK_ID=".$arIBlockSection["IBLOCK_ID"].
3524 "&IBLOCK_CODE=".$arIBlock["IBLOCK_CODE"].
3525 "&IBLOCK_EXTERNAL_ID=".$arIBlock["IBLOCK_EXTERNAL_ID"];
3526 $BODY =
3527 ($arIBlockSection["DESCRIPTION_TYPE"]=="html" ?
3528 CSearch::KillTags($arIBlockSection["DESCRIPTION"])
3529 :
3530 $arIBlockSection["DESCRIPTION"]
3531 );
3532 $BODY .= $USER_FIELD_MANAGER->OnSearchIndex("IBLOCK_".$arIBlockSection["IBLOCK_ID"]."_SECTION", $arIBlockSection["ID"]);
3533
3534 if($arIBlock["RIGHTS_MODE"] !== "E")
3535 $arPermissions = $arGroups;
3536 else
3537 {
3538 $obSectionRights = new CIBlockSectionRights($IBLOCK_ID, $arIBlockSection["ID"]);
3539 $arPermissions = $obSectionRights->GetGroups(array("section_read"));
3540 }
3541
3542 $Result = Array(
3543 "ID" => "S".$arIBlockSection["ID"],
3544 "LAST_MODIFIED" => $arIBlockSection["LAST_MODIFIED"],
3545 "TITLE" => $arIBlockSection["NAME"],
3546 "BODY" => $BODY,
3547 "SITE_ID" => $arSITE,
3548 "PARAM1" => $arIBlock["IBLOCK_TYPE_ID"],
3549 "PARAM2" => $IBLOCK_ID,
3550 "PERMISSIONS" => $arPermissions,
3551 "URL" => $DETAIL_URL,
3552 );
3553
3554 if ($arIBlock["SOCNET_GROUP_ID"] > 0)
3555 $Result["PARAMS"] = array(
3556 "socnet_group" => $arIBlock["SOCNET_GROUP_ID"],
3557 );
3558
3559 if($oCallback)
3560 {
3561 $res = call_user_func(array($oCallback, $callback_method), $Result);
3562 if(!$res)
3563 return $IBLOCK_ID.".S".$arIBlockSection["ID"];
3564 }
3565 else
3566 {
3567 $arResult[] = $Result;
3568 }
3569 }
3570 }
3571 $strNSFilter2="";
3572 $strNSFilter3="";
3573 }
3574
3575 if($oCallback)
3576 return false;
3577
3578 return $arResult;
3579 }
3580
3581 public static function GetElementCount($iblock_id)
3582 {
3584 global $DB;
3585
3586 $res = $DB->Query("
3587 SELECT COUNT('x') as C
3588 FROM b_iblock_element BE
3589 WHERE BE.IBLOCK_ID=".intval($iblock_id)."
3590 AND (
3591 (BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL)
3592 OR BE.WF_NEW='Y'
3593 )
3594 ");
3595 $ar = $res->Fetch();
3596 unset($res);
3597
3598 return (int)($ar["C"] ?? 0);
3599 }
3600
3601 public static function ResizePicture($arFile, $arResize)
3602 {
3603 if($arFile["tmp_name"] == '')
3604 return $arFile;
3605
3606 if(array_key_exists("error", $arFile) && $arFile["error"] !== 0)
3607 return Loc::getMessage("IBLOCK_BAD_FILE_ERROR");
3608
3609 $file = $arFile["tmp_name"];
3610
3611 if(!file_exists($file) && !is_file($file))
3612 return Loc::getMessage("IBLOCK_BAD_FILE_NOT_FOUND");
3613
3614 $width = (int)$arResize["WIDTH"];
3615 $height = (int)$arResize["HEIGHT"];
3616
3617 if($width <= 0 && $height <= 0)
3618 return $arFile;
3619
3620 $image = new Image($file);
3621 $imageInfo = $image->getInfo(false);
3622 if (empty($imageInfo))
3623 {
3624 return Loc::getMessage("IBLOCK_BAD_FILE_NOT_PICTURE");
3625 }
3626 $orig = [
3627 0 => $imageInfo->getWidth(),
3628 1 => $imageInfo->getHeight(),
3629 2 => $imageInfo->getFormat(),
3630 3 => $imageInfo->getAttributes(),
3631 "mime" => $imageInfo->getMime(),
3632 ];
3633
3634 $width_orig = $orig[0];
3635 $height_orig = $orig[1];
3636
3637 $orientation = 0;
3638 $exifData = [];
3639 $image_type = $orig[2];
3640 if($image_type == Image::FORMAT_JPEG)
3641 {
3642 $exifData = $image->getExifData();
3643 if (isset($exifData['Orientation']))
3644 {
3645 $orientation = $exifData['Orientation'];
3646 if ($orientation >= 5 && $orientation <= 8)
3647 {
3648 $width_orig = $orig[1];
3649 $height_orig = $orig[0];
3650 }
3651 }
3652 }
3653
3654 if(($width > 0 && $orig[0] > $width) || ($height > 0 && $orig[1] > $height))
3655 {
3656 if($arFile["COPY_FILE"] == "Y")
3657 {
3658 $new_file = CTempFile::GetFileName(basename($file));
3659 CheckDirPath($new_file);
3660 $arFile["copy"] = true;
3661
3662 if(copy($file, $new_file))
3663 $file = $new_file;
3664 else
3665 return Loc::getMessage("IBLOCK_BAD_FILE_NOT_FOUND");
3666 }
3667
3668 if($width <= 0)
3669 $width = $width_orig;
3670
3671 if($height <= 0)
3672 $height = $height_orig;
3673
3674 $height_new = $height_orig;
3675 if($width_orig > $width)
3676 $height_new = $width * $height_orig / $width_orig;
3677
3678 if($height_new > $height)
3679 $width = $height * $width_orig / $height_orig;
3680 else
3681 $height = $height_new;
3682
3683 $image_type = $orig[2];
3684 if ($image_type == Image::FORMAT_JPEG)
3685 {
3686 $image = imagecreatefromjpeg($file);
3687 if ($image === false)
3688 {
3689 ini_set('gd.jpeg_ignore_warning', 1);
3690 $image = imagecreatefromjpeg($file);
3691 }
3692
3693 if ($orientation > 1)
3694 {
3695 if ($orientation == 7 || $orientation == 8)
3696 $image = imagerotate($image, 90, null);
3697 elseif ($orientation == 3 || $orientation == 4)
3698 $image = imagerotate($image, 180, null);
3699 elseif ($orientation == 5 || $orientation == 6)
3700 $image = imagerotate($image, 270, null);
3701
3702 if (
3703 $orientation == 2 || $orientation == 7
3704 || $orientation == 4 || $orientation == 5
3705 )
3706 {
3707 $engine = new Image\Gd();
3708 $engine->setResource($image);
3709 $engine->flipHorizontal();
3710 }
3711 }
3712 }
3713 elseif ($image_type == Image::FORMAT_GIF)
3714 {
3715 $image = imagecreatefromgif($file);
3716 }
3717 elseif ($image_type == Image::FORMAT_PNG)
3718 {
3719 $image = imagecreatefrompng($file);
3720 }
3721 elseif ($image_type == Image::FORMAT_WEBP)
3722 {
3723 $image = imagecreatefromwebp($file);
3724 }
3725 else
3726 {
3727 return Loc::getMessage("IBLOCK_ERR_BAD_FILE_UNSUPPORTED");
3728 }
3729
3730 $image_p = imagecreatetruecolor($width, $height);
3731 if($image_type == Image::FORMAT_JPEG)
3732 {
3733 if($arResize["METHOD"] === "resample")
3734 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
3735 else
3736 imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
3737
3738 if($arResize["COMPRESSION"] > 0)
3739 imagejpeg($image_p, $file, $arResize["COMPRESSION"]);
3740 else
3741 imagejpeg($image_p, $file);
3742 }
3743 elseif($image_type == Image::FORMAT_GIF && function_exists("imagegif"))
3744 {
3745 imagetruecolortopalette($image_p, true, imagecolorstotal($image));
3746 imagepalettecopy($image_p, $image);
3747
3748 //Save transparency for GIFs
3749 $transparentColor = imagecolortransparent($image);
3750 if($transparentColor >= 0 && $transparentColor < imagecolorstotal($image))
3751 {
3752 $transparentColor = imagecolortransparent($image_p, $transparentColor);
3753 imagefilledrectangle($image_p, 0, 0, $width, $height, $transparentColor);
3754 }
3755
3756 if($arResize["METHOD"] === "resample")
3757 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
3758 else
3759 imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
3760 imagegif($image_p, $file);
3761 }
3762 else
3763 {
3764 //Save transparency for PNG
3765 $transparentColor = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
3766 imagefilledrectangle($image_p, 0, 0, $width, $height, $transparentColor);
3767 $transparentColor = imagecolortransparent($image_p, $transparentColor);
3768
3769 imagealphablending($image_p, false);
3770 if($arResize["METHOD"] === "resample")
3771 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
3772 else
3773 imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
3774
3775 imagesavealpha($image_p, true);
3776 imagepng($image_p, $file);
3777 }
3778
3779 imagedestroy($image);
3780 imagedestroy($image_p);
3781
3782 $arFile["size"] = filesize($file);
3783 $arFile["tmp_name"] = $file;
3784 return $arFile;
3785 }
3786 else
3787 {
3788 return $arFile;
3789 }
3790 }
3791
3792 public static function FilterPicture($filePath, $arFilter)
3793 {
3794 if (!file_exists($filePath))
3795 {
3796 return false;
3797 }
3798 if (
3799 !isset($arFilter['name'])
3800 || ($arFilter['name'] !== 'sharpen' && $arFilter['name'] !== 'watermark')
3801 )
3802 {
3803 return false;
3804 }
3805
3806 $image = new Image($filePath);
3807 $imageInfo = $image->getInfo();
3808 if (empty($imageInfo))
3809 {
3810 return false;
3811 }
3812 if (!$image->load())
3813 {
3814 return false;
3815 }
3816
3817 $orientation = 0;
3818 $exifData = $image->getExifData();
3819 if (isset($exifData['Orientation']))
3820 {
3821 $orientation = $exifData['Orientation'];
3822 }
3823 $image->autoRotate($orientation);
3824 switch ($arFilter['name'])
3825 {
3826 case 'sharpen':
3827 $image->filter(Image\Mask::createSharpen($arFilter['precision']));
3828 break;
3829 case 'watermark':
3830 if ($arFilter['type'] === 'text' && mb_strlen($arFilter['text']) > 1 && $arFilter['coefficient'] > 0)
3831 {
3832 $arFilter['text_width'] = ($imageInfo->getWidth() - 5) * $arFilter['coefficient'] / 100;
3833 }
3835 $image->drawWatermark($watermark);
3836 break;
3837 }
3838 $image->save(self::getDefaultJpegQuality());
3839 $image->clear();
3840
3841 return true;
3842 }
3843
3844 public static function NumberFormat($num)
3845 {
3846 if ($num <> '')
3847 {
3848 $res = preg_replace("#\\.([0-9]*?)(0+)\$#", ".\\1", $num);
3849 return rtrim($res, ".");
3850 }
3851 else
3852 {
3853 return "";
3854 }
3855 }
3856
3857 public static function _Order($by, $order, $default_order, $nullable = true)
3858 {
3859 static $arOrder = array(
3860 "nulls,asc" => array(true, "asc" ),
3861 "asc,nulls" => array(false, "asc" ),
3862 "nulls,desc" => array(true, "desc"),
3863 "desc,nulls" => array(false, "desc"),
3864 "asc" => array(true, "asc" ),
3865 "desc" => array(false, "desc"),
3866 );
3867 if (!is_string($order))
3868 {
3869 $order = 'desc,nulls';
3870 }
3871 $order = mb_strtolower(trim($order));
3872 $default_order = mb_strtolower(trim($default_order));
3873 if (isset($arOrder[$order]))
3874 $o = $arOrder[$order];
3875 elseif(isset($arOrder[$default_order]))
3876 $o = $arOrder[$default_order];
3877 else
3878 $o = $arOrder["desc,nulls"];
3879
3880 //There is no need to "reverse" nulls order when
3881 //column can not contain nulls
3882 if(!$nullable)
3883 {
3884 $o[0] = ($o[1] == "asc");
3885 }
3886
3887 return $o;
3888 }
3889
3890 public static function GetAdminIBlockEditLink($IBLOCK_ID, $arParams = array(), $strAdd = "")
3891 {
3892 if (
3893 (
3894 defined("CATALOG_PRODUCT")
3895 || (isset($arParams["force_catalog"]) && $arParams["force_catalog"])
3896 || array_key_exists('catalog', $arParams)
3897 )
3898 && !array_key_exists("menu", $arParams)
3899 )
3900 {
3901 $url = "cat_catalog_edit.php";
3902 $param = "IBLOCK_ID";
3903 }
3904 else
3905 {
3906 $url = "iblock_edit.php";
3907 $param = "ID";
3908 }
3909
3910 $url.= "?".$param."=".intval($IBLOCK_ID);
3911 $url.= "&type=".urlencode(CIBlock::GetArrayByID($IBLOCK_ID, "IBLOCK_TYPE_ID"));
3912 $url.= "&admin=Y";
3913 $url.= "&lang=".urlencode(LANGUAGE_ID);
3914 foreach ($arParams as $name => $value)
3915 if (isset($value))
3916 $url.= "&".urlencode($name)."=".urlencode($value);
3917
3918 if ($arParams["replace_script_name"])
3919 {
3920 $url = self::replaceScriptName($url);
3921 }
3922
3923 $url = str_replace("&skip_public=1", "", $url);
3924
3925 return $url.$strAdd;
3926 }
3927
3938 public static function GetAdminSectionEditLink($IBLOCK_ID, $SECTION_ID, $arParams = array(), $strAdd = "")
3939 {
3940 if (
3941 (
3942 defined("CATALOG_PRODUCT")
3943 || (isset($arParams["force_catalog"]) && $arParams["force_catalog"])
3944 || array_key_exists('catalog', $arParams)
3945 )
3946 && !array_key_exists("menu", $arParams)
3947 )
3948 $url = "cat_section_edit.php";
3949 else
3950 $url = "iblock_section_edit.php";
3951
3952 $url.= "?IBLOCK_ID=".intval($IBLOCK_ID);
3953 $url.= "&type=".urlencode(CIBlock::GetArrayByID($IBLOCK_ID, "IBLOCK_TYPE_ID"));
3954 if($SECTION_ID !== null)
3955 $url.= "&ID=".intval($SECTION_ID);
3956 $url.= "&lang=".urlencode(LANGUAGE_ID);
3957 foreach ($arParams as $name => $value)
3958 if (isset($value))
3959 $url.= "&".urlencode($name)."=".urlencode($value);
3960
3961 if (isset($arParams["replace_script_name"]) && $arParams["replace_script_name"])
3962 {
3963 $url = self::replaceScriptName($url);
3964 }
3965
3966 $url = str_replace("&skip_public=1", "", $url);
3967
3968 return $url.$strAdd;
3969 }
3970
3981 public static function GetAdminElementEditLink($IBLOCK_ID, $ELEMENT_ID, $arParams = array(), $strAdd = "")
3982 {
3983 if (
3984 (
3985 defined("CATALOG_PRODUCT")
3986 || (isset($arParams["force_catalog"]) && $arParams["force_catalog"])
3987 )
3988 && !array_key_exists("menu", $arParams)
3989 )
3990 $url = "cat_product_edit.php";
3991 else
3992 $url = "iblock_element_edit.php";
3993
3994 $url.= "?IBLOCK_ID=".intval($IBLOCK_ID);
3995 $url.= "&type=".urlencode(CIBlock::GetArrayByID($IBLOCK_ID, "IBLOCK_TYPE_ID"));
3996 if($ELEMENT_ID !== null)
3997 $url.= "&ID=".intval($ELEMENT_ID);
3998 $url.= "&lang=".urlencode(LANGUAGE_ID);
3999 foreach ($arParams as $name => $value)
4000 if (isset($value))
4001 $url.= "&".urlencode($name)."=".urlencode($value);
4002
4003 if (isset($arParams["replace_script_name"]) && $arParams["replace_script_name"])
4004 {
4005 $url = self::replaceScriptName($url);
4006 }
4007
4008 $url = str_replace("&skip_public=1", "", $url);
4009
4010 return $url.$strAdd;
4011 }
4012
4013 public static function GetAdminSubElementEditLink($IBLOCK_ID, $ELEMENT_ID, $SUBELEMENT_ID, $arParams = array(), $strAdd = '', $absoluteUrl = false)
4014 {
4015 $absoluteUrl = ($absoluteUrl === true);
4016 // it\s temporary hack
4017 if (defined('SELF_FOLDER_URL'))
4018 {
4019 $url = '/bitrix/tools/iblock/iblock_subelement_edit.php';
4020 }
4021 else
4022 {
4023 $url = ($absoluteUrl ? '/bitrix/admin/' : '') . 'iblock_subelement_edit.php';
4024 }
4025 $url .= '?IBLOCK_ID='.(int)$IBLOCK_ID.'&type='.urlencode(CIBlock::GetArrayByID($IBLOCK_ID, 'IBLOCK_TYPE_ID'));
4026 $url .= '&PRODUCT_ID='.(int)$ELEMENT_ID.'&ID='.(int)$SUBELEMENT_ID.'&lang='.LANGUAGE_ID;
4027
4028 foreach ($arParams as $name => $value)
4029 if (isset($value))
4030 $url.= '&'.urlencode($name).'='.urlencode($value);
4031
4032 if (isset($arParams["replace_script_name"]) && $arParams["replace_script_name"])
4033 {
4034 $url = self::replaceScriptName($url);
4035 }
4036
4037 $url = str_replace("&skip_public=1", "", $url);
4038
4039 return $url.$strAdd;
4040 }
4041
4051 public static function GetAdminElementListLink($IBLOCK_ID, $arParams = array(), $strAdd = "")
4052 {
4054 $url.= "?IBLOCK_ID=".intval($IBLOCK_ID);
4055 $url.= "&type=".urlencode(CIBlock::GetArrayByID($IBLOCK_ID, "IBLOCK_TYPE_ID"));
4056 $url.= "&lang=".urlencode(LANGUAGE_ID);
4057 foreach ($arParams as $name => $value)
4058 if (isset($value))
4059 $url.= "&".urlencode($name)."=".urlencode($value);
4060
4061 if (isset($arParams["replace_script_name"]) && $arParams["replace_script_name"])
4062 {
4063 $url = self::replaceScriptName($url);
4064 }
4065
4066 $url = str_replace("&skip_public=1", "", $url);
4067
4068 return $url.$strAdd;
4069 }
4070
4082 {
4083 if (!isset($arParams["skip_public"]))
4084 {
4085 if (defined("PUBLIC_MODE") && PUBLIC_MODE == 1 || self::isPublicSidePanel())
4086 {
4087 return "menu_catalog_" . $IBLOCK_ID . "/";
4088 }
4089 }
4090
4091 if (defined("CATALOG_PRODUCT") && !array_key_exists("menu", $arParams))
4092 {
4094 $url = "cat_product_list.php";
4095 else
4096 $url = "cat_product_admin.php";
4097 }
4098 else
4099 {
4101 $url = "iblock_list_admin.php";
4102 else
4103 $url = "iblock_element_admin.php";
4104 }
4105
4106 return $url;
4107 }
4108
4118 public static function GetAdminSectionListLink($IBLOCK_ID, $arParams = array(), $strAdd = "")
4119 {
4121 $url.= "?IBLOCK_ID=".intval($IBLOCK_ID);
4122 $url.= "&type=".urlencode(CIBlock::GetArrayByID($IBLOCK_ID, "IBLOCK_TYPE_ID"));
4123 $url.= "&lang=".urlencode(LANGUAGE_ID);
4124 foreach ($arParams as $name => $value)
4125 if (isset($value))
4126 $url.= "&".urlencode($name)."=".urlencode($value);
4127
4128 if (isset($arParams["replace_script_name"]) && $arParams["replace_script_name"])
4129 {
4130 $url = self::replaceScriptName($url);
4131 }
4132
4133 $url = str_replace("&skip_public=1", "", $url);
4134
4135 return $url.$strAdd;
4136 }
4137
4149 {
4150 if (!isset($arParams["skip_public"]))
4151 {
4152 if (defined("PUBLIC_MODE") && PUBLIC_MODE == 1 || self::isPublicSidePanel())
4153 {
4154 return "menu_catalog_category_".$IBLOCK_ID."/";
4155 }
4156 }
4157
4158 if ((defined("CATALOG_PRODUCT") || array_key_exists('catalog', $arParams)) && !array_key_exists("menu", $arParams))
4159 {
4161 $url = "cat_product_list.php";
4162 else
4163 $url = "cat_section_admin.php";
4164 }
4165 else
4166 {
4168 $url = "iblock_list_admin.php";
4169 else
4170 $url = "iblock_section_admin.php";
4171 }
4172
4173 return $url;
4174 }
4175
4176 private static function isPublicSidePanel()
4177 {
4178 $iframe = $_REQUEST["IFRAME"] ?? null;
4179 $iframeType = $_REQUEST["IFRAME_TYPE"] ?? null;
4180 $publicSidePanel = $_REQUEST["publicSidePanel"] ?? null;
4181
4182 return
4183 $iframe === "Y"
4184 && ($publicSidePanel === "Y" || $iframeType === "PUBLIC_FRAME")
4185 ;
4186 }
4187
4188 private static function replaceScriptName($url)
4189 {
4190 if (defined("PUBLIC_MODE") && PUBLIC_MODE == 1 || self::isPublicSidePanel())
4191 {
4192 $url = str_replace(".php", "/", $url);
4193 }
4194
4195 return str_replace("&replace_script_name=1", "", $url);
4196 }
4197
4202 public static function GetAdminListMode($IBLOCK_ID): string
4203 {
4204 $list_mode = (string)CIBlock::GetArrayByID($IBLOCK_ID, "LIST_MODE");
4205
4206 if (
4209 )
4210 {
4211 return $list_mode;
4212 }
4213 else
4214 {
4215 return
4216 Main\Config\Option::get('iblock', 'combined_list_mode') === 'Y'
4219 ;
4220 }
4221 }
4222
4223 public static function CheckForIndexes($IBLOCK_ID)
4224 {
4225 global $DB;
4227
4228 $ar = $arIBlock["FIELDS"]["CODE"]["DEFAULT_VALUE"];
4229 if (
4230 is_array($ar)
4231 && $ar["UNIQUE"] == "Y"
4232 && !$DB->IndexExists("b_iblock_element", array("IBLOCK_ID", "CODE"))
4233 )
4234 $DB->DDL("create index ix_iblock_element_code on b_iblock_element (IBLOCK_ID, CODE)");
4235
4236 $ar = $arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"];
4237 if (
4238 is_array($ar)
4239 && $ar["UNIQUE"] == "Y"
4240 && !$DB->IndexExists("b_iblock_section", array("IBLOCK_ID", "CODE"))
4241 )
4242 $DB->DDL("create index ix_iblock_section_code on b_iblock_section (IBLOCK_ID, CODE)");
4243 }
4244
4245 public static function GetAuditTypes()
4246 {
4247 return array(
4248 "IBLOCK_SECTION_ADD" => "[IBLOCK_SECTION_ADD] ".Loc::getMessage("IBLOCK_SECTION_ADD"),
4249 "IBLOCK_SECTION_EDIT" => "[IBLOCK_SECTION_EDIT] ".Loc::getMessage("IBLOCK_SECTION_EDIT"),
4250 "IBLOCK_SECTION_DELETE" => "[IBLOCK_SECTION_DELETE] ".Loc::getMessage("IBLOCK_SECTION_DELETE"),
4251 "IBLOCK_ELEMENT_ADD" => "[IBLOCK_ELEMENT_ADD] ".Loc::getMessage("IBLOCK_ELEMENT_ADD"),
4252 "IBLOCK_ELEMENT_EDIT" => "[IBLOCK_ELEMENT_EDIT] ".Loc::getMessage("IBLOCK_ELEMENT_EDIT"),
4253 "IBLOCK_ELEMENT_DELETE" => "[IBLOCK_ELEMENT_DELETE] ".Loc::getMessage("IBLOCK_ELEMENT_DELETE"),
4254 "IBLOCK_ADD" => "[IBLOCK_ADD] ".Loc::getMessage("IBLOCK_ADD"),
4255 "IBLOCK_EDIT" => "[IBLOCK_EDIT] ".Loc::getMessage("IBLOCK_EDIT"),
4256 "IBLOCK_DELETE" => "[IBLOCK_DELETE] ".Loc::getMessage("IBLOCK_DELETE"),
4257 );
4258 }
4259
4260 public static function roundDB($value)
4261 {
4262 $commonLength = 18;
4263 $decimals = 4;
4264 $wholePartLength = 14;
4265 $emptyFraction = '.0000'; // $decimals
4266
4267 $borderInt = 100000000000000; // 10 ^ $wholePartLength
4268
4269 if (is_int($value))
4270 {
4271 $sign = '';
4272 if ($value < 0)
4273 {
4274 $sign = '-';
4275 $value = -$value;
4276 }
4277 if ($value >= $borderInt)
4278 {
4279 $value = intdiv($value, $borderInt);
4280 }
4281
4282 return $sign . $value . $emptyFraction;
4283 }
4284 elseif (is_string($value))
4285 {
4286 $value = trim($value);
4287 if ($value === '')
4288 {
4289 return '0';
4290 }
4291
4292 $parsedValue = [];
4293 if (preg_match('/^([+-]?)([0-9]*)(\.[0-9]*)?$/', $value, $parsedValue))
4294 {
4295 $sign = $parsedValue[1] === '-' ? '-' : '';
4296 $wholePart = $parsedValue[2] === '' ? '0' : $parsedValue[2];
4297 if (strlen($wholePart) > $wholePartLength)
4298 {
4299 return $sign . substr($wholePart, 0, $wholePartLength) . $emptyFraction;
4300 }
4301
4302 $result = $sign . $wholePart;
4303 $fraction = $parsedValue[3] ?? $emptyFraction;
4304 if ($fraction === '' || $fraction === '.' || $fraction === $emptyFraction)
4305 {
4306 $result .= $emptyFraction;
4307 }
4308 else
4309 {
4310 $len = strlen($fraction) - 1;
4311 if ($len > $decimals)
4312 {
4313 $result .= substr($fraction, 0, $decimals + 1);
4314 }
4315 else
4316 {
4317 $result .= $fraction;
4318 if ($len !== $decimals)
4319 {
4320 $result .= str_repeat('0', $decimals - $len);
4321 }
4322 }
4323 }
4324
4325 return $result;
4326 }
4327 }
4328
4329 //$eps = 1.00 / pow(10, $commonLength + 4);
4330 $eps = 1.0E-22; // 1/(10 ^ ($commonLength + $decimals))
4331 $rounded = round((float)$value + $eps, $commonLength);
4332 if (is_nan($rounded) || is_infinite($rounded))
4333 {
4334 return '0' . $emptyFraction;
4335 }
4336
4337 $sign = $rounded < 0 ? 1 : 0;
4338 $result = sprintf('%01.' . $decimals . 'f', $rounded);
4339 $decimalPos = strpos($result, '.');
4340 $limit = $wholePartLength + $sign;
4341 if ($decimalPos === false)
4342 {
4343 if (strlen($result) > $limit)
4344 {
4345 $result = substr($result, 0, $limit) . $emptyFraction;
4346 }
4347 }
4348 elseif ($decimalPos > $limit)
4349 {
4350 $result = substr($result, 0, $limit) . $emptyFraction;
4351 }
4352
4353 return $result;
4354 }
4355
4356 public static function _transaction_lock($IBLOCK_ID)
4357 {
4359 global $DB;
4360
4361 $DB->Query("UPDATE b_iblock set TMP_ID = '".md5(mt_rand())."' WHERE ID = ".$IBLOCK_ID);
4362 }
4363
4364 public static function isShortDate($strDate)
4365 {
4366 $arDate = ParseDateTime($strDate, FORMAT_DATETIME);
4367 unset($arDate["DD"]);
4368 unset($arDate["MMMM"]);
4369 unset($arDate["MM"]);
4370 unset($arDate["M"]);
4371 unset($arDate["YYYY"]);
4372 return array_sum($arDate) == 0;
4373 }
4374
4375 public static function _Upper($str)
4376 {
4377 return $str;
4378 }
4379
4380 function _Add($ID)
4381 {
4382 return false;
4383 }
4384
4385 public static function _NotEmpty($column)
4386 {
4387 return "";
4388 }
4389
4390 public static function makeFilePropArray($data, $del = false, $description = null, $options = array())
4391 {
4392 if (is_array($data) && array_key_exists("VALUE", $data))
4393 {
4394 $data["VALUE"] = self::makeFileArray($data["VALUE"], $del, $description, $options);
4395 }
4396 else
4397 {
4398 $data = array(
4399 "VALUE" => self::makeFileArray($data, $del, $description, $options),
4400 );
4401 }
4402
4403 if (array_key_exists("description", $data["VALUE"] ?? []))
4404 {
4405 $data["DESCRIPTION"] = $data["VALUE"]["description"];
4406 }
4407
4408 return $data;
4409 }
4410
4411 public static function makeFileArray($data, $del = false, $description = null, $options = array())
4412 {
4413 $emptyFile = array(
4414 "name" => null,
4415 "type" => null,
4416 "tmp_name" => null,
4417 "error" => 4,
4418 "size" => 0,
4419 );
4420
4421 if ($del)
4422 {
4423 $result = $emptyFile;
4424 $result["del"] = "Y";
4425 }
4426 elseif (is_null($data))
4427 {
4428 $result = $emptyFile;
4429 }
4430 elseif (is_numeric($data))
4431 {
4432 $result = self::makeFileArrayFromId($data, $description, $options);
4433 if ($result === false)
4434 $result = $emptyFile;
4435 }
4436 elseif (is_string($data))
4437 {
4438 $result = self::makeFileArrayFromPath($data, $description, $options);
4439 if ($result === false)
4440 $result = $emptyFile;
4441 }
4442 elseif (is_array($data))
4443 {
4444 $result = self::makeFileArrayFromArray($data, $description, $options);
4445 if ($result === false)
4446 $result = $emptyFile;
4447 }
4448 else
4449 {
4450 $result = $emptyFile;
4451 }
4452
4453 return $result;
4454 }
4455
4456 private static function makeFileArrayFromId($file_id, $description = null, $options = array())
4457 {
4458 $result = false;
4459
4460 if (isset($options["allow_file_id"]) && $options["allow_file_id"] === true)
4461 {
4462 $result = CFile::MakeFileArray($file_id);
4463 }
4464
4465 if (!is_null($description))
4466 {
4467 $result = ($result === false ? array(
4468 "name" => null,
4469 "type" => null,
4470 "tmp_name" => null,
4471 "error" => 4,
4472 "size" => 0,
4473 ) : $result);
4474 $result["description"] = $description;
4475 }
4476 return $result;
4477 }
4478
4479 private static function makeFileArrayFromPath($file_path, $description = null, $options = array())
4480 {
4482 global $APPLICATION;
4483 $result = false;
4484
4485 if (preg_match("/^https?:\\/\\//", $file_path))
4486 {
4487 $result = CFile::MakeFileArray($file_path);
4488 }
4489 else
4490 {
4492 $normPath = $io->CombinePath("/", $file_path);
4493 $absPath = $io->CombinePath($_SERVER["DOCUMENT_ROOT"], $normPath);
4494 if ($io->ValidatePathString($absPath) && $io->FileExists($absPath))
4495 {
4496 $physicalName = $io->GetPhysicalName($absPath);
4497 $uploadDir = $io->GetPhysicalName(preg_replace("#[\\\\\\/]+#", "/", $_SERVER['DOCUMENT_ROOT'].'/'.(COption::GetOptionString('main', 'upload_dir', 'upload')).'/'));
4498 if (mb_strpos($physicalName, $uploadDir) === 0)
4499 {
4500 $result = CFile::MakeFileArray($physicalName);
4501 }
4502 else
4503 {
4504 $perm = $APPLICATION->GetFileAccessPermission($normPath);
4505 if ($perm >= "W")
4506 {
4507 $result = CFile::MakeFileArray($physicalName);
4508 }
4509 }
4510 }
4511 }
4512
4513 if (is_array($result))
4514 {
4515 if (!is_null($description))
4516 $result["description"] = $description;
4517 }
4518
4519 return $result;
4520 }
4521
4522 private static function makeFileArrayFromArray($file_array, $description = null, $options = array())
4523 {
4524 $result = false;
4525
4526 if (is_uploaded_file($file_array["tmp_name"]))
4527 {
4528 $result = $file_array;
4529 if (!is_null($description))
4530 $result["description"] = $description;
4531 }
4532 elseif (
4533 $file_array["tmp_name"] <> ''
4534 && mb_strpos($file_array["tmp_name"], CTempFile::GetAbsoluteRoot()) === 0
4535 )
4536 {
4538 $absPath = $io->CombinePath("/", $file_array["tmp_name"]);
4539 $tmpPath = CTempFile::GetAbsoluteRoot()."/";
4540 if (mb_strpos($absPath, $tmpPath) === 0 || (($absPath = ltrim($absPath, "/")) && mb_strpos($absPath, $tmpPath) === 0))
4541 {
4542 $result = $file_array;
4543 $result["tmp_name"] = $absPath;
4544 $result['error'] = (int)($result['error'] ?? 0);
4545 if (!is_null($description))
4546 $result["description"] = $description;
4547 }
4548 }
4549 elseif ($file_array["tmp_name"] <> '')
4550 {
4552 $normPath = $io->CombinePath("/", $file_array["tmp_name"]);
4553 $absPath = $io->CombinePath(CTempFile::GetAbsoluteRoot(), $normPath);
4554 $tmpPath = CTempFile::GetAbsoluteRoot()."/";
4555 if (mb_strpos($absPath, $tmpPath) === 0 && $io->FileExists($absPath) ||
4556 ($absPath = $io->CombinePath($_SERVER["DOCUMENT_ROOT"], $normPath)) && mb_strpos($absPath, $tmpPath) === 0)
4557 {
4558 $result = $file_array;
4559 $result["tmp_name"] = $absPath;
4560 $result['error'] = (int)($result['error'] ?? 0);
4561 if (!is_null($description))
4562 $result["description"] = $description;
4563 }
4564 }
4565 else
4566 {
4567 $emptyFile = array(
4568 "name" => null,
4569 "type" => null,
4570 "tmp_name" => null,
4571 "error" => 4,
4572 "size" => 0,
4573 );
4574 if ($file_array == $emptyFile)
4575 {
4576 $result = $emptyFile;
4577 if (!is_null($description))
4578 $result["description"] = $description;
4579 }
4580 }
4581
4582 return $result;
4583 }
4584
4585 public static function disableTagCache($iblock_id)
4586 {
4587 $iblock_id = (int)$iblock_id;
4588 if ($iblock_id > 0)
4589 self::$disabledCacheTag[$iblock_id] = $iblock_id;
4590 }
4591
4592 public static function enableTagCache($iblock_id)
4593 {
4594 $iblock_id = (int)$iblock_id;
4595 if (isset(self::$disabledCacheTag[$iblock_id]))
4596 unset(self::$disabledCacheTag[$iblock_id]);
4597 }
4598
4599 public static function clearIblockTagCache($iblock_id)
4600 {
4601 global $CACHE_MANAGER;
4602 $iblock_id = (int)$iblock_id;
4603 if (defined("BX_COMP_MANAGED_CACHE") && $iblock_id > 0 && self::isEnabledClearTagCache())
4604 $CACHE_MANAGER->ClearByTag('iblock_id_'.$iblock_id);
4605 }
4606
4607 public static function registerWithTagCache($iblock_id)
4608 {
4609 global $CACHE_MANAGER;
4610 $iblock_id = (int)$iblock_id;
4611 if ($iblock_id > 0 && !isset(self::$disabledCacheTag[$iblock_id]))
4612 $CACHE_MANAGER->RegisterTag("iblock_id_".$iblock_id);
4613 }
4614
4615 public static function enableClearTagCache()
4616 {
4617 self::$enableClearTagCache++;
4618 }
4619
4620 public static function disableClearTagCache()
4621 {
4622 self::$enableClearTagCache--;
4623 }
4624
4625 public static function isEnabledClearTagCache(): bool
4626 {
4627 return (self::$enableClearTagCache >= 0);
4628 }
4629
4630 public static function getDefaultJpegQuality(): int
4631 {
4632 $jpgQuality = (int)Main\Config\Option::get('main', 'image_resize_quality', '95');
4633 if ($jpgQuality <= 0 || $jpgQuality > 100)
4634 {
4635 $jpgQuality = 95;
4636 }
4637
4638 return $jpgQuality;
4639 }
4640
4641 public static function checkActivityDatesAgent($iblockId, $previousTime): string
4642 {
4643 $iblockId = (int)$iblockId;
4644 if ($iblockId <= 0)
4645 {
4646 return '';
4647 }
4648 $currentTime = time();
4649 $result = '\CIBlock::checkActivityDatesAgent('.$iblockId.', '.$currentTime.');';
4650 $previousTime = (int)$previousTime;
4651 if ($previousTime <= 0)
4652 {
4653 return $result;
4654 }
4655
4657 $finish = Main\Type\DateTime::createFromTimestamp($currentTime);
4658
4660 'select' => array('ID'),
4661 'filter' => array(
4662 '=IBLOCK_ID' => $iblockId,
4663 '=ACTIVE' => 'Y',
4664 '=WF_STATUS_ID' => 1,
4665 '=WF_PARENT_ELEMENT_ID' => null,
4666 array(
4667 'LOGIC' => 'OR',
4668 array(
4669 '>ACTIVE_FROM' => $start,
4670 '<=ACTIVE_FROM' => $finish
4671 ),
4672 array(
4673 '>ACTIVE_TO' => $start,
4674 '<=ACTIVE_TO' => $finish
4675 )
4676 )
4677 ),
4678 'limit' => 1
4679 ));
4680 unset($finish);
4681 unset($start);
4682 $row = $iterator->fetch();
4683 unset($iterator);
4684 if (!empty($row))
4685 {
4686 static::clearIblockTagCache($iblockId);
4687 }
4688 unset($row);
4689
4690 return $result;
4691 }
4692
4698 public static function getDefaultRights(): array
4699 {
4700 return array(
4701 1 => \CIBlockRights::FULL_ACCESS,
4702 2 => \CIBlockRights::PUBLIC_READ
4703 );
4704 }
4705
4706 public static function isUniqueElementCode(int $id): bool
4707 {
4708 if ($id <= 0)
4709 {
4710 return false;
4711 }
4712
4713 $iblock = static::GetFields($id);
4714
4715 return (
4716 isset($iblock['CODE']['DEFAULT_VALUE']['UNIQUE'])
4717 && $iblock['CODE']['DEFAULT_VALUE']['UNIQUE'] === 'Y'
4718 );
4719 }
4720
4721 public static function isUniqueSectionCode(int $id): bool
4722 {
4723 if ($id <= 0)
4724 {
4725 return false;
4726 }
4727
4728 $iblock = static::GetFields($id);
4729
4730 return (
4731 isset($iblock['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'])
4732 && $iblock['SECTION_CODE']['DEFAULT_VALUE']['UNIQUE'] === 'Y'
4733 );
4734 }
4735
4736 protected static function getFieldsDefaultValues(): array
4737 {
4738 $jpgQuality = static::getDefaultJpegQuality();
4739
4740 return [
4741 'IBLOCK_SECTION' => [
4742 'KEEP_IBLOCK_SECTION_ID' => 'N',
4743 ],
4744 'ACTIVE' => 'Y',
4745 'ACTIVE_FROM' => '',
4746 'ACTIVE_TO' => '',
4747 'SORT' => 500,
4748 'NAME' => '',
4749 'PREVIEW_PICTURE' => [
4750 'FROM_DETAIL' => 'N',
4751 'UPDATE_WITH_DETAIL' => 'N',
4752 'DELETE_WITH_DETAIL' => 'N',
4753 'SCALE' => 'N',
4754 'WIDTH' => '',
4755 'HEIGHT' => '',
4756 'IGNORE_ERRORS' => 'N',
4757 'METHOD' => 'resample',
4758 'COMPRESSION' => $jpgQuality,
4759 'USE_WATERMARK_TEXT' => 'N',
4760 'WATERMARK_TEXT' => '',
4761 'WATERMARK_TEXT_FONT' => '',
4762 'WATERMARK_TEXT_COLOR' => '',
4763 'WATERMARK_TEXT_SIZE' => '',
4764 'WATERMARK_TEXT_POSITION' => '',
4765 'USE_WATERMARK_FILE' => 'N',
4766 'WATERMARK_FILE' => '',
4767 'WATERMARK_FILE_ALPHA' => '',
4768 'WATERMARK_FILE_POSITION' => '',
4769 'WATERMARK_FILE_ORDER' => '', // unused
4770 ],
4771 'PREVIEW_TEXT_TYPE' => 'text',
4772 'PREVIEW_TEXT' => '',
4773 'DETAIL_PICTURE' => array(
4774 'SCALE' => 'N',
4775 'WIDTH' => '',
4776 'HEIGHT' => '',
4777 'IGNORE_ERRORS' => 'N',
4778 'METHOD' => 'resample',
4779 'COMPRESSION' => $jpgQuality,
4780 'USE_WATERMARK_TEXT' => 'N',
4781 'WATERMARK_TEXT' => '',
4782 'WATERMARK_TEXT_FONT' => '',
4783 'WATERMARK_TEXT_COLOR' => '',
4784 'WATERMARK_TEXT_SIZE' => '',
4785 'WATERMARK_TEXT_POSITION' => '',
4786 'USE_WATERMARK_FILE' => 'N',
4787 'WATERMARK_FILE' => '',
4788 'WATERMARK_FILE_ALPHA' => '',
4789 'WATERMARK_FILE_POSITION' => '',
4790 'WATERMARK_FILE_ORDER' => '', // unused
4791 ),
4792 'DETAIL_TEXT_TYPE' => 'text',
4793 'DETAIL_TEXT' => '',
4794 'XML_ID' => '',
4795 'CODE' => [
4796 'UNIQUE' => 'N',
4797 'TRANSLITERATION' => 'N',
4798 'TRANS_LEN' => 100,
4799 'TRANS_CASE' => 'L',
4800 'TRANS_SPACE' => '-',
4801 'TRANS_OTHER' => '-',
4802 'TRANS_EAT' => 'Y',
4803 'USE_GOOGLE' => 'N',
4804 ],
4805 'TAGS' => '',
4806 'SECTION_NAME' => '',
4807 'SECTION_PICTURE' => [
4808 'FROM_DETAIL' => 'N',
4809 'UPDATE_WITH_DETAIL' => 'N',
4810 'DELETE_WITH_DETAIL' => 'N',
4811 'SCALE' => 'N',
4812 'WIDTH' => '',
4813 'HEIGHT' => '',
4814 'IGNORE_ERRORS' => 'N',
4815 'METHOD' => 'resample',
4816 'COMPRESSION' => $jpgQuality,
4817 'USE_WATERMARK_TEXT' => 'N',
4818 'WATERMARK_TEXT' => '',
4819 'WATERMARK_TEXT_FONT' => '',
4820 'WATERMARK_TEXT_COLOR' => '',
4821 'WATERMARK_TEXT_SIZE' => '',
4822 'WATERMARK_TEXT_POSITION' => '',
4823 'USE_WATERMARK_FILE' => 'N',
4824 'WATERMARK_FILE' => '',
4825 'WATERMARK_FILE_ALPHA' => '',
4826 'WATERMARK_FILE_POSITION' => '',
4827 'WATERMARK_FILE_ORDER' => '', // unused
4828 ],
4829 'SECTION_DESCRIPTION_TYPE' => 'text',
4830 'SECTION_DESCRIPTION' => '',
4831 'SECTION_DETAIL_PICTURE' => [
4832 'SCALE' => 'N',
4833 'WIDTH' => '',
4834 'HEIGHT' => '',
4835 'IGNORE_ERRORS' => 'N',
4836 'METHOD' => 'resample',
4837 'COMPRESSION' => $jpgQuality,
4838 'USE_WATERMARK_TEXT' => 'N',
4839 'WATERMARK_TEXT' => '',
4840 'WATERMARK_TEXT_FONT' => '',
4841 'WATERMARK_TEXT_COLOR' => '',
4842 'WATERMARK_TEXT_SIZE' => '',
4843 'WATERMARK_TEXT_POSITION' => '',
4844 'USE_WATERMARK_FILE' => 'N',
4845 'WATERMARK_FILE' => '',
4846 'WATERMARK_FILE_ALPHA' => '',
4847 'WATERMARK_FILE_POSITION' => '',
4848 'WATERMARK_FILE_ORDER' => '',
4849 ],
4850 'SECTION_XML_ID' => '',
4851 'SECTION_CODE' => [
4852 'UNIQUE' => 'N',
4853 'TRANSLITERATION' => 'N',
4854 'TRANS_LEN' => 100,
4855 'TRANS_CASE' => 'L',
4856 'TRANS_SPACE' => '-',
4857 'TRANS_OTHER' => '-',
4858 'TRANS_EAT' => 'Y',
4859 'USE_GOOGLE' => 'N',
4860 ],
4861 'LOG_SECTION_ADD' => false,
4862 'LOG_SECTION_EDIT' => false,
4863 'LOG_SECTION_DELETE' => false,
4864 'LOG_ELEMENT_ADD' => false,
4865 'LOG_ELEMENT_EDIT' => false,
4866 'LOG_ELEMENT_DELETE' => false,
4867 'XML_IMPORT_START_TIME' => false,
4868 'DETAIL_TEXT_TYPE_ALLOW_CHANGE' => 'Y',
4869 'PREVIEW_TEXT_TYPE_ALLOW_CHANGE' => 'Y',
4870 'SECTION_DESCRIPTION_TYPE_ALLOW_CHANGE' => 'Y',
4871 ];
4872 }
4873
4875 {
4876 $compression = (int)$settings['COMPRESSION'];
4877 if ($compression > 100)
4878 {
4879 $compression = 100;
4880 }
4881 elseif ($compression <= 0)
4882 {
4883 $compression = '';
4884 }
4885
4886 return [
4887 'SCALE' => $settings['SCALE'] === 'Y'? 'Y': 'N',
4888 'WIDTH' => (int)$settings['WIDTH'] ?: '',
4889 'HEIGHT' => (int)$settings['HEIGHT'] ?: '',
4890 'IGNORE_ERRORS' => $settings['IGNORE_ERRORS'] === 'Y'? 'Y': 'N',
4891 'METHOD' => $settings['METHOD'] === 'resample'? 'resample': '',
4892 'COMPRESSION' => $compression,
4893 'USE_WATERMARK_TEXT' => $settings['USE_WATERMARK_TEXT'] === 'Y'? 'Y': 'N',
4894 'WATERMARK_TEXT' => $settings['WATERMARK_TEXT'],
4895 'WATERMARK_TEXT_FONT' => $settings['WATERMARK_TEXT_FONT'],
4896 'WATERMARK_TEXT_COLOR' => $settings['WATERMARK_TEXT_COLOR'],
4897 'WATERMARK_TEXT_SIZE' => (int)$settings['WATERMARK_TEXT_SIZE'] ?: '',
4898 'WATERMARK_TEXT_POSITION' => $settings['WATERMARK_TEXT_POSITION'],
4899 'USE_WATERMARK_FILE' => $settings['USE_WATERMARK_FILE'] === 'Y'? 'Y': 'N',
4900 'WATERMARK_FILE' => $settings['WATERMARK_FILE'],
4901 'WATERMARK_FILE_ALPHA' => (int)$settings['WATERMARK_FILE_ALPHA'] ?: '',
4902 'WATERMARK_FILE_POSITION' => $settings['WATERMARK_FILE_POSITION'],
4903 'WATERMARK_FILE_ORDER' => $settings['WATERMARK_FILE_ORDER'], // unused
4904 ];
4905 }
4906
4908 {
4909 $result = static::prepareDetailPictureFieldSettings($settings);
4910
4911 $result['FROM_DETAIL'] = $settings['FROM_DETAIL'] === 'Y'? 'Y': 'N';
4912 $result['DELETE_WITH_DETAIL'] = $settings['DELETE_WITH_DETAIL'] === 'Y'? 'Y': 'N';
4913 $result['UPDATE_WITH_DETAIL'] = $settings['UPDATE_WITH_DETAIL'] === 'Y'? 'Y': 'N';
4914
4915 return $result;
4916 }
4917
4918 protected static function prepareCodeFieldSettings(array $settings): array
4919 {
4920 $maxLength = (int)$settings['TRANS_LEN'];
4921 if ($maxLength > 255)
4922 {
4923 $maxLength = 255;
4924 }
4925 elseif($maxLength < 1)
4926 {
4927 $maxLength = 100;
4928 }
4929 $transCase = (string)$settings['TRANS_CASE'];
4930 if ($transCase !== 'U' && $transCase !== '')
4931 {
4932 $transCase = 'L';
4933 }
4934
4935 return [
4936 'UNIQUE' => $settings['UNIQUE'] === 'Y'? 'Y': 'N',
4937 'TRANSLITERATION' => $settings['TRANSLITERATION'] === 'Y'? 'Y': 'N',
4938 'TRANS_LEN' => $maxLength,
4939 'TRANS_CASE' => $transCase,
4940 'TRANS_SPACE' => substr($settings['TRANS_SPACE'], 0, 1),
4941 'TRANS_OTHER' => substr($settings['TRANS_OTHER'], 0, 1),
4942 'TRANS_EAT' => $settings['TRANS_EAT'] === 'N'? 'N': 'Y',
4943 'USE_GOOGLE' => $settings['USE_GOOGLE'] === 'Y'? 'Y': 'N',
4944 ];
4945 }
4946
4947 public static function getSinglePropertyValuesTableName(int $iblockId): string
4948 {
4949 return self::TABLE_PREFIX_SINGLE_PROPERTY_VALUES . $iblockId;
4950 }
4951
4952 public static function getMultiplePropertyValuesTableName(int $iblockId): string
4953 {
4954 return self::TABLE_PREFIX_MULTIPLE_PROPERTY_VALUES . $iblockId;
4955 }
4956
4957 public static function getCommonPropertyValuesTableName(): string
4958 {
4959 return self::TABLE_COMMON_PROPERTY_VALUES;
4960 }
4961
4962 public function getLastError(): string
4963 {
4964 return $this->LAST_ERROR;
4965 }
4966}
$arParams
Определения access_dialog.php:21
$connection
Определения actionsdefinitions.php:38
$count
Определения admin_tab.php:4
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
static createTable(int $iblockId)
Определения FullText.php:49
static drop(int $iblockId)
Определения FullText.php:71
const LIST_MODE_COMBINED
Определения iblocktable.php:95
const LIST_MODE_SEPARATE
Определения iblocktable.php:94
static getConnection($name="")
Определения application.php:638
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения Gd.php:14
static createSharpen($precision)
Определения Mask.php:59
static createFromArray($params)
Определения Watermark.php:160
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
static cleanCache()
Определения datamanager.php:1983
static getRow(array $parameters)
Определения datamanager.php:398
static getList(array $parameters=array())
Определения datamanager.php:431
static getCount($filter=array(), array $cache=array())
Определения datamanager.php:516
static filter()
Определения query.php:906
static createFromTimestamp($timestamp)
Определения datetime.php:246
Определения iblock.php:10
getLastError()
Определения iblock.php:4962
static GetAdminElementListScriptName($IBLOCK_ID, $arParams=array())
Определения iblock.php:4081
static GetFields($ID)
Определения iblock.php:2320
static GetAdminSubElementEditLink($IBLOCK_ID, $ELEMENT_ID, $SUBELEMENT_ID, $arParams=array(), $strAdd='', $absoluteUrl=false)
Определения iblock.php:4013
static GetAdminSectionListLink($IBLOCK_ID, $arParams=array(), $strAdd="")
Определения iblock.php:4118
static GetAuditTypes()
Определения iblock.php:4245
static prepareCodeFieldSettings(array $settings)
Определения iblock.php:4918
static SetMessages($ID, $arFields)
Определения iblock.php:1781
static isUniqueSectionCode(int $id)
Определения iblock.php:4721
static getCommonPropertyValuesTableName()
Определения iblock.php:4957
const TABLE_PREFIX_MULTIPLE_PROPERTY_VALUES
Определения iblock.php:12
static AddPanelButtons($mode, $componentName, $arButtons)
Определения iblock.php:229
static CheckForIndexes($IBLOCK_ID)
Определения iblock.php:4223
static disableClearTagCache()
Определения iblock.php:4620
static GetArrayByID($ID, $FIELD="")
Определения iblock.php:823
static ReplaceSectionUrl($url, $arr, $server_name=false, $arrType=false)
Определения iblock.php:3004
static Delete($ID)
Определения iblock.php:1376
static SetPermission($IBLOCK_ID, $arGROUP_ID)
Определения iblock.php:1697
static getMultiplePropertyValuesTableName(int $iblockId)
Определения iblock.php:4952
static GetFieldsDefaults()
Определения iblock.php:1888
static preparePreviewPictureFieldSettings(array $settings)
Определения iblock.php:4907
static makeFileArray($data, $del=false, $description=null, $options=array())
Определения iblock.php:4411
static GetAdminElementListLink($IBLOCK_ID, $arParams=array(), $strAdd="")
Определения iblock.php:4051
static fillUrlElementDataCache(int $id)
Определения iblock.php:38
static GetGroupPermissions($ID)
Определения iblock.php:2401
static GetAdminListMode($IBLOCK_ID)
Определения iblock.php:4202
static getFieldsDefaultValues()
Определения iblock.php:4736
CheckFields(&$arFields, $ID=false)
Определения iblock.php:1499
static OnSearchReindex($NS=Array(), $oCallback=NULL, $callback_method="")
Определения iblock.php:3273
static GetByID($ID)
Определения iblock.php:813
_Add($ID)
Определения iblock.php:4380
static SetFields($ID, $arFields)
Определения iblock.php:2128
static GetElementCount($iblock_id)
Определения iblock.php:3581
static ResizePicture($arFile, $arResize)
Определения iblock.php:3601
static _Order($by, $order, $default_order, $nullable=true)
Определения iblock.php:3857
static isUniqueElementCode(int $id)
Определения iblock.php:4706
static FilterCreate($field_name, $values, $type, $cOperationType=false, $bSkipEmpty=true)
Определения iblock.php:2568
static GetAdminSectionListScriptName($IBLOCK_ID, $arParams=array())
Определения iblock.php:4148
static ShowPanel($IBLOCK_ID=0, $ELEMENT_ID=0, $SECTION_ID="", $type="news", $bGetIcons=false, $componentName="", $arLabels=array())
Определения iblock.php:199
static GetSite($iblock_id)
Определения iblock.php:801
static checkActivityDatesAgent($iblockId, $previousTime)
Определения iblock.php:4641
static CleanCache($ID)
Определения iblock.php:920
static getSinglePropertyValuesTableName(int $iblockId)
Определения iblock.php:4947
static ReplaceDetailUrl($url, $arr, $server_name=false, $arrType=false)
Определения iblock.php:3102
static enableClearTagCache()
Определения iblock.php:4615
static GetAdminIBlockEditLink($IBLOCK_ID, $arParams=array(), $strAdd="")
Определения iblock.php:3890
static clearIblockTagCache($iblock_id)
Определения iblock.php:4599
static _transaction_lock($IBLOCK_ID)
Определения iblock.php:4356
static GetAdminElementEditLink($IBLOCK_ID, $ELEMENT_ID, $arParams=array(), $strAdd="")
Определения iblock.php:3981
static _Upper($str)
Определения iblock.php:4375
static getProductUrlValue(array $element, bool $serverName)
Определения iblock.php:3042
string $LAST_ERROR
Определения iblock.php:15
static isShortDate($strDate)
Определения iblock.php:4364
static enableTagCache($iblock_id)
Определения iblock.php:4592
static MkOperationFilter($key)
Определения iblock.php:2522
static getDefaultJpegQuality()
Определения iblock.php:4630
static GetAdminSectionEditLink($IBLOCK_ID, $SECTION_ID, $arParams=array(), $strAdd="")
Определения iblock.php:3938
static FilterPicture($filePath, $arFilter)
Определения iblock.php:3792
static clearUrlDataCache()
Определения iblock.php:30
static GetProperties($ID, $arOrder=array(), $arFilter=array())
Определения iblock.php:2394
static GetComponentMenu($mode, $arButtons)
Определения iblock.php:330
static GetPermission($IBLOCK_ID, $FOR_USER_ID=false)
Определения iblock.php:2423
static OnSearchGetURL($arFields)
Определения iblock.php:2963
static OnLangDelete($lang)
Определения iblock.php:2509
static FilterCreateEx($fname, $vals, $type, &$bFullJoin, $cOperationType=false, $bSkipEmpty=true)
Определения iblock.php:2581
static GetPanelButtons($IBLOCK_ID=0, $ELEMENT_ID=0, $SECTION_ID=0, $arOptions=array())
Определения iblock.php:357
static isCorrectFullFormatDate($value)
Определения iblock.php:2898
static prepareDetailPictureFieldSettings(array $settings)
Определения iblock.php:4874
static OnGroupDelete($group_id)
Определения iblock.php:2514
static _MergeIBArrays($iblock_id, $iblock_code=false, $iblock_id2=false, $iblock_code2=false)
Определения iblock.php:2929
static int $enableClearTagCache
Определения iblock.php:17
static OnBeforeLangDelete($lang)
Определения iblock.php:2482
static roundDB($value)
Определения iblock.php:4260
const TABLE_COMMON_PROPERTY_VALUES
Определения iblock.php:13
static registerWithTagCache($iblock_id)
Определения iblock.php:4607
static getFieldDefaultSettings(string $fieldName)
Определения iblock.php:2116
static disableTagCache($iblock_id)
Определения iblock.php:4585
static ForLIKE($str)
Определения iblock.php:2573
Add($arFields)
Определения iblock.php:943
static _GetProductUrl($OF_ELEMENT_ID, $OF_IBLOCK_ID, $server_name=false, $arrType=false)
Определения iblock.php:3031
const TABLE_PREFIX_SINGLE_PROPERTY_VALUES
Определения iblock.php:11
Update($ID, $arFields)
Определения iblock.php:1146
static bool $catalogIncluded
Определения iblock.php:19
static NumberFormat($num)
Определения iblock.php:3844
static array $disabledCacheTag
Определения iblock.php:16
static makeFilePropArray($data, $del=false, $description=null, $options=array())
Определения iblock.php:4390
static isEnabledClearTagCache()
Определения iblock.php:4625
static bool $workflowIncluded
Определения iblock.php:20
static GetMessages($ID, $type="")
Определения iblock.php:1831
static _NotEmpty($column)
Определения iblock.php:4385
static getDefaultRights()
Определения iblock.php:4698
static ChangePermission($MODULE_ID, $arGroups, $ITEM_ID=false, $PARAM1=false, $PARAM2=false, $SITE_ID=false, $PARAMS=false)
Определения search.php:3097
static DeleteIndex($MODULE_ID, $ITEM_ID=false, $PARAM1=false, $PARAM2=false, $SITE_ID=false)
Определения search.php:2922
static KillTags($str)
Определения search.php:2092
static GetInstance()
Определения virtual_io.php:60
static GetInfoByOfferIBlock($intIBlockID)
Определения catalog_sku.php:111
static getProductList($offerID, $iblockID=0)
Определения catalog_sku.php:694
static GetComponentDescr($componentName)
Определения component_util.php:402
Определения quota.php:6
static recalculateDb(bool $mode=true)
Определения quota.php:29
static MakeFileArray($path, $mimetype=false, $skipInternal=false, $external_id="")
Определения file.php:2005
static urlDeleteParams($url, $delete_params, $options=array())
Определения http.php:568
Определения iblock_rights.php:7
static GetByID($ID)
Определения iblocktype.php:220
static GetByIDLang($ID, $LID, $bFindAny=true)
Определения iblocktype.php:274
Определения sqlwhere.php:1359
static GetAbsoluteRoot()
Определения file_temp.php:11
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$options
Определения commerceml2.php:49
$str
Определения commerceml2.php:63
$componentName
Определения component_props2.php:49
$arComponentDescription
Определения component_props2.php:73
$arFields
Определения dblapprove.php:5
$data['IS_AVAILABLE']
Определения .description.php:13
$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
GetFilterQuery($field, $val, $procent="Y", $ex_sep=array(), $clob="N", $div_fields="Y", $clob_upper="N")
Определения filter_tools.php:383
$perm
Определения options.php:169
global $USER_FIELD_MANAGER
Определения attempt.php:6
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$start
Определения get_search.php:9
if($ajaxMode) $ID
Определения get_user.php:27
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$iblockId
Определения iblock_catalog_edit.php:30
$defaultValues
Определения iblock_catalog_edit.php:124
$productIblock
Определения iblock_catalog_edit.php:143
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
$_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
$context
Определения csv_new_setup.php:223
$io
Определения csv_new_run.php:98
const BX_AJAX_PARAM_ID(!defined('TAGGED_user_card_size'))
Определения constants.php:99
const SITE_DIR(!defined('LANG'))
Определения include.php:72
const FORMAT_DATETIME
Определения include.php:64
if(!defined('SITE_ID')) $lang
Определения include.php:91
$culture
Определения include.php:61
$arOptions
Определения structure.php:223
if(!defined('NOT_CHECK_PERMISSIONS')) $NS
Определения backup.php:24
CheckSerializedData($str, $max_depth=200)
Определения tools.php:4949
CheckDirPath($path)
Определения tools.php:2707
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
ParseDateTime($datetime, $format=false)
Определения tools.php:638
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
is_set($a, $k=false)
Определения tools.php:2133
$name
Определения menu_edit.php:35
$value
Определения Param.php:39
Определения Color.php:9
Определения chain.php:3
Определения collection.php:2
$order
Определения payment.php:8
$sign
Определения payment.php:69
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
const ADMIN_SECTION
Определения rss.php:2
$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
$width
Определения html.php:68
$props
Определения template.php:269
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
else $a
Определения template.php:137
$val
Определения options.php:1793
$engine
Определения options.php:121
$arRes
Определения options.php:104
$site_id
Определения sonet_set_content_view.php:9
$error
Определения subscription_card_product.php:20
$rs
Определения action.php:82
$action
Определения file_dialog.php:21
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$iterator
Определения yandex_run.php:610
$fields
Определения yandex_run.php:501
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644