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