<?php
  switch($Etape)
  {
    case 0:
      if ($resultat = DefaultRabais::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 "   <select name='CodeRabais'>\n";
        foreach($resultat as $ligne)
        {
          echo "    <option value=" . '"' . htmlspecialchars($ligne['CodeRabais']) . '"' . ">" . htmlspecialchars($ligne['CodeRabais']) . "</option>\n";
        }
        echo "   </select><BR>\n";
        echo "   <button type='submit'>Suite</button>\n";
        echo "  </form>\n";
      }
    break;
    case 1:
      if ($resultat = TypeRabais::getActiveTypeRabais())
      {
        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='2'>\n";
        echo "   <input type='hidden' name='CodeRabais' value=" . '"' . htmlspecialchars($CodeRabais) . '"' . ">\n";
        echo "<table border='1'>\n";
        echo "<tr><th>Code rabais</th><td><input type='text' name='NewCodeRabais' value=" . '"' . htmlspecialchars($CodeRabais) . '"' . "></td></tr>\n";
          if($ligne2 = DefaultRabais::getByCodeRabais(addslashes($CodeRabais)))
          {
            foreach($resultat as $ligne)
            {
              echo "<tr><th>" . $ligne['NoRabais'] . " " . htmlspecialchars($ligne['Description']) . "</th><td>";
              echo "<input type='text' name='Rabais" . $ligne['NoRabais'] . "' value='" . $ligne2['RabaisType'.$ligne['NoRabais']] . "'>";
              echo "</td></tr>\n";
            }
          }
        echo "</table>\n";
        echo "   <button type='submit'>Valider</button>\n";
        echo "  </form>\n";
      }
    break;
    case 2:
      if ($resultat = TypeRabais::getActiveTypeRabais())
      {
        $requette3="UPDATE defaultrabais SET CodeRabais=" . '"' . addslashes($NewCodeRabais) . '"';
        foreach($resultat as $ligne)
        {
          $requette3 .= " , RabaisType" . $ligne['NoRabais'] . '="' . ${"Rabais".$ligne['NoRabais']} . '"';
        }
        $requette3 .= " WHERE CodeRabais=" . '"' . addslashes($CodeRabais) . '"';
        if ($resultat3 = Connection::executeRawQuery($requette3))
        {
        }
      }
    break;
  }
?>
