Integrate payment directly in Xnet
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 30 Nov 2006 10:39:19 +0000 (10:39 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 30 Nov 2006 10:39:19 +0000 (10:39 +0000)
Fix some bugs in the calculation of paid amount
Backport [1199]

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1205 839d8a87-29fc-0310-9880-83ba4fa771e5

16 files changed:
htdocs/css/xnet.css
htdocs/images/icons/money.gif [new file with mode: 0644]
htdocs/xnet.php
modules/payment.php
modules/payment/money/cyberpaiement.inc.php
modules/payment/money/paypal.inc.php
modules/xnetevents.php
modules/xnetevents/xnetevents.inc.php
modules/xnetgrp.php
templates/payment/index.tpl
templates/payment/xnet.tpl [new file with mode: 0644]
templates/xnet/groupe/annuaire.tpl
templates/xnet/groupe/telepaiement.tpl [deleted file]
templates/xnetevents/admin.tpl
templates/xnetevents/index.tpl
templates/xnetevents/subscribe.tpl

index cb4ba7f..3c9889a 100644 (file)
@@ -39,6 +39,21 @@ tt,pre {
     font-size: 10pt;
 }
 
+fieldset {
+    border: 1px gray solid;
+
+    margin-top: 1em;
+    margin-bottom: 1em;
+}
+
+legend {
+    border: 1px gray solid;
+    background: #e9e0aa;
+    color: inherit;
+
+    padding: 2px 4px;
+}
+
 a, a:link, a:visited     { text-decoration: none ; color: #5c81aa; }
 
 a img { border: none; }
@@ -238,6 +253,11 @@ th.grayed {
     color: #666;
 }
 
+a.popup2 {
+    color: #4c618a;
+    background-color: inherit;
+}
+
 /***************************************************************************
  * Special pages
  ***************************************************************************/
diff --git a/htdocs/images/icons/money.gif b/htdocs/images/icons/money.gif
new file mode 100644 (file)
index 0000000..1040ec7
Binary files /dev/null and b/htdocs/images/icons/money.gif differ
index e8fbeef..8e55c69 100644 (file)
@@ -24,7 +24,7 @@ $GLOBALS['IS_XNET_SITE'] = true;
 require_once dirname(__FILE__).'/../include/xnet.inc.php';
 
 if (!($path = Env::v('n')) || substr($path, 0, 4) != 'Xnet') {
-    $platal = new Xnet('xnet', 'xnetgrp', 'xnetlists', 'xnetevents', 'geoloc');
+    $platal = new Xnet('xnet', 'xnetgrp', 'xnetlists', 'xnetevents', 'geoloc', 'payment');
     $platal->run();
 
     exit;
index d105f97..834b818 100644 (file)
@@ -79,7 +79,12 @@ class PaymentModule extends PLModule
             'payment'               => $this->make_hook('payment', AUTH_MDP),
             'payment/cyber_return'  => $this->make_hook('cyber_return',  AUTH_PUBLIC),
             'payment/paypal_return' => $this->make_hook('paypal_return',  AUTH_PUBLIC),
+            '%grp/paiement'              => $this->make_hook('xnet_payment', AUTH_MDP),
+            '%grp/payment'               => $this->make_hook('xnet_payment', AUTH_MDP),
+            '%grp/payment/cyber_return'  => $this->make_hook('cyber_return', AUTH_PUBLIC),
+            '%grp/payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUBLIC),
             'admin/payments'        => $this->make_hook('admin', AUTH_MDP, 'admin'),
+        
         );
     }
 
@@ -90,8 +95,22 @@ class PaymentModule extends PLModule
         require_once 'profil.func.inc.php' ;
         require_once dirname(__FILE__).'/payment/money.inc.php' ;
 
-        $page->changeTpl('payment/index.tpl');
-        $page->assign('xorg_title','Polytechnique.org - Télépaiements');
+        if (!empty($GLOBALS['IS_XNET_SITE'])) {
+            if (!$globals->asso('id')) {
+                return PL_NOT_FOUND;
+            }
+            $res = XDB::query("SELECT asso_id
+                                 FROM paiement.paiements
+                                WHERE asso_id = {?} AND id = {?}",
+                              $globals->asso('id'), $ref);
+            if (!$res->numRows()) {
+                return PL_FORBIDDEN;
+            }
+            new_group_page('payment/index.tpl');
+        } else {
+            $page->changeTpl('payment/index.tpl');
+            $page->assign('xorg_title','Polytechnique.org - Télépaiements');
+        }
 
         // initialisation
         $op   = Env::v('op', 'select');
@@ -169,8 +188,9 @@ class PaymentModule extends PLModule
         }
 
         echo ($ref = $matches[1]);
-        $res = XDB::query("SELECT mail,text,confirmation
-                                       FROM paiement.paiements WHERE id={?}", $ref);
+        $res = XDB::query("SELECT  mail,text,confirmation
+                             FROM  paiement.paiements
+                            WHERE  id={?}", $ref);
         if (!list($conf_mail,$conf_title,$conf_text) = $res->fetchOneRow()) {
             cb_erreur("référence de commande inconnue");
         }
@@ -178,9 +198,9 @@ class PaymentModule extends PLModule
         /* on extrait le code de retour */
         if ($champ906 != "0000") {
             $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'");
+                                 FROM  paiement.codeRCB AS rcb
+                            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{ 
@@ -190,8 +210,8 @@ 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'));
+                           VALUES  ({?},{?},{?},{?},{?},{?},{?})",
+                     $champ901, $uid, $ref, $champ200, $montant, $champ905,Env::v('comment'));
 
         /* on genere le mail de confirmation */
         $conf_text = str_replace("<prenom>",$prenom,$conf_text);
@@ -212,7 +232,7 @@ class PaymentModule extends PLModule
         /* on envoie les details de la transaction à telepaiement@ */
         $mymail = new HermesMailer();
         $mymail->setFrom("webmaster@polytechnique.org");
-        $mymail->addTo("telepaiement@polytechnique.org");
+        $mymail->addTo("telepaiement@staff.polytechnique.org");
         $mymail->setSubject($conf_title);
         $msg = "utilisateur : $prenom $nom ($uid)\n".
                "mail : $forlife@polytechnique.org\n\n".
@@ -228,7 +248,11 @@ class PaymentModule extends PLModule
 
     function handler_paypal_return(&$page, $uid = null)
     {
-        $page->changeTpl('payment/retour_paypal.tpl');
+        if (!empty($GLOBALS['IS_XNET_SITE'])) {
+            new_group_open_page('payment/retour_paypal.tpl');
+        } else {
+            $page->changeTpl('payment/retour_paypal.tpl');
+        }
         require_once 'diogenes/diogenes.hermes.inc.php';
 
         /* reference banque (numero de transaction) */
@@ -272,15 +296,16 @@ class PaymentModule extends PLModule
 
         $ref = $matches[1];
         $res = XDB::query("SELECT  mail,text,confirmation
-                                       FROM  paiement.paiements WHERE id={?}", $ref);
+                             FROM  paiement.paiements
+                            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'));
+                           VALUES  ({?},{?},{?},{?},{?},{?},{?})",
+                    $no_transaction, $uid, $ref, $fullref, $montant, $clef, Env::v('comment'));
 
         /* on genere le mail de confirmation */
         $conf_text = str_replace("<prenom>",$prenom,$conf_text);
@@ -316,6 +341,108 @@ class PaymentModule extends PLModule
         $page->assign('texte', $conf_text);
         $page->assign('erreur', $erreur);
     }
+
+    function handler_xnet_payment(&$page, $pid = null)
+    {
+        global $globals;
+        
+        if (!is_null($pid)) {
+            return  $this->handler_payment($page, $pid);
+        }
+        new_group_page('payment/xnet.tpl');
+        
+        $res = XDB::query(
+                "SELECT  id, text, url
+                   FROM  {$globals->money->mpay_tprefix}paiements
+                  WHERE  asso_id = {?} AND NOT FIND_IN_SET(flags, 'old')
+               ORDER BY  id DESC", $globals->asso('id'));
+        $tit = $res->fetchAllAssoc();
+        $page->assign('titres', $tit);
+
+        $order = Env::v('order', 'timestamp');
+        $orders = array('timestamp', 'nom', 'promo', 'montant');
+        if (!in_array($order, $orders)) {
+            $order = 'timestamp';
+        }
+        $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';
+        }
+
+        $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`, 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::iterRow("SELECT e.eid, e.short_name, e.intitule, ep.nb, ei.montant, ep.paid
+                                   FROM groupex.evenements AS e
+                              LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND uid = {?})
+                             INNER JOIN groupex.evenements_items AS ei ON (ep.eid = ei.eid AND ep.item_id = ei.item_id)
+                                  WHERE e.paiement_id = {?}",
+                                 S::v('uid'), $pid);
+            $event[$pid] = array();
+            $event[$pid]['paid'] = 0;
+            if ($res->total()) {
+                $event[$pid]['topay'] = 0;
+                while(list($eid, $shortname, $title, $nb, $montant, $paid) = $res->next()) {
+                    $event[$pid]['topay']     += ($nb * $montant);
+                    $event[$pid]['eid']       = $eid;
+                    $event[$pid]['shortname'] = $shortname;
+                    $event[$pid]['title']     = $title;
+                    $event[$pid]['ins']       = !is_null($nb);
+                    $event[$pid]['paid']      = $paid;
+                }
+            }
+            $res = XDB::query("SELECT montant
+                                 FROM {$globals->money->mpay_tprefix}transactions AS t
+                                WHERE ref = {?} AND uid = {?}", $pid, S::v('uid'));
+            $montants = $res->fetchColumn();
+
+            foreach ($montants as $m) {
+                $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
+                $event[$pid]['paid'] += trim($p);
+            }
+        }
+        $page->assign('trans', $trans);
+        $page->assign('event', $event);
+    }
+    
     function handler_admin(&$page, $action = 'list', $id = null) {
         $page->assign('xorg_title','Polytechnique.org - Administration - Paiements');
         $page->assign('title', 'Gestion des télépaiements');
index 9a35d41..d661f21 100644 (file)
@@ -43,49 +43,48 @@ class CyberPayment
     function prepareform(&$pay)
     {
        // toute la doc se trouve sur
-       // http://www.cyberpaiement.tm.fr/donnees.htm
+       // http://www.cyberpaiement.tm.fr/donnees.htm
 
-        global $globals;
+        global $globals, $platal;
 
-        $roboturl = str_replace("https://","http://",$globals->baseurl)
-            ."/payment/cyber_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'))."&CHAMPBPX";
-        if (Cookie::has(session_name())) {
-            $returnurl .= "?".SID;
-        }
-       $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();
+        $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();
 
         // on constuit la reference de la transaction
         $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
         $fullref = substr("$prefix-xorg-{$pay->id}",-15);
 
         $this->urlform = "https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe";
-       $this->infos['commercant'] = Array(
-               'CHAMP000' => 510879,
-               'CHAMP001' => 5965,
-               'CHAMP002' => 5429159012,
-               'CHAMP003' => "I",
-               'CHAMP004' => "Polytechnique.org",
-               'CHAMP005' => $roboturl,
-               'CHAMP006' => "Polytechnique.org",
-               'CHAMP007' => $globals->baseurl,
-               'CHAMP008' => $pay->mail);
-       $this->infos['client'] = Array(
-               'CHAMP100' => $name,
-               'CHAMP101' => S::v('prenom'),
-               'CHAMP102' => '.',
-               'CHAMP103' => '.',
-               'CHAMP104' => S::v('bestalias').'@polytechnique.org',
-               'CHAMP106' => '.',
-               'CHAMP107' => '.',
-               'CHAMP108' => '.',
-               'CHAMP109' => '.',
-               'CHAMP110' => '.');
-       $this->infos['commande'] = Array(
-               'CHAMP200' => $fullref,
-               'CHAMP201' => $this->val,
-               'CHAMP202' => "EUR");
-       $this->infos['divers'] = Array('CHAMP900' => '01');
+       $this->infos['commercant'] = Array(
+               'CHAMP000' => 510879,
+               'CHAMP001' => 5965,
+               'CHAMP002' => 5429159012,
+               'CHAMP003' => "I",
+               'CHAMP004' => "Polytechnique.org",
+               'CHAMP005' => $roboturl,
+               'CHAMP006' => "Polytechnique.org",
+               'CHAMP007' => $globals->baseurl . '/' . $platal->ns,
+               'CHAMP008' => $pay->mail);
+       $this->infos['client'] = Array(
+               'CHAMP100' => $name,
+               'CHAMP101' => S::v('prenom'),
+               'CHAMP102' => '.',
+               'CHAMP103' => '.',
+               'CHAMP104' => S::v('bestalias').'@polytechnique.org',
+               'CHAMP106' => '.',
+               'CHAMP107' => '.',
+               'CHAMP108' => '.',
+               'CHAMP109' => '.',
+               'CHAMP110' => '.');
+       $this->infos['commande'] = Array(
+               'CHAMP200' => $fullref,
+               'CHAMP201' => $this->val,
+               'CHAMP202' => "EUR");
+       $this->infos['divers'] = Array('CHAMP900' => '01');
     }
 
     // }}}
index edc5924..0b9237d 100644 (file)
@@ -44,58 +44,61 @@ class PayPal
     function prepareform(&$pay)
     {
        // toute la doc sur :
-       // https://www.paypal.com/fr_FR/pdf/integration_guide.pdf
-       // attention : le renvoi automatique ne fonctionne que si
-       // on oblige les gens à créer un compte paypal
-       // nous ne l'utilisons pas ; il faut donc que l'utilisateur
-       // revienne sur le site
-        global $globals;
+       // https://www.paypal.com/fr_FR/pdf/integration_guide.pdf
+       // attention : le renvoi automatique ne fonctionne que si
+       // on oblige les gens à créer un compte paypal
+       // nous ne l'utilisons pas ; il faut donc que l'utilisateur
+       // revienne sur le site
+        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();
+       $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();
 
         $roboturl = str_replace("https://","http://",$globals->baseurl)
-            ."/payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'));
+            . '/' . $platal->ns . "payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'));
 
-       $this->infos = Array();
+       $this->infos = Array();
        
-       $this->infos['commercant'] = Array(
-               'business'    => $globals->money->paypal_compte,
-               'rm'          => 2,
-               'return'      => $roboturl,
-               'cn'          => 'Commentaires',
-               'no_shipping' => 1,
-               'cbt'         => 'Revenir sur polytechnique.org');
+       $this->infos['commercant'] = Array(
+               'business'    => $globals->money->paypal_compte,
+               'rm'          => 2,
+               'return'      => $roboturl,
+               'cn'          => 'Commentaires',
+               'no_shipping' => 1,
+            'cbt'         => empty($GLOBALS['IS_XNET_SITE']) ? 
+                                'Revenir sur polytechnique.org' :
+                                'Revenir sur polytechnique.net');
        
-       $info_client = Array(
-               'first_name' => S::v('prenom'),
-               'last_name'  => $name,
-               'email'      => S::v('bestalias').'@polytechnique.org');
+       $info_client = Array(
+               'first_name' => S::v('prenom'),
+               'last_name'  => $name,
+               'email'      => S::v('bestalias').'@polytechnique.org');
                
-       $res = XDB::query(
-               "SELECT a.adr1 AS address1, a.adr2 AS address2,
-                       a.city, a.postcode AS zip, a.country,
-                       IF(t.tel, t.tel, q.profile_mobile) AS night_phone_b
-                  FROM auth_user_quick AS q
-             LEFT JOIN adresses        AS a ON (q.user_id = a.uid AND FIND_IN_SET('active', a.statut))
-             LEFT JOIN tels        AS t ON (t.uid = a.uid AND t.adrid = a.adrid)
+       $res = XDB::query(
+               "SELECT a.adr1 AS address1, a.adr2 AS address2,
+                               a.city, a.postcode AS zip, a.country,
+                       IF(t.tel, t.tel, q.profile_mobile) AS night_phone_b
+                  FROM auth_user_quick AS q
+         LEFT JOIN adresses    AS a ON (q.user_id = a.uid AND FIND_IN_SET('active', a.statut))
+          LEFT JOIN tels        AS t ON (t.uid = a.uid AND t.adrid = a.adrid)
                  WHERE q.user_id = {?}
-                 LIMIT 1", S::v('uid'));
-       $this->infos['client']=array_merge($info_client, $res->fetchOneAssoc());
+                 LIMIT 1", S::v('uid'));
+       $this->infos['client'] = array_merge($info_client, $res->fetchOneAssoc());
 
         // on constuit la reference de la transaction
         $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
         $fullref = substr("$prefix-xorg-{$pay->id}",-15);
 
-       $this->infos['commande'] = Array(
-               'item_name'     => $pay->text,
-               'amount'        => $this->val_number,
-               'currency_code' => 'EUR',
-               'custom'        => $fullref);
-
-       $this->infos['divers'] = Array('cmd' => '_xclick');
+       $this->infos['commande'] = Array(
+               'item_name'     => $pay->text,
+               'amount'        => $this->val_number,
+               'currency_code' => 'EUR',
+               'custom'        => $fullref);
 
+       $this->infos['divers'] = Array('cmd' => '_xclick');
     }
 
     // }}}
index 7afb82e..53c6186 100644 (file)
@@ -140,7 +140,7 @@ class XnetEventsModule extends PLModule
         while ($e = $evenements->next()) {
             $e['show_participants'] = ($e['show_participants'] && (is_member() || may_update()));
             $res = XDB::query(
-                "SELECT titre, details, montant, ei.item_id, nb
+                "SELECT titre, details, montant, ei.item_id, nb, ep.paid
                    FROM groupex.evenements_items AS ei
               LEFT JOIN groupex.evenements_participants AS ep
                         ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?})
@@ -149,6 +149,7 @@ class XnetEventsModule extends PLModule
             $e['moments'] = $res->fetchAllAssoc();
 
             $e['topay'] = 0;
+            $e['paid']  = $e['moments'][0]['paid'];
             foreach ($e['moments'] as $m) {
                 $e['topay'] += $m['nb'] * $m['montant'];
             }
@@ -217,7 +218,7 @@ class XnetEventsModule extends PLModule
         }
 
         // impossible to unsubscribe if you already paid sthing
-        if (array_sum($subs) && $evt['paid'] != 0) {
+        if (!array_sum($subs) && $evt['paid'] != 0) {
             $page->trig("Impossible de te désinscrire complètement ".
                         "parce que tu as fait un paiement par ".
                         "chèque ou par liquide. Contacte un ".
index 8615f8b..ed5794c 100644 (file)
@@ -68,7 +68,7 @@ function get_event_detail($eid, $item_id = false)
     }
 
     $res = XDB::query(
-        "SELECT titre, details, montant, ei.item_id, nb
+        "SELECT titre, details, montant, ei.item_id, nb, ep.paid
            FROM groupex.evenements_items        AS ei
       LEFT JOIN groupex.evenements_participants AS ep
                 ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?})
@@ -77,10 +77,13 @@ function get_event_detail($eid, $item_id = false)
     $evt['moments'] = $res->fetchAllAssoc();
 
     $evt['topay'] = 0;
+    $evt['paid'] = 0;
     foreach ($evt['moments'] as $m) {
         $evt['topay'] += $m['nb'] * $m['montant'];
-        if ($m['montant'])
+        if ($m['montant']) {
             $evt['money'] = true;
+        }
+        $evt['paid']  = $m['paid'];
     }
 
     $req = XDB::query(
@@ -89,7 +92,6 @@ function get_event_detail($eid, $item_id = false)
          WHERE ref = {?} AND uid = {?}", $evt['paiement_id'], S::v('uid'));
     $montants = $req->fetchColumn();
 
-    $evt['paid'] = 0;
     foreach ($montants as $m) {
         $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
         $evt['paid'] += trim($p);
index 1b17bf6..af4f6ea 100644 (file)
@@ -82,7 +82,6 @@ class XnetGrpModule extends PLModule
             '%grp/annuaire/vcard' => $this->make_hook('vcard',     AUTH_MDP),
             '%grp/trombi'         => $this->make_hook('trombi',    AUTH_MDP),
             '%grp/subscribe'      => $this->make_hook('subscribe', AUTH_MDP),
-            '%grp/paiement'       => $this->make_hook('paiement',  AUTH_MDP),
 
             '%grp/admin/annuaire'
                  => $this->make_hook('admin_annuaire', AUTH_MDP),
@@ -566,74 +565,6 @@ class XnetGrpModule extends PLModule
         }
     }
 
-    function handler_paiement(&$page)
-    {
-        global $globals;
-
-        new_group_page('xnet/groupe/telepaiement.tpl');
-
-        $res = XDB::query(
-                "SELECT id, text
-                  FROM {$globals->money->mpay_tprefix}paiements
-                 WHERE asso_id = {?} AND NOT FIND_IN_SET(flags, 'old')
-              ORDER BY id DESC", $globals->asso('id'));
-        $tit = $res->fetchAllAssoc();
-        $page->assign('titres', $tit);
-
-        $order = Env::v('order', 'timestamp');
-        $orders = array('timestamp', 'nom', 'promo', 'montant');
-        if (!in_array($order, $orders)) {
-            $order = 'timestamp';
-        }
-        $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';
-        }
-
-        if (may_update()) {
-            $trans = array();
-            foreach($tit as $foo) {
-                $pid = $foo['id'];
-                $res = XDB::query(
-                        "SELECT  IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom,
-                                 u.prenom, u.promo, a.alias, timestamp AS `date`, 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][] = array('nom' => 'somme totale',
-                                       'montant' => strtr($sum, '.', ',').' EUR');
-            }
-            $page->assign('trans', $trans);
-        }
-    }
-
     function handler_admin_annuaire(&$page)
     {
         global $globals;
@@ -942,13 +873,15 @@ class XnetGrpModule extends PLModule
                              INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
                                                                   AND (a.promo_max = 0 OR a.promo_max <= u.promo))
                              INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
-                                  WHERE u.user_id = {?} AND peremption >= NOW()", $uid);
+                             WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
+                                   $uid, $globals->asso('id'));
         } else {
             $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
                                          IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
                                     FROM groupex.announces AS a
                              INNER JOIN auth_user_md5 AS u USING(user_id)
-                                   WHERE FIND_IN_SET(a.flags, 'public') AND peremption >= NOW()");
+                             WHERE FIND_IN_SET(a.flags, 'public') AND peremption >= NOW() AND a.asso_id = {?}",
+                                  $globals->asso('id'));
         }
         $page->assign('asso', $globals->asso());
         $page->assign('rss', $rss);
index ae4e189..25c5bec 100644 (file)
@@ -34,8 +34,8 @@
     <td>{$pay->text}</td>
   </tr>
   <tr>
-    <td><b>Montant (euros)</b></td>
-    <td>{$montant}</td>
+    <td><b>Montant</b></td>
+    <td>{$montant} &euro;</td>
   </tr>
 {if $comment}
   <tr>
@@ -116,10 +116,14 @@ function payment_submit(form)
     <tr>
       <td>Transaction</td>
       <td>
+        {if $asso}
+        <strong>{$pay->text}</strong><input type="hidden" name="ref" value="{$pay->id}" />
+        {else}
         <select name="ref" onchange="payment_submit(this.form)">
           {select_db_table table="`$prefix`paiements" valeur=$pay->id where="WHERE FIND_IN_SET('old',t.flags)=0"
                            join="LEFT JOIN groupex.asso AS g ON (t.asso_id = g.id)" group="g.nom"}
         </select>
+        {/if}
         {if $pay->url}
         <br />
         <a href="{$pay->url}">plus d'informations</a>
@@ -135,8 +139,8 @@ function payment_submit(form)
       </td>
     </tr>
     <tr>
-      <td>Montant (euros)</td>
-      <td><input type="text" name="montant" size="13" class='right' value="{$montant}" /></td>
+      <td>Montant</td>
+      <td><input type="text" name="montant" size="13" class='right' value="{$montant}" /> &euro;</td>
     </tr>
     <tr>
       <td>Commentaire</td>
diff --git a/templates/payment/xnet.tpl b/templates/payment/xnet.tpl
new file mode 100644 (file)
index 0000000..33dcf40
--- /dev/null
@@ -0,0 +1,146 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2006 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>{$asso.nom} : Gestion des télépaiements </h1>
+
+<p class="descr">
+Voici la liste des paiements en ligne possible pour le groupe {$asso.nom}
+</p>
+
+{foreach from=$titres item=p}
+
+<fieldset>
+<legend><a href="{$platal->ns}payment/{$p.id}">{icon name=money title="Télépaiement"}{$p.text}</a></legend>
+
+{if $event[$p.id]}
+{assign var='ev' value=$event[$p.id]}
+<p>
+  {if $p.url}
+  Plus d'informations sur ce télépaiement sont disponibles sur <a href="{$p.url}">cette page</a>.<br />
+  {/if}
+  {if $ev.eid}
+  Ce paiement est associé à l'événement <a href="{$platal->ns}events">{$ev.title}</a>.<br />
+    {if $ev.ins}
+    Tu es inscrit à cet événements.
+      {if $ev.topay > $ev.paid}
+      <a href="{$platal->ns}payment/{$p.id}?montant={math equation="a-b" a=$ev.topay b=$ev.paid}">
+        Tu dois encore payer {math equation="a-b" a=$ev.topay b=$ev.paid}&euro;
+      </a>
+      {elseif $ev.topay eq $ev.paid}
+      Tu as déjà réglé l'intégralité de ton inscription ({$ev.topay}&euro;)
+      {else}
+      Tu as réglé {$ev.paid}&euro; alors que tu n'en devais que {$ev.topay}&euro;
+      {/if}
+    {else}
+    <a href="{$platal->ns}events/sub/{$ev.eid}">Tu peux t'inscire à cet événement.</a>
+    {/if}
+  {else}
+    {if !$ev.paid}
+    Tu n'as actuellement rien payé sur ce télépaiement
+    {else}
+    Tu as déjà payé {$ev.paid}&euro;.
+    {/if}
+  {/if}
+</p>
+{/if}
+
+{if $is_admin && $trans[$p.id]}
+<p>Liste des personnes ayant payé (pour les administrateurs uniquement)&nbsp;:</p>
+<table cellpadding="0" cellspacing="0" id="list_{$p.id}" class='tinybicol'>
+  <tr>
+    <th class="center">
+      {if $order eq 'timestamp'}
+        <a href='{$platal->ns}payment?order={$order}&order_inv={$order_inv}'>
+          <img src="{$platal->baseurl}images/{if !$order_inv}dn{else}up{/if}.png" alt="" title="Tri {if $order_inv}dé{/if}croissant" />
+      {else}
+        <a href='{$platal->ns}payment?order=timestamp'>
+      {/if}Date</a>
+    </th>
+    <th colspan="2" class="center">
+      {if $order eq 'nom'}
+        <a href='{$platal->ns}payment?order={$order}&order_inv={$order_inv}'>
+          <img src="{$platal->baseurl}images/{if $order_inv}dn{else}up{/if}.png" alt="" title="Tri {if !$order_inv}dé{/if}croissant" />
+      {else}
+        <a href='{$platal->ns}payment?order=nom'>{/if}
+      NOM Prénom</a>
+    </th>
+    <th class="center">
+      {if $order eq 'promo'}
+        <a href='{$platal->ns}payment?order={$order}&order_inv={$order_inv}'>
+          <img src="{$platal->baseurl}images/{if $order_inv}dn{else}up{/if}.png" alt="" title="Tri {if !$order_inv}dé{/if}croissant" />
+      {else}
+        <a href='{$platal->ns}payment?order=promo'>
+      {/if}Promo</a>
+    </th>
+    <th class="center">
+      {if $order eq 'montant'}
+        <a href='{$platal->ns}payment?order={$order}&order_inv={$order_inv}'>
+          <img src="{$platal->baseurl}images/{if $order_inv}dn{else}up{/if}.png" alt="" title="Tri {if !$order_inv}dé{/if}croissant" />
+      {else}
+        <a href='{$platal->ns}payment?order=montant'>
+      {/if}Montant</a>
+    </th>
+  </tr>
+  {assign var="somme" value=0}
+  {foreach from=$trans[$p.id] item=p name=people}
+  {if $p.nom neq "somme totale"}
+  <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>
+    </td>
+    <td>
+      <a href="mailto:{$p.alias}@polytechnique.org">{icon name=email title="mail"}</a>
+    </td>
+    <td class="center">{$p.promo}</td>
+    <td class="right">{$p.montant}</td>
+  </tr>
+  {elseif $smarty.foreach.people.first}
+  <tr>
+    <td colspan="5" class="center">Personne n'a encore payé pour ce télépaiement</td>
+  </tr>
+  {else}
+  <tr class="pair">
+    <td class="right" colspan="4"><strong>Total </strong></td>
+    <th class="right">{$p.montant}</th>
+  </tr>
+  {/if}
+  {/foreach}
+</table>
+{elseif $is_admin}
+Aucun versement n'a actuellement été réalisé sur ce télépaiement
+{else}
+Tu n'as pas payé pour ce télépaiement
+{/if}
+</fieldset>
+
+{foreachelse}
+
+<p class="descr">
+<em>Pas de télépaiement en cours ...</em>
+</p>
+
+{/foreach}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index f2dcd17..2ee139c 100644 (file)
@@ -97,9 +97,9 @@ Tu peux 
     <td>
       {if $m.admin}<strong>{/if}
       {if $m.inscrit}
-      <a href="https://www.polytechnique.org/profile/{$m.email}" class="popup2" style="color: #4c618a;">
+      <a href="https://www.polytechnique.org/profile/{$m.email}" class="popup2">
       {elseif $m.x}
-      <a href="https://www.polytechnique.org/marketing/public/{$m.uid}" style="color: #4c618a;">
+      <a href="https://www.polytechnique.org/marketing/public/{$m.uid}">
       {/if}
       {if $m.femme}&bull;{/if}{$m.prenom} {$m.nom|strtoupper}
       {if $m.x}</a>{/if} 
diff --git a/templates/xnet/groupe/telepaiement.tpl b/templates/xnet/groupe/telepaiement.tpl
deleted file mode 100644 (file)
index 3c97e45..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-{**************************************************************************}
-{*                                                                        *}
-{*  Copyright (C) 2003-2006 Polytechnique.org                             *}
-{*  http://opensource.polytechnique.org/                                  *}
-{*                                                                        *}
-{*  This program is free software; you can redistribute it and/or modify  *}
-{*  it under the terms of the GNU General Public License as published by  *}
-{*  the Free Software Foundation; either version 2 of the License, or     *}
-{*  (at your option) any later version.                                   *}
-{*                                                                        *}
-{*  This program is distributed in the hope that it will be useful,       *}
-{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
-{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
-{*  GNU General Public License for more details.                          *}
-{*                                                                        *}
-{*  You should have received a copy of the GNU General Public License     *}
-{*  along with this program; if not, write to the Free Software           *}
-{*  Foundation, Inc.,                                                     *}
-{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
-{*                                                                        *}
-{**************************************************************************}
-
-<h1>{$asso.nom} : Gestion des télépaiements </h1>
-
-<p class="descr">
-Voici la liste des paiements en ligne possible pour le groupe {$asso.nom}
-</p>
-
-{foreach from=$titres item=p}
-
-<hr />
-<h2>
-<a href="https://www.polytechnique.org/payment/{$p.id}">{$p.text}</a>
-</h2>
-
-{if $trans[$p.id]}
-<table cellpadding="0" cellspacing="0" class='bicol'>
-  <tr>
-    <th colspan="4">{$p.text} : détails pour les administrateurs</th>
-  </tr>
-  <tr>
-    <td class="center">[{if $order eq 'timestamp'}<strong><a href='{$platal->ns}paiement?order={$order}&order_inv={$order_inv}'>{else}<a href='{$platal->ns}paiement?order=timestamp'>{/if}Date</a>{if $order eq 'timestamp'}</strong>{/if}]</td>
-    <td class="center">[{if $order eq 'nom'}<strong><a href='{$platal->ns}paiement?order={$order}&order_inv={$order_inv}'>{else}<a href='{$platal->ns}paiement?order=nom'>{/if}Prénom NOM</a>{if $order eq 'nom'}</strong>{/if}]</td>
-    <td class="center">[{if $order eq 'promo'}<strong><a href='{$platal->ns}paiement?order={$order}&order_inv={$order_inv}'>{else}<a href='{$platal->ns}paiement?order=promo'>{/if}Promo</a>{if $order eq 'promo'}</strong>{/if}]</td>
-    <td class="center">[{if $order eq 'montant'}<strong><a href='{$platal->ns}paiement?order={$order}&order_inv={$order_inv}'>{else}<a href='{$platal->ns}paiement?order=montant'>{/if}Montant</a>{if $order eq 'montant'}</strong>{/if}]</td>
-  </tr>
-  {assign var="somme" value=0}
-  {foreach from=$trans[$p.id] item=p}
-  <tr>
-    {if $p.nom neq "somme totale"}
-        <td class="center">{$p.date|date_format:"%d/%m/%y"}</td>
-        <td>
-          {$p.prenom} {$p.nom}
-          <a href="https://www.polytechnique.org/profile/{$p.alias}">{icon name=user_suit title="fiche"}</a>
-          <a href="mailto:{$p.alias}@polytechnique.org">{icon name=email title="mail"}</a>
-        </td>
-        <td class="center">X {$p.promo}</td>
-        <td class="right">{$p.montant}</td>
-    {else}
-        <td class="right" colspan="3"><strong>Total </strong></td>
-        <th class="right">{$p.montant}</th>
-    {/if}        
-  </tr>
-  {/foreach}
-</table>
-{/if}
-
-{foreachelse}
-
-<p class="descr">
-<em>Pas de télépaiement en cours ...</em>
-</p>
-
-{/foreach}
-
-{* vim:set et sw=2 sts=2 sws=2: *}
index 4177566..9b88393 100644 (file)
@@ -68,7 +68,7 @@ function remplitAuto(mail) {
 Ils ont payé mais ont oublié de s'inscrire :
 </p>
 
-<table summary="payé mais non inscrits" class="tiny">
+<table summary="payé mais non inscrits" class="tinybicol">
   <tr>
     <th>Prénom NOM</th>
     <th>Promo</th>
@@ -76,7 +76,7 @@ Ils ont pay
     <th>Montant</th>
   </tr>
   {iterate from=$oubliinscription item=m}
-  <tr style="background:#d0c198;">
+  <tr class="pair">
     <td>
       <a href="" {if $is_admin}onclick="return remplitAuto('{$m.email}')"{/if}>
       {$m.prenom} {$m.nom}
index 0daa0c1..aed7bd2 100644 (file)
 {if $updated}
 <p class='error'>
   La modification de l'inscription a été prise en compte !
-  {if $updated.topay}
-    <br/>N'oublie pas de payer {$updated.topay|replace:'.':','}&nbsp;&euro;
+  {if $updated.topay > $updated.paid}
+    <br/>N'oublie pas de payer {math equation="a-b" a=$updated.topay b=$updated.paid}&nbsp;&euro;
     {if $updated.paid > 0}
     (tu as déjà payé {$updated.paid|replace:'.':','}&nbsp;&euro;)
     {/if}
     {if $updated.paiement_id}
-    [<a href="https://www.polytechnique.org/payment/{$updated.paiement_id}?montant={$updated.topay}">
+    [<a href="{$platal->ns}payment/{$updated.paiement_id}?montant={math equation="a-b" a=$updated.topay b=$updated.paid}">
     Payer en ligne</a>]
     {/if}
   {/if}
 
       {if $e.topay}
       <span class="error">
-      Tu dois payer {$e.topay|replace:'.':','}&nbsp;&euro;
-      {if $e.paid > 0}
-      (tu as déjà payé {$e.paid|replace:'.':','}&nbsp;&euro;)
-      {/if}
-      {if $e.paiement_id}
-        [<a href="https://www.polytechnique.org/payment/{$e.paiement_id}?montant={$e.topay}}">
+        {if !$e.paid}
+        Tu dois payer {$e.topay|replace:'.':','}&nbsp;&euro;.
+        {elseif $e.paid < $e.topay}
+        Tu dois encore payer {math equation="a-b" a=$e.topay b=$e.paid|replace:'.':','}&nbsp;&euro;
+        (tu as déjà payé {$e.paid|replace:'.':','}&nbsp;&euro;)
+        {else}
+        Tu as déjà payé {$e.paid|replace:'.':','}&nbsp;&euro; pour ton inscription.
+        {/if}
+        {if $e.paiement_id &&  $e.paid < $e.topay}
+        [<a href="{$platal->ns}payment/{$e.paiement_id}?montant={math equation="a-b" a=$e.topay b=$e.paid}">
         Payer en ligne</a>]
-      {/if}
+        {/if}
       </span>
       {/if}
     </td>
index ded6c03..a421033 100644 (file)
       <td>
         {if $event.topay}
         <span class="error">
-        Tu dois payer {$event.topay|replace:'.':','}&nbsp;&euro;
-        {if $event.paid > 0}
-        (tu as déjà payé {$event.paid|replace:'.':','}&nbsp;&euro;)
-        {/if}.
-        {if $event.paiement_id}
-          [<a href="https://www.polytechnique.org/payment/{$event.paiement_id}?montant={$event.topay}}">
+          {if !$event.paid}
+          Tu dois payer {$event.topay|replace:'.':','}&nbsp;&euro;.
+          {elseif $event.paid < $event.topay}
+          Tu dois encore payer {math equation="a-b" a=$event.topay b=$event.paid|replace:'.':','}&nbsp;&euro;
+          (tu as déjà payé {$event.paid|replace:'.':','}&nbsp;&euro;)
+          {else} 
+          Tu as déjà payé {$event.paid|replace:'.':','}&nbsp;&euro; pour ton inscription.
+          {/if} 
+          {if $event.paiement_id &&  $event.paid < $event.topay}
+          [<a href="{$platal->ns}payment/{$event.paiement_id}?montant={math equation="a-b" a=$event.topay b=$event.paid}">
           Payer en ligne</a>]
-        {/if}
+          {/if}
         </span>
         {else}
         Rien à payer