0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 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 | |
22 | // {{{ class PayReq |
23 | |
24 | class PayReq extends Validate |
25 | { |
26 | // {{{ properties |
27 | |
28 | var $titre; |
29 | var $site; |
30 | |
31 | var $montant; |
32 | var $montant_min; |
33 | var $montant_max; |
34 | |
35 | var $msg_reponse; |
36 | var $asso_id; |
37 | var $asso; |
38 | var $evt; |
39 | var $evt_intitule; |
40 | |
41 | var $rules = "Laisser la validation à un trésorier"; |
42 | // }}} |
43 | // {{{ constructor |
a3a049fc |
44 | |
45 | function PayReq($_uid, $_intitule, $_site, $_montant, $_msg, |
46 | $_montantmin=0, $_montantmax=999, $_asso_id = 0, |
47 | $_evt = 0, $_stamp=0) |
0337d704 |
48 | { |
0337d704 |
49 | $this->Validate($_uid, false, 'paiements', $_stamp); |
a3a049fc |
50 | |
0337d704 |
51 | $this->titre = $_intitule; |
52 | $this->site = $_site; |
53 | $this->msg_reponse = $_msg; |
54 | $this->asso_id = $_asso_id; |
55 | $this->evt = $_evt; |
56 | $this->montant = $_montant; |
57 | $this->montant_min = $_montantmin; |
58 | $this->montant_max = $_montantmax; |
59 | |
60 | if ($_asso_id) { |
08cce2ff |
61 | $res = XDB::query("SELECT nom FROM groupex.asso WHERE id = {?}", $_asso_id); |
0337d704 |
62 | $this->asso = $res->fetchOneCell(); |
63 | } |
64 | if ($_asso_id && $_evt) { |
08cce2ff |
65 | $res = XDB::query("SELECT intitule FROM groupex.evenements WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt); |
0337d704 |
66 | $this->evt_intitule = $res->fetchOneCell(); |
67 | } |
68 | } |
69 | |
70 | // }}} |
b479e26b |
71 | // {{{ function same_event() |
72 | function same_event($evt, $asso_id) |
73 | { |
74 | $wevt = 's:3:"evt";s:'.strlen($evt+"").':"'.$evt.'"'; |
75 | $wassoid = 's:7:"asso_id";s:'.strlen($asso_id + "").':"'.$asso_id.'"'; |
76 | $where = "%".$wassoid."%".$wevt."%"; |
77 | return $where; |
78 | } |
79 | // }}} |
029e6327 |
80 | // {{{ function submit() |
81 | // supprime les demandes de paiments pour le meme evenement |
82 | function submit() |
83 | { |
029e6327 |
84 | if ($this->evt) |
85 | { |
08cce2ff |
86 | XDB::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq::same_event($this->evt, $this->asso_id)); |
029e6327 |
87 | } |
88 | Validate::submit(); |
89 | } |
90 | // }}} |
91 | // {{{ function formu() |
0337d704 |
92 | |
93 | function formu() |
94 | { return 'include/form.valid.paiements.tpl'; } |
95 | |
96 | // }}} |
97 | // {{{ function _mail_subj |
98 | |
99 | function _mail_subj() |
100 | { |
101 | return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}"; |
102 | } |
103 | |
104 | // }}} |
105 | // {{{ function _mail_body |
106 | |
107 | function _mail_body($isok) |
108 | { |
109 | if ($isok) { |
110 | return " Le paiement que tu avais demandé pour {$this->titre} vient d'être créé.".($this->evt?" Il a bien été associé à la gestion de l'événement du groupe":""); |
111 | } else { |
112 | return " La demande que tu avais faite pour le paiement de {$this->intitule} a été refusée."; |
113 | } |
114 | } |
115 | |
116 | // }}} |
117 | // {{{ function commit() |
118 | |
119 | function commit() |
120 | { |
121 | global $globals; |
08cce2ff |
122 | $res = XDB::query("SELECT MAX(id) FROM paiement.paiements"); |
0337d704 |
123 | $id = $res->fetchOneCell()+1; |
08cce2ff |
124 | $ret = XDB::execute("INSERT INTO paiement.paiements VALUES |
0337d704 |
125 | ( {?}, {?}, {?}, '', |
126 | {?}, {?}, {?}, |
127 | {?}, {?}, {?} ) |
128 | ", |
129 | $id, $this->titre, $this->site, |
130 | $this->montant, $this->montant_min, $this->montant_max, |
131 | $this->bestalias."@".$globals->mail->domain, $this->msg_reponse, $this->asso_id); |
132 | if ($this->asso_id && $this->evt) |
08cce2ff |
133 | $ret = XDB::execute("UPDATE groupex.evenements SET paiement_id = {?} WHERE asso_id = {?} AND eid = {?}", $id, $this->asso_id, $this->evt); |
0337d704 |
134 | |
135 | return $ret; |
136 | } |
137 | |
138 | // }}} |
139 | } |
140 | |
141 | // }}} |
142 | |
143 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
144 | ?> |