<?php
#=
/****************************************************************************
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

****************************************************************************/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<?php
include("../include/vars_adm.php");
include("../include/util.inc.php");
opensession("Gest",false);

?>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>compétences par classe</title>
<link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">
</head>
<body class="arialgest" link="lightGrey" vlink="lightGrey" alink="lightGrey" >

<p class="sous_titre">Compétences prises en charge pour chaque classe</p>

<?php

$conn  = connecte($host, $user, $mdp, $db);
//Choix du niveau de brevet ?
$brevet_no=$etab_niveau;
switch ($brevet_no)  {
 case 'niv1': $rqniv="  and items.brevet_no = 1 "; break;
 case 'niv2': $rqniv=" and items.brevet_no = 2 ";  break;
 case 'niv3': $rqniv=" and items.brevet_no = 3 ";  break;
 case 'niv12': $rqniv=" and (items.brevet_no=1 || items.brevet_no=2) "; break;
 case 'niv23': $rqniv=" and (items.brevet_no=2 || items.brevet_no=3) "; break;
 default: $rqniv=" ";

}

//Recherche compétences profs-items-divisions
$sql_pid="SELECT count( profs.nom )  AS nb_pr, lpi.item_id, classes.classe_id
            FROM profs, lien_profs_classes, classes, lpi, items
            WHERE profs.etab_id=$etab_id
            AND profs.annee =  '$sess_ascol'
            AND profs.prof_id = lien_profs_classes.prof_id
            AND lien_profs_classes.classe_id = classes.classe_id
            AND classes.divgro='D'
            AND profs.prof_id = lpi.prof_id
            AND lpi.item_id=items.item_id ".$rqniv."
            GROUP  BY item_id, divcod
            ORDER  BY classes.divcod, lpi.item_id";
$res_pid=query($sql_pid);
$tab_pid=array();
while (list($nbp,$itid,$clid)=mysql_fetch_array($res_pid)) {
   $tab_pid[$clid][$itid]=$nbp;

   }


//Stockage classes
$resdiv=query("select classe_id, divcod from classes
                     WHERE etab_id=$etab_id
                     AND divgro='D' ORDER BY divcod DESC",$conn);
$nbdiv=0; //comptage des divisions
$tab_classes_id=array(); //stockage
$tab_classes=array();
while ($rowdiv=mysql_fetch_array($resdiv)) {
   $nbdiv++;
   $tab_classes_id[$nbdiv]=$rowdiv['classe_id'];
   $tab_classes[$nbdiv]=$rowdiv['divcod'];

}

//Stockage items
$resit=query("select  items.*, libelles.inst, left(libelles.inst,5) as code_it  from items, libelles ".
                      " WHERE items.item_id=libelles.item_id ".
                      $rqniv." order by item_id;",$conn);
$nbit=0;  //au passage on va compter les items
//print "<p>&nbsp;</p>";

print "<p class='attention' align=center>";
print "Une <img src=../themes/".$etab_theme."/boule.gif align='absmiddle'> indique que la compétence peut être validée ; la bulle sur chaque puce donne le nombre de professeurs déclarés.</p>";
print "<p align='center'><a target='_blank' href=compet_classes_aff_profs.php> Pour une version imprimable</a></p><br/>";
print "<div align='center'><table border='1'>\n";
print "<tr class='rubrique'>\n";
print "\t<td>Item n° :</td>";

// on compte les items
$nb=mysql_num_rows($resit);

//On stocke les item_id dans un tableau
$tab_items=array();

while ($rowit=mysql_fetch_array($resit)) {
    $nbit++;
    $item_id=$rowit['item_id'];
    $tab_items[$nbit]=$item_id;
    $code_it=$rowit["code_it"];
    $libelle=$rowit["inst"];
    //on choisit le décalage de la bulle
     if ($nbit<$nb/3) $decalbulle="decalbulleg";
     elseif ($nbit<2*$nb/3) $decalbulle="decalbullec";
     else $decalbulle="decalbulled";

//Première ligne du tableau : numéro des items avec bulle sur le libellé
//On peut afficher le code de chaque item au lieu du numéro avec $code_it  au lieu de $item_id
// Pour brevet 2006 ?
 //print "<td width='15'><a class='bulle' href=#>".$code_it."<span><B> Item ".$nbit."</BR></B>".$libelle."</span></a></td>";
 print "<td width='15'><a class='bulle taillebullegde $decalbulle' href=#>".$item_id."<span><B> Item ".$nbit."</BR></B>".$libelle."</span></a></td>";
}

print "</tr>";

//Afficher tableau
for ($k=1;$k<$nbdiv+1;$k++) {
    $cl=($k%2==0) ? "paire" : "impaire";
    print "<tr class=$cl>\n";
    print "\t<td>&nbsp;".$tab_classes[$k]."</td>\n";
    for ($i=1; $i<$nbit+1 ; $i++) {
        if (isset($tab_pid[$tab_classes_id[$k]][$tab_items[$i]])) {
            $nbpr=$tab_pid[$tab_classes_id[$k]][$tab_items[$i]];
            print "\t<td width=\"20\"align=\"center\"><a class='bulle taillebullepte' href=#><span>$nbpr</span><img src=../themes/".$etab_theme."/boule.gif border =\"0\"></a></td>";
            }
        else print "\t<td width=\"20\">&nbsp;</td>";
        }
    print "\t</tr>\n";
}

print "</table></div><br/><br/><br/>\n";


?>


</body>
</html>