| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 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. * |
| 10 | * * |
| 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. * |
| 15 | * * |
| 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 * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | // {{{ class PayReq |
| 23 | |
| 24 | class PayReq extends Validate |
| 25 | { |
| 26 | // {{{ properties |
| 27 | |
| 28 | public $titre; |
| 29 | public $site; |
| 30 | |
| 31 | public $montant; |
| 32 | public $montant_min; |
| 33 | public $montant_max; |
| 34 | |
| 35 | public $msg_reponse; |
| 36 | public $asso_id; |
| 37 | public $asso; |
| 38 | public $evt; |
| 39 | public $evt_intitule; |
| 40 | |
| 41 | public $rules = "Vérifier que les balises <salutation>, <prenom>, <nom> et <montant> 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"; |
| 44 | // }}} |
| 45 | // {{{ constructor |
| 46 | |
| 47 | public function __construct(User &$_user, $_intitule, $_site, $_montant, $_msg, |
| 48 | $_montantmin=0, $_montantmax=999, $_asso_id = 0, |
| 49 | $_evt = 0, $_stamp=0) |
| 50 | { |
| 51 | parent::__construct($_user, false, 'paiements', $_stamp); |
| 52 | |
| 53 | $this->titre = $_intitule; |
| 54 | $this->site = $_site; |
| 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; |
| 61 | |
| 62 | if ($_asso_id) { |
| 63 | $res = XDB::query("SELECT nom FROM groupex.asso WHERE id = {?}", $_asso_id); |
| 64 | $this->asso = $res->fetchOneCell(); |
| 65 | } |
| 66 | if ($_asso_id && $_evt) { |
| 67 | $res = XDB::query("SELECT intitule FROM groupex.evenements WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt); |
| 68 | $this->evt_intitule = $res->fetchOneCell(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // }}} |
| 73 | // {{{ function same_event() |
| 74 | |
| 75 | static public function same_event($evt, $asso_id) |
| 76 | { |
| 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."%"; |
| 80 | return $where; |
| 81 | } |
| 82 | |
| 83 | // }}} |
| 84 | // {{{ function accept() |
| 85 | |
| 86 | // check the message |
| 87 | public function accept() |
| 88 | { |
| 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"); |
| 92 | return false; |
| 93 | } |
| 94 | if (!preg_match('/<montant>/', $this->msg_reponse)) { |
| 95 | $this->trigError("Le demande de paiement ne contient pas la balise obligatoire <montant>"); |
| 96 | return false; |
| 97 | } |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | // }}} |
| 102 | // {{{ function submit() |
| 103 | |
| 104 | // supprime les demandes de paiments pour le meme evenement |
| 105 | public function submit() |
| 106 | { |
| 107 | if ($this->evt) |
| 108 | { |
| 109 | XDB::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq::same_event($this->evt, $this->asso_id)); |
| 110 | } |
| 111 | parent::submit(); |
| 112 | } |
| 113 | // }}} |
| 114 | // {{{ function formu() |
| 115 | |
| 116 | public function formu() |
| 117 | { |
| 118 | return 'include/form.valid.paiements.tpl'; |
| 119 | } |
| 120 | |
| 121 | // }}} |
| 122 | // {{{ function editor() |
| 123 | |
| 124 | public function editor() |
| 125 | { |
| 126 | return 'include/form.valid.edit-paiements.tpl'; |
| 127 | } |
| 128 | |
| 129 | // }}} |
| 130 | // {{{ function handle_editor() |
| 131 | |
| 132 | protected function handle_editor() |
| 133 | { |
| 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'); |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | // }}} |
| 144 | // {{{ function _mail_subj |
| 145 | |
| 146 | protected function _mail_subj() |
| 147 | { |
| 148 | return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}"; |
| 149 | } |
| 150 | |
| 151 | // }}} |
| 152 | // {{{ function _mail_body |
| 153 | |
| 154 | protected function _mail_body($isok) |
| 155 | { |
| 156 | if ($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":""); |
| 158 | } else { |
| 159 | return " La demande que tu avais faite pour le paiement de {$this->intitule} a été refusée."; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // }}} |
| 164 | // {{{ function commit() |
| 165 | |
| 166 | public function commit() |
| 167 | { |
| 168 | $res = XDB::query("SELECT MAX(id) FROM paiement.paiements"); |
| 169 | $id = $res->fetchOneCell()+1; |
| 170 | $ret = XDB::execute("INSERT INTO paiement.paiements VALUES |
| 171 | ( {?}, {?}, {?}, '', |
| 172 | {?}, {?}, {?}, |
| 173 | {?}, {?}, {?} ) |
| 174 | ", |
| 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 groupex.evenements |
| 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 |
| 184 | FROM groupex.asso AS a |
| 185 | INNER JOIN groupex.evenements AS e ON (a.id = e.asso_id) |
| 186 | WHERE e.eid = {?}", |
| 187 | $this->evt); |
| 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']) { |
| 193 | continue; |
| 194 | } |
| 195 | $topay = $u['montant'] - $u['paid']; |
| 196 | if ($topay > 0) { |
| 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); |
| 204 | $mailer->assign('to', $u['email']); |
| 205 | $mailer->send(); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | return $ret; |
| 210 | } |
| 211 | |
| 212 | // }}} |
| 213 | } |
| 214 | |
| 215 | // }}} |
| 216 | |
| 217 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 218 | ?> |