1 | <?php |
||
2 | /* Copyright (C) 2005-2013 Laurent Destailleur <[email protected]> |
||
3 | * Copyright (C) 2007-2009 Regis Houssin <[email protected]> |
||
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 <http://www.gnu.org/licenses/>. |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | * \file htdocs/core/menus/standard/eldy_menu.php |
||
21 | * \brief Menu eldy manager |
||
22 | */ |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Class to manage menu Eldy |
||
27 | */ |
||
28 | class MenuManager |
||
29 | { |
||
30 | /** |
||
31 | * @var DoliDB Database handler. |
||
32 | */ |
||
33 | public $db; |
||
34 | |||
35 | var $type_user; // Put 0 for internal users, 1 for external users |
||
36 | var $atarget=""; // To store default target to use onto links |
||
37 | var $name="eldy"; |
||
38 | |||
39 | var $menu_array; |
||
40 | var $menu_array_after; |
||
41 | |||
42 | var $tabMenu; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * Constructor |
||
47 | * |
||
48 | * @param DoliDB $db Database handler |
||
49 | * @param int $type_user Type of user |
||
50 | */ |
||
51 | function __construct($db, $type_user) |
||
52 | { |
||
53 | $this->type_user=$type_user; |
||
54 | $this->db=$db; |
||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Load this->tabMenu |
||
60 | * |
||
61 | * @param string $forcemainmenu To force mainmenu to load |
||
62 | * @param string $forceleftmenu To force leftmenu to load |
||
63 | * @return void |
||
64 | */ |
||
65 | function loadMenu($forcemainmenu='',$forceleftmenu='') |
||
66 | { |
||
67 | // On sauve en session le menu principal choisi |
||
68 | if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; |
||
69 | if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; |
||
70 | |||
71 | // Read mainmenu and leftmenu that define which menu to show |
||
72 | if (isset($_GET["mainmenu"])) |
||
73 | { |
||
74 | // On sauve en session le menu principal choisi |
||
75 | $mainmenu=$_GET["mainmenu"]; |
||
76 | $_SESSION["mainmenu"]=$mainmenu; |
||
77 | $_SESSION["leftmenuopened"]=""; |
||
78 | } |
||
79 | else |
||
80 | { |
||
81 | // On va le chercher en session si non defini par le lien |
||
82 | $mainmenu=isset($_SESSION["mainmenu"])?$_SESSION["mainmenu"]:''; |
||
83 | } |
||
84 | if (! empty($forcemainmenu)) $mainmenu=$forcemainmenu; |
||
85 | |||
86 | if (isset($_GET["leftmenu"])) |
||
87 | { |
||
88 | // On sauve en session le menu principal choisi |
||
89 | $leftmenu=$_GET["leftmenu"]; |
||
90 | $_SESSION["leftmenu"]=$leftmenu; |
||
91 | |||
92 | if ($_SESSION["leftmenuopened"]==$leftmenu) // To collapse |
||
93 | { |
||
94 | //$leftmenu=""; |
||
95 | $_SESSION["leftmenuopened"]=""; |
||
96 | } |
||
97 | else |
||
98 | { |
||
99 | $_SESSION["leftmenuopened"]=$leftmenu; |
||
100 | } |
||
101 | } else { |
||
102 | // On va le chercher en session si non defini par le lien |
||
103 | $leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:''; |
||
104 | } |
||
105 | if (! empty($forceleftmenu)) $leftmenu=$forceleftmenu; |
||
106 | |||
107 | require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; |
||
108 | $tabMenu=array(); |
||
109 | $menuArbo = new Menubase($this->db,'eldy'); |
||
110 | $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu); |
||
111 | $this->tabMenu=$tabMenu; |
||
112 | //var_dump($tabMenu); |
||
113 | |||
114 | //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; } |
||
115 | } |
||
116 | |||
117 | |||
118 | /** |
||
119 | * Show menu. |
||
120 | * Module defined in sql tables were stored into $this->tabMenu BEFORE this is called. |
||
121 | * |
||
122 | * @param string $mode 'top', 'topnb', 'left', 'jmobile' (used to get full xml ul/li menu) |
||
123 | * @param array $moredata An array with more data to output |
||
124 | * @return int 0 or nb of top menu entries if $mode = 'topnb' |
||
125 | */ |
||
126 | function showmenu($mode, $moredata=null) |
||
127 | { |
||
128 | global $conf, $langs, $user; |
||
129 | |||
130 | //var_dump($this->tabMenu); |
||
131 | |||
132 | require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; |
||
133 | |||
134 | if ($this->type_user == 1) |
||
135 | { |
||
136 | $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED=1; |
||
137 | $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED=1; |
||
138 | } |
||
139 | |||
140 | require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php'; |
||
141 | $this->menu=new Menu(); |
||
142 | |||
143 | if (empty($conf->global->MAIN_MENU_INVERT)) |
||
144 | { |
||
145 | if ($mode == 'top') print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
146 | if ($mode == 'left') print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0,'','',$moredata); |
||
147 | } |
||
148 | else |
||
149 | { |
||
150 | $conf->global->MAIN_SHOW_LOGO=0; |
||
151 | if ($mode == 'top') print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0); |
||
152 | if ($mode == 'left') print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode); |
||
153 | } |
||
154 | |||
155 | if ($mode == 'topnb') |
||
156 | { |
||
157 | print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); // no output |
||
158 | return $this->menu->getNbOfVisibleMenuEntries(); |
||
159 | } |
||
160 | |||
161 | if ($mode == 'jmobile') // Used to get menu in xml ul/li |
||
162 | { |
||
163 | print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); // Fill this->menu that is empty with top menu |
||
164 | |||
165 | // $this->menu->liste is top menu |
||
166 | //var_dump($this->menu->liste);exit; |
||
167 | $lastlevel = array(); |
||
168 | print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n"; |
||
169 | foreach($this->menu->liste as $key => $val) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' |
||
170 | { |
||
171 | print '<ul class="ulmenu" data-inset="true">'; |
||
172 | print '<li class="lilevel0">'; |
||
173 | |||
174 | if ($val['enabled'] == 1) |
||
175 | { |
||
176 | $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); |
||
177 | $substitarray['__USERID__'] = $user->id; // For backward compatibility |
||
178 | $val['url'] = make_substitutions($val['url'], $substitarray); |
||
179 | |||
180 | $relurl=dol_buildpath($val['url'],1); |
||
181 | $canonurl=preg_replace('/\?.*$/','',$val['url']); |
||
182 | |||
183 | print '<a class="alilevel0" href="#">'; |
||
184 | |||
185 | // Add font-awesome |
||
186 | if ($val['level'] == 0 && $val['mainmenu'] == 'home') print '<span class="fa fa-home fa-fw paddingright" aria-hidden="true"></span>'; |
||
187 | |||
188 | print $val['titre']; |
||
189 | print '</a>'."\n"; |
||
190 | |||
191 | // Search submenu fot this mainmenu entry |
||
192 | $tmpmainmenu=$val['mainmenu']; |
||
193 | $tmpleftmenu='all'; |
||
194 | $submenu=new Menu(); |
||
195 | print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$submenu,1,$tmpmainmenu,$tmpleftmenu); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home) |
||
196 | // Note: $submenu contains menu entry with substitution not yet done |
||
197 | //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') { var_dump($submenu); exit; } |
||
198 | //if ($tmpmainmenu=='accountancy') { var_dump($submenu->liste); exit; } |
||
199 | $nexturl=dol_buildpath($submenu->liste[0]['url'],1); |
||
200 | |||
201 | $canonrelurl=preg_replace('/\?.*$/','',$relurl); |
||
202 | $canonnexturl=preg_replace('/\?.*$/','',$nexturl); |
||
203 | //var_dump($canonrelurl); |
||
204 | //var_dump($canonnexturl); |
||
205 | print '<ul>'."\n"; |
||
206 | if (($canonrelurl != $canonnexturl && ! in_array($val['mainmenu'],array('tools'))) |
||
207 | || (strpos($canonrelurl,'/product/index.php') !== false || strpos($canonrelurl,'/compta/bank/list.php') !== false)) |
||
208 | { |
||
209 | // We add sub entry |
||
210 | print str_pad('',1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic |
||
211 | print '<a href="'.$relurl.'">'; |
||
212 | if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") // No translation |
||
213 | { |
||
214 | if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab'))) print $langs->trans("Access"); |
||
215 | else print $langs->trans("Dashboard"); |
||
216 | } |
||
217 | else print $langs->trans(ucfirst($val['mainmenu'])."Dashboard"); |
||
218 | print '</a>'; |
||
219 | print '</li>'."\n"; |
||
220 | } |
||
221 | |||
222 | if ($val['level']==0) |
||
223 | { |
||
224 | if ($val['enabled']) |
||
225 | { |
||
226 | $lastlevel[0]='enabled'; |
||
227 | } |
||
228 | else if ($showmenu) // Not enabled but visible (so greyed) |
||
229 | { |
||
230 | $lastlevel[0]='greyed'; |
||
231 | } |
||
232 | else |
||
233 | { |
||
234 | $lastlevel[0]='hidden'; |
||
235 | } |
||
236 | } |
||
237 | |||
238 | $lastlevel2 = array(); |
||
239 | foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' |
||
240 | { |
||
241 | $showmenu=true; |
||
242 | if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) $showmenu=false; |
||
243 | |||
244 | // If at least one parent is not enabled, we do not show any menu of all children |
||
245 | if ($val2['level'] > 0) |
||
246 | { |
||
247 | $levelcursor = $val2['level']-1; |
||
248 | while ($levelcursor >= 0) |
||
249 | { |
||
250 | if ($lastlevel2[$levelcursor] != 'enabled') $showmenu=false; |
||
251 | $levelcursor--; |
||
252 | } |
||
253 | } |
||
254 | |||
255 | if ($showmenu) // Visible (option to hide when not allowed is off or allowed) |
||
256 | { |
||
257 | $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); |
||
258 | $substitarray['__USERID__'] = $user->id; // For backward compatibility |
||
259 | $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__ |
||
260 | |||
261 | if (! preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) |
||
262 | { |
||
263 | $relurl2=dol_buildpath($val2['url'],1); |
||
264 | } |
||
265 | else |
||
266 | { |
||
267 | $relurl2=$val2['url']; |
||
268 | } |
||
269 | $canonurl2=preg_replace('/\?.*$/','',$val2['url']); |
||
270 | //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']); |
||
271 | if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2=''; |
||
272 | |||
273 | $disabled=''; |
||
274 | if (! $val2['enabled']) |
||
275 | { |
||
276 | $disabled=" vsmenudisabled"; |
||
277 | } |
||
278 | |||
279 | print str_pad('',$val2['level']+1); |
||
280 | print '<li class="lilevel'.($val2['level']+1); |
||
281 | if ($val2['level']==0) print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic |
||
282 | print $disabled.'">'; // ui-btn to highlight on clic |
||
283 | if ($relurl2) |
||
284 | { |
||
285 | if ($val2['enabled']) // Allowed |
||
286 | { |
||
287 | print '<a href="'.$relurl2.'"'; |
||
288 | //print ' data-ajax="false"'; |
||
289 | print '>'; |
||
290 | $lastlevel2[$val2['level']]='enabled'; |
||
291 | } |
||
292 | else // Not allowed but visible (greyed) |
||
293 | { |
||
294 | print '<a href="#" class="vsmenudisabled">'; |
||
295 | $lastlevel2[$val2['level']]='greyed'; |
||
296 | } |
||
297 | } |
||
298 | else |
||
299 | { |
||
300 | if ($val2['enabled']) // Allowed |
||
301 | { |
||
302 | $lastlevel2[$val2['level']]='enabled'; |
||
303 | } |
||
304 | else |
||
305 | { |
||
306 | $lastlevel2[$val2['level']]='greyed'; |
||
307 | } |
||
308 | } |
||
309 | //var_dump($val2['level']); |
||
310 | //var_dump($lastlevel2); |
||
311 | print $val2['titre']; |
||
312 | if ($relurl2) |
||
313 | { |
||
314 | if ($val2['enabled']) // Allowed |
||
315 | print '</a>'; |
||
316 | else |
||
317 | print '</a>'; |
||
318 | } |
||
319 | print '</li>'."\n"; |
||
320 | } |
||
321 | } |
||
322 | //var_dump($submenu); |
||
323 | print '</ul>'; |
||
324 | } |
||
325 | if ($val['enabled'] == 2) |
||
326 | { |
||
327 | print '<font class="vsmenudisabled">'.$val['titre'].'</font>'; |
||
328 | } |
||
329 | print '</li>'; |
||
330 | print '</ul>'."\n"; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | unset($this->menu); |
||
335 | |||
336 | //print 'xx'.$mode; |
||
337 | return 0; |
||
338 | } |
||
339 | } |
||
340 | |||
341 |