<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Stéphanie Roussel, Jean-Marie Treins
(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

****************************************************************************/

print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
?>
<html>
<head>

<?php
include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/utiljs.php");
opensession("Gest");
?>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>compétences par prof</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 par chaque professeur</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
$sql_pi="SELECT profs.prof_id, lpi.item_id
            FROM profs, lpi, items
            WHERE profs.etab_id=$etab_id
            AND profs.annee =  '$sess_ascol'
            AND profs.prof_id = lpi.prof_id
            AND lpi.item_id=items.item_id ".$rqniv;

$res_pi=query($sql_pi);
$tab_pi=array();
while (list($pid,$itid)=mysql_fetch_array($res_pi)) {
   $tab_pi[$pid][$itid]=1;
   }

//Stockage profs
$respr=query("SELECT * FROM profs
              WHERE etab_id=$etab_id
              AND annee=$sess_ascol
              ORDER BY nom, prenom");
$tab_pr=array();
$tab_pr_id=array();
$nbpr=0;
while (list($prof_id, $nom, $prenom)=mysql_fetch_array($respr)) {
      $nbpr++;
      $tab_pr_id[$nbpr]=$prof_id;
      $tab_pr[$nbpr]=$nom." ".$prenom;
      }


//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);

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

$nbit=0;  //au passage on va compter les items
//print "<p>&nbsp;</p>";

print "<div align='center'><table border='1'>\n";
print "<tr class='rubrique'>\n";
print "\t<td>Item n° :</td>";



//On stocke les item_id dans un tableau et les sauts de rubrique dans un autre
$tab_items=array();
$tab_srub=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"];
  $tab_srub[$nbit]=$rowit["s_rub_no"];
  //print $tab_srub[$nbit];

    //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 ($p=1;$p<$nbpr+1;$p++) {
    $cl=($p%2==0) ? "paire" : "impaire";
    print "<tr class=$cl>\n";
    print "\t<td>&nbsp;".$tab_pr[$p]."</td>\n";
    for ($i=1; $i<$nbit+1 ; $i++) {
        if (isset($tab_pi[$tab_pr_id[$p]][$tab_items[$i]])) {
            print "\t<td width=\"20\"align=\"center\"><img src=../themes/".$etab_theme."/boule.gif border =\"0\"></td>";
            }
        else print "\t<td width=\"20\">&nbsp;</td>";
        }
    print "\t</tr>\n";
}



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

?>

</body>
</html>