first reimport from platal
[platal.git] / htdocs / stats / graph_evolution.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once("xorg.inc.php");
23
24 new_skinned_page('index.tpl', AUTH_COOKIE);
25
26 //nombre de jours sur le graph
27 $JOURS=Env::getInt('jours', 364);
28 define('DUREEJOUR',24*3600);
29
30 //recupere le nombre d'inscriptions par jour sur la plage concernée
31 $res = $globals->xdb->iterRow(
32 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $JOURS DAY),
33 TO_DAYS(date_ins)-TO_DAYS(NOW()),
34 ".(-($JOURS+1)).") AS jour,
35 COUNT(user_id) AS nb
36 FROM auth_user_md5
37 WHERE perms IN ('admin','user')
38 GROUP BY jour");
39
40 //genere des donnees compatibles avec GNUPLOT
41 $inscrits='';
42
43 // la première ligne contient le total des inscrits avant la date de départ (J - $JOURS)
44 list(,$init_nb) = $res->next();
45 $total = $init_nb;
46
47 list($numjour, $nb) = $res->next();
48
49 for ($i=-$JOURS;$i<=0;$i++) {
50 if ($numjour<$i) {
51 if(!list($numjour, $nb) = $res->next()) {
52 $numjour = 0;
53 $nb = 0;
54 }
55 }
56 if ($numjour==$i) $total+=$nb;
57 $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n";
58 }
59
60 //Genere le graphique à la volée avec GNUPLOT
61 header( "Content-type: image/png");
62
63 $delt = ($total - $init_nb)/10;
64 $ymin = round($init_nb - $delt,0);
65 $ymax = round($total + $delt,0);
66
67 $gnuplot = <<<EOF2
68 gnuplot <<EOF
69
70 set term png small color
71 set size 640/480
72 set xdata time
73 set timefmt "%d/%m/%y"
74
75 set format x "%m/%y"
76 set yr [$ymin:$ymax]
77
78 set title "Nombre d'inscrits"
79
80 plot "-" using 1:2 title 'inscrits' with lines;
81 {$inscrits}
82 EOF
83 EOF2;
84
85 passthru($gnuplot);
86 ?>