dolibarr 20.0.2
hierarchy.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
4 * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
6 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
32
33// Load translation files required by page
34$langs->loadLangs(array('users', 'companies', 'hrm', 'salaries'));
35
36// Security check (for external users)
37$socid = 0;
38if ($user->socid > 0) {
39 $socid = $user->socid;
40}
41
42$optioncss = GETPOST('optioncss', 'alpha');
43$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userlist'; // To manage different context of search
44$mode = GETPOST("mode", 'alpha');
45if (empty($mode)) {
46 $mode = 'hierarchy';
47}
48
49$sortfield = GETPOST('sortfield', 'aZ09comma');
50$sortorder = GETPOST('sortorder', 'aZ09comma');
51$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
52
53
54$search_status = GETPOST('search_status', 'intcomma');
55if ($search_status == '') {
56 $search_status = '1';
57}
58
59if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
60 $search_status = "";
61}
62
63$search_employee = -1;
64if ($contextpage == 'employeelist') {
65 $search_employee = 1;
66}
67
68$userstatic = new User($db);
69
70// Define value to know what current user can do on users
71$canadduser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
72
73// Permission to list
74if (isModEnabled('salaries') && $contextpage == 'employeelist' && $search_employee == 1) {
75 if (!$user->hasRight("salaries", "read")) {
77 }
78} else {
79 if (!$user->hasRight("user", "user", "read") && empty($user->admin)) {
81 }
82}
83
84$childids = $user->getAllChildIds(1);
85
86
87
88/*
89 * View
90 */
91
92$form = new Form($db);
93
94$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios|DE:Modul_Benutzer';
95if ($contextpage == 'employeelist' && $search_employee == 1) {
96 $title = $langs->trans("Employees");
97} else {
98 $title = $langs->trans("Users");
99}
100$arrayofjs = array(
101 '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
102 '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
103);
104$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
105
106llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist mod-user page-hierarchy');
107
108$filters = [];
109if (($search_status != '' && $search_status >= 0)) {
110 $filters[] = "statut = ".((int) $search_status);
111}
112if (($search_employee != '' && $search_employee >= 0)) {
113 $filters[] = "employee = ".((int) $search_employee);
114}
115$sqlfilter= '';
116if (!empty($filters)) {
117 $sqlfilter = implode(' AND ', $filters);
118}
119// Load hierarchy of users
120$user_arbo_all = $userstatic->get_full_tree(0, '');
121if ($sqlfilter) {
122 $user_arbo = $userstatic->get_full_tree(0, $sqlfilter);
123} else {
124 $user_arbo = $user_arbo_all;
125}
126
127// Count total nb of records
128$nbtotalofrecords = count($user_arbo);
129
130
131if (!is_array($user_arbo) && $user_arbo < 0) {
132 setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
133} else {
134 // Define fulltree array
135 $fulltree = $user_arbo;
136 //var_dump($fulltree);
137 // Define data (format for treeview)
138 $data = array();
139 $data[0] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
140
141 foreach ($fulltree as $key => $val) {
142 $userstatic->id = $val['id'];
143 $userstatic->ref = (string) $val['id'];
144 $userstatic->login = $val['login'];
145 $userstatic->firstname = $val['firstname'];
146 $userstatic->lastname = $val['lastname'];
147 $userstatic->status = $val['statut'];
148 $userstatic->email = $val['email'];
149 $userstatic->gender = $val['gender'];
150 $userstatic->socid = $val['fk_soc'];
151 $userstatic->admin = $val['admin'];
152 $userstatic->entity = $val['entity'];
153 $userstatic->photo = $val['photo'];
154
155 $entity = $val['entity'];
156 $entitystring = '';
157
158 // TODO Set of entitystring should be done with a hook
159 if (isModEnabled('multicompany') && is_object($mc)) {
160 if (empty($entity)) {
161 $entitystring = $langs->trans("AllEntities");
162 } else {
163 $mc->getInfo($entity);
164 $entitystring = $mc->label;
165 }
166 }
167
168 $li = $userstatic->getNomUrl(-1, '', 0, 1);
169 if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
170 $li .= img_picto($langs->trans("SuperAdministratorDesc"), 'redstar', 'class="valignmiddle paddingright paddingleft"');
171 } elseif ($userstatic->admin) {
172 $li .= img_picto($langs->trans("AdministratorDesc"), 'star', 'class="valignmiddle paddingright paddingleft"');
173 }
174 $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
175
176 $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>';
177
178 $data[$val['rowid']] = array(
179 'rowid'=>$val['rowid'],
180 'fk_menu'=>$val['fk_user'], // TODO Replace fk_menu with fk_parent
181 'statut'=>$val['statut'],
182 'entry'=>$entry
183 );
184 }
185
186 // Loop on $data to link user linked to a parent that was excluded by the filter
187 foreach ($data as $key => $tmpdata) {
188 $idparent = $tmpdata['fk_menu'];
189 // Loop to check if parent exists
190 if ($idparent > 0) {
191 $parentfound = array_key_exists($idparent, $data) ? 1 : 0;
192
193 $i = 0;
194 while (!$parentfound && $i < 50) {
195 // Parent was not found but we need it to show the child, so we reintroduce the parent
196 if (!empty($user_arbo_all[$idparent])) {
197 $val = $user_arbo_all[$idparent];
198 $userstatic->id = $val['id'];
199 $userstatic->ref = (string) $val['id'];
200 $userstatic->login = $val['login'];
201 $userstatic->firstname = $val['firstname'];
202 $userstatic->lastname = $val['lastname'];
203 $userstatic->status = $val['statut'];
204 $userstatic->email = $val['email'];
205 $userstatic->gender = $val['gender'];
206 $userstatic->socid = $val['fk_soc'];
207 $userstatic->admin = $val['admin'];
208 $userstatic->entity = $val['entity'];
209 $userstatic->photo = $val['photo'];
210
211 $entity = $val['entity'];
212 $entitystring = '';
213
214 // TODO Set of entitystring should be done with a hook
215 if (isModEnabled('multicompany') && is_object($mc)) {
216 if (empty($entity)) {
217 $entitystring = $langs->trans("AllEntities");
218 } else {
219 $mc->getInfo($entity);
220 $entitystring = $mc->label;
221 }
222 }
223
224 $li = '<span class="opacitymedium">';
225 $li .= $userstatic->getNomUrl(-1, '', 0, 1);
226 if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
227 $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
228 } elseif ($userstatic->admin) {
229 $li .= img_picto($langs->trans("Administrator"), 'star');
230 }
231 $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
232 $li .= ' - <span class="opacitymedium">'.$langs->trans("ExcludedByFilter").'</span>';
233 $li .= '</span>';
234
235 $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>';
236
237 $data[$idparent] = array(
238 'rowid' => $idparent,
239 'fk_menu' => $user_arbo_all[$idparent]['fk_user'],
240 'statut' => $user_arbo_all[$idparent]['statut'],
241 'entry' => $entry
242 );
243 $idparent = $user_arbo_all[$idparent]['fk_user'];
244 if ($idparent > 0) {
245 $parentfound = array_key_exists($idparent, $data) ? 1 : 0;
246 } else {
247 $parentfound = 1;
248 }
249 //var_dump($data[$idparent]);
250 } else {
251 // We should not be here. If a record has a parent id, parent id should be into $user_arbo_all
252 $data[$key]['fk_menu'] = -2;
253 if (empty($data[-2])) {
254 $li = '<span class="opacitymedium">'.$langs->trans("WarningParentIDDoesNotExistAnymore").'</span>';
255 $entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="usertddisabled">'.$li.'</td><td align="right" class="usertddisabled"></td></tr></table>';
256 $data[-2] = array(
257 'rowid'=>'-2',
258 'fk_menu'=>null,
259 'statut'=>'1',
260 'entry'=>$entry
261 );
262 }
263 $parentfound = 1;
264 }
265
266 $i++;
267 }
268 }
269 }
270 //var_dump($data);exit;
271
272 $param = "&search_status=".urlencode($search_status);
273 $param = "&contextpage=".urlencode($contextpage);
274
275 $newcardbutton = '';
276 $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'));
277 $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'));
278 $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'));
279 $newcardbutton .= dolGetButtonTitleSeparator();
280 $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', $canadduser);
281
282 $massactionbutton = '';
283 $num = 0;
284 $limit = 0;
285
286 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $newcardbutton, '', $limit, 0, 0, 1);
287
288 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
289 if ($optioncss != '') {
290 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
291 }
292 print '<input type="hidden" name="token" value="'.newToken().'">';
293 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
294 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
295 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
296 print '<input type="hidden" name="page" value="'.$page.'">';
297 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
298 print '<input type="hidden" name="mode" value="'.$mode.'">';
299
300 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
301 print '<table class="liste nohover centpercent">';
302
303 print '<tr class="liste_titre_filter">';
304 // Action column
305 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
306 print '<td class="liste_titre maxwidthsearch">';
307 $searchpicto = $form->showFilterAndCheckAddButtons(0);
308 print $searchpicto;
309 print '</td>';
310 }
311 print '<td class="liste_titre">&nbsp;</td>';
312 print '<td class="liste_titre">&nbsp;</td>';
313 // Status
314 print '<td class="liste_titre right parentonrightofpage">';
315 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');
316 print '</td>';
317 // Action column
318 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
319 print '<td class="liste_titre maxwidthsearch">';
320 $searchpicto = $form->showFilterAndCheckAddButtons(0);
321 print $searchpicto;
322 print '</td>';
323 }
324 print '</tr>';
325
326 print '<tr class="liste_titre">';
327 // Action column
328 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
329 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
330 }
331 print_liste_field_titre("HierarchicView");
332 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"');
333 print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", '', '', '', 'right onrightofpage');
334 // Action column
335 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
336 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
337 }
338 print '</tr>';
339
340
341 $nbofentries = (count($data) - 1);
342
343 if ($nbofentries > 0) {
344 print '<tr>';
345 // Action column
346 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
347 print '<td></td>';
348 }
349 print '<td colspan="3">';
350 tree_recur($data, $data[0], 0);
351 print '</td>';
352 // Action column
353 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
354 print '<td></td>';
355 }
356 print '</tr>';
357 } else {
358 print '<tr class="oddeven">';
359 print '<td colspan="3">';
360 print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
361 print '<td valign="middle">';
362 print $langs->trans("NoCategoryYet");
363 print '</td>';
364 print '<td>&nbsp;</td>';
365 print '</table>';
366 print '</td>';
367 print '<td></td>';
368 print '</tr>';
369 }
370
371 print "</table>";
372 print '</div>';
373
374 print "</form>\n";
375}
376
377//
378/*print '<script type="text/javascript">
379jQuery(document).ready(function() {
380 function init_myfunc()
381 {
382 jQuery(".usertddisabled").hide();
383 }
384 init_myfunc();
385});
386</script>';
387*/
388
389// End of page
390llxFooter();
391$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.