-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathhierarchy.php
More file actions
400 lines (346 loc) · 14.8 KB
/
hierarchy.php
File metadata and controls
400 lines (346 loc) · 14.8 KB
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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 <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/user/hierarchy.php
* \ingroup user
* \brief Page of hierarchy view of user module
*/
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
// Load translation files required by page
$langs->loadLangs(array('users', 'companies', 'hrm', 'salaries'));
// Security check (for external users)
$socid = 0;
if ($user->socid > 0) {
$socid = $user->socid;
}
$optioncss = GETPOST('optioncss', 'alpha');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userlist'; // To manage different context of search
$mode = GETPOST("mode", 'alpha');
if (empty($mode)) {
$mode = 'hierarchy';
}
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
$search_status = GETPOST('search_status', 'intcomma');
if ($search_status == '') {
$search_status = '1';
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
$search_status = "";
}
$search_employee = -1;
if ($contextpage == 'employeelist') {
$search_employee = 1;
}
$userstatic = new User($db);
// Define value to know what current user can do on users
$permissiontoadd = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
// Permission to list
if (isModEnabled('salaries') && $contextpage == 'employeelist' && $search_employee == 1) {
if (!$user->hasRight("salaries", "read")) {
accessforbidden();
}
} else {
if (!$user->hasRight("user", "user", "read") && empty($user->admin)) {
accessforbidden();
}
}
$childids = $user->getAllChildIds(1);
/*
* View
*/
$form = new Form($db);
$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:Módulo_Usuarios|DE:Modul_Benutzer';
if ($contextpage == 'employeelist' && $search_employee == 1) {
$title = $langs->trans("Employees");
} else {
$title = $langs->trans("Users");
}
$arrayofjs = array(
'/public/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
'/public/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
);
$arrayofcss = array('/public/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist mod-user page-hierarchy');
$filters = [];
if (($search_status != '' && $search_status >= 0)) {
$filters[] = "(statut:=:".((int) $search_status).")";
}
if ($search_employee == 1) {
$filters[] = "(employee:=:1)";
}
$sqlfilter = '';
if (!empty($filters)) {
$sqlfilter = implode(' AND ', $filters);
}
// Load hierarchy of users
$user_arbo_all = $userstatic->get_full_tree(0, '');
if ($sqlfilter) {
$user_arbo = $userstatic->get_full_tree(0, $sqlfilter);
} else {
$user_arbo = $user_arbo_all;
}
// Count total nb of records
$nbtotalofrecords = count($user_arbo);
if (!is_array($user_arbo) && $user_arbo < 0) {
setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
} else {
// Define fulltree array
$fulltree = $user_arbo;
//var_dump($fulltree);
// Define data (format for treeview)
$data = array();
$data[0] = array('rowid' => 0, 'fk_menu' => -1, 'title' => 'racine', 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
foreach ($fulltree as $key => $val) {
$userstatic->id = $val['id'];
$userstatic->ref = (string) $val['id'];
$userstatic->login = $val['login'];
$userstatic->firstname = $val['firstname'];
$userstatic->lastname = $val['lastname'];
$userstatic->status = $val['statut'];
$userstatic->email = $val['email'];
$userstatic->gender = $val['gender'];
$userstatic->socid = $val['fk_soc'];
$userstatic->admin = $val['admin'];
$userstatic->entity = $val['entity'];
$userstatic->photo = $val['photo'];
$entity = $val['entity'];
$entitystring = '';
// TODO Set of entitystring should be done with a hook
if (isModEnabled('multicompany') && isset($mc) && is_object($mc)) {
if (empty($entity)) {
$entitystring = $langs->trans("AllEntities");
} else {
$mc->getInfo($entity);
$entitystring = $mc->label;
}
}
$li = $userstatic->getNomUrl(-1, '', 0, 1);
if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
$li .= img_picto($langs->trans("SuperAdministratorDesc"), 'superadmin', 'class="valignmiddle paddingright paddingleft"');
} elseif ($userstatic->admin) {
$li .= img_picto($langs->trans("AdministratorDesc"), 'admin', 'class="valignmiddle paddingright paddingleft"');
}
$li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
$entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$userstatic->getLibStatut(2).'</td></tr></table>';
$data[$val['rowid']] = array(
'rowid' => $val['rowid'],
'fk_menu' => $val['fk_user'], // TODO Replace fk_menu with fk_parent
'statut' => $val['statut'],
'entry' => $entry
);
}
// Loop on $data to link user linked to a parent that was excluded by the filter
foreach ($data as $key => $tmpdata) {
$idparent = $tmpdata['fk_menu'];
// Loop to check if parent exists
if ($idparent > 0) {
$parentfound = array_key_exists($idparent, $data) ? 1 : 0;
$i = 0;
while (!$parentfound && $i < 50) {
// Parent was not found but we need it to show the child, so we reintroduce the parent
if (!empty($user_arbo_all[$idparent])) {
$val = $user_arbo_all[$idparent];
$userstatic->id = $val['id'];
$userstatic->ref = (string) $val['id'];
$userstatic->login = $val['login'];
$userstatic->firstname = $val['firstname'];
$userstatic->lastname = $val['lastname'];
$userstatic->status = $val['statut'];
$userstatic->email = $val['email'];
$userstatic->gender = $val['gender'];
$userstatic->socid = $val['fk_soc'];
$userstatic->admin = $val['admin'];
$userstatic->entity = $val['entity'];
$userstatic->photo = $val['photo'];
$entity = $val['entity'];
$entitystring = '';
// TODO Set of entitystring should be done with a hook
if (isModEnabled('multicompany') && isset($mc) && is_object($mc)) {
if (empty($entity)) {
$entitystring = $langs->trans("AllEntities");
} else {
$mc->getInfo($entity);
$entitystring = $mc->label;
}
}
$li = '<span class="opacitymedium">';
$li .= $userstatic->getNomUrl(-1, '', 0, 1);
if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
$li .= img_picto($langs->trans("SuperAdministrator"), 'superadmin');
} elseif ($userstatic->admin) {
$li .= img_picto($langs->trans("Administrator"), 'admin');
}
$li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
$li .= ' - <span class="opacitymedium">'.$langs->trans("ExcludedByFilter").'</span>';
$li .= '</span>';
$entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$userstatic->getLibStatut(2).'</td></tr></table>';
$data[$idparent] = array(
'rowid' => $idparent,
'fk_menu' => $user_arbo_all[$idparent]['fk_user'],
'statut' => $user_arbo_all[$idparent]['statut'],
'entry' => $entry
);
$idparent = $user_arbo_all[$idparent]['fk_user'];
if ($idparent > 0) {
$parentfound = array_key_exists($idparent, $data) ? 1 : 0;
} else {
$parentfound = 1;
}
//var_dump($data[$idparent]);
} else {
// We should not be here. If a record has a parent id, parent id should be into $user_arbo_all
$data[$key]['fk_menu'] = -2;
if (empty($data[-2])) {
$li = '<span class="opacitymedium">'.$langs->trans("WarningParentIDDoesNotExistAnymore").'</span>';
$entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="usertddisabled">'.$li.'</td><td align="right" class="usertddisabled"></td></tr></table>';
$data[-2] = array(
'rowid' => -2,
'fk_menu' => null,
'statut' => 1,
'entry' => $entry
);
}
$parentfound = 1;
}
$i++;
}
}
}
//var_dump($data);exit;
$param = "&search_status=".urlencode($search_status);
$param = "&contextpage=".urlencode($contextpage);
$newcardbutton = '';
$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
$newcardbutton .= dolGetButtonTitle($langs->trans('HierarchicView'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php?mode=hierarchy'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', (($mode == 'hierarchy') ? 2 : 1), array('morecss' => 'reposition'));
$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/user/list.php?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
$newcardbutton .= dolGetButtonTitleSeparator();
$newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', (int) $permissiontoadd);
$massactionbutton = '';
$num = 0;
$limit = 0;
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $newcardbutton, '', $limit, 0, 0, 1);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
print '<table class="liste nohover centpercent">';
print '<tr class="liste_titre_filter">';
// Action column
if ($conf->main_checkbox_left_column) {
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
print $searchpicto;
print '</td>';
}
print '<td class="liste_titre"> </td>';
print '<td class="liste_titre"> </td>';
// Status
print '<td class="liste_titre right parentonrightofpage">';
print $form->selectarray('search_status', array('-1' => '', '0' => $langs->trans('Disabled'), '1' => $langs->trans('Enabled')), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp onrightofpage width100');
print '</td>';
// Action column
if (!$conf->main_checkbox_left_column) {
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
print $searchpicto;
print '</td>';
}
print '</tr>';
print '<tr class="liste_titre">';
// Action column
if ($conf->main_checkbox_left_column) {
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
}
print_liste_field_titre("HierarchicView");
print_liste_field_titre('<div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a> | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a></div>', $_SERVER['PHP_SELF'], "", '', "", 'align="center"');
print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", '', '', '', 'right onrightofpage');
// Action column
if (!$conf->main_checkbox_left_column) {
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
}
print '</tr>';
$nbofentries = (count($data) - 1);
if ($nbofentries > 0) {
print '<tr>';
// Action column
if ($conf->main_checkbox_left_column) {
print '<td></td>';
}
print '<td colspan="3">';
tree_recur($data, $data[0], 0);
print '</td>';
// Action column
if (!$conf->main_checkbox_left_column) {
print '<td></td>';
}
print '</tr>';
} else {
print '<tr class="oddeven">';
print '<td colspan="3">';
print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
print '<td valign="middle">';
print $langs->trans("NoCategoryYet");
print '</td>';
print '<td> </td>';
print '</table>';
print '</td>';
print '<td></td>';
print '</tr>';
}
print "</table>";
print '</div>';
print "</form>\n";
}
//
/*print '<script type="text/javascript">
jQuery(document).ready(function() {
function init_myfunc()
{
jQuery(".usertddisabled").hide();
}
init_myfunc();
});
</script>';
*/
// End of page
llxFooter();
$db->close();