auguria.lib.php 26 KB

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