16 private $arItems =
array();
17 private $arOptFlt =
array();
18 private static $defaultSort = 100;
19 private static $defaultPresetSort = 50;
21 private $tableId=
false;
30 $isAdmin =
$USER->CanDoOperation(
'edit_other_settings');
32 if(empty($popup) || !is_array($popup))
35 $this->
id = preg_replace(
'/[^a-z0-9_]/i',
'',
$id);
36 $this->popup = $popup;
38 if(is_array($arExtraParams))
40 if(isset($arExtraParams[
"url"]) && !empty($arExtraParams[
"url"]))
41 $this->url = $arExtraParams[
"url"];
43 if(isset($arExtraParams[
"table_id"]) && !empty($arExtraParams[
"table_id"]))
44 $this->tableId = $arExtraParams[
"table_id"];
47 $this->arOptFlt = CUserOptions::GetOption(
"filter", $this->
id,
array(
50 "presetsDeleted" =>
""
52 $this->arOptFlt[
'styleFolded'] = (string)($this->arOptFlt[
'styleFolded'] ??
'N');
55 if (isset($this->arOptFlt[
"presetsDeleted"]))
57 $presetsDeleted = explode(
",", $this->arOptFlt[
"presetsDeleted"]);
60 $this->arOptFlt[
"presetsDeleted"] = $presetsDeleted ?:
array();
64 if(is_array($presetsDeleted))
65 foreach($presetsDeleted as $preset)
66 if(trim($preset) <>
"")
67 $presetsDeletedJS .= ($presetsDeletedJS <>
"" ?
",":
"").
'"'.CUtil::JSEscape(trim($preset)).
'"';
69 $this->arOptFlt[
"presetsDeletedJS"] = $presetsDeletedJS;
78 $arItem[
"FIELDS"] = unserialize(
$arFilter[
"FIELDS"], [
'allowed_classes' =>
false]);
81 $arItem[
"SORT_FIELD"] = unserialize(
$arFilter[
"SORT_FIELD"], [
'allowed_classes' =>
false]);
88 $arItem[
"NAME"] = $langName;
90 foreach ($arItem[
"FIELDS"] as
$key => $field)
95 $arItem[
"FIELDS"][
$key][
"value"] = $langValue;
101 $this->AddItem($arItem);
105 private function AddItem($arItem, $bInsertFirst =
false)
108 if(!$arItem[
"EDITABLE"] && !empty($this->arOptFlt[
"presetsDeleted"]))
109 if(in_array($arItem[
"ID"], $this->arOptFlt[
"presetsDeleted"]))
112 $customPresetId = $this->FindItemByPresetId($arItem[
"ID"]);
116 $this->arItems[$customPresetId][
"SORT"] = $arItem[
"SORT"];
120 if(isset($arItem[
"PRESET_ID"]))
122 $presetID = $this->FindItemByID($arItem[
"PRESET_ID"]);
126 $arItem[
"SORT"] = $this->arItems[$presetID][
"SORT"];
127 unset($this->arItems[$presetID]);
132 if(!isset($arItem[
"SORT"]))
133 $arItem[
"SORT"] = self::$defaultSort;
137 $arNewItems[$arItem[
"ID"]] = $arItem;
139 foreach ($this->arItems as
$key => $item)
140 $arNewItems[
$key] = $item;
142 $this->arItems = $arNewItems;
145 $this->arItems[$arItem[
"ID"]] = $arItem;
147 unset($this->arItems[$arItem[
"ID"]][$arItem[
"ID"]]);
152 private static function CheckFields(
$arFields)
160 $aMsg[] =
array(
"id"=>
"FILTER_ID",
"text"=>
GetMessage(
"filters_error_table_name"));
163 $aMsg[] =
array(
"id"=>
"NAME",
"text"=>
GetMessage(
"filters_error_name"));
166 $aMsg[] =
array(
"id"=>
"FIELDS",
"text"=>
GetMessage(
"filters_error_fields"));
169 $aMsg[] =
array(
"id"=>
"USER_ID",
"text"=>
GetMessage(
"filters_error_user"));
177 $aMsg[] =
array(
"id"=>
"USER_ID",
"text"=>
GetMessage(
"filters_error_user"));
183 $e =
new CAdminException($aMsg);
191 private static function FieldsExcess(
$arFields)
204 private static function FieldsDelHiddenEmpty(
$arFields)
213 if(!empty($field[
"value"]) || $field[
"hidden"] ==
"false")
215 "value" => $field[
"value"],
216 "hidden" => $field[
"hidden"],
233 $outRows = implode(
",",
$rows);
240 if(!empty($this->arOptFlt[
"rows"]))
243 $this->arOptFlt[
"rows"] = $outRows;
254 $outRows = implode(
",",
$rows);
261 return CUserOptions::SetOption(
"filter", $filterId,
array(
"rows" => $outRows),
true);
301 "FILTER_ID" => $this->
id,
308 $item[
"FIELDS"] = CAdminFilter::FieldsExcess(
$arFields[
"FIELDS"]);
310 $item[
"FIELDS"] =
array();
313 $item[
"SORT"] = intval(
$arFields[
"SORT"]);
315 $item[
"SORT"] =self::$defaultPresetSort+
count($this->arItems)*10;
318 $item[
"SORT_FIELD"] =
$arFields[
"SORT_FIELD"];
320 return $this->AddItem($item,
false);
324 private function FindItemByPresetId($strID)
326 if (!is_array($this->arItems))
331 foreach ($this->arItems as
$key => $item)
333 if (isset($item[
"PRESET_ID"]) && $item[
"PRESET_ID"] == $strID)
342 private function FindItemByID($strID)
344 if(!is_array($this->arItems))
347 foreach ($this->arItems as
$key => $item)
348 if($item[
"ID"] == $strID)
365 $item[
"FIELDS"] =
array();
369 $arFields[
"SORT"] = self::$defaultPresetSort;
388 if(!CAdminFilter::CheckFields(
$arFields))
399 return (
$DB->Query(
"DELETE FROM b_filters WHERE ID='".intval(
$ID).
"'"));
417 if(!CAdminFilter::CheckFields(
$arFields))
420 $strUpdate =
$DB->PrepareUpdate(
"b_filters",
$arFields);
424 $arBinds[
"FIELDS"] =
$arFields[
"FIELDS"];
429 $strSql =
"UPDATE b_filters SET ".$strUpdate.
" WHERE ID=".
$ID;
430 return $DB->QueryBind($strSql, $arBinds);
443 $arSqlSearch = Array();
448 if ((
string)
$val ==
'' ||
$val==
"NOT_REF")
451 switch(mb_strtoupper(
$key))
459 $arSqlSearch[] =
"F.USER_ID=".intval(
$val).
" OR F.COMMON='Y'";
463 $arSqlSearch[] =
"F.USER_ID = ".intval(
$val);
467 $arSqlSearch[] =
"F.FILTER_ID = '".$DB->ForSql(
$val).
"'";
476 $arSqlSearch[] =
"F.COMMON = '".$DB->ForSql(
$val, 1).
"'";
479 $arSqlSearch[] =
"F.PRESET = '".$DB->ForSql(
$val, 1).
"'";
482 $arSqlSearch[] =
"F.LANGUAGE_ID = '".$DB->ForSql(
$val, 2).
"'";
500 $ord = (mb_strtoupper(
$val) <>
"ASC"?
"DESC":
"ASC");
501 switch(mb_strtoupper(
$key))
504 $sOrder .=
", F.ID ".$ord;
507 $sOrder .=
", F.USER_ID ".$ord;
510 $sOrder .=
", F.FILTER_ID ".$ord;
513 $sOrder .=
", F.NAME ".$ord;
516 $sOrder .=
", F.FIELDS ".$ord;
519 $sOrder .=
", F.COMMON ".$ord;
522 $sOrder .=
", F.PRESET ".$ord;
525 $sOrder .=
", F.LANGUAGE_ID ".$ord;
528 $sOrder .=
", F.PRESET_ID ".$ord;
531 $sOrder .=
", F.SORT ".$ord;
534 $sOrder .=
", F.SORT_FIELD ".$ord;
539 $sOrder =
"F.ID ASC";
540 $strSqlOrder =
" ORDER BY ".trim($sOrder,
", ");
545 F.ID, F.USER_ID, F.NAME, F.FILTER_ID, F.FIELDS, F.COMMON, F.PRESET, F.LANGUAGE_ID, F.PRESET_ID, F.SORT, F.SORT_FIELD
556 private static function Cmp(
$a, $b)
558 if (
$a[
"SORT"] == $b[
"SORT"])
559 return (
$a[
"ID"] < $b[
"ID"]) ? -1 : 1;
561 return (
$a[
"SORT"] < $b[
"SORT"]) ? -1 : 1;
566 uasort($this->arItems,
"CAdminFilter::Cmp");
569<div id="adm-filter-tab-wrap-'.$this->id.
'" class="adm-filter-wrap'.($this->arOptFlt[
'styleFolded'] ===
"Y" ?
" adm-filter-folded" :
"").
'" style = "display: none;">
570 <table class="adm-filter-main-table">
572 <td class="adm-filter-main-table-cell">
573 <div class="adm-filter-tabs-block" id="filter-tabs-'.$this->
id.
'">
574 <span id="adm-filter-tab-'.$this->
id.
'-0" class="adm-filter-tab adm-filter-tab-active" onclick="'.$this->
id.
'.SetActiveTab(this); '.$this->
id.
'.ApplyFilter(\'0\'); " title="'.
GetMessage(
"admin_lib_filter_goto_dfilter").
'">'.
GetMessage(
"admin_lib_filter_filter").
'</span>';
576 if(is_array($this->arItems) && !empty($this->arItems))
578 foreach($this->arItems as $filter_id =>
$filter)
581 echo
'<span id="adm-filter-tab-'.$this->id.
'-'.$filter_id.
'" class="adm-filter-tab" onclick="'.$this->
id.
'.SetActiveTab(this); '.$this->
id.
'.ApplyFilter(\''.$filter_id.
'\');
" title="'.GetMessage("admin_lib_filter_goto_filter").": "".htmlspecialcharsbx($name).'&
quot;
">'.htmlspecialcharsbx($name).'</span>';
585 echo '<span id="adm-filter-add-tab-
'.$this->id.'" class="adm-filter-tab adm-filter-add-tab
" onclick="'.$this->id.'.SaveAs();
" title="'.GetMessage("admin_lib_filter_new").'"></span><span onclick="'.$this->id.'.SetFoldedView();
" class="adm-filter-switcher-tab
"><span id="adm-filter-switcher-tab
" class="adm-filter-switcher-tab-icon
"></span></span><span class="adm-filter-tabs-block-underlay
"></span>
590 <td class="adm-filter-main-table-cell
">
591 <div class="adm-filter-content
" id="'.$this->id.'_content
">
592 <div class="adm-filter-content-table-wrap
">
593 <table cellspacing="0
" class="adm-filter-content-table
" id="'.$this->id.'">';
599 public function Buttons($aParams=false)
601 $hkInst = CHotKeys::getInstance();
607 <div class="adm-filter-bottom-separate
" id="'.$this->id.'_bottom_separator
"></div>
608 <div class="adm-filter-bottom
">';
610 if($aParams !== false)
612 $url = $aParams["url
"];
613 if(!str_contains($url, "?
"))
618 if(!str_contains($url, "lang=
"))
619 $url .= "lang=
".LANGUAGE_ID;
625 $this->tableId = $aParams["table_id
"];
627 if(isset($aParams['report']) && $aParams['report'])
630 <input type="submit
" class="adm-btn
" id="'.$this->id.'set_filter
" name="set_filter
" title="'.GetMessage("admin_lib_filter_set_rep_title").$hkInst->GetTitle("set_filter").'" onclick="return '.htmlspecialcharsbx($this->id.'.OnSet(\
''.CUtil::AddSlashes($aParams[
"table_id"]).
'\', \
''.CUtil::AddSlashes($url).
'\',
this);
').'" value="'.GetMessage("admin_lib_filter_set_rep").'">
631 <input type="submit
" class="adm-btn
" id="'.$this->id.'del_filter
" name="del_filter
" title="'.GetMessage("admin_lib_filter_clear_butt_title").$hkInst->GetTitle("del_filter").'" onclick="return '.htmlspecialcharsbx($this->id.'.OnClear(\
''.CUtil::AddSlashes($aParams[
"table_id"]).
'\', \
''.CUtil::AddSlashes($url).
'\',
this);
').'" value="'.GetMessage("admin_lib_filter_clear_butt").'">';
635 <input type="submit
" class="adm-btn
" id="'.$this->id.'set_filter
" name="set_filter
" title="'.GetMessage("admin_lib_filter_set_butt").$hkInst->GetTitle("set_filter").'" onclick="return '.htmlspecialcharsbx($this->id.'.OnSet(\
''.CUtil::AddSlashes($aParams[
"table_id"]).
'\', \
''.CUtil::AddSlashes($url).
'\',
this);
').'" value="'.GetMessage("admin_lib_filter_set_butt").'">
636 <input type="submit
" class="adm-btn
" id="'.$this->id.'del_filter
" name="del_filter
" title="'.GetMessage("admin_lib_filter_clear_butt").$hkInst->GetTitle("del_filter").'" onclick="return '.htmlspecialcharsbx($this->id.'.OnClear(\
''.CUtil::AddSlashes($aParams[
"table_id"]).
'\', \
''.CUtil::AddSlashes($url).
'\',
this);
').'" value="'.GetMessage("admin_lib_filter_clear_butt").'">';
643 <div class="adm-filter-setting-block
">
644 <span class="adm-filter-setting
" onClick="this.blur();
'.$this->id.'.SaveMenuShow(
this);
return false;
" hidefocus="true" title="'.GetMessage("admin_lib_filter_savedel_title").'"></span>
645 <span class="adm-filter-add-button
" onClick="this.blur();
'.$this->id.'.SettMenuShow(
this);
return false;
" hidefocus="true" title="'.GetMessage("admin_lib_filter_more_title").'"></span>
650 public function End()
661 $sRowIds = $sVisRowsIds = "";
664 if(is_array($this->popup))
666 foreach($this->popup as $key=>$item)
668 $sRowIds .= ($sRowIds <> ""? ",
":"").'"'.CUtil::JSEscape($key).'"';
670 $aRows = explode(",
", $this->arOptFlt["rows
"]);
673 foreach($aRows as $row)
675 $sVisRowsIds .= ($sVisRowsIds <> ""? ",
":"").'"'.CUtil::JSEscape(trim($row)).'":true';
678 $this->PrintSaveOptionsDIV();
679 $this->GetParamsFromCookie();
681 $openedTabUri = false;
682 $openedTabSes = $filteredTab = null;
684 if(isset($_REQUEST["adm_filter_applied
"]) && !empty($_REQUEST["adm_filter_applied
"]))
686 $openedTabUri = $_REQUEST["adm_filter_applied
"];
690 $session = \Bitrix\Main\Application::getInstance()->getSession();
691 if (isset($session[self::SESS_PARAMS_NAME][$this->id]["activeTabId
"]))
693 $openedTabSes = $session[self::SESS_PARAMS_NAME][$this->id]["activeTabId
"];
695 if (isset($session[self::SESS_PARAMS_NAME][$this->id]["filteredId
"]))
697 $filteredTab = $session[self::SESS_PARAMS_NAME][$this->id]["filteredId
"];
704 var '.$this->id.' = {};
706 '.$this->id.' = new BX.AdminFilter("'.$this->id.'", ['.$sRowIds.']);
709 BX.adminMenu = new BX.adminMenu();
711 '.$this->id.'.state.init = true;
712 '.$this->id.'.state.folded = '.($this->arOptFlt["styleFolded
"] === "Y
" ? "true" : "false").';
713 '.$this->id.'.InitFilter({'.$sVisRowsIds.'});
714 '.$this->id.'.oOptions = ' . Json::encode($this->arItems) . ';
715 '.$this->id.'.popupItems = ' . Json::encode($this->popup) . ';
716 '.$this->id.'.InitFirst();
717 '.$this->id.'.url = "'.CUtil::JSEscape($this->url).'";
718 '.$this->id.'.table_id = "'.CUtil::JSEscape($this->tableId).'";
719 '.$this->id.'.presetsDeleted = ['.$this->arOptFlt["presetsDeletedJS
"].'];';
721 if($filteredTab != null || $openedTabUri != false)
723 $tabToInit = ($openedTabUri ? $openedTabUri : $filteredTab);
726 '.$this->id.'.InitFilteredTab("'.CUtil::JSEscape($tabToInit).'");';
729 if($openedTabSes != null || $openedTabUri != false)
731 var openedFTab = '.$this->id.'.InitOpenedTab("'.CUtil::JSEscape($openedTabUri).'", "'.CUtil::JSEscape($openedTabSes).'");';
734 '.$this->id.'.state.init = false;
735 BX("adm-filter-tab-wrap-
'.$this->id.'").style.display = "block
";';
737 //making filter tabs draggable
740 $registerUrl = (new Uri($this->url))
741 ->deleteParams(["adm_filter_applied
", "adm_filter_preset
"])
745 foreach($this->arItems as $filter_id => $filter)
747 $arParamsAdd = array("adm_filter_applied
"=>$filter_id);
749 if(isset($filter["PRESET_ID
"]))
750 $arParamsAdd["adm_filter_preset
"] = $filter["PRESET_ID
"];
752 $filterUrl = (new Uri($registerUrl))
753 ->addParams($arParamsAdd)
757 if(BX.adminMenu && BX.adminMenu.registerItem)
759 BX.adminMenu.registerItem(
'adm-filter-tab-".$this->id.'-
'.$filter_id."', {URL:
'".$filterUrl."', TITLE:
true});
768 $hkInst = CHotKeys::getInstance();
770 echo $hkInst->PrintJSExecs($Execs);
775 //extracting filter params from cookie and transfer them to session
776 private function GetParamsFromCookie()
778 $cookieName = COption::GetOptionString("main
", "cookie_name
", "BITRIX_SM
")."_ADM_FLT_PARAMS
";
779 if(!isset($_COOKIE[$cookieName]) || $_COOKIE[$cookieName] == "")
782 $aParams = explode(",
",$_COOKIE[$cookieName]);
783 SetCookie($cookieName,'');
790 foreach ($aParams as $key => $aValue)
792 $aParam = explode(":
",$aValue);
793 unset($aParams[$key]);
795 if(!empty($aParam) && $aParam[0] != "filter_id
")
796 $aParams[$aParam[0]] = $aParam[1];
797 elseif($aParam[0] == "filter_id
")
798 $filterId = $aParam[1];
804 foreach ($aParams as $paramName => $value)
805 \Bitrix\Main\Application::getInstance()->getSession()[self::SESS_PARAMS_NAME][$filterId][$paramName] = $value;
811 private function IsFiltered()
813 $fltTable = \Bitrix\Main\Application::getInstance()->getSession()["SESS_ADMIN
"][$this->tableId];
815 if(!isset($fltTable) || !is_array($fltTable))
818 foreach ($fltTable as $value)
825 private function PrintSaveOptionsDIV()
828 $isAdmin = $USER->CanDoOperation('edit_other_settings');
831 <div id="filter_save_opts_<?=$this->
id?>
">
834 <td align="right" width="40%
"><?=GetMessage("admin_lib_filter_sett_name
")?></td>
835 <td><input type="text
" name="save_filter_name
" value="" size="30
" maxlength="255
"></td>
839 <td align="right" width="40%
"><?=GetMessage("admin_lib_filter_sett_common
")?></td>
840 <td><input type="checkbox
" name="common
" ></td>
852 public static function UnEscape()
static AddPresetToBase($arFields)
static SetDefaultRowsOption($filterId, $rows)
static GetList($aSort=array(), $arFilter=Array(), $getCommon=true)
static Update($ID, $arFields)
__construct($id, $popup=false, $arExtraParams=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
GetMessage($name, $aReplace=null)
if(empty($signedUserToken)) $key
</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."%"
adm detail iblock types adm detail iblock list tr_SITE_ID display