eldy_menu.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007-2009 Regis Houssin <regis.houssin@capnetworks.com>
  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/menus/standard/eldy_menu.php
  20. * \brief Menu eldy manager
  21. */
  22. /**
  23. * Class to manage menu Eldy
  24. */
  25. class MenuManager
  26. {
  27. var $db;
  28. var $type_user; // Put 0 for internal users, 1 for external users
  29. var $atarget=""; // To store default target to use onto links
  30. var $name="eldy";
  31. var $menu_array;
  32. var $menu_array_after;
  33. var $tabMenu;
  34. /**
  35. * Constructor
  36. *
  37. * @param DoliDB $db Database handler
  38. * @param int $type_user Type of user
  39. */
  40. function __construct($db, $type_user)
  41. {
  42. $this->type_user=$type_user;
  43. $this->db=$db;
  44. }
  45. /**
  46. * Load this->tabMenu
  47. *
  48. * @param string $forcemainmenu To force mainmenu to load
  49. * @param string $forceleftmenu To force leftmenu to load
  50. * @return void
  51. */
  52. function loadMenu($forcemainmenu='',$forceleftmenu='')
  53. {
  54. // On sauve en session le menu principal choisi
  55. if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"];
  56. if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"];
  57. // Read mainmenu and leftmenu that define which menu to show
  58. if (isset($_GET["mainmenu"]))
  59. {
  60. // On sauve en session le menu principal choisi
  61. $mainmenu=$_GET["mainmenu"];
  62. $_SESSION["mainmenu"]=$mainmenu;
  63. $_SESSION["leftmenuopened"]="";
  64. }
  65. else
  66. {
  67. // On va le chercher en session si non defini par le lien
  68. $mainmenu=isset($_SESSION["mainmenu"])?$_SESSION["mainmenu"]:'';
  69. }
  70. if (! empty($forcemainmenu)) $mainmenu=$forcemainmenu;
  71. if (isset($_GET["leftmenu"]))
  72. {
  73. // On sauve en session le menu principal choisi
  74. $leftmenu=$_GET["leftmenu"];
  75. $_SESSION["leftmenu"]=$leftmenu;
  76. if ($_SESSION["leftmenuopened"]==$leftmenu) // To collapse
  77. {
  78. //$leftmenu="";
  79. $_SESSION["leftmenuopened"]="";
  80. }
  81. else
  82. {
  83. $_SESSION["leftmenuopened"]=$leftmenu;
  84. }
  85. } else {
  86. // On va le chercher en session si non defini par le lien
  87. $leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:'';
  88. }
  89. if (! empty($forceleftmenu)) $leftmenu=$forceleftmenu;
  90. require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
  91. $tabMenu=array();
  92. $menuArbo = new Menubase($this->db,'eldy');
  93. $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu);
  94. $this->tabMenu=$tabMenu;
  95. //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
  96. }
  97. /**
  98. * Show menu
  99. *
  100. * @param string $mode 'top', 'topnb', 'left', 'jmobile'
  101. * @param array $moredata An array with more data to output
  102. * @return int 0 or nb of top menu entries if $mode = 'topnb'
  103. */
  104. function showmenu($mode, $moredata=null)
  105. {
  106. global $conf, $langs, $user;
  107. require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
  108. if ($this->type_user == 1)
  109. {
  110. $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED=0;
  111. $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED=1;
  112. }
  113. require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
  114. $this->menu=new Menu();
  115. if (empty($conf->global->MAIN_MENU_INVERT))
  116. {
  117. if ($mode == 'top') print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode);
  118. if ($mode == 'left') print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0,'','',$moredata);
  119. }
  120. else
  121. {
  122. $conf->global->MAIN_SHOW_LOGO=0;
  123. if ($mode == 'top') print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0);
  124. if ($mode == 'left') print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode);
  125. }
  126. if ($mode == 'topnb')
  127. {
  128. print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); // no output
  129. return $this->menu->getNbOfVisibleMenuEntries();
  130. }
  131. if ($mode == 'jmobile')
  132. {
  133. print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); // Fill this->menu that is empty with top menu
  134. // $this->menu->liste is top menu
  135. //var_dump($this->menu->liste);exit;
  136. print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
  137. foreach($this->menu->liste as $key => $val) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
  138. {
  139. print '<ul class="ulmenu" data-inset="true">';
  140. print '<li class="lilevel0">';
  141. if ($val['enabled'] == 1)
  142. {
  143. $relurl=dol_buildpath($val['url'],1);
  144. $relurl=preg_replace('/__LOGIN__/',$user->login,$relurl);
  145. $relurl=preg_replace('/__USERID__/',$user->id,$relurl);
  146. print '<a class="alilevel0" href="#">';
  147. // Add font-awesome
  148. if ($val['level'] == 0 && $val['mainmenu'] == 'home') print '<span class="fa fa-home fa-fw paddingright" aria-hidden="true"></span>';
  149. print $val['titre'];
  150. print '</a>'."\n";
  151. // Search submenu fot this mainmenu entry
  152. $tmpmainmenu=$val['mainmenu'];
  153. $tmpleftmenu='all';
  154. $submenu=new Menu();
  155. print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$submenu,1,$tmpmainmenu,$tmpleftmenu); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home)
  156. //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') { var_dump($submenu); exit; }
  157. //if ($tmpmainmenu=='accountancy') { var_dump($submenu->liste); exit; }
  158. $nexturl=dol_buildpath($submenu->liste[0]['url'],1);
  159. $canonrelurl=preg_replace('/\?.*$/','',$relurl);
  160. $canonnexturl=preg_replace('/\?.*$/','',$nexturl);
  161. //var_dump($canonrelurl);
  162. //var_dump($canonnexturl);
  163. print '<ul>'."\n";
  164. if (($canonrelurl != $canonnexturl && ! in_array($val['mainmenu'],array('tools')))
  165. || (strpos($canonrelurl,'/product/index.php') !== false || strpos($canonrelurl,'/compta/bank/index.php') !== false))
  166. {
  167. // We add sub entry
  168. print str_pad('',1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
  169. print '<a href="'.$relurl.'"';
  170. //print ' data-ajax="false"';
  171. print '>';
  172. if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") // No translation
  173. {
  174. if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) print $langs->trans("Access");
  175. else print $langs->trans("Dashboard");
  176. }
  177. else print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
  178. print '</a>';
  179. print '</li>'."\n";
  180. }
  181. foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu']
  182. {
  183. $showmenu=true;
  184. if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) $showmenu=false;
  185. if ($showmenu) // Visible (option to hide when not allowed is off or allowed)
  186. {
  187. $relurl2=dol_buildpath($val2['url'],1);
  188. $relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2);
  189. $relurl2=preg_replace('/__USERID__/',$user->id,$relurl2);
  190. $canonurl2=preg_replace('/\?.*$/','',$val2['url']);
  191. //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
  192. if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2='';
  193. if ($val2['level']==0) print str_pad('',$val2['level']+1).'<li class="lilevel'.($val2['level']+1).' ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
  194. else print str_pad('',$val2['level']+1).'<li class="lilevel'.($val2['level']+1).'">'; // ui-btn to highlight on clic
  195. if ($relurl2)
  196. {
  197. if ($val2['enabled']) // Allowed
  198. {
  199. print '<a href="'.$relurl2.'"';
  200. //print ' data-ajax="false"';
  201. print '>';
  202. }
  203. else // Not allowed but visible (greyed)
  204. {
  205. print '<a href="#" class="vsmenudisabled">';
  206. }
  207. }
  208. print $val2['titre'];
  209. if ($relurl2)
  210. {
  211. if ($val2['enabled']) // Allowed
  212. print '</a>';
  213. else
  214. print '</a>';
  215. }
  216. print '</li>'."\n";
  217. }
  218. }
  219. //var_dump($submenu);
  220. print '</ul>';
  221. }
  222. if ($val['enabled'] == 2)
  223. {
  224. print '<font class="vsmenudisabled">'.$val['titre'].'</font>';
  225. }
  226. print '</li>';
  227. print '</ul>'."\n";
  228. }
  229. }
  230. unset($this->menu);
  231. //print 'xx'.$mode;
  232. return 0;
  233. }
  234. }