auguria_menu.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  3. * Copyright (C) 2009 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/menus/standard/auguria_menu.php
  21. * \brief Menu auguria manager
  22. */
  23. /**
  24. * Class to manage menu Auguria
  25. */
  26. class MenuManager
  27. {
  28. /**
  29. * @var DoliDB Database handler.
  30. */
  31. public $db;
  32. public $type_user; // Put 0 for internal users, 1 for external users
  33. public $atarget = ""; // To store default target to use onto links
  34. public $name = "auguria";
  35. public $menu_array;
  36. public $menu_array_after;
  37. public $tabMenu;
  38. /**
  39. * Constructor
  40. *
  41. * @param DoliDB $db Database handler
  42. * @param int $type_user Type of user
  43. */
  44. public function __construct($db, $type_user)
  45. {
  46. $this->type_user = $type_user;
  47. $this->db = $db;
  48. }
  49. /**
  50. * Load this->tabMenu
  51. *
  52. * @param string $forcemainmenu To force mainmenu to load
  53. * @param string $forceleftmenu To force leftmenu to load
  54. * @return void
  55. */
  56. public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
  57. {
  58. global $conf, $user, $langs;
  59. // On sauve en session le menu principal choisi
  60. if (GETPOSTISSET("mainmenu")) {
  61. $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
  62. }
  63. if (GETPOSTISSET("idmenu")) {
  64. $_SESSION["idmenu"] = GETPOST("idmenu", 'int');
  65. }
  66. // Read mainmenu and leftmenu that define which menu to show
  67. if (GETPOSTISSET("mainmenu")) {
  68. // On sauve en session le menu principal choisi
  69. $mainmenu = GETPOST("mainmenu", 'aZ09');
  70. $_SESSION["mainmenu"] = $mainmenu;
  71. $_SESSION["leftmenuopened"] = "";
  72. } else {
  73. // On va le chercher en session si non defini par le lien
  74. $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
  75. }
  76. if (!empty($forcemainmenu)) {
  77. $mainmenu = $forcemainmenu;
  78. }
  79. if (GETPOSTISSET("leftmenu")) {
  80. // On sauve en session le menu principal choisi
  81. $leftmenu = GETPOST("leftmenu", 'aZ09');
  82. $_SESSION["leftmenu"] = $leftmenu;
  83. if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
  84. //$leftmenu="";
  85. $_SESSION["leftmenuopened"] = "";
  86. } else {
  87. $_SESSION["leftmenuopened"] = $leftmenu;
  88. }
  89. } else {
  90. // On va le chercher en session si non defini par le lien
  91. $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
  92. }
  93. if (!empty($forceleftmenu)) {
  94. $leftmenu = $forceleftmenu;
  95. }
  96. require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
  97. $tabMenu = array();
  98. $menuArbo = new Menubase($this->db, 'auguria');
  99. $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
  100. $this->tabMenu = $tabMenu;
  101. //var_dump($tabMenu);
  102. //if ($forcemainmenu == 'all') {
  103. //var_dump($this->tabMenu);
  104. //}
  105. }
  106. /**
  107. * Show menu.
  108. * Menu defined in sql tables were stored into $this->tabMenu BEFORE this is called.
  109. *
  110. * @param string $mode 'top', 'topnb', 'left', 'jmobile' (used to get full xml ul/li menu)
  111. * @param array $moredata An array with more data to output
  112. * @return int 0 or nb of top menu entries if $mode = 'topnb'
  113. */
  114. public function showmenu($mode, $moredata = null)
  115. {
  116. global $conf, $langs, $user;
  117. require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
  118. if ($this->type_user == 1) {
  119. $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
  120. $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
  121. }
  122. require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
  123. $this->menu = new Menu();
  124. if (empty($conf->global->MAIN_MENU_INVERT)) {
  125. if ($mode == 'top') {
  126. print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
  127. }
  128. if ($mode == 'left') {
  129. print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata);
  130. }
  131. } else {
  132. $conf->global->MAIN_SHOW_LOGO = 0;
  133. if ($mode == 'top') {
  134. print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
  135. }
  136. if ($mode == 'left') {
  137. print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
  138. }
  139. }
  140. if ($mode == 'topnb') {
  141. print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
  142. return $this->menu->getNbOfVisibleMenuEntries();
  143. }
  144. if ($mode == 'jmobile') { // Used to get menu in xml ul/li
  145. print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
  146. // $this->menu->liste is top menu
  147. //var_dump($this->menu->liste);exit;
  148. $lastlevel = array();
  149. print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
  150. foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
  151. print '<ul class="ulmenu" data-inset="true">';
  152. print '<li class="lilevel0">';
  153. if ($val['enabled'] == 1) {
  154. $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
  155. $substitarray['__USERID__'] = $user->id; // For backward compatibility
  156. $val['url'] = make_substitutions($val['url'], $substitarray);
  157. $relurl = dol_buildpath($val['url'], 1);
  158. $canonurl = preg_replace('/\?.*$/', '', $val['url']);
  159. print '<a class="alilevel0" href="#">';
  160. // Add font-awesome
  161. if ($val['level'] == 0 && !empty($val['prefix'])) {
  162. print $val['prefix'];
  163. } elseif ($val['level'] == 0 && $val['mainmenu'] == 'home') {
  164. print '<span class="fa fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
  165. }
  166. print $val['titre'];
  167. print '</a>'."\n";
  168. // Search submenu fot this mainmenu entry
  169. $tmpmainmenu = $val['mainmenu'];
  170. $tmpleftmenu = 'all';
  171. $submenu = new Menu();
  172. print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu);
  173. $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
  174. $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
  175. $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
  176. //var_dump($canonrelurl);
  177. //var_dump($canonnexturl);
  178. print '<ul>'."\n";
  179. if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
  180. || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
  181. // We add sub entry
  182. print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
  183. print '<a href="'.$relurl.'">';
  184. if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
  185. if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab'))) {
  186. print $langs->trans("Access");
  187. } else {
  188. print $langs->trans("Dashboard");
  189. }
  190. } else {
  191. print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
  192. }
  193. print '</a>';
  194. print '</li>'."\n";
  195. }
  196. if ($val['level'] == 0) {
  197. if ($val['enabled']) {
  198. $lastlevel[0] = 'enabled';
  199. } elseif ($showmenu) { // Not enabled but visible (so greyed)
  200. $lastlevel[0] = 'greyed';
  201. } else {
  202. $lastlevel[0] = 'hidden';
  203. }
  204. }
  205. $lastlevel2 = array();
  206. foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
  207. $showmenu = true;
  208. if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) {
  209. $showmenu = false;
  210. }
  211. // If at least one parent is not enabled, we do not show any menu of all children
  212. if ($val2['level'] > 0) {
  213. $levelcursor = $val2['level'] - 1;
  214. while ($levelcursor >= 0) {
  215. if ($lastlevel2[$levelcursor] != 'enabled') {
  216. $showmenu = false;
  217. }
  218. $levelcursor--;
  219. }
  220. }
  221. if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
  222. $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
  223. $substitarray['__USERID__'] = $user->id; // For backward compatibility
  224. $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
  225. if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
  226. $relurl2 = dol_buildpath($val2['url'], 1);
  227. } else {
  228. $relurl2 = $val2['url'];
  229. }
  230. $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
  231. //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
  232. if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
  233. $relurl2 = '';
  234. }
  235. $disabled = '';
  236. if (!$val2['enabled']) {
  237. $disabled = " vsmenudisabled";
  238. }
  239. print str_pad('', $val2['level'] + 1);
  240. print '<li class="lilevel'.($val2['level'] + 1);
  241. if ($val2['level'] == 0) {
  242. print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
  243. }
  244. print $disabled.'">'; // ui-btn to highlight on clic
  245. if ($relurl2) {
  246. if ($val2['enabled']) { // Allowed
  247. print '<a href="'.$relurl2.'"';
  248. //print ' data-ajax="false"';
  249. print '>';
  250. $lastlevel2[$val2['level']] = 'enabled';
  251. } else { // Not allowed but visible (greyed)
  252. print '<a href="#" class="vsmenudisabled">';
  253. $lastlevel2[$val2['level']] = 'greyed';
  254. }
  255. } else {
  256. if ($val2['enabled']) { // Allowed
  257. $lastlevel2[$val2['level']] = 'enabled';
  258. } else {
  259. $lastlevel2[$val2['level']] = 'greyed';
  260. }
  261. }
  262. if ($val2['level'] == 0 && !empty($val2['prefix'])) {
  263. print $val2['prefix'];
  264. } else {
  265. print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
  266. }
  267. print $val2['titre'];
  268. if ($relurl2) {
  269. if ($val2['enabled']) { // Allowed
  270. print '</a>';
  271. } else {
  272. print '</a>';
  273. }
  274. }
  275. print '</li>'."\n";
  276. }
  277. }
  278. //var_dump($submenu);
  279. print '</ul>';
  280. }
  281. if ($val['enabled'] == 2) {
  282. print '<span class="spanlilevel0 vsmenudisabled">';
  283. // Add font-awesome
  284. if ($val['level'] == 0 && !empty($val['prefix'])) {
  285. print $val['prefix'];
  286. }
  287. print $val['titre'];
  288. print '</span>';
  289. }
  290. print '</li>';
  291. print '</ul>'."\n";
  292. }
  293. }
  294. unset($this->menu);
  295. //print 'xx'.$mode;
  296. return 0;
  297. }
  298. }