dolibarr  16.0.5
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-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 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
28 
29 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userhome'; // To manage different context of search
30 
31 if (!$user->rights->user->user->lire && !$user->admin) {
32  // Redirection vers la page de l'utilisateur
33  header("Location: card.php?id=".$user->id);
34  exit;
35 }
36 
37 // Load translation files required by page
38 $langs->load("users");
39 
40 $canreadperms = true;
41 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
42  $canreadperms = ($user->admin || $user->rights->user->group_advance->read);
43 }
44 
45 // Security check (for external users)
46 $socid = 0;
47 if ($user->socid > 0) {
48  $socid = $user->socid;
49 }
50 
51 $companystatic = new Societe($db);
52 $fuserstatic = new User($db);
53 
54 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
55 $hookmanager->initHooks(array('userhome'));
56 if (!isset($form) || !is_object($form)) {
57  $form = new Form($db);
58 }
59 // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
60 $resultboxes = FormOther::getBoxesArea($user, "1");
61 
62 if (GETPOST('addbox')) {
63  // Add box (when submit is done from a form when ajax disabled)
64  require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
65  $zone = GETPOST('areacode', 'int');
66  $userid = GETPOST('userid', 'int');
67  $boxorder = GETPOST('boxorder', 'aZ09');
68  $boxorder .= GETPOST('boxcombo', 'aZ09');
69  $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
70  if ($result > 0) {
71  setEventMessages($langs->trans("BoxAdded"), null);
72  }
73 }
74 
75 /*
76  * View
77  */
78 
79 llxHeader();
80 
81 
82 print load_fiche_titre($langs->trans("MenuUsersAndGroups"), $resultboxes['selectboxlist'], 'user');
83 
84 
85 // Search User
86 $searchbox = '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
87 $searchbox .= '<input type="hidden" name="token" value="'.newToken().'">';
88 
89 $searchbox .= '<table class="noborder nohover centpercent">';
90 $searchbox .= '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Search").'</td></tr>';
91 $searchbox .= '<tr><td>';
92 $searchbox .= $langs->trans("User").':</td><td><input class="flat inputsearch width200" type="text" name="search_user"></td></tr>';
93 
94 // Search Group
95 if ($canreadperms) {
96  $searchbox .= '<tr><td>';
97  $searchbox .= $langs->trans("Group").':</td><td><input class="flat inputsearch width200" type="text" name="search_group"></td></tr>';
98 }
99 
100 $searchbox .= '<tr><td class="center" colspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
101 $searchbox .= "</table><br>\n";
102 
103 $searchbox .= '</form>';
104 
105 
106 /*
107  * Latest created users
108  */
109 $max = 10;
110 $lastcreatedbox = '';
111 $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut";
112 $sql .= ", u.entity";
113 $sql .= ", u.ldap_sid";
114 $sql .= ", u.photo";
115 $sql .= ", u.admin";
116 $sql .= ", u.email";
117 $sql .= ", s.nom as name";
118 $sql .= ", s.code_client";
119 $sql .= ", s.canvas";
120 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
121 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
122 // Add fields from hooks
123 $parameters = array();
124 $reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook
125 if ($reshook > 0) {
126  $sql .= $hookmanager->resPrint;
127 } else {
128  $sql .= " WHERE u.entity IN (".getEntity('user').")";
129 }
130 if (!empty($socid)) {
131  $sql .= " AND u.fk_soc = ".((int) $socid);
132 }
133 $sql .= $db->order("u.datec", "DESC");
134 $sql .= $db->plimit($max);
135 
136 $resql = $db->query($sql);
137 if ($resql) {
138  $num = $db->num_rows($resql);
139 
140  $lastcreatedbox .= '<div class="div-table-responsive-no-min">';
141  $lastcreatedbox .= '<table class="noborder centpercent">';
142  $lastcreatedbox .= '<tr class="liste_titre"><td colspan="3">'.$langs->trans("LastUsersCreated", min($num, $max)).'</td>';
143  $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>';
144  $lastcreatedbox .= '</tr>'."\n";
145  $i = 0;
146 
147  while ($i < $num && $i < $max) {
148  $obj = $db->fetch_object($resql);
149 
150  $fuserstatic->id = $obj->rowid;
151  $fuserstatic->statut = $obj->statut;
152  $fuserstatic->lastname = $obj->lastname;
153  $fuserstatic->firstname = $obj->firstname;
154  $fuserstatic->login = $obj->login;
155  $fuserstatic->photo = $obj->photo;
156  $fuserstatic->admin = $obj->admin;
157  $fuserstatic->email = $obj->email;
158  $fuserstatic->socid = $obj->fk_soc;
159 
160  $companystatic->id = $obj->fk_soc;
161  $companystatic->name = $obj->name;
162  $companystatic->code_client = $obj->code_client;
163  $companystatic->canvas = $obj->canvas;
164 
165  $lastcreatedbox .= '<tr class="oddeven">';
166  $lastcreatedbox .= '<td class="nowraponall tdoverflowmax150">';
167  $lastcreatedbox .= $fuserstatic->getNomUrl(-1);
168  if (!empty($conf->multicompany->enabled) && $obj->admin && !$obj->entity) {
169  $lastcreatedbox .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
170  } elseif ($obj->admin) {
171  $lastcreatedbox .= img_picto($langs->trans("Administrator"), 'star');
172  }
173  $lastcreatedbox .= "</td>";
174  $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.dol_escape_htmltag($obj->login).'</td>';
175  $texttoshow = '';
176  if ($obj->fk_soc) {
177  $texttoshow .= $companystatic->getNomUrl(1);
178  } else {
179  $texttoshow .= '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
180  }
181  if ($obj->ldap_sid) {
182  $texttoshow .= ' <span class="opacitymedium">('.$langs->trans("DomainUser").')</span>';
183  }
184  $entity = $obj->entity;
185  $entitystring = '';
186  // TODO Set of entitystring should be done with a hook
187  if (!empty($conf->multicompany->enabled) && is_object($mc)) {
188  if (empty($entity)) {
189  $entitystring = $langs->trans("AllEntities");
190  } else {
191  $mc->getInfo($entity);
192  $entitystring = $mc->label;
193  }
194  }
195  $texttoshow .= ($entitystring ? ' <span class="opacitymedium">('.$entitystring.')</span>' : '');
196  $lastcreatedbox .= '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($texttoshow)).'">';
197  $lastcreatedbox .= $texttoshow;
198  $lastcreatedbox .= '</td>';
199  $lastcreatedbox .= '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
200  $lastcreatedbox .= '<td class="right">';
201  $lastcreatedbox .= $fuserstatic->getLibStatut(3);
202  $lastcreatedbox .= '</td>';
203 
204  $lastcreatedbox .= '</tr>';
205  $i++;
206  }
207  $lastcreatedbox .= "</table>";
208  $lastcreatedbox .= "</div><br>";
209 
210  $db->free($resql);
211 } else {
212  dol_print_error($db);
213 }
214 
215 
216 /*
217  * Last groups created
218  */
219 $lastgroupbox = '';
220 if ($canreadperms) {
221  $max = 5;
222 
223  $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec";
224  $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
225  if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity))) {
226  $sql .= " WHERE g.entity IS NOT NULL";
227  } else {
228  $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
229  }
230  $sql .= $db->order("g.datec", "DESC");
231  $sql .= $db->plimit($max);
232 
233  $resql = $db->query($sql);
234  if ($resql) {
235  $colspan = 1;
236  if (!empty($conf->multicompany->enabled)) {
237  $colspan++;
238  }
239  $num = $db->num_rows($resql);
240 
241  $lastgroupbox .= '<div class="div-table-responsive-no-min">';
242  $lastgroupbox .= '<table class="noborder centpercent">';
243  $lastgroupbox .= '<tr class="liste_titre"><td colspan="'.$colspan.'">'.$langs->trans("LastGroupsCreated", ($num ? $num : $max)).'</td>';
244  $lastgroupbox .= '<td class="right"><a class="commonlink" href="'.DOL_URL_ROOT.'/user/group/list.php?sortfield=g.datec&sortorder=DESC">'.$langs->trans("FullList").'</td>';
245  $lastgroupbox .= '</tr>';
246  $i = 0;
247 
248  $grouptemp = new UserGroup($db);
249 
250  while ($i < $num && (!$max || $i < $max)) {
251  $obj = $db->fetch_object($resql);
252 
253  $grouptemp->id = $obj->rowid;
254  $grouptemp->name = $obj->name;
255  $grouptemp->note = $obj->note;
256 
257  $lastgroupbox .= '<tr class="oddeven">';
258  $lastgroupbox .= '<td>';
259  $lastgroupbox .= $grouptemp->getNomUrl(1);
260  if (!$obj->entity) {
261  $lastgroupbox .= img_picto($langs->trans("GlobalGroup"), 'redstar');
262  }
263  $lastgroupbox .= "</td>";
264  if (!empty($conf->multicompany->enabled) && is_object($mc)) {
265  $mc->getInfo($obj->entity);
266  $lastgroupbox .= '<td>';
267  $lastgroupbox .= $mc->label;
268  $lastgroupbox .= '</td>';
269  }
270  $lastgroupbox .= '<td class="nowrap right">'.dol_print_date($db->jdate($obj->datec), 'dayhour').'</td>';
271  $lastgroupbox .= "</tr>";
272  $i++;
273  }
274  $lastgroupbox .= "</table>";
275  $lastgroupbox .= "</div><br>";
276 
277  $db->free($resql);
278  } else {
279  dol_print_error($db);
280  }
281 }
282 
283 // boxes
284 print '<div class="clearboth"></div>';
285 print '<div class="fichecenter fichecenterbis">';
286 
287 $boxlist = '<div class="twocolumns">';
288 
289 $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
290 $boxlist .= $searchbox;
291 $boxlist .= $resultboxes['boxlista'];
292 $boxlist .= '</div>'."\n";
293 
294 $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
295 $boxlist .= $lastcreatedbox;
296 $boxlist .= $lastgroupbox;
297 $boxlist .= $resultboxes['boxlistb'];
298 $boxlist .= '</div>'."\n";
299 
300 $boxlist .= '</div>';
301 
302 print $boxlist;
303 
304 print '</div>';
305 
306 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
307 $parameters = array('user' => $user);
308 $reshook = $hookmanager->executeHooks('dashboardUsersGroups', $parameters, $object); // Note that $action and $object may have been modified by hook
309 
310 // End of page
311 llxFooter();
312 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
UserGroup
Class to manage user groups.
Definition: usergroup.class.php:39
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
InfoBox\saveboxorder
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
Definition: infobox.class.php:224
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
FormOther\getBoxesArea
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user.
Definition: html.formother.class.php:1173
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59