<?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("Gest",true);

set_time_limit(0);
//Cas d'un accès depuis Sadmin '
if ($sess_statut=="Sadmin") {
	$etab_id=$_GET['etab_id'];
	$etabli=getetab($etab_id);
	$etab_nom=$etabli['nom'];
	$etab_adresse=$etabli['adresse'];
	$etab_codepostal=$etabli['codepostal'];
	$etab_ville=$etabli['ville'];
	$etab_niveau=getniveau($etab_id);
	$chemin_theme="../include/general.css";
	}
else $chemin_theme="../themes/".$etab_theme."/b2i.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>Effectifs par item</title>
<link rel="stylesheet" href="<?php echo $chemin_theme; ?>">
<base target="_self">
</head>
<body class="arialgest" >
<?php
if ($MODULE=="GiSCCo") $tabniv=array(1=>'Ecole',2=>'Collège',3=>'Lycée & CFA');
else $tabniv=array(1=>' 1',2=>' 2',3=>' 3');

//Affichage établissement et nb élèves ?
//En-tête pour impression
$nbel=getnbeleves($etab_id);
Print "<p class='libelle_admin'>".$etab_nom."&nbsp;&nbsp;&nbsp;&nbsp;".
                 $etab_adresse."&nbsp;&nbsp;&nbsp;&nbsp;".$etab_codepostal.
                 "&nbsp;&nbsp;".$etab_ville."&nbsp;&nbsp;".date("d/m/Y");
print "<p class='titre_petit'>$nbel élèves</p>";

for ($n=1;$n<=3;$n++) {
  //Un graphique par niveau 
  //$values=array();
  $values='';
  
  //$absc=array();
  $absc='';
  $tab_nbitems=array();	
  if (strpos($etab_niveau,"$n")) {  //Uniquement niveau PRESENT DANS L'ETAB
    //print "niveau ".$n." ".strpos($etab_niveau,"$n");
	$titre="Répartition des résultats par item (Niveau $tabniv[$n])";	
	$titreX="Items du niveau $tabniv[$n]";
	$titreY="Effectif par item";
	//Recherche valeurs
	$resresult=query("SELECT resultats.item_id,COUNT(resultat_id) as nbit FROM resultats, items, eleves
		WHERE resultats.item_id=items.item_id 	AND items.brevet_no=$n
		AND resultats.eleve_id=eleves.eleve_id 	AND eleves.etab_id=$etab_id
		AND eleves.annee='".$sess_ascol."' 	GROUP BY resultats.item_id
		ORDER BY resultats.item_id");
	$resitems=query("SELECT items.item_id, LEFT(libelles.inst, 5) as lib FROM items, libelles
		WHERE brevet_no=$n AND items.item_id=libelles.item_id ORDER BY items.item_id");
	while (list($itid,$nbit)=mysql_fetch_array($resresult)) $tab_nbitems[$itid]=$nbit;
	while (list($it,$libit)=mysql_fetch_array($resitems))  {
		$absc.=",".$libit;
		if (isset($tab_nbitems[$it])) $values.=",".$tab_nbitems[$it];
		else $values.=",0";
		}
	mysql_free_result($resresult);
	mysql_free_result($resitems);
	$values=substr($values,1);
	$absc=substr($absc,1);
	
	echo "<p class='sous_titre'><img src='../outils/graph_histo_items.php?niv=$n&titreX=".urlencode($titreX)."&titreY=".urlencode($titreY)."&titre=".urlencode($titre)."&absc=".$absc."&values=".$values."'></p>";
	echo "<br><br>\n";
	
  } //Fin test présence étab
} //Fin graphique niveau $n

?>
</html>

