move stats into new URI's
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 9 Jul 2006 22:09:46 +0000 (22:09 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 9 Jul 2006 22:09:46 +0000 (22:09 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@410 839d8a87-29fc-0310-9880-83ba4fa771e5

16 files changed:
htdocs/stats/coupure.php [deleted file]
htdocs/stats/evolution_inscrits.php [deleted file]
htdocs/stats/graph_by_promo.php [deleted file]
htdocs/stats/graph_evolution.php [deleted file]
htdocs/stats/graph_promo.php [deleted file]
htdocs/stats/index.php [deleted file]
htdocs/stats/nb_by_promo.php [deleted file]
htdocs/stats/stats_promo.php [deleted file]
install.d/stats.files [deleted file]
modules/platal.php
modules/stats.php [new file with mode: 0644]
templates/skin/common.footer.tpl
templates/stats/coupure.tpl
templates/stats/evolution_inscrits.tpl
templates/stats/index.tpl
templates/stats/nb_by_promo.tpl

diff --git a/htdocs/stats/coupure.php b/htdocs/stats/coupure.php
deleted file mode 100644 (file)
index 4702978..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_skinned_page('stats/coupure.tpl',AUTH_PUBLIC);
-
-function serv_to_str($params) {
-    $flags = explode(',',$params);
-    $trad = Array('web' => 'site web', 'mail'=> 'redirection mail',
-                  'smtp' => 'serveur sécurisé d\'envoi de mails',
-                  'nntp' => 'serveur des forums de discussion');
-    $ret = Array();
-    foreach ($flags as $flag) {
-        $ret[] = $trad[$flag];
-    }
-    return implode(', ',$ret);
-}
-
-if (Env::has('cp_id')) {
-    $res = $globals->xdb->query("SELECT  UNIX_TIMESTAMP(debut) AS debut,
-                                         TIME_FORMAT(duree,'%kh%i') AS duree,
-                                         resume, description, services
-                                   FROM  coupures
-                                  WHERE  id = {?}", Env::getInt('cp_id'));
-    $cp  = $res->fetchOneAssoc();
-}
-
-if($cp) {
-    $cp['lg_services'] = serv_to_str($cp['services']);
-    $page->assign_by_ref('cp',$cp);
-} else {
-    $beginning_date = date("Ymd", time() - 3600*24*21) . "000000";
-    $sql = "select id, UNIX_TIMESTAMP(debut) as debut, resume, services from coupures where debut > '$beginning_date' order by debut desc";
-    $page->assign('coupures', $globals->xdb->iterator($sql));
-}
-
-$page->run();
-?>
diff --git a/htdocs/stats/evolution_inscrits.php b/htdocs/stats/evolution_inscrits.php
deleted file mode 100644 (file)
index 499e6ce..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_skinned_page("stats/evolution_inscrits.tpl", AUTH_COOKIE);
-
-$page->run();
-
-?>
diff --git a/htdocs/stats/graph_by_promo.php b/htdocs/stats/graph_by_promo.php
deleted file mode 100644 (file)
index 97665b8..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-
-new_skinned_page('index.tpl', AUTH_COOKIE);
-$promo = Env::getInt('promo', Session::getInt('promo'));
-
-// date de départ
-$depart = 1920;
-
-//recupere le nombre d'inscriptions par jour sur la plage concernée
-$res = $globals->xdb->iterRow(
-        "SELECT  promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100
-           FROM  auth_user_md5
-          WHERE  promo >= $depart AND deces = 0
-       GROUP BY  promo");
-
-//genere des donnees compatibles avec GNUPLOT
-$inscrits='';
-
-// la première ligne contient le total des inscrits avant la date de départ
-list($annee, $nb) = $res->next();
-
-for ($i=$depart;$i<=date("Y");$i++) {
-    if ($annee<$i) {
-        if(!list($annee, $nb) = $res->next()) {
-            $annee = 0;
-            $nb = 0;
-        }
-    }
-    if ($nb > 0 || $i < date("Y"))
-       $inscrits .= $i." ".$nb."\n";
-}
-
-//Genere le graphique à la volée avec GNUPLOT
-header( "Content-type: image/png");
-
-$ymin = 0;
-$ymax = 100;
-
-$fin = $i+10;
-
-$gnuplot = <<<EOF2
-gnuplot <<EOF
-
-set term png small color
-set size 640/480
-set timefmt "%d/%m/%y"
-
-set xr [$depart:$fin]
-set yr [$ymin:$ymax]
-
-set title "Nombre d'inscrits par promotion depuis $depart."
-
-plot "-" using 1:2 title 'inscrits' with boxes;
-{$inscrits}
-EOF
-EOF2;
-
-passthru($gnuplot);
-?>
diff --git a/htdocs/stats/graph_evolution.php b/htdocs/stats/graph_evolution.php
deleted file mode 100644 (file)
index 4ab9645..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-
-new_skinned_page('index.tpl', AUTH_COOKIE);
-
-//nombre de jours sur le graph
-$JOURS=Env::getInt('jours', 364);
-define('DUREEJOUR',24*3600);
-
-//recupere le nombre d'inscriptions par jour sur la plage concernée
-$res = $globals->xdb->iterRow(
-        "SELECT  IF( date_ins>DATE_SUB(NOW(),INTERVAL $JOURS DAY),
-                     TO_DAYS(date_ins)-TO_DAYS(NOW()),
-                    ".(-($JOURS+1)).") AS jour,
-                 COUNT(user_id) AS nb
-           FROM  auth_user_md5 
-          WHERE  perms IN ('admin','user')
-       GROUP BY  jour");
-
-//genere des donnees compatibles avec GNUPLOT
-$inscrits='';
-
-// la première ligne contient le total des inscrits avant la date de départ (J - $JOURS)
-list(,$init_nb) = $res->next();
-$total = $init_nb;
-
-list($numjour, $nb) = $res->next();
-
-for ($i=-$JOURS;$i<=0;$i++) {
-    if ($numjour<$i) {
-        if(!list($numjour, $nb) = $res->next()) {
-            $numjour = 0;
-            $nb = 0;
-        }
-    }
-    if ($numjour==$i) $total+=$nb;
-    $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n";
-}
-
-//Genere le graphique à la volée avec GNUPLOT
-header( "Content-type: image/png");
-
-$delt = ($total - $init_nb)/10;
-$ymin = round($init_nb - $delt,0);
-$ymax = round($total   + $delt,0);
-
-$gnuplot = <<<EOF2
-gnuplot <<EOF
-
-set term png small color
-set size 640/480
-set xdata time
-set timefmt "%d/%m/%y"
-
-set format x "%m/%y"
-set yr [$ymin:$ymax]
-
-set title "Nombre d'inscrits"
-
-plot "-" using 1:2 title 'inscrits' with lines;
-{$inscrits}
-EOF
-EOF2;
-
-passthru($gnuplot);
-?>
diff --git a/htdocs/stats/graph_promo.php b/htdocs/stats/graph_promo.php
deleted file mode 100644 (file)
index e953a2a..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-
-new_skinned_page('index.tpl', AUTH_COOKIE);
-$promo = Env::getInt('promo', Session::getInt('promo'));
-
-//nombre de jours sur le graph
-$JOURS=364;
-define('DUREEJOUR',24*3600);
-$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);
-$JOURS = -$res->fetchOneCell();
-
-//recupere le nombre d'inscriptions par jour sur la plage concernée
-$res = $globals->xdb->iterRow(
-        "SELECT  IF( date_ins>DATE_SUB(NOW(),INTERVAL $JOURS DAY),
-                     TO_DAYS(date_ins)-TO_DAYS(NOW()),
-                    ".(-($JOURS+1)).") AS jour,
-                 COUNT(user_id) AS nb
-           FROM  auth_user_md5 
-          WHERE  promo = {?} AND perms IN ('admin','user')
-       GROUP BY  jour", $promo);
-
-//genere des donnees compatibles avec GNUPLOT
-$inscrits='';
-
-// la première ligne contient le total des inscrits avant la date de départ (J - $JOURS)
-list(,$init_nb) = $res->next();
-$total = $init_nb;
-
-list($numjour, $nb) = $res->next();
-
-for ($i=-$JOURS;$i<=0;$i++) {
-    if ($numjour<$i) {
-        if(!list($numjour, $nb) = $res->next()) {
-            $numjour = 0;
-            $nb = 0;
-        }
-    }
-    if ($numjour==$i) $total+=$nb;
-    $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n";
-}
-
-//Genere le graphique à la volée avec GNUPLOT
-header( "Content-type: image/png");
-
-$delt = ($total - $init_nb) / 10;
-$delt += ($delt < 1);
-$ymin = round($init_nb - $delt,0);
-$ymax = round($total   + $delt,0);
-
-$gnuplot = <<<EOF2
-gnuplot <<EOF
-
-set term png small color
-set size 640/480
-set xdata time
-set timefmt "%d/%m/%y"
-
-set format x "%m/%y"
-set yr [$ymin:$ymax]
-
-set title "Nombre d'inscrits de la promotion $promo."
-
-plot "-" using 1:2 title 'inscrits' with lines;
-{$inscrits}e
-EOF
-EOF2;
-
-passthru($gnuplot);
-?>
diff --git a/htdocs/stats/index.php b/htdocs/stats/index.php
deleted file mode 100644 (file)
index fd8d431..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2004 Polytechnique.org                                   *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_skinned_page("stats/index.tpl",AUTH_PUBLIC);
-$page->run();
-?>
diff --git a/htdocs/stats/nb_by_promo.php b/htdocs/stats/nb_by_promo.php
deleted file mode 100644 (file)
index 40d383b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_skinned_page('stats/nb_by_promo.tpl', AUTH_COOKIE);
-
-$res = $globals->xdb->iterRow(
-        "SELECT  promo,COUNT(*)
-           FROM  auth_user_md5
-          WHERE  promo > 1900 AND perms IN ('admin','user')
-       GROUP BY  promo
-       ORDER BY  promo");
-$max=0; $min=3000;
-
-while (list($promo,$nb) = $res->next()) {
-    $promo = intval($promo);
-    if(!isset($nbpromo[$promo/10])) {
-        $nbpromo[$promo/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides
-    }
-    $nbpromo[$promo/10][$promo%10]=Array('promo' => $promo, 'nb' => $nb);
-}
-
-$page->assign_by_ref('nbs', $nbpromo);
-$page->assign('min', $min-$min % 10);
-$page->assign('max', $max+10-$max%10);
-
-$page->run();
-?>
diff --git a/htdocs/stats/stats_promo.php b/htdocs/stats/stats_promo.php
deleted file mode 100644 (file)
index fb71b87..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_skinned_page("stats/stats_promo.tpl", AUTH_COOKIE);
-
-$promo = Env::getInt('promo', Session::getInt('promo'));
-$page->assign('promo',$promo);
-$page->run();
-
-?>
diff --git a/install.d/stats.files b/install.d/stats.files
deleted file mode 100644 (file)
index 514e038..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-htdocs/admin/gerer_coupure.php
-htdocs/stats/coupure.php
-htdocs/stats/graph_promo.php
-htdocs/stats/index.php
-htdocs/stats/nb_by_promo.php
-htdocs/stats/stats_promo.php
-templates/stats/coupure.tpl
-templates/stats/index.tpl
-templates/stats/nb_by_promo.tpl
-templates/stats/stats_promo.tpl
index d6057b0..9faee9f 100644 (file)
@@ -101,14 +101,14 @@ class PlatalModule extends PLModule
         if (Env::get('submit') == 'Valider' and Env::has('url')) {
             $globals->xdb->execute('UPDATE auth_user_quick
                                        SET redirecturl = {?} WHERE user_id = {?}',
-                                   $url, Session::getInt('uid')))
+                                   $url, Session::getInt('uid'));
             $log->log('carva_add', 'http://'.Env::get('url'));
             $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
         } elseif (Env::get('submit') == "Supprimer") {
             $globals->xdb->execute("UPDATE auth_user_quick
                                        SET redirecturl = ''
                                      WHERE user_id = {?}",
-                                   Session::getInt('uid')))
+                                   Session::getInt('uid'));
             $log->log("carva_del", $url);
             Post::kill('url');
             $page->trig('Redirection supprimée');
diff --git a/modules/stats.php b/modules/stats.php
new file mode 100644 (file)
index 0000000..fbfb2b4
--- /dev/null
@@ -0,0 +1,310 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  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                *
+ ***************************************************************************/
+
+function serv_to_str($params) {
+    $flags = explode(',',$params);
+    $trad = Array('web' => 'site web', 'mail'=> 'redirection mail',
+                  'smtp' => 'serveur sécurisé d\'envoi de mails',
+                  'nntp' => 'serveur des forums de discussion');
+    $ret = Array();
+    foreach ($flags as $flag) {
+        $ret[] = $trad[$flag];
+    }
+    return implode(', ',$ret);
+}
+
+class StatsModule extends PLModule
+{
+    function handlers()
+    {
+        return array(
+            'stats'           => $this->make_hook('stats',     AUTH_COOKIE),
+            'stats/evolution' => $this->make_hook('evolution', AUTH_COOKIE),
+            'stats/graph'     => $this->make_hook('graph',     AUTH_COOKIE),
+            'stats/graph/evolution'
+                              => $this->make_hook('graph_evo', AUTH_COOKIE),
+            'stats/promos'    => $this->make_hook('promos',    AUTH_COOKIE),
+
+            'stats/coupures'  => $this->make_hook('coupures',  AUTH_PUBLIC),
+        );
+    }
+
+    function handler_stats(&$page)
+    {
+        $page->changeTpl('stats/index.tpl');
+        return PL_OK;
+    }
+
+    function handler_evolution(&$page, $jours = 365)
+    {
+        $page->changeTpl('stats/evolution_inscrits.tpl');
+        $page->assign('jours', $jours);
+        return PL_OK;
+    }
+
+    function handler_graph_evo(&$page, $jours = 365)
+    {
+        global $globals;
+
+        define('DUREEJOUR',24*3600);
+
+        //recupere le nombre d'inscriptions par jour sur la plage concernée
+        $res = $globals->xdb->iterRow(
+                "SELECT  IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
+                             TO_DAYS(date_ins)-TO_DAYS(NOW()),
+                            ".(-($jours+1)).") AS jour,
+                         COUNT(user_id) AS nb
+                   FROM  auth_user_md5 
+                  WHERE  perms IN ('admin','user')
+               GROUP BY  jour");
+
+        //genere des donnees compatibles avec GNUPLOT
+        $inscrits='';
+
+        // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
+        list(,$init_nb) = $res->next();
+        $total = $init_nb;
+
+        list($numjour, $nb) = $res->next();
+
+        for ($i = -$jours; $i<=0; $i++) {
+            if ($numjour<$i) {
+                if(!list($numjour, $nb) = $res->next()) {
+                    $numjour = 0;
+                    $nb = 0;
+                }
+            }
+            if ($numjour==$i) $total+=$nb;
+            $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n";
+        }
+
+        //Genere le graphique à la volée avec GNUPLOT
+        header( "Content-type: image/png");
+
+        $delt = ($total - $init_nb)/10;
+        $ymin = round($init_nb - $delt,0);
+        $ymax = round($total   + $delt,0);
+
+        $gnuplot = <<<EOF2
+gnuplot <<EOF
+
+set term png small color
+set size 640/480
+set xdata time
+set timefmt "%d/%m/%y"
+
+set format x "%m/%y"
+set yr [$ymin:$ymax]
+
+set title "Nombre d'inscrits"
+
+plot "-" using 1:2 title 'inscrits' with lines;
+{$inscrits}
+EOF
+EOF2;
+
+        passthru($gnuplot);
+        exit;
+    }
+
+    function handler_graph(&$page, $promo = null)
+    {
+        global $globals;
+
+        if ($promo == 'all') {
+            // date de départ
+            $depart = 1920;
+
+            //recupere le nombre d'inscriptions par jour sur la plage concernée
+            $res = $globals->xdb->iterRow(
+                    "SELECT  promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100
+                       FROM  auth_user_md5
+                      WHERE  promo >= $depart AND deces = 0
+                   GROUP BY  promo");
+
+            //genere des donnees compatibles avec GNUPLOT
+            $inscrits='';
+
+            // la première ligne contient le total des inscrits avant la date de départ
+            list($annee, $nb) = $res->next();
+
+            for ($i = $depart; $i <= date("Y"); $i++) {
+                if ($annee < $i) {
+                    if(!list($annee, $nb) = $res->next()) {
+                        $annee = 0;
+                        $nb = 0;
+                    }
+                }
+                if ($nb > 0 || $i < date('Y'))
+                    $inscrits .= $i.' '.$nb."\n";
+            }
+
+            //Genere le graphique à la volée avec GNUPLOT
+            $fin = $i+2;
+
+            $gnuplot = <<<EOF2
+gnuplot <<EOF
+
+set term png small color
+set size 640/480
+set timefmt "%d/%m/%y"
+
+set xr [$depart:$fin]
+set yr [0:100]
+
+set title "Nombre d'inscrits par promotion depuis $depart."
+
+plot "-" using 1:2 title 'inscrits' with boxes;
+{$inscrits}
+EOF
+EOF2;
+
+        } else {
+            //nombre de jours sur le graph
+            $jours = 365;
+            define('DUREEJOUR',24*3600);
+            $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);
+            $jours = -$res->fetchOneCell();
+
+            //recupere le nombre d'inscriptions par jour sur la plage concernée
+            $res = $globals->xdb->iterRow(
+                    "SELECT  IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
+                                 TO_DAYS(date_ins)-TO_DAYS(NOW()),
+                                ".(-($jours+1)).") AS jour,
+                             COUNT(user_id) AS nb
+                       FROM  auth_user_md5 
+                      WHERE  promo = {?} AND perms IN ('admin','user')
+                   GROUP BY  jour", $promo);
+
+            //genere des donnees compatibles avec GNUPLOT
+            $inscrits='';
+
+            // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
+            list(,$init_nb) = $res->next();
+            $total = $init_nb;
+
+            list($numjour, $nb) = $res->next();
+
+            for ($i = -$jours;$i<=0;$i++) {
+                if ($numjour<$i) {
+                    if(!list($numjour, $nb) = $res->next()) {
+                        $numjour = 0;
+                        $nb = 0;
+                    }
+                }
+                if ($numjour==$i) $total+=$nb;
+                $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n";
+            }
+
+            //Genere le graphique à la volée avec GNUPLOT
+            $delt = ($total - $init_nb) / 10;
+            $delt += ($delt < 1);
+            $ymin = round($init_nb - $delt,0);
+            $ymax = round($total   + $delt,0);
+
+            $gnuplot = <<<EOF2
+gnuplot <<EOF
+
+set term png small color
+set size 640/480
+set xdata time
+set timefmt "%d/%m/%y"
+
+set format x "%m/%y"
+set yr [$ymin:$ymax]
+
+set title "Nombre d'inscrits de la promotion $promo."
+
+plot "-" using 1:2 title 'inscrits' with lines;
+{$inscrits}e
+EOF
+EOF2;
+        }
+
+        header('Content-type: image/png');
+        passthru($gnuplot);
+        exit;
+    }
+
+    function handler_promos(&$page, $promo = null)
+    {
+        global $globals;
+
+        $page->changeTpl('stats/nb_by_promo.tpl');
+
+        $res = $globals->xdb->iterRow(
+                "SELECT  promo,COUNT(*)
+                   FROM  auth_user_md5
+                  WHERE  promo > 1900 AND perms IN ('admin','user')
+               GROUP BY  promo
+               ORDER BY  promo");
+        $max=0; $min=3000;
+
+        while (list($p,$nb) = $res->next()) {
+            $p = intval($p);
+            if(!isset($nbpromo[$p/10])) {
+                $nbpromo[$p/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides
+            }
+            $nbpromo[$p/10][$p%10]=Array('promo' => $p, 'nb' => $nb);
+        }
+
+        $page->assign_by_ref('nbs', $nbpromo);
+        $page->assign('min', $min-$min % 10);
+        $page->assign('max', $max+10-$max%10);
+        $page->assign('promo', $promo);
+
+        return PL_OK;
+    }
+
+    function handler_coupures(&$page, $cp_id = null)
+    {
+        global $globals;
+
+        $page->changeTpl('stats/coupure.tpl');
+
+        if (!is_null($cp_id)) {
+            $res = $globals->xdb->query("SELECT  UNIX_TIMESTAMP(debut) AS debut,
+                                                 TIME_FORMAT(duree,'%kh%i') AS duree,
+                                                 resume, description, services
+                                           FROM  coupures
+                                          WHERE  id = {?}", $cp_id);
+            $cp  = $res->fetchOneAssoc();
+        }
+
+        if($cp) {
+            $cp['lg_services'] = serv_to_str($cp['services']);
+            $page->assign_by_ref('cp',$cp);
+        } else {
+            $beginning_date = date("Ymd", time() - 3600*24*21) . "000000";
+            $sql = "SELECT  id, UNIX_TIMESTAMP(debut) AS debut, resume, services
+                      FROM  coupures where debut > '$beginning_date' order by debut desc";
+            $page->assign('coupures', $globals->xdb->iterator($sql));
+        }
+
+        return PL_OK;
+    }
+}
+
+?>
index 97315b0..b58942c 100644 (file)
@@ -31,8 +31,8 @@
   <a href="{rel}/Docs/Ethique">Services et Ethique</a>
   | <a href="{rel}/Docs/Charte">Charte</a>
 {min_auth level=cookie}
-  | <a href="{rel}/stats/coupure.php">Disponibilité</a>
-  | <a href="{rel}/stats/">Statistiques</a>
+  | <a href="{rel}/stats/coupures">Disponibilité</a>
+  | <a href="{rel}/stats">Statistiques</a>
 {/min_auth}
 </div>
 
index 73da9f7..9cdf7d4 100644 (file)
@@ -20,7 +20,6 @@
 {*                                                                        *}
 {**************************************************************************}
 
-
 {if $cp}
 <table class="bicol" summary="Ruptures de service">
   <tr>
@@ -51,7 +50,7 @@
 </table>
 
 <p class="center">
-<a href="{$smarty.server.PHP_SELF}">retour à la liste</a>
+<a href="{rel}/stats/coupures">retour à la liste</a>
 </p>
 
 {else}
@@ -82,7 +81,7 @@
     </td>
     <td>
       <span class="smaller">
-        <a href="{$smarty.server.PHP_SELF}?cp_id={$cp.id}">{$cp.resume}</a>
+        <a href="{rel}/stats/coupures/{$cp.id}">{$cp.resume}</a>
       </span>
     </td>
     <td>
index 0c9cbff..9f300b8 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-
-<h1>
-  Evolution du nombre d'inscrits au site polytechnique.org
-</h1>
+<h1>Evolution du nombre d'inscrits au site polytechnique.org</h1>
 
 <div class="center">
-{if $smarty.request.jours eq 1826}
+{if $jours eq 1825}
 [<strong>depuis 5 ans</strong>]
 {else}
-[<a href="?jours=1826">depuis 5 ans</a>]
+[<a href="{rel}/stats/evolution/1825">depuis 5 ans</a>]
 {/if}
-{if $smarty.request.jours eq 731}
+{if $jours eq 730}
 [<strong>depuis 2 ans</strong>]
 {else}
-[<a href="?jours=731">depuis 2 ans</a>]
+[<a href="{rel}/stats/evolution/730">depuis 2 ans</a>]
 {/if}
-{if (!$smarty.request.jours) or ($smarty.request.jours eq 364)}
+{if $jours eq 365}
 [<strong>depuis un an</strong>]
 {else}
-[<a href="?jours=364">depuis un an</a>]
+[<a href="{rel}/stats/evolution/365">depuis un an</a>]
 {/if}
-{if $smarty.request.jours eq 30}
+{if $jours eq 30}
 [<strong>depuis un mois</strong>]
 {else}
-[<a href="?jours=30">depuis 1 mois</a>]
+[<a href="{rel}/stats/evolution/30">depuis 1 mois</a>]
 {/if}
 </div>
 <div class="center">
-  <img src="{"stats/graph_evolution.php?jours="|url}{$smarty.request.jours}" alt=" [ INSCRITS ] " />
+  <img src="{rel}/stats/graph/evolution/{$jours}" alt=" [ INSCRITS ] " />
 </div>
 
 {* vim:set et sw=2 sts=2 sws=2: *}
index ea24271..cf2de05 100644 (file)
@@ -30,9 +30,9 @@ Quelques statistiques sur l'utilisation des services de Polytechnique.org ainsi
 </p>
 
 <ul>
-<li><a href="evolution_inscrits.php">Nombre d'inscrits au cours du temps</a></li>
-<li><a href="stats_promo.php">Nombre d'inscrits dans ta promotion</a></li>
-<li><a href="nb_by_promo.php">Nombre d'inscrits par promotion</a></li>
+<li><a href="{rel}/stats/evolution">Nombre d'inscrits au cours du temps</a></li>
+<li><a href="{rel}/stats/promos/{$smarty.session.promo}">Nombre d'inscrits dans ta promotion</a></li>
+<li><a href="{rel}/stats/promos">Nombre d'inscrits par promotion</a></li>
 </ul>
 
 {* vim:set et sw=2 sts=2 sws=2: *}
index e95e816..8319e4e 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-
-<h1>
-  Inscrits par promo
-</h1>
+<h1>Inscrits par promo</h1>
 
 <p>
 Voici le nombre d'inscrits par promo :
@@ -40,10 +37,10 @@ Voici le nombre d'inscrits par promo :
     <th>{$lustre}-</th>
     {foreach item=nb from=$nb10}
     <td class="center">
-      {if $nb && $nb.promo eq $smarty.request.promo}
+      {if $nb && $nb.promo eq $promo}
       <span class='erreur'>{$nb.nb}</span>
       {elseif $nb}
-      <a href="?promo={$nb.promo}">{$nb.nb}</a>
+      <a href="{rel}/stats/promos/{$nb.promo}">{$nb.nb}</a>
       {else}
       -
       {/if}
@@ -53,16 +50,16 @@ Voici le nombre d'inscrits par promo :
   {/foreach}
 </table>
 
-{if $smarty.request.promo}
+{if $promo}
 
 <p class='center'>
-[<a href="{$smarty.server.PHP_SELF}">répartition des inscrits par promo</a>]
+[<a href="{rel}/stats/promos">répartition des inscrits par promo</a>]
 </p>
 
-<h1>Courbe d'inscription de la promo {$smarty.request.promo}</h1>
+<h1>Courbe d'inscription de la promo {$promo}</h1>
 
 <div class="center">
-  <img src="{"stats/graph_promo.php"|url}?promo={$smarty.request.promo}" alt=" [ INSCRITS ] " />
+  <img src="{rel}/stats/graph/{$promo}" alt=" [ INSCRITS ] " />
 </div>
 
 {else}
@@ -70,7 +67,7 @@ Voici le nombre d'inscrits par promo :
 <h1>Inscrits par promo en (%)</h1>
 
 <div class="center">
-  <img src="{"stats/graph_by_promo.php"|url}" alt="[graphe du nombre d'inscrits par promo]" />
+  <img src="{rel}/stats/graph/all" alt="[graphe du nombre d'inscrits par promo]" />
 </div>
 
 {/if}