2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 class PayReq
extends Validate
41 public $rules = "Vérifier que les balises <salutation>, <prenom>, <nom>, <montant> et <comment> n'ont pas été modifiées.
42 Vérifier que le demandeur n'a pas laissé les crochets [].
43 Si le télépaiement n'est pas lié à un groupe ou supérieur à 51 euros, laisser la validation à un trésorier";
47 public function __construct(User
&$_user, $_intitule, $_site, $_montant, $_msg,
48 $_montantmin=0, $_montantmax=999, $_asso_id = 0,
51 parent
::__construct($_user, false
, 'paiements', $_stamp);
53 $this->titre
= $_intitule;
55 $this->msg_reponse
= $_msg;
56 $this->asso_id
= (string)$_asso_id;
57 $this->evt
= (string)$_evt;
58 $this->montant
= $_montant;
59 $this->montant_min
= $_montantmin;
60 $this->montant_max
= $_montantmax;
63 $res = XDB
::query("SELECT nom FROM groups WHERE id = {?}", $_asso_id);
64 $this->asso
= $res->fetchOneCell();
66 if ($_asso_id && $_evt) {
67 $res = XDB
::query("SELECT intitule FROM group_events WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt);
68 $this->evt_intitule
= $res->fetchOneCell();
73 // {{{ function same_event()
75 static public function same_event($evt, $asso_id)
77 $wevt = 's:3:"evt";s:'.strlen($evt+
"").':"'.$evt.'"';
78 $wassoid = 's:7:"asso_id";s:'.strlen($asso_id +
"").':"'.$asso_id.'"';
79 $where = "%".$wassoid."%".$wevt."%";
84 // {{{ function accept()
87 public function accept()
89 // no text [AI JMIAJM IJA MIJ]
90 if (preg_match('/\[[-\'"A-Z ]+\]/', $this->msg_reponse
)) {
91 $this->trigError("La demande de paiement n'est pas valide. Merci de compléter le texte avant de la soumettre");
94 if (!preg_match('/<montant>/', $this->msg_reponse
)) {
95 $this->trigError("Le demande de paiement ne contient pas la balise obligatoire <montant>");
102 // {{{ function submit()
104 // supprime les demandes de paiments pour le meme evenement
105 public function submit()
109 XDB
::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq
::same_event($this->evt
, $this->asso_id
));
114 // {{{ function formu()
116 public function formu()
118 return 'include/form.valid.paiements.tpl';
122 // {{{ function editor()
124 public function editor()
126 return 'include/form.valid.edit-paiements.tpl';
130 // {{{ function handle_editor()
132 protected function handle_editor()
134 $this->titre
= Env
::v('pay_titre');
135 $this->site
= Env
::v('pay_site');
136 $this->montant
= Env
::i('pay_montant');
137 $this->montant_min
= Env
::i('pay_montant_min');
138 $this->montant_max
= Env
::i('pay_montant_max');
139 $this->msg_reponse
= Env
::v('pay_msg_reponse');
144 // {{{ function _mail_subj
146 protected function _mail_subj()
148 return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}";
152 // {{{ function _mail_body
154 protected function _mail_body($isok)
157 return " Le paiement que tu avais demandé pour {$this->titre} vient d'être créé.".($this->evt?
" Il a bien été associé à la gestion de l'événement du groupe":"");
159 return " La demande que tu avais faite pour le paiement de {$this->intitule} a été refusée.";
164 // {{{ function commit()
166 public function commit()
168 $res = XDB
::query("SELECT MAX(id) FROM payments");
169 $id = $res->fetchOneCell()+
1;
170 $ret = XDB
::execute("INSERT INTO payments VALUES
175 $id, $this->titre
, $this->site
,
176 $this->montant
, $this->montant_min
, $this->montant_max
,
177 $this->user
->bestEmail(), $this->msg_reponse
, $this->asso_id
);
178 if ($this->asso_id
&& $this->evt
) {
179 XDB
::execute("UPDATE group_events
180 SET paiement_id = {?}
181 WHERE asso_id = {?} AND eid = {?}",
182 $id, $this->asso_id
, $this->evt
);
183 $res = XDB
::query("SELECT a.nom, a.diminutif, e.intitule
185 INNER JOIN group_events AS e ON (a.id = e.asso_id)
188 list($nom, $diminutif, $evt) = $res->fetchOneRow();
189 require_once dirname(__FILE__
) . '/../../modules/xnetevents/xnetevents.inc.php';
190 $participants = get_event_participants(get_event_detail($this->evt
, false
, $this->asso_id
), null
, 'nom');
191 foreach ($participants as &$u) {
192 if (!$u['notify_payment']) {
195 $topay = $u['montant'] - $u['paid'];
197 $mailer = new PlMailer('xnetevents/newpayment.mail.tpl');
198 $mailer->assign('asso', $nom);
199 $mailer->assign('diminutif', $diminutif);
200 $mailer->assign('evt', $evt);
201 $mailer->assign('payment', $id);
202 $mailer->assign('prenom', $u['prenom']);
203 $mailer->assign('topay', $topay);
205 if (strpos($u['email'], '@') === false
) {
206 $mailer->assign('to', $u['email'] . '@' . $globals->mail
->domain
);
208 $mailer->assign('to', $u['email']);
222 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: