dolibarr/htdocs/core/class/menu.class.php

100 lines
3.3 KiB
PHP
Raw Normal View History

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>
* 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
* 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
*/
/**
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
/**
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
{
var $liste;
2002-05-09 16:57:48 +02:00
/**
2011-09-11 20:35:38 +02:00
* Constructor
*/
function __construct()
{
2009-07-28 00:48:05 +02:00
$this->liste = array();
}
2002-05-09 16:57:48 +02:00
/**
2011-10-16 01:59:12 +02:00
* Clear property ->liste
*
* @return void
*/
function clear()
{
$this->liste = array();
}
2002-05-09 16:57:48 +02:00
/**
* Add a menu entry into this->liste (at end)
2011-10-16 01:59:12 +02:00
*
* @param string $url Url to follow on click
* @param string $titre Label of menu to add
* @param string $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)
2011-10-16 01:59:12 +02:00
* @param string $target Target lien
2012-01-03 20:27:10 +01:00
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
2011-10-16 01:59:12 +02:00
* @return void
*/
2012-01-03 20:27:10 +01:00
function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='')
{
$this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu);
}
/**
* 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
* @param string $level Level of menu to add
* @param int $enabled Menu active or not
* @param string $target Target lien
* @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
* @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
* @return void
*/
function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='')
{
$array_start = array_slice($this->liste,0,($idafter+1));
$array_new = array(0=>array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu));
$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
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
}
2002-05-09 16:57:48 +02:00
}