<?php
/* Biblos -- A library administration web interface
* Copyright (C) 2007 Jean-Nicolas Lagalaye <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 lecteurs");
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> lecteurs, <B>$total_eloui</B> lecteur$term1 emprunte$term2 des livres à la biliothèque");
echo _(" et <B>$total_elno</B> lecteur$term3 n'emprunte$term4 pas de livres.");
echo "<HR><H3>";
echo _("Top 5 des lecteurs qui lisent le plus :");
echo "</H3>";
$sql = "SELECT DISTINCT t1.eleve_id, count(t1.eleve_id) tot, t2.nom, t2.prenom FROM prets as t1 inner join eleves as t2 on t2.id=t1.eleve_id group by eleve_id order by tot desc, nom LIMIT 5" ;
$result = biblio_db_query($sql);
put_log(8,_("les 5 plus lecteurs"),$user);
echo "<TABLE BORDER=1><tr><th>";
echo _("Nom");
echo "</th><th>";
echo _("Prénom");
echo "</th><th>";
echo _("Nbr d'emprunts");
echo "</th><th>";
echo _("Répartition</th>");
while ($myrow = biblio_db_fetch_array($result))
{
$nom = $myrow['nom'];
$prenom = $myrow['prenom'];
$tot = $myrow['tot'];
$i++;
if ($i%2 == 1) {$col="WHITE";}
else {$col="lightyellow";}
echo "<TR bgcolor=$col><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 _("Les 5 <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 FROM prets as t1 inner join eleves as t2 on t2.id=t1.eleve_id group by eleve_id order by tot desc, nom LIMIT $limit,5" ;
$result = biblio_db_query($sql);
put_log(8,_("5 moins bon lecteurs"),$user);
echo "<TABLE BORDER=1><tr><th>";
echo _("Nom");
echo "</th><th>";
echo _("Prénom");
echo "</th><th>";
echo _("Nbr d'emprunts");
echo "</th><th>";
echo _("Répartition");
echo "</th>";
while ($myrow = biblio_db_fetch_array($result))
{
$nom = $myrow['nom'];
$prenom = $myrow['prenom'];
$tot = $myrow['tot'];
$i++;
if ($i%2 == 1) {$col="WHITE";}
else {$col="lightyellow";}
echo "<TR bgcolor=$col><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");
?>