| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2007 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 = "Laisser la validation à un trésorier"; |
| 42 | // }}} |
| 43 | // {{{ constructor |
| 44 | |
| 45 | public function __construct($_uid, $_intitule, $_site, $_montant, $_msg, |
| 46 | $_montantmin=0, $_montantmax=999, $_asso_id = 0, |
| 47 | $_evt = 0, $_stamp=0) |
| 48 | { |
| 49 | parent::__construct($_uid, false, 'paiements', $_stamp); |
| 50 | |
| 51 | $this->titre = $_intitule; |
| 52 | $this->site = $_site; |
| 53 | $this->msg_reponse = $_msg; |
| 54 | $this->asso_id = $_asso_id; |
| 55 | $this->evt = $_evt; |
| 56 | $this->montant = $_montant; |
| 57 | $this->montant_min = $_montantmin; |
| 58 | $this->montant_max = $_montantmax; |
| 59 | |
| 60 | if ($_asso_id) { |
| 61 | $res = XDB::query("SELECT nom FROM groupex.asso WHERE id = {?}", $_asso_id); |
| 62 | $this->asso = $res->fetchOneCell(); |
| 63 | } |
| 64 | if ($_asso_id && $_evt) { |
| 65 | $res = XDB::query("SELECT intitule FROM groupex.evenements WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt); |
| 66 | $this->evt_intitule = $res->fetchOneCell(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // }}} |
| 71 | // {{{ function same_event() |
| 72 | |
| 73 | static public function same_event($evt, $asso_id) |
| 74 | { |
| 75 | $wevt = 's:3:"evt";s:'.strlen($evt+"").':"'.$evt.'"'; |
| 76 | $wassoid = 's:7:"asso_id";s:'.strlen($asso_id + "").':"'.$asso_id.'"'; |
| 77 | $where = "%".$wassoid."%".$wevt."%"; |
| 78 | return $where; |
| 79 | } |
| 80 | |
| 81 | // }}} |
| 82 | // {{{ function accept() |
| 83 | |
| 84 | // check the message |
| 85 | public function accept() |
| 86 | { |
| 87 | // no text [AI JMIAJM IJA MIJ] |
| 88 | if (preg_match('/\[[-\'"A-Z ]+\]/', $this->msg_reponse)) { |
| 89 | $this->trig("La demande de paiement n'est pas valide. Merci de compléter le texte avant de la soumettre"); |
| 90 | return false; |
| 91 | } |
| 92 | if (!preg_match('/<montant>/', $this->msg_reponse)) { |
| 93 | $this->trig("Le demande de paiement ne contient pas la balise obligatoire <montant>"); |
| 94 | return false; |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | // }}} |
| 100 | // {{{ function submit() |
| 101 | |
| 102 | // supprime les demandes de paiments pour le meme evenement |
| 103 | public function submit() |
| 104 | { |
| 105 | if ($this->evt) |
| 106 | { |
| 107 | XDB::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq::same_event($this->evt, $this->asso_id)); |
| 108 | } |
| 109 | parent::submit(); |
| 110 | } |
| 111 | // }}} |
| 112 | // {{{ function formu() |
| 113 | |
| 114 | public function formu() |
| 115 | { |
| 116 | return 'include/form.valid.paiements.tpl'; |
| 117 | } |
| 118 | |
| 119 | // }}} |
| 120 | // {{{ function editor() |
| 121 | |
| 122 | public function editor() |
| 123 | { |
| 124 | return 'include/form.valid.edit-paiements.tpl'; |
| 125 | } |
| 126 | |
| 127 | // }}} |
| 128 | // {{{ function handle_editor() |
| 129 | |
| 130 | protected function handle_editor() |
| 131 | { |
| 132 | $this->titre = Env::v('pay_titre'); |
| 133 | $this->site = Env::v('pay_site'); |
| 134 | $this->montant = Env::i('pay_montant'); |
| 135 | $this->montant_min = Env::i('pay_montant_min'); |
| 136 | $this->montant_max = Env::i('pay_montant_max'); |
| 137 | $this->msg_reponse = Env::v('pay_msg_reponse'); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | // }}} |
| 142 | // {{{ function _mail_subj |
| 143 | |
| 144 | protected function _mail_subj() |
| 145 | { |
| 146 | return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}"; |
| 147 | } |
| 148 | |
| 149 | // }}} |
| 150 | // {{{ function _mail_body |
| 151 | |
| 152 | protected function _mail_body($isok) |
| 153 | { |
| 154 | if ($isok) { |
| 155 | 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":""); |
| 156 | } else { |
| 157 | return " La demande que tu avais faite pour le paiement de {$this->intitule} a été refusée."; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // }}} |
| 162 | // {{{ function commit() |
| 163 | |
| 164 | public function commit() |
| 165 | { |
| 166 | global $globals; |
| 167 | $res = XDB::query("SELECT MAX(id) FROM paiement.paiements"); |
| 168 | $id = $res->fetchOneCell()+1; |
| 169 | $ret = XDB::execute("INSERT INTO paiement.paiements VALUES |
| 170 | ( {?}, {?}, {?}, '', |
| 171 | {?}, {?}, {?}, |
| 172 | {?}, {?}, {?} ) |
| 173 | ", |
| 174 | $id, $this->titre, $this->site, |
| 175 | $this->montant, $this->montant_min, $this->montant_max, |
| 176 | $this->bestalias."@".$globals->mail->domain, $this->msg_reponse, $this->asso_id); |
| 177 | if ($this->asso_id && $this->evt) |
| 178 | $ret = XDB::execute("UPDATE groupex.evenements SET paiement_id = {?} WHERE asso_id = {?} AND eid = {?}", $id, $this->asso_id, $this->evt); |
| 179 | |
| 180 | return $ret; |
| 181 | } |
| 182 | |
| 183 | // }}} |
| 184 | } |
| 185 | |
| 186 | // }}} |
| 187 | |
| 188 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 189 | ?> |