X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fpayment.php;h=59f4574ff772a23b6447516f68510608213de4f2;hb=05978b09201b86278849d6448a15b4a59e2ed852;hp=d1942434b1437141d681aab052338b063ea44ce0;hpb=f336915bd25f046ed90b4d7e144384d7242adc97;p=platal.git diff --git a/modules/payment.php b/modules/payment.php index d194243..59f4574 100644 --- a/modules/payment.php +++ b/modules/payment.php @@ -1,6 +1,6 @@ $this->make_hook('payment', AUTH_MDP, 'payment'), - 'payment/cyber_return' => $this->make_hook('cyber_return', AUTH_PUBLIC, 'user', NO_HTTPS), 'payment/cyber2_return' => $this->make_hook('cyber2_return', AUTH_PUBLIC, 'user', NO_HTTPS), 'payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUBLIC, 'user', NO_HTTPS), '%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, 'user', NO_HTTPS), + '%grp/payment/csv' => $this->make_hook('payment_csv', AUTH_MDP, 'groupadmin'), '%grp/payment/cyber2_return' => $this->make_hook('cyber2_return', AUTH_PUBLIC, 'user', NO_HTTPS), '%grp/payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUBLIC, 'user', NO_HTTPS), 'admin/payments' => $this->make_hook('admin', AUTH_MDP, 'admin'), @@ -124,7 +123,7 @@ class PaymentModule extends PLModule ); } - function handler_payment(&$page, $ref = -1) + function handler_payment($page, $ref = -1) { global $globals; @@ -182,107 +181,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) - { - /* reference banque (numero de transaction) */ - $champ901 = Env::s('CHAMP901'); - /* cle d'acceptation */ - $champ905 = Env::s('CHAMP905'); - /* code retour */ - $champ906 = Env::s('CHAMP906'); - /* email renvoye par la banque */ - $champ104 = Env::s('CHAMP104'); - /* reference complete de la commande */ - $champ200 = Env::s('CHAMP200'); - /* montant de la transaction */ - $champ201 = Env::s('CHAMP201'); - /* devise */ - $champ202 = Env::s('CHAMP202'); - $montant = "$champ201 $champ202"; - - /* on extrait les informations sur l'utilisateur */ - $user = User::get($uid); - if (!$user) { - cb_erreur("uid invalide"); - } - - - /* on extrait la reference de la commande */ - 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 - FROM payments - WHERE id = {?}', $ref); - 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 - FROM payment_codeRCB AS rcb - LEFT JOIN payment_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{ - cb_erreur("erreur inconnue lors du paiement"); - } - } - - /* on fait l'insertion en base de donnees */ - XDB::execute('INSERT INTO payment_transactions (id, uid, ref, fullref, amount, pkey, comment) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', - $champ901, $user->id(), $ref, $champ200, $montant, $champ905, Env::v('comment')); - - // We check if it is an Xnet payment and then update the related ML. - $res = XDB::query('SELECT eid - FROM group_events - WHERE paiement_id = {?}', $ref); - if ($eid = $res->fetchOneCell()) { - require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php'; - $evt = get_event_detail($eid); - subscribe_lists_event($uid, $evt, 1, $montant, true); - } - - /* on genere le mail de confirmation */ - $conf_text = str_replace( - array('', '', '', '', '', '', 'comment>'), - array($user->firstName(), $user->lastName(), $user->promo(), $montant, - $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher', - Env::v('comment')), $conf_text); - - global $globals; - $mymail = new PlMailer(); - $mymail->setFrom($conf_mail); - $mymail->addCc($conf_mail); - $mymail->setSubject($conf_title); - $mymail->setWikiBody($conf_text); - $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 : ' . $user->login() . ' (' . $user->id() . ')' . "\n" . - 'mail : ' . $user->forlifeEmail() . "\n\n" . - "paiement : $conf_title ($conf_mail)\n". - "reference : $champ200\n". - "montant : $montant\n\n". - "dump de REQUEST:\n". - var_export($_REQUEST,true); - $mymail->setTxtBody($msg); - $mymail->send(); - exit; - } - - function handler_cyber2_return(&$page, $uid = null) + function handler_cyber2_return($page, $uid = null) { global $globals, $platal; @@ -344,7 +246,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, 1, $amount, true); + subscribe_lists_event($user->id(), $evt['short_name'], 1, $amount, true); } /* on genere le mail de confirmation */ @@ -352,7 +254,7 @@ class PaymentModule extends PLModule array('', '', '', '', '', '', ''), array($user->firstName(), $user->lastName(), $user->promo(), $montant, $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher', - Env::v('comment')), $conf_text); + Env::v('vads_order_info')), $conf_text); global $globals; $mymail = new PlMailer(); @@ -380,7 +282,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'); @@ -440,14 +342,14 @@ class PaymentModule extends PLModule if ($eid = $res->fetchOneCell()) { require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php'; $evt = get_event_detail($eid); - subscribe_lists_event($user->id(), $evt, 1, $montant, true); + subscribe_lists_event($user->id(), $evt['short_name'], 1, $montant, true); } /* on genere le mail de confirmation */ - $conf_text = str_replace(array('', '', '', '', '', ''), + $conf_text = str_replace(array('', '', '', '', '', '', ''), array($user->firstName(), $user->lastName(), $user->promo(), $montant, - $user->isFemale() ? 'Chère' : 'Cher', - $user->isFemale() ? 'Chère' : 'Cher'), $conf_text); + $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher', + Env::v('comment')), $conf_text); global $globals; $mymail = new PlMailer(); @@ -476,7 +378,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; @@ -486,8 +388,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) { @@ -588,7 +490,44 @@ class PaymentModule extends PLModule $page->assign('event', $event); } - function handler_admin(&$page, $action = 'list', $id = null) { + function handler_payment_csv($page, $pid = null) + { + if (is_null($pid)) { + pl_redirect('payment'); + } + if (substr($pid, -4) == '.vcf') { + $pid = substr($pid, 0, strlen($pid) - 4); + } + + $res = XDB::fetchAllAssoc('SELECT uid, IF(timestamp = \'0000-00-00\', 0, timestamp) AS date, comment, amount + FROM payment_transactions + WHERE ref = {?} + ORDER BY timestamp', + $pid); + if (is_null($res)) { + pl_redirect('payment'); + } + + $users = User::getBulkUsersWithUIDs($res, 'uid', 'user'); + $sum = 0; + + pl_cached_content_headers('text/x-csv', 1); + $csv = fopen('php://output', 'w'); + fputcsv($csv, array('Date', 'Nom', 'Prénom', 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';'); + foreach ($users as $item) { + $user = $item['user']; + $sum += strtr(substr($item['amount'], 0, strpos($item['amount'], 'EUR')), ',', '.'); + fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), $user->lastName(), $user->firstName(), + ($user->isFemale()) ? 'F' : 'M', $user->promo(), $user->ForlifeEmail(), + $item['comment'], str_replace('EUR', '€', $item['amount'])), ';'); + } + fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum, '.', ',') . ' €'), ';'); + + fclose($csv); + exit; + } + + 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'); @@ -611,7 +550,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}"); @@ -625,7 +564,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"); @@ -646,7 +585,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'); @@ -654,7 +593,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'); @@ -721,7 +660,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); @@ -893,7 +832,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')) {