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

****************************************************************************/
include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/get.inc.php");
opensession("Sadmin",true);

$chemin_theme="../include/general.css";

print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Répartition par département</title>
<link rel="stylesheet" href="<?php echo $chemin_theme; ?>">
<base target="_self">
</head>
<body class="arial_sadmin" >
<?php
if ($MODULE=="GiSCCo") $tabniv=array(1=>'Ecole',2=>'Collège',3=>'Lycée & CFA');
else $tabniv=array(1=>' 1',2=>' 2',3=>' 3');

//Recherche départements (3 chiffres ? Ah oui, les Antilles !)
$tabdep=array();
$res=query("SELECT LEFT(rne,3) as dep FROM etablissements GROUP BY dep ORDER BY dep");
while (list($d)=mysql_fetch_array($res)) $tabdep[]=$d;

Print "<p class='libelle_admin'>Répartition des validations par item dans chaque département le&nbsp;&nbsp;".date("d/m/Y");

//Niveau ??
//Choix du niveau à visualiser
if (!isset($btn_niv)) {
 $PHP_SELF=basename($_SERVER['PHP_SELF']);
 
 print "<form name='formniv' method='post' action='".$PHP_SELF."'>\n";
      print "<p align='center'>Choisissez le niveau à visualiser / imprimer : ";
      print "<select name='niv' value='' size='1'>\n";
      print "  <option value='1'>".getlibellenivo('niv1')."</option>\n";
      print "  <option value='2'>".getlibellenivo('niv2')."</option>\n";
      print "  <option value='3'>".getlibellenivo('niv3')."</option>\n";
      print "</select>&nbsp;&nbsp;\n";
      print "<input type='submit' class='coul' name='btn_niv' value='Choix du Niveau'></p>\n";
    }
else {
//Recherche valeurs
$resdep="SELECT LEFT(etablissements.rne,3) AS depart, resultats.item_id,COUNT(resultats.resultat_id) as nbit 
        FROM resultats,eleves,etablissements,items
        WHERE resultats.eleve_id=eleves.eleve_id
        AND resultats.item_id=items.item_id
        AND items.brevet_no=$niv
        AND eleves.annee='".$sess_ascol."'
        AND eleves.etab_id=etablissements.etab_id
        GROUP BY depart, resultats.item_id";
//print "<br>$resdep;";
$resresult=query($resdep);
while (list($dep,$etid,$nbit)=mysql_fetch_array($resresult)) $tab_nbitems[$dep][$etid]=$nbit;
mysql_free_result($resresult);

//On a tous les résultats, y'a plus qu'à faire les tableaux et graphiques...
for ($d=0;$d<count($tabdep);$d++) {
    $departement=$tabdep[$d];
    $titre="Nombre de validations par item (Niveau ".$tabniv[$niv].") dans le département $departement (".getnbelevdep($departement)." élèves)";    
    $titreX="Items du niveau ".$tabniv[$niv];
    $titreY="Nb validations";   
    $values='';
    $absc='';   
    $resit=query("SELECT items.item_id, LEFT(libelles.inst, 5) as lib 
                FROM items, libelles WHERE brevet_no=$niv 
                AND items.item_id=libelles.item_id 
                ORDER BY items.item_id");
    while (list($it,$libit)=mysql_fetch_array($resit))  {
        $absc.=",".$libit;
        if (isset($tab_nbitems[$departement][$it])) $values.=",".$tab_nbitems[$departement][$it];
        else $values.=",0";
        }
    mysql_free_result($resit);
    $values=substr($values,1);
    $absc=substr($absc,1);
    
    //Et si pas de réponses ?

    
    echo "<p><img src='../outils/graph_histo_items.php?niv=$niv&titreX=".urlencode($titreX)."&titreY=".urlencode($titreY)."&titre=".urlencode($titre)."&absc=".$absc."&values=".$values."'></p>";
    echo "<br><br>\n";

} //Fin graphique niveau $n

} //Fin choix niveau

?>
</html>

