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