<?php
  function Affiche_formulaire_setup($No_Formulaire,$NoVisu)
  {
    global $Type, $Sous_Type;
    $tab_description=Create_Table_Champs($No_Formulaire,$nb_champs);
    Affiche_No_Visu($No_Formulaire,VISU_SETUP);
    if ($resultat2 = Formulaire::getFormulaireByNoFormulaireNoDivisionNoVisu($No_Formulaire, 1, $NoVisu))
    {
      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='NoVisu' value=$NoVisu>\n";
      echo "   <input type='hidden' name='Etape' value='1'>\n";
      for($cpt=0;$cpt<30;$cpt++)
      {
        echo "   <select  name='champ$cpt'>\n";
        if($ligne2 = $resultat2[0])
        {
          if ($ligne2['NoChamp']==255)
          {
            echo "    <option value='255' selected>" . $tab_description[255][0] . "</option>\n";
          }
          else
          {
            echo "    <option value='255'>" . $tab_description[255][0] . "</option>\n";
          }
          for($cpt2=0;$cpt2<$nb_champs+1;$cpt2++)
          {
            if ($ligne2['NoChamp']==$tab_description[$cpt2][4])
            {
              echo "    <option value='" . $tab_description[$cpt2][4] . "' selected>" . $tab_description[$cpt2][0] . "</option>\n";
            }
            else
            {
              echo "    <option value='" . $tab_description[$cpt2][4] . "'>" . $tab_description[$cpt2][0] . "</option>\n";
            }
          }
        }
        else
        {
          if ($ligne2['NoChamp']==255)
          {
            echo "    <option value='255' selected>" . $tab_description[255][0] . "</option>\n";
          }
          else
          {
            echo "    <option value='255'>" . $tab_description[255][0] . "</option>\n";
          }
          echo "    <option value='0' selected>" . $tab_description[0][0] . "</option>\n";
          for($cpt2=1;$cpt2<$nb_champs+1;$cpt2++)
          {
            echo "    <option value='$cpt2'>" . $tab_description[$cpt2][0] . "</option>\n";
          }
        }
        echo "   </select><br>\n";
      }
      echo "   <button type='submit'>Suite</button>\n";
      echo "  </form>\n";
    }
  }
  
  function Valide_Modif_setup1($No_Formulaire,$NoVisu)
  {
    global $Type, $Sous_Type;
    $tab_description=Create_Table_Champs($No_Formulaire,$nb_champs);
    $nb_champs=0;
    $free=0;
    $err=0;
    $requette_insert = "INSERT INTO formulaire (NoFormulaire, NoDivision, NoVisu, Position, NoChamp) VALUES ";
    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='NoVisu' value=$NoVisu>\n";
    echo "   <input type='hidden' name='Etape' value='2'>\n";
    echo "<TABLE border=1>\n";
    echo "<TR><TD>Champ</TD><TD>Valeur par default</TD></TR>\n";
    $liste = array();
    for($cpt=0;$cpt<30;$cpt++)
    {
      $nom_var = "champ$cpt";
      $tmp_var = $GLOBALS[$nom_var];
	  //echo $tmp_var."<br/>";
      if($tmp_var!=0)
      {
        if(in_array($tmp_var,$liste) && $tmp_var != 255)
        {
          $err++;
        }
        else
        {
          array_push($liste,$tmp_var);
          echo " <TR>";
          echo "<TH>" . $tab_description[$tmp_var][0] . "</TH>";
          if($free==0)
          {
            $free=1;
          }
          else
          {
            $requette_insert .= ",";
          }
          $nb_champs++;
          $requette_insert .= "($No_Formulaire,1,$NoVisu,$nb_champs,$tmp_var)";
            if($ligne2 = Formulaire::getFormulaireByNoFormulaireNoDivisionNoVisuNoChamp($No_Formulaire, 1, $NoVisu, $tmp_var))
            {
              echo "<TD>";
              echo Cree_Entree_Type("default$nb_champs",$tab_description[$tmp_var][2],$tab_description[$tmp_var][3],$ligne2['ValeurDefault'],MODIFICATION);
              echo "&nbsp</TD>";
            }
            else
            {
              echo "<TD>";
              echo Cree_Entree_Type("default$nb_champs",$tab_description[$tmp_var][2],$tab_description[$tmp_var][3],"",MODIFICATION);
              echo "&nbsp</TD>";
            }
          echo "</TR>\n";
        }
      }
    }
    echo "</TABLE>\n";
    echo "   <button type='submit'>Terminer</button>\n";
    echo "  </form>\n";
    if ($resultat_delete = Connection::executeRawQuery("DELETE FROM formulaire WHERE NoFormulaire=$No_Formulaire AND NoDivision=1 AND NoVisu=$NoVisu"))
      if ($resultat_insert = Connection::executeRawQuery($requette_insert))
        echo "OK<BR>\n";
  }
  
  function Valide_Modif_setup2($No_Formulaire,$NoVisu)
  {
    $tab_description=Create_Table_Champs($No_Formulaire,$nb_champs);
    for($cpt=1;$cpt<31;$cpt++)
    {
        if($ligne2 = Formulaire::getFormulaireByNoFormulaireNoDivisionNoVisuPosition($No_Formulaire, 1, $NoVisu, $cpt))
        {
          $nom_var = "default$cpt";
          if(isset($GLOBALS[$nom_var]))
            ${$nom_var}=$GLOBALS[$nom_var];
          if(isset(${$nom_var})==TRUE)
          {
            if(!empty(${$nom_var}))
            {
              $data = Decode_Entree_Type(${$nom_var},$tab_description[$ligne2['NoChamp']][2]);
              $requette3 = "UPDATE formulaire SET ValeurDefault='$data' WHERE NoFormulaire=$No_Formulaire AND NoDivision=1 AND NoVisu=$NoVisu AND Position=$cpt";
              if ($resultat3 = Connection::executeRawQuery($requette3))
              {
              }
              else
              {
                echo "!erreur!";
              }
            }
          }
        }
    }
  }
  
  function Affiche_formulaire_type_setup($NoFormulaire)
  {
    global $Type, $Sous_Type;
    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=NoVisu>\n";
    $resultat=Division::getDivisionByNoFormulaireAndGratherNoVisu($NoFormulaire);
    foreach($resultat as $ligne)
    {
      echo "<option value='".$ligne["NoVisu"]."'>".$ligne["NomVisu"] . "</option>\n";
    }
    echo "</SELECT>\n";
    echo "<button type='submit'>Supprimer</button>\n";
    echo "</form>\n";
    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 "<SELECT name=NoVisu>\n";
    $resultat=Division::getDivisionByNoFormulaire($NoFormulaire);
    foreach($resultat as $ligne)
    {
      echo "<option value='".$ligne["NoVisu"]."'>".$ligne["NomVisu"] . "</option>\n";
    }
    echo "</SELECT>\n";
    echo "<button type='submit'>Modifier</button>\n";
    echo "</form>\n";
    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='4'>\n";
    echo "<button type='submit'>Nouveau</button>\n";
    echo "</form>\n";
  }
 
  function Supprime_formulaire_type($NoFormulaire,$NoVisu)
  {
    $requette="DELETE FROM division WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
    $requette="DELETE FROM formulaire WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
  }
  
  function Modifie_formulaire_type1($NoFormulaire,$NoVisu)
  {
    global $Type, $Sous_Type;
    $requette="SELECT * FROM division WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Division::getDivisionByNoFormulaireAndNoVisu($NoFormulaire, $NoVisu);
    $ligne=$resultat[0];
    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='3'>\n";
    echo "<input type='hidden' name='NoVisu' value='$NoVisu'>\n";
    echo "$NoVisu<input type='text' name='NomVisu' value='".$ligne["NomVisu"]."'>\n";
    echo "<button type='submit'>Valider</button>\n";
    echo "</form>\n";
  }
  
  function Modifie_formulaire_type2($NoFormulaire,$NoVisu,$NomVisu)
  {
    $requette="UPDATE division SET NomVisu='".addslashes($NomVisu)."' WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
  }
  
  function Cree_formulaire_type1($NoFormulaire)
  {
    global $Type, $Sous_Type;
    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='5'>\n";
    $requette="SELECT * FROM division WHERE NoFormulaire=1 ORDER BY NoVisu";
    $resultat=Division::getDivisionByNoFormulaire(1);
    $NoVisu=1;
    foreach($resultat as $ligne)
    {
      if($NoVisu==$ligne["NoVisu"])
      {
        $NoVisu+=1;
      }
    }
    echo "<input type='hidden' name='NoVisu' value='$NoVisu'>\n";
    echo "$NoVisu<input type='text' name='NomVisu' value='".$ligne["NomVisu"]."'>\n";
    echo "<button type='submit'>Valider</button>\n";
    echo "</form>\n";
  }
  
  function Cree_formulaire_type2($NoFormulaire,$NoVisu,$NomVisu)
  {
    $requette= "INSERT INTO division (NoFormulaire,NoDivision,NoVisu,NoTable,Description,NomVisu) VALUES ($NoFormulaire,1,$NoVisu,$NoFormulaire,'Articles','".addslashes($NomVisu)."')";
    $resultat=Connection::executeRawQuery($requette);
  }
  
  function Affiche_recherche_setup($No_Formulaire,$NoVisu)
  {
    global $Type, $Sous_Type;
    $tab_description=Create_Table_Champs($No_Formulaire,$nb_champs);
    Affiche_No_Visu_recherche($No_Formulaire,VISU_SETUP);
    if ($resultat2 = Recherche::getRechercheByNoRechercheAndNoVisu($No_Formulaire, $NoVisu))
    {
      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='NoVisu' value=$NoVisu>\n";
      echo "   <input type='hidden' name='Etape' value='1'>\n";
      for($cpt=0;$cpt<20;$cpt++)
      {
        echo "   <select  name='champ$cpt'>\n";
        if($ligne2 = $resultat2[0] )
        {
          for($cpt2=0;$cpt2<$nb_champs+1;$cpt2++)
          {
            if ($ligne2['NoChamp']==$cpt2)
            {
              echo "    <option value='$cpt2' selected>" . $tab_description[$cpt2][0] . "</option>\n";
            }
            else
            {
              echo "    <option value='$cpt2'>" . $tab_description[$cpt2][0] . "</option>\n";
            }
          }
        }
        else
        {
          echo "    <option value='0' selected>" . $tab_description[0][0] . "</option>\n";
          for($cpt2=1;$cpt2<$nb_champs+1;$cpt2++)
          {
            echo "    <option value='$cpt2'>" . $tab_description[$cpt2][0] . "</option>\n";
          }
        }
        echo "   </select><br>\n";
      }
      echo "   <button type='submit'>Suite</button>\n";
      echo "  </form>\n";
    }
  }
  
  function Valide_Modif_Recherche_setup1($No_Formulaire,$NoVisu)
  {
    global $Type, $Sous_Type;
    $tab_description=Create_Table_Champs($No_Formulaire,$nb_champs);
    $nb_champs=0;
    $free=0;
    $requette_insert = "INSERT INTO recherche (NoRecherche, NoVisu, Position, NoChamp) VALUES ";
    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='NoVisu' value=$NoVisu>\n";
    echo "   <input type='hidden' name='Etape' value='2'>\n";
    echo "<TABLE border=1>\n";
    echo "<TR><TD>Champ</TD><TD>Valeur par default</TD></TR>\n";
    for($cpt=0;$cpt<20;$cpt++)
    {
      $nom_var = "champ$cpt";
      $tmp_var = $GLOBALS[$nom_var];
      if($tmp_var!=0)
      {
        echo " <TR>";
        echo "<TH>" . $tab_description[$tmp_var][0] . "</TH>";
        if($free==0)
        {
          $free=1;
        }
        else
        {
          $requette_insert .= ",";
        }
        $nb_champs++;
        $requette_insert .= "($No_Formulaire,$NoVisu,$nb_champs,$tmp_var)";
          echo "<TD>";
          if($ligne2 = Recherche::getRechercheByNoRechercheAndNoVisuAndNoChamp( $No_Formulaire, $NoVisu, $tmp_var))
          {
            echo Cree_Entree_Type("default$nb_champs",$tab_description[$tmp_var][2],$tab_description[$tmp_var][3],$ligne2['ValeurDefault'],RECHERCHE);
          }
          else
          {
            echo Cree_Entree_Type("default$nb_champs",$tab_description[$tmp_var][2],$tab_description[$tmp_var][3],"",RECHERCHE);
          }
          echo "&nbsp</TD>";
        echo "</TR>\n";
      }
    }
    echo "</TABLE>\n";
    echo "   <button type='submit'>Suite</button>\n";
    echo "  </form>\n";
    if ($resultat_delete = Connection::executeRawQuery("DELETE FROM recherche WHERE NoRecherche=$No_Formulaire AND NoVisu=$NoVisu"))
      if ($resultat_insert = Connection::executeRawQuery($requette_insert))
        echo "OK<BR>\n";
  }
  
  function Valide_Modif_Recherche_setup2($No_Formulaire,$NoVisu)
  {
    $tab_description=Create_Table_Champs($No_Formulaire,$nb_champs);
    for($cpt=1;$cpt<21;$cpt++)
    {
      $requette2 = "SELECT * FROM recherche WHERE NoRecherche=$No_Formulaire AND NoVisu=$NoVisu AND Position=$cpt";
        if($ligne2 = Recherche::getRechercheByNoRechercheAndNoVisuAndPosition($No_Formulaire,$NoVisu, $cpt))
        {
          $nom_var = "default$cpt";
          if(isset($GLOBALS[$nom_var]))
            ${$nom_var}=$GLOBALS[$nom_var];
          if(isset(${$nom_var})==TRUE)
          {
            if(!empty(${$nom_var}))
            {
              $data = Decode_Recherche_Type(${$nom_var},$tab_description[$ligne2['NoChamp']][2]);
              $requette3 = "UPDATE recherche SET ValeurDefault='$data' WHERE NoRecherche=$No_Formulaire AND NoVisu=$NoVisu AND Position=$cpt";
              echo $requette3 . "<BR>\n";
              if ($resultat3 = Connection::executeRawQuery($requette3))
              {
              }
              else
              {
                echo "!erreur!";
              }
            }
          }
        }
    }
  }
  
  function Affiche_recherche_type_setup($NoFormulaire)
  {
    global $Type, $Sous_Type;
    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=NoVisu>\n";
    $resultat=DivisionRecherche::getDivisionRechercheByNoFormulaireAndNoVisuBigger0($NoFormulaire);
    foreach($resultat as $ligne)
    {
      echo "<option value='".$ligne["NoVisu"]."'>".$ligne["NomVisu"] . "</option>\n";
    }
    echo "</SELECT>\n";
    echo "<button type='submit'>Supprimer</button>\n";
    echo "</form>\n";
    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 "<SELECT name=NoVisu>\n";
    $resultat=DivisionRecherche::getDivisionRechercheByNoFormulaire($NoFormulaire);
    foreach($resultat as $ligne)
    {
      echo "<option value='".$ligne["NoVisu"]."'>".$ligne["NomVisu"] . "</option>\n";
    }
    echo "</SELECT>\n";
    echo "<button type='submit'>Modifier</button>\n";
    echo "</form>\n";
    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='4'>\n";
    echo "<button type='submit'>Nouveau</button>\n";
    echo "</form>\n";
  }
  
  function Supprime_recherche_type($NoFormulaire,$NoVisu)
  {
    $requette="DELETE FROM divisionrecherche WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
    $requette="DELETE FROM recherche WHERE NoRecherche=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
    $requette="DELETE FROM tabledata WHERE NoTable=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
  }
  
  function Modifie_recherche_type1($NoFormulaire,$NoVisu)
  {
    global $Type, $Sous_Type;
    $requette="SELECT * FROM divisionrecherche WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=DivisionRecherche::getDivisionRechercheByNoFormulaireAndNoVisu($NoFormulaire, $NoVisu);
    $ligne=$resultat[0];
    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='3'>\n";
    echo "<input type='hidden' name='NoVisu' value='$NoVisu'>\n";
    echo "$NoVisu<input type='text' name='NomVisu' value='".$ligne["NomVisu"]."'>\n";
    echo "<button type='submit'>Valider</button>\n";
    echo "</form>\n";
  }
 
  function Modifie_recherche_type2($NoFormulaire,$NoVisu,$NomVisu)
  {
    $requette="UPDATE divisionrecherche SET NomVisu='".addslashes($NomVisu)."' WHERE NoFormulaire=$NoFormulaire AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
  }
  
  function Cree_recherche_type1($NoFormulaire)
  {
    global $Type, $Sous_Type;
    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='5'>\n";
    $resultat=DivisionRecherche::getDivisionRechercheByNoFormulaire( $NoFormulaire);
    $NoVisu=1;
    foreach($resultat as $ligne)
    {
      if($NoVisu==$ligne["NoVisu"])
      {
        $NoVisu+=1;
      }
    }
    echo "<input type='hidden' name='NoVisu' value='$NoVisu'>\n";
    echo "$NoVisu<input type='text' name='NomVisu' value='".$ligne["NomVisu"]."'>\n";
    echo "<button type='submit'>Valider</button>\n";
    echo "</form>\n";
  }
 
  function Cree_recherche_type2($NoFormulaire,$NoVisu,$NomVisu)
  {
    $requette= "INSERT INTO divisionrecherche (NoFormulaire,NoDivision,NoVisu,NoTable,Description,NomVisu) VALUES (1,1,$NoVisu,1,'Articles','".addslashes($NomVisu)."')";
    $resultat=Connection::executeRawQuery($requette);
    $requette= "INSERT INTO tabledata (NoTable,NoVisu,Description,NomTable,ChampCle) VALUES (1,$NoVisu,'Articles','articles','NoArticle')";
    $resultat=Connection::executeRawQuery($requette);
  }

  function Create_Setup_Recherche_Article($mode)
  {
    global $Type,$Sous_Type;
    $resultat=DivisionRecherche::getDivisionRechercheByNoFormulaire($mode);
    echo "<TABLE border=1>";
    foreach($resultat as $ligne)
    {
      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 "<input type='hidden' name='NoVisu' value='".$ligne['NoVisu']."'>\n";
      echo "<TR><TD colspan=2><big>" . $ligne['NoVisu'] . " " . $ligne['NomVisu'] . "</big></TD></TR>";
      $ligne2=TableData::getTableDataByNoRechercheAndNoVisu($mode, $ligne['NoVisu']);
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Tri1</TH><TD><SELECT name=Tri1>";
      echo "<option value=''";
      if(strlen(separevirgule($ligne2['ChampsTri'],0))==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if(separevirgule($ligne2['ChampsTri'],0)==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Tri2</TH><TD><SELECT name=Tri2>";
      echo "<option value=''";
      if(strlen(separevirgule($ligne2['ChampsTri'],1))==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if(separevirgule($ligne2['ChampsTri'],1)==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Tri3</TH><TD><SELECT name=Tri3>";
      echo "<option value=''";
      if(strlen(separevirgule($ligne2['ChampsTri'],2))==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if(separevirgule($ligne2['ChampsTri'],2)==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Affichage1</TH><TD><SELECT name=Affichage1>";
      echo "<option value=''";
      if(strlen($ligne2['Affichage1'])==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if($ligne2['Affichage1']==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Affichage2</TH><TD><SELECT name=Affichage2>";
      echo "<option value=''";
      if(strlen($ligne2['Affichage2'])==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if($ligne2['Affichage2']==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Affichage3</TH><TD><SELECT name=Affichage3>";
      echo "<option value=''";
      if(strlen($ligne2['Affichage3'])==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if($ligne2['Affichage3']==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Affichage4</TH><TD><SELECT name=Affichage4>";
      echo "<option value=''";
      if(strlen($ligne2['Affichage4'])==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if($ligne2['Affichage4']==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Affichage5</TH><TD><SELECT name=Affichage5>";
      echo "<option value=''";
      if(strlen($ligne2['Affichage5'])==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if($ligne2['Affichage5']==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      $resultat3=Champ::getChampsByNoTable($mode);
      echo "<TR><TH>Affichage6</TH><TD><SELECT name=Affichage6>";
      echo "<option value=''";
      if(strlen($ligne2['Affichage6'])==0)
      {
        echo " selected";
      }
      echo ">-</option>";
      foreach($resultat3 as $ligne3)
      {
        echo "<option value='".$ligne3['NomChamp']."'";
        if($ligne2['Affichage6']==$ligne3['NomChamp'])
        {
          echo " selected";
        }
        echo ">".$ligne3['Description']."</option>";
      }
      echo "</SELECT></TD></TR>";
      echo "<TR><TD colspan=2 align='center'><button type='submit'>Valider</button></TD></TR>\n";
      echo "</form>\n";
    }
    echo "</TABLE>";
  }
  
  function Valide_Setup_Recherche_Article($mode)
  {
    global $Type,$Sous_Type,$NoVisu,$Tri1,$Tri2,$Tri3,$Affichage1,$Affichage2,$Affichage3,$Affichage4,$Affichage5,$Affichage6;
    $Tri="";
    if(!empty($Tri1))
    {
      $Tri=$Tri1;
      if(!empty($Tri2))
      {
        $Tri.= ", ".$Tri2;
        if(!empty($Tri3))
        {
          $Tri.= ", ".$Tri3;
        }
      }
    }
    $requette="UPDATE tabledata SET ChampsTri='$Tri', Affichage1='$Affichage1', Affichage2='$Affichage2', Affichage3='$Affichage3', Affichage4='$Affichage4', Affichage5='$Affichage5', Affichage6='$Affichage6' WHERE NoTable=$mode AND NoVisu=$NoVisu";
    $resultat=Connection::executeRawQuery($requette);
  }

?>