auguria.lib.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. /* Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.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 <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/menus/standard/auguria.lib.php
  21. * \brief Library for file auguria menus
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
  24. /**
  25. * Core function to output top menu auguria
  26. *
  27. * @param DoliDB $db Database handler
  28. * @param string $atarget Target (Example: '' or '_top')
  29. * @param int $type_user 0=Menu for backoffice, 1=Menu for front office
  30. * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
  31. * @param Menu $menu Object Menu to return back list of menu entries
  32. * @param int $noout 1=Disable output (Initialise &$menu only).
  33. * @param string $mode 'top', 'topnb', 'left', 'jmobile'
  34. * @return int 0
  35. */
  36. function print_auguria_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout = 0, $mode = '')
  37. {
  38. global $user, $conf, $langs, $mysoc;
  39. global $dolibarr_main_db_name;
  40. $mainmenu = (empty($_SESSION["mainmenu"]) ? '' : $_SESSION["mainmenu"]);
  41. $leftmenu = (empty($_SESSION["leftmenu"]) ? '' : $_SESSION["leftmenu"]);
  42. $id = 'mainmenu';
  43. $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
  44. // Show personalized menus
  45. $menuArbo = new Menubase($db, 'auguria');
  46. $newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'auguria', $tabMenu);
  47. $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
  48. if (empty($noout)) print_start_menu_array_auguria();
  49. global $usemenuhider;
  50. $usemenuhider = 1;
  51. // Show/Hide vertical menu. The hamburger icon for .menuhider action.
  52. if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  53. {
  54. $showmode = 1;
  55. $classname = 'class="tmenu menuhider"';
  56. $idsel = 'menu';
  57. $menu->add('#', (!empty($conf->global->THEME_TOPMENU_DISABLE_IMAGE) ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
  58. }
  59. $num = count($newTabMenu);
  60. for ($i = 0; $i < $num; $i++)
  61. {
  62. $idsel = (empty($newTabMenu[$i]['mainmenu']) ? 'none' : $newTabMenu[$i]['mainmenu']);
  63. $showmode = dol_auguria_showmenu($type_user, $newTabMenu[$i], $listofmodulesforexternal);
  64. if ($showmode == 1)
  65. {
  66. $newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);
  67. $url = $shorturl = $newTabMenu[$i]['url'];
  68. if (!preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url']))
  69. {
  70. $tmp = explode('?', $newTabMenu[$i]['url'], 2);
  71. $url = $shorturl = $tmp[0];
  72. $param = (isset($tmp[1]) ? $tmp[1] : '');
  73. // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
  74. if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($newTabMenu[$i]['url']))
  75. {
  76. $param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
  77. }
  78. if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($newTabMenu[$i]['url']))
  79. {
  80. $param .= ($param ? '&' : '').'leftmenu=';
  81. }
  82. //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
  83. $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
  84. //$shorturl = $shorturl.($param?'?'.$param:'');
  85. $shorturl = $url;
  86. if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
  87. }
  88. // TODO Find a generic solution
  89. if (preg_match('/search_project_user=__search_project_user__/', $shorturl))
  90. {
  91. $search_project_user = GETPOST('search_project_user', 'int');
  92. if ($search_project_user) $shorturl = preg_replace('/search_project_user=__search_project_user__/', 'search_project_user='.$search_project_user, $shorturl);
  93. else $shorturl = preg_replace('/search_project_user=__search_project_user__/', '', $shorturl);
  94. }
  95. // Define the class (top menu selected or not)
  96. if (!empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname = 'class="tmenusel"';
  97. elseif (!empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname = 'class="tmenusel"';
  98. else $classname = 'class="tmenu"';
  99. } elseif ($showmode == 2) $classname = 'class="tmenu"';
  100. $menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target'] ? $newTabMenu[$i]['target'] : $atarget), ($newTabMenu[$i]['mainmenu'] ? $newTabMenu[$i]['mainmenu'] : $newTabMenu[$i]['rowid']), ($newTabMenu[$i]['leftmenu'] ? $newTabMenu[$i]['leftmenu'] : ''), $newTabMenu[$i]['position'], $id, $idsel, $classname);
  101. }
  102. // Sort on position
  103. $menu->liste = dol_sort_array($menu->liste, 'position');
  104. // Output menu entries
  105. // Show logo company
  106. if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  107. {
  108. //$mysoc->logo_mini=(empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI);
  109. $mysoc->logo_squarred_mini = (empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI);
  110. $logoContainerAdditionalClass = 'backgroundforcompanylogo';
  111. if (!empty($conf->global->MAIN_INFO_SOCIETE_LOGO_NO_BACKGROUND)) {
  112. $logoContainerAdditionalClass = '';
  113. }
  114. if (!empty($mysoc->logo_squarred_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini))
  115. {
  116. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini);
  117. }
  118. /*elseif (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
  119. {
  120. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_mini);
  121. }*/
  122. else {
  123. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_512x512_white.png';
  124. $logoContainerAdditionalClass = '';
  125. }
  126. $title = $langs->trans("GoIntoSetupToChangeLogo");
  127. print "\n".'<!-- Show logo on menu -->'."\n";
  128. print_start_menu_entry_auguria('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1);
  129. print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n";
  130. print_end_menu_entry_auguria(4);
  131. }
  132. if (empty($noout)) {
  133. foreach ($menu->liste as $menuval) {
  134. print_start_menu_entry_auguria($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
  135. print_text_menu_entry_auguria($menuval['titre'], $menuval['enabled'], ($menuval['url'] != '#' ?DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $atarget));
  136. print_end_menu_entry_auguria($menuval['enabled']);
  137. }
  138. }
  139. $showmode = 1;
  140. if (empty($noout)) {
  141. print_start_menu_entry_auguria('', 'class="tmenuend"', $showmode);
  142. print_end_menu_entry_auguria($showmode);
  143. print_end_menu_array_auguria();
  144. }
  145. return 0;
  146. }
  147. /**
  148. * Output start menu array
  149. *
  150. * @return void
  151. */
  152. function print_start_menu_array_auguria()
  153. {
  154. global $conf;
  155. print '<div class="tmenudiv">';
  156. print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Top menu"').'>';
  157. }
  158. /**
  159. * Output start menu entry
  160. *
  161. * @param string $idsel Text
  162. * @param string $classname String to add a css class
  163. * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed
  164. * @return void
  165. */
  166. function print_start_menu_entry_auguria($idsel, $classname, $showmode)
  167. {
  168. if ($showmode)
  169. {
  170. print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
  171. //print '<div class="tmenuleft tmenusep"></div>';
  172. print '<div class="tmenucenter">';
  173. }
  174. }
  175. /**
  176. * Output menu entry
  177. *
  178. * @param string $text Text
  179. * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed
  180. * @param string $url Url
  181. * @param string $id Id
  182. * @param string $idsel Id sel
  183. * @param string $classname Class name
  184. * @param string $atarget Target
  185. * @return void
  186. */
  187. function print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $classname, $atarget)
  188. {
  189. global $langs;
  190. if ($showmode == 1) {
  191. print '<a class="tmenuimage" tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
  192. print '<div class="'.$id.' '.$idsel.' topmenuimage"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>';
  193. print '</a>';
  194. print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
  195. print '<span class="mainmenuaspan">';
  196. print $text;
  197. print '</span>';
  198. print '</a>';
  199. } elseif ($showmode == 2) {
  200. print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled"><span class="'.$id.'" id="mainmenuspan_'.$idsel.'"></span></div>';
  201. print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">';
  202. print '<span class="mainmenuaspan">';
  203. print $text;
  204. print '</span>';
  205. print '</a>';
  206. }
  207. }
  208. /**
  209. * Output end menu entry
  210. *
  211. * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed
  212. * @return void
  213. */
  214. function print_end_menu_entry_auguria($showmode)
  215. {
  216. if ($showmode)
  217. {
  218. print '</div></li>';
  219. }
  220. print "\n";
  221. }
  222. /**
  223. * Output menu array
  224. *
  225. * @return void
  226. */
  227. function print_end_menu_array_auguria()
  228. {
  229. print '</ul>';
  230. print '</div>';
  231. print "\n";
  232. }
  233. /**
  234. * Core function to output left menu auguria
  235. * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home)
  236. *
  237. * @param DoliDB $db Database handler
  238. * @param array $menu_array_before Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add)
  239. * @param array $menu_array_after Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add)
  240. * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
  241. * @param Menu $menu Object Menu to return back list of menu entries
  242. * @param int $noout Disable output (Initialise &$menu only).
  243. * @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x'
  244. * @param string $forceleftmenu 'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not defined in session.
  245. * @param array $moredata An array with more data to output
  246. * @return int Nb of menu entries
  247. */
  248. function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null)
  249. {
  250. global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
  251. $newmenu = $menu;
  252. $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]);
  253. $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]));
  254. global $usemenuhider;
  255. $usemenuhider = 0;
  256. if (is_array($moredata) && !empty($moredata['searchform'])) // searchform can contains select2 code or link to show old search form or link to switch on search page
  257. {
  258. print "\n";
  259. print "<!-- Begin SearchForm -->\n";
  260. print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
  261. print $moredata['searchform'];
  262. print '</div>'."\n";
  263. print "<!-- End SearchForm -->\n";
  264. }
  265. if (is_array($moredata) && !empty($moredata['bookmarks']))
  266. {
  267. print "\n";
  268. print "<!-- Begin Bookmarks -->\n";
  269. print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
  270. print $moredata['bookmarks'];
  271. print '</div>'."\n";
  272. print "<!-- End Bookmarks -->\n";
  273. }
  274. $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
  275. // We update newmenu with entries found into database
  276. $menuArbo = new Menubase($db, 'auguria');
  277. $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, ($user->socid ? 1 : 0), 'auguria', $tabMenu);
  278. // We update newmenu for special dynamic menus
  279. if ($conf->banque->enabled && $user->rights->banque->lire && $mainmenu == 'bank') // Entry for each bank account
  280. {
  281. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example
  282. $sql = "SELECT rowid, label, courant, rappro, courant";
  283. $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
  284. $sql .= " WHERE entity = ".$conf->entity;
  285. $sql .= " AND clos = 0";
  286. $sql .= " ORDER BY label";
  287. $resql = $db->query($sql);
  288. if ($resql)
  289. {
  290. $numr = $db->num_rows($resql);
  291. $i = 0;
  292. if ($numr > 0) $newmenu->add('/compta/bank/list.php', $langs->trans("BankAccounts"), 0, $user->rights->banque->lire);
  293. while ($i < $numr)
  294. {
  295. $objp = $db->fetch_object($resql);
  296. $newmenu->add('/compta/bank/card.php?id='.$objp->rowid, $objp->label, 1, $user->rights->banque->lire);
  297. if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) // If not cash account and not closed and can be reconciliate
  298. {
  299. $newmenu->add('/compta/bank/bankentries_list.php?id='.$objp->rowid, $langs->trans("Conciliate"), 2, $user->rights->banque->consolidate);
  300. }
  301. $i++;
  302. }
  303. } else dol_print_error($db);
  304. $db->free($resql);
  305. }
  306. if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') // Entry in accountancy journal for each bank account
  307. {
  308. $newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->rights->accounting->comptarapport->lire, '', 'accountancy', 'accountancy', 10);
  309. // Multi journal
  310. $sql = "SELECT rowid, code, label, nature";
  311. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
  312. $sql .= " WHERE entity = ".$conf->entity;
  313. $sql .= " AND active = 1";
  314. $sql .= " ORDER BY label DESC";
  315. $resql = $db->query($sql);
  316. if ($resql)
  317. {
  318. $numr = $db->num_rows($resql);
  319. $i = 0;
  320. if ($numr > 0)
  321. {
  322. while ($i < $numr)
  323. {
  324. $objp = $db->fetch_object($resql);
  325. $nature = '';
  326. // Must match array $sourceList defined into journals_list.php
  327. if ($objp->nature == 2 && !empty($conf->facture->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_SALES)) $nature = "sells";
  328. if ($objp->nature == 3
  329. && (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled))
  330. && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_PURCHASES))
  331. $nature = "purchases";
  332. if ($objp->nature == 4 && !empty($conf->banque->enabled)) $nature = "bank";
  333. if ($objp->nature == 5 && !empty($conf->expensereport->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS)) $nature = "expensereports";
  334. if ($objp->nature == 1) $nature = "various";
  335. if ($objp->nature == 8) $nature = "inventory";
  336. if ($objp->nature == 9) $nature = "hasnew";
  337. // To enable when page exists
  338. if (empty($conf->global->ACCOUNTANCY_SHOW_DEVELOP_JOURNAL))
  339. {
  340. if ($nature == 'various' || $nature == 'hasnew' || $nature == 'inventory') $nature = '';
  341. }
  342. if ($nature)
  343. {
  344. $langs->load('accountancy');
  345. $journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ...
  346. $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, $journallabel, 2, $user->rights->accounting->comptarapport->lire);
  347. }
  348. $i++;
  349. }
  350. } else {
  351. // Should not happend. Entries are added
  352. $newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->rights->accounting->comptarapport->lire);
  353. }
  354. } else dol_print_error($db);
  355. $db->free($resql);
  356. }
  357. if (!empty($conf->ftp->enabled) && $mainmenu == 'ftp') // Entry for FTP
  358. {
  359. $MAXFTP = 20;
  360. $i = 1;
  361. while ($i <= $MAXFTP)
  362. {
  363. $paramkey = 'FTP_NAME_'.$i;
  364. //print $paramkey;
  365. if (!empty($conf->global->$paramkey))
  366. {
  367. $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i;
  368. $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24));
  369. }
  370. $i++;
  371. }
  372. }
  373. // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
  374. //var_dump($menu_array_before);exit;
  375. //var_dump($menu_array_after);exit;
  376. $menu_array = $newmenu->liste;
  377. if (is_array($menu_array_before)) $menu_array = array_merge($menu_array_before, $menu_array);
  378. if (is_array($menu_array_after)) $menu_array = array_merge($menu_array, $menu_array_after);
  379. //var_dump($menu_array);exit;
  380. if (!is_array($menu_array)) return 0;
  381. // Show menu
  382. $invert = empty($conf->global->MAIN_MENU_INVERT) ? "" : "invert";
  383. if (empty($noout))
  384. {
  385. $altok = 0; $blockvmenuopened = false; $lastlevel0 = '';
  386. $num = count($menu_array);
  387. for ($i = 0; $i < $num; $i++) // Loop on each menu entry
  388. {
  389. $showmenu = true;
  390. if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) $showmenu = false;
  391. // Begin of new left menu block
  392. if (empty($menu_array[$i]['level']) && $showmenu)
  393. {
  394. $altok++;
  395. $blockvmenuopened = true;
  396. $lastopened = true;
  397. for ($j = ($i + 1); $j < $num; $j++)
  398. {
  399. if (empty($menu_array[$j]['level'])) $lastopened = false;
  400. }
  401. if ($altok % 2 == 0)
  402. {
  403. print '<div class="blockvmenu blockvmenuimpair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
  404. } else {
  405. print '<div class="blockvmenu blockvmenupair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
  406. }
  407. }
  408. // Add tabulation
  409. $tabstring = '';
  410. $tabul = ($menu_array[$i]['level'] - 1);
  411. if ($tabul > 0)
  412. {
  413. for ($j = 0; $j < $tabul; $j++)
  414. {
  415. $tabstring .= '&nbsp;&nbsp;&nbsp;';
  416. }
  417. }
  418. // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
  419. $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);
  420. $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url'];
  421. if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url']))
  422. {
  423. $tmp = explode('?', $menu_array[$i]['url'], 2);
  424. $url = $shorturl = $tmp[0];
  425. $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
  426. // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
  427. if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu']))
  428. {
  429. $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
  430. }
  431. if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu']))
  432. {
  433. $param .= ($param ? '&' : '').'leftmenu=';
  434. }
  435. //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad
  436. $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
  437. $shorturlwithoutparam = $shorturl;
  438. $shorturl = $shorturl.($param ? '?'.$param : '');
  439. }
  440. print '<!-- Process menu entry with mainmenu='.$menu_array[$i]['mainmenu'].', leftmenu='.$menu_array[$i]['leftmenu'].', level='.$menu_array[$i]['level'].' enabled='.$menu_array[$i]['enabled'].', position='.$menu_array[$i]['position'].' -->'."\n";
  441. // Menu level 0
  442. if ($menu_array[$i]['level'] == 0)
  443. {
  444. if ($menu_array[$i]['enabled']) // Enabled so visible
  445. {
  446. print '<div class="menu_titre">'.$tabstring;
  447. if ($shorturlwithoutparam) print '<a class="vmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
  448. else print '<span class="vmenu">';
  449. print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '').$menu_array[$i]['titre'];
  450. if ($shorturlwithoutparam) print '</a>';
  451. else print '</span>';
  452. print '</div>'."\n";
  453. $lastlevel0 = 'enabled';
  454. } elseif ($showmenu) // Not enabled but visible (so greyed)
  455. {
  456. print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>'."\n";
  457. $lastlevel0 = 'greyed';
  458. } else {
  459. $lastlevel0 = 'hidden';
  460. }
  461. if ($showmenu)
  462. {
  463. print '<div class="menu_top"></div>'."\n";
  464. }
  465. }
  466. // Menu level > 0
  467. if ($menu_array[$i]['level'] > 0)
  468. {
  469. $cssmenu = '';
  470. if ($menu_array[$i]['url']) $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
  471. if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') // Enabled so visible, except if parent was not enabled.
  472. {
  473. print '<div class="menu_contenu'.$cssmenu.'">'.$tabstring;
  474. if ($shorturlwithoutparam) print '<a class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
  475. else print '<span class="vsmenu">';
  476. print $menu_array[$i]['titre'];
  477. if ($shorturlwithoutparam) print '</a>';
  478. else print '</span>';
  479. // If title is not pure text and contains a table, no carriage return added
  480. if (!strstr($menu_array[$i]['titre'], '<table')) print '<br>';
  481. print '</div>'."\n";
  482. } elseif ($showmenu && $lastlevel0 == 'enabled') // Not enabled but visible (so greyed), except if parent was not enabled.
  483. {
  484. print '<div class="menu_contenu'.$cssmenu.'">'.$tabstring.'<font class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</font><br></div>'."\n";
  485. }
  486. }
  487. // If next is a new block or if there is nothing after
  488. if (empty($menu_array[$i + 1]['level'])) // End menu block
  489. {
  490. if ($showmenu)
  491. print '<div class="menu_end"></div>'."\n";
  492. if ($blockvmenuopened) { print '</div>'."\n"; $blockvmenuopened = false; }
  493. }
  494. }
  495. if ($altok) print '<div class="blockvmenuend"></div>'; // End menu block
  496. }
  497. return count($menu_array);
  498. }
  499. /**
  500. * Function to test if an entry is enabled or not
  501. *
  502. * @param string $type_user 0=We need backoffice menu, 1=We need frontoffice menu
  503. * @param array $menuentry Array for menu entry
  504. * @param array $listofmodulesforexternal Array with list of modules allowed to external users
  505. * @return int 0=Hide, 1=Show, 2=Show gray
  506. */
  507. function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal)
  508. {
  509. global $conf;
  510. //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
  511. //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
  512. if (empty($menuentry['enabled'])) return 0; // Entry disabled by condition
  513. if ($type_user && $menuentry['module'])
  514. {
  515. $tmploops = explode('|', $menuentry['module']);
  516. $found = 0;
  517. foreach ($tmploops as $tmploop)
  518. {
  519. if (in_array($tmploop, $listofmodulesforexternal)) {
  520. $found++; break;
  521. }
  522. }
  523. if (!$found) return 0; // Entry is for menus all excluded to external users
  524. }
  525. if (!$menuentry['perms'] && $type_user) return 0; // No permissions and user is external
  526. if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) return 0; // No permissions and option to hide when not allowed, even for internal user, is on
  527. if (!$menuentry['perms']) return 2; // No permissions and user is external
  528. return 1;
  529. }