Fix queries of payment, fix typo in xnetgrp, fix make check return value.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 14 Feb 2009 18:51:15 +0000 (19:51 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 14 Feb 2009 18:51:15 +0000 (19:51 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
Makefile
modules/payment.php
modules/payment/money/cyberpaiement.inc.php
modules/payment/money/paypal.inc.php
modules/xnetgrp/mail.inc.php
templates/payment/xnet.tpl

index d982bca..45e715a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ all: build
 build: core conf banana wiki openid medals jquery
 
 check:
-       @find . -name '*.php' -exec php -l {} ";" | grep -v 'No syntax errors detected'
+       @!(find . -name '*.php' -exec php -l {} ";" | grep -v 'No syntax errors detected')
 
 q:
        @echo -e "Code statistics\n"
index 69ba4c2..9324e08 100644 (file)
@@ -180,35 +180,31 @@ class PaymentModule extends PLModule
         $montant = "$champ201 $champ202";
 
         /* on extrait les informations sur l'utilisateur */
-        $res = XDB::query("
-            SELECT  a.prenom,a.nom,a.promo,l.alias,FIND_IN_SET('femme', a.flags)
-              FROM  auth_user_md5 AS a
-        INNER JOIN  aliases       AS l ON (a.user_id=l.id AND type!='homonyme')
-             WHERE  a.user_id={?}", $uid);
-        if (!list($prenom,$nom,$promo,$forlife,$femme) = $res->fetchOneRow()) {
+        $user = User::get($uid);
+        if (!$user) {
             cb_erreur("uid invalide");
         }
 
 
         /* on extrait la reference de la commande */
-        if (!ereg('-xorg-([0-9]+)$',$champ200,$matches)) {
+        if (!ereg('-xorg-([0-9]+)$', $champ200, $matches)) {
             cb_erreur("référence de commande invalide");
         }
 
         echo ($ref = $matches[1]);
-        $res = XDB::query("SELECT  mail,text,confirmation
+        $res = XDB::query("SELECT  mail, text, confirmation
                              FROM  paiement.paiements
                             WHERE  id={?}", $ref);
-        if (!list($conf_mail,$conf_title,$conf_text) = $res->fetchOneRow()) {
+        if (!list($conf_mail, $conf_title, $conf_text) = $res->fetchOneRow()) {
             cb_erreur("référence de commande inconnue");
         }
 
         /* on extrait le code de retour */
         if ($champ906 != "0000") {
-            $res = XDB::query("SELECT  rcb.text,c.id,c.text
+            $res = XDB::query('SELECT  rcb.text, c.id, c.text
                                  FROM  paiement.codeRCB AS rcb
-                            LEFT JOIN  paiement.codeC   AS c ON rcb.codeC=c.id
-                                WHERE  rcb.id='$champ906'");
+                            LEFT JOIN  paiement.codeC   AS c ON (rcb.codeC = c.id)
+                                WHERE  rcb.id = {?}', $champ906);
             if (list($rcb_text, $c_id, $c_text) = $res->fetchOneRow()) {
                 cb_erreur("erreur lors du paiement : $c_text ($c_id)");
             } else{
@@ -217,34 +213,31 @@ class PaymentModule extends PLModule
         }
 
         /* on fait l'insertion en base de donnees */
-        XDB::execute("INSERT INTO  paiement.transactions (id,uid,ref,fullref,montant,cle,comment)
-                           VALUES  ({?},{?},{?},{?},{?},{?},{?})",
-                     $champ901, $uid, $ref, $champ200, $montant, $champ905,Env::v('comment'));
+        XDB::execute("INSERT INTO  paiement.transactions (id, uid, ref, fullref, montant, cle, comment)
+                           VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?})",
+                     $champ901, $user->id(), $ref, $champ200, $montant, $champ905, Env::v('comment'));
 
         /* on genere le mail de confirmation */
-        $conf_text = str_replace("<prenom>",$prenom,$conf_text);
-        $conf_text = str_replace("<nom>",$nom,$conf_text);
-        $conf_text = str_replace("<promo>",$promo,$conf_text);
-        $conf_text = str_replace("<montant>",$montant,$conf_text);
-        $conf_text = str_replace("<salutation>",$femme ? "Chère" : "Cher",$conf_text);
-        $conf_text = str_replace("<cher>",$femme ? "Chère" : "Cher",$conf_text);
+        $conf_text = str_replace(array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>'),
+                                 array($user->firstName(), $user->lastName(), $user->promo(), $montant,
+                                       $user->isFemale() ? 'Chère' : 'Cher',
+                                       $user->isFemale() ? 'Chère' : 'Cher'), $conf_text);
 
         global $globals;
         $mymail = new PlMailer();
         $mymail->setFrom($conf_mail);
-        $mymail->addTo("\"$prenom $nom\" <$forlife@" . $globals->mail->domain . '>');
         $mymail->addCc($conf_mail);
         $mymail->setSubject($conf_title);
         $mymail->setWikiBody($conf_text);
-        $mymail->send(S::v('mail_fmt') == 'html');
+        $mymail->sendTo($user);
 
         /* on envoie les details de la transaction à telepaiement@ */
         $mymail = new PlMailer();
         $mymail->setFrom("webmaster@" . $globals->mail->domain);
         $mymail->addTo($globals->money->email);
         $mymail->setSubject($conf_title);
-        $msg = "utilisateur : $prenom $nom ($uid)\n".
-               "mail : $forlife@polytechnique.org\n\n".
+        $msg = 'utilisateur : ' . $user->login() . ' (' . $user->id() . ')' . "\n" .
+               'mail : ' . $user->forlifeEmail() . "\n\n" .
                "paiement : $conf_title ($conf_mail)\n".
                "reference : $champ200\n".
                "montant : $montant\n\n".
@@ -284,59 +277,52 @@ class PaymentModule extends PLModule
         }
 
         /* on extrait les informations sur l'utilisateur */
-        $res = XDB::query("
-            SELECT  a.prenom,a.nom,a.promo,l.alias,FIND_IN_SET('femme', a.flags)
-              FROM  auth_user_md5 AS a
-        INNER JOIN  aliases       AS l ON (a.user_id=l.id AND type!='homonyme')
-             WHERE  a.user_id={?}", $uid);
-        if (!list($prenom,$nom,$promo,$forlife,$femme) = $res->fetchOneRow()) {
+        $user = User::get($uid);
+        if (!$user) {
             paypal_erreur("uid invalide");
         }
 
         /* on extrait la reference de la commande */
-        if (!ereg('-xorg-([0-9]+)$',$fullref,$matches)) {
+        if (!ereg('-xorg-([0-9]+)$', $fullref, $matches)) {
             paypal_erreur("référence de commande invalide");
         }
 
         $ref = $matches[1];
-        $res = XDB::query("SELECT  mail,text,confirmation
+        $res = XDB::query("SELECT  mail, text, confirmation
                              FROM  paiement.paiements
-                            WHERE  id={?}", $ref);
+                            WHERE  id = {?}", $ref);
         if (!list($conf_mail,$conf_title,$conf_text) = $res->fetchOneRow()) {
             paypal_erreur("référence de commande inconnue");
         }
 
         /* on fait l'insertion en base de donnees */
-        XDB::execute("INSERT INTO  paiement.transactions (id,uid,ref,fullref,montant,cle,comment)
-                           VALUES  ({?},{?},{?},{?},{?},{?},{?})",
-                    $no_transaction, $uid, $ref, $fullref, $montant, $clef, Env::v('comment'));
+        XDB::execute("INSERT INTO  paiement.transactions (id, uid, ref, fullref, montant, cle, comment)
+                           VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?})",
+                    $no_transaction, $user->id(), $ref, $fullref, $montant, $clef, Env::v('comment'));
 
         /* on genere le mail de confirmation */
-        $conf_text = str_replace("<prenom>",$prenom,$conf_text);
-        $conf_text = str_replace("<nom>",$nom,$conf_text);
-        $conf_text = str_replace("<promo>",$promo,$conf_text);
-        $conf_text = str_replace("<montant>",$montant,$conf_text);
-        $conf_text = str_replace("<salutation>",$femme ? "Chère" : "Cher",$conf_text);
-        $conf_text = str_replace("<cher>",$femme ? "Chère" : "Cher",$conf_text);
+        $conf_text = str_replace(array('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>'),
+                                 array($user->firstName(), $user->lastName(), $user->promo(), $montant,
+                                       $user->isFemale() ? 'Chère' : 'Cher',
+                                       $user->isFemale() ? 'Chère' : 'Cher'), $conf_text);
 
         global $globals;
         $mymail = new PlMailer();
         $mymail->setFrom($conf_mail);
-        $mymail->addTo("\"$prenom $nom\" <$forlife@" . $globals->mail->domain . '>');
         $mymail->addCc($conf_mail);
         $mymail->setSubject($conf_title);
         $mymail->setWikiBody($conf_text);
-        $mymail->send(S::v('mail_fmt') == 'html');
+        $mymail->sendTo($user);
 
         /* on envoie les details de la transaction à telepaiement@ */
         $mymail = new PlMailer();
         $mymail->setFrom("webmaster@" . $globals->mail->domain);
         $mymail->addTo($globals->money->email);
         $mymail->setSubject($conf_title);
-        $msg = "utilisateur : $prenom $nom ($uid)\n".
-               "mail : $forlife@polytechnique.org\n\n".
+        $msg = 'utilisateur : ' . $user->login() . ' (' . $user->id() . ')' . "\n" .
+               'mail : ' . $user->forlifeEmail() . "\n\n" .
                "paiement : $conf_title ($conf_mail)\n".
-               "reference : $no_transaction\n".
+               "reference : $champ200\n".
                "montant : $montant\n\n".
                "dump de REQUEST:\n".
                var_export($_REQUEST,true);
@@ -379,58 +365,24 @@ class PaymentModule extends PLModule
         $tit = $res->fetchAllAssoc();
         $page->assign('titres', $tit);
 
-        $order = Env::v('order', 'timestamp');
-        $orders = array('timestamp', 'nom', 'promo', 'montant', 'comment');
-        if (!in_array($order, $orders)) {
-            $order = 'timestamp';
-        } elseif ($order == 'comment') {
-            $order = 't.comment';
-        }
-        $inv_order = Env::v('order_inv', 0);
-        $page->assign('order', $order);
-        $page->assign('order_inv', !$inv_order);
-
-        if ($order == 'timestamp') {
-            $inv_order = !$inv_order;
-        }
-
-        if ($inv_order) {
-            $inv_order = ' DESC';
-        } else {
-            $inv_order = '';
-        }
-        if ($order == 'montant') {
-            $order = 'LENGTH(montant) '.$inv_order.', montant';
-        }
-
-        $orderby = 'ORDER BY '.$order.$inv_order;
-        if ($order != 'nom') {
-            $orderby .= ', nom'; $inv_order = '';
-        }
-        $orderby .= ', prenom'.$inv_order;
-        if ($order != 'timestamp') {
-            $orderby .= ', timestamp DESC';
-        }
 
+        // TODO: replug sort.
         $trans = array();
         $event = array();
         foreach($tit as $foo) {
             $pid = $foo['id'];
             if (may_update()) {
-                $res = XDB::query("SELECT  IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom,
-                                           u.prenom, u.promo, a.alias, timestamp AS `date`, t.comment, montant
-                                     FROM  {$globals->money->mpay_tprefix}transactions AS t
-                               INNER JOIN  auth_user_md5  AS u ON ( t.uid = u.user_id )
-                               INNER JOIN  aliases        AS a ON ( t.uid = a.id AND a.type='a_vie' )
-                                    WHERE  ref = {?} ".$orderby, $pid);
-                    $trans[$pid] = $res->fetchAllAssoc();
-                    $sum = 0;
-                    foreach ($trans[$pid] as $i => $t) {
-                        $sum += strtr(substr($t['montant'], 0, strpos($t['montant'], 'EUR')), ',', '.');
-                        $trans[$pid][$i]['montant'] = str_replace('EUR', '€', $t['montant']);
-                    }
-                    $trans[$pid][] = array('nom' => 'somme totale',
-                                           'montant' => strtr($sum, '.', ',').' €');
+                $res = XDB::query('SELECT  t.uid, timestamp AS `date`, t.comment, montant
+                                     FROM  ' . $globals->money->mpay_tprefix . 'transactions AS t
+                                    WHERE  t.ref = {?}', $pid);
+                $trans[$pid] = User::getBulkUsersWithUIDs($res->fetchAllAssoc(), 'uid', 'user');
+                $sum = 0;
+                foreach ($trans[$pid] as $i => $t) {
+                    $sum += strtr(substr($t['montant'], 0, strpos($t['montant'], 'EUR')), ',', '.');
+                    $trans[$pid][$i]['montant'] = str_replace('EUR', '€', $t['montant']);
+                }
+                $trans[$pid][] = array('nom' => 'somme totale',
+                                       'montant' => strtr($sum, '.', ',').' €');
             }
             $res = XDB::iterRow("SELECT e.eid, e.short_name, e.intitule, ep.nb, ei.montant, ep.paid
                                    FROM groupex.evenements AS e
index 27c034e..462bae7 100644 (file)
@@ -49,10 +49,8 @@ class CyberPayment
 
         $roboturl = str_replace("https://","http://", $globals->baseurl)
             . '/' . $platal->ns . "payment/cyber_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'))."&CHAMPBPX";
-        $req = XDB::query("SELECT IF(nom_usage!='', nom_usage, nom) AS nom
-                             FROM auth_user_md5
-                            WHERE user_id = {?}",S::v('uid'));
-        $name = $req->fetchOneCell();
+        $user = S::user();
+        $name = $user->lastName();
 
         // on constuit la reference de la transaction
         $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
index 13d1796..c972e56 100644 (file)
@@ -52,10 +52,8 @@ class PayPal
         global $globals, $platal;
 
         $this->urlform = 'https://'.$globals->money->paypal_site.'/cgi-bin/webscr';
-        $req = XDB::query("SELECT  IF(nom_usage!='', nom_usage, nom) AS nom
-                             FROM  auth_user_md5
-                            WHERE  user_id = {?}",S::v('uid'));
-        $name = $req->fetchOneCell();
+        $user = S::user();
+        $name = $user->lastName();
 
         $roboturl = str_replace("https://","http://",$globals->baseurl)
             . '/' . $platal->ns . "payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'));
@@ -77,6 +75,7 @@ class PayPal
             'last_name'  => $name,
             'email'      => S::user()->bestEmail());
 
+        // XXX: waiting for port of adresses.
         $res = XDB::query(
             "SELECT a.adr1 AS address1, a.adr2 AS address2,
                     a.city, a.postcode AS zip, a.country,
index 8edc98f..090b5b5 100644 (file)
@@ -29,7 +29,7 @@ function get_all_redirects($membres, $mls, &$client)
 
     // TODO: add more filters to choose users
     if (!empty($membres)) {
-        $uf = new UserFilter(new UFC_Group($globals->asso('id')))
+        $uf = new UserFilter(new UFC_Group($globals->asso('id')));
         $tos = $uf->getUsers();
     }
 
index 4f25b69..3eec463 100644 (file)
@@ -114,14 +114,12 @@ Voici la liste des paiements en ligne possible pour le groupe {$asso->nom} :
   <tr>
     <td class="center">{$p.date|date_format:"%d/%m/%y"}</td>
     <td>
-      <a href="https://www.polytechnique.org/profile/{$p.alias}" class="popup2">
-        {$p.nom|strtoupper} {$p.prenom}
-       </a>
+      {profile user=$p.user promo=false}
     </td>
     <td>
-      <a href="mailto:{$p.alias}@{#globals.mail.domain#}">{icon name=email title="email"}</a>
+      <a href="mailto:{$p.user->bestEmail()}">{icon name=email title="email"}</a>
     </td>
-    <td class="center">{$p.promo}</td>
+    <td class="center">{$p.user->promo()}</td>
     <td>{$p.comment|comment_decode}</td>
     <td class="right">{$p.montant}</td>
   </tr>