home.php 10 KB

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