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