Switch to the new trigger pattern.
[platal.git] / include / validations / evts.inc.php
index 1adf6db..c33ce5e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -30,14 +30,14 @@ class EvtReq extends Validate
     public $texte;
     public $pmin;
     public $pmax;
-    public $peremption;    
+    public $peremption;
     public $comment;
 
     public $imgtype;
     public $imgx;
     public $imgy;
     public $img;
-    
+
     // }}}
     // {{{ constructor
 
@@ -52,7 +52,7 @@ class EvtReq extends Validate
         $this->comment    = $_comment;
         if ($upload) {
             $this->readImage($upload);
-        } 
+        }
     }
 
     // }}}
@@ -96,12 +96,12 @@ class EvtReq extends Validate
         if (@$_FILES['image']['tmp_name']) {
             $upload = PlUpload::get($_FILES['image'], S::v('forlife'), 'event');
             if (!$upload) {
-                $this->trig("Impossible de télécharger le fichier");
+                $this->trigError("Impossible de télécharger le fichier");
             } elseif (!$upload->isType('image')) {
-                $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG');
+                $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG');
                 $upload->rm();
             } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
-                $page->trig('Impossible de retraiter l\'image');
+                $page->trigError('Impossible de retraiter l\'image');
             } else {
                 $this->readImage($upload);
             }
@@ -111,7 +111,7 @@ class EvtReq extends Validate
 
     // }}}
     // {{{ function _mail_subj
-    
+
     protected function _mail_subj()
     {
         return "[Polytechnique.org/EVENEMENTS] Proposition d'événement";
@@ -136,14 +136,30 @@ class EvtReq extends Validate
     {
         if (XDB::execute("INSERT INTO  evenements
                          SET  user_id = {?}, creation_date=NOW(), titre={?}, texte={?},
-                              peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide')",
+                              peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')",
                 $this->uid, $this->titre, $this->texte,
                 $this->peremption, $this->pmin, $this->pmax)) {
+            $eid = XDB::insertId();
             if ($this->img) {
                 XDB::execute("INSERT INTO evenements_photo
                                       SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}",
                              XDB::insertId(), $this->imgtype, $this->imgx, $this->imgy, $this->img);
             }
+            global $globals;
+            if ($globals->banana->event_forum) {
+                require_once 'user.func.inc.php';
+                $forlife = get_user_forlife($this->uid);
+                require_once 'banana/forum.inc.php';
+                $banana = new ForumsBanana($forlife);
+                $post = $banana->post($globals->banana->event_forum,
+                                      $globals->banana->event_reply,
+                                      $this->titre, MiniWiki::wikiToText($this->texte, false, 0, 80));
+                if ($post != -1) {
+                    XDB::execute("UPDATE  evenements
+                                     SET  creation_date = creation_date, post_id = {?}
+                                   WHERE  id = {?}", $post, $eid);
+                }
+            }
             return true;
         }
         return false;