Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 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 | |
eaf30d86 | 27 | |
612a2d8a | 28 | public $titre; |
29 | public $site; | |
0337d704 | 30 | |
612a2d8a | 31 | public $montant; |
32 | public $montant_min; | |
33 | public $montant_max; | |
0337d704 | 34 | |
612a2d8a | 35 | public $msg_reponse; |
36 | public $asso_id; | |
37 | public $asso; | |
38 | public $evt; | |
39 | public $evt_intitule; | |
0a9d877e | 40 | public $public; |
b9c62780 AL |
41 | public $rib_id; |
42 | public $rib_nom; | |
0337d704 | 43 | |
1539dae9 | 44 | public $rules = "Vérifier que les balises <salutation>, <prenom>, <nom>, <montant> et <comment> n'ont pas été modifiées. |
19de13f1 DB |
45 | Vérifier que le demandeur n'a pas laissé les crochets []. |
46 | Si le télépaiement n'est pas lié à un groupe ou supérieur à 51 euros, laisser la validation à un trésorier"; | |
0337d704 | 47 | // }}} |
48 | // {{{ constructor | |
a3a049fc | 49 | |
26ba053e | 50 | public function __construct(User $_user, $_intitule, $_site, $_montant, $_msg, |
612a2d8a | 51 | $_montantmin=0, $_montantmax=999, $_asso_id = 0, |
0a9d877e | 52 | $_evt = 0, $_public = false, $_stamp = 0) |
0337d704 | 53 | { |
5daf68f6 | 54 | parent::__construct($_user, false, 'paiements', $_stamp); |
a3a049fc | 55 | |
0337d704 | 56 | $this->titre = $_intitule; |
57 | $this->site = $_site; | |
58 | $this->msg_reponse = $_msg; | |
2ac0bcee FB |
59 | $this->asso_id = (string)$_asso_id; |
60 | $this->evt = (string)$_evt; | |
0337d704 | 61 | $this->montant = $_montant; |
62 | $this->montant_min = $_montantmin; | |
63 | $this->montant_max = $_montantmax; | |
0a9d877e | 64 | $this->public = $_public; |
0337d704 | 65 | |
66 | if ($_asso_id) { | |
eb41eda9 | 67 | $res = XDB::query("SELECT nom FROM groups WHERE id = {?}", $_asso_id); |
0337d704 | 68 | $this->asso = $res->fetchOneCell(); |
69 | } | |
70 | if ($_asso_id && $_evt) { | |
eb41eda9 | 71 | $res = XDB::query("SELECT intitule FROM group_events WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt); |
0337d704 | 72 | $this->evt_intitule = $res->fetchOneCell(); |
73 | } | |
b9c62780 AL |
74 | // for future use, when anims can choose there bankaccounts |
75 | if ($this->rib_id) { | |
76 | $res = XDB::query("SELECT owner FROM payment_bankaccounts WHERE id = {?}", $this->rib_id); | |
77 | $this->rib_nom = $res->fetchOneCell(); | |
78 | } | |
0337d704 | 79 | } |
80 | ||
81 | // }}} | |
612a2d8a | 82 | // {{{ function same_event() |
83 | ||
84 | static public function same_event($evt, $asso_id) | |
b479e26b | 85 | { |
86 | $wevt = 's:3:"evt";s:'.strlen($evt+"").':"'.$evt.'"'; | |
87 | $wassoid = 's:7:"asso_id";s:'.strlen($asso_id + "").':"'.$asso_id.'"'; | |
88 | $where = "%".$wassoid."%".$wevt."%"; | |
89 | return $where; | |
90 | } | |
eaf30d86 | 91 | |
612a2d8a | 92 | // }}} |
20934085 | 93 | // {{{ function accept() |
94 | ||
95 | // check the message | |
96 | public function accept() | |
97 | { | |
98 | // no text [AI JMIAJM IJA MIJ] | |
857bab90 | 99 | if (preg_match('/\[[-\'"a-zA-Z ]+\]/', replace_accent($this->msg_reponse))) { |
a7d35093 | 100 | $this->trigError("La demande de paiement n'est pas valide. Merci de compléter le texte avant de la soumettre"); |
20934085 | 101 | return false; |
102 | } | |
103 | if (!preg_match('/<montant>/', $this->msg_reponse)) { | |
a7d35093 | 104 | $this->trigError("Le demande de paiement ne contient pas la balise obligatoire <montant>"); |
20934085 | 105 | return false; |
106 | } | |
107 | return true; | |
108 | } | |
109 | ||
eaf30d86 PH |
110 | // }}} |
111 | // {{{ function submit() | |
112 | ||
612a2d8a | 113 | // supprime les demandes de paiments pour le meme evenement |
114 | public function submit() | |
029e6327 | 115 | { |
029e6327 | 116 | if ($this->evt) |
117 | { | |
08cce2ff | 118 | XDB::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq::same_event($this->evt, $this->asso_id)); |
029e6327 | 119 | } |
612a2d8a | 120 | parent::submit(); |
029e6327 | 121 | } |
122 | // }}} | |
123 | // {{{ function formu() | |
0337d704 | 124 | |
612a2d8a | 125 | public function formu() |
126 | { | |
127 | return 'include/form.valid.paiements.tpl'; | |
128 | } | |
0337d704 | 129 | |
130 | // }}} | |
6aa01fed | 131 | // {{{ function editor() |
132 | ||
612a2d8a | 133 | public function editor() |
6aa01fed | 134 | { |
135 | return 'include/form.valid.edit-paiements.tpl'; | |
136 | } | |
137 | ||
138 | // }}} | |
139 | // {{{ function handle_editor() | |
140 | ||
612a2d8a | 141 | protected function handle_editor() |
6aa01fed | 142 | { |
143 | $this->titre = Env::v('pay_titre'); | |
144 | $this->site = Env::v('pay_site'); | |
4617190f | 145 | $this->montant = Env::t('pay_montant'); |
6aa01fed | 146 | $this->montant_min = Env::i('pay_montant_min'); |
147 | $this->montant_max = Env::i('pay_montant_max'); | |
148 | $this->msg_reponse = Env::v('pay_msg_reponse'); | |
0a9d877e | 149 | $this->public = (Env::v('pay_public') == 'yes'); |
b9c62780 AL |
150 | $this->rib_id = Env::v('pay_rib_id'); |
151 | if ($this->rib_id) { | |
152 | $res = XDB::query("SELECT owner FROM payment_bankaccounts WHERE id = {?}", $this->rib_id); | |
153 | $this->rib_nom = $res->fetchOneCell(); | |
154 | } else { | |
155 | $this->rib_nom = null; | |
156 | } | |
6aa01fed | 157 | return true; |
158 | } | |
159 | ||
160 | // }}} | |
0337d704 | 161 | // {{{ function _mail_subj |
162 | ||
612a2d8a | 163 | protected function _mail_subj() |
0337d704 | 164 | { |
a7de4ef7 | 165 | return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}"; |
0337d704 | 166 | } |
167 | ||
168 | // }}} | |
169 | // {{{ function _mail_body | |
170 | ||
612a2d8a | 171 | protected function _mail_body($isok) |
0337d704 | 172 | { |
173 | if ($isok) { | |
a3923909 | 174 | return " Le paiement demandé pour {$this->titre} vient d'être créé.".($this->evt?" Il a bien été associé à la gestion de l'événement du groupe":""); |
0337d704 | 175 | } else { |
a3923909 | 176 | return " La demande faite pour le paiement de {$this->intitule} a été refusée."; |
0337d704 | 177 | } |
178 | } | |
179 | ||
180 | // }}} | |
181 | // {{{ function commit() | |
eaf30d86 | 182 | |
612a2d8a | 183 | public function commit() |
0337d704 | 184 | { |
69fffc4b | 185 | $res = XDB::query("SELECT MAX(id) FROM payments"); |
0337d704 | 186 | $id = $res->fetchOneCell()+1; |
b9c62780 AL |
187 | $ret = XDB::execute('INSERT INTO payments (id, text, url, amount_def, amount_min, amount_max, mail, confirmation, asso_id, flags, rib_id) |
188 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', | |
75d4576e | 189 | $id, $this->titre, $this->site, $this->montant, $this->montant_min, |
0a9d877e | 190 | $this->montant_max, $this->user->bestEmail(), $this->msg_reponse, $this->asso_id, |
b9c62780 | 191 | ($this->public ? 'public' : ''), $this->rib_id); |
2ac0bcee | 192 | if ($this->asso_id && $this->evt) { |
eb41eda9 | 193 | XDB::execute("UPDATE group_events |
2ac0bcee FB |
194 | SET paiement_id = {?} |
195 | WHERE asso_id = {?} AND eid = {?}", | |
196 | $id, $this->asso_id, $this->evt); | |
197 | $res = XDB::query("SELECT a.nom, a.diminutif, e.intitule | |
eb41eda9 FB |
198 | FROM groups AS a |
199 | INNER JOIN group_events AS e ON (a.id = e.asso_id) | |
2ac0bcee FB |
200 | WHERE e.eid = {?}", |
201 | $this->evt); | |
202 | list($nom, $diminutif, $evt) = $res->fetchOneRow(); | |
2ac0bcee | 203 | require_once dirname(__FILE__) . '/../../modules/xnetevents/xnetevents.inc.php'; |
20642792 | 204 | $participants = get_event_participants(get_event_detail($this->evt, false, $this->asso_id), null); |
f036c896 | 205 | foreach ($participants as $u) { |
2ac0bcee FB |
206 | if (!$u['notify_payment']) { |
207 | continue; | |
208 | } | |
209 | $topay = $u['montant'] - $u['paid']; | |
210 | if ($topay > 0) { | |
d0327f6d | 211 | $mailer = new PlMailer('xnetevents/newpayment.mail.tpl'); |
3bf29c06 | 212 | $mailer->addTo($u['user']); |
6c4b5005 FB |
213 | $mailer->assign('asso', $nom); |
214 | $mailer->assign('diminutif', $diminutif); | |
215 | $mailer->assign('evt', $evt); | |
c90dde93 | 216 | $mailer->assign('eid', $this->evt); |
3bf29c06 | 217 | $mailer->assign('prenom', $u['user']->firstName()); |
2ac0bcee FB |
218 | $mailer->send(); |
219 | } | |
220 | } | |
221 | } | |
0337d704 | 222 | return $ret; |
223 | } | |
224 | ||
225 | // }}} | |
226 | } | |
227 | ||
228 | // }}} | |
229 | ||
448c8cdc | 230 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
0337d704 | 231 | ?> |