From 2ac0bcee0c4da41699b4c396ea82c0abc256e4df Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 16 Sep 2007 23:27:41 +0200 Subject: [PATCH] Closes #702: When a payment associated with an event is validated, the subscribers of that event can be notified they can pay. Signed-off-by: Florent Bruneau --- ChangeLog | 3 +++ configs/mails.conf | 3 +++ include/validations/paiements.inc.php | 38 ++++++++++++++++++++++---- modules/xnetevents.php | 13 ++++++--- modules/xnetevents/xnetevents.inc.php | 44 ++++++++++++++++++------------- templates/xnetevents/mail.new_payment.tpl | 38 ++++++++++++++++++++++++++ templates/xnetevents/subscribe.tpl | 12 ++++++--- upgrade/0.9.15/05_payment.sql | 4 +++ 8 files changed, 124 insertions(+), 31 deletions(-) create mode 100644 templates/xnetevents/mail.new_payment.tpl create mode 100644 upgrade/0.9.15/05_payment.sql diff --git a/ChangeLog b/ChangeLog index 0a3cdb2..1363407 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ New: * Search: - Shortcuts to open profiles or search in documentation -FRU + * XnetEvents: + - #702: Be notified of the availability of the payment -FRU + Bug/Wish: * Auth: diff --git a/configs/mails.conf b/configs/mails.conf index f0b3d7b..b3a6082 100644 --- a/configs/mails.conf +++ b/configs/mails.conf @@ -38,3 +38,6 @@ to=geoloc@staff.polytechnique.org [mails_ax] from="Association des Anciens élèves de l'X" replyto=info@amicale.polytechnique.org + +[payment_ready] +from="Gestion des paiements" diff --git a/include/validations/paiements.inc.php b/include/validations/paiements.inc.php index 54a01ba..6782166 100644 --- a/include/validations/paiements.inc.php +++ b/include/validations/paiements.inc.php @@ -51,8 +51,8 @@ class PayReq extends Validate $this->titre = $_intitule; $this->site = $_site; $this->msg_reponse = $_msg; - $this->asso_id = $_asso_id; - $this->evt = $_evt; + $this->asso_id = (string)$_asso_id; + $this->evt = (string)$_evt; $this->montant = $_montant; $this->montant_min = $_montantmin; $this->montant_max = $_montantmax; @@ -174,9 +174,37 @@ class PayReq extends Validate $id, $this->titre, $this->site, $this->montant, $this->montant_min, $this->montant_max, $this->bestalias."@".$globals->mail->domain, $this->msg_reponse, $this->asso_id); - if ($this->asso_id && $this->evt) - $ret = XDB::execute("UPDATE groupex.evenements SET paiement_id = {?} WHERE asso_id = {?} AND eid = {?}", $id, $this->asso_id, $this->evt); - + if ($this->asso_id && $this->evt) { + XDB::execute("UPDATE groupex.evenements + SET paiement_id = {?} + WHERE asso_id = {?} AND eid = {?}", + $id, $this->asso_id, $this->evt); + $res = XDB::query("SELECT a.nom, a.diminutif, e.intitule + FROM groupex.asso AS a + INNER JOIN groupex.evenements AS e ON (a.id = e.asso_id) + WHERE e.eid = {?}", + $this->evt); + list($nom, $diminutif, $evt) = $res->fetchOneRow(); + $mailer = new PlMailer('xnetevents/mail.new_payment.tpl'); + $mailer->assign('asso', $nom); + $mailer->assign('diminutif', $diminutif); + $mailer->assign('evt', $evt); + $mailer->assign('payment', $id); + require_once dirname(__FILE__) . '/../../modules/xnetevents/xnetevents.inc.php'; + $participants = get_event_participants(get_event_detail($this->evt, false, $this->asso_id), null, 'nom'); + foreach ($participants as &$u) { + if (!$u['notify_payment']) { + continue; + } + $topay = $u['montant'] - $u['paid']; + if ($topay > 0) { + $mailer->assign('prenom', $u['prenom']); + $mailer->assign('topay', $topay); + $mailer->assign('to', $u['email']); + $mailer->send(); + } + } + } return $ret; } diff --git a/modules/xnetevents.php b/modules/xnetevents.php index e7e939e..56dacd4 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -186,6 +186,11 @@ class XnetEventsModule extends PLModule $page->kill('Cet événement est fermé aux non-membres du groupe'); } + global $globals; + $res = XDB::query("SELECT stamp FROM requests + WHERE type = 'paiements' AND data LIKE {?}", + PayReq::same_event($evt['eid'], $globals->asso('id'))); + $page->assign('validation', $res->numRows()); $page->assign('event', $evt); if (!Post::has('submit')) { @@ -229,8 +234,8 @@ class XnetEventsModule extends PLModule if ($nb >= 0) { XDB::execute( "REPLACE INTO groupex.evenements_participants - VALUES ({?}, {?}, {?}, {?}, {?})", - $eid, S::v('uid'), $j, $nb, $paid); + VALUES ({?}, {?}, {?}, {?}, {?}, {?})", + $eid, S::v('uid'), $j, $nb, Env::has('notify_payment') ? 'notify_payment' : '', $paid); $updated = $eid; } else { XDB::execute( @@ -537,8 +542,8 @@ class XnetEventsModule extends PLModule foreach ($nbs as $id => $nb) { $nb = max(intval($nb), 0); XDB::execute("REPLACE INTO groupex.evenements_participants - VALUES ({?}, {?}, {?}, {?}, {?})", - $evt['eid'], $member['uid'], $id, $nb, $paid); + VALUES ({?}, {?}, {?}, {?}, {?}, {?})", + $evt['eid'], $member['uid'], $id, $nb, '', $paid); } $res = XDB::query("SELECT COUNT(uid) AS cnt, SUM(nb) AS nb diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index d0f80a1..007dec9 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -21,11 +21,14 @@ // {{{ function get_event_detail() -function get_event_detail($eid, $item_id = false) +function get_event_detail($eid, $item_id = false, $asso_id = null) { global $globals; + if (is_null($asso_id)) { + $asso_id = $globals->asso('id'); + } $res = XDB::query( - "SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, + "SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, LEFT(10, e.debut) AS debut_day, LEFT(10, e.fin) AS fin_day, @@ -33,22 +36,22 @@ function get_event_detail($eid, $item_id = false) ei.titre, al.vid AS absent_list, pl.vid AS participant_list, a.nom, a.prenom, a.promo, aa.alias - FROM groupex.evenements AS e + FROM groupex.evenements AS e INNER JOIN x4dat.auth_user_md5 AS a ON a.user_id = e.organisateur_uid INNER JOIN x4dat.aliases AS aa ON (aa.type = 'a_vie' AND aa.id = a.user_id) - INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) - LEFT JOIN groupex.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) + INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) + LEFT JOIN groupex.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) LEFT JOIN virtual AS al ON(al.type = 'evt' AND al.alias = CONCAT(short_name, {?})) LEFT JOIN virtual AS pl ON(pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?})) - WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?} + WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?} GROUP BY ei.item_id", '-absents@'.$globals->xnet->evts_domain, '-participants@'.$globals->xnet->evts_domain, - $eid, $eid, $item_id ? $item_id : 1, $globals->asso('id')); + $eid, $eid, $item_id ? $item_id : 1, $asso_id); $evt = $res->fetchOneAssoc(); - if (!$evt || ($evt['accept_nonmembre'] == 0 && !is_member() && !may_update())) { + if (!$evt || ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update())) { return null; } @@ -68,7 +71,7 @@ function get_event_detail($eid, $item_id = false) } $res = XDB::query( - "SELECT titre, details, montant, ei.item_id, nb, ep.paid + "SELECT titre, details, montant, ei.item_id, nb, ep.paid, FIND_IN_SET('notify_payment', ep.flags) AS notify_payment 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 = {?}) @@ -78,12 +81,14 @@ function get_event_detail($eid, $item_id = false) $evt['topay'] = 0; $evt['paid'] = 0; + $evt['notify_payment'] = false; foreach ($evt['moments'] as $m) { $evt['topay'] += $m['nb'] * $m['montant']; if ($m['montant']) { $evt['money'] = true; } $evt['paid'] = $m['paid']; + $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; } $req = XDB::query( @@ -115,7 +120,7 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { } $eid = $evt['eid']; - $money = $evt['money'] && may_update(); + $money = $evt['money'] && (function_exists('may_update')) && may_update(); $pay_id = $evt['paiement_id']; $query = @@ -126,10 +131,11 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { IF(m.origine != 'X',m.sexe,FIND_IN_SET('femme', u.flags)) AS femme, m.perms='admin' AS admin, (m.origine = 'X') AS x, - ep.uid, SUM(ep.paid) AS paid, SUM(nb) AS nb + ep.uid, SUM(ep.paid) AS paid, SUM(nb) AS nb, + FIND_IN_SET('notify_payment', ep.flags) AS notify_payment FROM groupex.evenements_participants AS ep INNER JOIN groupex.evenements AS e ON (ep.eid = e.eid) - LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id) + LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id) LEFT JOIN auth_user_md5 AS u ON ( u.user_id = ep.uid ) LEFT JOIN aliases AS a ON ( a.id = ep.uid AND a.type='a_vie' ) WHERE ep.eid = {?} AND ep.nb > 0 @@ -150,7 +156,7 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { while ($u = $res->next()) { $u['adminpaid'] = $u['paid']; $u['montant'] = 0; - if ($money && $pay_id) { + if ($money && $pay_id) { $res_ = XDB::query( "SELECT montant FROM {$globals->money->mpay_tprefix}transactions AS t @@ -161,19 +167,19 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); $u['paid'] += trim($p); } - } + } $u['telepayment'] = $u['paid'] - $u['adminpaid']; $res_ = XDB::iterator( - "SELECT ep.nb, ep.item_id, ei.montant - FROM groupex.evenements_participants AS ep - INNER JOIN groupex.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) - WHERE ep.eid = {?} AND ep.uid = {?}", + "SELECT ep.nb, ep.item_id, ei.montant + FROM groupex.evenements_participants AS ep + INNER JOIN groupex.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) + WHERE ep.eid = {?} AND ep.uid = {?}", $eid, $u['uid']); while ($i = $res_->next()) { $u[$i['item_id']] = $i['nb']; $u['montant'] += $i['montant']*$i['nb']; } - $tab[] = $u; + $tab[] = $u; } return $tab; } diff --git a/templates/xnetevents/mail.new_payment.tpl b/templates/xnetevents/mail.new_payment.tpl new file mode 100644 index 0000000..6278e99 --- /dev/null +++ b/templates/xnetevents/mail.new_payment.tpl @@ -0,0 +1,38 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2007 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 *} +{* *} +{**************************************************************************} + +{config_load file="mails.conf" section="payment_ready"} +{if $mail_part eq 'head'} +{from full=#from#} +{to addr=$to} +{subject text="[`$asso`] Paiement activé"} +{elseif $mail_part eq 'wiki'} +Cher {$prenom}, + +Nous t'écrivons pour t'informer que le télépaiement associé à l'événement '''{$evt}''' du groupe {$asso} vient d'être activé. Tu peux donc finaliser ton inscription. + +Pour ceci, va simplement sur [[http://www.polytechnique.net/{$diminutif}/payment/{$payment}?montant={$topay}|cette page]]. + +Cordialement,\\ +L'Equipe de Polytechnique.org +{/if} +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/xnetevents/subscribe.tpl b/templates/xnetevents/subscribe.tpl index ad18039..2dfbb79 100644 --- a/templates/xnetevents/subscribe.tpl +++ b/templates/xnetevents/subscribe.tpl @@ -104,7 +104,7 @@ {if $event.topay} - +
{if !$event.paid} Tu dois payer {$event.topay|replace:'.':','} €. {elseif $event.paid < $event.topay} @@ -112,12 +112,18 @@ (tu as déjà payé {$event.paid|replace:'.':','} €) {else} Tu as déjà payé {$event.paid|replace:'.':','} € pour ton inscription. - {/if} + {/if} +
+
{if $event.paiement_id && $event.paid < $event.topay} [ Payer en ligne] + {elseif $validation && $event.paid < $event.topay} +
Le télépaiement pour cet événement est en instance de validation :
+ + {/if} - +
{else} Rien à payer {if $event.paid > 0} diff --git a/upgrade/0.9.15/05_payment.sql b/upgrade/0.9.15/05_payment.sql new file mode 100644 index 0000000..ffc7483 --- /dev/null +++ b/upgrade/0.9.15/05_payment.sql @@ -0,0 +1,4 @@ +use groupex; +alter table evenements_participants add column flags set('notify_payment') not null after nb; +use x4dat; +# vim:set syntax=mysql: -- 2.1.4