dolibarr  16.0.5
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-2021 Frédéric France <frederic.france@netlogic.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 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
31 
32 // Load translation files required by page
33 $langs->loadLangs(array('users', 'companies'));
34 
35 // Security check (for external users)
36 $socid = 0;
37 if ($user->socid > 0) {
38  $socid = $user->socid;
39 }
40 
41 $optioncss = GETPOST('optioncss', 'alpha');
42 $contextpage = GETPOST('optioncss', 'aZ09');
43 $sortfield = GETPOST('sortfield', 'aZ09comma');
44 $sortorder = GETPOST('sortorder', 'aZ09comma');
45 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
46 
47 // Load mode employee
48 $mode = GETPOST("mode", 'alpha');
49 
50 $search_statut = GETPOST('search_statut', 'int');
51 
52 if ($search_statut == '' || $search_statut == '0') {
53  $search_statut = '1';
54 }
55 
56 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
57  $search_statut = "";
58 }
59 
60 $userstatic = new User($db);
61 
62 // Define value to know what current user can do on users
63 $canadduser = (!empty($user->admin) || $user->rights->user->user->creer);
64 
65 if (!$user->rights->user->user->lire && !$user->admin) {
67 }
68 
69 $childids = $user->getAllChildIds(1);
70 
71 
72 /*
73  * View
74  */
75 
76 $form = new Form($db);
77 
78 $help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios|DE:Modul_Benutzer';
79 $title = $langs->trans("Users");
80 $arrayofjs = array(
81  '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
82  '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
83 );
84 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
85 
86 llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist');
87 
88 
89 // Load hierarchy of users
90 $user_arbo = $userstatic->get_full_tree(0, ($search_statut != '' && $search_statut >= 0) ? "statut = ".$search_statut : '');
91 
92 
93 // Count total nb of records
94 $nbtotalofrecords = count($user_arbo);
95 
96 
97 if (!is_array($user_arbo) && $user_arbo < 0) {
98  setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
99 } else {
100  // Define fulltree array
101  $fulltree = $user_arbo;
102  //var_dump($fulltree);
103  // Define data (format for treeview)
104  $data = array();
105  $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
106  foreach ($fulltree as $key => $val) {
107  $userstatic->id = $val['id'];
108  $userstatic->ref = $val['id'];
109  $userstatic->login = $val['login'];
110  $userstatic->firstname = $val['firstname'];
111  $userstatic->lastname = $val['lastname'];
112  $userstatic->statut = $val['statut'];
113  $userstatic->email = $val['email'];
114  $userstatic->gender = $val['gender'];
115  $userstatic->socid = $val['fk_soc'];
116  $userstatic->admin = $val['admin'];
117  $userstatic->entity = $val['entity'];
118  $userstatic->photo = $val['photo'];
119 
120  $entity = $val['entity'];
121  $entitystring = '';
122 
123  // TODO Set of entitystring should be done with a hook
124  if (!empty($conf->multicompany->enabled) && is_object($mc)) {
125  if (empty($entity)) {
126  $entitystring = $langs->trans("AllEntities");
127  } else {
128  $mc->getInfo($entity);
129  $entitystring = $mc->label;
130  }
131  }
132 
133  $li = $userstatic->getNomUrl(-1, '', 0, 1);
134  if (!empty($conf->multicompany->enabled) && $userstatic->admin && !$userstatic->entity) {
135  $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
136  } elseif ($userstatic->admin) {
137  $li .= img_picto($langs->trans("Administrator"), 'star');
138  }
139  $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
140 
141  $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>';
142 
143  $data[] = array(
144  'rowid'=>$val['rowid'],
145  'fk_menu'=>$val['fk_user'],
146  'statut'=>$val['statut'],
147  'entry'=>$entry
148  );
149  }
150 
151  //var_dump($data);
152 
153  $param = "&search_statut=".urlencode($search_statut);
154 
155  $newcardbutton = '';
156  $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'));
157  $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'));
158  $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'));
159  $newcardbutton .= dolGetButtonTitleSeparator();
160  $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', $canadduser);
161 
162  $massactionbutton = '';
163  $num = 0;
164  $limit = 0;
165 
166  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $newcardbutton, '', $limit, 0, 0, 1);
167 
168  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
169  if ($optioncss != '') {
170  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
171  }
172  print '<input type="hidden" name="token" value="'.newToken().'">';
173  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
174  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
175  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
176  print '<input type="hidden" name="page" value="'.$page.'">';
177  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
178  print '<input type="hidden" name="mode" value="'.$mode.'">';
179 
180  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
181  print '<table class="liste nohover centpercent">';
182 
183  print '<tr class="liste_titre_filter">';
184  print '<td class="liste_titre">&nbsp;</td>';
185  print '<td class="liste_titre">&nbsp;</td>';
186  // Status
187  print '<td class="liste_titre right">';
188  print $form->selectarray('search_statut', array('-1'=>'', '1'=>$langs->trans('Enabled')), $search_statut, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp');
189  print '</td>';
190  print '<td class="liste_titre maxwidthsearch">';
191  $searchpicto = $form->showFilterAndCheckAddButtons(0);
192  print $searchpicto;
193  print '</td>';
194  print '</tr>';
195 
196  print '<tr class="liste_titre">';
197  print_liste_field_titre("HierarchicView");
198  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"');
199  print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", 'align="right"');
200  print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
201  print '</tr>';
202 
203 
204  $nbofentries = (count($data) - 1);
205 
206  if ($nbofentries > 0) {
207  print '<tr><td colspan="3">';
208  tree_recur($data, $data[0], 0);
209  print '</td>';
210  print '<td></td>';
211  print '</tr>';
212  } else {
213  print '<tr class="oddeven">';
214  print '<td colspan="3">';
215  print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
216  print '<td valign="middle">';
217  print $langs->trans("NoCategoryYet");
218  print '</td>';
219  print '<td>&nbsp;</td>';
220  print '</table>';
221  print '</td>';
222  print '<td></td>';
223  print '</tr>';
224  }
225 
226  print "</table>";
227  print '</div>';
228 
229  print "</form>\n";
230 }
231 
232 //
233 /*print '<script type="text/javascript">
234 jQuery(document).ready(function() {
235  function init_myfunc()
236  {
237  jQuery(".usertddisabled").hide();
238  }
239  init_myfunc();
240 });
241 </script>';
242 */
243 
244 // End of page
245 llxFooter();
246 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dolGetButtonTitleSeparator
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
Definition: functions.lib.php:10570
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
tree_recur
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.
Definition: treeview.lib.php:114
print_barre_liste
print_barre_liste($titre, $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.
Definition: functions.lib.php:5257
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59