X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fpaiements.inc.php;h=2343ac3a8ae43d249136117d21ad4d6357cafb7c;hb=a7d35093a40837b3a17d7fbac0259995f084812c;hp=8ec5de51bc32cf69785b04477bcc28d4a3ae5494;hpb=029e6327b625787aa0820bc458f8d814a467e958;p=platal.git diff --git a/include/validations/paiements.inc.php b/include/validations/paiements.inc.php index 8ec5de5..2343ac3 100644 --- a/include/validations/paiements.inc.php +++ b/include/validations/paiements.inc.php @@ -1,6 +1,6 @@ Validate($_uid, false, 'paiements', $_stamp); - + parent::__construct($_uid, 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 = $globals->xdb->query("SELECT nom FROM groupex.asso WHERE id = {?}", $_asso_id); + $res = XDB::query("SELECT nom FROM groupex.asso WHERE id = {?}", $_asso_id); $this->asso = $res->fetchOneCell(); } if ($_asso_id && $_evt) { - $res = $globals->xdb->query("SELECT intitule FROM groupex.evenements WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt); + $res = XDB::query("SELECT intitule FROM groupex.evenements WHERE asso_id = {?} AND eid = {?}", $_asso_id, $_evt); $this->evt_intitule = $res->fetchOneCell(); } } // }}} - // {{{ function submit() - // supprime les demandes de paiments pour le meme evenement - function submit() + // {{{ function same_event() + + static public function same_event($evt, $asso_id) + { + $wevt = 's:3:"evt";s:'.strlen($evt+"").':"'.$evt.'"'; + $wassoid = 's:7:"asso_id";s:'.strlen($asso_id + "").':"'.$asso_id.'"'; + $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('//', $this->msg_reponse)) { + $this->trigError("Le demande de paiement ne contient pas la balise obligatoire <montant>"); + return false; + } + return true; + } + + // }}} + // {{{ function submit() + + // supprime les demandes de paiments pour le meme evenement + public function submit() { - global $globals; - $evt = 's:3:"evt";s:'.strlen($this->evt+"").':"'.$this->evt.'"'; - $assoid = 's:7:"asso_id";s:'.strlen($this->asso_id + "").':"'.$this->asso_id.'"'; if ($this->evt) { - $globals->xdb->execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', "%".$assoid."%".$evt."%"); + XDB::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq::same_event($this->evt, $this->asso_id)); } - Validate::submit(); + parent::submit(); } // }}} // {{{ function formu() - function formu() - { return 'include/form.valid.paiements.tpl'; } + public function formu() + { + return 'include/form.valid.paiements.tpl'; + } + + // }}} + // {{{ function editor() + + public function editor() + { + return 'include/form.valid.edit-paiements.tpl'; + } + + // }}} + // {{{ function handle_editor() + + protected function handle_editor() + { + $this->titre = Env::v('pay_titre'); + $this->site = Env::v('pay_site'); + $this->montant = Env::i('pay_montant'); + $this->montant_min = Env::i('pay_montant_min'); + $this->montant_max = Env::i('pay_montant_max'); + $this->msg_reponse = Env::v('pay_msg_reponse'); + return true; + } // }}} // {{{ function _mail_subj - function _mail_subj() + protected function _mail_subj() { - return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}"; + return "[Polytechnique.org/Paiments] Demande de création de paiement {$this->titre}"; } // }}} // {{{ function _mail_body - function _mail_body($isok) + protected function _mail_body($isok) { if ($isok) { - 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":""); + 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":""); } else { - return " La demande que tu avais faite pour le paiement de {$this->intitule} a été refusée."; + return " La demande que tu avais faite pour le paiement de {$this->intitule} a été refusée."; } } // }}} // {{{ function commit() - - function commit() + + public function commit() { global $globals; - $res = $globals->xdb->query("SELECT MAX(id) FROM paiement.paiements"); + $res = XDB::query("SELECT MAX(id) FROM paiement.paiements"); $id = $res->fetchOneCell()+1; - $ret = $globals->xdb->execute("INSERT INTO paiement.paiements VALUES + $ret = XDB::execute("INSERT INTO paiement.paiements VALUES ( {?}, {?}, {?}, '', {?}, {?}, {?}, {?}, {?}, {?} ) @@ -122,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 = $globals->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(); + 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 = 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); + $mailer->assign('to', $u['email']); + $mailer->send(); + } + } + } return $ret; } @@ -133,5 +213,5 @@ class PayReq extends Validate // }}} -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>