home.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. /* Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/user/home.php
  21. * \brief Home page of users and groups management
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  27. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userhome'; // To manage different context of search
  28. if (!$user->hasRight('user', 'user', 'lire') && !$user->admin) {
  29. // Redirection vers la page de l'utilisateur
  30. header("Location: card.php?id=".$user->id);
  31. exit;
  32. }
  33. // Load translation files required by page
  34. $langs->load("users");
  35. $canreadperms = true;
  36. if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  37. $canreadperms = ($user->admin || $user->rights->user->group_advance->read);
  38. }
  39. // Security check (for external users)
  40. $socid = 0;
  41. if ($user->socid > 0) {
  42. $socid = $user->socid;
  43. }
  44. $companystatic = new Societe($db);
  45. $fuserstatic = new User($db);
  46. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  47. $hookmanager->initHooks(array('userhome'));
  48. if (!isset($form) || !is_object($form)) {
  49. $form = new Form($db);
  50. }
  51. // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
  52. $resultboxes = FormOther::getBoxesArea($user, "1");
  53. if (GETPOST('addbox')) {
  54. // Add box (when submit is done from a form when ajax disabled)
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  56. $zone = GETPOST('areacode', 'int');
  57. $userid = GETPOST('userid', 'int');
  58. $boxorder = GETPOST('boxorder', 'aZ09');
  59. $boxorder .= GETPOST('boxcombo', 'aZ09');
  60. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  61. if ($result > 0) {
  62. setEventMessages($langs->trans("BoxAdded"), null);
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. $title = $langs->trans("MenuUsersAndGroups");
  69. $help_url = '';
  70. llxHeader('', $title, $help_url);
  71. print load_fiche_titre($langs->trans("MenuUsersAndGroups"), $resultboxes['selectboxlist'], 'user');
  72. // Search User
  73. $searchbox = '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  74. $searchbox .= '<input type="hidden" name="token" value="'.newToken().'">';
  75. $searchbox .= '<table class="noborder nohover centpercent">';
  76. $searchbox .= '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Search").'</td></tr>';
  77. $searchbox .= '<tr><td>';
  78. $searchbox .= $langs->trans("User").':</td><td><input class="flat inputsearch width200" type="text" name="search_user"></td></tr>';
  79. // Search Group
  80. if ($canreadperms) {
  81. $searchbox .= '<tr><td>';
  82. $searchbox .= $langs->trans("Group").':</td><td><input class="flat inputsearch width200" type="text" name="search_group"></td></tr>';
  83. }
  84. $searchbox .= '<tr><td class="center" colspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  85. $searchbox .= "</table><br>\n";
  86. $searchbox .= '</form>';
  87. /*
  88. * Latest created users
  89. */
  90. $max = 10;
  91. $lastcreatedbox = '';
  92. $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut";
  93. $sql .= ", u.entity";
  94. $sql .= ", u.ldap_sid";
  95. $sql .= ", u.photo";
  96. $sql .= ", u.admin";
  97. $sql .= ", u.email";
  98. $sql .= ", s.nom as name";
  99. $sql .= ", s.code_client";
  100. $sql .= ", s.canvas";
  101. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  102. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
  103. // Add fields from hooks
  104. $parameters = array();
  105. $reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook
  106. if ($reshook > 0) {
  107. $sql .= $hookmanager->resPrint;
  108. } else {
  109. $sql .= " WHERE u.entity IN (".getEntity('user').")";
  110. }
  111. if (!empty($socid)) {
  112. $sql .= " AND u.fk_soc = ".((int) $socid);
  113. }
  114. $sql .= $db->order("u.datec", "DESC");
  115. $sql .= $db->plimit($max);
  116. $resql = $db->query($sql);
  117. if ($resql) {
  118. $num = $db->num_rows($resql);
  119. $lastcreatedbox .= '<div class="div-table-responsive-no-min">';
  120. $lastcreatedbox .= '<table class="noborder centpercent">';
  121. $lastcreatedbox .= '<tr class="liste_titre"><td colspan="3">'.$langs->trans("LastUsersCreated", min($num, $max)).'</td>';
  122. $lastcreatedbox .= '<td class="right" colspan="2"><a class="commonlink" href="'.DOL_URL_ROOT.'/user/list.php?sortfield=u.datec&sortorder=DESC">'.$langs->trans("FullList").'</td>';
  123. $lastcreatedbox .= '</tr>'."\n";
  124. $i = 0;
  125. while ($i < $num && $i < $max) {
  126. $obj = $db->fetch_object($resql);
  127. $fuserstatic->id = $obj->rowid;
  128. $fuserstatic->statut = $obj->statut;
  129. $fuserstatic->lastname = $obj->lastname;
  130. $fuserstatic->firstname = $obj->firstname;
  131. $fuserstatic->login = $obj->login;
  132. $fuserstatic->photo = $obj->photo;
  133. $fuserstatic->admin = $obj->admin;
  134. $fuserstatic->email = $obj->email;
  135. $fuserstatic->socid = $obj->fk_soc;
  136. $companystatic->id = $obj->fk_soc;
  137. $companystatic->name = $obj->name;
  138. $companystatic->code_client = $obj->code_client;
  139. $companystatic->canvas = $obj->canvas;
  140. $lastcreatedbox .= '<tr class="oddeven">';
  141. $lastcreatedbox .= '<td class="nowraponall tdoverflowmax150">';
  142. $lastcreatedbox .= $fuserstatic->getNomUrl(-1);
  143. if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) {
  144. $lastcreatedbox .= img_picto($langs->trans("SuperAdministratorDesc"), 'redstar');
  145. } elseif ($obj->admin) {
  146. $lastcreatedbox .= img_picto($langs->trans("AdministratorDesc"), 'star');
  147. }
  148. $lastcreatedbox .= "</td>";
  149. $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.dol_escape_htmltag($obj->login).'</td>';
  150. $texttoshow = '';
  151. if ($obj->fk_soc) {
  152. $texttoshow .= $companystatic->getNomUrl(1);
  153. } else {
  154. $texttoshow .= '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
  155. }
  156. if ($obj->ldap_sid) {
  157. $texttoshow .= ' <span class="opacitymedium">('.$langs->trans("DomainUser").')</span>';
  158. }
  159. $entity = $obj->entity;
  160. $entitystring = '';
  161. // TODO Set of entitystring should be done with a hook
  162. if (isModEnabled('multicompany') && is_object($mc)) {
  163. if (empty($entity)) {
  164. $entitystring = $langs->trans("AllEntities");
  165. } else {
  166. $mc->getInfo($entity);
  167. $entitystring = $mc->label;
  168. }
  169. }
  170. $texttoshow .= ($entitystring ? ' <span class="opacitymedium">('.$entitystring.')</span>' : '');
  171. $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($texttoshow)).'">';
  172. $lastcreatedbox .= $texttoshow;
  173. $lastcreatedbox .= '</td>';
  174. $lastcreatedbox .= '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
  175. $lastcreatedbox .= '<td class="right">';
  176. $lastcreatedbox .= $fuserstatic->getLibStatut(3);
  177. $lastcreatedbox .= '</td>';
  178. $lastcreatedbox .= '</tr>';
  179. $i++;
  180. }
  181. $lastcreatedbox .= "</table>";
  182. $lastcreatedbox .= "</div><br>";
  183. $db->free($resql);
  184. } else {
  185. dol_print_error($db);
  186. }
  187. /*
  188. * Last groups created
  189. */
  190. $lastgroupbox = '';
  191. if ($canreadperms) {
  192. $max = 5;
  193. $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec";
  194. $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
  195. if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
  196. $sql .= " WHERE g.entity IS NOT NULL";
  197. } else {
  198. $sql .= " WHERE g.entity IN (0, ".$conf->entity.")";
  199. }
  200. $sql .= $db->order("g.datec", "DESC");
  201. $sql .= $db->plimit($max);
  202. $resql = $db->query($sql);
  203. if ($resql) {
  204. $colspan = 1;
  205. if (isModEnabled('multicompany')) {
  206. $colspan++;
  207. }
  208. $num = $db->num_rows($resql);
  209. $lastgroupbox .= '<div class="div-table-responsive-no-min">';
  210. $lastgroupbox .= '<table class="noborder centpercent">';
  211. $lastgroupbox .= '<tr class="liste_titre"><td colspan="'.$colspan.'">'.$langs->trans("LastGroupsCreated", ($num ? $num : $max)).'</td>';
  212. $lastgroupbox .= '<td class="right"><a class="commonlink" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC">'.$langs->trans("FullList").'</td>';
  213. $lastgroupbox .= '</tr>';
  214. $i = 0;
  215. $grouptemp = new UserGroup($db);
  216. while ($i < $num && (!$max || $i < $max)) {
  217. $obj = $db->fetch_object($resql);
  218. $grouptemp->id = $obj->rowid;
  219. $grouptemp->name = $obj->name;
  220. $grouptemp->note = $obj->note;
  221. $lastgroupbox .= '<tr class="oddeven">';
  222. $lastgroupbox .= '<td>';
  223. $lastgroupbox .= $grouptemp->getNomUrl(1);
  224. if (!$obj->entity) {
  225. $lastgroupbox .= img_picto($langs->trans("GlobalGroup"), 'redstar');
  226. }
  227. $lastgroupbox .= "</td>";
  228. if (isModEnabled('multicompany') && is_object($mc)) {
  229. $mc->getInfo($obj->entity);
  230. $lastgroupbox .= '<td>';
  231. $lastgroupbox .= $mc->label;
  232. $lastgroupbox .= '</td>';
  233. }
  234. $lastgroupbox .= '<td class="nowrap right">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
  235. $lastgroupbox .= "</tr>";
  236. $i++;
  237. }
  238. $lastgroupbox .= "</table>";
  239. $lastgroupbox .= "</div><br>";
  240. $db->free($resql);
  241. } else {
  242. dol_print_error($db);
  243. }
  244. }
  245. // boxes
  246. print '<div class="clearboth"></div>';
  247. print '<div class="fichecenter fichecenterbis">';
  248. $boxlist = '<div class="twocolumns">';
  249. $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  250. $boxlist .= $searchbox;
  251. $boxlist .= $resultboxes['boxlista'];
  252. $boxlist .= '</div>'."\n";
  253. $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  254. $boxlist .= $lastcreatedbox;
  255. $boxlist .= $lastgroupbox;
  256. $boxlist .= $resultboxes['boxlistb'];
  257. $boxlist .= '</div>'."\n";
  258. $boxlist .= '</div>';
  259. print $boxlist;
  260. print '</div>';
  261. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  262. $parameters = array('user' => $user);
  263. $reshook = $hookmanager->executeHooks('dashboardUsersGroups', $parameters, $object); // Note that $action and $object may have been modified by hook
  264. // End of page
  265. llxFooter();
  266. $db->close();