dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 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
34// Load translation files required by page
35$langs->loadLangs(array('users', 'companies', 'hrm', 'salaries'));
36
37// Security check (for external users)
38$socid = 0;
39if ($user->socid > 0) {
40 $socid = $user->socid;
41}
42
43$optioncss = GETPOST('optioncss', 'alpha');
44$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userlist'; // To manage different context of search
45$mode = GETPOST("mode", 'alpha');
46if (empty($mode)) {
47 $mode = 'hierarchy';
48}
49
50$sortfield = GETPOST('sortfield', 'aZ09comma');
51$sortorder = GETPOST('sortorder', 'aZ09comma');
52$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
53
54
55$search_status = GETPOST('search_status', 'intcomma');
56if ($search_status == '') {
57 $search_status = '1';
58}
59
60if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
61 $search_status = "";
62}
63
64$search_employee = -1;
65if ($contextpage == 'employeelist') {
66 $search_employee = 1;
67}
68
69$userstatic = new User($db);
70
71// Define value to know what current user can do on users
72$permissiontoadd = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
73
74// Permission to list
75if (isModEnabled('salaries') && $contextpage == 'employeelist' && $search_employee == 1) {
76 if (!$user->hasRight("salaries", "read")) {
78 }
79} else {
80 if (!$user->hasRight("user", "user", "read") && empty($user->admin)) {
82 }
83}
84
85$childids = $user->getAllChildIds(1);
86
87
88
89/*
90 * View
91 */
92
93$form = new Form($db);
94
95$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios|DE:Modul_Benutzer';
96if ($contextpage == 'employeelist' && $search_employee == 1) {
97 $title = $langs->trans("Employees");
98} else {
99 $title = $langs->trans("Users");
100}
101$arrayofjs = array(
102 '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
103 '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
104);
105$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
106
107llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist mod-user page-hierarchy');
108
109$filters = [];
110if (($search_status != '' && $search_status >= 0)) {
111 $filters[] = "statut = ".((int) $search_status);
112}
113if (($search_employee != '' && $search_employee >= 0)) {
114 $filters[] = "employee = ".((int) $search_employee);
115}
116$sqlfilter = '';
117if (!empty($filters)) {
118 $sqlfilter = implode(' AND ', $filters);
119}
120// Load hierarchy of users
121$user_arbo_all = $userstatic->get_full_tree(0, '');
122if ($sqlfilter) {
123 $user_arbo = $userstatic->get_full_tree(0, $sqlfilter);
124} else {
125 $user_arbo = $user_arbo_all;
126}
127
128// Count total nb of records
129$nbtotalofrecords = count($user_arbo);
130
131
132if (!is_array($user_arbo) && $user_arbo < 0) {
133 setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
134} else {
135 // Define fulltree array
136 $fulltree = $user_arbo;
137 //var_dump($fulltree);
138 // Define data (format for treeview)
139 $data = array();
140 $data[0] = array('rowid' => 0, 'fk_menu' => -1, 'title' => "racine", 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
141
142 foreach ($fulltree as $key => $val) {
143 $userstatic->id = $val['id'];
144 $userstatic->ref = (string) $val['id'];
145 $userstatic->login = $val['login'];
146 $userstatic->firstname = $val['firstname'];
147 $userstatic->lastname = $val['lastname'];
148 $userstatic->status = $val['statut'];
149 $userstatic->email = $val['email'];
150 $userstatic->gender = $val['gender'];
151 $userstatic->socid = $val['fk_soc'];
152 $userstatic->admin = $val['admin'];
153 $userstatic->entity = $val['entity'];
154 $userstatic->photo = $val['photo'];
155
156 $entity = $val['entity'];
157 $entitystring = '';
158
159 // TODO Set of entitystring should be done with a hook
160 if (isModEnabled('multicompany') && is_object($mc)) {
161 if (empty($entity)) {
162 $entitystring = $langs->trans("AllEntities");
163 } else {
164 $mc->getInfo($entity);
165 $entitystring = $mc->label;
166 }
167 }
168
169 $li = $userstatic->getNomUrl(-1, '', 0, 1);
170 if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
171 $li .= img_picto($langs->trans("SuperAdministratorDesc"), 'redstar', 'class="valignmiddle paddingright paddingleft"');
172 } elseif ($userstatic->admin) {
173 $li .= img_picto($langs->trans("AdministratorDesc"), 'star', 'class="valignmiddle paddingright paddingleft"');
174 }
175 $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
176
177 $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>';
178
179 $data[$val['rowid']] = array(
180 'rowid' => $val['rowid'],
181 'fk_menu' => $val['fk_user'], // TODO Replace fk_menu with fk_parent
182 'statut' => $val['statut'],
183 'entry' => $entry
184 );
185 }
186
187 // Loop on $data to link user linked to a parent that was excluded by the filter
188 foreach ($data as $key => $tmpdata) {
189 $idparent = $tmpdata['fk_menu'];
190 // Loop to check if parent exists
191 if ($idparent > 0) {
192 $parentfound = array_key_exists($idparent, $data) ? 1 : 0;
193
194 $i = 0;
195 while (!$parentfound && $i < 50) {
196 // Parent was not found but we need it to show the child, so we reintroduce the parent
197 if (!empty($user_arbo_all[$idparent])) {
198 $val = $user_arbo_all[$idparent];
199 $userstatic->id = $val['id'];
200 $userstatic->ref = (string) $val['id'];
201 $userstatic->login = $val['login'];
202 $userstatic->firstname = $val['firstname'];
203 $userstatic->lastname = $val['lastname'];
204 $userstatic->status = $val['statut'];
205 $userstatic->email = $val['email'];
206 $userstatic->gender = $val['gender'];
207 $userstatic->socid = $val['fk_soc'];
208 $userstatic->admin = $val['admin'];
209 $userstatic->entity = $val['entity'];
210 $userstatic->photo = $val['photo'];
211
212 $entity = $val['entity'];
213 $entitystring = '';
214
215 // TODO Set of entitystring should be done with a hook
216 if (isModEnabled('multicompany') && is_object($mc)) {
217 if (empty($entity)) {
218 $entitystring = $langs->trans("AllEntities");
219 } else {
220 $mc->getInfo($entity);
221 $entitystring = $mc->label;
222 }
223 }
224
225 $li = '<span class="opacitymedium">';
226 $li .= $userstatic->getNomUrl(-1, '', 0, 1);
227 if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
228 $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
229 } elseif ($userstatic->admin) {
230 $li .= img_picto($langs->trans("Administrator"), 'star');
231 }
232 $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
233 $li .= ' - <span class="opacitymedium">'.$langs->trans("ExcludedByFilter").'</span>';
234 $li .= '</span>';
235
236 $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>';
237
238 $data[$idparent] = array(
239 'rowid' => $idparent,
240 'fk_menu' => $user_arbo_all[$idparent]['fk_user'],
241 'statut' => $user_arbo_all[$idparent]['statut'],
242 'entry' => $entry
243 );
244 $idparent = $user_arbo_all[$idparent]['fk_user'];
245 if ($idparent > 0) {
246 $parentfound = array_key_exists($idparent, $data) ? 1 : 0;
247 } else {
248 $parentfound = 1;
249 }
250 //var_dump($data[$idparent]);
251 } else {
252 // We should not be here. If a record has a parent id, parent id should be into $user_arbo_all
253 $data[$key]['fk_menu'] = -2;
254 if (empty($data[-2])) {
255 $li = '<span class="opacitymedium">'.$langs->trans("WarningParentIDDoesNotExistAnymore").'</span>';
256 $entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="usertddisabled">'.$li.'</td><td align="right" class="usertddisabled"></td></tr></table>';
257 $data[-2] = array(
258 'rowid' => '-2',
259 'fk_menu' => null,
260 'statut' => '1',
261 'entry' => $entry
262 );
263 }
264 $parentfound = 1;
265 }
266
267 $i++;
268 }
269 }
270 }
271 //var_dump($data);exit;
272
273 $param = "&search_status=".urlencode($search_status);
274 $param = "&contextpage=".urlencode($contextpage);
275
276 $newcardbutton = '';
277 $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'));
278 $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'));
279 $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'));
280 $newcardbutton .= dolGetButtonTitleSeparator();
281 $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', (int) $permissiontoadd);
282
283 $massactionbutton = '';
284 $num = 0;
285 $limit = 0;
286
287 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $newcardbutton, '', $limit, 0, 0, 1);
288
289 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
290 if ($optioncss != '') {
291 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
292 }
293 print '<input type="hidden" name="token" value="'.newToken().'">';
294 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
295 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
296 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
297 print '<input type="hidden" name="page" value="'.$page.'">';
298 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
299 print '<input type="hidden" name="mode" value="'.$mode.'">';
300
301 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
302 print '<table class="liste nohover centpercent">';
303
304 print '<tr class="liste_titre_filter">';
305 // Action column
306 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
307 print '<td class="liste_titre maxwidthsearch">';
308 $searchpicto = $form->showFilterAndCheckAddButtons(0);
309 print $searchpicto;
310 print '</td>';
311 }
312 print '<td class="liste_titre">&nbsp;</td>';
313 print '<td class="liste_titre">&nbsp;</td>';
314 // Status
315 print '<td class="liste_titre right parentonrightofpage">';
316 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');
317 print '</td>';
318 // Action column
319 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
320 print '<td class="liste_titre maxwidthsearch">';
321 $searchpicto = $form->showFilterAndCheckAddButtons(0);
322 print $searchpicto;
323 print '</td>';
324 }
325 print '</tr>';
326
327 print '<tr class="liste_titre">';
328 // Action column
329 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
330 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
331 }
332 print_liste_field_titre("HierarchicView");
333 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"');
334 print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", '', '', '', 'right onrightofpage');
335 // Action column
336 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
337 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
338 }
339 print '</tr>';
340
341
342 $nbofentries = (count($data) - 1);
343
344 if ($nbofentries > 0) {
345 print '<tr>';
346 // Action column
347 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
348 print '<td></td>';
349 }
350 print '<td colspan="3">';
351 tree_recur($data, $data[0], 0);
352 print '</td>';
353 // Action column
354 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
355 print '<td></td>';
356 }
357 print '</tr>';
358 } else {
359 print '<tr class="oddeven">';
360 print '<td colspan="3">';
361 print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
362 print '<td valign="middle">';
363 print $langs->trans("NoCategoryYet");
364 print '</td>';
365 print '<td>&nbsp;</td>';
366 print '</table>';
367 print '</td>';
368 print '<td></td>';
369 print '</tr>';
370 }
371
372 print "</table>";
373 print '</div>';
374
375 print "</form>\n";
376}
377
378//
379/*print '<script type="text/javascript">
380jQuery(document).ready(function() {
381 function init_myfunc()
382 {
383 jQuery(".usertddisabled").hide();
384 }
385 init_myfunc();
386});
387</script>';
388*/
389
390// End of page
391llxFooter();
392$db->close();
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:70
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a 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.