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