hierarchy.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. /**
  23. * \file htdocs/user/hierarchy.php
  24. * \ingroup user
  25. * \brief Page of hierarchy view of user module
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  30. // Load translation files required by page
  31. $langs->loadLangs(array('users', 'companies', 'hrm', 'salaries'));
  32. // Security check (for external users)
  33. $socid = 0;
  34. if ($user->socid > 0) {
  35. $socid = $user->socid;
  36. }
  37. $optioncss = GETPOST('optioncss', 'alpha');
  38. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userlist'; // To manage different context of search
  39. $mode = GETPOST("mode", 'alpha');
  40. if (empty($mode)) {
  41. $mode = 'hierarchy';
  42. }
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. $search_statut = GETPOST('search_statut', 'int');
  47. if ($search_statut == '' || $search_statut == '0') {
  48. $search_statut = '1';
  49. }
  50. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  51. $search_statut = "";
  52. }
  53. if ($contextpage == 'employeelist') {
  54. $search_employee = 1;
  55. }
  56. $userstatic = new User($db);
  57. // Define value to know what current user can do on users
  58. $canadduser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
  59. // Permission to list
  60. if (isModEnabled('salaries') && $contextpage == 'employeelist' && $search_employee == 1) {
  61. if (!$user->hasRight("salaries", "read")) {
  62. accessforbidden();
  63. }
  64. } else {
  65. if (!$user->hasRight("user", "user", "read") && empty($user->admin)) {
  66. accessforbidden();
  67. }
  68. }
  69. $childids = $user->getAllChildIds(1);
  70. /*
  71. * View
  72. */
  73. $form = new Form($db);
  74. $help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios|DE:Modul_Benutzer';
  75. if ($contextpage == 'employeelist' && $search_employee == 1) {
  76. $title = $langs->trans("Employees");
  77. } else {
  78. $title = $langs->trans("Users");
  79. }
  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. llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist');
  86. // Load hierarchy of users
  87. $user_arbo = $userstatic->get_full_tree(0, ($search_statut != '' && $search_statut >= 0) ? "statut = ".$search_statut : '');
  88. // Count total nb of records
  89. $nbtotalofrecords = count($user_arbo);
  90. if (!is_array($user_arbo) && $user_arbo < 0) {
  91. setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
  92. } else {
  93. // Define fulltree array
  94. $fulltree = $user_arbo;
  95. //var_dump($fulltree);
  96. // Define data (format for treeview)
  97. $data = array();
  98. $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
  99. foreach ($fulltree as $key => $val) {
  100. $userstatic->id = $val['id'];
  101. $userstatic->ref = $val['id'];
  102. $userstatic->login = $val['login'];
  103. $userstatic->firstname = $val['firstname'];
  104. $userstatic->lastname = $val['lastname'];
  105. $userstatic->statut = $val['statut'];
  106. $userstatic->email = $val['email'];
  107. $userstatic->gender = $val['gender'];
  108. $userstatic->socid = $val['fk_soc'];
  109. $userstatic->admin = $val['admin'];
  110. $userstatic->entity = $val['entity'];
  111. $userstatic->photo = $val['photo'];
  112. $entity = $val['entity'];
  113. $entitystring = '';
  114. // TODO Set of entitystring should be done with a hook
  115. if (isModEnabled('multicompany') && is_object($mc)) {
  116. if (empty($entity)) {
  117. $entitystring = $langs->trans("AllEntities");
  118. } else {
  119. $mc->getInfo($entity);
  120. $entitystring = $mc->label;
  121. }
  122. }
  123. $li = $userstatic->getNomUrl(-1, '', 0, 1);
  124. if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
  125. $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar', 'class="valignmiddle paddingright paddingleft"');
  126. } elseif ($userstatic->admin) {
  127. $li .= img_picto($langs->trans("Administrator"), 'star', 'class="valignmiddle paddingright paddingleft"');
  128. }
  129. $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
  130. $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>';
  131. $data[] = array(
  132. 'rowid'=>$val['rowid'],
  133. 'fk_menu'=>$val['fk_user'],
  134. 'statut'=>$val['statut'],
  135. 'entry'=>$entry
  136. );
  137. }
  138. //var_dump($data);
  139. $param = "&search_statut=".urlencode($search_statut);
  140. $param = "&contextpage=".urlencode($contextpage);
  141. $newcardbutton = '';
  142. $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'));
  143. $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'));
  144. $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'));
  145. $newcardbutton .= dolGetButtonTitleSeparator();
  146. $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', $canadduser);
  147. $massactionbutton = '';
  148. $num = 0;
  149. $limit = 0;
  150. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $newcardbutton, '', $limit, 0, 0, 1);
  151. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  152. if ($optioncss != '') {
  153. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  154. }
  155. print '<input type="hidden" name="token" value="'.newToken().'">';
  156. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  157. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  158. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  159. print '<input type="hidden" name="page" value="'.$page.'">';
  160. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  161. print '<input type="hidden" name="mode" value="'.$mode.'">';
  162. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  163. print '<table class="liste nohover centpercent">';
  164. print '<tr class="liste_titre_filter">';
  165. print '<td class="liste_titre">&nbsp;</td>';
  166. print '<td class="liste_titre">&nbsp;</td>';
  167. // Status
  168. print '<td class="liste_titre right">';
  169. print $form->selectarray('search_statut', array('-1'=>'', '1'=>$langs->trans('Enabled')), $search_statut, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp');
  170. print '</td>';
  171. print '<td class="liste_titre maxwidthsearch">';
  172. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  173. print $searchpicto;
  174. print '</td>';
  175. print '</tr>';
  176. print '<tr class="liste_titre">';
  177. print_liste_field_titre("HierarchicView");
  178. 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"');
  179. print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", 'align="right"');
  180. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
  181. print '</tr>';
  182. $nbofentries = (count($data) - 1);
  183. if ($nbofentries > 0) {
  184. print '<tr><td colspan="3">';
  185. tree_recur($data, $data[0], 0);
  186. print '</td>';
  187. print '<td></td>';
  188. print '</tr>';
  189. } else {
  190. print '<tr class="oddeven">';
  191. print '<td colspan="3">';
  192. print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
  193. print '<td valign="middle">';
  194. print $langs->trans("NoCategoryYet");
  195. print '</td>';
  196. print '<td>&nbsp;</td>';
  197. print '</table>';
  198. print '</td>';
  199. print '<td></td>';
  200. print '</tr>';
  201. }
  202. print "</table>";
  203. print '</div>';
  204. print "</form>\n";
  205. }
  206. //
  207. /*print '<script type="text/javascript">
  208. jQuery(document).ready(function() {
  209. function init_myfunc()
  210. {
  211. jQuery(".usertddisabled").hide();
  212. }
  213. init_myfunc();
  214. });
  215. </script>';
  216. */
  217. // End of page
  218. llxFooter();
  219. $db->close();