menu.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/class/menu.class.php
  20. * \ingroup core
  21. * \brief Fichier de la classe de gestion du menu gauche
  22. */
  23. /**
  24. * Class to manage left menus
  25. */
  26. class Menu
  27. {
  28. var $liste;
  29. /**
  30. * Constructor
  31. */
  32. function __construct()
  33. {
  34. $this->liste = array();
  35. }
  36. /**
  37. * Clear property ->liste
  38. *
  39. * @return void
  40. */
  41. function clear()
  42. {
  43. $this->liste = array();
  44. }
  45. /**
  46. * Add a menu entry into this->liste (at end)
  47. *
  48. * @param string $url Url to follow on click
  49. * @param string $titre Label of menu to add
  50. * @param integer $level Level of menu to add
  51. * @param int $enabled Menu active or not (0=Not active, 1=Active, 2=Active but grey)
  52. * @param string $target Target link
  53. * @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
  54. * @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
  55. * @param int $position Position (not used yet)
  56. * @return void
  57. */
  58. function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0)
  59. {
  60. $this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position);
  61. }
  62. /**
  63. * Insert a menu entry into this->liste
  64. *
  65. * @param int $idafter Array key after which inserting new entry
  66. * @param string $url Url to follow on click
  67. * @param string $titre Label of menu to add
  68. * @param integer $level Level of menu to add
  69. * @param int $enabled Menu active or not
  70. * @param string $target Target link
  71. * @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
  72. * @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
  73. * @param int $position Position (not used yet)
  74. * @return void
  75. */
  76. function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0)
  77. {
  78. $array_start = array_slice($this->liste,0,($idafter+1));
  79. $array_new = array(0=>array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu,'position'=>$position));
  80. $array_end = array_slice($this->liste,($idafter+1));
  81. $this->liste=array_merge($array_start,$array_new,$array_end);
  82. }
  83. /**
  84. * Remove a menu entry from this->liste
  85. *
  86. * @return void
  87. */
  88. function remove_last()
  89. {
  90. if (count($this->liste) > 1) array_pop($this->liste);
  91. }
  92. /**
  93. * Return number of visible entries (gray or not)
  94. *
  95. * @return int Number of visible (gray or not) menu entries
  96. */
  97. function getNbOfVisibleMenuEntries()
  98. {
  99. $nb=0;
  100. foreach($this->liste as $val)
  101. {
  102. if (! empty($val['enabled'])) $nb++;
  103. }
  104. return $nb;
  105. }
  106. }