Adapts upgrade scripts to domain.
[platal.git] / modules / payment.php
index f6669bd..52dd453 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -124,7 +124,7 @@ class PaymentModule extends PLModule
         );
     }
 
-    function handler_payment(&$page, $ref = -1)
+    function handler_payment($page, $ref = -1)
     {
         global $globals;
 
@@ -182,9 +182,10 @@ class PaymentModule extends PLModule
         $page->assign('meth', $meth);
         $page->assign('pay', $pay);
         $page->assign('evtlink', $pay->event());
+        $page->assign('sex', S::user()->isFemale());
     }
 
-    function handler_cyber_return(&$page, $uid = null)
+    function handler_cyber_return($page, $uid = null)
     {
         /* reference banque (numero de transaction) */
         $champ901 = Env::s('CHAMP901');
@@ -252,7 +253,7 @@ class PaymentModule extends PLModule
 
         /* on genere le mail de confirmation */
         $conf_text = str_replace(
-            array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>', 'comment>'),
+            array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>', '<comment>'),
             array($user->firstName(), $user->lastName(), $user->promo(), $montant,
                   $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher',
                   Env::v('comment')), $conf_text);
@@ -282,7 +283,7 @@ class PaymentModule extends PLModule
         exit;
     }
 
-    function handler_cyber2_return(&$page, $uid = null)
+    function handler_cyber2_return($page, $uid = null)
     {
         global $globals, $platal;
 
@@ -299,7 +300,7 @@ class PaymentModule extends PLModule
         //}
 
         /* on extrait les informations sur l'utilisateur */
-        $user = User::get(Env::v('vads_cust_id'));
+        $user = User::get(Env::i('vads_cust_id'));
         if (!$user) {
             cb_erreur("uid invalide");
         }
@@ -312,16 +313,18 @@ class PaymentModule extends PLModule
         $ref = $matches[1];
         $res = XDB::query('SELECT  mail, text, confirmation
                              FROM  payments
-                            WHERE  id = {?}', $ref);
-        if (!list($conf_mail, $conf_title, $conf_text) = $res->fetchOneRow()) {
+                            WHERE  id={?}', $ref);
+        if ($res->numRows() != 1) {
             cb_erreur("référence de commande inconnue");
         }
+        list($conf_mail, $conf_title, $conf_text) = $res->fetchOneRow();
 
         /* on extrait le montant */
         if (Env::v('vads_currency') != '978') {
             cb_erreur("monnaie autre que l'euro");
         }
-        $montant = sprintf("%.02f", ((float)Env::v('vads_amount')) / 100) . ' EUR';
+        $amount = ((float)Env::i('vads_amount')) / 100;
+        $montant = sprintf("%.02f EUR", $amount);
 
         /* on extrait le code de retour */
         if (Env::v('vads_result') != '00') {
@@ -335,18 +338,19 @@ class PaymentModule extends PLModule
         echo "Paiement stored.\n";
 
         // We check if it is an Xnet payment and then update the related ML.
-        $res = XDB::query('SELECT  eid
+        $res = XDB::query('SELECT  eid, asso_id
                              FROM  group_events
                             WHERE  paiement_id = {?}', $ref);
-        if ($eid = $res->fetchOneCell()) {
+        if ($res->numRows() == 1) {
+            list($eid, $asso_id) = $res->fetchOneRow();
             require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php';
-            $evt = get_event_detail($eid);
-            subscribe_lists_event($user->id(), $evt, 1, $montant, true);
+            $evt = get_event_detail($eid, false, $asso_id);
+            subscribe_lists_event($user->id(), $evt, 1, $amount, true);
         }
 
         /* on genere le mail de confirmation */
         $conf_text = str_replace(
-            array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>', 'comment>'),
+            array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>', '<comment>'),
             array($user->firstName(), $user->lastName(), $user->promo(), $montant,
                   $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher',
                   Env::v('comment')), $conf_text);
@@ -377,7 +381,7 @@ class PaymentModule extends PLModule
         exit;
     }
 
-    function handler_paypal_return(&$page, $uid = null)
+    function handler_paypal_return($page, $uid = null)
     {
         $page->changeTpl('payment/retour_paypal.tpl');
 
@@ -473,7 +477,7 @@ class PaymentModule extends PLModule
         $page->assign('erreur', $erreur);
     }
 
-    function handler_xnet_payment(&$page, $pid = null)
+    function handler_xnet_payment($page, $pid = null)
     {
         global $globals;
 
@@ -483,8 +487,8 @@ class PaymentModule extends PLModule
                 return PL_FORBIDDEN;
             }
             $res = XDB::query("SELECT  1
-                                 FROM  group_events             AS e
-                           INNER JOIN  group_event_participants AS ep ON (ep.eid = e.eid AND uid = {?})
+                                 FROM  group_events AS e
+                           INNER JOIN  group_event_participants AS ep ON (ep.eid = e.eid AND e.uid = {?})
                                 WHERE  e.paiement_id = {?} AND e.asso_id = {?}",
                               S::i('uid'), $pid, $globals->asso('id'));
             if ($res->numRows() == 0) {
@@ -585,7 +589,7 @@ class PaymentModule extends PLModule
         $page->assign('event', $event);
     }
 
-    function handler_admin(&$page, $action = 'list', $id = null) {
+    function handler_admin($page, $action = 'list', $id = null) {
         $page->setTitle('Administration - Paiements');
         $page->assign('title', 'Gestion des télépaiements');
         $table_editor = new PLTableEditor('admin/payments','payments','id');
@@ -608,7 +612,7 @@ class PaymentModule extends PLModule
         $table_editor->apply($page, $action, $id);
     }
 
-    function handler_adm_transactions(&$page, $payment_id = null, $action = "list", $id = null) {
+    function handler_adm_transactions($page, $payment_id = null, $action = "list", $id = null) {
         // show transactions. FIXME: should not be modifiable
         $page->setTitle('Administration - Paiements - Transactions');
         $page->assign('title', "Liste des transactions pour le paiement {$payment_id}");
@@ -622,7 +626,7 @@ class PaymentModule extends PLModule
         $page->assign('readonly', 'readonly');     // don't show modification features
     }
 
-    function handler_adm_bankaccounts(&$page, $action = 'list', $id = null) {
+    function handler_adm_bankaccounts($page, $action = "list", $id = null) {
         // managment of bank account used for money transfert
         $page->setTitle('Administration - Paiements - RIBs');
         $page->assign('title', "Liste des RIBs");
@@ -643,7 +647,7 @@ class PaymentModule extends PLModule
         $table_editor->apply($page, $action, $id);
     }
 
-    function handler_adm_methods(&$page, $action = 'list', $id = null) {
+    function handler_adm_methods($page, $action = "list", $id = null) {
         // show and edit payment methods
         $page->setTitle('Administration - Paiements - Méthodes');
         $page->assign('title', 'Méthodes de paiement');
@@ -651,7 +655,7 @@ class PaymentModule extends PLModule
         $table_editor->apply($page, $action, $id);
     }
 
-    function handler_adm_reconcile(&$page, $step = 'list', $param = null) {
+    function handler_adm_reconcile($page, $step = 'list', $param = null) {
         // reconciles logs with transactions
         // FIXME: the admin is considered to be fair => he doesn't hack the $step value, nor other params
         $page->setTitle('Administration - Paiements - Réconciliations');
@@ -718,7 +722,7 @@ class PaymentModule extends PLModule
         }
     }
 
-    function handler_adm_importlogs(&$page, $step, $param = null) {
+    function handler_adm_importlogs($page, $step, $param = null) {
         $page->setTitle('Administration - Paiements - Réconciliations');
         $page->changeTpl('payment/reconcile.tpl');
         $page->assign('step', $step);
@@ -890,7 +894,7 @@ class PaymentModule extends PLModule
         }
     }
 
-    function handler_adm_transfers(&$page, $action = null, $id = null) {
+    function handler_adm_transfers($page, $action = null, $id = null) {
         // list/log all bank transfers and link them to individual transactions
 
         if (Post::has('generate')) {