PageRenderTime 121ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/menus/standard/empty.php

http://github.com/Dolibarr/dolibarr
PHP | 556 lines | 366 code | 75 blank | 115 comment | 104 complexity | 714c50a1ea39e237724fa250bf43c421 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/menus/standard/empty.php
  19. * \brief This is an example of an empty top menu handler
  20. */
  21. /**
  22. * Class to manage empty menu
  23. */
  24. class MenuManager
  25. {
  26. /**
  27. * @var DoliDB Database handler.
  28. */
  29. public $db;
  30. public $type_user = 0; // Put 0 for internal users, 1 for external users
  31. public $atarget = ""; // To store default target to use onto links
  32. public $name = "empty";
  33. public $menu;
  34. public $menu_array_after;
  35. public $tabMenu;
  36. /**
  37. * Constructor
  38. *
  39. * @param DoliDB $db Database handler
  40. * @param int $type_user Type of user
  41. */
  42. public function __construct($db, $type_user)
  43. {
  44. $this->type_user = $type_user;
  45. $this->db = $db;
  46. }
  47. /**
  48. * Load this->tabMenu
  49. *
  50. * @param string $forcemainmenu To force mainmenu to load
  51. * @param string $forceleftmenu To force leftmenu to load
  52. * @return void
  53. */
  54. public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
  55. {
  56. // Do nothing
  57. $this->tabMenu = array();
  58. }
  59. /**
  60. * Show menu
  61. *
  62. * @param string $mode 'top', 'left', 'jmobile'
  63. * @param array $moredata An array with more data to output
  64. * @return int 0 or nb of top menu entries if $mode = 'topnb'
  65. */
  66. public function showmenu($mode, $moredata = null)
  67. {
  68. global $user, $conf, $langs, $dolibarr_main_db_name;
  69. $id = 'mainmenu';
  70. require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
  71. $this->menu = new Menu();
  72. $res = 'ErrorBadParameterForMode';
  73. $noout = 0;
  74. //if ($mode == 'jmobile') $noout=1;
  75. if ($mode == 'topnb') {
  76. return 1;
  77. }
  78. if ($mode == 'top') {
  79. if (empty($noout)) {
  80. print_start_menu_array_empty();
  81. }
  82. $usemenuhider = 1;
  83. // Show/Hide vertical menu
  84. if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  85. $showmode = 1;
  86. $classname = 'class="tmenu menuhider"';
  87. $idsel = 'menu';
  88. $this->menu->add('#', '', 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
  89. }
  90. // Home
  91. $showmode = 1;
  92. $classname = 'class="tmenusel"';
  93. $idsel = 'home';
  94. $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
  95. // Sort on position
  96. $this->menu->liste = dol_sort_array($this->menu->liste, 'position');
  97. // Output menu entries
  98. foreach ($this->menu->liste as $menkey => $menuval) {
  99. if (empty($noout)) {
  100. print_start_menu_entry_empty($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
  101. }
  102. if (empty($noout)) {
  103. print_text_menu_entry_empty($menuval['titre'], $menuval['enabled'], ($menuval['url'] != '#' ?DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $atarget));
  104. }
  105. if (empty($noout)) {
  106. print_end_menu_entry_empty($menuval['enabled']);
  107. }
  108. }
  109. $showmode = 1;
  110. if (empty($noout)) {
  111. print_start_menu_entry_empty('', 'class="tmenuend"', $showmode);
  112. }
  113. if (empty($noout)) {
  114. print_end_menu_entry_empty($showmode);
  115. }
  116. if (empty($noout)) {
  117. print_end_menu_array_empty();
  118. }
  119. if ($mode == 'jmobile') {
  120. $this->topmenu = clone $this->menu;
  121. unset($this->menu->liste);
  122. }
  123. }
  124. if ($mode == 'jmobile') { // Used to get menu in xml ul/li
  125. // Home
  126. $showmode = 1;
  127. $classname = 'class="tmenusel"';
  128. $idsel = 'home';
  129. $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
  130. $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
  131. // $this->menu->liste is top menu
  132. //var_dump($this->menu->liste);exit;
  133. $lastlevel = array();
  134. print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
  135. foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
  136. print '<ul class="ulmenu" data-inset="true">';
  137. print '<li class="lilevel0">';
  138. $val['url'] = make_substitutions($val['url'], $substitarray);
  139. if ($val['enabled'] == 1) {
  140. $relurl = dol_buildpath($val['url'], 1);
  141. $canonurl = preg_replace('/\?.*$/', '', $val['url']);
  142. print '<a class="alilevel0" href="#">';
  143. // Add font-awesome
  144. if ($val['level'] == 0 && $val['mainmenu'] == 'home') {
  145. print '<span class="fa fa-home fa-fw paddingright" aria-hidden="true"></span>';
  146. }
  147. print $val['titre'];
  148. print '</a>'."\n";
  149. // Search submenu fot this mainmenu entry
  150. $tmpmainmenu = $val['mainmenu'];
  151. $tmpleftmenu = 'all';
  152. $submenu = new Menu();
  153. $langs->load("admin"); // Load translation file admin.lang
  154. $submenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
  155. $submenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
  156. $submenu->add("/admin/modules.php", $langs->trans("Modules"), 1);
  157. $submenu->add("/admin/menus.php", $langs->trans("Menus"), 1);
  158. $submenu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
  159. $submenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
  160. $submenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
  161. $submenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
  162. $submenu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
  163. $submenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
  164. $submenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
  165. $submenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
  166. $submenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
  167. $submenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
  168. $submenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
  169. $submenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
  170. //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') { var_dump($submenu); exit; }
  171. //if ($tmpmainmenu=='accountancy') { var_dump($submenu->liste); exit; }
  172. $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
  173. $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
  174. $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
  175. //var_dump($canonrelurl);
  176. //var_dump($canonnexturl);
  177. print '<ul>'."\n";
  178. if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
  179. || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
  180. // We add sub entry
  181. print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
  182. print '<a href="'.$relurl.'">';
  183. if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
  184. if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) {
  185. print $langs->trans("Access");
  186. } else {
  187. print $langs->trans("Dashboard");
  188. }
  189. } else {
  190. print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
  191. }
  192. print '</a>';
  193. print '</li>'."\n";
  194. }
  195. if ($val['level'] == 0) {
  196. if ($val['enabled']) {
  197. $lastlevel[0] = 'enabled';
  198. } elseif ($showmenu) { // Not enabled but visible (so greyed)
  199. $lastlevel[0] = 'greyed';
  200. } else {
  201. $lastlevel[0] = 'hidden';
  202. }
  203. }
  204. $lastlevel2 = array();
  205. foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
  206. $showmenu = true;
  207. if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) {
  208. $showmenu = false;
  209. }
  210. // If at least one parent is not enabled, we do not show any menu of all children
  211. if ($val2['level'] > 0) {
  212. $levelcursor = $val2['level'] - 1;
  213. while ($levelcursor >= 0) {
  214. if ($lastlevel2[$levelcursor] != 'enabled') {
  215. $showmenu = false;
  216. }
  217. $levelcursor--;
  218. }
  219. }
  220. if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
  221. $val2['url'] = make_substitutions($val2['url'], $substitarray);
  222. $relurl2 = dol_buildpath($val2['url'], 1);
  223. $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
  224. //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
  225. if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
  226. $relurl2 = '';
  227. }
  228. $disabled = '';
  229. if (!$val2['enabled']) {
  230. $disabled = " vsmenudisabled";
  231. }
  232. print str_pad('', $val2['level'] + 1);
  233. print '<li class="lilevel'.($val2['level'] + 1);
  234. if ($val2['level'] == 0) {
  235. print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
  236. }
  237. print $disabled.'">'; // ui-btn to highlight on clic
  238. if ($relurl2) {
  239. if ($val2['enabled']) {
  240. // Allowed
  241. print '<a href="'.$relurl2.'">';
  242. $lastlevel2[$val2['level']] = 'enabled';
  243. } else {
  244. // Not allowed but visible (greyed)
  245. print '<a href="#" class="vsmenudisabled">';
  246. $lastlevel2[$val2['level']] = 'greyed';
  247. }
  248. } else {
  249. if ($val2['enabled']) { // Allowed
  250. $lastlevel2[$val2['level']] = 'enabled';
  251. } else {
  252. $lastlevel2[$val2['level']] = 'greyed';
  253. }
  254. }
  255. //var_dump($val2['level']);
  256. //var_dump($lastlevel2);
  257. print $val2['titre'];
  258. if ($relurl2) {
  259. if ($val2['enabled']) {
  260. // Allowed
  261. print '</a>';
  262. } else {
  263. // Not allowed
  264. print '</a>';
  265. }
  266. }
  267. print '</li>'."\n";
  268. }
  269. }
  270. //var_dump($submenu);
  271. print '</ul>';
  272. }
  273. if ($val['enabled'] == 2) {
  274. print '<span class="vsmenudisabled">'.$val['titre'].'</span>';
  275. }
  276. print '</li>';
  277. print '</ul>'."\n";
  278. }
  279. }
  280. if ($mode == 'left') {
  281. // Put here left menu entries
  282. // ***** START *****
  283. $langs->load("admin"); // Load translation file admin.lang
  284. $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
  285. $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
  286. $this->menu->add("/admin/modules.php", $langs->trans("Modules"), 1);
  287. $this->menu->add("/admin/menus.php", $langs->trans("Menus"), 1);
  288. $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
  289. $this->menu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
  290. $this->menu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
  291. $this->menu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
  292. $this->menu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
  293. $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
  294. $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
  295. $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
  296. $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
  297. $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
  298. $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
  299. $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
  300. // ***** END *****
  301. $menu_array_before = array();
  302. $menu_array_after = array();
  303. // do not change code after this
  304. $menu_array = $this->menu->liste;
  305. if (is_array($menu_array_before)) {
  306. $menu_array = array_merge($menu_array_before, $menu_array);
  307. }
  308. if (is_array($menu_array_after)) {
  309. $menu_array = array_merge($menu_array, $menu_array_after);
  310. }
  311. //var_dump($menu_array);exit;
  312. if (!is_array($menu_array)) {
  313. return 0;
  314. }
  315. if (empty($noout)) {
  316. $alt = 0;
  317. $altok = 0;
  318. $blockvmenuopened = false;
  319. $num = count($menu_array);
  320. for ($i = 0; $i < $num; $i++) {
  321. $alt++;
  322. if (empty($menu_array[$i]['level'])) {
  323. $altok++;
  324. $blockvmenuopened = true;
  325. $lastopened = true;
  326. for ($j = ($i + 1); $j < $num; $j++) {
  327. if (empty($menu_array[$j]['level'])) {
  328. $lastopened = false;
  329. }
  330. }
  331. $alt = 0; // For menu manager "empty", we force to not have blockvmenufirst defined
  332. $lastopened = 1; // For menu manager "empty", we force to not have blockvmenulast defined
  333. if (($alt % 2 == 0)) {
  334. print '<div class="blockvmenub lockvmenuimpair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
  335. } else {
  336. print '<div class="blockvmenu blockvmenupair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
  337. }
  338. }
  339. // Add tabulation
  340. $tabstring = '';
  341. $tabul = ($menu_array[$i]['level'] - 1);
  342. if ($tabul > 0) {
  343. for ($j = 0; $j < $tabul; $j++) {
  344. $tabstring .= '&nbsp; &nbsp;';
  345. }
  346. }
  347. if ($menu_array[$i]['level'] == 0) {
  348. if ($menu_array[$i]['enabled']) {
  349. print '<div class="menu_titre">'.$tabstring.'<a class="vmenu" href="'.dol_buildpath($menu_array[$i]['url'], 1).'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>'.$menu_array[$i]['titre'].'</a></div>'."\n";
  350. } else {
  351. print '<div class="menu_titre">'.$tabstring.'<span class="vmenudisabled">'.$menu_array[$i]['titre'].'</span></div>'."\n";
  352. }
  353. print '<div class="menu_top"></div>'."\n";
  354. }
  355. if ($menu_array[$i]['level'] > 0) {
  356. $cssmenu = '';
  357. if ($menu_array[$i]['url']) {
  358. $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
  359. }
  360. print '<div class="menu_contenu'.$cssmenu.'">';
  361. if ($menu_array[$i]['enabled']) {
  362. print $tabstring;
  363. if ($menu_array[$i]['url']) {
  364. print '<a class="vsmenu" itle="'.dol_escape_htmltag($menu_array[$i]['titre']).'" href="'.dol_buildpath($menu_array[$i]['url'], 1).'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
  365. } else {
  366. print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
  367. }
  368. if ($menu_array[$i]['url']) {
  369. print $menu_array[$i]['titre'].'</a>';
  370. } else {
  371. print '</span>';
  372. }
  373. } else {
  374. print $tabstring.'<span class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</span>';
  375. }
  376. // If title is not pure text and contains a table, no carriage return added
  377. if (!strstr($menu_array[$i]['titre'], '<table')) {
  378. print '<br>';
  379. }
  380. print '</div>'."\n";
  381. }
  382. // If next is a new block or end
  383. if (empty($menu_array[$i + 1]['level'])) {
  384. print '<div class="menu_end"></div>'."\n";
  385. print "</div>\n";
  386. }
  387. }
  388. if ($altok) {
  389. print '<div class="blockvmenuend"></div>';
  390. }
  391. }
  392. if ($mode == 'jmobile') {
  393. $this->leftmenu = clone $this->menu;
  394. unset($menu_array);
  395. }
  396. }
  397. unset($this->menu);
  398. return $res;
  399. }
  400. }
  401. /**
  402. * Output menu entry
  403. *
  404. * @return void
  405. */
  406. function print_start_menu_array_empty()
  407. {
  408. global $conf;
  409. print '<div class="tmenudiv">';
  410. print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Top menu"').'>';
  411. }
  412. /**
  413. * Output start menu entry
  414. *
  415. * @param string $idsel Text
  416. * @param string $classname String to add a css class
  417. * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed
  418. * @return void
  419. */
  420. function print_start_menu_entry_empty($idsel, $classname, $showmode)
  421. {
  422. if ($showmode) {
  423. print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
  424. //print '<div class="tmenuleft tmenusep"></div>';
  425. print '<div class="tmenucenter">';
  426. }
  427. }
  428. /**
  429. * Output menu entry
  430. *
  431. * @param string $text Text
  432. * @param int $showmode 1 or 2
  433. * @param string $url Url
  434. * @param string $id Id
  435. * @param string $idsel Id sel
  436. * @param string $classname Class name
  437. * @param string $atarget Target
  438. * @return void
  439. */
  440. function print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget)
  441. {
  442. global $conf, $langs;
  443. if ($showmode == 1) {
  444. print '<a class="tmenuimage" tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').'>';
  445. print '<div class="'.$id.' '.$idsel.'"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>';
  446. print '</a>';
  447. print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').'>';
  448. print '<span class="mainmenuaspan">';
  449. print $text;
  450. print '</span>';
  451. print '</a>';
  452. }
  453. if ($showmode == 2) {
  454. print '<div class="'.$id.' '.$idsel.' tmenudisabled"><span class="'.$id.'" id="mainmenuspan_'.$idsel.'"></span></div>';
  455. print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">';
  456. }
  457. }
  458. /**
  459. * Output end menu entry
  460. *
  461. * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed
  462. * @return void
  463. */
  464. function print_end_menu_entry_empty($showmode)
  465. {
  466. if ($showmode) {
  467. print '</div></li>';
  468. print "\n";
  469. }
  470. }
  471. /**
  472. * Output menu array
  473. *
  474. * @return void
  475. */
  476. function print_end_menu_array_empty()
  477. {
  478. print '</ul>';
  479. print '</div>';
  480. print "\n";
  481. }