From 2cda2dbc8172b728fc3a2f81ad64157c19d20b82 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Thu, 27 Jan 2005 15:55:40 +0000 Subject: [PATCH] Nouveau fichier --- htdocs/user/group/fiche.php | 262 ++++++++++++++++++++++++++++++++++ htdocs/user/group/index.php | 77 ++++++++++ htdocs/user/group/pre.inc.php | 54 +++++++ htdocs/usergroup.class.php | 135 ++++++++++++++++++ 4 files changed, 528 insertions(+) create mode 100644 htdocs/user/group/fiche.php create mode 100644 htdocs/user/group/index.php create mode 100644 htdocs/user/group/pre.inc.php create mode 100644 htdocs/usergroup.class.php diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php new file mode 100644 index 00000000000..4bc71512dda --- /dev/null +++ b/htdocs/user/group/fiche.php @@ -0,0 +1,262 @@ + + * + * 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/fiche.php + \brief Onglet user et permissions de la fiche utilisateur + \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"]); + + $result = $editgroup->create(); + + if ($result == 0) + { + Header("Location: fiche.php?id=".$editgroup->id); + } + else + { + $message='
'.$langs->trans("LoginAlreadyExists",$edituser->login).'
'; + $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")); + + if ($message) { print "
".$message."
"; } + + print '
'; + print ''; + + print ''; + + print "".''; + print ''; + + print "".'\n"; + + print "".''; + print ""; + print "
'.$langs->trans("Lastname").'
'.$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, $group->nom); + + /* + * Confirmation suppression + */ + if ($action == 'delete') + { + $html = new Form($db); + $html->form_confirm("fiche.php?id=$fuser->id",$langs->trans("DisableAUser"),$langs->trans("ConfirmDisableUser",$fuser->login),"confirm_delete"); + } + + + /* + * Fiche en mode visu + */ + + print ''; + print ''; + print ''; + print "\n"; + print ''; + print ''; + print "\n"; + print "
'.$langs->trans("Lastname").''.$group->nom.'
'.$langs->trans("Note").''.nl2br($group->note).' 
\n"; + print "
\n"; + + $uss = array(); + + $sql = "SELECT u.rowid, u.name, u.firstname, u.code "; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $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++; + } + } + + if ($user->admin) + { + $form = new Form($db); + print '
'."\n"; + print ''; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print '
Ajouter'; + 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(); + $i = 0; + + print "
"; + + print ''; + print ''; + print_liste_field_titre($langs->trans("LastName"),"index.php","name","","","",$sortfield); + print_liste_field_titre($langs->trans("FirstName"),"index.php","firstname","","","",$sortfield); + print_liste_field_titre($langs->trans("Code"),"index.php","code","","","",$sortfield); + print "\n"; + $var=True; + while ($i < $num) + { + $obj = $db->fetch_object(); + $var=!$var; + + print ""; + print ''; + print ''; + print '\n"; + $i++; + } + print "
-
'.ucfirst(stripslashes($obj->name)).''.ucfirst(stripslashes($obj->firstname)).''.$obj->code.''; + + if ($user->admin) + { + + print ''; + print img_delete(); + } + else + { + print "-"; + } + print "
"; + $db->free(); + } + } +} + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php new file mode 100644 index 00000000000..59f88bce013 --- /dev/null +++ b/htdocs/user/group/index.php @@ -0,0 +1,77 @@ + + * Copyright (C) 2004 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/index.php + \brief Page d'accueil de la gestion des utilisateurs + \version $Revision$ +*/ + +require("./pre.inc.php"); + +$langs->load("users"); + +llxHeader(); + +print_titre($langs->trans("ListOfGroups")); + +$sql = "SELECT g.rowid, g.nom"; +$sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g"; +$sql .= " ORDER BY g.nom ASC"; + +$result = $db->query($sql); +if ($result) +{ + $num = $db->num_rows(); + $i = 0; + + print "
"; + + print ""; + print ''; + print_liste_field_titre($langs->trans("LastName"),"index.php","name","","","",$sortfield); + print "\n"; + $var=True; + while ($i < $num) + { + $obj = $db->fetch_object( $i); + $var=!$var; + + print ""; + print ''; + + print "\n"; + $i++; + } + print "
'.img_file().' '.$obj->nom.'
"; + $db->free(); +} +else +{ + dolibarr_print_error($db); +} + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/user/group/pre.inc.php b/htdocs/user/group/pre.inc.php new file mode 100644 index 00000000000..5ba5db19a81 --- /dev/null +++ b/htdocs/user/group/pre.inc.php @@ -0,0 +1,54 @@ + + * + * 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$ + */ +require("../../main.inc.php"); + +require(DOL_DOCUMENT_ROOT.'/usergroup.class.php'); + +function llxHeader($head = "", $urlp = "") +{ + global $user, $langs; + /* + * + * + */ + top_menu($head); + + $menu = new Menu(); + + $menu->add(DOL_URL_ROOT."/user/", "Utilisateurs"); + + if($user->admin) + { + $menu->add_submenu("fiche.php?&action=create",$langs->trans("NewUser")); + } + + $menu->add(DOL_URL_ROOT."/user/group/", "Groupes"); + + if($user->admin) + { + $menu->add_submenu(DOL_URL_ROOT."/user/group/fiche.php?&action=create",$langs->trans("NewGroup")); + } + + + left_menu($menu->liste); +} + +?> diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php new file mode 100644 index 00000000000..abfa90ebceb --- /dev/null +++ b/htdocs/usergroup.class.php @@ -0,0 +1,135 @@ + + * + * 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/usergroup.class.php + \brief Fichier de la classe des groupes d'utilisateur + \author Rodolphe Qiedeville + \version $Revision$ +*/ + +/** + \class User + \brief Classe permettant la gestion des groupes d'utilisateur +*/ + +class UserGroup +{ + var $db; + + var $id; + var $label; + + /** + * \brief Constructeur de la classe + * \param $DB handler accès base de données + */ + + function UserGroup($DB) + { + $this->db = $DB; + + return 0; + } + + /** + * \brief Ajoute un droit a l'utilisateur + * \param rid id du droit à ajouter + */ + + + /** + * \brief Charge un objet user avec toutes ces caractéristiques depuis un login + * \param login login a charger + */ + + function fetch($id) + { + $this->id = $id; + + $sql = "SELECT g.rowid, g.nom FROM ".MAIN_DB_PREFIX."usergroup as g"; + $sql .= " WHERE g.rowid = ".$this->id; + + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object(); + + $this->id = $obj->rowid; + $this->nom = stripslashes($obj->nom); + + } + $this->db->free(); + + } + else + { + dolibarr_syslog("UserGroup::Fetch Erreur"); + } + } + + /** + * \brief Efface un groupe de la base + */ + + function delete() + { + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup"; + $sql .= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + + } + + } + + /** + * \brief Crée un groupe en base + */ + + function create() + { + + $sql = "INSERT into ".MAIN_DB_PREFIX."usergroup (datec,nom)"; + $sql .= " VALUES(now(),'$this->nom')"; + + if ($this->db->query($sql)) + { + $this->id = $this->db->last_insert_id(); + return 0; + } + else + { + dolibarr_syslog("UserGroup::Create"); + return -1; + } + } + + +} + +?>