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