Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
ba6ae046 | 3 | * Copyright (C) 2003-2013 Polytechnique.org * |
0337d704 | 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 | ||
612a2d8a | 28 | public $evtid; |
29 | public $titre; | |
30 | public $texte; | |
31 | public $pmin; | |
32 | public $pmax; | |
b58e5ac2 | 33 | public $expiration; |
612a2d8a | 34 | public $comment; |
02838718 | 35 | |
36 | public $imgtype; | |
37 | public $imgx; | |
38 | public $imgy; | |
39 | public $img; | |
eaf30d86 | 40 | |
0337d704 | 41 | // }}} |
42 | // {{{ constructor | |
43 | ||
26ba053e | 44 | public function __construct($_titre, $_texte, $_pmin, $_pmax, $_expiration, $_comment, User $_user, PlUpload $upload = null) |
612a2d8a | 45 | { |
5daf68f6 | 46 | parent::__construct($_user, false, 'evts'); |
0337d704 | 47 | $this->titre = $_titre; |
48 | $this->texte = $_texte; | |
49 | $this->pmin = $_pmin; | |
50 | $this->pmax = $_pmax; | |
b58e5ac2 | 51 | $this->expiration = $_expiration; |
0337d704 | 52 | $this->comment = $_comment; |
02838718 | 53 | if ($upload) { |
54 | $this->readImage($upload); | |
eaf30d86 | 55 | } |
02838718 | 56 | } |
57 | ||
58 | // }}} | |
59 | // {{{ function readImage() | |
60 | ||
26ba053e | 61 | private function readImage(PlUpload $upload) |
02838718 | 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 | } | |
0337d704 | 68 | } |
69 | ||
70 | // }}} | |
71 | // {{{ function formu() | |
72 | ||
612a2d8a | 73 | public function formu() |
74 | { | |
75 | return 'include/form.valid.evts.tpl'; | |
76 | } | |
0337d704 | 77 | |
78 | // }}} | |
6aa01fed | 79 | // {{{ functon editor() |
80 | ||
612a2d8a | 81 | public function editor() |
82 | { | |
83 | return 'include/form.valid.edit-evts.tpl'; | |
84 | } | |
6aa01fed | 85 | |
86 | // }}} | |
87 | // {{{ function handle_editor() | |
88 | ||
612a2d8a | 89 | protected function handle_editor() |
6aa01fed | 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'); | |
b58e5ac2 | 95 | $this->expiration = Env::v('expiration'); |
02838718 | 96 | if (@$_FILES['image']['tmp_name']) { |
f3df6d38 | 97 | $upload = PlUpload::get($_FILES['image'], S::user()->login(), 'event'); |
02838718 | 98 | if (!$upload) { |
a7d35093 | 99 | $this->trigError("Impossible de télécharger le fichier"); |
02838718 | 100 | } elseif (!$upload->isType('image')) { |
a7d35093 | 101 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG'); |
02838718 | 102 | $upload->rm(); |
103 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { | |
a7d35093 | 104 | $page->trigError('Impossible de retraiter l\'image'); |
02838718 | 105 | } else { |
106 | $this->readImage($upload); | |
107 | } | |
108 | } | |
6aa01fed | 109 | return true; |
110 | } | |
111 | ||
112 | // }}} | |
0337d704 | 113 | // {{{ function _mail_subj |
eaf30d86 | 114 | |
612a2d8a | 115 | protected function _mail_subj() |
0337d704 | 116 | { |
a7de4ef7 | 117 | return "[Polytechnique.org/EVENEMENTS] Proposition d'événement"; |
0337d704 | 118 | } |
119 | ||
120 | // }}} | |
121 | // {{{ function _mail_body | |
122 | ||
612a2d8a | 123 | protected function _mail_body($isok) |
0337d704 | 124 | { |
a3923909 | 125 | $you_have = ($this->formal ? 'vous aviez' : 'tu avais'); |
0337d704 | 126 | if ($isok) { |
a3923909 | 127 | return " L'annonce que $you_have proposée ({$this->titre}) vient d'être validée."; |
0337d704 | 128 | } else { |
a3923909 | 129 | return " L'annonce que $you_have proposée ({$this->titre}) a été refusée."; |
0337d704 | 130 | } |
131 | } | |
132 | ||
133 | // }}} | |
33305f63 PEM |
134 | // {{{ function _mail_ps |
135 | ||
136 | protected function _mail_ps($isok) | |
137 | { | |
138 | $maildate = make_datetime($this->expiration)->format('d / m / Y'); | |
139 | return "\nPS : pour rappel, en voici le contenu :" | |
140 | . "\n--------------------------------------------------------------------------\n" | |
141 | . $this->titre | |
142 | . "\n--------------------------------------------------------------------------\n" | |
143 | . $this->texte . "\n\nPour les promotions de " . $this->pmin . " à " . $this->pmax . ", avec expiration le " . $maildate . ".\n"; | |
144 | } | |
145 | ||
146 | // }}} | |
0337d704 | 147 | // {{{ function commit() |
148 | ||
612a2d8a | 149 | public function commit() |
0337d704 | 150 | { |
5a9ad4b0 | 151 | /* TODO: refines this filter on promotions by using userfilter. */ |
06f4daf9 | 152 | if (XDB::execute("INSERT INTO announces |
f280f651 | 153 | SET uid = {?}, creation_date=NOW(), titre={?}, texte={?}, |
b58e5ac2 | 154 | expiration={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')", |
5daf68f6 | 155 | $this->user->id(), $this->titre, $this->texte, |
b58e5ac2 | 156 | $this->expiration, $this->pmin, $this->pmax)) { |
b2bffbe6 | 157 | $eid = XDB::insertId(); |
02838718 | 158 | if ($this->img) { |
06f4daf9 | 159 | XDB::execute("INSERT INTO announce_photos |
02838718 | 160 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", |
161 | XDB::insertId(), $this->imgtype, $this->imgx, $this->imgy, $this->img); | |
162 | } | |
b2bffbe6 | 163 | global $globals; |
164 | if ($globals->banana->event_forum) { | |
b2bffbe6 | 165 | require_once 'banana/forum.inc.php'; |
5daf68f6 | 166 | $banana = new ForumsBanana($this->user); |
b2bffbe6 | 167 | $post = $banana->post($globals->banana->event_forum, |
168 | $globals->banana->event_reply, | |
794feea7 | 169 | $this->titre, MiniWiki::wikiToText($this->texte, false, 0, 80)); |
b2bffbe6 | 170 | if ($post != -1) { |
06f4daf9 | 171 | XDB::execute("UPDATE announces |
b2bffbe6 | 172 | SET creation_date = creation_date, post_id = {?} |
173 | WHERE id = {?}", $post, $eid); | |
174 | } | |
175 | } | |
02838718 | 176 | return true; |
177 | } | |
178 | return false; | |
0337d704 | 179 | } |
180 | ||
181 | // }}} | |
182 | } | |
183 | ||
184 | // }}} | |
185 | ||
a7de4ef7 | 186 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 187 | ?> |