PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/menus/standard/auguria.lib.php

https://github.com/asterix14/dolibarr
PHP | 322 lines | 220 code | 41 blank | 61 comment | 64 complexity | 8e6fd5150bcf5c8e550d11c2c2459c8a MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  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 $db
  27. * @param $atarget
  28. * @param $type_user 0=Internal,1=External,2=All
  29. */
  30. function print_auguria_menu($db,$atarget,$type_user)
  31. {
  32. require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");
  33. global $user,$conf,$langs,$dolibarr_main_db_name;
  34. // On sauve en session le menu principal choisi
  35. if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"];
  36. if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"];
  37. $_SESSION["leftmenuopened"]="";
  38. $menuArbo = new Menubase($db,'auguria','top');
  39. $newTabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'], '', $type_user, 'auguria');
  40. print_start_menu_array_auguria();
  41. $num = count($newTabMenu);
  42. for($i = 0; $i < $num; $i++)
  43. {
  44. if ($newTabMenu[$i]['enabled'] == true)
  45. {
  46. $idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']);
  47. if ($newTabMenu[$i]['right'] == true) // Is allowed
  48. {
  49. // Define url
  50. if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
  51. {
  52. $url = $newTabMenu[$i]['url'];
  53. }
  54. else
  55. {
  56. $url=dol_buildpath($newTabMenu[$i]['url'],1);
  57. if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url))
  58. {
  59. if (! preg_match('/\?/',$url)) $url.='?';
  60. else $url.='&';
  61. $url.='mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
  62. }
  63. //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
  64. }
  65. $url=preg_replace('/__LOGIN__/',$user->login,$url);
  66. // Define the class (top menu selected or not)
  67. if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
  68. else if (! empty($_SESSION['mainmenu']) && $newTabMenu[$i]['mainmenu'] == $_SESSION['mainmenu']) $classname='class="tmenusel"';
  69. else $classname='class="tmenu"';
  70. print_start_menu_entry_auguria($idsel);
  71. print '<div class="mainmenu '.$idsel.'"><span class="mainmenu_'.$idsel.'" id="mainmenuspan_'.$idsel.'"></span></div>';
  72. print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($newTabMenu[$i]['atarget']?' target="'.$newTabMenu[$i]['atarget'].'"':($atarget?' target="'.$atarget.'"':'')).'>';
  73. print_text_menu_entry_auguria($newTabMenu[$i]['titre']);
  74. print '</a>';
  75. print_end_menu_entry_auguria();
  76. }
  77. else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
  78. {
  79. if (! $type_user)
  80. {
  81. print_start_menu_entry_auguria($idsel);
  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. }
  90. }
  91. print_end_menu_array_auguria();
  92. print "\n";
  93. }
  94. function print_start_menu_array_auguria()
  95. {
  96. global $conf;
  97. if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '<table class="tmenu" summary="topmenu"><tr class="tmenu">';
  98. else print '<ul class="tmenu">';
  99. }
  100. function print_start_menu_entry_auguria($idsel)
  101. {
  102. global $conf;
  103. if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '<td class="tmenu" id="mainmenutd_'.$idsel.'">';
  104. else print '<li class="tmenu" id="mainmenutd_'.$idsel.'">';
  105. }
  106. function print_text_menu_entry_auguria($text)
  107. {
  108. global $conf;
  109. print '<span class="mainmenuaspan">';
  110. print $text;
  111. print '</span>';
  112. }
  113. function print_end_menu_entry_auguria()
  114. {
  115. global $conf;
  116. if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '</td>';
  117. else print '</li>';
  118. print "\n";
  119. }
  120. function print_end_menu_array_auguria()
  121. {
  122. global $conf;
  123. if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '</tr></table>';
  124. else print '</ul>';
  125. print "\n";
  126. }
  127. /**
  128. * Core function to output left menu auguria
  129. *
  130. * @param db Database handler
  131. * @param menu_array_before Table of menu entries to show before entries of menu handler
  132. * @param menu_array_after Table of menu entries to show after entries of menu handler
  133. */
  134. function print_left_auguria_menu($db,$menu_array_before,$menu_array_after)
  135. {
  136. global $user,$conf,$langs,$dolibarr_main_db_name,$mysoc;
  137. $overwritemenufor = array();
  138. $newmenu = new Menu();
  139. // Read mainmenu and leftmenu that define which menu to show
  140. if (isset($_GET["mainmenu"])) {
  141. // On sauve en session le menu principal choisi
  142. $mainmenu=$_GET["mainmenu"];
  143. $_SESSION["mainmenu"]=$mainmenu;
  144. $_SESSION["leftmenuopened"]="";
  145. } else {
  146. // On va le chercher en session si non defini par le lien
  147. $mainmenu=$_SESSION["mainmenu"];
  148. }
  149. if (isset($_GET["leftmenu"])) {
  150. // On sauve en session le menu principal choisi
  151. $leftmenu=$_GET["leftmenu"];
  152. $_SESSION["leftmenu"]=$leftmenu;
  153. if ($_SESSION["leftmenuopened"]==$leftmenu) {
  154. //$leftmenu="";
  155. $_SESSION["leftmenuopened"]="";
  156. }
  157. else {
  158. $_SESSION["leftmenuopened"]=$leftmenu;
  159. }
  160. } else {
  161. // On va le chercher en session si non defini par le lien
  162. $leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:'';
  163. }
  164. //this->menu_array contains menu in pre.inc.php
  165. // Show logo company
  166. if (! empty($conf->global->MAIN_SHOW_LOGO))
  167. {
  168. $mysoc->logo_mini=$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
  169. if (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
  170. {
  171. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode('thumbs/'.$mysoc->logo_mini);
  172. print "\n".'<!-- Show logo on menu -->'."\n";
  173. print '<div class="blockvmenuimpair">'."\n";
  174. print '<div class="menu_titre" id="menu_titre_logo"></div>';
  175. print '<div class="menu_top" id="menu_top_logo"></div>';
  176. print '<div class="menu_contenu" id="menu_contenu_logo">';
  177. print '<center><img title="'.$title.'" src="'.$urllogo.'"></center>'."\n";
  178. print '</div>';
  179. print '<div class="menu_end" id="menu_end_logo"></div>';
  180. print '</div>'."\n";
  181. }
  182. }
  183. /**
  184. * On definit newmenu en fonction de mainmenu et leftmenu
  185. * ------------------------------------------------------
  186. */
  187. if ($mainmenu)
  188. {
  189. require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");
  190. $menuArbo = new Menubase($db,'auguria','left');
  191. $newmenu = $menuArbo->menuLeftCharger($newmenu,$mainmenu,$leftmenu,($user->societe_id?1:0),'auguria');
  192. //var_dump($newmenu);
  193. }
  194. //var_dump($menu_array_before);exit;
  195. //var_dump($menu_array_after);exit;
  196. $menu_array=$newmenu->liste;
  197. if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array);
  198. if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after);
  199. //var_dump($menu_array);exit;
  200. // Show menu
  201. $alt=0;
  202. if (is_array($menu_array))
  203. {
  204. $num=count($menu_array);
  205. for ($i = 0; $i < $num; $i++)
  206. {
  207. $alt++;
  208. if (empty($menu_array[$i]['level']))
  209. {
  210. if (($alt%2==0))
  211. {
  212. if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_ACCORDION)
  213. {
  214. print '<div class="blockvmenupair">'."\n";
  215. }
  216. else
  217. {
  218. print '<div class="blockvmenuimpair">'."\n";
  219. }
  220. }
  221. else
  222. {
  223. print '<div class="blockvmenupair">'."\n";
  224. }
  225. }
  226. // Place tabulation
  227. $tabstring='';
  228. $tabul=($menu_array[$i]['level'] - 1);
  229. if ($tabul > 0)
  230. {
  231. for ($j=0; $j < $tabul; $j++)
  232. {
  233. $tabstring.='&nbsp; &nbsp;';
  234. }
  235. }
  236. // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
  237. $url=dol_buildpath($menu_array[$i]['url'],1);
  238. if (! preg_match('/mainmenu=/i',$menu_array[$i]['url']))
  239. {
  240. if (! preg_match('/\?/',$url)) $url.='?';
  241. else $url.='&';
  242. $url.='mainmenu='.$mainmenu;
  243. }
  244. // Menu niveau 0
  245. if ($menu_array[$i]['level'] == 0)
  246. {
  247. if ($menu_array[$i]['enabled'])
  248. {
  249. 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>';
  250. }
  251. else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
  252. {
  253. print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>';
  254. }
  255. print "\n".'<div id="section_content_'.$i.'">'."\n";
  256. print '<div class="menu_top"></div>'."\n";
  257. }
  258. // Menu niveau > 0
  259. if ($menu_array[$i]['level'] > 0)
  260. {
  261. if ($menu_array[$i]['enabled'])
  262. {
  263. 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>';
  264. }
  265. else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
  266. {
  267. print '<div class="menu_contenu">'.$tabstring.'<font class="vsmenudisabled">'.$menu_array[$i]['titre'].'</font></div>';
  268. }
  269. }
  270. // If next is a new block or end
  271. if (empty($menu_array[$i+1]['level']))
  272. {
  273. print '<div class="menu_end"></div>'."\n";
  274. print "</div><!-- end section content -->\n";
  275. print "</div><!-- end blockvmenu pair/impair -->\n";
  276. }
  277. }
  278. }
  279. return count($menu_array);
  280. }
  281. ?>