[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/user/group/ -> fiche.php (source)

   1  <?php
   2  /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License
  16   * along with this program; if not, write to the Free Software
  17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18   *
  19   * $Id: fiche.php,v 1.16 2005/08/11 18:48:08 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/user/group/fiche.php,v $
  21   */
  22  
  23  /**
  24          \file       htdocs/user/group/fiche.php
  25          \brief      Onglet groupes utilisateurs
  26          \version    $Revision: 1.16 $
  27  */
  28  
  29  
  30  require ("./pre.inc.php");
  31  
  32  $langs->load("users");
  33  
  34  $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
  35  
  36  
  37  /**
  38   *  Action suppression groupe
  39   */
  40  if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes")
  41  {
  42    $editgroup = new Usergroup($db, $_GET["id"]);
  43    $editgroup->fetch($_GET["id"]);
  44    $editgroup->delete();
  45    Header("Location: index.php");
  46  }
  47  
  48  /**
  49   *  Action ajout groupe
  50   */
  51  if ($_POST["action"] == 'add' && $user->admin)
  52  {
  53      $message="";
  54      if (! $_POST["nom"]) {
  55          $message='<div class="error">'.$langs->trans("NameNotDefined").'</div>';
  56          $action="create";       // Go back to create page
  57      }
  58  
  59      if (! $message) {
  60          $editgroup = new UserGroup($db,0);
  61  
  62          $editgroup->nom    = trim($_POST["nom"]);
  63          $editgroup->note   = trim($_POST["note"]);
  64  
  65          $db->begin();
  66  
  67          $id = $editgroup->create();
  68  
  69          if ($id > 0)
  70          {
  71              $db->commit();
  72  
  73              Header("Location: fiche.php?id=".$editgroup->id);
  74          }
  75          else
  76          {
  77              $db->rollback();
  78  
  79              $message='<div class="error">'.$langs->trans("ErrorGroupAlreadyExists",$editgroup->nom).'</div>';
  80              $action="create";       // Go back to create page
  81          }
  82      }
  83  }
  84  
  85  if ($_POST["action"] == 'adduser' && $user->admin)
  86  {
  87      if ($_POST["user"])
  88      {
  89          $edituser = new User($db, $_POST["user"]);
  90          $edituser->SetInGroup($_GET["id"]);
  91  
  92          Header("Location: fiche.php?id=".$_GET["id"]);
  93      }
  94  }
  95  
  96  if ($_GET["action"] == 'removeuser' && $user->admin)
  97  {
  98      if ($_GET["user"])
  99      {
 100          $edituser = new User($db, $_GET["user"]);
 101          $edituser->RemoveFromGroup($_GET["id"]);
 102  
 103          Header("Location: fiche.php?id=".$_GET["id"]);
 104      }
 105  }
 106  
 107  if ($_POST["action"] == 'update' && $user->admin)
 108  {
 109      $message="";
 110  
 111      $db->begin();
 112  
 113      $editgroup = new Usergroup($db, $_GET["id"]);
 114      $editgroup->fetch($_GET["id"]);
 115  
 116      $editgroup->nom           = $_POST["group"];
 117      $editgroup->note          = $_POST["note"];
 118  
 119      $ret=$editgroup->update();
 120  
 121      if ($ret >= 0) {
 122          $message.='<div class="ok">'.$langs->trans("GroupModified").'</div>';
 123          $db->commit();
 124      } else {
 125          $message.='<div class="error">'.$editgroup->error.'</div>';
 126          $db->rollback;
 127      }
 128  
 129  }
 130  
 131  
 132  llxHeader('',$langs->trans("GroupCard"));
 133  
 134  
 135  /* ************************************************************************** */
 136  /*                                                                            */
 137  /* Affichage fiche en mode création                                           */
 138  /*                                                                            */
 139  /* ************************************************************************** */
 140  
 141  if ($action == 'create')
 142  {
 143      print_titre($langs->trans("NewGroup"));
 144      print "<br>";
 145  
 146      if ($message) { print $message."<br>"; }
 147  
 148      print '<form action="fiche.php" method="post">';
 149      print '<input type="hidden" name="action" value="add">';
 150  
 151      print '<table class="border" width="100%">';
 152  
 153      print "<tr>".'<td valign="top">'.$langs->trans("Name").'</td>';
 154      print '<td class="valeur"><input size="30" type="text" name="nom" value=""></td></tr>';
 155  
 156      print "<tr>".'<td valign="top">'.$langs->trans("Note").'</td><td>';
 157      print "<textarea name=\"note\" rows=\"12\" cols=\"40\">";
 158      print "</textarea></td></tr>\n";
 159  
 160      print "<tr>".'<td align="center" colspan="2"><input class="button" value="'.$langs->trans("CreateGroup").'" type="submit"></td></tr>';
 161      print "</table>\n";
 162      print "</form>";
 163  }
 164  
 165  
 166  /* ************************************************************************** */
 167  /*                                                                            */
 168  /* Visu et edition                                                            */
 169  /*                                                                            */
 170  /* ************************************************************************** */
 171  else
 172  {
 173      if ($_GET["id"] )
 174      {
 175          $group = new UserGroup($db);
 176          $group->fetch($_GET["id"]);
 177  
 178          /*
 179           * Affichage onglets
 180           */
 181  
 182          $h = 0;
 183  
 184          $head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$group->id;
 185          $head[$h][1] = $langs->trans("GroupCard");
 186          $hselected=$h;
 187          $h++;
 188  
 189          $head[$h][0] = DOL_URL_ROOT.'/user/group/perms.php?id='.$group->id;
 190          $head[$h][1] = $langs->trans("GroupRights");
 191          $h++;
 192  
 193          dolibarr_fiche_head($head, $hselected, $langs->trans("Group").": ".$group->nom);
 194  
 195  
 196          /*
 197           * Confirmation suppression
 198           */
 199          if ($action == 'delete')
 200          {
 201              $html = new Form($db);
 202              $html->form_confirm("fiche.php?id=$group->id",$langs->trans("DeleteAGroup"),$langs->trans("ConfirmDeleteGroup",$group->name),"confirm_delete");
 203          }
 204  
 205  
 206          /*
 207           * Fiche en mode visu
 208           */
 209  
 210          if ($_GET["action"] != 'edit') {
 211  
 212              print '<table class="border" width="100%">';
 213              print '<tr><td width="25%" valign="top">'.$langs->trans("Name").'</td>';
 214              print '<td width="75%" class="valeur">'.$group->nom.'</td>';
 215              print "</tr>\n";
 216              print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>';
 217              print '<td class="valeur">'.nl2br($group->note).'&nbsp;</td>';
 218              print "</tr>\n";
 219              print "</table>\n";
 220      
 221              print '</div>';
 222      
 223              if ($message) { print $message; }
 224      
 225              /*
 226               * Barre d'actions
 227               *
 228               */
 229              print '<div class="tabsAction">';
 230      
 231              if ($user->admin)
 232              {
 233                  print '<a class="tabAction" href="fiche.php?id='.$group->id.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
 234              }
 235      
 236              if ($user->id <> $_GET["id"] && $user->admin)
 237              {
 238                  print '<a class="butDelete" href="fiche.php?action=delete&amp;id='.$group->id.'">'.$langs->trans("DeleteGroup").'</a>';
 239              }
 240      
 241              print "</div>\n";
 242              print "<br>\n";
 243      
 244      
 245              /*
 246               * Liste des utilisateurs dans le groupe
 247               */
 248      
 249              print_fiche_titre($langs->trans("ListOfUsersInGroup"));
 250              
 251              // On sélectionne les users qui ne sont pas déjà dans le groupe
 252              $uss = array();
 253      
 254              $sql = "SELECT u.rowid, u.login, u.name, u.firstname, u.code, u.admin";
 255              $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
 256              #      $sql .= " LEFT JOIN llx_usergroup_user ug ON u.rowid = ug.fk_user";
 257              #      $sql .= " WHERE ug.fk_usergroup IS NULL";
 258              $sql .= " ORDER BY u.name";
 259      
 260              $result = $db->query($sql);
 261              if ($result)
 262              {
 263                  $num = $db->num_rows($result);
 264                  $i = 0;
 265      
 266                  while ($i < $num)
 267                  {
 268                      $obj = $db->fetch_object($result);
 269      
 270                      $uss[$obj->rowid] = ucfirst(stripslashes($obj->name)).' '.ucfirst(stripslashes($obj->firstname));
 271                      if ($obj->login) $uss[$obj->rowid].=' ('.$obj->login.')';
 272                      $i++;
 273                  }
 274              }
 275              else {
 276                  dolibarr_print_error($db);
 277              }
 278      
 279              if ($user->admin)
 280              {
 281                  $form = new Form($db);
 282                  print '<form action="fiche.php?id='.$group->id.'" method="post">'."\n";
 283                  print '<input type="hidden" name="action" value="adduser">';
 284                  print '<table class="noborder" width="100%">'."\n";
 285                  //      print '<tr class="liste_titre"><td width="25%">'.$langs->trans("NonAffectedUsers").'</td>'."\n";
 286                  print '<tr class="liste_titre"><td width="25%">'.$langs->trans("UsersToAdd").'</td>'."\n";
 287                  print '<td>';
 288                  print $form->select_array("user",$uss);
 289                  print ' &nbsp; ';
 290                  print '<input type="submit" class=button value="'.$langs->trans("Add").'">';
 291                  print '</td></tr>'."\n";
 292                  print '</table></form>'."\n";
 293              }
 294      
 295              /*
 296               * Membres du groupe
 297               */
 298              $sql = "SELECT u.rowid, u.login, u.name, u.firstname, u.code, u.admin";
 299              $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
 300              $sql.= " ".MAIN_DB_PREFIX."usergroup_user as ug";
 301              $sql.= " WHERE ug.fk_user = u.rowid";
 302              $sql.= " AND ug.fk_usergroup = ".$group->id;
 303              $sql.= " ORDER BY u.name";
 304      
 305              $result = $db->query($sql);
 306              if ($result)
 307              {
 308                  $num = $db->num_rows($result);
 309                  $i = 0;
 310      
 311                  print '<br>';
 312      
 313                  print '<table class="noborder" width="100%">';
 314                  print '<tr class="liste_titre">';
 315                  print '<td width="25%">'.$langs->trans("Login").'</td>';
 316                  print '<td width="25%">'.$langs->trans("Lastname").'</td>';
 317                  print '<td width="25%">'.$langs->trans("Firstname").'</td>';
 318                  print '<td>'.$langs->trans("Code").'</td>';
 319                  print "<td>&nbsp;</td></tr>\n";
 320                  if ($num) {
 321                      $var=True;
 322                      while ($i < $num)
 323                      {
 324                          $obj = $db->fetch_object($result);
 325                          $var=!$var;
 326          
 327                          print "<tr $bc[$var]>";
 328                          print '<td>';
 329                          print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowUser"),"user").' '.$obj->login.'</a>';
 330                          if ($obj->admin) print img_picto($langs->trans("Administrator"),'star');
 331                          print '</td>';
 332                          print '<td>'.ucfirst(stripslashes($obj->name)).'</td>';
 333                          print '<td>'.ucfirst(stripslashes($obj->firstname)).'</td>';
 334                          print '<td>'.$obj->code.'</td><td>';
 335          
 336                          if ($user->admin)
 337                          {
 338          
 339                              print '<a href="fiche.php?id='.$group->id.'&amp;action=removeuser&amp;user='.$obj->rowid.'">';
 340                              print img_delete($langs->trans("RemoveFromGroup"));
 341                          }
 342                          else
 343                          {
 344                              print "-";
 345                          }
 346                          print "</td></tr>\n";
 347                          $i++;
 348                      }
 349                  }
 350                  else
 351                  {
 352                      print '<tr><td colspan=2>'.$langs->trans("None").'</td></tr>';    
 353                  }
 354                  print "</table>";
 355                  print "<br>";
 356                  $db->free($result);
 357              }
 358              else {
 359                  dolibarr_print_error($db);
 360              }
 361          }
 362  
 363          /*
 364           * Fiche en mode edition
 365           */
 366          if ($_GET["action"] == 'edit' && $user->admin)
 367          {
 368              print '<form action="fiche.php?id='.$group->id.'" method="post" name="updategroup" enctype="multipart/form-data">';
 369              print '<input type="hidden" name="action" value="update">';
 370  
 371              print '<table class="border" width="100%">';
 372              print '<tr><td width="25%" valign="top">'.$langs->trans("Name").'</td>';
 373              print '<td width="75%" class="valeur"><input size="12" maxlength="8" type="text" name="group" value="'.$group->nom.'"></td>';
 374              print "</tr>\n";
 375              print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>';
 376              print '<td class="valeur"><textarea name="note" rows="12" cols="40">'.nl2br($group->note).'</textarea></td>';
 377              print "</tr>\n";
 378              print '<tr><td align="center" colspan="2"><input value="'.$langs->trans("Save").'" type="submit"></td></tr>';
 379              print "</table>\n";
 380              print "<br>\n";
 381              print '</form>';
 382      
 383              print '</div>';
 384  
 385  
 386          }
 387  
 388      }
 389  }
 390  
 391  $db->close();
 392  
 393  llxFooter("<em>Derni&egrave;re modification $Date: 2005/08/11 18:48:08 $ r&eacute;vision $Revision: 1.16 $</em>");
 394  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics