Merge commit 'origin/fusionax' into account
[platal.git] / modules / newsletter.php
index cb7b60c..3d8b610 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -56,18 +56,19 @@ class NewsletterModule extends PLModule
 
         require_once 'newsletter.inc.php';
 
-        $nl  = new NewsLetter($nid);
-        if (Get::has('text')) {
-            $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme'));
-        } else {
-            $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
-        }
-        if (Post::has('send')) {
-            $res = XDB::query("SELECT hash FROM newsletter_ins WHERE user_id = {?}", S::i('uid'));
-            $nl->sendTo(S::user()->login(), S::user()->bestEmail(),
-                        S::v('prenom'), S::v('nom'),
-                        S::v('femme'), S::v('mail_fmt') != 'texte',
-                        $res->fetchOneCell());
+        try {
+            $nl = new NewsLetter($nid);
+            $user =& S::user();
+            if (Get::has('text')) {
+                $nl->toText($page, $user);
+            } else {
+                $nl->toHtml($page, $user);
+            }
+            if (Post::has('send')) {
+                $nl->sendTo($user);
+            }
+        } catch (MailNotFound $e) {
+            return PL_NOT_FOUND;
         }
     }
 
@@ -87,7 +88,7 @@ class NewsletterModule extends PLModule
             $page->assign('art', $art);
         } elseif (Post::has('valid')) {
             require_once('validations.inc.php');
-            $art = new NLReq(S::v('uid'), Post::v('title'),
+            $art = new NLReq(S::user(), Post::v('title'),
                              Post::v('body'), Post::v('append'));
             $art->submit();
             $page->assign('submited', true);