* Copyright (C) 2005-2024 Regis Houssin * Copyright (C) 2019 Nicolas ZABOURI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/user/home.php * \brief Home page of users and groups management */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userhome'; // To manage different context of search if (!$user->hasRight('user', 'user', 'lire') && !$user->admin) { // Redirection vers la page de l'utilisateur header("Location: card.php?id=".$user->id); exit; } // Load translation files required by page $langs->load("users"); $permissiontoreadgroup = true; if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { $permissiontoreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read")); } // Security check (for external users) $socid = 0; if ($user->socid > 0) { $socid = $user->socid; } $companystatic = new Societe($db); $fuserstatic = new User($db); // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('userhome')); if (!isset($form) || !is_object($form)) { $form = new Form($db); } // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb) $resultboxes = FormOther::getBoxesArea($user, "1"); if (GETPOST('addbox')) { // Add box (when submit is done from a form when ajax disabled) require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php'; $zone = GETPOSTINT('areacode'); $userid = GETPOSTINT('userid'); $boxorder = GETPOST('boxorder', 'aZ09'); $boxorder .= GETPOST('boxcombo', 'aZ09'); $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid); if ($result > 0) { setEventMessages($langs->trans("BoxAdded"), null); } } $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5); /* * View */ $title = $langs->trans("MenuUsersAndGroups"); $help_url = ''; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-home'); print load_fiche_titre($langs->trans("MenuUsersAndGroups"), $resultboxes['selectboxlist'], 'user'); // Search User $searchbox = '
'; $searchbox .= ''; $searchbox .= ''; $searchbox .= ''; $searchbox .= ''; // Search Group if ($permissiontoreadgroup) { $searchbox .= ''; } $searchbox .= ''; $searchbox .= "
'.$langs->trans("Search").'
'; $searchbox .= $langs->trans("User").':
'; $searchbox .= $langs->trans("Group").':

\n"; $searchbox .= '
'; /* * Latest created users */ $lastcreatedbox = ''; $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut"; $sql .= ", u.entity"; $sql .= ", u.ldap_sid"; $sql .= ", u.photo"; $sql .= ", u.admin"; $sql .= ", u.email"; $sql .= ", s.nom as name"; $sql .= ", s.code_client"; $sql .= ", s.canvas"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook if ($reshook > 0) { $sql .= $hookmanager->resPrint; } else { $sql .= " WHERE u.entity IN (".getEntity('user').")"; } if (!empty($socid)) { $sql .= " AND u.fk_soc = ".((int) $socid); } $sql .= $db->order("u.datec", "DESC"); $sql .= $db->plimit($max); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $lastcreatedbox .= '
'; $lastcreatedbox .= ''; $lastcreatedbox .= ''; $lastcreatedbox .= ''; $lastcreatedbox .= ''."\n"; $i = 0; while ($i < $num && $i < $max) { $obj = $db->fetch_object($resql); $fuserstatic->id = $obj->rowid; $fuserstatic->statut = $obj->statut; $fuserstatic->status = $obj->statut; $fuserstatic->lastname = $obj->lastname; $fuserstatic->firstname = $obj->firstname; $fuserstatic->login = $obj->login; $fuserstatic->photo = $obj->photo; $fuserstatic->admin = $obj->admin; $fuserstatic->email = $obj->email; $fuserstatic->socid = $obj->fk_soc; $companystatic->id = $obj->fk_soc; $companystatic->name = $obj->name; $companystatic->code_client = $obj->code_client; $companystatic->canvas = $obj->canvas; $lastcreatedbox .= ''; $lastcreatedbox .= '"; $lastcreatedbox .= ''; $texttoshow = ''; if ($obj->fk_soc) { $texttoshow .= $companystatic->getNomUrl(1); } else { $texttoshow .= ''.$langs->trans("InternalUser").''; } if ($obj->ldap_sid) { $texttoshow .= ' ('.$langs->trans("DomainUser").')'; } $entity = $obj->entity; $entitystring = ''; // TODO Set of entitystring should be done with a hook if (isModEnabled('multicompany') && is_object($mc)) { if (empty($entity)) { $entitystring = $langs->trans("AllEntities"); } else { $mc->getInfo($entity); $entitystring = $mc->label; } } $texttoshow .= ($entitystring ? ' ('.$entitystring.')' : ''); $lastcreatedbox .= ''; $lastcreatedbox .= ''; $lastcreatedbox .= ''; $lastcreatedbox .= ''; $i++; } $lastcreatedbox .= "
'; $lastcreatedbox .= ''.$langs->trans("LastUsersCreated", min($num, $max)).''; $lastcreatedbox .= ''; $lastcreatedbox .= '...'; $lastcreatedbox .= ''; $lastcreatedbox .= ''; //$lastcreatedbox .= ''.$langs->trans("FullList"); $lastcreatedbox .= '
'; $lastcreatedbox .= $fuserstatic->getNomUrl(-1); if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) { $lastcreatedbox .= img_picto($langs->trans("SuperAdministratorDesc"), 'redstar'); } elseif ($obj->admin) { $lastcreatedbox .= img_picto($langs->trans("AdministratorDesc"), 'star'); } $lastcreatedbox .= "'.dol_escape_htmltag($obj->login).''; $lastcreatedbox .= $texttoshow; $lastcreatedbox .= ''.dol_print_date($db->jdate($obj->datec), 'dayhour').''; $lastcreatedbox .= $fuserstatic->getLibStatut(3); $lastcreatedbox .= '
"; $lastcreatedbox .= "

"; $db->free($resql); } else { dol_print_error($db); } /* * Last groups created */ $lastgroupbox = ''; if ($permissiontoreadgroup) { $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec"; $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g"; if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) { $sql .= " WHERE g.entity IS NOT NULL"; } else { $sql .= " WHERE g.entity IN (0, ".$conf->entity.")"; } $sql .= $db->order("g.datec", "DESC"); $sql .= $db->plimit($max); $resql = $db->query($sql); if ($resql) { $colspan = 1; if (isModEnabled('multicompany')) { $colspan++; } $num = $db->num_rows($resql); $lastgroupbox .= '
'; $lastgroupbox .= ''; $lastgroupbox .= ''; $lastgroupbox .= ''; $lastgroupbox .= ''; $i = 0; $grouptemp = new UserGroup($db); while ($i < $num && (!$max || $i < $max)) { $obj = $db->fetch_object($resql); $grouptemp->id = $obj->rowid; $grouptemp->name = $obj->name; $grouptemp->note = $obj->note; $lastgroupbox .= ''; $lastgroupbox .= '"; if (isModEnabled('multicompany') && is_object($mc)) { $mc->getInfo($obj->entity); $lastgroupbox .= ''; } $lastgroupbox .= ''; $lastgroupbox .= ""; $i++; } $lastgroupbox .= "
'; $lastgroupbox .= ''.$langs->trans("LastGroupsCreated", ($num ? $num : $max)).''; $lastgroupbox .= ''; $lastgroupbox .= '...'; $lastgroupbox .= ''; $lastgroupbox .= ''; //$lastgroupbox .= ''.$langs->trans("FullList"); $lastgroupbox .= '
'; $lastgroupbox .= $grouptemp->getNomUrl(1); if (!$obj->entity) { $lastgroupbox .= img_picto($langs->trans("GlobalGroup"), 'redstar'); } $lastgroupbox .= "'; $lastgroupbox .= $mc->label; $lastgroupbox .= ''.dol_print_date($db->jdate($obj->datec), 'dayhour').'
"; $lastgroupbox .= "

"; $db->free($resql); } else { dol_print_error($db); } } // boxes print '
'; print '
'; $boxlist = '
'; $boxlist .= '
'; $boxlist .= $searchbox; $boxlist .= $resultboxes['boxlista']; $boxlist .= '
'."\n"; $boxlist .= '
'; $boxlist .= $lastcreatedbox; $boxlist .= $lastgroupbox; $boxlist .= $resultboxes['boxlistb']; $boxlist .= '
'."\n"; $boxlist .= '
'; print $boxlist; print '
'; // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array $parameters = array('user' => $user); $reshook = $hookmanager->executeHooks('dashboardUsersGroups', $parameters, $object); // Note that $action and $object may have been modified by hook // End of page llxFooter(); $db->close();