1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
admin_ui_list.php
См. документацию.
1<?php
2
16
18{
19 public $enableNextPage = false;
20 public $totalRowCount = 0;
21
22 protected $filterPresets = array();
23 protected $currentPreset = array();
24
25 private $isShownContext = false;
26 private $contextSettings = array();
27
29 public $context = false;
30
31 public function AddHeaders($aParams)
32 {
33 parent::AddHeaders($aParams);
35 }
36
37 public function SetVisibleHeaderColumn()
38 {
39 $gridOptions = new Grid\Options($this->table_id);
40 $gridColumns = $gridOptions->GetVisibleColumns();
41 if ($gridColumns)
42 {
43 $this->arVisibleColumns = array();
44 $this->aVisibleHeaders = array();
45 foreach ($gridColumns as $columnId)
46 {
47 if (isset($this->aHeaders[$columnId]) && !isset($this->aVisibleHeaders[$columnId]))
48 {
49 $this->arVisibleColumns[] = $columnId;
50 $this->aVisibleHeaders[$columnId] = $this->aHeaders[$columnId];
51 }
52 }
53 }
54 }
55
61 public function getPageNavigation($navigationId)
62 {
63 $pageNum = 1;
64
66 && !($this->request->get('clear_nav') === 'Y')
67 && isset($this->session['ADMIN_PAGINATION_DATA'][$this->table_id])
68 )
69 {
70 $paginationData = $this->session['ADMIN_PAGINATION_DATA'][$this->table_id];
71 if (isset($paginationData['PAGE_NUM']))
72 {
73 $pageNum = (int)$paginationData['PAGE_NUM'];
74 }
75 }
76
77 $nav = new PageNavigation($navigationId);
78 $nav->setPageSize($this->getNavSize());
79 $nav->setCurrentPage($pageNum);
80 $nav->initFromUri();
81
83 {
84 if (!isset($this->session['ADMIN_PAGINATION_DATA']))
85 {
86 $this->session['ADMIN_PAGINATION_DATA'] = [];
87 }
88 $this->session['ADMIN_PAGINATION_DATA'][$this->table_id] = ['PAGE_NUM' => $nav->getCurrentPage()];
89 }
90
91 return $nav;
92 }
93
94 public function isTotalCountRequest()
95 {
96 $request = Bitrix\Main\Context::getCurrent()->getRequest();
97 if ($request->isAjaxRequest() && $request->get("action") == "getTotalCount")
98 {
99 return true;
100 }
101 return false;
102 }
103
105 {
106 global $adminAjaxHelper;
107 if (!is_object($adminAjaxHelper))
108 {
109 require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/admin_lib.php");
111 }
112
113 $adminAjaxHelper->sendJsonResponse(["totalCountHtml" => GetMessage("admin_lib_list_all_title").": ".(int) $totalCount]);
114 }
115
116 public function SetNavigationParams(\CAdminUiResult $queryObject, $params = array())
117 {
118 if ($this->isPublicMode)
119 {
120 unset($params["BASE_LINK"]);
121 }
122 $queryObject->setNavigationParams($params);
123 $this->NavText($queryObject->GetNavPrint(""));
124 $this->totalRowCount = $queryObject->NavRecordCount;
125 $this->enableNextPage = $queryObject->PAGEN < $queryObject->NavPageCount;
126 }
127
128 public function setNavigation(\Bitrix\Main\UI\PageNavigation $nav, $title, $showAllways = true, $post = false)
129 {
130 global $APPLICATION;
131
132 $this->totalRowCount = $nav->getRecordCount();
133 $this->enableNextPage = $nav->getCurrentPage() < $nav->getPageCount();
134
135 ob_start();
136
137 $APPLICATION->IncludeComponent(
138 "bitrix:main.pagenavigation",
139 "grid",
140 array(
141 "NAV_OBJECT" => $nav,
142 "TITLE" => $title,
143 "SHOW_ALWAYS" => $showAllways,
144 "POST" => $post,
145 "TABLE_ID" => $this->table_id,
146 ),
147 false,
148 array(
149 "HIDE_ICONS" => "Y",
150 )
151 );
152
153 $this->NavText(ob_get_clean());
154 }
155
156 public function getCurPageParam($strParam="", $arParamKill=array(), $get_index_page=null)
157 {
158 global $APPLICATION;
159
161 {
162 $arParamKill = array_merge($arParamKill, array("internal", "grid_id", "grid_action", "bxajaxid", "sessid"));
163 }
164
165 return $APPLICATION->GetCurPageParam($strParam, $arParamKill, $get_index_page);
166 }
167
168 public function getNavSize()
169 {
170 $gridOptions = new Grid\Options($this->table_id);
171 $navParams = $gridOptions->getNavParams();
172 return $navParams["nPageSize"];
173 }
174
175 public function EditAction()
176 {
177 if(
178 $_SERVER["REQUEST_METHOD"] == "POST" &&
179 !empty($_REQUEST["action_button_".$this->table_id]) &&
180 isset($_POST["FIELDS"]) &&
181 is_array($_POST["FIELDS"]) &&
183 )
184 {
185 $arrays = array(&$_POST, &$_REQUEST);
186 foreach ($arrays as $i => &$array)
187 {
188 $customFields = [];
189 foreach ($array["FIELDS"] as $id => &$fields)
190 {
191 if (is_array($fields))
192 {
193 $keys = array_keys($fields);
194 foreach ($keys as $key)
195 {
196 if (preg_match("/_custom/i", $key, $match))
197 {
198 if (!is_array($arrays[$i]["FIELDS"][$id][$key]))
199 {
200 continue;
201 }
202 foreach ($arrays[$i]["FIELDS"][$id][$key] as $value)
203 {
204 if (!isset($value["name"]) || !isset($value["value"]))
205 {
206 continue;
207 }
208 if (preg_match_all("/(.*?)\[(.*?)\]/", $value["name"], $listMatchKeys))
209 {
210 $listPreparedKeys = [];
211 foreach ($listMatchKeys as $matchKeys)
212 {
213 foreach ($matchKeys as $matchKey)
214 {
215 if (!is_string($matchKey) || trim($matchKey) == '')
216 {
217 continue;
218 }
219 if (!str_contains($matchKey, "[") && !str_contains($matchKey, "]"))
220 {
221 $listPreparedKeys[] = $matchKey;
222 }
223 }
224 }
225 $listPreparedKeys[] = $value["value"];
226 $customFields = array_replace_recursive($customFields, $this->prepareCustomKey(
227 array_shift($listPreparedKeys), $listPreparedKeys));
228 }
229 }
230 unset($arrays[$i]["FIELDS"][$id][$key]);
231 }
232
233 if(($c = substr($key, 0, 1)) == '~' || $c == '=')
234 {
235 unset($arrays[$i]["FIELDS"][$id][$key]);
236 }
237 }
238 }
239 }
240 if ($customFields)
241 {
242 $arrays[$i] = array_replace_recursive($arrays[$i], $customFields);
243 }
244 }
245 return true;
246 }
247 return false;
248 }
249
250 private function prepareCustomKey($key, array $keys)
251 {
252 return (count($keys) == 1 ? [$key => array_shift($keys)] :
253 [$key => $this->prepareCustomKey(array_shift($keys), $keys)]);
254 }
255
259 public function GroupAction()
260 {
261 $this->PrepareAction();
262
263 if ($this->GetAction() === null)
264 {
265 return false;
266 }
267
268 if (!check_bitrix_sessid())
269 {
270 return false;
271 }
272
273 if (!empty($_REQUEST["bxajaxid"]))
274 {
276 $adminSidePanelHelper->setSkipResponse(true);
277 }
278
279 if (!$this->IsGroupActionToAll())
280 {
281 $arID = $this->GetGroupIds();
282 if ($arID === null)
283 {
284 $arID = false;
285 }
286 }
287 else
288 {
289 $arID = array("");
290 }
291
292 return $arID;
293 }
294
300 public function IsGroupActionToAll()
301 {
302 return (
303 isset($_REQUEST["action_all_rows_".$this->table_id])
304 && $_REQUEST["action_all_rows_".$this->table_id] === 'Y'
305 );
306 }
307
311 protected function PrepareAction()
312 {
313 if (isset($_REQUEST["action"]) && is_array($_REQUEST["action"]))
314 {
315 foreach ($_REQUEST["action"] as $actionKey => $actionValue)
316 $_REQUEST[$actionKey] = $actionValue;
317 }
318 if (!empty($_REQUEST["action_button_".$this->table_id]))
319 {
320 $_REQUEST["action"] = $_REQUEST["action_button_".$this->table_id];
321 $_REQUEST["action_button"] = $_REQUEST["action_button_".$this->table_id];
322 }
323 }
324
325 public function ActionDoGroup($id, $action_id, $add_params = "")
326 {
327 $listParams = explode("&", $add_params);
328 $addParams = array();
329 if ($listParams)
330 {
331 foreach($listParams as $param)
332 {
333 $explode = explode("=", $param);
334 if ($explode[0] && $explode[1])
335 {
336 $addParams[$explode[0]] = $explode[1];
337 }
338 }
339 }
340
341 $postParams = array_merge(array(
342 "action_button_".$this->table_id => $action_id,
343 "ID" => $id
344 ), $addParams);
345
346 return $this->ActionAjaxPostGrid($postParams);
347 }
348
350 {
351 return "BX.Main.gridManager.getById('".$this->table_id."').instance.reloadTable('POST', ".
352 CUtil::PhpToJsObject($postParams).");";
353 }
354
356 {
357 $filterOption = new Filter\Options($this->table_id);
358 $filterData = $filterOption->getFilter($filterFields);
359 $filterable = array();
360 $quickSearchKey = "";
361 foreach ($filterFields as $filterField)
362 {
363 if (isset($filterField["quickSearch"]))
364 {
365 $quickSearchKey = $filterField["quickSearch"].$filterField["id"];
366 }
367 $filterable[$filterField["id"]] = $filterField["filterable"] ?? null;
368 }
369
370 foreach ($filterData as $fieldId => $fieldValue)
371 {
372 if ((is_array($fieldValue) && empty($fieldValue)) || (is_string($fieldValue) && $fieldValue == ''))
373 {
374 continue;
375 }
376
377 if (str_ends_with($fieldId, "_from"))
378 {
379 $realFieldId = mb_substr($fieldId, 0, mb_strlen($fieldId) - 5);
380 if (!array_key_exists($realFieldId, $filterable))
381 {
382 continue;
383 }
384 if (str_ends_with($realFieldId, "_1"))
385 {
386 $arFilter[$realFieldId] = $fieldValue;
387 }
388 else
389 {
390 if (!empty($filterData[$realFieldId."_numsel"]) && $filterData[$realFieldId."_numsel"] == "more")
391 $filterPrefix = ">";
392 else
393 $filterPrefix = ">=";
394 $arFilter[$filterPrefix.$realFieldId] = trim($fieldValue);
395 }
396 }
397 elseif (str_ends_with($fieldId, "_to"))
398 {
399 $realFieldId = mb_substr($fieldId, 0, mb_strlen($fieldId) - 3);
400 if (!array_key_exists($realFieldId, $filterable))
401 {
402 continue;
403 }
404 if (str_ends_with($realFieldId, "_1"))
405 {
406 $realFieldId = mb_substr($realFieldId, 0, mb_strlen($realFieldId) - 2);
407 $arFilter[$realFieldId."_2"] = $fieldValue;
408 }
409 else
410 {
411 if (!empty($filterData[$realFieldId."_numsel"]) && $filterData[$realFieldId."_numsel"] == "less")
412 $filterPrefix = "<";
413 else
414 $filterPrefix = "<=";
415 $arFilter[$filterPrefix.$realFieldId] = trim($fieldValue);
416 }
417 }
418 else
419 {
420 if (array_key_exists($fieldId, $filterable))
421 {
422 $filterPrefix = $filterable[$fieldId];
423 $arFilter[$filterPrefix.$fieldId] = $fieldValue;
424 }
425 if ($fieldId == "FIND" && trim($fieldValue) && $quickSearchKey)
426 {
427 $arFilter[$quickSearchKey] = $fieldValue;
428 }
429 }
430 }
431 }
432
433 public function hasGroupErrors()
434 {
435 return (bool)(count($this->arGroupErrors));
436 }
437
438 public function getGroupErrors()
439 {
440 $error = "";
441 foreach ($this->arGroupErrors as $groupError)
442 {
443 $error .= " ".$groupError[0];
444 }
445
446 return trim($error);
447 }
448
450 {
451 $this->contextSettings = $settings;
452 }
453
454 protected function GetSystemContextMenu(array $config = []): array
455 {
456 $result = [];
458 global $APPLICATION;
459
460 if (isset($config['excel']))
461 {
462 if (!empty($this->contextSettings["pagePath"]))
463 {
464 $pagePath = $this->contextSettings['pagePath'];
465 $queryString = DeleteParam([self::MODE_FIELD_NAME]);
466 if ($queryString !== '')
467 {
468 $pagePath .= (!str_contains($pagePath, '?') ? '?' : '&') . $queryString;
469 }
470 $pageParams = static::getModeExportParam();
471 if ($this->isPublicMode)
472 $pageParams["public"] = "y";
473 $uri = (new Uri($pagePath))->addParams($pageParams);
474 }
475 else
476 {
477 $uri = (new Uri($APPLICATION->GetCurPageParam()))->addParams(static::getModeExportParam());
478 }
479 $link = $uri->deleteParams(["apply_filter"])->getUri();
480 $result[] = [
481 "TEXT" => "Excel",
482 "TITLE" => GetMessage("admin_lib_excel"),
483 "LINK" => $link,
484 "GLOBAL_ICON"=>"adm-menu-excel",
485 ];
486 }
487 return $result;
488 }
489
490 protected function InitContextMenu(array $menu = [], array $additional = []): void
491 {
492 if (!empty($menu) || !empty($additional))
493 {
494 $this->context = new CAdminUiContextMenu($menu, $additional);
495 }
496 }
497
498 private function GetGroupAction()
499 {
500 $actionPanelConstructor = new CAdminUiListActionPanel(
501 $this->table_id, $this->arActions, $this->arActionsParams);
502
503 return $actionPanelConstructor->getActionPanel();
504 }
505
506 public function &AddRow($id = false, $arRes = Array(), $link = false, $title = false)
507 {
508 $row = new CAdminUiListRow($this->aHeaders, $this->table_id);
509 $row->id = ($id ?: Security\Random::getString(4));
510 $row->arRes = $arRes;
512 if ($publicMode)
513 {
514 $selfFolderUrl = (defined("SELF_FOLDER_URL") ? SELF_FOLDER_URL : "/bitrix/admin/");
515 $reqValue = "/".str_replace("/", "\/", $selfFolderUrl)."/i";
516 if (!empty($link) && !preg_match($reqValue, $link) && preg_match("/\.php/i", $link))
517 {
518 $link = $selfFolderUrl.$link;
519 }
520 }
521 $row->link = $link;
522 $row->title = $title;
523 $row->pList = &$this;
524 $row->bEditMode = true;
525 $row->setPublicModeState($publicMode);
526
527 $this->aRows[] = &$row;
528 return $row;
529 }
530
537 {
538 $filterOptions = new Filter\Options($this->table_id);
539 $filterOptions->setFilterSettings(
540 "default_filter",
541 array("rows" => $fields),
542 false
543 );
544 $filterOptions->save();
545 }
546
553 {
554 $this->filterPresets = $filterPresets;
555 foreach ($filterPresets as $filterPreset)
556 {
557 if (!empty($filterPreset["current"]))
558 {
559 $this->currentPreset = $filterPreset;
560 }
561 }
562 }
563
564 public function deletePreset($presetId)
565 {
566 $options = new Filter\Options($this->table_id);
567 $options->deleteFilter($presetId);
568 $options->save();
569 }
570
571 public function DisplayFilter(array $filterFields = [], array $filterParams = [])
572 {
573 global $APPLICATION;
574
575 $filterFields = $this->getPreparedFilterFields($filterFields);
576
577 $filterParams = array_merge(
578 $filterParams,
579 [
580 "FILTER_ID" => $this->table_id,
581 "GRID_ID" => $this->table_id,
582 "FILTER" => $filterFields,
583 "FILTER_PRESETS" => $this->filterPresets,
584 "ENABLE_LABEL" => true,
585 "ENABLE_LIVE_SEARCH" => true,
586 ]
587 );
588
589 if ($this->currentPreset)
590 {
591 $options = new Filter\Options($this->table_id, $this->filterPresets);
592 $options->setFilterSettings($this->currentPreset["id"] ?? '', $this->currentPreset, true, false);
593 $options->save();
594 }
595
596 if ($this->context)
597 {
598 $this->context->setFilterContextParam(true);
599 }
600
601 if ($this->getPublicModeState())
602 {
603 \Bitrix\UI\Toolbar\Facade\Toolbar::addFilter($filterParams);
604 }
605 else
606 {
607 \Bitrix\Main\UI\Extension::load('ui.fonts.opensans');
608 $APPLICATION->SetAdditionalCSS('/bitrix/css/main/grid/webform-button.css');
609 \Bitrix\UI\Toolbar\Facade\Toolbar::addFilter($filterParams);
610 \Bitrix\UI\Toolbar\Facade\Toolbar::hideTitle();
611 $APPLICATION->IncludeComponent('bitrix:ui.toolbar', 'admin');
612 $this->ShowContext();
613 }
614
615 $this->createFilterSelectorHandlers($filterFields);
616
617 ?>
618 <script>
619 BX.ready(function () {
620 if (!window['filter_<?=$this->table_id?>'] ||
621 !BX.is_subclass_of(window['filter_<?=$this->table_id?>'], BX.adminUiFilter))
622 {
623 window['filter_<?=$this->table_id?>'] = new BX.adminUiFilter('<?=$this->table_id?>', []);
624 }
625 });
626 </script>
627 <?
628 }
629
630 private static function checkFilterField($field): bool
631 {
632 return !(empty($field) || !is_array($field));
633 }
634
635 private function getPreparedFilterFields(array $filterFields): array
636 {
637 $filterFields = array_filter(
639 [__CLASS__, 'checkFilterField']
640 );
641
642 if (
643 !$this->getPublicModeState()
644 || empty($filterFields)
645 )
646 {
647 return $filterFields;
648 }
649
650 foreach ($filterFields as $index => $row)
651 {
652 if (!isset($row['type']) || $row['type'] !== Filter\FieldAdapter::CUSTOM_ENTITY)
653 {
654 continue;
655 }
656 if (isset($row['selector']) && isset($row['selector']['type']))
657 {
658 if ($row['selector']['type'] === 'user')
659 {
660 $row['type'] = Filter\FieldAdapter::DEST_SELECTOR;
661 unset($row['selector']);
662
663 $row['params'] = [
664 'context' => 'SHOP_USER',
665 'multiple' => 'N',
666 'contextCode' => 'U',
667 'enableAll' => 'N',
668 'enableSonetgroups' => 'N',
669 'allowEmailInvitation' => 'N',
670 'allowSearchEmailUsers' => 'N',
671 'departmentSelectDisable' => 'Y',
672 'isNumeric' => 'Y',
673 'prefix' => 'U',
674 ];
675
676 $filterFields[$index] = $row;
677 }
678 }
679 }
680
681 return $filterFields;
682 }
683
684 private function createFilterSelectorHandlers(array $filterFields = array())
685 {
686 $selfFolderUrl = (defined("SELF_FOLDER_URL") ? SELF_FOLDER_URL : "/bitrix/admin/");
687 foreach ($filterFields as $filterField)
688 {
689 if (isset($filterField["type"]) && $filterField["type"] !== Filter\FieldAdapter::CUSTOM_ENTITY)
690 {
691 continue;
692 }
693
694 if (isset($filterField["selector"]) && isset($filterField["selector"]["type"]))
695 {
696 switch ($filterField["selector"]["type"])
697 {
698 case "user":
699 ?>
700 <script>
701 BX.ready(function() {
702 if (!window["userFilterHandler_<?=$filterField["id"]?>"])
703 {
704 var params = {
705 filterId: "<?=$this->table_id?>",
706 fieldId: "<?=$filterField["id"]?>",
707 languageId: "<?=LANGUAGE_ID?>",
708 selfFolderUrl: "<?=$selfFolderUrl?>"
709 };
710 window["userFilterHandler_<?=$filterField["id"]?>"] =
711 new BX.adminUserFilterHandler(params);
712 }
713 });
714 if (typeof(SUVsetUserId_<?=$filterField["id"]?>) === "undefined")
715 {
716 function SUVsetUserId_<?=$filterField["id"]?>(userId)
717 {
718 if (window["userFilterHandler_<?=$filterField["id"]?>"])
719 {
720 var adminUserFilterHandler = window["userFilterHandler_<?=$filterField["id"]?>"];
721 adminUserFilterHandler.setSelected(userId);
722 }
723 }
724 }
725 </script>
726 <?
727 break;
728 case "product":
729 ?>
730 <script>
731 BX.ready(function() {
732 if (!window["productFilterHandler_<?=$filterField["id"]?>"])
733 {
734 var params = {
735 filterId: "<?=$this->table_id?>",
736 fieldId: "<?=$filterField["id"]?>",
737 languageId: "<?=LANGUAGE_ID?>",
738 publicMode: "<?=($this->isPublicMode ? "Y" : "N")?>",
739 selfFolderUrl: "<?=$selfFolderUrl?>"
740 };
741 window["productFilterHandler_<?=$filterField["id"]?>"] =
742 new BX.adminProductFilterHandler(params);
743 }
744 });
745 if (typeof(FillProductFields_<?=$filterField["id"]?>) === "undefined")
746 {
747 function FillProductFields_<?=$filterField["id"]?>(product)
748 {
749 if (window["productFilterHandler_<?=$filterField["id"]?>"])
750 {
751 var adminProductFilterHandler =
752 window["productFilterHandler_<?=$filterField["id"]?>"];
753 adminProductFilterHandler.closeProductSearchDialog();
754 adminProductFilterHandler.setSelected(product["id"], product["name"]);
755 }
756 }
757 }
758 </script>
759 <?
760 break;
761 }
762 }
763 }
764 }
765
766 public function ShowActionTable() {}
767
768 public function DisplayList($arParams = array())
769 {
770 $arParams = array_change_key_case($arParams, CASE_UPPER);
771
772 foreach(GetModuleEvents("main", "OnAdminListDisplay", true) as $arEvent)
773 ExecuteModuleEventEx($arEvent, array(&$this));
774
775 // Check after event handlers
776 if (!is_array($this->arActions))
777 {
778 $this->arActions = [];
779 }
780 if (!is_array($this->arActionsParams))
781 {
782 $this->arActionsParams = [];
783 }
784
785 $errorMessages = [];
786 foreach ($this->arFilterErrors as $error)
787 {
788 $errorMessages[] = [
789 'TYPE' => Bitrix\Main\Grid\MessageType::ERROR,
790 'TEXT' => $error,
791 ];
792 }
793 foreach ($this->arUpdateErrors as $arError)
794 {
795 $errorMessages[] = [
796 'TYPE' => Bitrix\Main\Grid\MessageType::ERROR,
797 'TEXT' => $arError[0],
798 ];
799 }
800 foreach ($this->arGroupErrors as $arError)
801 {
802 $errorMessages[] = [
803 'TYPE' => Bitrix\Main\Grid\MessageType::ERROR,
804 'TEXT' => $arError[0],
805 ];
806 }
807
808 if (Context::isValidateRequest())
809 {
810 global $adminAjaxHelper;
811 if (!is_object($adminAjaxHelper))
812 {
813 require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/admin_lib.php");
814 $adminAjaxHelper = new CAdminAjaxHelper();
815 }
816 global $APPLICATION;
817 $APPLICATION->RestartBuffer();
818 if (!empty($errorMessages))
819 {
820 $adminAjaxHelper->sendJsonResponse(["messages" => $errorMessages]);
821 }
822 else
823 {
824 $adminAjaxHelper->sendJsonResponse(array("messages" => array()));
825 }
826 }
827
828 if (Context::isShowpageRequest() && !empty($errorMessages))
829 {
830 global $adminAjaxHelper;
831 if (!is_object($adminAjaxHelper))
832 {
833 require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/admin_lib.php");
834 $adminAjaxHelper = new CAdminAjaxHelper();
835 }
836 global $APPLICATION;
837 $APPLICATION->RestartBuffer();
838
839 $adminAjaxHelper->sendJsonResponse(["messages" => $errorMessages]);
840 }
841
842 global $APPLICATION;
843 \Bitrix\Main\UI\Extension::load('ui.fonts.opensans');
844 $APPLICATION->SetAdditionalCSS('/bitrix/css/main/grid/webform-button.css');
845
847
848 $selfFolderUrl = (defined("SELF_FOLDER_URL") ? SELF_FOLDER_URL : "/bitrix/admin/");
849
850 $this->ShowContext();
851
852 $gridParameters = array(
853 "GRID_ID" => $this->table_id,
854 "AJAX_MODE" => "Y",
855 "AJAX_OPTION_JUMP" => "N",
856 "AJAX_OPTION_HISTORY" => "N",
857 "SHOW_PAGESIZE" => true,
858 "AJAX_ID" => CAjax::getComponentID("bitrix:main.ui.grid", ".default", ""),
859 "ALLOW_PIN_HEADER" => true,
860 "ALLOW_VALIDATE" => false,
861 "HANDLE_RESPONSE_ERRORS" => true,
862 'USE_CHECKBOX_LIST_FOR_SETTINGS_POPUP' => $arParams['USE_CHECKBOX_LIST_FOR_SETTINGS_POPUP'] ?? false,
863 'ENABLE_FIELDS_SEARCH' => $arParams['ENABLE_FIELDS_SEARCH'] ?? 'N',
864 );
865
866 $actionPanel = ($arParams["ACTION_PANEL"] ?? $this->GetGroupAction());
867 if ($actionPanel)
868 {
869 $gridParameters["ACTION_PANEL"] = $actionPanel;
870 }
871 else
872 {
873 $gridParameters["SHOW_CHECK_ALL_CHECKBOXES"] = false;
874 $gridParameters["SHOW_ROW_CHECKBOXES"] = false;
875 $gridParameters["SHOW_SELECTED_COUNTER"] = false;
876 $gridParameters["SHOW_ACTION_PANEL"] = false;
877 }
878
879 if (isset($arParams["SHOW_TOTAL_COUNTER"]))
880 {
881 $gridParameters["SHOW_TOTAL_COUNTER"] = $arParams["SHOW_TOTAL_COUNTER"];
882 }
883
884 $showTotalCountHtml = (isset($arParams["SHOW_COUNT_HTML"]) && $arParams["SHOW_COUNT_HTML"] === true);
885 if ($showTotalCountHtml)
886 {
887 $gridParameters["TOTAL_ROWS_COUNT_HTML"] = $this->getTotalRowsCountHtml();
888 }
889
890 $gridOptions = new Grid\Options($gridParameters["GRID_ID"]);
891 $defaultSort = array();
892 if ($this->sort instanceof CAdminSorting)
893 {
894 $defaultSort = array("sort" => array($this->sort->getField() => $this->sort->getOrder()));
895 }
896 $sorting = $gridOptions->GetSorting($defaultSort);
897 $gridParameters["SORT"] = !isset($_GET[$sorting['vars']['by']]) || !isset($_GET[$sorting['vars']['order']]) ? $sorting["sort"] : $defaultSort['sort'];
898 $gridParameters["SORT_VARS"] = $sorting["vars"];
899 $gridColumns = $gridOptions->getVisibleColumns();
900 if (empty($gridColumns))
901 $gridColumns = array_keys($this->aVisibleHeaders);
902
903 $gridParameters["ENABLE_NEXT_PAGE"] = $this->enableNextPage;
904 $gridParameters["TOTAL_ROWS_COUNT"] = $this->totalRowCount;
905 if ($this->sNavText)
906 {
907 $gridParameters["NAV_STRING"] = $this->sNavText;
908 }
909 else
910 {
911 $gridParameters["SHOW_PAGINATION"] = false;
912 }
913
914 $gridParameters["PAGE_SIZES"] = array(
915 array("NAME" => "5", "VALUE" => "5"),
916 array("NAME" => "10", "VALUE" => "10"),
917 array("NAME" => "20", "VALUE" => "20"),
918 array("NAME" => "50", "VALUE" => "50"),
919 array("NAME" => "100", "VALUE" => "100"),
920 array("NAME" => "200", "VALUE" => "200"),
921 array("NAME" => "500", "VALUE" => "500")
922 );
923
924 $gridParameters["ROWS"] = array();
926 foreach ($this->aRows as $row)
927 {
928 $gridRow = array(
929 "id" => $row->id,
930 "actions" => $row->getPreparedActions()
931 );
932
933 $gridRow["default_action"] = array();
934 if ($row->title)
935 {
936 $gridRow["default_action"]["title"] = $row->title;
937 }
938 $defaultActionType = $row->getConfigValue(CAdminUiListRow::DEFAULT_ACTION_TYPE_FIELD);
939 switch ($defaultActionType)
940 {
942 $skipUrlModify = $row->getConfigValue(CAdminUiListRow::SKIP_URL_MODIFY_FIELD) === true
943 ? 'true'
944 : 'false'
945 ;
946 $gridRow["default_action"]["onclick"] = "BX.adminSidePanel.onOpenPage('".$row->link."', ".$skipUrlModify.");";
947 break;
949 $gridRow["default_action"]["href"] = htmlspecialcharsback($row->link);
950 break;
951 default:
952 if (isset($arParams["DEFAULT_ACTION"]) && $arParams["DEFAULT_ACTION"])
953 {
954 if ($this->isPublicMode)
955 {
956 if (!empty($row->link))
957 {
958 $row->link = str_replace("/bitrix/admin/", $selfFolderUrl, $row->link);
959 }
960 }
961 $gridRow["default_action"]["href"] = htmlspecialcharsback($row->link);
962 }
963 elseif ($row->link)
964 {
965 if ($this->isPublicMode)
966 {
967 $skipUrlModificationEnabled = ($arParams['SKIP_URL_MODIFICATION'] ?? false) === true;
968 $skipUrlModification = $skipUrlModificationEnabled && !str_contains($row->link, '/bitrix/admin/')
969 ? 'true'
970 : 'false';
971 $gridRow["default_action"]["onclick"] = "BX.adminSidePanel.onOpenPage('".$row->link."', ".$skipUrlModification.");";
972 }
973 else
974 {
975 $gridRow["default_action"]["href"] = htmlspecialcharsback($row->link);
976 }
977 }
978 else
979 {
980 $gridRow["default_action"]["onclick"] = "";
981 }
982 break;
983 }
984
985 foreach ($row->aFields as $fieldId => $field)
986 {
987 if (!empty($field["edit"]["type"]))
988 $this->SetHeaderEditType($fieldId, $field);
989 }
990
991 $listEditable = array();
992 foreach (array_diff_key($this->aHeaders, $row->aFields) as $fieldId => $field)
993 {
994 $listEditable[$fieldId] = false;
995 }
996
997 $disableEditColumns = array();
998
999 foreach ($gridColumns as $columnId)
1000 {
1001 $value = '';
1002 $field = [];
1003 if (isset($row->aFields[$columnId]))
1004 {
1005 $field = $row->aFields[$columnId];
1006 }
1007 if (isset($row->arRes[$columnId]))
1008 {
1009 if (!is_array($row->arRes[$columnId]))
1010 {
1011 $value = trim((string)$row->arRes[$columnId]);
1012 }
1013 else
1014 {
1015 $value = $row->arRes[$columnId];
1016 }
1017 }
1018
1019 $editValue = $value;
1020 if (isset($field["edit"]["type"]))
1021 {
1022 switch ($field["edit"]["type"])
1023 {
1024 case "file":
1025 if ($fileArray = CFile::getFileArray($value))
1026 $editValue = $fileArray["SRC"];
1027 break;
1028 case "html":
1029 $editValue = $field["edit"]["value"];
1030 break;
1031 case "money":
1032 $moneyAttributes = $field["edit"]["attributes"];
1033 $editValue = [
1034 'PRICE' => $moneyAttributes['PRICE'],
1035 'CURRENCY' => $moneyAttributes['CURRENCY'],
1036 'ATTRIBUTES' => $moneyAttributes['ATTRIBUTES'],
1037 ];
1038
1039 if (is_array($moneyAttributes['HIDDEN']))
1040 {
1041 $editValue['HIDDEN'] = [];
1042 foreach ($moneyAttributes['HIDDEN'] as $hiddenItem)
1043 {
1044 $editValue['HIDDEN'][$hiddenItem['NAME']] = $hiddenItem['VALUE'];
1045 }
1046 }
1047 break;
1048 }
1049 }
1050 else
1051 {
1052 $disableEditColumns[$columnId] = false;
1053 }
1054
1055 $gridRow["data"][$columnId] = $editValue;
1056
1057 if (isset($field["view"]["type"]))
1058 {
1059 switch ($field["view"]["type"])
1060 {
1061 case "checkbox":
1062 if ($value == "Y")
1063 $value = htmlspecialcharsex(GetMessage("admin_lib_list_yes"));
1064 else
1065 $value = htmlspecialcharsex(GetMessage("admin_lib_list_no"));
1066 break;
1067 case "select":
1068 if (isset($field["edit"]["values"][$value]))
1069 {
1070 $value = htmlspecialcharsex($field["edit"]["values"][$value]);
1071 }
1072 elseif (isset($field["view"]["values"][$value]))
1073 {
1074 $value = htmlspecialcharsex($field["view"]["values"][$value]);
1075 }
1076 break;
1077 case "file":
1078 $value = $value ? CFileInput::Show("fileInput_".$value, $value,
1079 $field["view"]["showInfo"], $field["view"]["inputs"]) : "";
1080 break;
1081 case "html":
1082 $value = $field["view"]["value"] ?? '';
1083 break;
1084 default:
1085 $value = htmlspecialcharsex($value);
1086 break;
1087 }
1088 }
1089 else
1090 {
1091 $value = htmlspecialcharsbx($value);
1092 }
1093
1094 $gridRow["columns"][$columnId] = $value;
1095 }
1096 $gridRow["editable"] = $listEditable;
1097 if (!empty($disableEditColumns))
1098 $gridRow["editableColumns"] = $disableEditColumns;
1099
1100 $gridParameters["ROWS"][] = $gridRow;
1101 }
1102
1103 $gridParameters["COLUMNS"] = array();
1104 foreach ($this->aHeaders as $header)
1105 {
1106 $header["name"] = $header["content"];
1107 $gridParameters["COLUMNS"][] = $header;
1108 }
1109
1110 if (!empty($errorMessages))
1111 {
1112 $gridParameters["MESSAGES"] = $errorMessages;
1113 }
1114
1115 $APPLICATION->includeComponent(
1116 "bitrix:main.ui.grid",
1117 "",
1118 $gridParameters,
1119 false, array("HIDE_ICONS" => "Y")
1120 );
1121
1123
1124 $jsParams = [];
1125 $jsParams["publicMode"] = $this->isPublicMode;
1126 $jsParams["showTotalCountHtml"] = $showTotalCountHtml;
1127 $jsParams["serviceUrl"] = ($arParams["SERVICE_URL"] ?? "");
1128
1129 ?>
1130 <script>
1131 if (!window['<?=$this->table_id?>'] || !BX.is_subclass_of(window['<?=$this->table_id?>'], BX.adminUiList))
1132 {
1133 window['<?=$this->table_id?>'] = new BX.adminUiList(
1134 '<?=$this->table_id?>', <?= Json::encode($jsParams) ?>);
1135 }
1136 BX.adminChain.addItems("<?=$this->table_id?>_navchain_div");
1137 </script>
1138 <?
1139 }
1140
1141 private function getTotalRowsCountHtml()
1142 {
1143 ob_start();
1144 ?>
1145 <div><?= GetMessage("admin_lib_list_all_title").": " ?>
1146 <a id="<?=$this->table_id?>_show_total_count" href="#"><?= GetMessage("admin_lib_list_show_row_count_title")?></a>
1147 </div>
1148 <?
1149 return ob_get_clean();
1150 }
1151
1152 private function ShowContext()
1153 {
1154 if ($this->context && !$this->isShownContext)
1155 {
1156 $this->isShownContext = true;
1157 $this->context->Show();
1158 }
1159 }
1160
1161 private function SetHeaderEditType($headerId, $field)
1162 {
1163 if (!isset($this->aHeaders[$headerId]))
1164 {
1165 return;
1166 }
1167
1168 if (isset($this->aHeaders[$headerId]["editable"]) && $this->aHeaders[$headerId]["editable"] === false)
1169 {
1170 return;
1171 }
1172
1173 // TODO: use \Bitrix\Main\Grid\Column\Type::getEditorType
1174 switch ($field["edit"]["type"])
1175 {
1176 case "input":
1177 $editable = array("TYPE" => Types::TEXT);
1178 break;
1179 case "calendar":
1180 $editable = array("TYPE" => Types::DATE);
1181 break;
1182 case "checkbox":
1183 $editable = array("TYPE" => Types::CHECKBOX);
1184 break;
1185 case "select":
1186 $editable = array(
1187 "TYPE" => Types::DROPDOWN,
1188 "items" => $field["edit"]["values"]
1189 );
1190 break;
1191 case "file":
1192 $editable = array(
1193 "TYPE" => Types::IMAGE,
1194 );
1195 break;
1196 case "html":
1197 $editable = array("TYPE" => Types::CUSTOM);
1198 break;
1199 case "money":
1200 $editable = array(
1201 "TYPE" => Types::MONEY,
1202 "CURRENCY_LIST" => $field["edit"]["attributes"]["CURRENCY_LIST"],
1203 "HTML_ENTITY" => $field["edit"]["attributes"]["HTML_ENTITY"] ?? false,
1204 );
1205 break;
1206 default:
1207 $editable = array("TYPE" => Types::TEXT);
1208 }
1209
1210 $this->aHeaders[$headerId]["editable"] = $editable;
1211 }
1212}
1213
1254{
1255 private $tableId;
1256 private $inputActions;
1257 private $inputActionsParams;
1258
1262 private $gridSnippets;
1263
1264 private $actionSections = [];
1265 private $mapTypesAndSections = [
1266 "edit" => "default",
1267 "delete" => "default",
1268 "button" => "button",
1269 "select" => "list",
1270 "customjs" => "list",
1271 "html" => "html",
1272 "for_all" => "forAll"
1273 ];
1274 private $mapTypesAndHandlers = [];
1275
1276 public function __construct($tableId, array $actions, array $actionsParams)
1277 {
1278 $this->tableId = $tableId;
1279 $this->inputActions = $actions;
1280 $this->inputActionsParams = $actionsParams;
1281
1282 $this->gridSnippets = new Panel\Snippet();
1283
1284 $this->actionSections = [
1285 "default" => [],
1286 "button" => [],
1287 "list" => [
1288 "TYPE" => Panel\Types::DROPDOWN,
1289 "ID" => "base_action_select_{$this->tableId}",
1290 "NAME" => "action_button_{$this->tableId}",
1291 "ITEMS" => [
1292 [
1293 "NAME" => GetMessage("admin_lib_list_actions"),
1294 "VALUE" => "default",
1295 "ONCHANGE" => [["ACTION" => Panel\Actions::RESET_CONTROLS]]
1296 ]
1297 ]
1298 ],
1299 "html" => [],
1300 "forAll" => []
1301 ];
1302 }
1303
1308 public function getActionPanel()
1309 {
1310 $actionPanel = [];
1311
1312 $items = $this->getItems();
1313
1314 $actionPanel["GROUPS"][] = array("ITEMS" => $items);
1315
1316 return $actionPanel;
1317 }
1318
1344 public function setActionSections(array $actionSections, $listKeyForDelete = [])
1345 {
1346 foreach ($listKeyForDelete as $keyForDelete)
1347 {
1348 if (isset($this->actionSections[$keyForDelete]))
1349 {
1350 unset($this->actionSections[$keyForDelete]);
1351 }
1352 }
1353
1354 $this->actionSections = array_merge($this->actionSections, $actionSections);
1355 }
1356
1362 public function setTypeToSectionMap(array $mapTypesAndSections)
1363 {
1364 $this->mapTypesAndSections = array_merge($this->mapTypesAndSections, $mapTypesAndSections);
1365 }
1366
1393 public function setHandlerToType(array $mapTypesAndHandlers)
1394 {
1395 $this->mapTypesAndHandlers = array_merge($this->mapTypesAndHandlers, $mapTypesAndHandlers);
1396 }
1397
1401 private function getDefaultApplyAction()
1402 {
1403 return ["JS" => "BX.adminUiList.SendSelected('{$this->tableId}')"];
1404 }
1405
1409 private function getItems()
1410 {
1411 $items = [];
1412
1413 $actionSections = $this->getActionSections();
1414
1415 foreach ($actionSections as $actionSection)
1416 {
1417 if ($this->isAssociativeArray($actionSection))
1418 {
1419 $items[] = $actionSection;
1420 }
1421 else
1422 {
1423 foreach ($actionSection as $aSection)
1424 {
1425 $items[] = $aSection;
1426 }
1427 }
1428 }
1429
1430 return $items;
1431 }
1432
1436 private function getActionSections()
1437 {
1438 if (isset($this->inputActions["edit"]) && isset($this->actionSections[$this->mapTypesAndSections["edit"]]))
1439 {
1440 $this->actionSections[$this->mapTypesAndSections["edit"]][] = $this->gridSnippets->getEditButton();
1441 }
1442 if (isset($this->inputActions["delete"]) && isset($this->actionSections[$this->mapTypesAndSections["delete"]]))
1443 {
1444 $this->actionSections[$this->mapTypesAndSections["delete"]][] = $this->gridSnippets->getRemoveButton();
1445 }
1446
1447 foreach ($this->inputActions as $actionKey => $action)
1448 {
1449 $this->setActionSection($this->actionSections, $actionKey, $action);
1450 }
1451
1452 if (isset($this->inputActions["for_all"]) && isset($this->actionSections[$this->mapTypesAndSections["for_all"]]))
1453 {
1454 $this->actionSections[$this->mapTypesAndSections["for_all"]][] = $this->gridSnippets->getForAllCheckbox();
1455 }
1456
1457 if (count($this->actionSections["list"]["ITEMS"]) == 1)
1458 {
1459 $this->actionSections["list"] = [];
1460 }
1461
1462 return $this->actionSections;
1463 }
1464
1471 private function setActionSection(array &$actionSections, $actionKey, $action)
1472 {
1473 if (is_array($action))
1474 {
1475 self::prepareAction($action);
1476 $type = $action["type"];
1477 $actionSection = $this->mapTypesAndSections[$type] ?? "list";
1478
1479 $method = "get".$type."ActionData";
1480 if (isset($this->mapTypesAndHandlers[$type]) && is_callable($this->mapTypesAndHandlers[$type]))
1481 {
1482 $actionSections[$actionSection][] = $this->mapTypesAndHandlers[$type]($actionKey, $action);
1483 }
1484 elseif (method_exists(__CLASS__, $method))
1485 {
1486 if ($actionSection == "list")
1487 {
1488 $actionSections["list"]["ITEMS"][] = $this->$method($actionKey, $action);
1489 }
1490 else
1491 {
1492 $actionSections[$actionSection][] = $this->$method($actionKey, $action);
1493 }
1494 }
1495 }
1496 else
1497 {
1498 if (!in_array($actionKey, ["edit", "delete", "for_all"]))
1499 {
1500 $actionSections["list"]["ITEMS"][] = [
1501 "NAME" => $action,
1502 "VALUE" => $actionKey,
1503 "ONCHANGE" => [
1504 [
1505 "ACTION" => Panel\Actions::RESET_CONTROLS
1506 ],
1507 $this->getApplyButtonCreationAction()
1508 ]
1509 ];
1510 }
1511 }
1512 }
1513
1519 private function getButtonActionData($actionKey, $action)
1520 {
1521 $onChange = $action["action"] ? [
1522 ["ACTION" => Panel\Actions::CALLBACK, "DATA" => [["JS" => $action["action"]]]]] : [];
1523
1524 return [
1525 "ID" => $actionKey,
1526 "TYPE" => Bitrix\Main\Grid\Panel\Types::BUTTON,
1527 "TEXT" => $action["name"],
1528 "ONCHANGE" => $onChange
1529 ];
1530 }
1531
1537 private function getSelectActionData($actionKey, $action)
1538 {
1539 $internalOnchange = [];
1540 if (!empty($this->inputActionsParams["internal_select_onchange"]))
1541 {
1542 $internalOnchange[] = [
1543 "ACTION" => Panel\Actions::CALLBACK,
1544 "DATA" => [
1545 ["JS" => $this->inputActionsParams["internal_select_onchange"]]
1546 ]
1547 ];
1548 }
1549
1564 if (is_array($action["items"]))
1565 {
1566 foreach ($action["items"] as &$items)
1567 {
1568 if (empty($items["ONCHANGE"]))
1569 {
1570 $items["ONCHANGE"] = $internalOnchange;
1571 }
1572 else
1573 {
1574 $items["ONCHANGE"] = [
1575 [
1576 "ACTION" => Panel\Actions::CALLBACK,
1577 "DATA" => [
1578 ["JS" => $items["ONCHANGE"]]
1579 ]
1580 ]
1581 ];
1582 }
1583 }
1584 }
1585
1586 $onchange = [
1587 [
1588 "ACTION" => Panel\Actions::RESET_CONTROLS
1589 ],
1590 [
1591 "ACTION" => Panel\Actions::CREATE,
1592 "DATA" => [
1593 [
1594 "TYPE" => Panel\Types::DROPDOWN,
1595 "ID" => "selected_action_{$this->tableId}_".$action["controlId"],
1596 "NAME" => $action["controlName"],
1597 "ITEMS" => $action["items"]
1598 ],
1599 $this->gridSnippets->getApplyButton(
1600 [
1601 "ONCHANGE" => [
1602 [
1603 "ACTION" => Panel\Actions::CALLBACK,
1604 "DATA" => [
1605 $this->getDefaultApplyAction()
1606 ]
1607 ]
1608 ]
1609 ]
1610 )
1611 ]
1612 ]
1613 ];
1614
1615 if (!empty($this->inputActionsParams["select_onchange"]))
1616 {
1617 $onchange[] = [
1618 "ACTION" => Panel\Actions::CALLBACK,
1619 "DATA" => [
1620 ["JS" => $this->inputActionsParams["select_onchange"]]
1621 ]
1622 ];
1623 }
1624
1625 return [
1626 "NAME" => $action["name"],
1627 "VALUE" => $actionKey,
1628 "ONCHANGE" => $onchange
1629 ];
1630 }
1631
1637 private function getCustomJsActionData($actionKey, $action)
1638 {
1639 return [
1640 "NAME" => $action["name"],
1641 "VALUE" => $actionKey,
1642 "ONCHANGE" => [
1643 ["ACTION" => Panel\Actions::RESET_CONTROLS],
1644 $this->getApplyButtonCreationAction($action["js"])
1645 ]
1646 ];
1647 }
1648
1654 private function getBaseActionData($actionKey, $action)
1655 {
1656 return [
1657 "NAME" => $action["name"],
1658 "VALUE" => $actionKey,
1659 "ONCHANGE" => [
1660 ["ACTION" => Panel\Actions::RESET_CONTROLS],
1661 $this->getApplyButtonCreationAction($action["action"])
1662 ]
1663 ];
1664 }
1665
1671 private function getHtmlActionData($actionKey, $action)
1672 {
1673 return [
1674 "ID" => $actionKey,
1675 "TYPE" => Panel\Types::CUSTOM,
1676 "VALUE" => $action["value"]
1677 ];
1678 }
1679
1685 private function getMultiControlActionData($actionKey, array $action)
1686 {
1687 return [
1688 "NAME" => $action["name"],
1689 "VALUE" => $actionKey,
1690 "ONCHANGE" => $action["action"]
1691 ];
1692 }
1693
1698 private function getApplyButtonCreationAction($jsCallback = "")
1699 {
1700 $action = $this->getDefaultApplyAction();
1701 if ($jsCallback != '')
1702 {
1703 $action["JS"] = $jsCallback;
1704 }
1705 return [
1706 "ACTION" => Panel\Actions::CREATE,
1707 "DATA" => [
1708 $this->gridSnippets->getApplyButton(
1709 [
1710 "ONCHANGE" => [
1711 [
1712 "ACTION" => Panel\Actions::CALLBACK,
1713 "DATA" => [
1714 $action
1715 ]
1716 ]
1717 ]
1718 ]
1719 )
1720 ]
1721 ];
1722 }
1723
1728 private function isAssociativeArray($array)
1729 {
1730 if (!is_array($array) || empty($array))
1731 return false;
1732 return array_keys($array) !== range(0, count($array) - 1);
1733 }
1734
1741 private static function prepareAction(array &$action)
1742 {
1743 $action["type"] = (!empty($action["type"])? mb_strtolower($action["type"]) : "base");
1744 if ($action["type"] == "select")
1745 {
1746 if (!isset($action["controlName"]) && isset($action["name"]))
1747 {
1748 $action["controlName"] = $action["name"];
1749 unset($action["name"]);
1750 }
1751 if (!isset($action["controlId"]) && isset($action["controlName"]))
1752 {
1753 $action["controlId"] = $action["controlName"];
1754 }
1755 }
1756 if (!isset($action["name"]))
1757 {
1758 if (isset($action["lable"]))
1759 {
1760 $action["name"] = $action["lable"];
1761 unset($action["lable"]);
1762 }
1763 if (isset($action["label"]))
1764 {
1765 $action["name"] = $action["label"];
1766 unset($action["label"]);
1767 }
1768 }
1769 }
1770}
1771
1773{
1774 public const LINK_TYPE_URL = 'url';
1775 public const DEFAULT_ACTION_TYPE_FIELD = 'DEFAULT_ACTION_TYPE';
1776 public const SKIP_URL_MODIFY_FIELD = 'SKIP_URL_MODIFICATION';
1777 public const LINK_TYPE_SLIDER = 'slider';
1778
1782 public function getPreparedActions()
1783 {
1784 $result = [];
1785 foreach ($this->aActions as $action)
1786 {
1787 if (isset($action["SEPARATOR"]))
1788 continue;
1789
1790 if (empty($action["ACTION"]) && !empty($action["ONCLICK"]))
1791 {
1792 $action["ACTION"] = $action["ONCLICK"];
1793 }
1794
1795 if (!empty($action["LINK"]) && empty($action["ACTION"]))
1796 {
1797 $action["href"] = $action["LINK"];
1798 }
1799 else
1800 {
1801 if (preg_match("/BX.adminPanel.Redirect/", $action["ACTION"]))
1802 {
1803 $explode = explode("'", $action["ACTION"]);
1804 if (!empty($explode[1]))
1805 $action["href"] = $explode[1];
1806 }
1807 else
1808 {
1809 $action["ONCLICK"] = $action["ACTION"];
1810 }
1811 }
1812
1813 if ($this->isPublicMode)
1814 {
1815 if (!empty($action["href"]) &&
1816 !preg_match("/bitrix\/admin/i", $action["href"]) && preg_match("/\.php/i", $action["href"]))
1817 {
1818 $action["href"] = "/bitrix/admin/".$action["href"];
1819 }
1820 }
1821
1822 $result[] = $action;
1823 }
1824 unset($action);
1825
1826 return $result;
1827 }
1828}
1829
1831{
1832 protected static $navParams = [
1833 "totalCount" => 0,
1834 "totalPages" => 1,
1835 "pagen" => 1
1836 ];
1837
1838 private $componentParams = array();
1839
1845 public static function setNavParams($tableId, $className, &$getListParams)
1846 {
1847 if (isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "excel")
1848 {
1849 return;
1850 }
1851
1852 $navyParams = CAdminUiResult::getNavParams(CAdminUiResult::getNavSize($tableId));
1853 if ($navyParams["SHOW_ALL"])
1854 {
1855 return;
1856 }
1857 else
1858 {
1859 $navyParams["PAGEN"] = (int)$navyParams["PAGEN"];
1860 $navyParams["SIZEN"] = (int)$navyParams["SIZEN"];
1861 }
1862
1863 try
1864 {
1865 if (class_exists($className))
1866 {
1870 $countQuery = new Query($className::getEntity());
1871 $countQuery->addSelect(new ExpressionField("CNT", "COUNT(1)"));
1872 $countQuery->setFilter($getListParams["filter"]);
1873 $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
1874 unset($countQuery);
1875 $totalCount = (int)$totalCount["CNT"];
1876 $totalPages = 1;
1877
1878 $navyParams = CAdminUiResult::getNavParams(CAdminUiResult::getNavSize($tableId));
1879 if ($totalCount > 0)
1880 {
1881 $totalPages = ceil($totalCount/ $navyParams["SIZEN"]);
1882 if ($navyParams["PAGEN"] > $totalPages)
1883 {
1884 $navyParams["PAGEN"] = $totalPages;
1885 }
1886 }
1887 else
1888 {
1889 $navyParams["PAGEN"] = 1;
1890 }
1891
1892 self::$navParams["totalCount"] = $totalCount;
1893 self::$navParams["totalPages"] = $totalPages;
1894 self::$navParams["pagen"] = $navyParams["PAGEN"];
1895 }
1896 }
1897 catch (Exception $exception)
1898 {
1899 $getListParams["limit"] = $navyParams["SIZEN"];
1900 $getListParams["offset"] = $navyParams["SIZEN"] * ($navyParams["PAGEN"] - 1);
1901 }
1902
1903 $getListParams["limit"] = $navyParams["SIZEN"];
1904 $getListParams["offset"] = $navyParams["SIZEN"] * ($navyParams["PAGEN"] - 1);
1905 }
1906
1907 public function NavStart($nPageSize=20, $bShowAll=true, $iNumPage=false)
1908 {
1909 $nSize = $this->GetNavSize($this->table_id, $nPageSize);
1910
1911 if(!is_array($nPageSize))
1912 $nPageSize = array();
1913
1914 $nPageSize["nPageSize"] = $nSize;
1915 if (isset($_REQUEST["mode"]) && $_REQUEST["mode"] === "excel")
1916 {
1917 $nPageSize["NavShowAll"] = true;
1918 }
1919
1920 $this->nInitialSize = $nPageSize["nPageSize"];
1921
1922 $this->parentNavStart($nPageSize, $bShowAll, $iNumPage);
1923
1924 if ((!isset($_REQUEST["mode"]) || $_REQUEST["mode"] != "excel") && !empty(self::$navParams["totalCount"]))
1925 {
1926 $this->NavRecordCount = self::$navParams["totalCount"];
1927 $this->NavPageCount = self::$navParams["totalPages"];
1928 $this->NavPageNomer = self::$navParams["pagen"];
1929 }
1930 }
1931
1932 public function GetNavPrint($title, $show_allways=true, $StyleText="", $template_path=false, $arDeleteParam=false)
1933 {
1934 $componentObject = null;
1935 $this->bShowAll = false;
1936 return $this->getPageNavStringEx(
1937 $componentObject,
1938 "",
1939 "grid",
1940 false,
1941 null,
1942 $this->componentParams
1943 );
1944 }
1945
1946 public static function GetNavSize($table_id = false, $nPageSize = 20, $listUrl = '')
1947 {
1948 $gridOptions = new Grid\Options($table_id);
1949 $navParams = $gridOptions->getNavParams();
1950 return $navParams["nPageSize"];
1951 }
1952
1954 {
1955 $gridOptions = new Grid\Options($this->table_id);
1956 $this->componentParams = array_merge($params, $gridOptions->getNavParams());
1957 }
1958}
1959
1961{
1962 private $isShownFilterContext = false;
1963
1964 public function setFilterContextParam($bool)
1965 {
1966 $this->isShownFilterContext = $bool;
1967 }
1968
1969 public function Show()
1970 {
1971 foreach (GetModuleEvents("main", "OnAdminContextMenuShow", true) as $arEvent)
1972 {
1973 ExecuteModuleEventEx($arEvent, array(&$this->items, &$this->additional_items));
1974 }
1975
1976 if (empty($this->items) && empty($this->additional_items))
1977 {
1978 return;
1979 }
1980
1981 \Bitrix\Main\UI\Extension::load(["ui.buttons", "ui.buttons.icons"]);
1982
1983 if ($this->isPublicMode)
1984 {
1985 $this->showBaseButton(ButtonLocation::AFTER_TITLE);
1986 $this->showActionButton();
1987 }
1988 else
1989 {
1990 $this->showActionButton();
1991 $this->showBaseButton();
1992 if (!$this->isShownFilterContext)
1993 {
1994 global $APPLICATION;
1995 \Bitrix\UI\Toolbar\Facade\Toolbar::hideTitle();
1996 $APPLICATION->IncludeComponent('bitrix:ui.toolbar', 'admin');
1997 }
1998 }
1999 }
2000
2001 private function showActionButton()
2002 {
2003 if (!empty($this->additional_items))
2004 {
2005 if ($this->isPublicMode)
2006 {
2007 $menuUrl = 'BX.adminList.showPublicMenu(this.getContainer(), ' .
2008 CAdminPopup::PhpToJavaScript($this->additional_items) . ');';
2009 }
2010 else
2011 {
2012 $menuUrl = 'BX.adminList.ShowMenu(this.getContainer(), ' .
2013 CAdminPopup::PhpToJavaScript($this->additional_items) . ');';
2014 }
2015
2016 $button = new \Bitrix\UI\Buttons\SettingsButton([
2017 'click' => new \Bitrix\UI\Buttons\JsCode($menuUrl),
2018 ]);
2019 \Bitrix\UI\Toolbar\Facade\Toolbar::addButton($button);
2020 }
2021 }
2022
2023 private function showBaseButton(string $location = ButtonLocation::RIGHT)
2024 {
2025 if (!empty($this->items))
2026 {
2028 $firstItem = array_shift($items);
2029 if (!empty($firstItem['MENU']))
2030 {
2031 $items = array_merge($items, $firstItem['MENU']);
2032 }
2033 if ($this->isPublicMode)
2034 {
2035 $menuUrl = 'BX.adminList.showPublicMenu(this.getContainer(), ' .
2037 }
2038 else
2039 {
2040 $menuUrl = 'BX.adminList.ShowMenu(this.getContainer(), ' .
2042 }
2043
2044 $buttonParams = [
2045 'color' => \Bitrix\UI\Buttons\Color::PRIMARY,
2046 'id' => !empty($firstItem['ID']) ? $firstItem['ID'] : null,
2047 'text' => $firstItem['TEXT'],
2048 ];
2049 if (!empty($items))
2050 {
2051 if (!empty($firstItem['ONCLICK']))
2052 {
2053 $buttonParams['mainButton']['click'] = new \Bitrix\UI\Buttons\JsCode($firstItem['ONCLICK']);
2054 }
2055 else
2056 {
2057 if (isset($firstItem['DISABLE']))
2058 {
2059 $buttonParams['mainButton']['click'] = new \Bitrix\UI\Buttons\JsCode($menuUrl);
2060 }
2061 else
2062 {
2063 $buttonParams['mainButton']['link'] = $firstItem['LINK'];
2064 }
2065 }
2066 $buttonParams['menuButton']['click'] = new \Bitrix\UI\Buttons\JsCode($menuUrl);
2067 $button = new Bitrix\UI\Buttons\Split\Button($buttonParams);
2068 }
2069 else
2070 {
2071 if (!empty($firstItem['ONCLICK']))
2072 {
2073 $buttonParams['click'] = new \Bitrix\UI\Buttons\JsCode($firstItem['ONCLICK']);
2074 }
2075 else
2076 {
2077 $buttonParams['link'] = $firstItem['LINK'];
2078 }
2079 $button = new \Bitrix\UI\Buttons\Button($buttonParams);
2080 }
2081 \Bitrix\UI\Toolbar\Facade\Toolbar::addButton($button, $location);
2082 }
2083 }
2084}
2085
2087{
2091 protected function getUserSorting()
2092 {
2093 $result = [
2094 'by' => null,
2095 'order' => null
2096 ];
2097 $gridOptions = new Grid\Options($this->table_id);
2098 $sorting = $gridOptions->getSorting();
2099 if (!empty($sorting['sort']))
2100 {
2101 $order = reset($sorting['sort']);
2102 $result['by'] = key($sorting['sort']);
2103 $result['order'] = strtoupper($order) === 'ASC' ? 'ASC' : 'DESC';
2104 }
2105
2106 return $result;
2107 }
2108}
$arParams
Определения access_dialog.php:21
$type
Определения options.php:106
const BX_ROOT
Определения bx_root.php:3
global $APPLICATION
Определения include.php:80
$jsParams
Определения catalog_reindex.php:168
static isInternalRequest()
Определения context.php:24
const RESET_CONTROLS
Определения actions.php:24
const DROPDOWN
Определения types.php:13
static getString($length, $caseSensitive=false)
Определения random.php:76
static load($extNames)
Определения extension.php:16
Определения json.php:9
Определения uri.php:17
Определения admin_lib.php:429
$items
Определения admin_lib.php:1557
Определения admin_list.php:16
GetGroupIds()
Определения admin_list.php:472
$isPublicMode
Определения admin_list.php:54
DisplayList($arParams=array())
Определения admin_list.php:1151
NavText($sNavText)
Определения admin_list.php:718
GetAction()
Определения admin_list.php:464
$sEpilogContent
Определения admin_list.php:50
$sPrologContent
Определения admin_list.php:50
$table_id
Определения admin_list.php:25
$request
Определения admin_list.php:61
getPublicModeState()
Определения admin_list.php:91
$sNavText
Определения admin_list.php:35
Определения admin_list.php:1404
static PhpToJavaScript($items)
Определения admin_lib.php:1448
Определения admin_lib.php:2054
parentNavStart($nPageSize, $bShowAll, $iNumPage)
Определения admin_lib.php:2087
$table_id
Определения admin_lib.php:2056
Определения admin_lib.php:1890
$order
Определения admin_lib.php:1898
setFilterContextParam($bool)
Определения admin_ui_list.php:1964
setTypeToSectionMap(array $mapTypesAndSections)
Определения admin_ui_list.php:1362
setActionSections(array $actionSections, $listKeyForDelete=[])
Определения admin_ui_list.php:1344
setHandlerToType(array $mapTypesAndHandlers)
Определения admin_ui_list.php:1393
__construct($tableId, array $actions, array $actionsParams)
Определения admin_ui_list.php:1276
Определения admin_ui_list.php:18
getNavSize()
Определения admin_ui_list.php:168
setContextSettings(array $settings)
Определения admin_ui_list.php:449
getPageNavigation($navigationId)
Определения admin_ui_list.php:61
GetSystemContextMenu(array $config=[])
Определения admin_ui_list.php:454
IsGroupActionToAll()
Определения admin_ui_list.php:300
$currentPreset
Определения admin_ui_list.php:23
PrepareAction()
Определения admin_ui_list.php:311
EditAction()
Определения admin_ui_list.php:175
$totalRowCount
Определения admin_ui_list.php:20
GroupAction()
Определения admin_ui_list.php:259
setDefaultFilterFields(array $fields)
Определения admin_ui_list.php:536
setNavigation(\Bitrix\Main\UI\PageNavigation $nav, $title, $showAllways=true, $post=false)
Определения admin_ui_list.php:128
sendTotalCountResponse($totalCount)
Определения admin_ui_list.php:104
$filterPresets
Определения admin_ui_list.php:22
getCurPageParam($strParam="", $arParamKill=array(), $get_index_page=null)
Определения admin_ui_list.php:156
SetVisibleHeaderColumn()
Определения admin_ui_list.php:37
$enableNextPage
Определения admin_ui_list.php:19
ActionDoGroup($id, $action_id, $add_params="")
Определения admin_ui_list.php:325
& AddRow($id=false, $arRes=Array(), $link=false, $title=false)
Определения admin_ui_list.php:506
ActionAjaxPostGrid($postParams)
Определения admin_ui_list.php:349
hasGroupErrors()
Определения admin_ui_list.php:433
AddFilter(array $filterFields, array &$arFilter)
Определения admin_ui_list.php:355
SetNavigationParams(\CAdminUiResult $queryObject, $params=array())
Определения admin_ui_list.php:116
$context
Определения admin_ui_list.php:29
AddHeaders($aParams)
Определения admin_ui_list.php:31
deletePreset($presetId)
Определения admin_ui_list.php:564
InitContextMenu(array $menu=[], array $additional=[])
Определения admin_ui_list.php:490
getGroupErrors()
Определения admin_ui_list.php:438
isTotalCountRequest()
Определения admin_ui_list.php:94
ShowActionTable()
Определения admin_ui_list.php:766
setFilterPresets(array $filterPresets)
Определения admin_ui_list.php:552
DisplayFilter(array $filterFields=[], array $filterParams=[])
Определения admin_ui_list.php:571
const LINK_TYPE_SLIDER
Определения admin_ui_list.php:1777
getPreparedActions()
Определения admin_ui_list.php:1782
const SKIP_URL_MODIFY_FIELD
Определения admin_ui_list.php:1776
const LINK_TYPE_URL
Определения admin_ui_list.php:1774
const DEFAULT_ACTION_TYPE_FIELD
Определения admin_ui_list.php:1775
GetNavPrint($title, $show_allways=true, $StyleText="", $template_path=false, $arDeleteParam=false)
Определения admin_ui_list.php:1932
static GetNavSize($table_id=false, $nPageSize=20, $listUrl='')
Определения admin_ui_list.php:1946
setNavigationParams(array $params)
Определения admin_ui_list.php:1953
NavStart($nPageSize=20, $bShowAll=true, $iNumPage=false)
Определения admin_ui_list.php:1907
static $navParams
Определения admin_ui_list.php:1832
getUserSorting()
Определения admin_ui_list.php:2091
$bShowAll
Определения dbresult.php:21
static Show( $strInputName, $strFileId="", $showInfo=false, $inputs=array())
Определения file_input.php:62
$options
Определения commerceml2.php:49
$selfFolderUrl
Определения discount_coupon_list.php:18
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$postParams
Определения iblock_catalog_edit.php:50
$listUrl
Определения iblock_catalog_edit.php:54
$getListParams
Определения iblock_catalog_list.php:210
if($usePageNavigation) $totalPages
Определения iblock_catalog_list.php:234
$navyParams
Определения iblock_catalog_list.php:182
$filterFields
Определения iblock_catalog_list.php:55
global $adminSidePanelHelper
Определения init_admin.php:7
global $adminAjaxHelper
Определения init_admin.php:7
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$navParams
Определения csv_new_run.php:35
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
check_bitrix_sessid($varname='sessid')
Определения tools.php:4686
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
DeleteParam($ParamNames)
Определения tools.php:4548
htmlspecialcharsback($str)
Определения tools.php:2693
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$value
Определения Param.php:39
Определения culture.php:9
Определения chain.php:3
Определения actions.php:3
$publicMode
Определения product_settings.php:144
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$config
Определения quickway.php:69
if(empty($signedUserToken)) $key
Определения quickway.php:257
$filterOptions
Определения options.php:63
$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
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$items
Определения template.php:224
$post
Определения template.php:8
$title
Определения pdf.php:123
$location
Определения options.php:2729
$method
Определения index.php:27
$arRes
Определения options.php:104
$error
Определения subscription_card_product.php:20
$totalCount
Определения subscription_card_product.php:51
$action
Определения file_dialog.php:21
$arFilter
Определения user_search.php:106
$fields
Определения yandex_run.php:501