rationalize globals + money module
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Sun, 5 Dec 2004 11:19:26 +0000 (11:19 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:26:30 +0000 (23:26 +0200)
* Core :
    - use a static function to initialize $globals.

* Money :
    - brand new module.
    - remove trezo.operations --> x4dat.money_trezo.
    - corrects a few bugs in interface.

git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-50

23 files changed:
htdocs/paiement/index.php
htdocs/trezo/gere_operations.php
htdocs/trezo/index.php
include/conf.d/banana.globals.inc.php
include/conf.d/lists.globals.inc.php
include/conf.d/mail.globals.inc.php
include/conf.d/money.globals.inc.php
include/conf.d/money.menu.inc.php
include/conf.d/newsletter.globals.inc.php
include/conf.d/search.globals.inc.php
include/conf.d/skin.globals.inc.php
include/conf.d/webredirect.globals.inc.php
include/money.inc.php
include/money/trezo.inc.php [moved from include/trezo.inc.php with 97% similarity]
include/xorg.globals.inc.php.in
include/xorg.inc.php
install.d/money/README [new file with mode: 0644]
install.d/money/install.sql [new file with mode: 0644]
install.d/money/uninstall.sql [new file with mode: 0644]
templates/trezo/choix_date.tpl
templates/trezo/index.tpl
upgrade/0.9.3/50_admin.sql
upgrade/0.9.3/70_money.sql [new file with mode: 0644]

index 581c37d..39dccad 100644 (file)
@@ -22,7 +22,7 @@
 require_once("xorg.inc.php");
 new_skinned_page('paiment/index.tpl', AUTH_MDP);
 require_once('profil.func.inc.php');
-require_once("money.inc.php");
+require_once('money.inc.php');
 
 // initialisation
 $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : 'select';
@@ -51,6 +51,6 @@ $page->assign('montant',$val);
 $page->assign('meth', $meth);
 $page->assign('pay',  $pay);
 
-$page->assign('prefix',$globals->money->table_prefix);
+$page->assign('prefix',$globals->money->mpay_tprefix);
 $page->run();
 ?>
index 091363d..8160241 100644 (file)
@@ -20,7 +20,7 @@
  ***************************************************************************/
 
 require_once('xorg.inc.php');
-require_once("trezo.inc.php");
+require_once("money/trezo.inc.php");
 new_admin_page('trezo/gere_operations.tpl');
 
 //Table operations :
@@ -35,31 +35,23 @@ new_admin_page('trezo/gere_operations.tpl');
 //+--------+---------------+------+-----+------------+----------------+
 
 $action = clean_request('action');
-$annee_sel = clean_request('annee');
-$mois_sel = clean_request('mois');
 $operation_id = clean_request('operation_id');
 $operation_date = clean_request('operation_date');
 $operation_label = clean_request('operation_label');
 $operation_credit = clean_request('operation_credit');
 $operation_debit = clean_request('operation_debit');
 
-//selection mois et date
-if (!$annee_sel) $annee_sel = date("Y");
-    
-if ($mois_sel) {
-    $from_date = $annee_sel."-".$mois_sel."-01";
-    $to_date = $annee_sel."-".$mois_sel."-31";
-    $mon_sel = $mois_fr[$mois_sel]." ".$annee_sel;
-} else {
-    $from_date = date("Y-m")."-01";
-    $to_date = date("Y-m")."-31";
-    $mon_sel = $mois_fr[date("m")]." ".date("Y");
-}
+$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 ($operation_id) {
-            $res=$globals->db->query("select date,label,credit,debit from trezo.operations where id='$operation_id'");
+            $res=$globals->db->query("select date,label,credit,debit from money_trezo where id='$operation_id'");
             list($operation_date,$operation_label,$operation_credit,$operation_debit)=mysql_fetch_row($res);
         }
     break;
@@ -83,14 +75,14 @@ switch($action) {
         }
 
         if ($operation_id) {
-            $sql = "update trezo.operations set date='".$mydate."',label='".$operation_label."'".$sql_add." where id='".$operation_id."'";
+            $sql = "update money_trezo set date='".$mydate."',label='".$operation_label."'".$sql_add." where id='".$operation_id."'";
         } else { 
-            $sql = "insert into trezo.operations set date='".$mydate."',label='".$operation_label."'".$sql_add;
+            $sql = "insert into money_trezo set date='".$mydate."',label='".$operation_label."'".$sql_add;
         }
     break;
     case "del":
         if ($operation_id) {
-            $globals->db->query("delete from trezo.operations where id='".$operation_id."'");
+            $globals->db->query("delete from money_trezo where id='".$operation_id."'");
         }
     break;
 
@@ -110,7 +102,7 @@ $page->assign('to_solde', solde_until($to_date));
 $page->assign_by_ref('month_arr', $mois_fr);
 
 $sql = "SELECT id,date,label,credit,debit 
-        FROM trezo.operations
+        FROM money_trezo
         WHERE date >= '$from_date' AND date <= '$to_date' 
         ORDER BY date";
 $page->mysql_assign($sql, 'ops');
index 926ecf2..ff13b21 100644 (file)
@@ -20,7 +20,7 @@
  ***************************************************************************/
 
 require_once("xorg.inc.php");
-require_once("trezo.inc.php");
+require_once("money/trezo.inc.php");
 new_admin_page('trezo/index.tpl');
 
 //Table operations :
@@ -34,32 +34,22 @@ new_admin_page('trezo/index.tpl');
 //| debit  | decimal(10,2) |      |     | 0.00       |                |
 //+--------+---------------+------+-----+------------+----------------+
 
-$annee_sel = clean_request('annee');
-$mois_sel = clean_request('mois');
+$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));
 
-if(isset($_REQUEST['action']) && $_REQUEST['action']=='lister') {
-    if (!$annee_sel)
-        $annee_sel = date("Y");
-    $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;
-} else {
-    $mois_sel = sprintf("%02u", date("m") - (date("m")%3) + 1);
-    $mois_sel_fin = sprintf("%02u",$mois_sel + 2);
-
-    $from_date = date("Y")."-".$mois_sel."-01";
-    $to_date = date("Y")."-".$mois_sel_fin."-31";
-    $mon_sel = $trim_fr[$mois_sel]." ".date("Y");
-}
+$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);
 
-$sql = "SELECT date,label,credit,debit FROM trezo.operations 
+$sql = "SELECT date,label,credit,debit FROM money_trezo 
         WHERE date >= '$from_date' and date <= '$to_date'
         ORDER BY date";
 $page->mysql_assign($sql,'ops');
index 3e18547..419b8f0 100644 (file)
@@ -34,7 +34,7 @@ class BananaConfig
 
 // }}}
 
-$this->banana = new BananaConfig;
+$globals->banana = new BananaConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 65b2c67..b5be7ea 100644 (file)
@@ -34,7 +34,7 @@ class ListsConfig
 
 // }}}
 
-$this->lists = new ListsConfig;
+$globals->lists = new ListsConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 09f0878..79e1b42 100644 (file)
@@ -29,7 +29,7 @@ class MailConfig
 
 // }}}
 
-$this->mail = new MailConfig;
+$globals->mail = new MailConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 1d57304..b15f0da 100644 (file)
 
 class MoneyConfig
 {
-    var $payment_def  = 0;
-    var $method_def   = 0;
-    var $table_prefix = 'paiement.';
+    var $mpay_enable   = true;
+    var $mpay_def_id   = 0;
+    var $mpay_def_meth = 0;
+    var $mpay_tprefix  = 'paiement.';
 }
 
 // }}}
 
-$this->money = new MoneyConfig;
+$globals->money = new MoneyConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index fbee059..d07419b 100644 (file)
@@ -1,3 +1,5 @@
 <?php
-$this->addPrivateEntry(XOM_SERVICES, 30, 'Micropaiments', 'paiement/');
+if ($globals->money->mpay_enable) {
+    $this->addPrivateEntry(XOM_SERVICES, 30, 'Micropaiments', 'paiement/');
+}
 ?>
index 210a271..e9606e6 100644 (file)
@@ -29,7 +29,7 @@ class NLConfig
 
 // }}}
 
-$this->newsletter = new NLConfig;
+$globals->newsletter = new NLConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 338b5ac..802a057 100644 (file)
@@ -31,7 +31,7 @@ class SearchConfig
 
 // }}}
 
-$this->search = new SearchConfig;
+$globals->search = new SearchConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 0a6dc57..26df496 100644 (file)
@@ -30,7 +30,7 @@ class SkinConfig
 
 // }}}
 
-$this->skin = new SkinConfig;
+$globals->skin = new SkinConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index ec4a9b2..9ac01f6 100644 (file)
@@ -28,7 +28,7 @@ class WebRedirConfig
 
 // }}}
 
-$this->webredirect = new WebRedirConfig;
+$globals->webredirect = new WebRedirConfig;
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 3e094e2..e289853 100644 (file)
@@ -42,9 +42,9 @@ class Payment
     function Payment($ref=-1)
     {
         global $globals;
-        $r   = $ref==-1 ? $globals->money->payment_def : $ref;
+        $r   = $ref==-1 ? $globals->money->mpay_def_id : $ref;
         $res = $globals->db->query("SELECT  id, text, url, flags, mail, montant_min, montant_max, montant_def
-                                      FROM  {$globals->money->table_prefix}paiements WHERE id='$r'");
+                                      FROM  {$globals->money->mpay_tprefix}paiements WHERE id='$r'");
         list($this->id, $this->text, $this->url, $flags, $this->mail,
                 $this->montant_min, $this->montant_max, $this->montant_def)
             = mysql_fetch_row($res);
@@ -105,8 +105,8 @@ class PayMethod
     function PayMethod($id=-1)
     {
         global $globals;
-        $i   = $id==-1 ? $globals->money->method_def : $id;
-        $res = $globals->db->query("SELECT id,text,include FROM {$globals->money->table_prefix}methodes WHERE id='$i'");
+        $i   = $id==-1 ? $globals->money->mpay_def_meth : $id;
+        $res = $globals->db->query("SELECT id,text,include FROM {$globals->money->mpay_tprefix}methodes WHERE id='$i'");
         list($this->id, $this->text, $this->inc) = mysql_fetch_row($res);
         mysql_free_result($res);
     } 
similarity index 97%
rename from include/trezo.inc.php
rename to include/money/trezo.inc.php
index 342e36e..8d13d98 100644 (file)
@@ -55,7 +55,7 @@ function isDate($date)
 function solde_until($date='')
 {
     global $globals;
-    $sql = "select sum(credit)-sum(debit) from trezo.operations";
+    $sql = "select sum(credit)-sum(debit) from money_trezo";
     if(!empty($date))
         $sql .= " where date <= '$date'";
     $res = $globals->db->query($sql);
@@ -64,4 +64,3 @@ function solde_until($date='')
 }
 
 ?>
-
index 94ae3c6..4b20e5f 100644 (file)
@@ -54,14 +54,21 @@ class XorgGlobals extends DiogenesCoreGlobals
     var $spoolroot = "/var/spool/xorg";
     var $root      = null;
 
-    function XorgGlobals() {
-        $this->root = dirname(dirname(__FILE__));
+    function init()
+    {
+        global $globals;
+        require_once("xorg/menu.inc.php");
+        require_once('xorg/session.inc.php');
 
-        foreach(glob($this->root.'/include/conf.d/*.globals.inc.php') as $inc) {
+        $globals = new XorgGlobals;
+
+        $globals->root = dirname(dirname(__FILE__));
+
+        foreach(glob($globals->root.'/include/conf.d/*.globals.inc.php') as $inc) {
             require_once($inc);
         }
         
-        $array = parse_ini_file($this->root.'/configs/platal.conf', true);
+        $array = parse_ini_file($globals->root.'/configs/platal.conf', true);
         if (!is_array($array)) {
             return;
         }
@@ -69,21 +76,21 @@ class XorgGlobals extends DiogenesCoreGlobals
         foreach ($array as $cat=>$conf) {
             $c = strtolower($cat);
             foreach ($conf as $key=>$val) {
-                if ($c == 'core' && isset($this->$key)) {
-                    $this->$key=$val;
+                if ($c == 'core' && isset($globals->$key)) {
+                    $globals->$key=$val;
                 } else {
-                    $this->$c->$key = $val;
+                    $globals->$c->$key = $val;
                 }
             }
         }
         
-        $this->menu = new XOrgMenu($this->root.'/include/conf.d/');
+        $globals->menu = new XOrgMenu($globals->root.'/include/conf.d/');
 
         session_start();
 
-        $this->dbconnect();
-        if ($this->debug) {
-            $this->db->trace_on();
+        $globals->dbconnect();
+        if ($globals->debug) {
+            $globals->db->trace_on();
         }
     }
 }
index eb3e7b2..013133d 100644 (file)
@@ -44,10 +44,7 @@ define('NO_SKIN', 1);
 // {{{ import class definitions
 
 require_once("xorg.globals.inc.php");
-require_once("xorg/menu.inc.php");
-require_once("xorg/session.inc.php");
-
-$globals = new XorgGlobals;
+XorgGlobals::init();
 
 // }}}
 // {{{ function _new_page()
diff --git a/install.d/money/README b/install.d/money/README
new file mode 100644 (file)
index 0000000..a7aebca
--- /dev/null
@@ -0,0 +1,35 @@
+
+  Notes for the money module for plat/al
+
+STATUS
+------
+
+TODO: 
+  tables are atm in paiments.* and we should put it in x4dat.money_*
+  we have to wait for x.net here.
+
+CONFIG OPTIONS
+--------------
+
+  All settings of the module are shown here with their default and meaning
+
+  [Money]
+
+  mpay_enable   = 1     ; enable micro-payments
+  mpay_def_id   = 0     ; id of the default micro-payment id
+  mpay_def_meth = 0     ; id of the default payment method
+  mpay_tprefix  = paiments. 
+                        ; obsolete when TODO will be closed
+
+
+BUGS
+----
+
+  http://trackers.polytechnique.org/index.php?cat=16
+
+
+DEPENDS
+-------
+
+  platal
+
diff --git a/install.d/money/install.sql b/install.d/money/install.sql
new file mode 100644 (file)
index 0000000..1706707
--- /dev/null
@@ -0,0 +1,5 @@
+INSERT INTO `admin_h2` VALUES (2,9,'Trésorerie',60);
+
+INSERT INTO `admin_a` VALUES (9,'Comptes','admin/gere_operations.php',0);
+INSERT INTO `admin_a` VALUES (9,'Paiements','admin/gerer_paiement.php',10);
+
diff --git a/install.d/money/uninstall.sql b/install.d/money/uninstall.sql
new file mode 100644 (file)
index 0000000..07dd63d
--- /dev/null
@@ -0,0 +1,4 @@
+
+delete from admin_h2 where h2id=9;
+delete from admin_a  where h2id=9;
+
index ff98cde..18c06d4 100644 (file)
  ***************************************************************************}
 
 
-{assign var=def_month value=$smarty.now|date_format:"%m"}
-{assign var=def_year value=$smarty.now|date_format:"%Y"}
-{assign var=month value=$smarty.request.mois|default:$def_month}
-
 <form method="post" action="{$smarty.server.PHP_SELF}">
   <div class="center">
     <input type="hidden" name="action" value="lister" />
     Afficher la période suivante :
     <select name="mois" size="1">
       {foreach key=key item=item from=$month_arr}
-      <option value="{$key}" {if $month eq $key}selected="selected"{/if}>{$item}</option>
+      <option value="{$key}" {if $mois_sel eq $key}selected="selected"{/if}>{$item}</option>
       {/foreach}
     </select>
-    <input type="text" name="annee" size="10" value="{$smarty.request.annee|default:$def_year}" />
+    <input type="text" name="annee" size="10" value="{$smarty.request.annee|default:$annee_sel}" />
     <input type="submit" value="lister" />
   </div>
 </form>
index b1b6318..fb4650a 100644 (file)
 
 {dynamic}
 
-<h1>
-  Tr&eacute;sorerie pour {$mon_sel}
-</h1>
+<h1>Tr&eacute;sorerie pour {$mon_sel}</h1>
+
+{perms level=admin}
+<p>[<a href="{rel}/trezo/gere_operations.php">éditer les comptes</a>]</p>
+{/perms}
 
 <table class="bicol">
 <tr>
-  <th>Solde en début de mois</th>
+  <th>Solde en début de période</th>
 </tr>
 <tr>
   <td class="right">{$from_solde}</td>
index 7e150bf..ad1ee47 100644 (file)
@@ -83,7 +83,7 @@ insert into admin_a values(7, 'Listes', 'admin/lists.php', 10);
 insert into admin_a values(8, 'Valider', 'admin/valider.php',  0);
 insert into admin_a values(8, 'Événements', 'admin/evenements.php', 10);
 
-insert into admin_a values(9, 'Comptes', 'admin/gere_operations.php', 0);
+insert into admin_a values(9, 'Comptes', 'trezo/gere_operations.php', 0);
 insert into admin_a values(9, 'Paiements', 'admin/gerer_paiement.php', 10);
 
 insert into admin_a values(10, 'Table auth_user_md5', 'admin/FormatePrenomNOM.php', 0);
diff --git a/upgrade/0.9.3/70_money.sql b/upgrade/0.9.3/70_money.sql
new file mode 100644 (file)
index 0000000..aba2d0b
--- /dev/null
@@ -0,0 +1,25 @@
+-- MySQL dump 9.11
+--
+-- Host: localhost    Database: trezo
+-- ------------------------------------------------------
+-- Server version      4.0.22-log
+
+--
+-- Table structure for table `operations`
+--
+
+CREATE TABLE `money_trezo` (
+  `id` int(11) NOT NULL auto_increment,
+  `date` date NOT NULL default '0000-00-00',
+  `label` varchar(80) NOT NULL default '',
+  `credit` decimal(10,2) NOT NULL default '0.00',
+  `debit` decimal(10,2) NOT NULL default '0.00',
+  PRIMARY KEY  (`id`)
+) TYPE=MyISAM COMMENT='Table des comptes de l''assoce';
+
+insert into money_trezo
+   select * from trezo.operations;
+
+drop table trezo.operations;
+drop database trezo;
+