hierarchy.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 == '' || $search_statut == '0') {
  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. $title = $langs->trans("Users").' - '.$langs->trans("HierarchicView");
  61. $arrayofjs = array(
  62. '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
  63. '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js',
  64. );
  65. $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
  66. llxHeader('', $title, '', '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist');
  67. // Load hierarchy of users
  68. $user_arbo = $userstatic->get_full_tree(0, ($search_statut != '' && $search_statut >= 0) ? "statut = ".$search_statut : '');
  69. if (!is_array($user_arbo) && $user_arbo < 0) {
  70. setEventMessages($userstatic->error, $userstatic->errors, 'warnings');
  71. } else {
  72. // Define fulltree array
  73. $fulltree = $user_arbo;
  74. //var_dump($fulltree);
  75. // Define data (format for treeview)
  76. $data = array();
  77. $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
  78. foreach ($fulltree as $key => $val) {
  79. $userstatic->id = $val['id'];
  80. $userstatic->ref = $val['id'];
  81. $userstatic->login = $val['login'];
  82. $userstatic->firstname = $val['firstname'];
  83. $userstatic->lastname = $val['lastname'];
  84. $userstatic->statut = $val['statut'];
  85. $userstatic->email = $val['email'];
  86. $userstatic->gender = $val['gender'];
  87. $userstatic->socid = $val['fk_soc'];
  88. $userstatic->admin = $val['admin'];
  89. $userstatic->entity = $val['entity'];
  90. $userstatic->photo = $val['photo'];
  91. $entity = $val['entity'];
  92. $entitystring = '';
  93. // TODO Set of entitystring should be done with a hook
  94. if (!empty($conf->multicompany->enabled) && is_object($mc)) {
  95. if (empty($entity)) {
  96. $entitystring = $langs->trans("AllEntities");
  97. } else {
  98. $mc->getInfo($entity);
  99. $entitystring = $mc->label;
  100. }
  101. }
  102. $li = $userstatic->getNomUrl(-1, '', 0, 1);
  103. if (!empty($conf->multicompany->enabled) && $userstatic->admin && !$userstatic->entity) {
  104. $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
  105. } elseif ($userstatic->admin) {
  106. $li .= img_picto($langs->trans("Administrator"), 'star');
  107. }
  108. $li .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
  109. $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>';
  110. $data[] = array(
  111. 'rowid'=>$val['rowid'],
  112. 'fk_menu'=>$val['fk_user'],
  113. 'statut'=>$val['statut'],
  114. 'entry'=>$entry
  115. );
  116. }
  117. //var_dump($data);
  118. $param = "search_statut=".urlencode($search_statut);
  119. $newcardbutton = '';
  120. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/user/list.php?mode=kanban'.(($search_statut != '' && $search_statut >= 0) ? '&search_statut='.$search_statut : '').preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  121. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php?mode=common'.(($search_statut != '' && $search_statut >= 0) ? '&search_statut='.$search_statut : '').preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  122. $newcardbutton .= dolGetButtonTitle($langs->trans('HierarchicView'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php?mode=hierarchy'.(($search_statut != '' && $search_statut >= 0) ? '&search_statut='.$search_statut : '').preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', (($mode == 'hierarchy') ? 2 : 1), array('morecss'=>'reposition'));
  123. $newcardbutton .= dolGetButtonTitleSeparator();
  124. $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/card.php?action=create'.($mode == 'employee' ? '&employee=1' : '').'&leftmenu=', '', $canadduser);
  125. $massactionbutton = '';
  126. $num = 0;
  127. $limit = 0;
  128. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, '', 'user', 0, $newcardbutton, '', $limit, 0, 0, 1);
  129. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  130. if ($optioncss != '') {
  131. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  132. }
  133. print '<input type="hidden" name="token" value="'.newToken().'">';
  134. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  135. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  136. print '<input type="hidden" name="page" value="'.$page.'">';
  137. print '<input type="hidden" name="mode" value="'.$mode.'">';
  138. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  139. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  140. print '<table class="liste nohover centpercent">';
  141. print '<tr class="liste_titre_filter">';
  142. print '<td class="liste_titre">&nbsp;</td>';
  143. print '<td class="liste_titre">&nbsp;</td>';
  144. // Status
  145. print '<td class="liste_titre right">';
  146. print $form->selectarray('search_statut', array('-1'=>'', '1'=>$langs->trans('Enabled')), $search_statut, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp');
  147. print '</td>';
  148. print '<td class="liste_titre maxwidthsearch">';
  149. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  150. print $searchpicto;
  151. print '</td>';
  152. print '</tr>';
  153. print '<tr class="liste_titre">';
  154. print_liste_field_titre("HierarchicView");
  155. 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"');
  156. print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", 'align="right"');
  157. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
  158. print '</tr>';
  159. $nbofentries = (count($data) - 1);
  160. if ($nbofentries > 0) {
  161. print '<tr><td colspan="3">';
  162. tree_recur($data, $data[0], 0);
  163. print '</td>';
  164. print '<td></td>';
  165. print '</tr>';
  166. } else {
  167. print '<tr class="oddeven">';
  168. print '<td colspan="3">';
  169. print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
  170. print '<td valign="middle">';
  171. print $langs->trans("NoCategoryYet");
  172. print '</td>';
  173. print '<td>&nbsp;</td>';
  174. print '</table>';
  175. print '</td>';
  176. print '<td></td>';
  177. print '</tr>';
  178. }
  179. print "</table>";
  180. print '</div>';
  181. print "</form>\n";
  182. }
  183. //
  184. /*print '<script type="text/javascript">
  185. jQuery(document).ready(function() {
  186. function init_myfunc()
  187. {
  188. jQuery(".usertddisabled").hide();
  189. }
  190. init_myfunc();
  191. });
  192. </script>';
  193. */
  194. // End of page
  195. llxFooter();
  196. $db->close();