• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblock.php
  • Класс: CAllIBlock
  • Вызов: CAllIBlock::GetPanelButtons
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 = BitrixMainLoader::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 = BitrixMainContext::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 = BitrixMainLoader::includeModule('workflow');
	$bWorkflow = self::$workflowIncluded && ($arIBlock["WORKFLOW"] !== "N");
	$s = $bWorkflow? "&WF=Y": "";

	$arLabels = ($arOptions["LABELS"] ?? []);
	$labelList = [
		'ELEMENT_EDIT_TEXT' => 'ELEMENT_EDIT',
		'ELEMENT_EDIT_TITLE' => 'ELEMENT_EDIT',
		'ELEMENT_ADD_TEXT' => 'ELEMENT_ADD',
		'ELEMENT_ADD_TITLE' => 'ELEMENT_ADD',
		'ELEMENT_DELETE_TEXT' => 'ELEMENT_DELETE',
		'ELEMENT_DELETE_TITLE' => 'ELEMENT_DELETE',
		'SECTION_EDIT_TEXT' => 'SECTION_EDIT',
		'SECTION_EDIT_TITLE' => 'SECTION_EDIT',
		'SECTION_ADD_TEXT' => 'SECTION_ADD',
		'SECTION_ADD_TITLE' => 'SECTION_ADD',
		'SECTION_DELETE_TEXT' => 'SECTION_DELETE',
		'SECTION_DELETE_TITLE' => 'SECTION_DELETE',
		'ELEMENTS_NAME_TEXT' => 'ELEMENTS_NAME',
		'ELEMENTS_NAME_TITLE' => 'ELEMENTS_NAME',
		'SECTIONS_NAME_TEXT' => 'SECTIONS_NAME',
		'SECTIONS_NAME_TITLE' => 'SECTIONS_NAME',
	];
	foreach ($labelList as $phraseId => $iblockPhrase)
	{
		if (
			isset($arLabels[$phraseId])
			&& is_string($arLabels[$phraseId])
			&& $arLabels[$phraseId] !== ''
		)
		{
			continue;
		}
		$arLabels[$phraseId] = $arIBlock[$iblockPhrase];
	}

	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" => $arLabels["ELEMENT_EDIT_TEXT"],
			"TITLE" => $arLabels["ELEMENT_EDIT_TITLE"],
			"ACTION" => 'javascript:'.$action,
			"ACTION_URL" => $url,
			"ONCLICK" => $action,
			"DEFAULT" => $APPLICATION->GetPublicShowMode() !== 'configure',
			"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" => $arLabels["ELEMENT_ADD_TEXT"],
				"TITLE" => $arLabels["ELEMENT_ADD_TITLE"],
				"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" => $arLabels["ELEMENT_DELETE_TEXT"],
			"TITLE" => $arLabels["ELEMENT_DELETE_TITLE"],
			"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" => $arLabels["SECTION_EDIT_TEXT"],
					"TITLE" => $arLabels["SECTION_EDIT_TITLE"],
					"ACTION" => 'javascript:'.$action,
					"ACTION_URL" => $url,
					"ICON" => "bx-context-toolbar-edit-icon",
					"ONCLICK" => $action,
					"DEFAULT" => $APPLICATION->GetPublicShowMode() !== 'configure',
					"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" => $arLabels["SECTION_ADD_TEXT"],
					"TITLE" => $arLabels["SECTION_ADD_TITLE"],
					"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" => $arLabels["SECTION_DELETE_TEXT"],
					"TITLE" => $arLabels["SECTION_DELETE_TITLE"],
					"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', 'clear_filter'=>'Y', 'apply_filter'=>'Y'));

		$arButton = array(
			"TEXT" => (($arLabels["ELEMENTS_NAME_TEXT"] ?? '') <> ''? $arLabels["ELEMENTS_NAME_TEXT"] : $arIBlock["ELEMENTS_NAME"]),
			"TITLE" => (($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" => (($arLabels["SECTIONS_NAME_TEXT"] ?? '') <> ''? $arLabels["SECTIONS_NAME_TEXT"] : $arIBlock["SECTIONS_NAME"]),
			"TITLE" => (($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;
}