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>
|
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
|
2011-08-01 01:45:11 +02:00
|
|
|
* along with this program. If not, see <http://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
|
2009-07-28 00:48:05 +02:00
|
|
|
* \brief Fichier de la classe de gestion du menu gauche
|
|
|
|
|
*/
|
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
|
|
|
|
|
{
|
2005-01-19 23:50:56 +01:00
|
|
|
var $liste;
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2005-01-19 23:50:56 +01:00
|
|
|
/**
|
2011-09-11 20:35:38 +02:00
|
|
|
* Constructor
|
2005-01-19 23:50:56 +01:00
|
|
|
*/
|
2012-07-30 17:17:33 +02:00
|
|
|
function __construct()
|
2005-01-19 23:50:56 +01:00
|
|
|
{
|
2009-07-28 00:48:05 +02:00
|
|
|
$this->liste = array();
|
2005-01-19 23:50:56 +01:00
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2005-01-19 23:50:56 +01:00
|
|
|
/**
|
2011-10-16 01:59:12 +02:00
|
|
|
* Clear property ->liste
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
2005-01-19 23:50:56 +01:00
|
|
|
*/
|
|
|
|
|
function clear()
|
|
|
|
|
{
|
|
|
|
|
$this->liste = array();
|
|
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2005-01-19 23:50:56 +01:00
|
|
|
/**
|
2012-01-04 19:31:46 +01:00
|
|
|
* Add a menu entry into this->liste (at end)
|
2011-10-16 01:59:12 +02:00
|
|
|
*
|
2017-06-27 04:25:41 +02:00
|
|
|
* @param string $url Url to follow on click (does not include DOL_URL_ROOT)
|
2011-10-16 01:59:12 +02:00
|
|
|
* @param string $titre Label of menu to add
|
2015-03-06 03:10:01 +01:00
|
|
|
* @param integer $level Level of menu to add
|
2013-03-05 15:42:26 +01:00
|
|
|
* @param int $enabled Menu active or not (0=Not active, 1=Active, 2=Active but grey)
|
2016-01-31 07:31:48 +01:00
|
|
|
* @param string $target Target link
|
2012-01-03 20:27:10 +01:00
|
|
|
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
|
|
|
|
|
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
|
2015-07-02 22:43:51 +02:00
|
|
|
* @param int $position Position (not used yet)
|
2017-06-27 04:25:41 +02:00
|
|
|
* @param string $id Id
|
|
|
|
|
* @param string $idsel Id sel
|
|
|
|
|
* @param string $classname Class name
|
2017-12-01 12:55:28 +01:00
|
|
|
* @param string $prefix Prefix to title (image or picto)
|
2011-10-16 01:59:12 +02:00
|
|
|
* @return void
|
2005-01-19 23:50:56 +01:00
|
|
|
*/
|
2017-12-01 12:55:28 +01:00
|
|
|
function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
|
2005-01-19 23:50:56 +01:00
|
|
|
{
|
2017-12-01 12:55:28 +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);
|
2012-01-04 19:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert a menu entry into this->liste
|
|
|
|
|
*
|
|
|
|
|
* @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
|
2015-03-06 03:10:01 +01:00
|
|
|
* @param integer $level Level of menu to add
|
2012-01-04 19:31:46 +01:00
|
|
|
* @param int $enabled Menu active or not
|
2016-01-31 07:31:48 +01:00
|
|
|
* @param string $target Target link
|
2012-01-04 19:31:46 +01:00
|
|
|
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
|
|
|
|
|
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
|
2015-07-02 22:43:51 +02:00
|
|
|
* @param int $position Position (not used yet)
|
2017-06-27 04:25:41 +02:00
|
|
|
* @param string $id Id
|
|
|
|
|
* @param string $idsel Id sel
|
|
|
|
|
* @param string $classname Class name
|
2017-12-01 12:55:28 +01:00
|
|
|
* @param string $prefix Prefix to title (image or picto)
|
2012-01-04 19:31:46 +01:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-12-01 12:55:28 +01:00
|
|
|
function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
|
2012-01-04 19:31:46 +01:00
|
|
|
{
|
|
|
|
|
$array_start = array_slice($this->liste,0,($idafter+1));
|
2017-12-01 12:55:28 +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));
|
2012-01-04 19:31:46 +01:00
|
|
|
$array_end = array_slice($this->liste,($idafter+1));
|
|
|
|
|
$this->liste=array_merge($array_start,$array_new,$array_end);
|
2005-01-19 23:50:56 +01:00
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2006-12-04 18:50:54 +01:00
|
|
|
/**
|
2011-10-16 01:59:12 +02:00
|
|
|
* Remove a menu entry from this->liste
|
|
|
|
|
*
|
2012-01-03 20:27:10 +01:00
|
|
|
* @return void
|
2006-12-04 18:50:54 +01:00
|
|
|
*/
|
|
|
|
|
function remove_last()
|
2009-07-28 00:48:05 +02:00
|
|
|
{
|
2011-09-17 21:49:50 +02:00
|
|
|
if (count($this->liste) > 1) array_pop($this->liste);
|
2006-12-04 18:50:54 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-12 00:45:30 +01:00
|
|
|
/**
|
|
|
|
|
* Return number of visible entries (gray or not)
|
2017-06-27 04:25:41 +02:00
|
|
|
*
|
2015-11-12 00:45:30 +01:00
|
|
|
* @return int Number of visible (gray or not) menu entries
|
|
|
|
|
*/
|
|
|
|
|
function getNbOfVisibleMenuEntries()
|
|
|
|
|
{
|
|
|
|
|
$nb=0;
|
|
|
|
|
foreach($this->liste as $val)
|
|
|
|
|
{
|
|
|
|
|
if (! empty($val['enabled'])) $nb++;
|
|
|
|
|
}
|
|
|
|
|
return $nb;
|
|
|
|
|
}
|
2002-05-09 16:57:48 +02:00
|
|
|
}
|