13a506ad0be8bdf165fa4307452104496c838bf0
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 class EvtReq
extends Validate
44 public function __construct($_titre, $_texte, $_pmin, $_pmax, $_expiration, $_comment, User
&$_user, PlUpload
&$upload = null
)
46 parent
::__construct($_user, false
, 'evts');
47 $this->titre
= $_titre;
48 $this->texte
= $_texte;
51 $this->expiration
= $_expiration;
52 $this->comment
= $_comment;
54 $this->readImage($upload);
59 // {{{ function readImage()
61 private function readImage(PlUpload
&$upload)
63 if ($upload->exists() && $upload->isType('image')) {
64 list($this->imgx
, $this->imgy
, $this->imgtype
) = $upload->imageInfo();
65 $this->img
= $upload->getContents();
71 // {{{ function formu()
73 public function formu()
75 return 'include/form.valid.evts.tpl';
79 // {{{ functon editor()
81 public function editor()
83 return 'include/form.valid.edit-evts.tpl';
87 // {{{ function handle_editor()
89 protected function handle_editor()
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->expiration
= Env
::v('expiration');
96 if (@$_FILES['image']['tmp_name']) {
97 $upload = PlUpload
::get($_FILES['image'], S
::user()->login(), 'event');
99 $this->trigError("Impossible de télécharger le fichier");
100 } elseif (!$upload->isType('image')) {
101 $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG');
103 } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
104 $page->trigError('Impossible de retraiter l\'image');
106 $this->readImage($upload);
113 // {{{ function _mail_subj
115 protected function _mail_subj()
117 return "[Polytechnique.org/EVENEMENTS] Proposition d'événement";
121 // {{{ function _mail_body
123 protected function _mail_body($isok)
126 return " L'annonce que tu avais proposée ({$this->titre}) vient d'être validée.";
128 return " L'annonce que tu avais proposée ({$this->titre}) a été refusée.";
133 // {{{ function commit()
135 public function commit()
137 /* TODO: refines this filter on promotions by using userfilter. */
138 if (XDB
::execute("INSERT INTO announces
139 SET uid = {?}, creation_date=NOW(), titre={?}, texte={?},
140 expiration={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')",
141 $this->user
->id(), $this->titre
, $this->texte
,
142 $this->expiration
, $this->pmin
, $this->pmax
)) {
143 $eid = XDB
::insertId();
145 XDB
::execute("INSERT INTO announce_photos
146 SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
147 XDB
::insertId(), $this->imgtype
, $this->imgx
, $this->imgy
, $this->img
);
150 if ($globals->banana
->event_forum
) {
151 require_once 'banana/forum.inc.php';
152 $banana = new ForumsBanana($this->user
);
153 $post = $banana->post($globals->banana
->event_forum
,
154 $globals->banana
->event_reply
,
155 $this->titre
, MiniWiki
::wikiToText($this->texte
, false
, 0, 80));
157 XDB
::execute("UPDATE announces
158 SET creation_date = creation_date, post_id = {?}
159 WHERE id = {?}", $post, $eid);
172 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: