[ 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/ -> create.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   * $Id: create.php,v 1.2 2005/09/20 20:33:28 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/categories/create.php,v $
  20   */
  21  
  22  require  "./pre.inc.php";
  23  
  24  if (!$user->rights->categorie->creer) accessforbidden();
  25  
  26  if (isset ($_REQUEST['choix']))
  27  {
  28    $nbcats = $_REQUEST['choix'];
  29  }
  30  else
  31  { // par défault, une nouvelle catégorie sera dans une seule catégorie mère
  32    $nbcats = 1;
  33  }
  34  
  35  llxHeader("","",$langs->trans("Categories"));
  36  
  37  print_titre($langs->trans("CreateCat"));
  38  
  39  print '<table border="0" width="100%">';
  40  
  41  print '<tr><td valign="top" width="30%">';
  42  ?>
  43  <form method="post" action="<?php print $_SERVER['REQUEST_URI']; ?>">
  44      <table class="border">
  45          <tr>
  46              <td><?php print $langs->trans ("Label"); ?>&nbsp;:</td>
  47  
  48              <td><input type='text' size='25' id='nom' name ='nom' value='<?php 
  49                      print htmlspecialchars (stripslashes ($_REQUEST['nom']), ENT_QUOTES); 
  50                  ?>' />
  51          </tr>
  52          <tr>
  53              <td><?php print $langs->trans ("Description"); ?>&nbsp;:</td>
  54              
  55              <td><textarea name='description' cols='40' rows='6' id='description'><?php
  56                      print htmlspecialchars (stripslashes ($_REQUEST['description']), ENT_QUOTES); 
  57              ?></textarea></td>
  58              
  59          </tr>
  60          <tr>
  61              <td><?php print $langs->trans ("In"); ?> <select name="choix">
  62                      <?php
  63                      // création d'un objet de type catégorie pour faire des requêtes sur la table
  64                      $c = new Categorie ($db);
  65                      
  66                      $nb = $c->get_nb_categories ();
  67                      
  68                      for ($i = 0 ; $i <= $nb ; $i++)
  69                          {
  70                          echo "<option value='$i' ";//creation d'une valeur dans la liste
  71                              
  72                          if ($_REQUEST['choix'] == $i)
  73                                  echo 'selected="true"'; // permet de rendre le choix toujours selectionne
  74                          else if (!isset ($_REQUEST['choix']) && $i == $nbcats) // nombre de catégories mères par défaut.
  75                                  echo 'selected="true"';
  76  
  77                          echo ">$i</option>";
  78                          }
  79                      ?>
  80                  </select> <?php print $langs->trans ("categories"); ?>
  81              </td>
  82              <td>
  83                  <input type="submit" value="<?php print $langs->trans ("modify"); ?>" name="ok" id="ok" />
  84              </td>
  85              <?php
  86                  $cats = $c->get_all_categories ();//on récupère toutes les catégories et leurs attributs
  87  
  88                  for ($i = 0; $i < $nbcats ; $i++)
  89                      {
  90                      echo "<tr><td>".$langs->trans ("Categorie")." ".($i+1)."</td><td><select name='catsMeres[".$i."]'>"; //creation des categories meres
  91                      
  92                      echo "<option value='-1' id='choix'>".$langs->trans ("Choose")."</option>\n";
  93  
  94                      foreach ($cats as $id => $cat)
  95                          { //ajout des categories dans la liste
  96                          echo "<option value='$id' id='$id'";
  97                          
  98                          if ($_REQUEST['catsMeres'][$i] == $id)
  99                              echo ' selected="true"';
 100                          
 101                          echo ">".$cat->label."</option>\n";
 102                          }
 103                  
 104                      echo "</select></td></tr>";
 105                      }
 106                  ?>
 107          <tr>
 108              <td colspan="2"><input type='submit' value='<?php print $langs->trans ("CreateThisCat"); ?>' id="creation" name="creation"/></td>
 109          </tr>
 110          </form>
 111                  
 112              <?php
 113              if (isset ($_REQUEST['creation']))
 114                  {    
 115                  // doit être à true pour valider la saisie de l'utilisateur
 116                  $OK = true;
 117  
 118                  $cats_meres = isset ($_REQUEST['catsMeres']) ? $_REQUEST['catsMeres'] : array ();
 119                  
 120                  if (sizeof ($cats_meres) > 1 && sizeof (array_unique ($cats_meres)) != sizeof ($cats_meres))
 121                      { // alors il y a des valeurs en double
 122                      echo "<p>".$langs->trans ("ErrSameCatSelected")."</p>";
 123                      $OK = false;
 124                      }
 125  
 126                  // vérification des champs renseignés par l'utilisateur: si il y a un problème, on affiche un message d'erreur
 127                  foreach ($cats_meres as $nb => $cat_mere)
 128                      {
 129                      if ($cat_mere == -1)
 130                          {
 131                          echo "<p>".$langs->trans ("ErrForgotCat")." ".($nb+1)."</p>";
 132                          $OK = false;
 133                          }
 134                      }
 135                      
 136                  // si les champs de description sont mal renseignés
 137                  if ($_POST["nom"] == '')
 138                      {
 139                      echo "<p>".$langs->trans ("ErrForgotField")." \"".$langs->trans ("Label")."\"</p>";
 140                      $OK = false;
 141                      }
 142                  else if ($c->already_exists ($_POST["nom"]))
 143                      {
 144                      // on regarde si le champ nom n'est pas déjà dans la table catégorie (rappel: un nom est unique dans la table catégorie
 145                      // nb a déjà été renseigné, il contient le nombre de catégories
 146                      echo "<p>".$langs->trans ("ErrCatAlreadyExists")."</p>";
 147                      $OK = false;
 148                      }
 149  
 150                  if ($_POST["description"] == '')
 151                      {
 152                      echo "<p>".$langs->trans ("ErrForgotField")." \"".$langs->trans ("Description")."\"</p>";
 153                      $OK = false;
 154                      }
 155                      
 156                  // vérification pour savoir si tous les champs sont corrects
 157                  if ($OK)
 158                      {
 159                      $nom         = htmlspecialchars(stripslashes($_REQUEST['nom'])        ,ENT_QUOTES);
 160                      $description = htmlspecialchars(stripslashes($_REQUEST['description']),ENT_QUOTES);
 161                      // creation de champs caches pour etre appele dans la classe de traitement
 162                      ?>
 163                      <table class="noborder"><tr><td>
 164                      <form method="post" action="docreate.php">
 165                          <p><?php print $langs->trans ("ValidateFields"); ?>&nbsp;?
 166                          <input type='submit' value='<?php print $langs->trans ("Valid"); ?>'/>
 167                          <input type='hidden' name='nom'         value="<?php print $nom;         ?>">
 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></p>
 177                      </td></tr></table>
 178                      <?php
 179                      }
 180                  }
 181  
 182  print '</td></tr></table>';
 183  
 184  $db->close();
 185  
 186  llxFooter("<em>Derni&egrave;re modification $Date: 2005/09/20 20:33:28 $ r&eacute;vision $Revision: 1.2 $</em>");
 187  ?>


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