Commit | Line | Data |
---|---|---|
a2558f2b | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
a2558f2b | 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 | /* sort en affichant une erreur */ | |
23 | function cb_erreur($text) { | |
115c90db | 24 | global $globals; |
1e33266a | 25 | $mymail = new PlMailer(); |
d7dd70be | 26 | $mymail->addTo($globals->money->email); |
1d55fe45 | 27 | $mymail->setFrom("webmaster@" . $globals->mail->domain); |
a7de4ef7 | 28 | $mymail->setSubject("erreur lors d'un télépaiement (CyberPaiement)"); |
a2558f2b | 29 | $mymail->setTxtBody("\n\n".var_export($_REQUEST,true)); |
30 | $mymail->send(); | |
31 | exit; | |
32 | } | |
33 | ||
34 | /* sort en affichant une erreur */ | |
88e3843c | 35 | function paypal_erreur($text, $send=true) |
36 | { | |
d7610c35 | 37 | global $erreur, $globals; |
a2558f2b | 38 | if ($erreur) return; |
39 | $erreur = $text; | |
40 | if (!$send) return; | |
41 | ||
1e33266a | 42 | $mymail = new PlMailer(); |
d7dd70be | 43 | $mymail->addTo($globals->money->email); |
1d55fe45 | 44 | $mymail->setFrom("webmaster@" . $globals->mail->domain); |
a7de4ef7 | 45 | $mymail->setSubject("erreur lors d'un télépaiement (PayPal)"); |
a2558f2b | 46 | $mymail->setTxtBody("\n\n".var_export($_REQUEST,true)); |
47 | $mymail->send(); | |
48 | ||
d7610c35 | 49 | Platal::page()->trigError($text); |
a2558f2b | 50 | } |
51 | ||
52 | /* http://fr.wikipedia.org/wiki/Formule_de_Luhn */ | |
53 | function luhn($nombre) { | |
54 | $s = strrev($nombre); | |
55 | $sum = 0; | |
56 | for ($i = 0; $i < strlen($s); $i++) { | |
57 | $dgt = $s{$i}; | |
58 | $sum += ($i % 2) ? (2*$dgt) % 9 : $dgt; | |
59 | } | |
60 | return $sum % 10; | |
61 | } | |
62 | ||
a7de4ef7 | 63 | /* calcule la clé d'acceptation a partir de 5 champs */ |
a2558f2b | 64 | function cle_accept($d1,$d2,$d3,$d4,$d5) |
65 | { | |
66 | $m1 = luhn($d1.$d5); | |
67 | $m2 = luhn($d2.$d5); | |
68 | $m3 = luhn($d3.$d5); | |
69 | $m4 = luhn($d4.$d5); | |
70 | $n = $m1 + $m2 + $m3 + $m4; | |
71 | $alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
72 | return $alpha{$n-1}.$m1.$m2.$m3.$m4; | |
73 | } | |
74 | ||
17793ccf FB |
75 | /* decode the comment */ |
76 | function comment_decode($comment) { | |
77 | $comment = urldecode($comment); | |
78 | if (is_utf8($comment)) { | |
79 | return $comment; | |
80 | } else { | |
81 | return utf8_encode($comment); | |
82 | } | |
83 | } | |
84 | ||
a2558f2b | 85 | |
86 | class PaymentModule extends PLModule | |
87 | { | |
88 | function handlers() | |
89 | { | |
90 | return array( | |
eb5a266d SJ |
91 | 'payment' => $this->make_hook('payment', AUTH_MDP), |
92 | 'payment/cyber_return' => $this->make_hook('cyber_return', AUTH_PUBLIC, 'user', NO_HTTPS), | |
a690a74c | 93 | 'payment/cyber2_return' => $this->make_hook('cyber2_return', AUTH_PUBLIC, 'user', NO_HTTPS), |
eb5a266d SJ |
94 | 'payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUBLIC, 'user', NO_HTTPS), |
95 | '%grp/paiement' => $this->make_hook('xnet_payment', AUTH_MDP), | |
96 | '%grp/payment' => $this->make_hook('xnet_payment', AUTH_MDP), | |
97 | '%grp/payment/cyber_return' => $this->make_hook('cyber_return', AUTH_PUBLIC, 'user', NO_HTTPS), | |
a690a74c | 98 | '%grp/payment/cyber2_return' => $this->make_hook('cyber2_return', AUTH_PUBLIC, 'user', NO_HTTPS), |
41cce805 | 99 | '%grp/payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUBLIC, 'user', NO_HTTPS), |
eb5a266d | 100 | 'admin/payments' => $this->make_hook('admin', AUTH_MDP, 'admin'), |
eaf30d86 | 101 | |
a2558f2b | 102 | ); |
103 | } | |
104 | ||
105 | function handler_payment(&$page, $ref = -1) | |
106 | { | |
107 | global $globals; | |
108 | ||
109 | require_once 'profil.func.inc.php' ; | |
460d8f55 | 110 | $this->load('money.inc.php'); |
a2558f2b | 111 | |
98a7e9dc | 112 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
113 | if (!$globals->asso('id')) { | |
114 | return PL_NOT_FOUND; | |
115 | } | |
116 | $res = XDB::query("SELECT asso_id | |
69fffc4b | 117 | FROM payments |
98a7e9dc | 118 | WHERE asso_id = {?} AND id = {?}", |
119 | $globals->asso('id'), $ref); | |
120 | if (!$res->numRows()) { | |
121 | return PL_FORBIDDEN; | |
122 | } | |
98a7e9dc | 123 | } |
1490093c | 124 | $page->changeTpl('payment/index.tpl'); |
46f272fe | 125 | $page->setTitle('Télépaiements'); |
a2558f2b | 126 | |
127 | // initialisation | |
5e2307dc | 128 | $op = Env::v('op', 'select'); |
129 | $meth = new PayMethod(Env::i('methode', -1)); | |
a2558f2b | 130 | $pay = new Payment($ref); |
131 | ||
132 | if($pay->flags->hasflag('old')){ | |
a7d35093 | 133 | $page->trigError("La transaction selectionnée est périmée."); |
a2558f2b | 134 | $pay = new Payment(); |
135 | } | |
a690a74c | 136 | $val = Env::v('montant') != 0 ? Env::v('montant') : $pay->amount_def; |
a2558f2b | 137 | |
138 | if (($e = $pay->check($val)) !== true) { | |
a7d35093 | 139 | $page->trigError($e); |
a2558f2b | 140 | } |
141 | ||
142 | if ($op=='submit') { | |
143 | $pay->init($val, $meth); | |
144 | $pay->prepareform($pay); | |
145 | } else { | |
69fffc4b FB |
146 | $res = XDB::iterator("SELECT timestamp, amount |
147 | FROM payment_transactions | |
8a7fab54 | 148 | WHERE uid = {?} AND ref = {?} |
149 | ORDER BY timestamp DESC", | |
150 | S::v('uid', -1), $ref); | |
a2558f2b | 151 | |
152 | if ($res->total()) $page->assign('transactions', $res); | |
153 | } | |
154 | ||
155 | $val = floor($val).".".substr(floor(($val - floor($val))*100+100),1); | |
156 | $page->assign('montant',$val); | |
bff6d838 | 157 | $page->assign('comment',Env::v('comment')); |
a2558f2b | 158 | |
159 | $page->assign('meth', $meth); | |
160 | $page->assign('pay', $pay); | |
161 | $page->assign('evtlink', $pay->event()); | |
a2558f2b | 162 | } |
163 | ||
164 | function handler_cyber_return(&$page, $uid = null) | |
165 | { | |
a2558f2b | 166 | /* reference banque (numero de transaction) */ |
7280eb45 | 167 | $champ901 = Env::s('CHAMP901'); |
a2558f2b | 168 | /* cle d'acceptation */ |
7280eb45 | 169 | $champ905 = Env::s('CHAMP905'); |
a2558f2b | 170 | /* code retour */ |
7280eb45 | 171 | $champ906 = Env::s('CHAMP906'); |
a2558f2b | 172 | /* email renvoye par la banque */ |
7280eb45 | 173 | $champ104 = Env::s('CHAMP104'); |
a2558f2b | 174 | /* reference complete de la commande */ |
7280eb45 | 175 | $champ200 = Env::s('CHAMP200'); |
a2558f2b | 176 | /* montant de la transaction */ |
7280eb45 | 177 | $champ201 = Env::s('CHAMP201'); |
a2558f2b | 178 | /* devise */ |
7280eb45 | 179 | $champ202 = Env::s('CHAMP202'); |
a2558f2b | 180 | $montant = "$champ201 $champ202"; |
181 | ||
182 | /* on extrait les informations sur l'utilisateur */ | |
1eaaa62d FB |
183 | $user = User::get($uid); |
184 | if (!$user) { | |
a2558f2b | 185 | cb_erreur("uid invalide"); |
186 | } | |
187 | ||
188 | ||
189 | /* on extrait la reference de la commande */ | |
1eaaa62d | 190 | if (!ereg('-xorg-([0-9]+)$', $champ200, $matches)) { |
a7de4ef7 | 191 | cb_erreur("référence de commande invalide"); |
a2558f2b | 192 | } |
193 | ||
194 | echo ($ref = $matches[1]); | |
1eaaa62d | 195 | $res = XDB::query("SELECT mail, text, confirmation |
69fffc4b | 196 | FROM payments |
98a7e9dc | 197 | WHERE id={?}", $ref); |
1eaaa62d | 198 | if (!list($conf_mail, $conf_title, $conf_text) = $res->fetchOneRow()) { |
a7de4ef7 | 199 | cb_erreur("référence de commande inconnue"); |
a2558f2b | 200 | } |
201 | ||
202 | /* on extrait le code de retour */ | |
203 | if ($champ906 != "0000") { | |
1eaaa62d | 204 | $res = XDB::query('SELECT rcb.text, c.id, c.text |
69fffc4b FB |
205 | FROM payment_codeRCB AS rcb |
206 | LEFT JOIN payment_codeC AS c ON (rcb.codeC = c.id) | |
1eaaa62d | 207 | WHERE rcb.id = {?}', $champ906); |
a2558f2b | 208 | if (list($rcb_text, $c_id, $c_text) = $res->fetchOneRow()) { |
209 | cb_erreur("erreur lors du paiement : $c_text ($c_id)"); | |
eaf30d86 | 210 | } else{ |
a2558f2b | 211 | cb_erreur("erreur inconnue lors du paiement"); |
212 | } | |
213 | } | |
214 | ||
215 | /* on fait l'insertion en base de donnees */ | |
69fffc4b | 216 | XDB::execute("INSERT INTO payment_transactions (id, uid, ref, fullref, amount, pkey, comment) |
1eaaa62d FB |
217 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})", |
218 | $champ901, $user->id(), $ref, $champ200, $montant, $champ905, Env::v('comment')); | |
a2558f2b | 219 | |
9ff5b337 SJ |
220 | // We check if it is an Xnet payment and then update the related ML. |
221 | $res = XDB::query('SELECT eid | |
eb41eda9 | 222 | FROM group_events |
9ff5b337 SJ |
223 | WHERE paiement_id = {?}', $ref); |
224 | if ($eid = $res->fetchOneCell()) { | |
fd03857b | 225 | require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php'; |
9ff5b337 SJ |
226 | $evt = get_event_detail($eid); |
227 | subscribe_lists_event(0, $uid, $evt, $montant, true); | |
228 | } | |
229 | ||
a2558f2b | 230 | /* on genere le mail de confirmation */ |
d1e61677 SJ |
231 | $conf_text = str_replace( |
232 | array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>', 'comment>'), | |
233 | array($user->firstName(), $user->lastName(), $user->promo(), $montant, | |
234 | $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher', | |
235 | Env::v('comment')), $conf_text); | |
a2558f2b | 236 | |
7895f3c1 | 237 | global $globals; |
1e33266a | 238 | $mymail = new PlMailer(); |
a2558f2b | 239 | $mymail->setFrom($conf_mail); |
a2558f2b | 240 | $mymail->addCc($conf_mail); |
241 | $mymail->setSubject($conf_title); | |
88e3843c | 242 | $mymail->setWikiBody($conf_text); |
1eaaa62d | 243 | $mymail->sendTo($user); |
a2558f2b | 244 | |
a7de4ef7 | 245 | /* on envoie les details de la transaction à telepaiement@ */ |
1e33266a | 246 | $mymail = new PlMailer(); |
1d55fe45 | 247 | $mymail->setFrom("webmaster@" . $globals->mail->domain); |
d7dd70be | 248 | $mymail->addTo($globals->money->email); |
a2558f2b | 249 | $mymail->setSubject($conf_title); |
1eaaa62d FB |
250 | $msg = 'utilisateur : ' . $user->login() . ' (' . $user->id() . ')' . "\n" . |
251 | 'mail : ' . $user->forlifeEmail() . "\n\n" . | |
a2558f2b | 252 | "paiement : $conf_title ($conf_mail)\n". |
253 | "reference : $champ200\n". | |
254 | "montant : $montant\n\n". | |
255 | "dump de REQUEST:\n". | |
256 | var_export($_REQUEST,true); | |
257 | $mymail->setTxtBody($msg); | |
258 | $mymail->send(); | |
259 | exit; | |
260 | } | |
261 | ||
a690a74c DB |
262 | function handler_cyber2_return(&$page, $uid = null) |
263 | { | |
264 | global $globals, $platal; | |
265 | ||
266 | /* on vérifie la signature */ | |
267 | $vads_params = array(); | |
268 | foreach($_REQUEST as $key => $value) | |
269 | if(substr($key,0,5) == "vads_") | |
270 | $vads_params[$key] = $value; | |
271 | ksort($vads_params); | |
272 | $signature = sha1(join('+',$vads_params).'+'.$globals->money->cyperplus_key); | |
273 | //if($signature != Env::v('signature')) { | |
274 | // cb_erreur("signature invalide"); | |
275 | //} | |
276 | ||
277 | /* on extrait les informations sur l'utilisateur */ | |
278 | $user = User::get(Env::v('vads_cust_id')); | |
279 | if (!$user) { | |
280 | cb_erreur("uid invalide"); | |
281 | } | |
282 | ||
283 | /* on extrait la reference de la commande */ | |
284 | if (!ereg('-([0-9]+)$', Env::v('vads_order_id'), $matches)) { | |
285 | cb_erreur("référence de commande invalide"); | |
286 | } | |
287 | ||
288 | echo ($ref = $matches[1]); | |
289 | $res = XDB::query("SELECT mail, text, confirmation | |
290 | FROM payments | |
291 | WHERE id={?}", $ref); | |
292 | if (!list($conf_mail, $conf_title, $conf_text) = $res->fetchOneRow()) { | |
293 | cb_erreur("référence de commande inconnue"); | |
294 | } | |
295 | ||
296 | /* on extrait le montant */ | |
297 | if (Env::v('vads_currency') != "978") { | |
298 | cb_erreur("monnaie autre que l'euro"); | |
299 | } | |
300 | $montant = sprintf("%.02f", ((float)Env::v('vads_amount'))/100) . " EUR"; | |
301 | ||
302 | /* on extrait le code de retour */ | |
303 | if (Env::v('vads_result') != "00") { | |
304 | cb_erreur("erreur lors du paiement : ?? (".Env::v('vads_result').")"); | |
305 | } | |
306 | ||
307 | /* on fait l'insertion en base de donnees */ | |
308 | XDB::execute("INSERT INTO payment_transactions (id, uid, ref, fullref, amount, pkey, comment) | |
309 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
310 | Env::v('vads_trans_date'), $user->id(), $ref, Env::v('vads_order_id'), $montant, "", Env::v('vads_order_info')); | |
311 | ||
312 | // We check if it is an Xnet payment and then update the related ML. | |
313 | $res = XDB::query('SELECT eid | |
314 | FROM group_events | |
315 | WHERE paiement_id = {?}', $ref); | |
316 | if ($eid = $res->fetchOneCell()) { | |
317 | require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php'; | |
318 | $evt = get_event_detail($eid); | |
319 | subscribe_lists_event(0, $uid, $evt, $montant, true); | |
320 | } | |
321 | ||
322 | /* on genere le mail de confirmation */ | |
323 | $conf_text = str_replace( | |
324 | array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>', 'comment>'), | |
325 | array($user->firstName(), $user->lastName(), $user->promo(), $montant, | |
326 | $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher', | |
327 | Env::v('comment')), $conf_text); | |
328 | ||
329 | global $globals; | |
330 | $mymail = new PlMailer(); | |
331 | $mymail->setFrom($conf_mail); | |
332 | $mymail->addCc($conf_mail); | |
333 | $mymail->setSubject($conf_title); | |
334 | $mymail->setWikiBody($conf_text); | |
335 | $mymail->sendTo($user); | |
336 | ||
337 | /* on envoie les details de la transaction à telepaiement@ */ | |
338 | $mymail = new PlMailer(); | |
339 | $mymail->setFrom("webmaster@" . $globals->mail->domain); | |
340 | $mymail->addTo($globals->money->email); | |
341 | $mymail->setSubject($conf_title); | |
342 | $msg = 'utilisateur : ' . $user->login() . ' (' . $user->id() . ')' . "\n" . | |
343 | 'mail : ' . $user->forlifeEmail() . "\n\n" . | |
344 | "paiement : $conf_title ($conf_mail)\n". | |
345 | "reference : $champ200\n". | |
346 | "montant : $montant\n\n". | |
347 | "dump de REQUEST:\n". | |
348 | var_export($_REQUEST,true); | |
349 | $mymail->setTxtBody($msg); | |
350 | $mymail->send(); | |
351 | exit; | |
352 | } | |
353 | ||
a2558f2b | 354 | function handler_paypal_return(&$page, $uid = null) |
355 | { | |
da157660 | 356 | $page->changeTpl('payment/retour_paypal.tpl'); |
a2558f2b | 357 | |
358 | /* reference banque (numero de transaction) */ | |
7280eb45 | 359 | $no_transaction = Env::s('tx'); |
a2558f2b | 360 | /* token a renvoyer pour avoir plus d'information */ |
7280eb45 | 361 | $clef = Env::s('sig'); |
a2558f2b | 362 | /* code retour */ |
7280eb45 | 363 | $status = Env::s('st'); |
a2558f2b | 364 | /* raison */ |
7280eb45 | 365 | $reason = ($status == 'Pending')? Env::s('pending_reason'): Env::s('reason_code'); |
a2558f2b | 366 | /* reference complete de la commande */ |
7280eb45 | 367 | $fullref = Env::s('cm'); |
a2558f2b | 368 | /* montant de la transaction */ |
7280eb45 | 369 | $montant_nb = Env::s('amt'); |
a2558f2b | 370 | /* devise */ |
7280eb45 | 371 | $montant_dev = Env::s('cc'); |
a2558f2b | 372 | $montant = "$montant_nb $montant_dev"; |
373 | ||
374 | /* on extrait le code de retour */ | |
375 | if ($status != "Completed") { | |
376 | if ($status) | |
377 | paypal_erreur("erreur lors du paiement : $status - $reason"); | |
378 | else | |
a7de4ef7 | 379 | paypal_erreur("Paiement annulé", false); |
a2558f2b | 380 | } |
381 | ||
382 | /* on extrait les informations sur l'utilisateur */ | |
1eaaa62d FB |
383 | $user = User::get($uid); |
384 | if (!$user) { | |
a2558f2b | 385 | paypal_erreur("uid invalide"); |
386 | } | |
387 | ||
388 | /* on extrait la reference de la commande */ | |
1eaaa62d | 389 | if (!ereg('-xorg-([0-9]+)$', $fullref, $matches)) { |
a7de4ef7 | 390 | paypal_erreur("référence de commande invalide"); |
a2558f2b | 391 | } |
392 | ||
393 | $ref = $matches[1]; | |
1eaaa62d | 394 | $res = XDB::query("SELECT mail, text, confirmation |
69fffc4b | 395 | FROM payments |
1eaaa62d | 396 | WHERE id = {?}", $ref); |
a2558f2b | 397 | if (!list($conf_mail,$conf_title,$conf_text) = $res->fetchOneRow()) { |
a7de4ef7 | 398 | paypal_erreur("référence de commande inconnue"); |
a2558f2b | 399 | } |
400 | ||
401 | /* on fait l'insertion en base de donnees */ | |
69fffc4b | 402 | XDB::execute("INSERT INTO payment_transactions (id, uid, ref, fullref, amount, pkey, comment) |
1eaaa62d FB |
403 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})", |
404 | $no_transaction, $user->id(), $ref, $fullref, $montant, $clef, Env::v('comment')); | |
a2558f2b | 405 | |
9ff5b337 SJ |
406 | // We check if it is an Xnet payment and then update the related ML. |
407 | $res = XDB::query('SELECT eid | |
eb41eda9 | 408 | FROM group_events |
9ff5b337 SJ |
409 | WHERE paiement_id = {?}', $ref); |
410 | if ($eid = $res->fetchOneCell()) { | |
fd03857b | 411 | require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php'; |
9ff5b337 SJ |
412 | $evt = get_event_detail($eid); |
413 | subscribe_lists_event(0, $uid, $evt, $montant, true); | |
414 | } | |
415 | ||
a2558f2b | 416 | /* on genere le mail de confirmation */ |
1eaaa62d FB |
417 | $conf_text = str_replace(array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>'), |
418 | array($user->firstName(), $user->lastName(), $user->promo(), $montant, | |
419 | $user->isFemale() ? 'Chère' : 'Cher', | |
420 | $user->isFemale() ? 'Chère' : 'Cher'), $conf_text); | |
a2558f2b | 421 | |
7895f3c1 | 422 | global $globals; |
1e33266a | 423 | $mymail = new PlMailer(); |
a2558f2b | 424 | $mymail->setFrom($conf_mail); |
a2558f2b | 425 | $mymail->addCc($conf_mail); |
426 | $mymail->setSubject($conf_title); | |
88e3843c | 427 | $mymail->setWikiBody($conf_text); |
1eaaa62d | 428 | $mymail->sendTo($user); |
a2558f2b | 429 | |
a7de4ef7 | 430 | /* on envoie les details de la transaction à telepaiement@ */ |
1e33266a | 431 | $mymail = new PlMailer(); |
1d55fe45 | 432 | $mymail->setFrom("webmaster@" . $globals->mail->domain); |
d7dd70be | 433 | $mymail->addTo($globals->money->email); |
a2558f2b | 434 | $mymail->setSubject($conf_title); |
1eaaa62d FB |
435 | $msg = 'utilisateur : ' . $user->login() . ' (' . $user->id() . ')' . "\n" . |
436 | 'mail : ' . $user->forlifeEmail() . "\n\n" . | |
a2558f2b | 437 | "paiement : $conf_title ($conf_mail)\n". |
1eaaa62d | 438 | "reference : $champ200\n". |
a2558f2b | 439 | "montant : $montant\n\n". |
440 | "dump de REQUEST:\n". | |
441 | var_export($_REQUEST,true); | |
442 | $mymail->setTxtBody($msg); | |
443 | $mymail->send(); | |
444 | ||
445 | $page->assign('texte', $conf_text); | |
446 | $page->assign('erreur', $erreur); | |
a2558f2b | 447 | } |
98a7e9dc | 448 | |
449 | function handler_xnet_payment(&$page, $pid = null) | |
450 | { | |
451 | global $globals; | |
eaf30d86 | 452 | |
45a5307b FB |
453 | $perms = S::v('perms'); |
454 | if (!$perms->hasFlag('groupmember')) { | |
455 | if (is_null($pid)) { | |
456 | return PL_FORBIDDEN; | |
457 | } | |
458 | $res = XDB::query("SELECT 1 | |
eb41eda9 FB |
459 | FROM group_events AS e |
460 | INNER JOIN group_event_participants AS ep ON (ep.eid = e.eid AND uid = {?}) | |
45a5307b FB |
461 | WHERE e.paiement_id = {?} AND e.asso_id = {?}", |
462 | S::i('uid'), $pid, $globals->asso('id')); | |
463 | if ($res->numRows() == 0) { | |
464 | return PL_FORBIDDEN; | |
465 | } | |
466 | } | |
467 | ||
98a7e9dc | 468 | if (!is_null($pid)) { |
469 | return $this->handler_payment($page, $pid); | |
470 | } | |
1490093c | 471 | $page->changeTpl('payment/xnet.tpl'); |
eaf30d86 | 472 | |
98a7e9dc | 473 | $res = XDB::query( |
474 | "SELECT id, text, url | |
a690a74c | 475 | FROM payments |
010268b2 | 476 | WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags) |
98a7e9dc | 477 | ORDER BY id DESC", $globals->asso('id')); |
478 | $tit = $res->fetchAllAssoc(); | |
479 | $page->assign('titres', $tit); | |
480 | ||
98a7e9dc | 481 | |
1eaaa62d | 482 | // TODO: replug sort. |
98a7e9dc | 483 | $trans = array(); |
484 | $event = array(); | |
485 | foreach($tit as $foo) { | |
486 | $pid = $foo['id']; | |
487 | if (may_update()) { | |
b3cd1320 | 488 | $res = XDB::query('SELECT t.uid, timestamp AS `date`, t.comment, amount |
a690a74c | 489 | FROM payment_transactions AS t |
1eaaa62d FB |
490 | WHERE t.ref = {?}', $pid); |
491 | $trans[$pid] = User::getBulkUsersWithUIDs($res->fetchAllAssoc(), 'uid', 'user'); | |
492 | $sum = 0; | |
493 | foreach ($trans[$pid] as $i => $t) { | |
b3cd1320 DB |
494 | $sum += strtr(substr($t['amount'], 0, strpos($t['amount'], 'EUR')), ',', '.'); |
495 | $trans[$pid][$i]['amount'] = str_replace('EUR', '€', $t['amount']); | |
1eaaa62d FB |
496 | } |
497 | $trans[$pid][] = array('nom' => 'somme totale', | |
b3cd1320 | 498 | 'amount' => strtr($sum, '.', ',').' €'); |
98a7e9dc | 499 | } |
500 | $res = XDB::iterRow("SELECT e.eid, e.short_name, e.intitule, ep.nb, ei.montant, ep.paid | |
eb41eda9 FB |
501 | FROM group_events AS e |
502 | LEFT JOIN group_event_participants AS ep ON (ep.eid = e.eid AND uid = {?}) | |
503 | INNER JOIN group_event_items AS ei ON (ep.eid = ei.eid AND ep.item_id = ei.item_id) | |
98a7e9dc | 504 | WHERE e.paiement_id = {?}", |
505 | S::v('uid'), $pid); | |
506 | $event[$pid] = array(); | |
507 | $event[$pid]['paid'] = 0; | |
508 | if ($res->total()) { | |
509 | $event[$pid]['topay'] = 0; | |
510 | while(list($eid, $shortname, $title, $nb, $montant, $paid) = $res->next()) { | |
511 | $event[$pid]['topay'] += ($nb * $montant); | |
512 | $event[$pid]['eid'] = $eid; | |
513 | $event[$pid]['shortname'] = $shortname; | |
514 | $event[$pid]['title'] = $title; | |
515 | $event[$pid]['ins'] = !is_null($nb); | |
516 | $event[$pid]['paid'] = $paid; | |
517 | } | |
518 | } | |
b3cd1320 | 519 | $res = XDB::query("SELECT amount |
a690a74c | 520 | FROM payment_transactions AS t |
98a7e9dc | 521 | WHERE ref = {?} AND uid = {?}", $pid, S::v('uid')); |
522 | $montants = $res->fetchColumn(); | |
523 | ||
524 | foreach ($montants as $m) { | |
525 | $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.'); | |
526 | $event[$pid]['paid'] += trim($p); | |
527 | } | |
528 | } | |
17793ccf | 529 | $page->register_modifier('decode_comment', 'decode_comment'); |
98a7e9dc | 530 | $page->assign('trans', $trans); |
531 | $page->assign('event', $event); | |
532 | } | |
eaf30d86 | 533 | |
92423144 | 534 | function handler_admin(&$page, $action = 'list', $id = null) { |
46f272fe | 535 | $page->setTitle('Administration - Paiements'); |
a7de4ef7 | 536 | $page->assign('title', 'Gestion des télépaiements'); |
69fffc4b FB |
537 | $table_editor = new PLTableEditor('admin/payments','payments','id'); |
538 | $table_editor->add_join_table('payment_transactions','ref',true); | |
2e7b5921 | 539 | $table_editor->add_sort_field('flags'); |
de61dbcf | 540 | $table_editor->add_sort_field('id', true, true); |
69fffc4b | 541 | $table_editor->on_delete("UPDATE payments SET flags = 'old' WHERE id = {?}", "Le paiement a été archivé"); |
a7de4ef7 | 542 | $table_editor->describe('text','intitulé',true); |
92423144 | 543 | $table_editor->describe('url','site web',false); |
69fffc4b FB |
544 | $table_editor->describe('amount_def','montant par défaut',false); |
545 | $table_editor->describe('amount_min','montant minimum',false); | |
546 | $table_editor->describe('amount_max','montant maximum',false); | |
92423144 | 547 | $table_editor->describe('mail','email contact',true); |
548 | $table_editor->describe('confirmation','message confirmation',false); | |
9c966750 PC |
549 | |
550 | // adds a column with the start date of the linked event if there is one | |
551 | $table_editor->add_option_table('group_events','group_events.paiement_id = t.id'); | |
552 | $table_editor->add_option_field('group_events.debut', 'related_event', 'évènement', 'timestamp'); | |
553 | ||
92423144 | 554 | $table_editor->apply($page, $action, $id); |
eaf30d86 | 555 | } |
a2558f2b | 556 | } |
557 | ||
a7de4ef7 | 558 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
a2558f2b | 559 | ?> |