Location: PHPKode > scripts > TAF > taf/html/insert.php
<!DOCTYPE HTML PUBLIC "-//SQ//DTD HTML 2.0 HoTMetaL + extensions//EN">
<HTML>
<HEAD>
<TITLE>Taches - inserer</TITLE></HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" BACKGROUND="/13a.jpg">
<? include "$DOCUMENT_ROOT/page-header.shtml" ?>
<? include "$DOCUMENT_ROOT/section-header.shtml" ?>

<?
  echo "<H1 ALIGN=center>T&acirc;ches pour $REMOTE_USER</H1>";
?>

<h2>Saisissez votre t&acirc;che</h2>

<?
  /*
   * On se connecte à la base, et on ne joue que si ça marche
   */
  $conn = pg_connect("dbname=tafdb");
  if (!$conn)
  {
     echo "<h2>Une erreur est survenue</h2>";
     echo "<p>Acc&egrave;s &agrave; la base impossible.</p>";
     echo " retour &agrave; l'<a href='./'>accueil</a>";
     echo "<HR WIDTH='50%'>\n";
     include "$DOCUMENT_ROOT/section-footer.shtml";
     include "$DOCUMENT_ROOT/page-footer.shtml";
     echo "</BODY></HTML>";
     exit;
  }
  /*
   * Les requêtes SQL qui vont bien ...
   */
  $sql="SET DateStyle TO 'European';";
  pg_Exec($sql);

?>

<?
  $update=$id;

  if ($insert == "")
  {
    /*
     * On peut utiliser la présence de la variable id, pour faire une modif ...
     */
    if ($update == "")
    {
      echo "<p>Remplissez les champs suivants pour ins&eacute;rer";
      echo " un nouvel &eacute;l&eacute;ment dans la base.\n";
    }
    else
    {
      echo "<p>Modifiez les champs suivants pour mettre &agrave; jour";
      echo " l'&eacute;l&eacute;ment dans la base.\n";

      /*
       * La, on en profite pour lire l'enregistrement...
       */
       $sql="select * from item where id = '$update';";
       $sql_res=pg_Exec($sql);
       $old_priority=pg_result($sql_res, 0, "priority_id");
       $old_category=pg_result($sql_res, 0, "category_id");
       $old_private=pg_result($sql_res, 0, "private");
       $old_owner=pg_result($sql_res, 0, "owner");
       $old_detail=pg_result($sql_res, 0, "detail");
    }

    echo "<form action='insert.php' method=post>\n";
    echo "  <input type=hidden name=insert value=1>\n";
    echo "  <input type=hidden name=id value=$update>\n";
    echo "  <table border=0>\n";

    echo "  <tr><td>Priorit&eacute;</td><td>\n";
    echo "  <select name=priority>\n";
    /*
     * Les diverses priorités
     */
    $sql="select * from priority order by id;";
    $sql_res=pg_Exec($sql);
    $sql_count = pg_NumRows($sql_res);
    if ((!$sql_res) || ($sql_count < 1))
    {
      echo "<option value=0>Erreur !\n";
    }
    else
    {
      for ($i=0; $i < $sql_count; $i++)
      {
        $item_id= pg_result($sql_res, $i, "id");
        echo "<option value="; echo $item_id;
        if (($item_id == 0 && $old_priority == "") || $item_id == $old_priority) echo " selected";
        $item_value= pg_result($sql_res, $i, "value");
        echo ">$item_value\n";
      }
    }
    echo "  </select>\n";

    echo "  <tr><td>Cat&eacute;gorie</td><td>\n";
    echo "  <select name=category>\n";

    /*
     * Les diverses catégories
     */
    $sql="select * from category order by id;";
    $sql_res=pg_Exec($sql);
    $sql_count = pg_NumRows($sql_res);
    if ((!$sql_res) || ($sql_count < 1))
    {
      echo "<option value=0>Erreur !\n";
    }
    else
    {
      for ($i=0; $i < $sql_count; $i++)
      {
        $item_id= pg_result($sql_res, $i, "id");
        echo "<option value="; echo $item_id;
        if (($item_id == 0 && $old_category == "") || $item_id == $old_category) echo " selected";
        $item_value= pg_result($sql_res, $i, "value");
        echo ">$item_value\n";
      }
    }

    echo "  </select>\n";

    echo "  </td></tr>\n";
    echo "  <tr><td>Assign&eacute; &agrave;</td>\n";
    echo "  <td>\n";
    echo "  <select name=owner>\n";
    echo "    <option value='$REMOTE_USER'>$REMOTE_USER\n";
    echo "    <option value=''>Personne\n";
    echo "  </select>\n";
    echo "  </td></tr>\n";
    echo "  <tr><td>Perso</td>\n";
    echo "  <td>\n";
    echo "  <select name=private>\n";
    echo "    <option";
    if ($old_private == "f") echo " selected";
    echo " value=0>Non\n";
    echo "    <option";
    if ($old_private == "t") echo " selected";
    echo " value=1>Oui\n";
    echo "  </select>\n";
    echo "  </td>\n";
    echo "  <tr><td>Descriptif</td>\n";
    echo "  <td>\n";
    echo "  <textarea name=detail\n";
    echo "      cols=80\n";
    echo "      rows=10\n";
    echo "  >";
    if ($old_detail != "")
      echo "$old_detail";
    else
      echo "Entrez votre description ici";
    echo "</textarea>\n";
    echo "  </td>\n";
    echo "  </table>\n";
    echo "  <br><center><input type=submit value='";
    if ($update != "")
      echo "Modification";
    else
      echo "Insertion";
    echo "'></center>\n";
    echo "</form>\n";

  }
  else
  {
    /*
     * On est censé avoir toutes les billes...
     */
    if ($update != "")
      $sql="update item set owner ='$owner', private='$private', priority_id='$priority', category_id='$category', detail='$detail' where id='$update';";
    else
      $sql="insert into item (startdate, owner, private, priority_id, category_id, detail) values ('now', '$owner', '$private', '$priority', '$category', '$detail');";
    $sql_res=pg_Exec($sql);
    if (!$sql_res)
    {
      echo "<p><b>Erreur d'insertion.";
    }
    else
    {
      echo "<p>Insertion effectu&eacute;e correctement.";
    }
  }
?>

<p>Vous pouvez revenir &agrave;
<a href="./">la liste</a>, ou saisir un <a href='insert.php'>nouvel &eacute;l&eacute;ment</a>.
<? include "$DOCUMENT_ROOT/section-footer.shtml" ?>
<? include "$DOCUMENT_ROOT/page-footer.shtml" ?>
</BODY></HTML>
Return current item: TAF