hierarchy.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  29. if (!$user->rights->user->user->lire && !$user->admin) {
  30. accessforbidden();
  31. }
  32. // Load translation files required by page
  33. $langs->loadLangs(array('users', 'companies'));
  34. // Security check (for external users)
  35. $socid = 0;
  36. if ($user->socid > 0) {
  37. $socid = $user->socid;
  38. }
  39. $optioncss = GETPOST('optioncss', 'alpha');
  40. $contextpage = GETPOST('optioncss', 'aZ09');
  41. $sortfield = GETPOST('sortfield', 'aZ09comma');
  42. $sortorder = GETPOST('sortorder', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. // Load mode employee
  45. $mode = GETPOST("mode", 'alpha');
  46. $userstatic = new User($db);
  47. $search_statut = GETPOST('search_statut', 'int');
  48. if ($search_statut == '') {
  49. $search_statut = '1';
  50. }
  51. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  52. $search_statut = "";
  53. }
  54. // Define value to know what current user can do on users
  55. $canadduser = (!empty($user->admin) || $user->rights->user->user->creer);
  56. /*
  57. * View
  58. */
  59. $form = new Form($db);
  60. $arrayofjs = array(
  61. '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
  62. '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
  63. );
  64. $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
  65. llxHeader('', $langs->trans("ListOfUsers").' - '.$langs->trans("HierarchicView"), '', '', 0, 0, $arrayofjs, $arrayofcss);
  66. // Load hierarchy of users
  67. $user_arbo = $userstatic->get_full_tree(0, ($search_statut != '' && $search_statut >= 0) ? "statut = ".$search_statut : '');
  68. if (!is_array($user_arbo) && $user_arbo < 0) {
  69. setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
  70. } else {
  71. // Define fulltree array
  72. $fulltree = $user_arbo;
  73. //var_dump($fulltree);
  74. // Define data (format for treeview)
  75. $data = array();
  76. $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
  77. foreach ($fulltree as $key => $val) {
  78. $userstatic->id = $val['id'];
  79. $userstatic->ref = $val['id'];
  80. $userstatic->login = $val['login'];
  81. $userstatic->firstname = $val['firstname'];
  82. $userstatic->lastname = $val['lastname'];
  83. $userstatic->statut = $val['statut'];
  84. $userstatic->email = $val['email'];
  85. $userstatic->gender = $val['gender'];
  86. $userstatic->socid = $val['fk_soc'];
  87. $userstatic->admin = $val['admin'];
  88. $userstatic->entity = $val['entity'];
  89. $userstatic->photo = $val['photo'];
  90. $entity = $val['entity'];
  91. $entitystring = '';
  92. // TODO Set of entitystring should be done with a hook
  93. if (!empty($conf->multicompany->enabled) && is_object($mc)) {
  94. if (empty($entity)) {
  95. $entitystring = $langs->trans("AllEntities");
  96. } else {
  97. $mc->getInfo($entity);
  98. $entitystring = $mc->label;
  99. }
  100. }
  101. $li = $userstatic->getNomUrl(-1, '', 0, 1);
  102. if (!empty($conf->multicompany->enabled) && $userstatic->admin && !$userstatic->entity) {
  103. $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
  104. } elseif ($userstatic->admin) {
  105. $li .= img_picto($langs->trans("Administrator"), 'star');
  106. }
  107. $li .= ' ('.$val['login'].($entitystring ? ' - '.$entitystring : '').')';
  108. $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>';
  109. $data[] = array(
  110. 'rowid'=>$val['rowid'],
  111. 'fk_menu'=>$val['fk_user'],
  112. 'statut'=>$val['statut'],
  113. 'entry'=>$entry
  114. );
  115. }
  116. //var_dump($data);
  117. $title = $langs->trans("ListOfUsers").' - '.$langs->trans("HierarchicView");
  118. $param = "search_statut=".urlencode($search_statut);
  119. $newcardbutton = '';
  120. $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', $canadduser);
  121. $morehtmlright = '';
  122. $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 : ''));
  123. $param = array('morecss'=>'marginleftonly btnTitleSelected');
  124. $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);
  125. print load_fiche_titre($title, $morehtmlright.' '.$newcardbutton, 'user');
  126. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  127. if ($optioncss != '') {
  128. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  129. }
  130. print '<input type="hidden" name="token" value="'.newToken().'">';
  131. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  132. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  133. print '<input type="hidden" name="page" value="'.$page.'">';
  134. print '<input type="hidden" name="mode" value="'.$mode.'">';
  135. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  136. print '<table class="liste nohover centpercent">';
  137. print '<tr class="liste_titre_filter">';
  138. print '<td class="liste_titre">&nbsp;</td>';
  139. print '<td class="liste_titre">&nbsp;</td>';
  140. // Status
  141. print '<td class="liste_titre right">';
  142. print $form->selectarray('search_statut', array('-1'=>'', '1'=>$langs->trans('Enabled')), $search_statut);
  143. print '</td>';
  144. print '<td class="liste_titre maxwidthsearch">';
  145. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  146. print $searchpicto;
  147. print '</td>';
  148. print '</tr>';
  149. print '<tr class="liste_titre">';
  150. print_liste_field_titre("HierarchicView");
  151. 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"');
  152. print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", 'align="right"');
  153. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
  154. print '</tr>';
  155. $nbofentries = (count($data) - 1);
  156. if ($nbofentries > 0) {
  157. print '<tr><td colspan="3">';
  158. tree_recur($data, $data[0], 0);
  159. print '</td>';
  160. print '<td></td>';
  161. print '</tr>';
  162. } else {
  163. print '<tr class="oddeven">';
  164. print '<td colspan="3">';
  165. print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
  166. print '<td valign="middle">';
  167. print $langs->trans("NoCategoryYet");
  168. print '</td>';
  169. print '<td>&nbsp;</td>';
  170. print '</table>';
  171. print '</td>';
  172. print '<td></td>';
  173. print '</tr>';
  174. }
  175. print "</table>";
  176. print "</form>\n";
  177. }
  178. //
  179. /*print '<script type="text/javascript" language="javascript">
  180. jQuery(document).ready(function() {
  181. function init_myfunc()
  182. {
  183. jQuery(".usertddisabled").hide();
  184. }
  185. init_myfunc();
  186. });
  187. </script>';
  188. */
  189. // End of page
  190. llxFooter();
  191. $db->close();