| 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 EvtReq |
| 23 | |
| 24 | class EvtReq extends Validate |
| 25 | { |
| 26 | // {{{ properties |
| 27 | |
| 28 | public $evtid; |
| 29 | public $titre; |
| 30 | public $texte; |
| 31 | public $pmin; |
| 32 | public $pmax; |
| 33 | public $peremption; |
| 34 | public $comment; |
| 35 | |
| 36 | public $imgtype; |
| 37 | public $imgx; |
| 38 | public $imgy; |
| 39 | public $img; |
| 40 | |
| 41 | // }}} |
| 42 | // {{{ constructor |
| 43 | |
| 44 | public function __construct($_titre, $_texte, $_pmin, $_pmax, $_peremption, $_comment, $_uid, PlUpload &$upload = null) |
| 45 | { |
| 46 | parent::__construct($_uid, false, 'evts'); |
| 47 | $this->titre = $_titre; |
| 48 | $this->texte = $_texte; |
| 49 | $this->pmin = $_pmin; |
| 50 | $this->pmax = $_pmax; |
| 51 | $this->peremption = $_peremption; |
| 52 | $this->comment = $_comment; |
| 53 | if ($upload) { |
| 54 | $this->readImage($upload); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // }}} |
| 59 | // {{{ function readImage() |
| 60 | |
| 61 | private function readImage(PlUpload &$upload) |
| 62 | { |
| 63 | if ($upload->exists() && $upload->isType('image')) { |
| 64 | list($this->imgx, $this->imgy, $this->imgtype) = $upload->imageInfo(); |
| 65 | $this->img = $upload->getContents(); |
| 66 | $upload->rm(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // }}} |
| 71 | // {{{ function formu() |
| 72 | |
| 73 | public function formu() |
| 74 | { |
| 75 | return 'include/form.valid.evts.tpl'; |
| 76 | } |
| 77 | |
| 78 | // }}} |
| 79 | // {{{ functon editor() |
| 80 | |
| 81 | public function editor() |
| 82 | { |
| 83 | return 'include/form.valid.edit-evts.tpl'; |
| 84 | } |
| 85 | |
| 86 | // }}} |
| 87 | // {{{ function handle_editor() |
| 88 | |
| 89 | protected function handle_editor() |
| 90 | { |
| 91 | $this->titre = Env::v('titre'); |
| 92 | $this->texte = Env::v('texte'); |
| 93 | $this->pmin = Env::i('promo_min'); |
| 94 | $this->pmax = Env::i('promo_max'); |
| 95 | $this->peremption = Env::v('peremption'); |
| 96 | if (@$_FILES['image']['tmp_name']) { |
| 97 | $upload = PlUpload::get($_FILES['image'], S::v('forlife'), 'event'); |
| 98 | if (!$upload) { |
| 99 | $this->trig("Impossible de télécharger le fichier"); |
| 100 | } elseif (!$upload->isType('image')) { |
| 101 | $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG'); |
| 102 | $upload->rm(); |
| 103 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { |
| 104 | $page->trig('Impossible de retraiter l\'image'); |
| 105 | } else { |
| 106 | $this->readImage($upload); |
| 107 | } |
| 108 | } |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | // }}} |
| 113 | // {{{ function _mail_subj |
| 114 | |
| 115 | protected function _mail_subj() |
| 116 | { |
| 117 | return "[Polytechnique.org/EVENEMENTS] Proposition d'événement"; |
| 118 | } |
| 119 | |
| 120 | // }}} |
| 121 | // {{{ function _mail_body |
| 122 | |
| 123 | protected function _mail_body($isok) |
| 124 | { |
| 125 | if ($isok) { |
| 126 | return " L'annonce que tu avais proposée ({$this->titre}) vient d'être validée."; |
| 127 | } else { |
| 128 | return " L'annonce que tu avais proposée ({$this->titre}) a été refusée."; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // }}} |
| 133 | // {{{ function commit() |
| 134 | |
| 135 | public function commit() |
| 136 | { |
| 137 | if (XDB::execute("INSERT INTO evenements |
| 138 | SET user_id = {?}, creation_date=NOW(), titre={?}, texte={?}, |
| 139 | peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide')", |
| 140 | $this->uid, $this->titre, $this->texte, |
| 141 | $this->peremption, $this->pmin, $this->pmax)) { |
| 142 | $eid = XDB::insertId(); |
| 143 | if ($this->img) { |
| 144 | XDB::execute("INSERT INTO evenements_photo |
| 145 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", |
| 146 | XDB::insertId(), $this->imgtype, $this->imgx, $this->imgy, $this->img); |
| 147 | } |
| 148 | global $globals; |
| 149 | if ($globals->banana->event_forum) { |
| 150 | require_once 'user.func.inc.php'; |
| 151 | $forlife = get_user_forlife($this->uid); |
| 152 | require_once 'banana/forum.inc.php'; |
| 153 | $banana = new ForumsBanana($forlife); |
| 154 | $text = strip_tags($this->texte, '<p><br><li><ul><ol><a>'); |
| 155 | $text = preg_replace(',<a href="([^"]+)">(.*?)</a>,', '$1', $text); |
| 156 | $text = preg_replace('/<li>/', '* ', $text); |
| 157 | $text = preg_replace(',</?.+?>,i', "\n", $text); |
| 158 | $text = preg_replace("/\n{2,}/", "\n\n", $text); |
| 159 | $post = $banana->post($globals->banana->event_forum, |
| 160 | $globals->banana->event_reply, |
| 161 | $this->titre, pl_entity_decode($text)); |
| 162 | if ($post != -1) { |
| 163 | XDB::execute("UPDATE evenements |
| 164 | SET creation_date = creation_date, post_id = {?} |
| 165 | WHERE id = {?}", $post, $eid); |
| 166 | } |
| 167 | } |
| 168 | return true; |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | // }}} |
| 174 | } |
| 175 | |
| 176 | // }}} |
| 177 | |
| 178 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 179 | ?> |