dolibarr 25.0.0-alpha
home.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2024 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
5 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31
40$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userhome'; // To manage different context of search
41
42if (!$user->hasRight('user', 'user', 'lire') && !$user->admin) {
43 // Redirect to the user's own page
44 header("Location: card.php?id=".$user->id);
45 exit;
46}
47
48// Load translation files required by page
49$langs->load("users");
50
51$permissiontoreadgroup = true;
52if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
53 $permissiontoreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
54}
55
56// Security check (for external users)
57$socid = 0;
58if ($user->socid > 0) {
59 $socid = $user->socid;
60}
61
62$companystatic = new Societe($db);
63$fuserstatic = new User($db);
64
65// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
66$hookmanager->initHooks(array('userhome'));
67if (!isset($form) || !is_object($form)) {
68 $form = new Form($db);
69}
70// Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
71$resultboxes = FormOther::getBoxesArea($user, "1");
72
73// Add box (when submit is done from a form when ajax disabled)
74include DOL_DOCUMENT_ROOT.'/core/actions_addbox.inc.php';
75
76$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
77
78
79/*
80 * View
81 */
82
83$title = $langs->trans("MenuUsersAndGroups");
84$help_url = '';
85llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-home');
86
87
88print load_fiche_titre($langs->trans("MenuUsersAndGroups"), $resultboxes['selectboxlist'], 'user');
89
90
91// Search User
92$searchbox = '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
93$searchbox .= '<input type="hidden" name="token" value="'.newToken().'">';
94
95$searchbox .= '<table class="noborder nohover centpercent">';
96$searchbox .= '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Search").'</td></tr>';
97$searchbox .= '<tr><td>';
98$searchbox .= $langs->trans("User").':</td><td><input class="flat inputsearch width200" type="text" name="search_user"></td></tr>';
99
100// Search Group
101if ($permissiontoreadgroup) {
102 $searchbox .= '<tr><td>';
103 $searchbox .= $langs->trans("Group").':</td><td><input class="flat inputsearch width200" type="text" name="search_group"></td></tr>';
104}
105
106$searchbox .= '<tr><td class="center" colspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
107$searchbox .= "</table><br>\n";
108
109$searchbox .= '</form>';
110
111
112/*
113 * Latest created users
114 */
115
116$lastcreatedbox = '';
117$sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut";
118$sql .= ", u.entity";
119$sql .= ", u.ldap_sid";
120$sql .= ", u.photo";
121$sql .= ", u.admin";
122$sql .= ", u.email";
123$sql .= ", s.nom as name";
124$sql .= ", s.code_client";
125$sql .= ", s.canvas";
126$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
127$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
128// Add fields from hooks
129$parameters = array();
130$reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook
131if ($reshook > 0) {
132 $sql .= $hookmanager->resPrint;
133} else {
134 $sql .= " WHERE u.entity IN (".getEntity('user').")";
135}
136if (!empty($socid)) {
137 $sql .= " AND u.fk_soc = ".((int) $socid);
138}
139$sql .= $db->order("u.datec", "DESC");
140$sql .= $db->plimit($max);
141
142$resql = $db->query($sql);
143if ($resql) {
144 $num = $db->num_rows($resql);
145
146 $lastcreatedbox .= '<div class="div-table-responsive-no-min">';
147 $lastcreatedbox .= '<table class="noborder centpercent">';
148 $lastcreatedbox .= '<tr class="liste_titre"><td colspan="3" class="valignmiddle">';
149 $lastcreatedbox .= '<span class="valignmiddle">'.$langs->trans("LastUsersCreated", min($num, $max)).'</span>';
150 $lastcreatedbox .= '<a class="valignmiddle marginleftonlyshort" href="'.dolBuildUrl(DOL_URL_ROOT.'/user/list.php', ['sortfield' => 'u.datec', 'sortorder' => 'DESC']).'" title="'.$langs->trans("FullList").'">';
151 $lastcreatedbox .= '<span class="badge marginleftonlyshort valignmiddle">...</span>';
152 $lastcreatedbox .= '</a>';
153 $lastcreatedbox .= '</td>';
154 $lastcreatedbox .= '<td class="right" colspan="2">';
155 //$lastcreatedbox .= '<a class="commonlink" href="'.DOL_URL_ROOT.'/user/list.php?sortfield=u.datec&sortorder=DESC">'.$langs->trans("FullList");
156 $lastcreatedbox .= '</td>';
157 $lastcreatedbox .= '</tr>'."\n";
158 $i = 0;
159
160 while ($i < $num && $i < $max) {
161 $obj = $db->fetch_object($resql);
162
163 $fuserstatic->id = $obj->rowid;
164 $fuserstatic->status = $obj->statut;
165 $fuserstatic->lastname = $obj->lastname;
166 $fuserstatic->firstname = $obj->firstname;
167 $fuserstatic->login = $obj->login;
168 $fuserstatic->photo = $obj->photo;
169 $fuserstatic->admin = $obj->admin;
170 $fuserstatic->email = $obj->email;
171 $fuserstatic->socid = $obj->fk_soc;
172
173 $companystatic->id = $obj->fk_soc;
174 $companystatic->name = $obj->name;
175 $companystatic->code_client = $obj->code_client;
176 $companystatic->canvas = $obj->canvas;
177
178 $lastcreatedbox .= '<tr class="oddeven">';
179 $lastcreatedbox .= '<td class="nowraponall tdoverflowmax150">';
180 $lastcreatedbox .= $fuserstatic->getNomUrl(-1);
181 if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) {
182 $lastcreatedbox .= img_picto($langs->trans("SuperAdministratorDesc"), 'superadmin');
183 } elseif ($obj->admin) {
184 $lastcreatedbox .= img_picto($langs->trans("AdministratorDesc"), 'admin');
185 }
186 $lastcreatedbox .= "</td>";
187 $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.dol_escape_htmltag($obj->login).'</td>';
188 $texttoshow = '';
189 if ($obj->fk_soc) {
190 $texttoshow .= $companystatic->getNomUrl(1);
191 } else {
192 $texttoshow .= '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
193 }
194 if ($obj->ldap_sid) {
195 $texttoshow .= ' <span class="opacitymedium">('.$langs->trans("DomainUser").')</span>';
196 }
197 $entity = $obj->entity;
198 $entitystring = '';
199 // TODO Set of entitystring should be done with a hook
200 if (isModEnabled('multicompany') && isset($mc) && is_object($mc)) {
201 if (empty($entity)) {
202 $entitystring = $langs->trans("AllEntities");
203 } else {
204 $mc->getInfo($entity);
205 $entitystring = $mc->label;
206 }
207 }
208 $texttoshow .= ($entitystring ? ' <span class="opacitymedium">('.$entitystring.')</span>' : '');
209 $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($texttoshow)).'">';
210 $lastcreatedbox .= $texttoshow;
211 $lastcreatedbox .= '</td>';
212 $lastcreatedbox .= '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
213 $lastcreatedbox .= '<td class="right">';
214 $lastcreatedbox .= $fuserstatic->getLibStatut(3);
215 $lastcreatedbox .= '</td>';
216
217 $lastcreatedbox .= '</tr>';
218 $i++;
219 }
220 $lastcreatedbox .= "</table>";
221 $lastcreatedbox .= "</div><br>";
222
223 $db->free($resql);
224} else {
225 dol_print_error($db);
226}
227
228
229/*
230 * Last groups created
231 */
232$lastgroupbox = '';
233if ($permissiontoreadgroup) {
234 $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec";
235 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
236 if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
237 $sql .= " WHERE g.entity IS NOT NULL";
238 } else {
239 $sql .= " WHERE g.entity IN (0, ".((int) $conf->entity).")";
240 }
241 $sql .= $db->order("g.datec", "DESC");
242 $sql .= $db->plimit($max);
243
244 $resql = $db->query($sql);
245 if ($resql) {
246 $colspan = 1;
247 if (isModEnabled('multicompany')) {
248 $colspan++;
249 }
250 $num = $db->num_rows($resql);
251
252 $lastgroupbox .= '<div class="div-table-responsive-no-min">';
253 $lastgroupbox .= '<table class="noborder centpercent">';
254 $lastgroupbox .= '<tr class="liste_titre"><td colspan="'.$colspan.'">';
255 $lastgroupbox .= '<span class="valignmiddle">'.$langs->trans("LastGroupsCreated", ($num ? $num : $max)).'</span>';
256 $lastgroupbox .= '<a class="valignmiddle marginleftonlyshort" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC" title="'.$langs->trans("FullList").'">';
257 $lastgroupbox .= '<span class="badge marginleftonlyshort valignmiddle">...</span>';
258 $lastgroupbox .= '</a>';
259
260 $lastgroupbox .= '</td>';
261 $lastgroupbox .= '<td class="right">';
262 //$lastgroupbox .= '<a class="commonlink" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC">'.$langs->trans("FullList");
263 $lastgroupbox .= '</td>';
264 $lastgroupbox .= '</tr>';
265 $i = 0;
266
267 $grouptemp = new UserGroup($db);
268
269 while ($i < $num && (!$max || $i < $max)) {
270 $obj = $db->fetch_object($resql);
271
272 $grouptemp->id = $obj->rowid;
273 $grouptemp->name = $obj->name;
274 $grouptemp->note = $obj->note;
275
276 $lastgroupbox .= '<tr class="oddeven">';
277 $lastgroupbox .= '<td>';
278 $lastgroupbox .= $grouptemp->getNomUrl(1);
279 if (!$obj->entity) {
280 $lastgroupbox .= img_picto($langs->trans("GlobalGroup"), 'superadmin');
281 }
282 $lastgroupbox .= "</td>";
283 if (isModEnabled('multicompany') && isset($mc) && is_object($mc)) {
284 $mc->getInfo($obj->entity);
285 $lastgroupbox .= '<td>';
286 $lastgroupbox .= $mc->label;
287 $lastgroupbox .= '</td>';
288 }
289 $lastgroupbox .= '<td class="nowrap right">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
290 $lastgroupbox .= "</tr>";
291 $i++;
292 }
293 $lastgroupbox .= "</table>";
294 $lastgroupbox .= "</div><br>";
295
296 $db->free($resql);
297 } else {
298 dol_print_error($db);
299 }
300}
301
302// boxes
303print '<div class="clearboth"></div>';
304print '<div class="fichecenter fichecenterbis">';
305
306$boxlist = '<div class="twocolumns">';
307
308$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
309$boxlist .= $searchbox;
310$boxlist .= $resultboxes['boxlista'];
311$boxlist .= '</div>'."\n";
312
313$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
314$boxlist .= $lastcreatedbox;
315$boxlist .= $lastgroupbox;
316$boxlist .= $resultboxes['boxlistb'];
317$boxlist .= '</div>'."\n";
318
319$boxlist .= '</div>';
320
321print $boxlist;
322
323print '</div>';
324
325// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
326$parameters = array('user' => $user);
327$reshook = $hookmanager->executeHooks('dashboardUsersGroups', $parameters, $object); // Note that $action and $object may have been modified by hook
328
329// End of page
330llxFooter();
331$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of us...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage user groups.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181