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