[ 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/categories/ -> edit.php (source)

   1  <?php
   2  /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   */
  18  
  19  require  "./pre.inc.php";
  20  
  21  
  22  if (false && (!isset ($_REQUEST['id']) || !$user->rights->categories->lire))
  23    accessforbidden();
  24  // toujours pas trouvé comment mettre les droits qui vont bien
  25  
  26  llxHeader("","",$langs->trans("Categories"));
  27  
  28  print_titre($langs->trans("ModifCat"));
  29  
  30  print '<table border="0" width="100%">';
  31  
  32  print '<tr><td valign="top" width="30%">';
  33  
  34  
  35  $c = new Categorie ($db, $_REQUEST['id']);
  36  
  37  if (isset ($_REQUEST['cats_meres']))
  38  {
  39    $cats_meres = $_REQUEST['cats_meres'];
  40  }
  41  else
  42  {
  43    $cats_meres = array ();
  44    foreach ($c->get_meres () as $mere)
  45      {
  46        $cats_meres[] = $mere->id;
  47      }
  48  }
  49  $label       = isset ($_REQUEST['nom'])         ? $_REQUEST['nom']         : $c->label;
  50  $description = isset ($_REQUEST['description']) ? $_REQUEST['description'] : $c->description;
  51  $nbcats      = isset ($_REQUEST['choix'])       ? $_REQUEST['choix']       : sizeof ($cats_meres);
  52  
  53  print '<tr><td valign="top" width="30%">';
  54  ?>
  55  <form method="post" action="<?php print $_SERVER['REQUEST_URI']; ?>">
  56  <table class="border">
  57      <tr>
  58          <td><?php print $langs->trans("Label"); ?>&nbsp;:</td>
  59  
  60          <td><input type='text' size='25' id='nom' name ='nom' value='<?php 
  61                  print htmlspecialchars (stripslashes ($label), ENT_QUOTES); 
  62              ?>' />
  63      </tr>
  64      <tr>
  65          <td><?php print $langs->trans("Description"); ?>&nbsp;:</td>
  66          
  67          <td><textarea name='description' cols='40' rows='6' id='description'><?php
  68                  print htmlspecialchars (stripslashes ($description), ENT_QUOTES); 
  69          ?></textarea></td>
  70          
  71      </tr>
  72      
  73      <tr>
  74          <td>
  75              <?php print $langs->trans("In"); ?>
  76              <select name="choix">
  77                  <?php
  78                  // création d'un objet de type catégorie pour faire des requêtes sur la table
  79                  $c = new Categorie ($db);
  80                  
  81                  $nb = $c->get_nb_categories ();
  82                  
  83                  for ($i = 0 ; $i <= $nb ; $i++)
  84                      {
  85                      echo "<option value='$i' ";//creation d'une valeur dans la liste
  86                          
  87                      if ($i == $nbcats)
  88                              echo 'selected="true"'; // permet de rendre le choix toujours selectionne
  89  
  90                      echo ">$i</option>";
  91                      }
  92                  ?>
  93              </select>
  94              <?php print $langs->trans("categories"); ?>
  95          </td>
  96          <td>
  97              <input type="submit" value="<?php print $langs->trans ("modify"); ?>" name="ok" id="ok" />
  98          </td>
  99      </tr>
 100      <?php
 101      $cats = $c->get_all_categories ();//on récupère toutes les catégories et leurs attributs
 102  
 103      for ($i = 0 ; $i < $nbcats ; $i++)
 104          {
 105          print "<tr><td>";
 106          print $langs->trans("Categorie")." ".($i+1)."</td><td><select name='cats_meres[".$i."]'>"; //creation des categories meres
 107          
 108          echo "<option value='-1' id='choix'>".$langs->trans ("Choose")."</option>\n";
 109  
 110          foreach ($cats as $id => $cat)
 111              { //ajout des categories dans la liste
 112              echo "<option value='$id' id='$id'";
 113              
 114              if ($cats_meres[$i] == $id)
 115                  echo ' selected="true"';
 116              
 117              echo ">".$cat->label."</option>\n";
 118              }
 119      
 120          echo "</select></td></tr>\n";
 121          }
 122  
 123          ?>
 124      <tr>
 125          <td colspan="2" align="center"><input type='submit' value='<?php print $langs->trans ("Modify"); ?>' id="modif" name="modif"/></td>
 126      </tr>
 127  </table>
 128  </form>
 129          
 130      <?php
 131      if (isset ($_REQUEST['modif']))
 132          {    
 133          // doit être à true pour valider la saisie de l'utilisateur
 134          $OK = true;
 135  
 136          if (sizeof ($cats_meres) > 1 && sizeof (array_unique ($cats_meres)) != sizeof ($cats_meres))
 137              { // alors il y a des valeurs en double
 138              echo "<p>".$langs->trans ("ErrSameCatSelected")."</p>";
 139              $OK = false;
 140              }
 141  
 142          // vérification des champs renseignés par l'utilisateur: si il y a un problème, on affiche un message d'erreur
 143          if (sizeof ($cats_meres) > 0) foreach ($cats_meres as $nb => $cat_mere)
 144              {
 145              if ($cat_mere == -1)
 146                  {
 147                  echo "<p>".$langs->trans ("ErrForgotCat")."</p>";
 148                  $OK = false;
 149                  }
 150              }
 151              
 152          // si les champs de description sont mal renseignés
 153          if ($label == '')
 154              {
 155              echo "<p>".$langs->trans ("ErrForgotField")."</p>";
 156              $OK = false;
 157              }
 158              
 159          // vérification pour savoir si tous les champs sont corrects
 160          if ($OK)
 161              {
 162              // creation de champs caches pour etre appele dans la classe de traitement
 163              ?>
 164              <form method="post" action="domodif.php">
 165                  <p><?php print $langs->trans("ValidateFields"); ?> ? <input type='submit' value='<?php print $langs->trans("Valid"); ?>'/></p>
 166                  <input type='hidden' name='id'          value="<?php print $_REQUEST['id']; ?>">
 167                  <input type='hidden' name='nom'         value="<?php print $label;          ?>">
 168                  <input type='hidden' name='description' value="<?php print $description;    ?>">
 169  
 170                  <?php
 171                  foreach ($cats_meres as $id => $cat_mere)
 172                      {
 173                      echo "<input type='hidden' name='cats_meres[$id]' value='$cat_mere'>";
 174                      }
 175                  ?>
 176              </form>
 177              <?php
 178              }
 179          }
 180  
 181  
 182  print '</td></tr></table>';
 183  
 184  $db->close();
 185  ?>


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