<?php
/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
class PayReq extends Validate
{
// {{{ properties
-
+
public $titre;
public $site;
public $evt;
public $evt_intitule;
- public $rules = "Laisser la validation à un trésorier";
+ public $rules = "Vérifier que les balises <salutation>, <prenom>, <nom>, <montant> et <comment> n'ont pas été modifiées.
+Vérifier que le demandeur n'a pas laissé les crochets [].
+Si le télépaiement n'est pas lié à un groupe ou supérieur à 51 euros, laisser la validation à un trésorier";
// }}}
// {{{ constructor
- public function __construct($_uid, $_intitule, $_site, $_montant, $_msg,
+ public function __construct(User &$_user, $_intitule, $_site, $_montant, $_msg,
$_montantmin=0, $_montantmax=999, $_asso_id = 0,
$_evt = 0, $_stamp=0)
{
- parent::__construct($_uid, false, 'paiements', $_stamp);
+ parent::__construct($_user, false, 'paiements', $_stamp);
$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;
if ($_asso_id) {
- $res = XDB::query("SELECT nom FROM groupex.asso WHERE id = {?}", $_asso_id);
+ $res = XDB::query("SELECT nom FROM groups WHERE id = {?}", $_asso_id);
$this->asso = $res->fetchOneCell();
}
if ($_asso_id && $_evt) {
- $res = XDB::query("SELECT intitule FROM groupex.evenements WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt);
+ $res = XDB::query("SELECT intitule FROM group_events WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt);
$this->evt_intitule = $res->fetchOneCell();
}
}
$where = "%".$wassoid."%".$wevt."%";
return $where;
}
-
+
+ // }}}
+ // {{{ function accept()
+
+ // check the message
+ public function accept()
+ {
+ // no text [AI JMIAJM IJA MIJ]
+ if (preg_match('/\[[-\'"A-Z ]+\]/', $this->msg_reponse)) {
+ $this->trigError("La demande de paiement n'est pas valide. Merci de compléter le texte avant de la soumettre");
+ return false;
+ }
+ if (!preg_match('/<montant>/', $this->msg_reponse)) {
+ $this->trigError("Le demande de paiement ne contient pas la balise obligatoire <montant>");
+ return false;
+ }
+ return true;
+ }
+
// }}}
- // {{{ function submit()
-
+ // {{{ function submit()
+
// supprime les demandes de paiments pour le meme evenement
public function submit()
{
// }}}
// {{{ function commit()
-
+
public function commit()
{
- global $globals;
- $res = XDB::query("SELECT MAX(id) FROM paiement.paiements");
+ $res = XDB::query("SELECT MAX(id) FROM payments");
$id = $res->fetchOneCell()+1;
- $ret = XDB::execute("INSERT INTO paiement.paiements VALUES
+ $ret = XDB::execute("INSERT INTO payments VALUES
( {?}, {?}, {?}, '',
{?}, {?}, {?},
{?}, {?}, {?} )
",
$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);
-
+ $this->user->bestEmail(), $this->msg_reponse, $this->asso_id);
+ if ($this->asso_id && $this->evt) {
+ XDB::execute("UPDATE group_events
+ 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 groups AS a
+ INNER JOIN group_events AS e ON (a.id = e.asso_id)
+ WHERE e.eid = {?}",
+ $this->evt);
+ list($nom, $diminutif, $evt) = $res->fetchOneRow();
+ require_once dirname(__FILE__) . '/../../modules/xnetevents/xnetevents.inc.php';
+ $participants = get_event_participants(get_event_detail($this->evt, false, $this->asso_id), null);
+ foreach ($participants as &$u) {
+ if (!$u['notify_payment']) {
+ continue;
+ }
+ $topay = $u['montant'] - $u['paid'];
+ if ($topay > 0) {
+ $mailer = new PlMailer('xnetevents/newpayment.mail.tpl');
+ $mailer->assign('asso', $nom);
+ $mailer->assign('diminutif', $diminutif);
+ $mailer->assign('evt', $evt);
+ $mailer->assign('payment', $id);
+ $mailer->assign('prenom', $u['prenom']);
+ $mailer->assign('topay', $topay);
+
+ if (strpos($u['email'], '@') === false) {
+ $mailer->assign('to', $u['email'] . '@' . $globals->mail->domain);
+ } else {
+ $mailer->assign('to', $u['email']);
+ }
+ $mailer->send();
+ }
+ }
+ }
return $ret;
}