<?php
  switch($Etape)
  {
    case 0:
      if ($resultat = TypeRabais::getAll())
      {
        echo "  <form>\n";
        echo "   <input type='hidden' name='Type' value=$Type>\n";
        echo "   <input type='hidden' name='Sous_Type' value=$Sous_Type>\n";
        echo "   <input type='hidden' name='Etape' value='1'>\n";
        echo "<table border='1'>\n";
        echo "<tr><th>No</th><th>Description</th><th>Actif</th></tr>\n";
        foreach($resultat as $ligne)
        {
          echo "<tr><td>" . $ligne['NoRabais'] . "</td><td><input type='text' name='Description" . $ligne['NoRabais'] . "' value=" . '"' . htmlspecialchars($ligne['Description']) . '"' . "></td><td><input type='checkbox' name='Actif" . $ligne['NoRabais'] . "' value='1'";
          if ($ligne['Actif']==1)
          {
            echo " CHECKED";
          }
          echo "></td></tr>\n";
        }
        echo "</table>\n";
        echo "   <button type='submit'>Valider</button>\n";
        echo "  </form>\n";
      }
    break;
    case 1:
      for ($cpt=0;$cpt<20;$cpt++)
      {
        $nom_actif = "Actif$cpt";
        $actif=0;
        if (isset(${$nom_actif}))
          if (${$nom_actif}==1)
            $actif=1;
        $desc=addslashes(${"Description" . $cpt});
        $requette="UPDATE typerabais SET Description=" . '"' . $desc . '"' . ", Actif=$actif WHERE NoRabais=$cpt";
        if ($resultat = Connection::executeRawQuery($requette))
        {
        }
      }
    break;
  }
?>
