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');
55 function handler_evolution(&$page, $jours = 365)
57 $page->changeTpl('stats/evolution_inscrits.tpl');
58 $page->assign('jours', $jours);
61 function handler_graph_evo(&$page, $jours = 365)
63 define('DUREEJOUR',24*3600);
65 //recupere le nombre d'inscriptions par jour sur la plage concernée
67 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
68 TO_DAYS(date_ins)-TO_DAYS(NOW()),
69 ".(-($jours+
1)).") AS jour,
72 WHERE perms IN ('admin','user')
75 //genere des donnees compatibles avec GNUPLOT
78 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
79 list(,$init_nb) = $res->next();
82 list($numjour, $nb) = $res->next();
84 for ($i = -$jours; $i<=0; $i++
) {
86 if(!list($numjour, $nb) = $res->next()) {
91 if ($numjour==$i) $total+
=$nb;
92 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
95 //Genere le graphique à la volée avec GNUPLOT
96 header( "Content-type: image/png");
98 $delt = ($total - $init_nb)/10;
99 $ymin = round($init_nb - $delt,0);
100 $ymax = round($total +
$delt,0);
105 set term png small color
108 set timefmt
"%d/%m/%y"
113 set title
"Nombre d'inscrits"
115 plot
"-" using
1:2 title
'inscrits' with lines
;
124 function handler_graph(&$page, $promo = null
)
126 if ($promo == 'all') {
130 //recupere le nombre d'inscriptions par jour sur la plage concernée
132 "SELECT promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100
134 WHERE promo >= $depart AND deces = 0
137 //genere des donnees compatibles avec GNUPLOT
140 // la première ligne contient le total des inscrits avant la date de départ
141 list($annee, $nb) = $res->next();
143 for ($i = $depart; $i <= date("Y"); $i++
) {
145 if(!list($annee, $nb) = $res->next()) {
150 if ($nb > 0 ||
$i < date('Y'))
151 $inscrits .= $i.' '.$nb."\n";
154 //Genere le graphique à la volée avec GNUPLOT
160 set term png small color
162 set timefmt
"%d/%m/%y"
164 set xr
[$depart:$fin]
167 set title
"Nombre d'inscrits par promotion depuis $depart."
169 plot
"-" using
1:2 title
'inscrits' with boxes
;
175 //nombre de jours sur le graph
177 define('DUREEJOUR',24*3600);
178 $res = XDB
::query("SELECT min(TO_DAYS(date_ins)-TO_DAYS(now()))
181 AND perms IN ('admin', 'user')",
183 $jours = -$res->fetchOneCell();
185 //recupere le nombre d'inscriptions par jour sur la plage concernée
187 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
188 TO_DAYS(date_ins)-TO_DAYS(NOW()),
189 ".(-($jours+
1)).") AS jour,
192 WHERE promo = {?} AND perms IN ('admin','user')
193 GROUP BY jour", $promo);
195 //genere des donnees compatibles avec GNUPLOT
198 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
199 list(,$init_nb) = $res->next();
202 list($numjour, $nb) = $res->next();
204 for ($i = -$jours;$i<=0;$i++
) {
206 if(!list($numjour, $nb) = $res->next()) {
211 if ($numjour==$i) $total+
=$nb;
212 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
215 //Genere le graphique à la volée avec GNUPLOT
216 $delt = ($total - $init_nb) / 10;
217 $delt +
= ($delt < 1);
218 $ymin = round($init_nb - $delt,0);
219 $ymax = round($total +
$delt,0);
224 set term png small color
227 set timefmt
"%d/%m/%y"
232 set title
"Nombre d'inscrits de la promotion $promo."
234 plot
"-" using
1:2 title
'inscrits' with lines
;
240 header('Content-type: image/png');
245 function handler_promos(&$page, $promo = null
)
247 $page->changeTpl('stats/nb_by_promo.tpl');
250 "SELECT promo,COUNT(*)
252 WHERE promo > 1900 AND perms IN ('admin','user')
257 while (list($p,$nb) = $res->next()) {
259 if(!isset($nbpromo[$p/10])) {
260 $nbpromo[$p/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides
262 $nbpromo[$p/10][$p%10
]=Array('promo' => $p, 'nb' => $nb);
265 $page->assign_by_ref('nbs', $nbpromo);
266 $page->assign('min', $min-$min %
10);
267 $page->assign('max', $max+
10-$max%10
);
268 $page->assign('promo', $promo);
271 function handler_coupures(&$page, $cp_id = null
)
273 $page->changeTpl('stats/coupure.tpl');
275 if (!is_null($cp_id)) {
276 $res = XDB
::query("SELECT debut,
277 TIME_FORMAT(duree,'%kh%i') AS duree,
278 resume, description, services
280 WHERE id = {?}", $cp_id);
281 $cp = $res->fetchOneAssoc();
285 $cp['lg_services'] = serv_to_str($cp['services']);
286 $page->assign_by_ref('cp',$cp);
288 $beginning_date = date("Ymd", time() - 3600*24*21) . "000000";
289 $sql = "SELECT id, debut, resume, services
290 FROM coupures where debut > '$beginning_date' order by debut desc";
291 $page->assign('coupures', XDB
::iterator($sql));