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 20/** 21 * \file htdocs/user/home.php 22 * \brief Home page of users and groups management 23 */ 24 25require '../main.inc.php'; 26require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; 27require_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 31if (!$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; 41if (!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; 47if ($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')); 56if (!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 62if (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 79llxHeader(); 80 81 82print 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 95if ($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 125if ($reshook > 0) { 126 $sql .= $hookmanager->resPrint; 127} else { 128 $sql .= " WHERE u.entity IN (".getEntity('user').")"; 129} 130if (!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); 137if ($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">'; 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>'.$obj->login.'</td>'; 175 $lastcreatedbox .="<td>"; 176 if ($obj->fk_soc) { 177 $lastcreatedbox .=$companystatic->getNomUrl(1); 178 } else { 179 $lastcreatedbox .=$langs->trans("InternalUser"); 180 } 181 if ($obj->ldap_sid) { 182 $lastcreatedbox .=' ('.$langs->trans("DomainUser").')'; 183 } 184 185 $entity = $obj->entity; 186 $entitystring = ''; 187 // TODO Set of entitystring should be done with a hook 188 if (!empty($conf->multicompany->enabled) && is_object($mc)) { 189 if (empty($entity)) { 190 $entitystring = $langs->trans("AllEntities"); 191 } else { 192 $mc->getInfo($entity); 193 $entitystring = $mc->label; 194 } 195 } 196 $lastcreatedbox .=($entitystring ? ' ('.$entitystring.')' : ''); 197 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 = ''; 220if ($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 284print '<div class="clearboth"></div>'; 285print '<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 302print $boxlist; 303 304print '</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 311llxFooter(); 312$db->close(); 313