2004-10-20 23:06:45 +02:00
|
|
|
<?php
|
2006-12-04 19:31:18 +01:00
|
|
|
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2012-01-04 19:31:46 +01:00
|
|
|
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
2024-03-13 15:06:34 +01:00
|
|
|
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
2009-07-28 00:48:05 +02:00
|
|
|
*
|
2002-05-09 16:57:48 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-05-09 16:57:48 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-05-09 16:57:48 +02:00
|
|
|
*/
|
|
|
|
|
|
2005-03-28 14:08:19 +02:00
|
|
|
/**
|
2010-04-28 12:02:54 +02:00
|
|
|
* \file htdocs/core/class/menu.class.php
|
2010-11-22 10:18:53 +01:00
|
|
|
* \ingroup core
|
2024-01-13 19:48:20 +01:00
|
|
|
* \brief Fichier de la class de gestion du menu gauche
|
2009-07-28 00:48:05 +02:00
|
|
|
*/
|
2004-10-29 00:15:31 +02:00
|
|
|
|
|
|
|
|
|
2005-01-19 23:50:56 +01:00
|
|
|
/**
|
2012-01-27 16:12:11 +01:00
|
|
|
* Class to manage left menus
|
2009-07-28 00:48:05 +02:00
|
|
|
*/
|
2011-10-16 01:59:12 +02:00
|
|
|
class Menu
|
|
|
|
|
{
|
2024-03-10 01:53:04 +01:00
|
|
|
/**
|
|
|
|
|
* List of menu items
|
|
|
|
|
*
|
2024-08-03 13:51:03 +02:00
|
|
|
* @var array<array{url:string,titre:string,enabled:int<0,2>,target:string,mainmenu:string,leftmenu:string,position:int,level?:int,id:string,idsel:string,classname:string,prefix?:string}>
|
2024-03-10 01:53:04 +01:00
|
|
|
*/
|
2020-10-31 14:32:18 +01:00
|
|
|
public $liste;
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2023-12-04 12:04:36 +01:00
|
|
|
$this->liste = array();
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
|
|
|
|
* Clear property ->liste
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function clear()
|
|
|
|
|
{
|
|
|
|
|
$this->liste = array();
|
|
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
|
|
|
|
* Add a menu entry into this->liste (at end)
|
|
|
|
|
*
|
|
|
|
|
* @param string $url Url to follow on click (does not include DOL_URL_ROOT)
|
|
|
|
|
* @param string $titre Label of menu to add. The value must already be translated.
|
|
|
|
|
* @param integer $level Level of menu to add
|
|
|
|
|
* @param int $enabled Menu active or not (0=Not active, 1=Active, 2=Active but grey)
|
|
|
|
|
* @param string $target Target link
|
|
|
|
|
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
|
|
|
|
|
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
|
|
|
|
|
* @param int $position Position (not used yet)
|
|
|
|
|
* @param string $id Id
|
|
|
|
|
* @param string $idsel Id sel
|
|
|
|
|
* @param string $classname Class name
|
|
|
|
|
* @param string $prefix Prefix to title (image or picto)
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function add($url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
|
|
|
|
|
{
|
2024-03-10 01:53:04 +01:00
|
|
|
$this->liste[] = array('url' => $url, 'titre' => $titre, 'level' => $level, 'enabled' => $enabled, 'target' => $target, 'mainmenu' => $mainmenu, 'leftmenu' => $leftmenu, 'position' => $position, 'id' => $id, 'idsel' => $idsel, 'classname' => $classname, 'prefix' => $prefix);
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
2012-01-04 19:31:46 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
2023-10-13 15:00:51 +02:00
|
|
|
* Insert a menu entry into this->liste (after $idafter)
|
2020-10-31 14:32:18 +01:00
|
|
|
*
|
|
|
|
|
* @param int $idafter Array key after which inserting new entry
|
|
|
|
|
* @param string $url Url to follow on click
|
|
|
|
|
* @param string $titre Label of menu to add. The value must already be translated.
|
|
|
|
|
* @param integer $level Level of menu to add
|
|
|
|
|
* @param int $enabled Menu active or not
|
|
|
|
|
* @param string $target Target link
|
|
|
|
|
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
|
|
|
|
|
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
|
|
|
|
|
* @param int $position Position (not used yet)
|
|
|
|
|
* @param string $id Id
|
|
|
|
|
* @param string $idsel Id sel
|
|
|
|
|
* @param string $classname Class name
|
|
|
|
|
* @param string $prefix Prefix to title (image or picto)
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function insert($idafter, $url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
|
|
|
|
|
{
|
|
|
|
|
$array_start = array_slice($this->liste, 0, ($idafter + 1));
|
2024-03-10 01:53:04 +01:00
|
|
|
$array_new = array(0 => array('url' => $url, 'titre' => $titre, 'level' => $level, 'enabled' => $enabled, 'target' => $target, 'mainmenu' => $mainmenu, 'leftmenu' => $leftmenu, 'position' => $position, 'id' => $id, 'idsel' => $idsel, 'classname' => $classname, 'prefix' => $prefix));
|
2020-10-31 14:32:18 +01:00
|
|
|
$array_end = array_slice($this->liste, ($idafter + 1));
|
|
|
|
|
$this->liste = array_merge($array_start, $array_new, $array_end);
|
|
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
|
|
|
|
/**
|
|
|
|
|
* Remove a menu entry from this->liste
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function remove_last()
|
|
|
|
|
{
|
|
|
|
|
// phpcs:enable
|
|
|
|
|
if (count($this->liste) > 1) {
|
|
|
|
|
array_pop($this->liste);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-04 18:50:54 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
/**
|
|
|
|
|
* Return number of visible entries (gray or not)
|
|
|
|
|
*
|
|
|
|
|
* @return int Number of visible (gray or not) menu entries
|
|
|
|
|
*/
|
|
|
|
|
public function getNbOfVisibleMenuEntries()
|
|
|
|
|
{
|
|
|
|
|
$nb = 0;
|
2021-02-23 22:03:23 +01:00
|
|
|
foreach ($this->liste as $val) {
|
|
|
|
|
if (!empty($val['enabled'])) {
|
|
|
|
|
$nb++; // $val['enabled'] is already evaluated to 0 or 1, no need for dol_eval()
|
|
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
return $nb;
|
|
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
}
|