* Copyright (C) 2005 Laurent Destailleur * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ */ /** \file htdocs/user/group/fiche.php \brief Onglet groupes utilisateurs \version $Revision$ */ require("./pre.inc.php"); $langs->load("users"); $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; /** * Action ajout */ if ($_POST["action"] == 'add' && $user->admin) { $message=""; if (! $_POST["nom"]) { $message='
'.$langs->trans("NameNotDefined").'
'; $action="create"; // Go back to create page } if (! $message) { $editgroup = new UserGroup($db,0); $editgroup->nom = trim($_POST["nom"]); $editgroup->note = trim($_POST["note"]); $db->begin(); $id = $editgroup->create(); if ($id > 0) { $db->commit(); Header("Location: fiche.php?id=".$editgroup->id); } else { $db->rollback(); $message='
'.$langs->trans("ErrorGroupAlreadyExists",$editgroup->nom).'
'; $action="create"; // Go back to create page } } } if ($_POST["action"] == 'adduser' && $user->admin) { if ($_POST["user"]) { $edituser = new User($db, $_POST["user"]); $edituser->SetInGroup($_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]); } } if ($_GET["action"] == 'removeuser' && $user->admin) { if ($_GET["user"]) { $edituser = new User($db, $_GET["user"]); $edituser->RemoveFromGroup($_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]); } } llxHeader(); /* ************************************************************************** */ /* */ /* Affichage fiche en mode création */ /* */ /* ************************************************************************** */ if ($action == 'create') { print_titre($langs->trans("NewGroup")); print "
"; if ($message) { print $message."
"; } print '
'; print ''; print ''; print "".''; print ''; print "".'\n"; print "".''; print ""; print "
'.$langs->trans("Name").'
'.$langs->trans("Note").''; print "
\n"; } /* ************************************************************************** */ /* */ /* Visu et edition */ /* */ /* ************************************************************************** */ else { if ($_GET["id"]) { $group = new UserGroup($db); $group->fetch($_GET["id"]); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$group->id; $head[$h][1] = $langs->trans("GroupCard"); $hselected=$h; $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Group").": ".$group->nom); /* * Confirmation suppression */ if ($action == 'delete') { $html = new Form($db); $html->form_confirm("fiche.php?id=$fuser->id",$langs->trans("DisableAGroup"),$langs->trans("ConfirmDisableGroup",$fuser->login),"confirm_delete"); } /* * Fiche en mode visu */ print ''; print ''; print ''; print "\n"; print ''; print ''; print "\n"; print "
'.$langs->trans("Name").''.$group->nom.'
'.$langs->trans("Note").''.nl2br($group->note).' 
\n"; print "
\n"; $uss = array(); // On sélectionne les users qui ne sont pas déjà dans le groupe $sql = "SELECT u.rowid, u.name, u.firstname, u.code "; $sql .= " FROM ".MAIN_DB_PREFIX."user as u "; # $sql .= " LEFT JOIN llx_usergroup_user ug ON u.rowid = ug.fk_user"; # $sql .= " WHERE ug.fk_usergroup IS NULL"; $sql .= " ORDER BY u.name"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $obj = $db->fetch_object(); $uss[$obj->rowid] = ucfirst(stripslashes($obj->firstname)) . " ".ucfirst(stripslashes($obj->name)); $i++; } } else { dolibarr_print_error($db); } if ($user->admin) { $form = new Form($db); print '
'."\n"; print ''; print ''."\n"; // print ''."\n"; print ''."\n"; print ''."\n"; print '
'.$langs->trans("NonAffectedUsers").'
'.$langs->trans("Users").''; print $form->select_array("user",$uss); print ''; print ''; print '
'."\n"; } /* * Membres du groupe * */ $sql = "SELECT u.rowid, u.name, u.firstname, u.code "; $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= " WHERE ug.fk_user = u.rowid"; $sql .= " AND ug.fk_usergroup = ".$group->id; $sql .= " ORDER BY u.name"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; print "
"; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=True; while ($i < $num) { $obj = $db->fetch_object($result); $var=!$var; print ""; print ''; print ''; print '\n"; $i++; } print "
'.$langs->trans("Lastname").''.$langs->trans("Firstname").''.$langs->trans("Code").' 
'; print ''.img_object($langs->trans("ShowUser"),"user").' '; print ''.ucfirst(stripslashes($obj->name)).''; print ''.ucfirst(stripslashes($obj->firstname)).''.$obj->code.''; if ($user->admin) { print ''; print img_delete($langs->trans("RemoveFromGroup")); } else { print "-"; } print "
"; print "
"; $db->free($result); } print ''; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>