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