From 82367abd45089b3c38471f63f39106a41be583a4 Mon Sep 17 00:00:00 2001 From: "Pierre Habouzit (MadCoder" Date: Sun, 5 Dec 2004 11:19:26 +0000 Subject: [PATCH] rationalize globals + money module * 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 --- htdocs/paiement/index.php | 4 ++-- htdocs/trezo/gere_operations.php | 32 ++++++++++----------------- htdocs/trezo/index.php | 30 +++++++++---------------- include/conf.d/banana.globals.inc.php | 2 +- include/conf.d/lists.globals.inc.php | 2 +- include/conf.d/mail.globals.inc.php | 2 +- include/conf.d/money.globals.inc.php | 9 ++++---- include/conf.d/money.menu.inc.php | 4 +++- include/conf.d/newsletter.globals.inc.php | 2 +- include/conf.d/search.globals.inc.php | 2 +- include/conf.d/skin.globals.inc.php | 2 +- include/conf.d/webredirect.globals.inc.php | 2 +- include/money.inc.php | 8 +++---- include/{ => money}/trezo.inc.php | 3 +-- include/xorg.globals.inc.php.in | 29 +++++++++++++++---------- include/xorg.inc.php | 5 +---- install.d/money/README | 35 ++++++++++++++++++++++++++++++ install.d/money/install.sql | 5 +++++ install.d/money/uninstall.sql | 4 ++++ templates/trezo/choix_date.tpl | 8 ++----- templates/trezo/index.tpl | 10 +++++---- upgrade/0.9.3/50_admin.sql | 2 +- upgrade/0.9.3/70_money.sql | 25 +++++++++++++++++++++ 23 files changed, 141 insertions(+), 86 deletions(-) rename include/{ => money}/trezo.inc.php (97%) create mode 100644 install.d/money/README create mode 100644 install.d/money/install.sql create mode 100644 install.d/money/uninstall.sql create mode 100644 upgrade/0.9.3/70_money.sql diff --git a/htdocs/paiement/index.php b/htdocs/paiement/index.php index 581c37d..39dccad 100644 --- a/htdocs/paiement/index.php +++ b/htdocs/paiement/index.php @@ -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(); ?> diff --git a/htdocs/trezo/gere_operations.php b/htdocs/trezo/gere_operations.php index 091363d..8160241 100644 --- a/htdocs/trezo/gere_operations.php +++ b/htdocs/trezo/gere_operations.php @@ -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'); diff --git a/htdocs/trezo/index.php b/htdocs/trezo/index.php index 926ecf2..ff13b21 100644 --- a/htdocs/trezo/index.php +++ b/htdocs/trezo/index.php @@ -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'); diff --git a/include/conf.d/banana.globals.inc.php b/include/conf.d/banana.globals.inc.php index 3e18547..419b8f0 100644 --- a/include/conf.d/banana.globals.inc.php +++ b/include/conf.d/banana.globals.inc.php @@ -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: ?> diff --git a/include/conf.d/lists.globals.inc.php b/include/conf.d/lists.globals.inc.php index 65b2c67..b5be7ea 100644 --- a/include/conf.d/lists.globals.inc.php +++ b/include/conf.d/lists.globals.inc.php @@ -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: ?> diff --git a/include/conf.d/mail.globals.inc.php b/include/conf.d/mail.globals.inc.php index 09f0878..79e1b42 100644 --- a/include/conf.d/mail.globals.inc.php +++ b/include/conf.d/mail.globals.inc.php @@ -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: ?> diff --git a/include/conf.d/money.globals.inc.php b/include/conf.d/money.globals.inc.php index 1d57304..b15f0da 100644 --- a/include/conf.d/money.globals.inc.php +++ b/include/conf.d/money.globals.inc.php @@ -23,14 +23,15 @@ 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: ?> diff --git a/include/conf.d/money.menu.inc.php b/include/conf.d/money.menu.inc.php index fbee059..d07419b 100644 --- a/include/conf.d/money.menu.inc.php +++ b/include/conf.d/money.menu.inc.php @@ -1,3 +1,5 @@ addPrivateEntry(XOM_SERVICES, 30, 'Micropaiments', 'paiement/'); +if ($globals->money->mpay_enable) { + $this->addPrivateEntry(XOM_SERVICES, 30, 'Micropaiments', 'paiement/'); +} ?> diff --git a/include/conf.d/newsletter.globals.inc.php b/include/conf.d/newsletter.globals.inc.php index 210a271..e9606e6 100644 --- a/include/conf.d/newsletter.globals.inc.php +++ b/include/conf.d/newsletter.globals.inc.php @@ -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: ?> diff --git a/include/conf.d/search.globals.inc.php b/include/conf.d/search.globals.inc.php index 338b5ac..802a057 100644 --- a/include/conf.d/search.globals.inc.php +++ b/include/conf.d/search.globals.inc.php @@ -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: ?> diff --git a/include/conf.d/skin.globals.inc.php b/include/conf.d/skin.globals.inc.php index 0a6dc57..26df496 100644 --- a/include/conf.d/skin.globals.inc.php +++ b/include/conf.d/skin.globals.inc.php @@ -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: ?> diff --git a/include/conf.d/webredirect.globals.inc.php b/include/conf.d/webredirect.globals.inc.php index ec4a9b2..9ac01f6 100644 --- a/include/conf.d/webredirect.globals.inc.php +++ b/include/conf.d/webredirect.globals.inc.php @@ -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: ?> diff --git a/include/money.inc.php b/include/money.inc.php index 3e094e2..e289853 100644 --- a/include/money.inc.php +++ b/include/money.inc.php @@ -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); } diff --git a/include/trezo.inc.php b/include/money/trezo.inc.php similarity index 97% rename from include/trezo.inc.php rename to include/money/trezo.inc.php index 342e36e..8d13d98 100644 --- a/include/trezo.inc.php +++ b/include/money/trezo.inc.php @@ -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='') } ?> - diff --git a/include/xorg.globals.inc.php.in b/include/xorg.globals.inc.php.in index 94ae3c6..4b20e5f 100644 --- a/include/xorg.globals.inc.php.in +++ b/include/xorg.globals.inc.php.in @@ -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(); } } } diff --git a/include/xorg.inc.php b/include/xorg.inc.php index eb3e7b2..013133d 100644 --- a/include/xorg.inc.php +++ b/include/xorg.inc.php @@ -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 index 0000000..a7aebca --- /dev/null +++ b/install.d/money/README @@ -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 index 0000000..1706707 --- /dev/null +++ b/install.d/money/install.sql @@ -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 index 0000000..07dd63d --- /dev/null +++ b/install.d/money/uninstall.sql @@ -0,0 +1,4 @@ + +delete from admin_h2 where h2id=9; +delete from admin_a where h2id=9; + diff --git a/templates/trezo/choix_date.tpl b/templates/trezo/choix_date.tpl index ff98cde..18c06d4 100644 --- a/templates/trezo/choix_date.tpl +++ b/templates/trezo/choix_date.tpl @@ -19,20 +19,16 @@ ***************************************************************************} -{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} -
Afficher la période suivante : - +
diff --git a/templates/trezo/index.tpl b/templates/trezo/index.tpl index b1b6318..fb4650a 100644 --- a/templates/trezo/index.tpl +++ b/templates/trezo/index.tpl @@ -21,13 +21,15 @@ {dynamic} -

- Trésorerie pour {$mon_sel} -

+

Trésorerie pour {$mon_sel}

+ +{perms level=admin} +

[éditer les comptes]

+{/perms} - + diff --git a/upgrade/0.9.3/50_admin.sql b/upgrade/0.9.3/50_admin.sql index 7e150bf..ad1ee47 100644 --- a/upgrade/0.9.3/50_admin.sql +++ b/upgrade/0.9.3/50_admin.sql @@ -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 index 0000000..aba2d0b --- /dev/null +++ b/upgrade/0.9.3/70_money.sql @@ -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; + -- 2.1.4
Solde en début de moisSolde en début de période
{$from_solde}