<?php
  function affiche_sous_categorie($ID,$niveau)
  {
    $resultat=Category::getCategoryByParent($ID);
    foreach($resultat as $ligne)
    {
      for($cpt=0;$cpt<$niveau;$cpt++)
      {
        echo "--";
      }
      echo $ligne["Nom"]." <A HREF='default.php?Type=1&Sous_Type=11&Etape=3&ParentID=".$ligne["ID"]."'>Add sub</A><BR>\n";
      affiche_sous_categorie($ligne["ID"], $niveau + 1);
    }
  }
  switch($Etape)
  {
    case 0:
      echo "<form><input type='hidden' name='Type' value=$Type><input type='hidden' name='Sous_Type' value=$Sous_Type><input type='hidden' name='Etape' value='1'><input type='submit' value='Nouvelle categorie'></form>";
      $requette="SELECT * FROM categories WHERE ParentID IS NULL";
      $resultat=Category::getTopCategories();
      foreach($resultat as $ligne)
      {
        echo $ligne["Nom"]." <A HREF='default.php?Type=1&Sous_Type=11&Etape=3&ParentID=".$ligne["ID"]."'>Add sub</A><BR>\n";
        affiche_sous_categorie($ligne["ID"],1);
      }
    break;
    case 1:
      echo "<form>";
      echo "<input type='hidden' name='Type' value=$Type>";
      echo "<input type='hidden' name='Sous_Type' value=$Sous_Type>";
      echo "<input type='hidden' name='Etape' value='2'>";
      echo "<input type='text' name='Nom'>";
      echo "<input type='text' name='Description'>";
      echo "<input type='text' name='Image'>";
      echo "<input type='submit' value='Valider'>";
      echo "</form>";
    break;
    case 2:
      $requette="INSERT INTO categories (Nom, Description, Image) VALUES ('$Nom', '$Description', '$Image')";
      Connection::executeRawQuery($requette);
    break;
    case 3:
      echo "<form>";
      echo "<input type='hidden' name='Type' value=$Type>";
      echo "<input type='hidden' name='Sous_Type' value=$Sous_Type>";
      echo "<input type='hidden' name='ParentID' value=$ParentID>";
      echo "<input type='hidden' name='Etape' value='4'>";
      echo "Nom<input type='text' name='Nom'><BR>";
      echo "Description<input type='text' name='Description'><BR>";
      echo "Image<input type='text' name='Image'><BR>";
      echo "<input type='submit' value='Valider'>";
      echo "</form>";
    break;
    case 4:
      $requette="INSERT INTO categories (Nom, Description, Image, ParentID) VALUES ('$Nom', '$Description', '$Image', '$ParentID')";
      Connection::executeRawQuery($requette);
    break;
  }
?>
