Automatically disconnect after auth-groupe-x authentication.
[platal.git] / modules / payment.php
index 1613259..623aad2 100644 (file)
 /* sort en affichant une erreur */
 function cb_erreur($text) {
     global $globals;
-    echo "Error.\n";
+    echo "Error: ".$text."\n";
     $mymail = new PlMailer();
     $mymail->addTo($globals->money->email);
     $mymail->setFrom("webmaster@" . $globals->mail->domain);
     $mymail->setSubject("erreur lors d'un télépaiement (CyberPaiement)");
-    $mymail->setTxtBody("\n\n".var_export($_REQUEST,true));
+    $mymail->setTxtBody("raison de l'erreur : ".$text."\n".
+                        "paiement : $conf_title \n\n".
+                        "dump de REQUEST :\n".
+                        var_export($_REQUEST,true));
     $mymail->send();
     echo "Notification sent.\n";
     exit;
@@ -45,7 +48,10 @@ function paypal_erreur($text, $send=true)
     $mymail->addTo($globals->money->email);
     $mymail->setFrom("webmaster@" . $globals->mail->domain);
     $mymail->setSubject("erreur lors d'un télépaiement (PayPal)");
-    $mymail->setTxtBody("\n\n".var_export($_REQUEST,true));
+    $mymail->setTxtBody("raison de l'erreur : ".$text."\n".
+                        "paiement : $conf_title \n\n".
+                        "dump de REQUEST :\n".
+                        var_export($_REQUEST,true));
     $mymail->send();
 
     Platal::page()->trigError($text);
@@ -142,6 +148,9 @@ class PaymentModule extends PLModule
             $page->kill('La transaction selectionnée est périmée.');
         }
 
+        if (Env::has('montant')) {
+            $pay->amount_def = Env::v('montant');
+        }
         $val = (Post::v('amount') != 0) ? Post::v('amount') : $pay->amount_def;
 
         if (($error = $pay->check($val)) !== true) {
@@ -162,6 +171,7 @@ class PaymentModule extends PLModule
             } else {
                 $pay->init($val, $meth);
                 $pay->prepareform($user);
+                $page->assign('full_name', $user->fullName(true));
                 $page->assign('sex', $user->isFemale());
             }
         } elseif (S::logged()) {
@@ -277,7 +287,7 @@ class PaymentModule extends PLModule
             list($eid, $asso_id) = $res->fetchOneRow();
             require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php';
             $evt = get_event_detail($eid, false, $asso_id);
-            subscribe_lists_event($user->id(), $evt['short_name'], 1, $amount, true);
+            subscribe_lists_event($user->id(), $evt['short_name'], 1, $montant, true);
         }
 
         /* on genere le mail de confirmation */
@@ -368,12 +378,13 @@ class PaymentModule extends PLModule
                     $no_transaction, $user->id(), $ref, $fullref, $montant, $clef, Env::v('comment'), Get::i('display'));
 
         // 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);
+            $evt = get_event_detail($eid, false, $asso_id);
             subscribe_lists_event($user->id(), $evt['short_name'], 1, $montant, true);
         }
 
@@ -450,7 +461,7 @@ class PaymentModule extends PLModule
         $trans = array();
         $event = array();
         if (may_update()) {
-            static $orders = array('timestamp' => 'p', 'directory_name' => 'a', 'promo' => 'pd', 'comment' => 'p', 'amount' => 'p');
+            static $orders = array('ts_confirmed' => 'p', 'directory_name' => 'a', 'promo' => 'pd', 'comment' => 'p', 'amount' => 'p');
 
             if (Get::has('order_id') && Get::has('order') && array_key_exists(Get::v('order'), $orders)) {
                 $order_id = Get::i('order_id');
@@ -543,17 +554,17 @@ class PaymentModule extends PLModule
         $users = User::getBulkUsersWithUIDs($res, 'uid', 'user');
         $sum = 0;
 
-        pl_cached_content_headers('text/x-csv', 1);
+        pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
         $csv = fopen('php://output', 'w');
-        fputcsv($csv, array('Date', 'Nom', 'Prénom', 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';');
+        fputcsv($csv, array('Date', 'Nom', utf8_decode('Prénom'), 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';');
         foreach ($users as $item) {
             $user = $item['user'];
             $sum += $item['amount'];
-            fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), $user->lastName(), $user->firstName(),
+            fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), utf8_decode($user->lastName()), utf8_decode($user->firstName()),
                                 ($user->isFemale()) ? 'F' : 'M', $user->promo(), $user->ForlifeEmail(),
-                                $item['comment'], strtr($item['amount'],'.',',').' €' ), ';');
+                                utf8_decode($item['comment']), strtr($item['amount'], '.', ',') . ' EUR' ), ';');
         }
-        fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum,'.',',').' €'), ';');
+        fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum, '.', ',') . ' EUR'), ';');
 
         fclose($csv);
         exit;
@@ -955,7 +966,7 @@ class PaymentLogsImporter extends CSVImporter {
 
     static public function compute_systempay_commission($line, $key, $relation) {
         static $EEE_countries = array(
-            'France', 'Allemagne', 'Autriche', 'Belgique', 'Bulgarie', 'Chypre',
+            'France', 'Allemagne', 'Autriche', 'Belgique', 'Bulgarie', 'Chypre', 'Suisse',
             'Danemark', 'Espagne', 'Estonie', 'Finlande', 'Grèce', 'Hongrie', 'Irlande', 'Islande', 'Italie',
             'Lettonie', 'Liechtenstein', 'Lituanie', 'Luxembourg', 'Malte', 'Norvège', 'Pays-Bas', 'Pologne',
             'Portugal', 'Roumanie', 'Royaume-Uni', 'Slovaquie', 'Slovénie', 'Suède', 'République Tchèque'