Location: PHPKode > projects > Open Biblio > biblio2/statsel.php
<?php 
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <hide@address.com>
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

include_once("includes/db.inc");
include_once("includes/functions.inc");

session_start();
include_once("includes/session.inc");

ControleAcces("statsel.php",$login,$pwd,$user_id,session_id());

if(!$user_id)
{
 exit;
}

$title = _("Statistiques au niveau des &eacute;l&egrave;ves");
include ("includes/header.inc");

echo "<CENTER><br>";
$sql = "SELECT id  FROM prets" ;	
$result = biblio_db_query($sql);
$total_emp=biblio_db_num_rows($result);
$sql = "SELECT id FROM eleves where del = 0" ;	
$result = biblio_db_query($sql);
$total_el=biblio_db_num_rows($result);
$sql = "SELECT DISTINCT eleve_id FROM prets" ;	
$result = biblio_db_query($sql);
$total_eloui=biblio_db_num_rows($result);
$sql = "SELECT DISTINCT eleves.id  FROM eleves, prets where eleves.id =prets.eleve_id" ;	
$result = biblio_db_query($sql);
$total_elno=$total_el - biblio_db_num_rows($result);

if ($total_eloui > 1) {$term1 = _("s"); $term2 = _("nt"); }
if ($total_elno > 1) {$term3 = _("s"); $term4 = _("nt"); }

echo _("Sur <B>$total_el</B> &eacute;l&egrave;ves, <B>$total_eloui</B> &eacute;l&egrave;ve$term1 emprunte$term2 des livres à la bilioth&egrave;que");
echo _(" et <B>$total_elno</B> &eacute;l&egrave;ve$term3 n'emprunte$term4 pas de livres.");

echo "<HR><H3>";
echo _("Top 5 des &eacute;l&egrave;ves qui lisent le plus :");
echo "</H3>";
$sql = "SELECT DISTINCT t1.eleve_id, count(t1.eleve_id) tot, t2.nom, t2.prenom, t3.classe FROM prets as t1 inner join eleves as t2 on t2.id=t1.eleve_id inner join classes as t3 on t3.id = t2.classe_id group by eleve_id order by tot desc, classe, nom LIMIT 5" ;	
$result = biblio_db_query($sql);
put_log(8,_("top 5 &eacute;l&egrave;ves lecteurs"),$user);
echo "<TABLE BORDER=1><tr><th>";
echo _("Classe");
echo "</th><th>";
echo _("Nom");
echo "</th><th>";
echo _("Pr&eacute;nom");
echo "</th><th>";
echo _("Nbr d'emprunts");
echo "</th><th>";
echo _("R&eacute;partition</th>");
while ($myrow = biblio_db_fetch_array($result)) 
{
                $nom = $myrow['nom'];
                $prenom = $myrow['prenom'];
                $tot  = $myrow['tot'];
                $classe = $myrow['classe'];                
                $i++;
                if ($i%2 == 1) {$col="WHITE";}
                else {$col="lightyellow";}
                echo "<TR bgcolor=$col><TD>". $classe ."</TD><TD>" .$nom ."</TD><TD>". $prenom ."</TD><TD align=right>". $tot ."</TD>";      
	        $pct = sprintf("%2d",($tot / $total_emp) * 100);
                echo "<TD><IMG SRC=\"images/leftbar.gif\" height=\"15\" width=\"7\" Alt=\"$prenom $nom : $pct%\" border=0>";
                echo"<IMG SRC=\"images/mainbar.gif\" height=\"15\" width=\"". $pct  ."\" Alt=\"$prenom $nom : $pct%\" border=0>";
	        echo "<IMG SRC=\"images/rightbar.gif\" height=\"15\" width=\"7\" Alt=\"$prenom $nom : $pct%\" border=0> $pct %</TD>";
}
echo "</TABLE><BR>";

echo "<HR><H3>";
echo _("Top 5 des &eacute;l&egrave;ves (<i>lecteurs</i>) qui lisent le moins :");
echo "</H3>";
$limit = $total_el - 5;
if ($limit < 5) $limit=0;
$sql = "SELECT DISTINCT t1.eleve_id, count(t1.eleve_id) tot, t2.nom, t2.prenom, t3.classe FROM prets as t1 inner join eleves as t2 on t2.id=t1.eleve_id inner join classes as t3 on t3.id = t2.classe_id group by eleve_id order by tot desc, classe, nom LIMIT $limit,5" ;	
$result = biblio_db_query($sql);
put_log(8,_("top 5 &eacute;l&egrave;ves moins bon lecteurs"),$user);
echo "<TABLE BORDER=1><tr><th>";
echo _("Classe");
echo "</th><th>";
echo _("Nom");
echo "</th><th>";
echo _("Pr&eacute;nom");
echo "</th><th>";
echo _("Nbr d'emprunts");
echo "</th><th>";
echo _("R&eacute;partition");
echo "</th>";
while ($myrow = biblio_db_fetch_array($result)) 
{
                $nom = $myrow['nom'];
                $prenom = $myrow['prenom'];
                $tot  = $myrow['tot'];
                $classe = $myrow['classe'];                
                $i++;
                if ($i%2 == 1) {$col="WHITE";}
                else {$col="lightyellow";}
                echo "<TR bgcolor=$col><TD>". $classe ."</TD><TD>" .$nom ."</TD><TD>". $prenom ."</TD><TD align=right>". $tot ."</TD>";      
	        $pct = sprintf("%2d",($tot / $total_emp) * 100);
                echo "<TD><IMG SRC=\"images/leftbar.gif\" height=\"15\" width=\"7\" Alt=\"$prenom $nom : $pct%\" border=0>";
                echo"<IMG SRC=\"images/mainbar.gif\" height=\"15\" width=\"". $pct  ."\" Alt=\"$prenom $nom : $pct%\" border=0>";
	        echo "<IMG SRC=\"images/rightbar.gif\" height=\"15\" width=\"7\" Alt=\"$prenom $nom : $pct%\" border=0> $pct %</TD>";
}
echo "</TABLE><BR></center>";
?>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
<?php
include("includes/footer.inc");
?>
Return current item: Open Biblio