| 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 | $promo = Env::getInt('promo', Session::getInt('promo')); |
| 26 | |
| 27 | //nombre de jours sur le graph |
| 28 | $JOURS=364; |
| 29 | define('DUREEJOUR',24*3600); |
| 30 | $res = $globals->xdb->query("SELECT min(TO_DAYS(date_ins)-TO_DAYS(now())) FROM auth_user_md5 WHERE promo = {?} AND perms IN ('admin', 'user')", $promo); |
| 31 | $JOURS = -$res->fetchOneCell(); |
| 32 | |
| 33 | //recupere le nombre d'inscriptions par jour sur la plage concernée |
| 34 | $res = $globals->xdb->iterRow( |
| 35 | "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $JOURS DAY), |
| 36 | TO_DAYS(date_ins)-TO_DAYS(NOW()), |
| 37 | ".(-($JOURS+1)).") AS jour, |
| 38 | COUNT(user_id) AS nb |
| 39 | FROM auth_user_md5 |
| 40 | WHERE promo = {?} AND perms IN ('admin','user') |
| 41 | GROUP BY jour", $promo); |
| 42 | |
| 43 | //genere des donnees compatibles avec GNUPLOT |
| 44 | $inscrits=''; |
| 45 | |
| 46 | // la première ligne contient le total des inscrits avant la date de départ (J - $JOURS) |
| 47 | list(,$init_nb) = $res->next(); |
| 48 | $total = $init_nb; |
| 49 | |
| 50 | list($numjour, $nb) = $res->next(); |
| 51 | |
| 52 | for ($i=-$JOURS;$i<=0;$i++) { |
| 53 | if ($numjour<$i) { |
| 54 | if(!list($numjour, $nb) = $res->next()) { |
| 55 | $numjour = 0; |
| 56 | $nb = 0; |
| 57 | } |
| 58 | } |
| 59 | if ($numjour==$i) $total+=$nb; |
| 60 | $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n"; |
| 61 | } |
| 62 | |
| 63 | //Genere le graphique à la volée avec GNUPLOT |
| 64 | header( "Content-type: image/png"); |
| 65 | |
| 66 | $delt = ($total - $init_nb) / 10; |
| 67 | $delt += ($delt < 1); |
| 68 | $ymin = round($init_nb - $delt,0); |
| 69 | $ymax = round($total + $delt,0); |
| 70 | |
| 71 | $gnuplot = <<<EOF2 |
| 72 | gnuplot <<EOF |
| 73 | |
| 74 | set term png small color |
| 75 | set size 640/480 |
| 76 | set xdata time |
| 77 | set timefmt "%d/%m/%y" |
| 78 | |
| 79 | set format x "%m/%y" |
| 80 | set yr [$ymin:$ymax] |
| 81 | |
| 82 | set title "Nombre d'inscrits de la promotion $promo." |
| 83 | |
| 84 | plot "-" using 1:2 title 'inscrits' with lines; |
| 85 | {$inscrits}e |
| 86 | EOF |
| 87 | EOF2; |
| 88 | |
| 89 | passthru($gnuplot); |
| 90 | ?> |