auguria.lib.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.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 2 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 <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/menus/standard/auguria.lib.php
  21. * \brief Library for file auguria menus
  22. */
  23. /**
  24. * Core function to output top menu auguria
  25. *
  26. * @param DoliDB $db Database handler
  27. * @param string $atarget Target
  28. * @param int $type_user 0=Internal,1=External,2=All
  29. * @return void
  30. */
  31. function print_auguria_menu($db,$atarget,$type_user)
  32. {
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
  34. global $user,$conf,$langs,$dolibarr_main_db_name;
  35. // On sauve en session le menu principal choisi
  36. if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"];
  37. if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"];
  38. $_SESSION["leftmenuopened"]="";
  39. $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
  40. $tabMenu=array();
  41. $menuArbo = new Menubase($db,'auguria','top');
  42. $newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'auguria',$tabMenu);
  43. print_start_menu_array_auguria();
  44. $num = count($newTabMenu);
  45. for($i = 0; $i < $num; $i++)
  46. {
  47. $idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']);
  48. $showmode=dol_auguria_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal);
  49. if ($showmode == 1)
  50. {
  51. // Define url
  52. if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
  53. {
  54. $url = $newTabMenu[$i]['url'];
  55. }
  56. else
  57. {
  58. $url=dol_buildpath($newTabMenu[$i]['url'],1);
  59. if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url))
  60. {
  61. if (! preg_match('/\?/',$url)) $url.='?';
  62. else $url.='&';
  63. $url.='mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
  64. }
  65. //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
  66. }
  67. $url=preg_replace('/__LOGIN__/',$user->login,$url);
  68. // Define the class (top menu selected or not)
  69. if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
  70. else if (! empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname='class="tmenusel"';
  71. else $classname='class="tmenu"';
  72. print_start_menu_entry_auguria($idsel,$classname);
  73. print '<div class="mainmenu '.$idsel.'"><span class="mainmenu_'.$idsel.'" id="mainmenuspan_'.$idsel.'"></span></div>';
  74. print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($newTabMenu[$i]['target']?' target="'.$newTabMenu[$i]['target'].'"':($atarget?' target="'.$atarget.'"':'')).'>';
  75. print_text_menu_entry_auguria($newTabMenu[$i]['titre']);
  76. print '</a>';
  77. print_end_menu_entry_auguria();
  78. }
  79. else if ($showmode == 2)
  80. {
  81. print_start_menu_entry_auguria($idsel,'class="tmenu"');
  82. print '<div class="mainmenu '.$idsel.'"><span class="mainmenu_'.$idsel.'" id="mainmenuspan_'.$idsel.'"></span></div>';
  83. print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">';
  84. print_text_menu_entry_auguria($newTabMenu[$i]['titre']);
  85. print '</a>';
  86. print_end_menu_entry_auguria();
  87. }
  88. }
  89. print_end_menu_array_auguria();
  90. print "\n";
  91. }
  92. /**
  93. * Output start menu array
  94. *
  95. * @return void
  96. */
  97. function print_start_menu_array_auguria()
  98. {
  99. global $conf;
  100. print '<div class="tmenudiv">';
  101. print '<ul class="tmenu">';
  102. }
  103. /**
  104. * Output start menu entry
  105. *
  106. * @param string $idsel Text
  107. * @param string $classname String to add a css class
  108. * @return void
  109. */
  110. function print_start_menu_entry_auguria($idsel,$classname)
  111. {
  112. print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
  113. print '<div class="tmenuleft"></div><div class="tmenucenter">';
  114. }
  115. /**
  116. * Output menu entry
  117. *
  118. * @param string $text Text
  119. * @return void
  120. */
  121. function print_text_menu_entry_auguria($text)
  122. {
  123. print '<span class="mainmenuaspan">';
  124. print $text;
  125. print '</span>';
  126. }
  127. /**
  128. * Output end menu entry
  129. *
  130. * @return void
  131. */
  132. function print_end_menu_entry_auguria()
  133. {
  134. print '</div>';
  135. print '</li>';
  136. print "\n";
  137. }
  138. /**
  139. * Output menu array
  140. *
  141. * @return void
  142. */
  143. function print_end_menu_array_auguria()
  144. {
  145. print '</ul>';
  146. print '</div>';
  147. print "\n";
  148. }
  149. /**
  150. * Core function to output left menu auguria
  151. *
  152. * @param DoliDB $db Database handler
  153. * @param array $menu_array_before Table of menu entries to show before entries of menu handler
  154. * @param array $menu_array_after Table of menu entries to show after entries of menu handler
  155. * @return void
  156. */
  157. function print_left_auguria_menu($db,$menu_array_before,$menu_array_after)
  158. {
  159. global $user,$conf,$langs,$dolibarr_main_db_name,$mysoc;
  160. $overwritemenufor = array();
  161. $newmenu = new Menu();
  162. // Read mainmenu and leftmenu that define which menu to show
  163. if (isset($_GET["mainmenu"])) {
  164. // On sauve en session le menu principal choisi
  165. $mainmenu=$_GET["mainmenu"];
  166. $_SESSION["mainmenu"]=$mainmenu;
  167. $_SESSION["leftmenuopened"]="";
  168. } else {
  169. // On va le chercher en session si non defini par le lien
  170. $mainmenu=$_SESSION["mainmenu"];
  171. }
  172. if (isset($_GET["leftmenu"])) {
  173. // On sauve en session le menu principal choisi
  174. $leftmenu=$_GET["leftmenu"];
  175. $_SESSION["leftmenu"]=$leftmenu;
  176. if ($_SESSION["leftmenuopened"]==$leftmenu) {
  177. //$leftmenu="";
  178. $_SESSION["leftmenuopened"]="";
  179. }
  180. else {
  181. $_SESSION["leftmenuopened"]=$leftmenu;
  182. }
  183. } else {
  184. // On va le chercher en session si non defini par le lien
  185. $leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:'';
  186. }
  187. //this->menu_array contains menu in pre.inc.php
  188. // Show logo company
  189. if (! empty($conf->global->MAIN_SHOW_LOGO))
  190. {
  191. $mysoc->logo_mini=$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
  192. if (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
  193. {
  194. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode('thumbs/'.$mysoc->logo_mini);
  195. print "\n".'<!-- Show logo on menu -->'."\n";
  196. print '<div class="blockvmenuimpair">'."\n";
  197. print '<div class="menu_titre" id="menu_titre_logo"></div>';
  198. print '<div class="menu_top" id="menu_top_logo"></div>';
  199. print '<div class="menu_contenu" id="menu_contenu_logo">';
  200. print '<center><img title="" src="'.$urllogo.'"></center>'."\n";
  201. print '</div>';
  202. print '<div class="menu_end" id="menu_end_logo"></div>';
  203. print '</div>'."\n";
  204. }
  205. }
  206. // Modules system tools
  207. // TODO Find a way to add parent menu only if child menu exists. For the moment, no ther method than hard coded methods.
  208. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
  209. {
  210. if (empty($user->societe_id))
  211. {
  212. $newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', $mainmenu, 'modulesadmintools');
  213. if ($leftmenu=="modulesadmintools" && $user->admin)
  214. {
  215. $langs->load("products");
  216. $newmenu->add("/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
  217. }
  218. }
  219. }
  220. /**
  221. * We update newmenu with entries found into database
  222. * --------------------------------------------------
  223. */
  224. if ($mainmenu)
  225. {
  226. require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
  227. $tabMenu=array();
  228. $menuArbo = new Menubase($db,'auguria','left');
  229. $newmenu = $menuArbo->menuLeftCharger($newmenu,$mainmenu,$leftmenu,($user->societe_id?1:0),'auguria',$tabMenu);
  230. //var_dump($newmenu);
  231. }
  232. //var_dump($menu_array_before);exit;
  233. //var_dump($menu_array_after);exit;
  234. $menu_array=$newmenu->liste;
  235. if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array);
  236. if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after);
  237. //var_dump($menu_array);exit;
  238. // Show menu
  239. $alt=0;
  240. if (is_array($menu_array))
  241. {
  242. $num=count($menu_array);
  243. for ($i = 0; $i < $num; $i++)
  244. {
  245. $alt++;
  246. if (empty($menu_array[$i]['level']))
  247. {
  248. if (($alt%2==0))
  249. {
  250. if ($conf->use_javascript_ajax && ! empty($conf->global->MAIN_MENU_USE_JQUERY_ACCORDION))
  251. {
  252. print '<div class="blockvmenupair">'."\n";
  253. }
  254. else
  255. {
  256. print '<div class="blockvmenuimpair">'."\n";
  257. }
  258. }
  259. else
  260. {
  261. print '<div class="blockvmenupair">'."\n";
  262. }
  263. }
  264. // Place tabulation
  265. $tabstring='';
  266. $tabul=($menu_array[$i]['level'] - 1);
  267. if ($tabul > 0)
  268. {
  269. for ($j=0; $j < $tabul; $j++)
  270. {
  271. $tabstring.='&nbsp; &nbsp;';
  272. }
  273. }
  274. // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
  275. $url=dol_buildpath($menu_array[$i]['url'],1);
  276. if (! preg_match('/mainmenu=/i',$menu_array[$i]['url']))
  277. {
  278. if (! preg_match('/\?/',$url)) $url.='?';
  279. else $url.='&';
  280. $url.='mainmenu='.$mainmenu;
  281. }
  282. print '<!-- Add menu entry with mainmenu='.$menu_array[$i]['mainmenu'].', leftmenu='.$menu_array[$i]['leftmenu'].', level='.$menu_array[$i]['mainmenu'].' -->'."\n";
  283. // Menu niveau 0
  284. if ($menu_array[$i]['level'] == 0)
  285. {
  286. if ($menu_array[$i]['enabled'])
  287. {
  288. print '<div class="menu_titre">'.$tabstring.'<a class="vmenu" href="'.$url.'"'.($menu_array[$i]['target']?' target="'.$menu_array[$i]['target'].'"':'').'>'.$menu_array[$i]['titre'].'</a></div>';
  289. }
  290. else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
  291. {
  292. print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>';
  293. }
  294. print "\n".'<div id="section_content_'.$i.'">'."\n";
  295. print '<div class="menu_top"></div>'."\n";
  296. }
  297. // Menu niveau > 0
  298. if ($menu_array[$i]['level'] > 0)
  299. {
  300. if ($menu_array[$i]['enabled'])
  301. {
  302. print '<div class="menu_contenu">'.$tabstring.'<a class="vsmenu" href="'.$url.'"'.($menu_array[$i]['target']?' target="'.$menu_array[$i]['target'].'"':'').'>'.$menu_array[$i]['titre'].'</a></div>';
  303. }
  304. else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
  305. {
  306. print '<div class="menu_contenu">'.$tabstring.'<font class="vsmenudisabled">'.$menu_array[$i]['titre'].'</font></div>';
  307. }
  308. }
  309. // If next is a new block or end
  310. if (empty($menu_array[$i+1]['level']))
  311. {
  312. print '<div class="menu_end"></div>'."\n";
  313. print "</div><!-- end section content -->\n";
  314. print "</div><!-- end blockvmenu pair/impair -->\n";
  315. }
  316. }
  317. }
  318. return count($menu_array);
  319. }
  320. /**
  321. * Function to test if an entry is enabled or not
  322. *
  323. * @param string $type_user 0=We need backoffice menu, 1=We need frontoffice menu
  324. * @param array &$menuentry Array for menu entry
  325. * @param array &$listofmodulesforexternal Array with list of modules allowed to external users
  326. * @return int 0=Hide, 1=Show, 2=Show gray
  327. */
  328. function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal)
  329. {
  330. //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
  331. //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
  332. if (empty($menuentry['enabled'])) return 0; // Entry disabled by condition
  333. if ($type_user && $menuentry['module'])
  334. {
  335. $tmploops=explode('|',$menuentry['module']);
  336. $found=0;
  337. foreach($tmploops as $tmploop)
  338. {
  339. if (in_array($tmploop, $listofmodulesforexternal)) { $found++; break; }
  340. }
  341. if (! $found) return 0; // Entry is for menus all excluded to external users
  342. }
  343. if (! $menuentry['perms'] && $type_user) return 0; // No permissions and user is external
  344. 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
  345. if (! $menuentry['perms']) return 2; // No permissions and user is external
  346. return 1;
  347. }
  348. ?>