<?php
#Melia (n'existe pas dans GiBii)
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Alain Pomirol
(CATICE Académie de Bordeaux)

This file is part of Gibii.

Gibii 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 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; 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/utiljs.php");

function apourlangue($el,$rg) {
 //retourne les rangs si l'élève $el a la langue $disc
 static $tabelrg=array();
 if (empty($tabelrg)) {
         $res=query("SELECT * FROM lien_eleves_disciplines");
    while (list($rang,$eleve_id,$disc_id)=mysql_fetch_array($res)) {
            $tabelrg[$eleve_id][$rang]=$disc_id;
    }
 }
 if (isset($tabelrg[$el][$rg])) return $tabelrg[$el][$rg];
 else return -1;
 }

function combolangues($el_id, $rng,$num,&$last) {
static $first;
static $tablang=array();
global $conn;

if (empty($tablang)) {
    $res=query("SELECT disc_id,libelle FROM disciplines ORDER BY libelle");
    while (list($disc_id,$libelle)=mysql_fetch_array($res)) {
            $tablang[$disc_id]=$libelle;
    }
}

if ($rng==1) $first=0;   //initialiser mémoire langues
//affiche la langue de rang $rng de l'élève $el_id
$nomcombo="clang".$rng;
$disabled=($last==-1) ? "disabled" : "";
print "<select name=".$nomcombo."[$num] size=\"1\"  $disabled>\n";
//première ligne vide
print "<option  value='-1'>&nbsp;</option>\n";

foreach($tablang as $dis=>$lib) {
        $rel=apourlangue($el_id,$rng);
        $selected=($rel==$dis) ? "selected" : "";
        if (($last!=$dis) && ((isset($first)) && ($first!=$dis)))  {  //pas de répétition de discipline
            print "<option value=\"$dis\" $selected $disabled>";
            print $lib;
            print "</option>\n";
            }
        else $first=$last;
}

$last=$rel;
mysql_free_result($result);
print "</select>";
}

function langue_existe($elev,$rng) {
 global $conn;
 $ret=false;
 $res=query("SELECT * FROM lien_eleves_disciplines
            WHERE rang=$rng AND eleve_id=$elev;");
 if (mysql_num_rows($res)>0) $ret=true;
return $ret;
}

function modif_langue($rng,$elev,$lang) {
 global $conn;
 //alert("modif_langue $lang");
 $res=query("UPDATE lien_eleves_disciplines
            SET disc_id=".seci($lang)." 
            WHERE eleve_id=".seci($elev )." AND rang=".seci($rng));
}

function efface_langue($elev,$rng) {
 global $conn;
 //alert("efface_langue LV$rng");
 $res=query("DELETE FROM lien_eleves_disciplines
            WHERE eleve_id=$elev AND rang=$rng;");
}

function cree_langue($rng,$elev,$lang) {
 global $conn;
 //alert("crée langue $lang");
 $res=query("INSERT INTO lien_eleves_disciplines
            SET rang=".seci($rng)." , eleve_id=".seci($elev)." , disc_id=".seci($lang));
}



//==============================================================================
$statut=$_REQUEST['statut'];
opensession($statut,false);
<<<<<<< fiche_langue.php
$PHP_SELF=basename($_SERVER['PHP_SELF']);

?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
       <title>Fiche des langues d'une classe</title>
<link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">
</head>

<?php


switch ($statut) {
       case "Prof":
           echo "<BODY class='arialprof'>";
           break;
       case "Admin":
           echo "<BODY class='arialadmin'>";
           break;
       case "Gest":
           echo "<BODY class='arialgest'>";
           break;
   }

if (!isset($divcod)) exit();
$pretitre="Choix des langues pour les élèves de la classe";

print "<p class='sous_titre'>";
print $pretitre."&nbsp;".$divcod."</p>";
$conn  = connecte($host,$user,$mdp,$db);


if (isset($temoin))   { //Traitement éventuel des saisies avant affichage
        //print_r($_POST);


        //Enregistrer les tableaux de langues dans lien_eleves_disciplines
        //Connaissant les id des élèves à traiter ainsi que leurs 3 LV
        for ($i=1;$i<=$nbel;$i++) {  //Pour ch. élève de la classe
         for ($j=1;$j<=3;$j++) {   //Pour ch. langue vivante
          $nomcombo="clang".$j;
          $nc=$$nomcombo;      //la valeur de la langue est dans $nc[$i]
          $e_id=$id_elev[$i];              //l'ID élève est dans $id_elev[$i]
          if (isset($nc[$i])&&($nc[$i]>=0))  {   //langue choisie
             if (langue_existe($e_id,$j)) modif_langue($j,$e_id,$nc[$i]);
                    else cree_langue($j,$e_id,$nc[$i]);
            } else  {  //langue vide
             if (langue_existe($e_id,$j)) efface_langue($e_id,$j);
            }

          }
        }
        print "Enregistrement effectué...";
}   //Fin enregistrements


 //Affichage tableau

$sql="SELECT eleves.nom, eleves.prenom, eleves.dnaiss, eleves.eleve_id, comptes.login
        FROM classes, eleves, comptes
       WHERE classes.etab_id=$etab_id and classes.divcod='$divcod'
         and classes.classe_id=eleves.classe_id
         AND comptes.eleve_id=eleves.eleve_id
         and eleves.annee='$sess_ascol'
       ORDER BY nom, prenom;" ;
$resclasse=query($sql);
$nbelev=0;

//Formulaire des langues
print "<form name=\"formlangues\" method='POST' action=$PHP_SELF >";
print "<input type='hidden' name='statut' value=$statut>";
print "<input type='hidden' name='classe_id' value=$classe_id>";
print "<input type='hidden' name='divcod' value=$divcod>";
print "<input type='hidden' name='objet' value=$objet>";
print "<input type='hidden' name='temoin' value='ok'>";

//début du tableau
print "<table border='1' align='center'>\n";
print "<tr class='rubrique'>\n";
print "\t<td >Nom</td><td >Prénom</td><td>Login</td><td>Date de naissance</td><td>LV1</td><td>LV2</td><td>LV3</td></tr>\n";

while ($rowclasse=mysql_fetch_array($resclasse)) {
      $nbelev++;
      $nom=stripslashes($rowclasse["nom"]);
      $prenom=stripslashes($rowclasse["prenom"]);
      $dnaiss=$rowclasse["dnaiss"];
      $login=stripslashes($rowclasse["login"]);
      $id=$rowclasse["eleve_id"];

      $last=0;
     //Affichage d'une ligne
     print "\t<tr >\n";
     print "\t<td>&nbsp;&nbsp;$nom&nbsp;&nbsp;</td>\n";
     print "\t<td>&nbsp;&nbsp;$prenom&nbsp;&nbsp;</td>\n";
     print "\t<td>&nbsp;&nbsp;$login&nbsp;&nbsp;</td>\n";
     print "\t<td>&nbsp;&nbsp;$dnaiss</td>\n";
     print "\t<td>&nbsp;&nbsp;"; combolangues($id,"1",$nbelev,$last); print "&nbsp;&nbsp;</td>\n";
     print "\t<td>&nbsp;&nbsp;"; combolangues($id,"2",$nbelev,$last); print "&nbsp;&nbsp;</td>\n";
     print "\t<td>&nbsp;&nbsp;"; combolangues($id,"3",$nbelev,$last); print "&nbsp;&nbsp;</td>\n";
     print "<input type='hidden' name=\"id_elev[$nbelev]\" value=$id>";
     print "\t</tr>\n";
}

 print "</table><br>\n";
 print $nbelev;
 print ($nbelev>1) ? " élèves" : " élève";

print "<input type='hidden' name='nbel' value=$nbelev>";
print "<p align='center'><input class='coul' type='submit' name='btn_go' value='Enregistrer'>&nbsp;";
print "<input class='coul' type='reset' name='btn_esc' value='Valeurs initiales'></p>";
print "</form>";


?>
</body>
</html>
