Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
0337d704 | 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 | ||
0337d704 | 22 | class Payment |
23 | { | |
a1cce2cd SJ |
24 | public $id; |
25 | public $text; | |
26 | public $url; | |
27 | public $flags; | |
28 | public $mvarail; | |
29 | public $amount_min; | |
30 | public $amount_max; | |
31 | public $amount_def; | |
32 | public $asso_id; | |
33 | ||
34 | public $api = null; | |
35 | ||
36 | function Payment($ref = -1) | |
0337d704 | 37 | { |
38 | global $globals; | |
a1cce2cd SJ |
39 | |
40 | $r = ($ref == -1) ? $globals->money->mpay_def_id : $ref; | |
41 | $res = XDB::query('SELECT id, text, url, flags, mail, amount_min, amount_max, amount_def, asso_id | |
42 | FROM payments | |
43 | WHERE id = {?}', $r); | |
0337d704 | 44 | list($this->id, $this->text, $this->url, $flags, $this->mail, |
a690a74c | 45 | $this->amount_min, $this->amount_max, $this->amount_def, $this->asso_id) = $res->fetchOneRow(); |
eaf30d86 | 46 | |
a690a74c DB |
47 | $this->amount_min = (float)$this->amount_min; |
48 | $this->amount_max = (float)$this->amount_max; | |
a1cce2cd | 49 | $this->flags = new PlFlagSet($flags); |
0337d704 | 50 | } |
51 | ||
0337d704 | 52 | function check($value) |
53 | { | |
54 | $v = (float)strtr($value, ',', '.'); | |
a690a74c DB |
55 | if ($this->amount_min > $v) { |
56 | return "Montant inférieur au minimum autorisé ({$this->amount_min})."; | |
57 | } elseif ($v > $this->amount_max) { | |
58 | return "Montant supérieur au maximum autorisé ({$this->amount_max})."; | |
0337d704 | 59 | } else { |
60 | return true; | |
61 | } | |
62 | } | |
63 | ||
26ba053e | 64 | function init($val, $meth) |
0337d704 | 65 | { |
a1cce2cd | 66 | require_once dirname(__FILE__) . '/money/' . $meth->inc; |
0337d704 | 67 | $this->api = new $api($val); |
68 | } | |
69 | ||
0337d704 | 70 | function prepareform() |
71 | { | |
72 | return $this->api->prepareform($this); | |
73 | } | |
3b3e9d15 | 74 | |
75 | function event() | |
76 | { | |
a3a049fc | 77 | if ($this->asso_id) { |
614199d8 | 78 | $res = XDB::query("SELECT e.eid, a.diminutif |
eb41eda9 FB |
79 | FROM group_events AS e |
80 | INNER JOIN groups AS a ON (e.asso_id = a.id) | |
81 | LEFT JOIN group_event_participants AS p ON (p.eid = e.eid AND p.uid = {?}) | |
614199d8 FB |
82 | WHERE e.paiement_id = {?} AND p.uid IS NULL", S::i('uid'), $this->id); |
83 | if ($res->numRows()) { | |
84 | return $res->fetchOneAssoc(); | |
85 | } | |
3b3e9d15 | 86 | } |
87 | return null; | |
88 | } | |
0337d704 | 89 | } |
90 | ||
0337d704 | 91 | class PayMethod |
92 | { | |
a1cce2cd SJ |
93 | public $id; |
94 | public $text; | |
95 | public $inc; | |
0337d704 | 96 | |
a1cce2cd | 97 | function PayMethod($id = -1) |
0337d704 | 98 | { |
99 | global $globals; | |
a1cce2cd SJ |
100 | |
101 | $i = ($id == -1) ? $globals->money->mpay_def_meth : $id; | |
102 | $res = XDB::query('SELECT id, text, include | |
103 | FROM payment_methods | |
104 | WHERE id = {?}', $i); | |
0337d704 | 105 | list($this->id, $this->text, $this->inc) = $res->fetchOneRow(); |
eaf30d86 | 106 | } |
0337d704 | 107 | } |
108 | ||
a7de4ef7 | 109 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 110 | ?> |