dolibarr 21.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 *
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
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
29
30$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userhome'; // To manage different context of search
31
32if (!$user->hasRight('user', 'user', 'lire') && !$user->admin) {
33 // Redirection vers la page de l'utilisateur
34 header("Location: card.php?id=".$user->id);
35 exit;
36}
37
38// Load translation files required by page
39$langs->load("users");
40
41$permissiontoreadgroup = true;
42if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
43 $permissiontoreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
44}
45
46// Security check (for external users)
47$socid = 0;
48if ($user->socid > 0) {
49 $socid = $user->socid;
50}
51
52$companystatic = new Societe($db);
53$fuserstatic = new User($db);
54
55// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
56$hookmanager->initHooks(array('userhome'));
57if (!isset($form) || !is_object($form)) {
58 $form = new Form($db);
59}
60// Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
61$resultboxes = FormOther::getBoxesArea($user, "1");
62
63if (GETPOST('addbox')) {
64 // Add box (when submit is done from a form when ajax disabled)
65 require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
66 $zone = GETPOSTINT('areacode');
67 $userid = GETPOSTINT('userid');
68 $boxorder = GETPOST('boxorder', 'aZ09');
69 $boxorder .= GETPOST('boxcombo', 'aZ09');
70 $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
71 if ($result > 0) {
72 setEventMessages($langs->trans("BoxAdded"), null);
73 }
74}
75
76$max = 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="'.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->statut = $obj->statut;
165 $fuserstatic->status = $obj->statut;
166 $fuserstatic->lastname = $obj->lastname;
167 $fuserstatic->firstname = $obj->firstname;
168 $fuserstatic->login = $obj->login;
169 $fuserstatic->photo = $obj->photo;
170 $fuserstatic->admin = $obj->admin;
171 $fuserstatic->email = $obj->email;
172 $fuserstatic->socid = $obj->fk_soc;
173
174 $companystatic->id = $obj->fk_soc;
175 $companystatic->name = $obj->name;
176 $companystatic->code_client = $obj->code_client;
177 $companystatic->canvas = $obj->canvas;
178
179 $lastcreatedbox .= '<tr class="oddeven">';
180 $lastcreatedbox .= '<td class="nowraponall tdoverflowmax150">';
181 $lastcreatedbox .= $fuserstatic->getNomUrl(-1);
182 if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) {
183 $lastcreatedbox .= img_picto($langs->trans("SuperAdministratorDesc"), 'redstar');
184 } elseif ($obj->admin) {
185 $lastcreatedbox .= img_picto($langs->trans("AdministratorDesc"), 'star');
186 }
187 $lastcreatedbox .= "</td>";
188 $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.dol_escape_htmltag($obj->login).'</td>';
189 $texttoshow = '';
190 if ($obj->fk_soc) {
191 $texttoshow .= $companystatic->getNomUrl(1);
192 } else {
193 $texttoshow .= '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
194 }
195 if ($obj->ldap_sid) {
196 $texttoshow .= ' <span class="opacitymedium">('.$langs->trans("DomainUser").')</span>';
197 }
198 $entity = $obj->entity;
199 $entitystring = '';
200 // TODO Set of entitystring should be done with a hook
201 if (isModEnabled('multicompany') && is_object($mc)) {
202 if (empty($entity)) {
203 $entitystring = $langs->trans("AllEntities");
204 } else {
205 $mc->getInfo($entity);
206 $entitystring = $mc->label;
207 }
208 }
209 $texttoshow .= ($entitystring ? ' <span class="opacitymedium">('.$entitystring.')</span>' : '');
210 $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($texttoshow)).'">';
211 $lastcreatedbox .= $texttoshow;
212 $lastcreatedbox .= '</td>';
213 $lastcreatedbox .= '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
214 $lastcreatedbox .= '<td class="right">';
215 $lastcreatedbox .= $fuserstatic->getLibStatut(3);
216 $lastcreatedbox .= '</td>';
217
218 $lastcreatedbox .= '</tr>';
219 $i++;
220 }
221 $lastcreatedbox .= "</table>";
222 $lastcreatedbox .= "</div><br>";
223
224 $db->free($resql);
225} else {
226 dol_print_error($db);
227}
228
229
230/*
231 * Last groups created
232 */
233$lastgroupbox = '';
234if ($permissiontoreadgroup) {
235 $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec";
236 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
237 if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
238 $sql .= " WHERE g.entity IS NOT NULL";
239 } else {
240 $sql .= " WHERE g.entity IN (0, ".$conf->entity.")";
241 }
242 $sql .= $db->order("g.datec", "DESC");
243 $sql .= $db->plimit($max);
244
245 $resql = $db->query($sql);
246 if ($resql) {
247 $colspan = 1;
248 if (isModEnabled('multicompany')) {
249 $colspan++;
250 }
251 $num = $db->num_rows($resql);
252
253 $lastgroupbox .= '<div class="div-table-responsive-no-min">';
254 $lastgroupbox .= '<table class="noborder centpercent">';
255 $lastgroupbox .= '<tr class="liste_titre"><td colspan="'.$colspan.'">';
256 $lastgroupbox .= '<span class="valignmiddle">'.$langs->trans("LastGroupsCreated", ($num ? $num : $max)).'</span>';
257 $lastgroupbox .= '<a class="valignmiddle marginleftonlyshort" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC" title="'.$langs->trans("FullList").'">';
258 $lastgroupbox .= '<span class="badge marginleftonlyshort valignmiddle">...</span>';
259 $lastgroupbox .= '</a>';
260
261 $lastgroupbox .= '</td>';
262 $lastgroupbox .= '<td class="right">';
263 //$lastgroupbox .= '<a class="commonlink" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC">'.$langs->trans("FullList");
264 $lastgroupbox .= '</td>';
265 $lastgroupbox .= '</tr>';
266 $i = 0;
267
268 $grouptemp = new UserGroup($db);
269
270 while ($i < $num && (!$max || $i < $max)) {
271 $obj = $db->fetch_object($resql);
272
273 $grouptemp->id = $obj->rowid;
274 $grouptemp->name = $obj->name;
275 $grouptemp->note = $obj->note;
276
277 $lastgroupbox .= '<tr class="oddeven">';
278 $lastgroupbox .= '<td>';
279 $lastgroupbox .= $grouptemp->getNomUrl(1);
280 if (!$obj->entity) {
281 $lastgroupbox .= img_picto($langs->trans("GlobalGroup"), 'redstar');
282 }
283 $lastgroupbox .= "</td>";
284 if (isModEnabled('multicompany') && is_object($mc)) {
285 $mc->getInfo($obj->entity);
286 $lastgroupbox .= '<td>';
287 $lastgroupbox .= $mc->label;
288 $lastgroupbox .= '</td>';
289 }
290 $lastgroupbox .= '<td class="nowrap right">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
291 $lastgroupbox .= "</tr>";
292 $i++;
293 }
294 $lastgroupbox .= "</table>";
295 $lastgroupbox .= "</div><br>";
296
297 $db->free($resql);
298 } else {
299 dol_print_error($db);
300 }
301}
302
303// boxes
304print '<div class="clearboth"></div>';
305print '<div class="fichecenter fichecenterbis">';
306
307$boxlist = '<div class="twocolumns">';
308
309$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
310$boxlist .= $searchbox;
311$boxlist .= $resultboxes['boxlista'];
312$boxlist .= '</div>'."\n";
313
314$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
315$boxlist .= $lastcreatedbox;
316$boxlist .= $lastgroupbox;
317$boxlist .= $resultboxes['boxlistb'];
318$boxlist .= '</div>'."\n";
319
320$boxlist .= '</div>';
321
322print $boxlist;
323
324print '</div>';
325
326// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
327$parameters = array('user' => $user);
328$reshook = $hookmanager->executeHooks('dashboardUsersGroups', $parameters, $object); // Note that $action and $object may have been modified by hook
329
330// End of page
331llxFooter();
332$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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...