dolibarr/htdocs/user/home.php

263 lines
7.6 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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
2011-08-01 01:19:04 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/user/home.php
* \brief Home page of users and groups management
*/
require '../main.inc.php';
2011-04-06 21:54:06 +02:00
if (! $user->rights->user->user->lire && ! $user->admin)
2005-08-23 13:16:40 +02:00
{
// Redirection vers la page de l'utilisateur
2012-08-31 05:58:38 +02:00
header("Location: fiche.php?id=".$user->id);
2011-04-06 21:54:06 +02:00
exit;
2005-08-23 13:16:40 +02:00
}
$langs->load("users");
2010-11-08 15:33:44 +01:00
$canreadperms=true;
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
{
$canreadperms=($user->admin || $user->rights->user->group_advance->read);
}
// Security check (for external users)
$socid=0;
if ($user->societe_id > 0) $socid = $user->societe_id;
2010-10-29 18:08:54 +02:00
$companystatic = new Societe($db);
2011-04-06 21:54:06 +02:00
$fuserstatic = new User($db);
/*
* View
*/
llxHeader();
print_fiche_titre($langs->trans("MenuUsersAndGroups"));
//print '<table border="0" width="100%" class="notopnoleftnoright">';
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
print '<div class="fichecenter"><div class="fichethirdleft">';
2010-10-29 09:27:33 +02:00
// Search User
$var=false;
print '<form method="post" action="'.DOL_URL_ROOT.'/user/index.php">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2005-09-06 21:55:56 +02:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAUser").'</td></tr>';
print '<tr '.$bc[$var].'><td>';
2008-05-13 08:52:31 +02:00
print $langs->trans("Ref").':</td><td><input class="flat" type="text" name="search_user" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
print '<tr '.$bc[$var].'><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td></tr>';
2005-09-06 21:55:56 +02:00
print "</table><br>\n";
print '</form>';
2010-10-29 09:27:33 +02:00
// Search Group
2010-11-08 15:33:44 +01:00
if ($canreadperms)
2010-10-29 09:27:33 +02:00
{
$var=false;
print '<form method="post" action="'.DOL_URL_ROOT.'/user/group/index.php">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAGroup").'</td></tr>';
print '<tr '.$bc[$var].'><td>';
print $langs->trans("Ref").':</td><td><input class="flat" type="text" name="search_group" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
print '<tr '.$bc[$var].'><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td></tr>';
2010-10-29 09:27:33 +02:00
print "</table><br>\n";
print '</form>';
}
//print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
/*
2011-04-06 21:54:06 +02:00
* Last created users
*/
$max=10;
2013-02-23 17:40:28 +01:00
$sql = "SELECT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_societe, u.datec, u.statut, u.entity, u.ldap_sid,";
$sql.= " s.nom as name, s.canvas";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_societe = s.rowid";
if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->multicompany->transverse_mode || ($user->admin && ! $user->entity)))
2011-08-20 00:15:22 +02:00
{
$sql.= " WHERE u.entity IS NOT NULL";
}
else
{
$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
}
if (!empty($socid)) $sql.= " AND u.fk_societe = ".$socid;
2010-08-12 15:35:08 +02:00
$sql.= $db->order("u.datec","DESC");
$sql.= $db->plimit($max);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
print '<table class="noborder" width="100%">';
2011-04-06 21:54:06 +02:00
print '<tr class="liste_titre"><td colspan="5">'.$langs->trans("LastUsersCreated",min($num,$max)).'</td></tr>';
$var = true;
$i = 0;
while ($i < $num && $i < $max)
{
$obj = $db->fetch_object($resql);
$var=!$var;
2013-06-20 09:18:12 +02:00
print "<tr ".$bc[$var].">";
print '<td><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowUser"),"user").' '.dolGetFirstLastname($obj->firstname,$obj->lastname).'</a>';
if (! empty($conf->multicompany->enabled) && $obj->admin && ! $obj->entity)
{
print img_picto($langs->trans("SuperAdministrator"),'redstar');
}
else if ($obj->admin)
{
print img_picto($langs->trans("Administrator"),'star');
}
print "</td>";
2010-10-29 16:22:35 +02:00
print '<td align="left">'.$obj->login.'</td>';
print "<td>";
if ($obj->fk_societe)
{
2010-10-29 18:08:54 +02:00
$companystatic->id=$obj->fk_societe;
$companystatic->name=$obj->name;
2010-10-29 18:08:54 +02:00
$companystatic->canvas=$obj->canvas;
print $companystatic->getNomUrl(1);
}
2011-08-21 12:01:36 +02:00
else if (! empty($conf->multicompany->enabled))
2011-08-20 00:15:22 +02:00
{
if ($obj->admin && ! $obj->entity)
{
print $langs->trans("AllEntities");
}
else
{
$mc->getInfo($obj->entity);
print $mc->label;
}
}
else if ($obj->ldap_sid)
{
print $langs->trans("DomainUser");
}
2011-08-20 00:15:22 +02:00
else
{
print $langs->trans("InternalUser");
}
print '</td>';
2010-10-29 16:22:35 +02:00
print '<td align="right">'.dol_print_date($db->jdate($obj->datec),'dayhour').'</td>';
2011-04-06 21:54:06 +02:00
print '<td align="right">';
$fuserstatic->id=$obj->rowid;
2011-04-06 21:54:06 +02:00
$fuserstatic->statut=$obj->statut;
print $fuserstatic->getLibStatut(3);
print '</td>';
print '</tr>';
$i++;
}
print "</table><br>";
$db->free($resql);
}
else
{
dol_print_error($db);
}
/*
* Last groups created
*/
2010-11-08 15:33:44 +01:00
if ($canreadperms)
{
2010-10-29 09:27:33 +02:00
$max=5;
2011-04-06 21:54:06 +02:00
2010-10-29 09:27:33 +02:00
$sql = "SELECT g.rowid, g.nom, g.note, g.entity, g.datec";
$sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g";
if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->multicompany->transverse_mode || ($user->admin && ! $user->entity)))
2011-08-20 11:03:38 +02:00
{
$sql.= " WHERE g.entity IS NOT NULL";
}
else
{
$sql.= " WHERE g.entity IN (0,".$conf->entity.")";
}
2010-10-29 09:27:33 +02:00
$sql.= $db->order("g.datec","DESC");
$sql.= $db->plimit($max);
2011-04-06 21:54:06 +02:00
2010-10-29 09:27:33 +02:00
$resql=$db->query($sql);
if ($resql)
{
2011-08-20 11:03:38 +02:00
$colspan=2;
2011-08-21 12:01:36 +02:00
if (! empty($conf->multicompany->enabled)) $colspan++;
2010-10-29 09:27:33 +02:00
$num = $db->num_rows($resql);
print '<table class="noborder" width="100%">';
2011-08-20 11:03:38 +02:00
print '<tr class="liste_titre"><td colspan="'.$colspan.'">'.$langs->trans("LastGroupsCreated",($num ? $num : $max)).'</td></tr>';
2010-10-29 09:27:33 +02:00
$var = true;
$i = 0;
2011-04-06 21:54:06 +02:00
2010-10-29 09:27:33 +02:00
while ($i < $num && (! $max || $i < $max))
{
2010-10-29 09:27:33 +02:00
$obj = $db->fetch_object($resql);
$var=!$var;
2011-04-06 21:54:06 +02:00
2013-06-20 09:18:12 +02:00
print "<tr ".$bc[$var].">";
2010-10-29 09:27:33 +02:00
print '<td><a href="'.DOL_URL_ROOT.'/user/group/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowGroup"),"group").' '.$obj->nom.'</a>';
2011-08-20 11:03:38 +02:00
if (! $obj->entity)
2010-10-29 09:27:33 +02:00
{
print img_picto($langs->trans("GlobalGroup"),'redstar');
}
print "</td>";
2011-08-21 12:01:36 +02:00
if (! empty($conf->multicompany->enabled))
2011-09-20 17:41:16 +02:00
{
2011-08-20 11:03:38 +02:00
$mc->getInfo($obj->entity);
print '<td>';
print $mc->label;
print '</td>';
2011-09-20 17:41:16 +02:00
}
print '<td class="nowrap" align="right">'.dol_print_date($db->jdate($obj->datec),'dayhour').'</td>';
2010-10-29 09:27:33 +02:00
print "</tr>";
$i++;
}
2010-10-29 09:27:33 +02:00
print "</table><br>";
2011-04-06 21:54:06 +02:00
2010-10-29 09:27:33 +02:00
$db->free($resql);
}
else
{
dol_print_error($db);
}
}
//print '</td></tr></table>';
2013-03-30 19:40:52 +01:00
print '</div></div></div>';
llxFooter();
$db->close();
?>