<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Alain Pomirol
(CATICE Académie de Bordeaux)

This file is part of Gibii/Melia.

Gibii/Melia is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Gibii/Melia is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Gibii/Melia; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

****************************************************************************/
include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/eleve.inc.php");
include("../include/utiljs.php");

opensession("Eleve");
connecte($host, $user, $mdp, $db);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Elève coche1</title>
<link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">

<script language="javascript">
function textLimit(field, maxlen) {
   if (field.value.length > maxlen) {
      field.value = field.value.substring(0, maxlen);
      alert('Longueur maximale atteinte !');
   }
}

function target_top() {
         window.document.formitems.target='_top';
}

function trim(s) {
   cs=new String(' \t\n');  //caractères à suprimer
   //au début
   i=0;
   while (i<s.length && cs.indexOf(s.charAt(i))!=-1) i++;
   s=s.substr(i);

   //à la fin
   i=s.length-1;
   while (i>=0 && cs.indexOf(s.charAt(i))!=-1) i--;
   return s.substr(0,i+1);
}

function soumettre() {
  var i,i,k,m1,m2;
    cumul='';
    k=0;
    if (<?php print $etab_alert_message_vide; ?>) {
        ta=window.document.getElementsByTagName('textarea');
        for (i=0; i < ta.length; i++) { //<!-- ><-->
            if (trim(ta[i].value)=='') {
                j=i+1;
                k++;
                cumul+=', '+j.toString();
            }
        }
        if (k) {
            cumul=cumul.substr(2);
            if (k>1) {m1='s ' ; m2=' sont ';}
            else     {m1=' '  ; m2=' est ';}
            if (!confirm('Le'+m1+'commentaire'+m1+cumul+m2+'vide'+m1+'\nContinuer quand même ?')) {
               return;
            }
        }
    }
    window.document.formitems.submit();
}
</script>

</head>
<body class="arialeleve">

<?php
//narguer les truands avant qu'ils aient tapé leurs commentaires
//(ce sera fait aussi après).
$nbdemandes=count($CBItem);
//$nbattente récupéré par POST

if ($nbattente+$nbdemandes>$etab_nb_max_demandes) {
    alert("Hum... Le nombre maximal de demandes est $etab_nb_max_demandes,\n".
          "le nombre de demandes en cours est $nbattente\n".
          "et il n'est donc pas possible de faire $nbdemandes demandes !");
    goto("eleve_choix.php");
    print "</body></html>";
}

print "<p class=\"rubrique\">Demande";if ($nbdemandes>1) print "s";
print "</p>";

print "<form name=\"formitems\" method=\"post\" action=\"eleve_coche2.php?eleve_id=$eleve_id\">";
print "<table border=\"1\" width=\"100%\">";
for ($i=0; $i<$nbdemandes; $i++) { //$CBItems sont les check boxes des items cochés
    $item_id=$CBItem[$i];
    $resitem=query("SELECT inst FROM libelles WHERE item_id=$item_id ;");
    $rowitem=mysql_fetch_array($resitem);
    print "<tr>";
    print "<td width=\"55%\" valign=\"top\">";
    print "<p class=\"rubrique\">Item $item_id</p>";
    print "<p class=\"libelle_eleve\">".$rowitem["inst"]."</p>";
    print "</td>";
    print "<td width=\"45%\">";
    print "<p class=\"attention\" align=\"left\" ><i><b>";
    print "Indique".tuvous("","z")." ici pourquoi ".tuvous("tu penses","vous pensez")." avoir acquis cet item : <br />(message limité à la boîte !)</b></i></p>";
    print "<p align=\"right\">";
    print "<textarea name=\"commentaire[$item_id]\" rows=\"8\" cols=60 maxlength=40 onkeyup=\"textLimit(this, 400);\">"; //cols=40 ?
    print "</textarea></p>";
    print "</td>\n";
    print "</tr>\n";
}
print "</table>";
//c'est le bouton du cadre "haut" qui validera la saisie (fonction soumettre())
print "<input type=\"hidden\" name=\"nbattente\" value=\"$nbattente\">";

print "</form>";


?>

</body>
</html>