<?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 *
{
return array(
'payment' => $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'),
);
}
- function handler_payment(&$page, $ref = -1)
+ function handler_payment($page, $ref = -1)
{
global $globals;
$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('<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);
-
- 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;
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 */
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);
+ Env::v('vads_order_info')), $conf_text);
global $globals;
$mymail = new PlMailer();
exit;
}
- function handler_paypal_return(&$page, $uid = null)
+ function handler_paypal_return($page, $uid = null)
{
$page->changeTpl('payment/retour_paypal.tpl');
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('<prenom>', '<nom>', '<promo>', '<montant>', '<salutation>', '<cher>'),
+ $conf_text = str_replace(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'), $conf_text);
+ $user->isFemale() ? 'Chère' : 'Cher', $user->isFemale() ? 'Chère' : 'Cher',
+ Env::v('comment')), $conf_text);
global $globals;
$mymail = new PlMailer();
$page->assign('erreur', $erreur);
}
- function handler_xnet_payment(&$page, $pid = null)
+ function handler_xnet_payment($page, $pid = null)
{
global $globals;
$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');
$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}");
$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");
$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');
$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');
}
}
- 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);
}
}
- 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')) {