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
73if (GETPOST('addbox')) {
74 // Add box (when submit is done from a form when ajax disabled)
75 require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
76 $zone = GETPOSTINT('areacode');
77 $userid = GETPOSTINT('userid');
78 $boxorder = GETPOST('boxorder', 'aZ09');
79 $boxorder .= GETPOST('boxcombo', 'aZ09');
80 $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
81 if ($result > 0) {
82 setEventMessages($langs->trans("BoxAdded"), null);
83 }
84}
85
86$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
87
88
89/*
90 * View
91 */
92
93$title = $langs->trans("MenuUsersAndGroups");
94$help_url = '';
95llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-home');
96
97
98print load_fiche_titre($langs->trans("MenuUsersAndGroups"), $resultboxes['selectboxlist'], 'user');
99
100
101// Search User
102$searchbox = '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
103$searchbox .= '<input type="hidden" name="token" value="'.newToken().'">';
104
105$searchbox .= '<table class="noborder nohover centpercent">';
106$searchbox .= '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Search").'</td></tr>';
107$searchbox .= '<tr><td>';
108$searchbox .= $langs->trans("User").':</td><td><input class="flat inputsearch width200" type="text" name="search_user"></td></tr>';
109
110// Search Group
111if ($permissiontoreadgroup) {
112 $searchbox .= '<tr><td>';
113 $searchbox .= $langs->trans("Group").':</td><td><input class="flat inputsearch width200" type="text" name="search_group"></td></tr>';
114}
115
116$searchbox .= '<tr><td class="center" colspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
117$searchbox .= "</table><br>\n";
118
119$searchbox .= '</form>';
120
121
122/*
123 * Latest created users
124 */
125
126$lastcreatedbox = '';
127$sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut";
128$sql .= ", u.entity";
129$sql .= ", u.ldap_sid";
130$sql .= ", u.photo";
131$sql .= ", u.admin";
132$sql .= ", u.email";
133$sql .= ", s.nom as name";
134$sql .= ", s.code_client";
135$sql .= ", s.canvas";
136$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
137$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
138// Add fields from hooks
139$parameters = array();
140$reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook
141if ($reshook > 0) {
142 $sql .= $hookmanager->resPrint;
143} else {
144 $sql .= " WHERE u.entity IN (".getEntity('user').")";
145}
146if (!empty($socid)) {
147 $sql .= " AND u.fk_soc = ".((int) $socid);
148}
149$sql .= $db->order("u.datec", "DESC");
150$sql .= $db->plimit($max);
151
152$resql = $db->query($sql);
153if ($resql) {
154 $num = $db->num_rows($resql);
155
156 $lastcreatedbox .= '<div class="div-table-responsive-no-min">';
157 $lastcreatedbox .= '<table class="noborder centpercent">';
158 $lastcreatedbox .= '<tr class="liste_titre"><td colspan="3" class="valignmiddle">';
159 $lastcreatedbox .= '<span class="valignmiddle">'.$langs->trans("LastUsersCreated", min($num, $max)).'</span>';
160 $lastcreatedbox .= '<a class="valignmiddle marginleftonlyshort" href="'.dolBuildUrl(DOL_URL_ROOT.'/user/list.php', ['sortfield' => 'u.datec', 'sortorder' => 'DESC']).'" title="'.$langs->trans("FullList").'">';
161 $lastcreatedbox .= '<span class="badge marginleftonlyshort valignmiddle">...</span>';
162 $lastcreatedbox .= '</a>';
163 $lastcreatedbox .= '</td>';
164 $lastcreatedbox .= '<td class="right" colspan="2">';
165 //$lastcreatedbox .= '<a class="commonlink" href="'.DOL_URL_ROOT.'/user/list.php?sortfield=u.datec&sortorder=DESC">'.$langs->trans("FullList");
166 $lastcreatedbox .= '</td>';
167 $lastcreatedbox .= '</tr>'."\n";
168 $i = 0;
169
170 while ($i < $num && $i < $max) {
171 $obj = $db->fetch_object($resql);
172
173 $fuserstatic->id = $obj->rowid;
174 $fuserstatic->statut = $obj->statut;
175 $fuserstatic->status = $obj->statut;
176 $fuserstatic->lastname = $obj->lastname;
177 $fuserstatic->firstname = $obj->firstname;
178 $fuserstatic->login = $obj->login;
179 $fuserstatic->photo = $obj->photo;
180 $fuserstatic->admin = $obj->admin;
181 $fuserstatic->email = $obj->email;
182 $fuserstatic->socid = $obj->fk_soc;
183
184 $companystatic->id = $obj->fk_soc;
185 $companystatic->name = $obj->name;
186 $companystatic->code_client = $obj->code_client;
187 $companystatic->canvas = $obj->canvas;
188
189 $lastcreatedbox .= '<tr class="oddeven">';
190 $lastcreatedbox .= '<td class="nowraponall tdoverflowmax150">';
191 $lastcreatedbox .= $fuserstatic->getNomUrl(-1);
192 if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) {
193 $lastcreatedbox .= img_picto($langs->trans("SuperAdministratorDesc"), 'superadmin');
194 } elseif ($obj->admin) {
195 $lastcreatedbox .= img_picto($langs->trans("AdministratorDesc"), 'admin');
196 }
197 $lastcreatedbox .= "</td>";
198 $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.dol_escape_htmltag($obj->login).'</td>';
199 $texttoshow = '';
200 if ($obj->fk_soc) {
201 $texttoshow .= $companystatic->getNomUrl(1);
202 } else {
203 $texttoshow .= '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
204 }
205 if ($obj->ldap_sid) {
206 $texttoshow .= ' <span class="opacitymedium">('.$langs->trans("DomainUser").')</span>';
207 }
208 $entity = $obj->entity;
209 $entitystring = '';
210 // TODO Set of entitystring should be done with a hook
211 if (isModEnabled('multicompany') && isset($mc) && is_object($mc)) {
212 if (empty($entity)) {
213 $entitystring = $langs->trans("AllEntities");
214 } else {
215 $mc->getInfo($entity);
216 $entitystring = $mc->label;
217 }
218 }
219 $texttoshow .= ($entitystring ? ' <span class="opacitymedium">('.$entitystring.')</span>' : '');
220 $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($texttoshow)).'">';
221 $lastcreatedbox .= $texttoshow;
222 $lastcreatedbox .= '</td>';
223 $lastcreatedbox .= '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
224 $lastcreatedbox .= '<td class="right">';
225 $lastcreatedbox .= $fuserstatic->getLibStatut(3);
226 $lastcreatedbox .= '</td>';
227
228 $lastcreatedbox .= '</tr>';
229 $i++;
230 }
231 $lastcreatedbox .= "</table>";
232 $lastcreatedbox .= "</div><br>";
233
234 $db->free($resql);
235} else {
237}
238
239
240/*
241 * Last groups created
242 */
243$lastgroupbox = '';
244if ($permissiontoreadgroup) {
245 $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec";
246 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
247 if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
248 $sql .= " WHERE g.entity IS NOT NULL";
249 } else {
250 $sql .= " WHERE g.entity IN (0, ".((int) $conf->entity).")";
251 }
252 $sql .= $db->order("g.datec", "DESC");
253 $sql .= $db->plimit($max);
254
255 $resql = $db->query($sql);
256 if ($resql) {
257 $colspan = 1;
258 if (isModEnabled('multicompany')) {
259 $colspan++;
260 }
261 $num = $db->num_rows($resql);
262
263 $lastgroupbox .= '<div class="div-table-responsive-no-min">';
264 $lastgroupbox .= '<table class="noborder centpercent">';
265 $lastgroupbox .= '<tr class="liste_titre"><td colspan="'.$colspan.'">';
266 $lastgroupbox .= '<span class="valignmiddle">'.$langs->trans("LastGroupsCreated", ($num ? $num : $max)).'</span>';
267 $lastgroupbox .= '<a class="valignmiddle marginleftonlyshort" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC" title="'.$langs->trans("FullList").'">';
268 $lastgroupbox .= '<span class="badge marginleftonlyshort valignmiddle">...</span>';
269 $lastgroupbox .= '</a>';
270
271 $lastgroupbox .= '</td>';
272 $lastgroupbox .= '<td class="right">';
273 //$lastgroupbox .= '<a class="commonlink" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC">'.$langs->trans("FullList");
274 $lastgroupbox .= '</td>';
275 $lastgroupbox .= '</tr>';
276 $i = 0;
277
278 $grouptemp = new UserGroup($db);
279
280 while ($i < $num && (!$max || $i < $max)) {
281 $obj = $db->fetch_object($resql);
282
283 $grouptemp->id = $obj->rowid;
284 $grouptemp->name = $obj->name;
285 $grouptemp->note = $obj->note;
286
287 $lastgroupbox .= '<tr class="oddeven">';
288 $lastgroupbox .= '<td>';
289 $lastgroupbox .= $grouptemp->getNomUrl(1);
290 if (!$obj->entity) {
291 $lastgroupbox .= img_picto($langs->trans("GlobalGroup"), 'superadmin');
292 }
293 $lastgroupbox .= "</td>";
294 if (isModEnabled('multicompany') && isset($mc) && is_object($mc)) {
295 $mc->getInfo($obj->entity);
296 $lastgroupbox .= '<td>';
297 $lastgroupbox .= $mc->label;
298 $lastgroupbox .= '</td>';
299 }
300 $lastgroupbox .= '<td class="nowrap right">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
301 $lastgroupbox .= "</tr>";
302 $i++;
303 }
304 $lastgroupbox .= "</table>";
305 $lastgroupbox .= "</div><br>";
306
307 $db->free($resql);
308 } else {
310 }
311}
312
313// boxes
314print '<div class="clearboth"></div>';
315print '<div class="fichecenter fichecenterbis">';
316
317$boxlist = '<div class="twocolumns">';
318
319$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
320$boxlist .= $searchbox;
321$boxlist .= $resultboxes['boxlista'];
322$boxlist .= '</div>'."\n";
323
324$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
325$boxlist .= $lastcreatedbox;
326$boxlist .= $lastgroupbox;
327$boxlist .= $resultboxes['boxlistb'];
328$boxlist .= '</div>'."\n";
329
330$boxlist .= '</div>';
331
332print $boxlist;
333
334print '</div>';
335
336// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
337$parameters = array('user' => $user);
338$reshook = $hookmanager->executeHooks('dashboardUsersGroups', $parameters, $object); // Note that $action and $object may have been modified by hook
339
340// End of page
341llxFooter();
342$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...
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...