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