7e2db82fd8a313e93462646451f40b0df5253038
[platal.git] / modules / payment / money.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 class Payment
23 {
24 // {{{ properties
25
26 var $id;
27 var $text;
28 var $url;
29 var $flags;
30 var $mail;
31 var $montant_min;
32 var $montant_max;
33 var $montant_def;
34 var $asso_id;
35
36 var $api = null;
37
38 // }}}
39 // {{{ constructor
40
41 function Payment($ref=-1)
42 {
43 global $globals;
44 $r = $ref==-1 ? $globals->money->mpay_def_id : $ref;
45 $res = XDB::query("SELECT id, text, url, flags, mail, montant_min, montant_max, montant_def, asso_id
46 FROM {$globals->money->mpay_tprefix}paiements WHERE id={?}", $r);
47 list($this->id, $this->text, $this->url, $flags, $this->mail,
48 $this->montant_min, $this->montant_max, $this->montant_def, $this->asso_id) = $res->fetchOneRow();
49
50 $this->montant_min = (float)$this->montant_min;
51 $this->montant_max = (float)$this->montant_max;
52 $this->flags = new Flagset($flags);
53
54 return $link;
55 }
56
57 // }}}
58 // {{{ function check()
59
60 function check($value)
61 {
62 $v = (float)strtr($value, ',', '.');
63 if ($this->montant_min > $v) {
64 return "Montant inférieur au minimum autorisé ({$this->montant_min}).";
65 } elseif ($v > $this->montant_max) {
66 return "Montant supérieur au maximum autorisé ({$this->montant_max}).";
67 } else {
68 return true;
69 }
70 }
71
72 // }}}
73 // {{{ function init()
74
75 function init($val, &$meth)
76 {
77 require_once dirname(__FILE__).'/money/'.$meth->inc;
78 $this->api = new $api($val);
79 }
80
81 // }}}
82 // {{{ function prepareform()
83
84 function prepareform()
85 {
86 return $this->api->prepareform($this);
87 }
88
89 function event()
90 {
91 if ($this->asso_id) {
92 $res = XDB::query("SELECT eid, a.diminutif FROM groupex.evenements AS e, groupex.asso AS a WHERE e.asso_id = {?} AND a.id = {?}", $this->asso_id, $this->asso_id);
93 return $res->fetchOneAssoc();
94 }
95 return null;
96 }
97 // }}}
98 }
99
100 // {{{ class PayMethod
101
102 class PayMethod
103 {
104 // {{{ properties
105
106 var $id;
107 var $text;
108 var $inc;
109
110 // }}}
111 // {{{ constructor
112
113 function PayMethod($id=-1)
114 {
115 global $globals;
116 $i = $id==-1 ? $globals->money->mpay_def_meth : $id;
117 $res = XDB::query("SELECT id,text,include FROM {$globals->money->mpay_tprefix}methodes WHERE id={?}", $i);
118 list($this->id, $this->text, $this->inc) = $res->fetchOneRow();
119 }
120
121 // }}}
122 }
123
124 // }}}
125
126 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
127 ?>