示例#1
0
 /**
  * <p>Метод возвращает массив, описывающий набор кнопок для управления элементами инфоблока. Метод статический.</p>
  *
  *
  * @param int $IBLOCK_ID = 0 Идентификатор инфоблока, которому принадлежит элемент.
  *
  * @param int $ELEMENT_ID = 0 Идентификатор текущего элемента информационного блока.
  *
  * @param int $SECTION_ID = 0 Идентификатор раздела инфоблока (при наличии).
  *
  * @param array $arOptions = array() Массив, содержащий локализацию названий и <a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/fields.php#fiblocklang">всплывающих подсказок к
  * ним</a>. Должен содержать секцию <i>LABELS</i>, в которой ключами будут
  * названия действий с элементами и разделами информационных
  * блоков с префиксами <i>TEXT</i> и <i>TITLE</i> (<i>ELEMENT_ADD_TEXT</i> и <i>ELEMENT_ADD_TITLE</i>).
  * <br><br> Если массив отсутствует, то настройки локализации берутся
  * из настроек информационных блоков, которые возвращаются методом
  * <a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblock/GetArrayByID.php">CIBlock::GetArrayByID</a>.
  *
  * @return array <p>Массив, описывающий набор кнопок (добавление, редактирование,
  * настройка и пр.) с учётом уровней права доступа к информационным
  * блокам. </p> <h4>Смотрите также</h4> <ul> <li><a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/fields.php#fiblocklang">Дополнительные параметры
  * информационных блоков</a></li> <li><a
  * href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblock/GetArrayByID.php">CIBlock::GetArrayByID</a></li> </ul>
  * <br><br>
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblock/getpanelbuttons.php
  * @author Bitrix
  */
 public static function GetPanelButtons($IBLOCK_ID = 0, $ELEMENT_ID = 0, $SECTION_ID = 0, $arOptions = array())
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     $windowParams = array('width' => 700, 'height' => 400, 'resize' => false);
     $arButtons = array("view" => array(), "edit" => array(), "configure" => array(), "submenu" => array());
     $bSectionButtons = !(isset($arOptions['SECTION_BUTTONS']) && $arOptions['SECTION_BUTTONS'] === false);
     $bSessID = !(isset($arOptions['SESSID']) && $arOptions['SESSID'] === false);
     $IBLOCK_ID = (int) $IBLOCK_ID;
     $ELEMENT_ID = (int) $ELEMENT_ID;
     $SECTION_ID = (int) $SECTION_ID;
     if ($ELEMENT_ID > 0 && ($IBLOCK_ID <= 0 || $bSectionButtons && $SECTION_ID == 0)) {
         $rsIBlockElement = CIBlockElement::GetList(array(), array("ID" => $ELEMENT_ID, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y"), false, false, array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID"));
         if ($arIBlockElement = $rsIBlockElement->Fetch()) {
             $IBLOCK_ID = $arIBlockElement["IBLOCK_ID"];
             $SECTION_ID = $arIBlockElement["IBLOCK_SECTION_ID"];
         }
     }
     if ($IBLOCK_ID <= 0) {
         return $arButtons;
     }
     $bCatalog = false;
     $useCatalogButtons = ($ELEMENT_ID <= 0 || isset($arOptions['SHOW_CATALOG_BUTTONS'])) && !empty($arOptions['USE_CATALOG_BUTTONS']) && is_array($arOptions['USE_CATALOG_BUTTONS']);
     $catalogButtons = array();
     if ($useCatalogButtons || isset($arOptions["CATALOG"]) && $arOptions["CATALOG"] == true) {
         if (self::$catalogIncluded === null) {
             self::$catalogIncluded = \Bitrix\Main\Loader::includeModule('catalog');
         }
         $bCatalog = self::$catalogIncluded;
         if (!self::$catalogIncluded) {
             $useCatalogButtons = false;
         }
     }
     if ($useCatalogButtons) {
         if (isset($arOptions['USE_CATALOG_BUTTONS']['add_product']) && $arOptions['USE_CATALOG_BUTTONS']['add_product'] == true) {
             $catalogButtons['add_product'] = true;
         }
         if (isset($arOptions['USE_CATALOG_BUTTONS']['add_sku']) && $arOptions['USE_CATALOG_BUTTONS']['add_sku'] == true) {
             $catalogButtons['add_sku'] = true;
         }
         if (empty($catalogButtons)) {
             $useCatalogButtons = false;
         }
     }
     $return_url = array("add_element" => "", "edit_element" => "", "edit_iblock" => "", "history_element" => "", "edit_section" => "", "add_section" => "", "delete_section" => "", "delete_element" => "", "element_list" => "", "section_list" => "");
     if (isset($arOptions['RETURN_URL'])) {
         if (is_array($arOptions["RETURN_URL"])) {
             foreach ($arOptions["RETURN_URL"] as $key => $url) {
                 if (!empty($url) && array_key_exists($key, $return_url)) {
                     $return_url[$key] = $url;
                 }
             }
         } elseif (!empty($arOptions["RETURN_URL"])) {
             foreach ($return_url as $key => $url) {
                 $return_url[$key] = $arOptions["RETURN_URL"];
             }
         }
     }
     $str = "";
     foreach ($return_url as $key => $url) {
         if (empty($url)) {
             if (empty($str)) {
                 $str = \Bitrix\Main\Context::getCurrent()->getServer()->getRequestUri();
                 if (defined("BX_AJAX_PARAM_ID")) {
                     $str = CHTTP::urlDeleteParams($str, array(BX_AJAX_PARAM_ID));
                 }
             }
             $return_url[$key] = $str;
         }
     }
     $arIBlock = CIBlock::GetArrayByID($IBLOCK_ID);
     if (self::$workflowIncluded === null) {
         self::$workflowIncluded = \Bitrix\Main\Loader::includeModule('workflow');
     }
     $bWorkflow = self::$workflowIncluded && $arIBlock["WORKFLOW"] !== "N";
     $s = $bWorkflow ? "&WF=Y" : "";
     $arLabels = $arOptions["LABELS"];
     if ($ELEMENT_ID > 0 && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ELEMENT_ID, "element_edit")) {
         $url = "/bitrix/admin/" . CIBlock::GetAdminElementEditLink($IBLOCK_ID, $ELEMENT_ID, array("force_catalog" => $bCatalog, "filter_section" => $SECTION_ID, "bxpublic" => "Y", "from_module" => "iblock", "return_url" => $return_url["edit_element"])) . $s;
         $action = $APPLICATION->GetPopupLink(array("URL" => $url, "PARAMS" => $windowParams));
         $arButton = array("TEXT" => strlen($arLabels["ELEMENT_EDIT_TEXT"]) ? $arLabels["ELEMENT_EDIT_TEXT"] : $arIBlock["ELEMENT_EDIT"], "TITLE" => strlen($arLabels["ELEMENT_EDIT_TITLE"]) ? $arLabels["ELEMENT_EDIT_TITLE"] : $arIBlock["ELEMENT_EDIT"], "ACTION" => 'javascript:' . $action, "ACTION_URL" => $url, "ONCLICK" => $action, "DEFAULT" => $APPLICATION->GetPublicShowMode() != 'configure' ? true : false, "ICON" => "bx-context-toolbar-edit-icon", "ID" => "bx-context-toolbar-edit-element");
         $arButtons["edit"]["edit_element"] = $arButton;
         $arButtons["configure"]["edit_element"] = $arButton;
         $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
         $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')";
         unset($arButton["ONCLICK"]);
         $arButtons["submenu"]["edit_element"] = $arButton;
         if ($bWorkflow) {
             $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"]);
             $arButton = array("TEXT" => GetMessage("IBLOCK_PANEL_HISTORY_BUTTON"), "TITLE" => GetMessage("IBLOCK_PANEL_HISTORY_BUTTON"), "ACTION" => "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ONCLICK" => "jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ID" => "bx-context-toolbar-history-element");
             $arButtons["submenu"]["history_element"] = $arButton;
         }
     }
     if (CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_element_bind")) {
         $params = array("force_catalog" => $bCatalog, "filter_section" => $SECTION_ID, "IBLOCK_SECTION_ID" => $SECTION_ID, "bxpublic" => "Y", "from_module" => "iblock", "return_url" => $return_url["add_element"]);
         if ($useCatalogButtons) {
             CCatalogAdminTools::setProductFormParams();
             CCatalogAdminTools::setCatalogPanelButtons($arButtons, $IBLOCK_ID, $catalogButtons, $params, $windowParams);
         } else {
             $url = "/bitrix/admin/" . CIBlock::GetAdminElementEditLink($IBLOCK_ID, null, $params);
             $action = $APPLICATION->GetPopupLink(array("URL" => $url, "PARAMS" => $windowParams));
             $arButton = array("TEXT" => strlen($arLabels["ELEMENT_ADD_TEXT"]) ? $arLabels["ELEMENT_ADD_TEXT"] : $arIBlock["ELEMENT_ADD"], "TITLE" => strlen($arLabels["ELEMENT_ADD_TITLE"]) ? $arLabels["ELEMENT_ADD_TITLE"] : $arIBlock["ELEMENT_ADD"], "ACTION" => 'javascript:' . $action, "ACTION_URL" => $url, "ONCLICK" => $action, "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-add-element");
             $arButtons["edit"]["add_element"] = $arButton;
             $arButtons["configure"]["add_element"] = $arButton;
             $arButtons["intranet"][] = array('TEXT' => $arButton["TEXT"], 'TITLE' => $arButton["TITLE"], 'ICON' => 'add', 'ONCLICK' => $arButton["ACTION"], 'SORT' => 1000);
             $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
             $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')";
             unset($arButton["ONCLICK"]);
             $arButtons["submenu"]["add_element"] = $arButton;
         }
     }
     if ($ELEMENT_ID > 0 && CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ELEMENT_ID, "element_delete")) {
         //Delete Element
         if (!empty($arButtons["edit"])) {
             $arButtons["edit"][] = array("SEPARATOR" => "Y", "HREF" => "");
         }
         if (!empty($arButtons["configure"])) {
             $arButtons["configure"][] = array("SEPARATOR" => "Y", "HREF" => "");
         }
         if (!empty($arButtons["submenu"])) {
             $arButtons["submenu"][] = array("SEPARATOR" => "Y", "HREF" => "");
         }
         $url = CIBlock::GetAdminElementListLink($IBLOCK_ID, array('action' => 'delete'));
         if ($bSessID) {
             $url .= '&' . bitrix_sessid_get();
         }
         $url .= '&ID=' . (preg_match('/^iblock_list_admin\\.php/', $url) ? "E" : "") . $ELEMENT_ID . "&return_url=" . UrlEncode($return_url["delete_element"]);
         $url = "/bitrix/admin/" . $url;
         $arButton = array("TEXT" => strlen($arLabels["ELEMENT_DELETE_TEXT"]) ? $arLabels["ELEMENT_DELETE_TEXT"] : $arIBlock["ELEMENT_DELETE"], "TITLE" => strlen($arLabels["ELEMENT_DELETE_TITLE"]) ? $arLabels["ELEMENT_DELETE_TITLE"] : $arIBlock["ELEMENT_DELETE"], "ACTION" => "javascript:if(confirm('" . GetMessageJS("IBLOCK_PANEL_ELEMENT_DEL_CONF") . "'))jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ACTION_URL" => $url, "ONCLICK" => "if(confirm('" . GetMessageJS("IBLOCK_PANEL_ELEMENT_DEL_CONF") . "'))jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ICON" => "bx-context-toolbar-delete-icon", "ID" => "bx-context-toolbar-delete-element");
         $arButtons["edit"]["delete_element"] = $arButton;
         $arButtons["configure"]["delete_element"] = $arButton;
         $arButtons["submenu"]["delete_element"] = $arButton;
     }
     if ($ELEMENT_ID <= 0 && $bSectionButtons) {
         $rsIBTYPE = CIBlockType::GetByID($arIBlock["IBLOCK_TYPE_ID"]);
         if (($arIBTYPE = $rsIBTYPE->Fetch()) && $arIBTYPE["SECTIONS"] == "Y") {
             if ($SECTION_ID > 0 && CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_edit")) {
                 if (!empty($arButtons["edit"])) {
                     $arButtons["edit"][] = array("SEPARATOR" => "Y", "HREF" => "");
                 }
                 if (!empty($arButtons["configure"])) {
                     $arButtons["configure"][] = array("SEPARATOR" => "Y", "HREF" => "");
                 }
                 if (!empty($arButtons["submenu"])) {
                     $arButtons["submenu"][] = array("SEPARATOR" => "Y", "HREF" => "");
                 }
                 $url = "/bitrix/admin/" . CIBlock::GetAdminSectionEditLink($IBLOCK_ID, $SECTION_ID, array("force_catalog" => $bCatalog, "filter_section" => $SECTION_ID, "bxpublic" => "Y", "from_module" => "iblock", "return_url" => $return_url["edit_section"]));
                 $action = $APPLICATION->GetPopupLink(array("URL" => $url, "PARAMS" => $windowParams));
                 $arButton = array("TEXT" => strlen($arLabels["SECTION_EDIT_TEXT"]) ? $arLabels["SECTION_EDIT_TEXT"] : $arIBlock["SECTION_EDIT"], "TITLE" => strlen($arLabels["SECTION_EDIT_TITLE"]) ? $arLabels["SECTION_EDIT_TITLE"] : $arIBlock["SECTION_EDIT"], "ACTION" => 'javascript:' . $action, "ACTION_URL" => $url, "ICON" => "bx-context-toolbar-edit-icon", "ONCLICK" => $action, "DEFAULT" => $APPLICATION->GetPublicShowMode() != 'configure' ? true : false, "ID" => "bx-context-toolbar-edit-section");
                 $arButtons["edit"]["edit_section"] = $arButton;
                 $arButtons["configure"]["edit_section"] = $arButton;
                 $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
                 $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')";
                 unset($arButton["ONCLICK"]);
                 $arButtons["submenu"]["edit_section"] = $arButton;
             }
             if (CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_section_bind")) {
                 $url = "/bitrix/admin/" . CIBlock::GetAdminSectionEditLink($IBLOCK_ID, null, array("force_catalog" => $bCatalog, "IBLOCK_SECTION_ID" => $SECTION_ID, "filter_section" => $SECTION_ID, "bxpublic" => "Y", "from_module" => "iblock", "return_url" => $return_url["add_section"]));
                 $action = $APPLICATION->GetPopupLink(array("URL" => $url, "PARAMS" => $windowParams));
                 $arButton = array("TEXT" => strlen($arLabels["SECTION_ADD_TEXT"]) ? $arLabels["SECTION_ADD_TEXT"] : $arIBlock["SECTION_ADD"], "TITLE" => strlen($arLabels["SECTION_ADD_TITLE"]) ? $arLabels["SECTION_ADD_TITLE"] : $arIBlock["SECTION_ADD"], "ACTION" => 'javascript:' . $action, "ACTION_URL" => $url, "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-add-section", "ONCLICK" => $action);
                 $arButtons["edit"]["add_section"] = $arButton;
                 $arButtons["configure"]["add_section"] = $arButton;
                 $url = str_replace("&bxpublic=Y&from_module=iblock", "", $url);
                 $arButton["ACTION"] = "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')";
                 unset($arButton["ONCLICK"]);
                 $arButtons["submenu"]["add_section"] = $arButton;
             }
             //Delete section
             if ($SECTION_ID > 0 && CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $SECTION_ID, "section_delete")) {
                 $url = CIBlock::GetAdminSectionListLink($IBLOCK_ID, array('action' => 'delete'));
                 if ($bSessID) {
                     $url .= '&' . bitrix_sessid_get();
                 }
                 $url .= '&ID[]=' . (preg_match('/^iblock_list_admin\\.php/', $url) ? "S" : "") . $SECTION_ID . "&return_url=" . UrlEncode($return_url["delete_section"]);
                 $url = "/bitrix/admin/" . $url;
                 $arButton = array("TEXT" => strlen($arLabels["SECTION_DELETE_TEXT"]) ? $arLabels["SECTION_DELETE_TEXT"] : $arIBlock["SECTION_DELETE"], "TITLE" => strlen($arLabels["SECTION_DELETE_TITLE"]) ? $arLabels["SECTION_DELETE_TITLE"] : $arIBlock["SECTION_DELETE"], "ACTION" => "javascript:if(confirm('" . GetMessageJS("IBLOCK_PANEL_SECTION_DEL_CONF") . "'))jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ACTION_URL" => $url, "ONCLICK" => "if(confirm('" . GetMessageJS("IBLOCK_PANEL_SECTION_DEL_CONF") . "'))jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ICON" => "bx-context-toolbar-delete-icon", "ID" => "bx-context-toolbar-delete-section");
                 $arButtons["edit"]["delete_section"] = $arButton;
                 $arButtons["configure"]["delete_section"] = $arButton;
                 $arButtons["submenu"]["delete_section"] = $arButton;
             }
         }
     }
     if ($IBLOCK_ID > 0 && CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, "iblock_admin_display")) {
         if (!empty($arButtons["submenu"])) {
             $arButtons["submenu"][] = array("SEPARATOR" => "Y", "HREF" => "");
         }
         if ($SECTION_ID > 0) {
             $url = "/bitrix/admin/" . CIBlock::GetAdminElementListLink($IBLOCK_ID, array('find_section_section' => $SECTION_ID));
         } else {
             $url = "/bitrix/admin/" . CIBlock::GetAdminElementListLink($IBLOCK_ID, array('find_el_y' => 'Y'));
         }
         $arButton = array("TEXT" => strlen($arLabels["ELEMENTS_NAME_TEXT"]) ? $arLabels["ELEMENTS_NAME_TEXT"] : $arIBlock["ELEMENTS_NAME"], "TITLE" => strlen($arLabels["ELEMENTS_NAME_TITLE"]) ? $arLabels["ELEMENTS_NAME_TITLE"] : $arIBlock["ELEMENTS_NAME"], "ACTION" => "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ACTION_URL" => $url, "ONCLICK" => "jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ID" => "bx-context-toolbar-elements-list");
         $arButtons["submenu"]["element_list"] = $arButton;
         $arButtons["intranet"]["element_list"] = array('TEXT' => $arButton["TEXT"], 'TITLE' => $arButton["TITLE"], 'ICON' => 'settings', 'ONCLICK' => $arButton["ACTION"], 'SORT' => 1010);
         $url = "/bitrix/admin/" . CIBlock::GetAdminSectionListLink($IBLOCK_ID, array('find_section_section' => $SECTION_ID));
         $arButton = array("TEXT" => strlen($arLabels["SECTIONS_NAME_TEXT"]) ? $arLabels["SECTIONS_NAME_TEXT"] : $arIBlock["SECTIONS_NAME"], "TITLE" => strlen($arLabels["SECTIONS_NAME_TITLE"]) ? $arLabels["SECTIONS_NAME_TITLE"] : $arIBlock["SECTIONS_NAME"], "ACTION" => "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ACTION_URL" => $url, "ONCLICK" => "jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ID" => "bx-context-toolbar-sections-list");
         $arButtons["submenu"]["section_list"] = $arButton;
         if (CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, "iblock_edit")) {
             $url = "/bitrix/admin/iblock_edit.php?type=" . $arIBlock["IBLOCK_TYPE_ID"] . "&lang=" . LANGUAGE_ID . "&ID=" . $IBLOCK_ID . "&return_url=" . UrlEncode($return_url["edit_iblock"]);
             $arButton = array("TEXT" => GetMessage("IBLOCK_PANEL_EDIT_IBLOCK_BUTTON", array("#IBLOCK_NAME#" => $arIBlock["NAME"])), "TITLE" => GetMessage("IBLOCK_PANEL_EDIT_IBLOCK_BUTTON", array("#IBLOCK_NAME#" => $arIBlock["NAME"])), "ACTION" => "javascript:jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ACTION_URL" => $url, "ONCLICK" => "jsUtils.Redirect([], '" . CUtil::JSEscape($url) . "')", "ID" => "bx-context-toolbar-edit-iblock");
             $arButtons["submenu"]["edit_iblock"] = $arButton;
         }
     }
     return $arButtons;
 }
示例#2
0
 function _Order($by, $order, $default_order, $nullable = true)
 {
     $o = parent::_Order($by, $order, $default_order, $nullable);
     //$o[0] - bNullsFirst
     //$o[1] - asc|desc
     if ($o[0]) {
         if ($o[1] == "asc") {
             return $by . " asc";
         } else {
             return "length(" . $by . ")>0 asc, " . $by . " desc";
         }
     } else {
         if ($o[1] == "asc") {
             return "length(" . $by . ")>0 desc, " . $by . " asc";
         } else {
             return $by . " desc";
         }
     }
 }