migrate trezo
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 10 Jul 2006 21:24:19 +0000 (21:24 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 10 Jul 2006 21:24:19 +0000 (21:24 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@424 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
htdocs/trezo/gere_operations.php [deleted file]
htdocs/trezo/index.php [deleted file]
include/money/trezo.inc.php
modules/trezo.php [new file with mode: 0644]
templates/trezo/choix_date.tpl
templates/trezo/index.tpl

index 9267faf..bb8b11c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,6 +28,9 @@ New:
     * Stats:
         - Switch to the new URI scheme.                                     -MC
 
+    * Trezo:
+        - Migrate to new URI scheme.                                        -MC
+
 
 ================================================================================
 VERSION 0.9.10                                                      29 Juin 2006
diff --git a/htdocs/trezo/gere_operations.php b/htdocs/trezo/gere_operations.php
deleted file mode 100644 (file)
index a368fdc..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');
-require_once("money/trezo.inc.php");
-new_admin_page('trezo/gere_operations.tpl');
-$page->assign('xorg_title','Polytechnique.org - Administration - Trezo : gestion');
-
-$action    = clean_request('action');
-$op_id     = clean_request('op_id');
-$op_date   = clean_request('op_date');
-$op_label  = clean_request('op_label');
-$op_credit = clean_request('op_credit');
-$op_debit  = clean_request('op_debit');
-
-$annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y");
-$mois_sel  = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m'));
-
-$from_date = "$annee_sel-$mois_sel-01";
-$to_date   = "$annee_sel-$mois_sel-31";
-$mon_sel   = $trim_fr[$mois_sel]." $annee_sel";
-
-switch($action) {
-    case "edit":
-        if ($op_id) {
-            $res = $globals->xdb->query("SELECT date,label,credit,debit FROM money_trezo WHERE id={?}", $op_id);
-            list($op_date,$op_label,$op_credit,$op_debit) = $res->fetchOneRow();
-        }
-        break;
-
-    case "update":
-        if (isDate($op_date)){
-            $mydatefr = explode("/",$op_date);
-            $mydate   = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0];
-        } else {
-            $mydate   = date("Y-m-d");
-        }
-
-        $sql = "replace into money_trezo set date='$mydate',label='".addslashes($op_label)."'";
-
-        if ($op_credit) { $sql .= ',credit='.$op_credit; }
-        if ($op_debit)  { $sql .= ",debit=".$op_debit;   }
-        if ($op_id)     { $sql .= ",id='$op_id'";        }
-        
-        $globals->xdb->execute($sql);
-        break;
-
-    case "del":
-        if ($op_id) {
-            $globals->xdb->execute("DELETE FROM money_trezo WHERE id={?}", $op_id);
-        }
-        break;
-}
-
-$page->assign('op_id',     $op_id);
-$page->assign('annee_sel', $annee_sel);
-$page->assign('mois_sel',  $mois_sel);
-$page->assign('op_date',   $op_date);
-$page->assign('op_label',  $op_label);
-$page->assign('op_debit',  $op_debit);
-$page->assign('op_credit', $op_credit);
-$page->assign('mon_sel',   $mon_sel);
-
-$page->assign('from_solde', solde_until($from_date));
-$page->assign('to_solde',   solde_until($to_date));
-$page->assign('month_arr',  $mois_fr);
-$page->assign('ops', $globals->xdb->iterator(
-            "SELECT id,date,label,credit,debit FROM money_trezo WHERE date >= {?} and date <= {?} ORDER BY date",
-            $from_date, $to_date));
-
-$page->run();
-?>
diff --git a/htdocs/trezo/index.php b/htdocs/trezo/index.php
deleted file mode 100644 (file)
index 57d1337..0000000
+++ /dev/null
@@ -1,57 +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");
-require_once("money/trezo.inc.php");
-new_skinned_page('trezo/index.tpl', AUTH_COOKIE);
-
-//Table operations :
-//+--------+---------------+------+-----+------------+----------------+
-//| Field  | Type          | Null | Key | Default    | Extra          |
-//+--------+---------------+------+-----+------------+----------------+
-//| id     | int(11)       |      | PRI | NULL       | auto_increment |
-//| date   | date          |      |     | 0000-00-00 |                |
-//| label  | varchar(80)   |      |     |            |                |
-//| credit | decimal(10,2) |      |     | 0.00       |                |
-//| debit  | decimal(10,2) |      |     | 0.00       |                |
-//+--------+---------------+------+-----+------------+----------------+
-
-$annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y");
-$mois_sel  = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m') - (intval(date('m')-1)%3));
-
-$mois_sel_fin = sprintf("%02u",$mois_sel + 2);
-$from_date    = "$annee_sel-$mois_sel-01";
-$to_date      = "$annee_sel-$mois_sel_fin-31";
-$mon_sel      = $trim_fr[$mois_sel]." $annee_sel";
-
-$page->assign('from_solde', solde_until($from_date));
-$page->assign('to_solde', solde_until($to_date));
-$page->assign('annee_sel', $annee_sel);
-$page->assign('mois_sel', $mois_sel);
-$page->assign('mon_sel', $mon_sel);
-$page->assign_by_ref('month_arr', $trim_fr);
-
-$page->assign('ops', $globals->xdb->iterator(
-            "SELECT date,label,credit,debit FROM money_trezo  WHERE date >= {?} and date <= {?} ORDER BY date",
-            $from_date, $to_date));
-
-$page->run();
-?>
index ca5a132..6f9b72a 100644 (file)
@@ -42,13 +42,10 @@ $trim_fr = array('01'=>'Janvier-Mars',
 
 function isDate($date)
 {
-  list($d, $m, $y) = split('[/.-]', $date);
-  $dummy = date("d/m/Y", mktime (0,0,0,$m,$d,$y));
-  $date = ereg_replace('-', '/', $date);
-  if ($dummy != $date)
-    return false;
-  else
-    return true;
+    list($d, $m, $y) = split('[/.-]', $date);
+    $dummy = date("d/m/Y", mktime (0,0,0,$m,$d,$y));
+    $date = ereg_replace('-', '/', $date);
+    return ($dummy == $date);
 }
 
 
diff --git a/modules/trezo.php b/modules/trezo.php
new file mode 100644 (file)
index 0000000..93dd253
--- /dev/null
@@ -0,0 +1,151 @@
+<?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                *
+ ***************************************************************************/
+
+class TrezoModule extends PLModule
+{
+    function handlers()
+    {
+        return array(
+            'trezo'     => $this->make_hook('default', AUTH_COOKIE),
+            'trezo/ops' => $this->make_hook('operation',  AUTH_COOKIE),
+        );
+    }
+
+    function handler_default(&$page)
+    {
+        global $globals;
+
+        $page->changeTpl('trezo/index.tpl');
+
+        require_once 'money/trezo.inc.php';
+
+        //table operations :
+        //+--------+---------------+------+-----+------------+----------------+
+        //| field  | type          | null | key | default    | extra          |
+        //+--------+---------------+------+-----+------------+----------------+
+        //| id     | int(11)       |      | pri | null       | auto_increment |
+        //| date   | date          |      |     | 0000-00-00 |                |
+        //| label  | varchar(80)   |      |     |            |                |
+        //| credit | decimal(10,2) |      |     | 0.00       |                |
+        //| debit  | decimal(10,2) |      |     | 0.00       |                |
+        //+--------+---------------+------+-----+------------+----------------+
+
+        $annee_sel = Env::get('annee', date('y'));
+        $mois_sel  = Env::get('mois', sprintf('%02u', date('m') - (intval(date('m') - 1) % 3)));
+
+        $mois_sel_fin = sprintf('%02u',$mois_sel + 2);
+        $from_date    = "$annee_sel-$mois_sel-01";
+        $to_date      = "$annee_sel-$mois_sel_fin-31";
+        $mon_sel      = $trim_fr[$mois_sel]." $annee_sel";
+
+        $page->assign('from_solde', solde_until($from_date));
+        $page->assign('to_solde', solde_until($to_date));
+        $page->assign('annee_sel', $annee_sel);
+        $page->assign('mois_sel', $mois_sel);
+        $page->assign('mon_sel', $mon_sel);
+        $page->assign_by_ref('month_arr', $trim_fr);
+
+        $page->assign('ops', $globals->xdb->iterator(
+                "SELECT date, label, credit, debit
+                   FROM money_trezo  WHERE date >= {?} and date <= {?} order by date", 
+                $from_date, $to_date));
+
+        return PL_OK;
+    }
+
+    function handler_op(&$page)
+    {
+        global $globals;
+
+        $page->changeTpl('trezo/gere_operations.tpl');
+
+        require_once 'money/trezo.inc.php';
+
+        $page->assign('xorg_title','Polytechnique.org - Administration - Trezo : gestion');
+
+        $action    = clean_request('action');
+        $op_id     = clean_request('op_id');
+        $op_date   = clean_request('op_date');
+        $op_label  = clean_request('op_label');
+        $op_credit = clean_request('op_credit');
+        $op_debit  = clean_request('op_debit');
+
+        $annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y");
+        $mois_sel  = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m'));
+
+        $from_date = "$annee_sel-$mois_sel-01";
+        $to_date   = "$annee_sel-$mois_sel-31";
+        $mon_sel   = $trim_fr[$mois_sel]." $annee_sel";
+
+        switch($action) {
+            case "edit":
+                if ($op_id) {
+                    $res = $globals->xdb->query("SELECT date,label,credit,debit FROM money_trezo WHERE id={?}", $op_id);
+                    list($op_date,$op_label,$op_credit,$op_debit) = $res->fetchOneRow();
+                }
+                break;
+
+            case "update":
+                if (isDate($op_date)){
+                    $mydatefr = explode("/",$op_date);
+                    $mydate   = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0];
+                } else {
+                    $mydate   = date("Y-m-d");
+                }
+
+                $sql = "replace into money_trezo set date='$mydate',label='".addslashes($op_label)."'";
+
+                if ($op_credit) { $sql .= ',credit='.$op_credit; }
+                if ($op_debit)  { $sql .= ',debit='.$op_debit;   }
+                if ($op_id)     { $sql .= ",id='$op_id'";        }
+
+                $globals->xdb->execute($sql);
+                break;
+
+            case "del":
+                if ($op_id) {
+                    $globals->xdb->execute("DELETE FROM money_trezo WHERE id={?}", $op_id);
+                }
+                break;
+        }
+
+        $page->assign('op_id',     $op_id);
+        $page->assign('annee_sel', $annee_sel);
+        $page->assign('mois_sel',  $mois_sel);
+        $page->assign('op_date',   $op_date);
+        $page->assign('op_label',  $op_label);
+        $page->assign('op_debit',  $op_debit);
+        $page->assign('op_credit', $op_credit);
+        $page->assign('mon_sel',   $mon_sel);
+
+        $page->assign('from_solde', solde_until($from_date));
+        $page->assign('to_solde',   solde_until($to_date));
+        $page->assign('month_arr',  $mois_fr);
+        $page->assign('ops', $globals->xdb->iterator(
+                    "SELECT id, date, label, credit, debit FROM money_trezo
+                      WHERE date >= {?} and date <= {?} ORDER BY date", 
+                    $from_date, $to_date));
+
+        return PL_OK;
+    }
+}
+
+?>
index 4e52e53..304b3ee 100644 (file)
@@ -20,8 +20,7 @@
 {*                                                                        *}
 {**************************************************************************}
 
-
-<form method="post" action="{$smarty.server.PHP_SELF}">
+<form method="post" action="{rel}/{$platal->path}">
   <div class="center">
     <input type="hidden" name="action" value="lister" />
     Afficher la période suivante :
index 407186d..715b9b7 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-
-
 <h1>Tr&eacute;sorerie pour {$mon_sel}</h1>
 
 {perms level=admin}
-<p>[<a href="{rel}/trezo/gere_operations.php">éditer les comptes</a>]</p>
+<p>[<a href="{rel}/trezo/ops">éditer les comptes</a>]</p>
 {/perms}
 
 <table class="bicol">