dolibarr  13.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 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 if (!$user->rights->user->user->lire && !$user->admin)
34 
35 // Load translation files required by page
36 $langs->loadLangs(array('users', 'companies'));
37 
38 // Security check (for external users)
39 $socid = 0;
40 if ($user->socid > 0)
41  $socid = $user->socid;
42 
43 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
44 $search_user = GETPOST('search_user', 'alpha');
45 
46 // Load mode employee
47 $mode = GETPOST("mode", 'alpha');
48 
49 $userstatic = new User($db);
50 $search_statut = GETPOST('search_statut', 'int');
51 
52 if ($search_statut == '') $search_statut = '1';
53 
54 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers
55 {
56  $search_statut = "";
57 }
58 
59 // Define value to know what current user can do on users
60 $canadduser = (!empty($user->admin) || $user->rights->user->user->creer);
61 
62 
63 
64 /*
65  * View
66  */
67 
68 $form = new Form($db);
69 
70 $arrayofjs = array(
71  '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
72  '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
73 );
74 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
75 
76 llxHeader('', $langs->trans("ListOfUsers").' - '.$langs->trans("HierarchicView"), '', '', 0, 0, $arrayofjs, $arrayofcss);
77 
78 
79 // Load hierarchy of users
80 $user_arbo = $userstatic->get_full_tree(0, ($search_statut != '' && $search_statut >= 0) ? "statut = ".$search_statut : '');
81 
82 if (!is_array($user_arbo) && $user_arbo < 0)
83 {
84  setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
85 } else {
86  // Define fulltree array
87  $fulltree = $user_arbo;
88  //var_dump($fulltree);
89  // Define data (format for treeview)
90  $data = array();
91  $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
92  foreach ($fulltree as $key => $val)
93  {
94  $userstatic->id = $val['id'];
95  $userstatic->ref = $val['label'];
96  $userstatic->login = $val['login'];
97  $userstatic->firstname = $val['firstname'];
98  $userstatic->lastname = $val['lastname'];
99  $userstatic->statut = $val['statut'];
100  $userstatic->email = $val['email'];
101  $userstatic->gender = $val['gender'];
102  $userstatic->socid = $val['fk_soc'];
103  $userstatic->admin = $val['admin'];
104  $userstatic->entity = $val['entity'];
105  $userstatic->photo = $val['photo'];
106 
107  $entity = $val['entity'];
108  $entitystring = '';
109 
110  // TODO Set of entitystring should be done with a hook
111  if (!empty($conf->multicompany->enabled) && is_object($mc))
112  {
113  if (empty($entity))
114  {
115  $entitystring = $langs->trans("AllEntities");
116  } else {
117  $mc->getInfo($entity);
118  $entitystring = $mc->label;
119  }
120  }
121 
122  $li = $userstatic->getNomUrl(-1, '', 0, 1);
123  if (!empty($conf->multicompany->enabled) && $userstatic->admin && !$userstatic->entity)
124  {
125  $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
126  } elseif ($userstatic->admin)
127  {
128  $li .= img_picto($langs->trans("Administrator"), 'star');
129  }
130  $li .= ' ('.$val['login'].($entitystring ? ' - '.$entitystring : '').')';
131 
132  $entry = '<table class="nobordernopadding centpercent"><tr><td class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$userstatic->getLibStatut(2).'</td></tr></table>';
133 
134  $data[] = array(
135  'rowid'=>$val['rowid'],
136  'fk_menu'=>$val['fk_user'],
137  'statut'=>$val['statut'],
138  'entry'=>$entry
139  );
140  }
141 
142  //var_dump($data);
143 
144  $title = $langs->trans("ListOfUsers").' - '.$langs->trans("HierarchicView");
145 
146  $param = "search_statut=".urlencode($search_statut);
147 
148  $newcardbutton = '';
149  $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', $canadduser);
150 
151  $morehtmlright .= dolGetButtonTitle($langs->trans("List"), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php'.(($search_statut != '' && $search_statut >= 0) ? '?search_statut='.$search_statut : ''));
152  $param = array('morecss'=>'marginleftonly btnTitleSelected');
153  $morehtmlright .= dolGetButtonTitle($langs->trans("HierarchicView"), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php'.(($search_statut != '' && $search_statut >= 0) ? '?search_statut='.$search_statut : ''), '', 1, $param);
154 
155  print load_fiche_titre($title, $morehtmlright.' '.$newcardbutton, 'user');
156 
157  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
158  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
159  print '<input type="hidden" name="token" value="'.newToken().'">';
160  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
161  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
162  print '<input type="hidden" name="page" value="'.$page.'">';
163  print '<input type="hidden" name="mode" value="'.$mode.'">';
164  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
165 
166  print '<table class="liste nohover centpercent">';
167 
168  print '<tr class="liste_titre_filter">';
169  print '<td class="liste_titre">&nbsp;</td>';
170  print '<td class="liste_titre">&nbsp;</td>';
171  // Status
172  print '<td class="liste_titre right">';
173  print $form->selectarray('search_statut', array('-1'=>'', '1'=>$langs->trans('Enabled')), $search_statut);
174  print '</td>';
175  print '<td class="liste_titre maxwidthsearch">';
176  $searchpicto = $form->showFilterAndCheckAddButtons(0);
177  print $searchpicto;
178  print '</td>';
179  print '</tr>';
180 
181  print '<tr class="liste_titre">';
182  print_liste_field_titre("HierarchicView");
183  print_liste_field_titre('<div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a> | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div>', $_SERVER['PHP_SELF'], "", '', "", 'align="center"');
184  print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", 'align="right"');
185  print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
186  print '</tr>';
187 
188 
189  $nbofentries = (count($data) - 1);
190 
191  if ($nbofentries > 0)
192  {
193  print '<tr><td colspan="3">';
194  tree_recur($data, $data[0], 0);
195  print '</td>';
196  print '<td></td>';
197  print '</tr>';
198  } else {
199  print '<tr class="oddeven">';
200  print '<td colspan="3">';
201  print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
202  print '<td valign="middle">';
203  print $langs->trans("NoCategoryYet");
204  print '</td>';
205  print '<td>&nbsp;</td>';
206  print '</table>';
207  print '</td>';
208  print '<td></td>';
209  print '</tr>';
210  }
211 
212  print "</table>";
213  print "</form>\n";
214 }
215 
216 //
217 /*print '<script type="text/javascript" language="javascript">
218 jQuery(document).ready(function() {
219  function init_myfunc()
220  {
221  jQuery(".usertddisabled").hide();
222  }
223  init_myfunc();
224 });
225 </script>';
226 */
227 
228 // End of page
229 llxFooter();
230 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59
tree_recur($tab, $pere, $rang, $iddivjstree= 'iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam= '')
Recursive function to output a tree.