2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 function serv_to_str($params) {
23 $flags = explode(',',$params);
24 $trad = Array('web' => 'site web', 'mail'=> 'redirection mail',
25 'smtp' => 'serveur sécurisé d\'envoi de mails',
26 'nntp' => 'serveur des forums de discussion');
28 foreach ($flags as $flag) {
29 $ret[] = $trad[$flag];
31 return implode(', ',$ret);
34 class StatsModule
extends PLModule
39 'stats' => $this->make_hook('stats', AUTH_COOKIE
),
40 'stats/evolution' => $this->make_hook('evolution', AUTH_COOKIE
),
41 'stats/graph' => $this->make_hook('graph', AUTH_COOKIE
),
42 'stats/graph/evolution'
43 => $this->make_hook('graph_evo', AUTH_COOKIE
),
44 'stats/promos' => $this->make_hook('promos', AUTH_COOKIE
),
46 'stats/coupures' => $this->make_hook('coupures', AUTH_PUBLIC
),
50 function handler_stats(&$page)
52 $page->changeTpl('stats/index.tpl');
56 function handler_evolution(&$page, $jours = 365)
58 $page->changeTpl('stats/evolution_inscrits.tpl');
59 $page->assign('jours', $jours);
63 function handler_graph_evo(&$page, $jours = 365)
67 define('DUREEJOUR',24*3600);
69 //recupere le nombre d'inscriptions par jour sur la plage concernée
70 $res = $globals->xdb
->iterRow(
71 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
72 TO_DAYS(date_ins)-TO_DAYS(NOW()),
73 ".(-($jours+
1)).") AS jour,
76 WHERE perms IN ('admin','user')
79 //genere des donnees compatibles avec GNUPLOT
82 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
83 list(,$init_nb) = $res->next();
86 list($numjour, $nb) = $res->next();
88 for ($i = -$jours; $i<=0; $i++
) {
90 if(!list($numjour, $nb) = $res->next()) {
95 if ($numjour==$i) $total+
=$nb;
96 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
99 //Genere le graphique à la volée avec GNUPLOT
100 header( "Content-type: image/png");
102 $delt = ($total - $init_nb)/10;
103 $ymin = round($init_nb - $delt,0);
104 $ymax = round($total +
$delt,0);
109 set term png small color
112 set timefmt
"%d/%m/%y"
117 set title
"Nombre d'inscrits"
119 plot
"-" using
1:2 title
'inscrits' with lines
;
128 function handler_graph(&$page, $promo = null
)
132 if ($promo == 'all') {
136 //recupere le nombre d'inscriptions par jour sur la plage concernée
137 $res = $globals->xdb
->iterRow(
138 "SELECT promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100
140 WHERE promo >= $depart AND deces = 0
143 //genere des donnees compatibles avec GNUPLOT
146 // la première ligne contient le total des inscrits avant la date de départ
147 list($annee, $nb) = $res->next();
149 for ($i = $depart; $i <= date("Y"); $i++
) {
151 if(!list($annee, $nb) = $res->next()) {
156 if ($nb > 0 ||
$i < date('Y'))
157 $inscrits .= $i.' '.$nb."\n";
160 //Genere le graphique à la volée avec GNUPLOT
166 set term png small color
168 set timefmt
"%d/%m/%y"
170 set xr
[$depart:$fin]
173 set title
"Nombre d'inscrits par promotion depuis $depart."
175 plot
"-" using
1:2 title
'inscrits' with boxes
;
181 //nombre de jours sur le graph
183 define('DUREEJOUR',24*3600);
184 $res = $globals->xdb
->query("SELECT min(TO_DAYS(date_ins)-TO_DAYS(now()))
187 AND perms IN ('admin', 'user')",
189 $jours = -$res->fetchOneCell();
191 //recupere le nombre d'inscriptions par jour sur la plage concernée
192 $res = $globals->xdb
->iterRow(
193 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
194 TO_DAYS(date_ins)-TO_DAYS(NOW()),
195 ".(-($jours+
1)).") AS jour,
198 WHERE promo = {?} AND perms IN ('admin','user')
199 GROUP BY jour", $promo);
201 //genere des donnees compatibles avec GNUPLOT
204 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
205 list(,$init_nb) = $res->next();
208 list($numjour, $nb) = $res->next();
210 for ($i = -$jours;$i<=0;$i++
) {
212 if(!list($numjour, $nb) = $res->next()) {
217 if ($numjour==$i) $total+
=$nb;
218 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
221 //Genere le graphique à la volée avec GNUPLOT
222 $delt = ($total - $init_nb) / 10;
223 $delt +
= ($delt < 1);
224 $ymin = round($init_nb - $delt,0);
225 $ymax = round($total +
$delt,0);
230 set term png small color
233 set timefmt
"%d/%m/%y"
238 set title
"Nombre d'inscrits de la promotion $promo."
240 plot
"-" using
1:2 title
'inscrits' with lines
;
246 header('Content-type: image/png');
251 function handler_promos(&$page, $promo = null
)
255 $page->changeTpl('stats/nb_by_promo.tpl');
257 $res = $globals->xdb
->iterRow(
258 "SELECT promo,COUNT(*)
260 WHERE promo > 1900 AND perms IN ('admin','user')
265 while (list($p,$nb) = $res->next()) {
267 if(!isset($nbpromo[$p/10])) {
268 $nbpromo[$p/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides
270 $nbpromo[$p/10][$p%10
]=Array('promo' => $p, 'nb' => $nb);
273 $page->assign_by_ref('nbs', $nbpromo);
274 $page->assign('min', $min-$min %
10);
275 $page->assign('max', $max+
10-$max%10
);
276 $page->assign('promo', $promo);
281 function handler_coupures(&$page, $cp_id = null
)
285 $page->changeTpl('stats/coupure.tpl');
287 if (!is_null($cp_id)) {
288 $res = $globals->xdb
->query("SELECT UNIX_TIMESTAMP(debut) AS debut,
289 TIME_FORMAT(duree,'%kh%i') AS duree,
290 resume, description, services
292 WHERE id = {?}", $cp_id);
293 $cp = $res->fetchOneAssoc();
297 $cp['lg_services'] = serv_to_str($cp['services']);
298 $page->assign_by_ref('cp',$cp);
300 $beginning_date = date("Ymd", time() - 3600*24*21) . "000000";
301 $sql = "SELECT id, UNIX_TIMESTAMP(debut) AS debut, resume, services
302 FROM coupures where debut > '$beginning_date' order by debut desc";
303 $page->assign('coupures', $globals->xdb
->iterator($sql));