menu.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 (does not include DOL_URL_ROOT)
  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. * @param string $id Id
  57. * @param string $idsel Id sel
  58. * @param string $classname Class name
  59. * @param string $prefix Prefix to title (image or picto)
  60. * @return void
  61. */
  62. function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
  63. {
  64. $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);
  65. }
  66. /**
  67. * Insert a menu entry into this->liste
  68. *
  69. * @param int $idafter Array key after which inserting new entry
  70. * @param string $url Url to follow on click
  71. * @param string $titre Label of menu to add
  72. * @param integer $level Level of menu to add
  73. * @param int $enabled Menu active or not
  74. * @param string $target Target link
  75. * @param string $mainmenu Main menu ('home', 'companies', 'products', ...)
  76. * @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...)
  77. * @param int $position Position (not used yet)
  78. * @param string $id Id
  79. * @param string $idsel Id sel
  80. * @param string $classname Class name
  81. * @param string $prefix Prefix to title (image or picto)
  82. * @return void
  83. */
  84. function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
  85. {
  86. $array_start = array_slice($this->liste,0,($idafter+1));
  87. $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));
  88. $array_end = array_slice($this->liste,($idafter+1));
  89. $this->liste=array_merge($array_start,$array_new,$array_end);
  90. }
  91. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  92. /**
  93. * Remove a menu entry from this->liste
  94. *
  95. * @return void
  96. */
  97. function remove_last()
  98. {
  99. // phpcs:enable
  100. if (count($this->liste) > 1) {
  101. array_pop($this->liste);
  102. }
  103. }
  104. /**
  105. * Return number of visible entries (gray or not)
  106. *
  107. * @return int Number of visible (gray or not) menu entries
  108. */
  109. function getNbOfVisibleMenuEntries()
  110. {
  111. $nb=0;
  112. foreach($this->liste as $val)
  113. {
  114. if (! empty($val['enabled'])) $nb++;
  115. }
  116. return $nb;
  117. }
  118. }