Adds email storage backends in the redirection list in redirection testing emails.
[platal.git] / modules / axletter / axletter.inc.php
index 0f16c36..a82eb64 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   *
@@ -33,7 +33,7 @@ class AXLetter extends MassMailer
 
     function __construct($id)
     {
-        parent::__construct('axletter/letter.tpl', 'ax.css', 'ax/show');
+        parent::__construct('axletter/letter.mail.tpl', 'ax.css', 'ax/show', 'axletter', 'axletter_ins');
         $this->_head = '<cher> <prenom>,';
 
         if (!is_array($id)) {
@@ -45,7 +45,7 @@ class AXLetter extends MassMailer
             } else {
                 $res = XDB::query("SELECT  *
                                      FROM  axletter
-                                    WHERE  id = {?} OR shortname = {?}", $id, $id);
+                                    WHERE  id = {?} OR short_name = {?}", $id, $id);
             }
             if (!$res->numRows()) {
                 $this->_id = null;
@@ -56,6 +56,9 @@ class AXLetter extends MassMailer
         list($this->_id, $this->_shortname, $this->_title_mail, $this->_title,
              $this->_body, $this->_signature, $this->_promo_min, $this->_promo_max,
              $this->_echeance, $this->_date, $this->_bits) = $id;
+        if ($this->_date == '0000-00-00') {
+            $this->_date = 0;
+        }
     }
 
     protected function assignData(&$smarty)
@@ -110,7 +113,7 @@ class AXLetter extends MassMailer
                  WHERE  ni.last < {?} AND {$this->subscriptionWhere()}
                         AND (e.email IS NOT NULL OR ni.user_id = 0)
               GROUP BY  u.user_id";
-    }              
+    }
 
     static public function subscriptionState($uid = null)
     {
@@ -119,8 +122,8 @@ class AXLetter extends MassMailer
                              FROM  axletter_ins
                             WHERE  user_id={?}", $user);
         return $res->fetchOneCell();
-    }   
-    
+    }
+
     static public function unsubscribe($uid = null, $hash = false)
     {
         $user = is_null($uid) ? S::v('uid') : $uid;
@@ -157,9 +160,28 @@ class AXLetter extends MassMailer
         return $res->fetchOneCell();
     }
 
-    protected function subscriptionTable()
+    static public function grantPerms($uid)
+    {
+        if (!is_numeric($uid)) {
+            $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid);
+            $uid = $res->fetchOneCell();
+        }
+        if (!$uid) {
+            return false;
+        }
+        return XDB::execute("INSERT IGNORE INTO axletter_rights SET user_id = {?}", $uid);
+    }
+
+    static public function revokePerms($uid)
     {
-        return 'axletter_ins';
+        if (!is_numeric($uid)) {
+            $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid);
+            $uid = $res->fetchOneCell();
+        }
+        if (!$uid) {
+            return false;
+        }
+        return XDB::execute("DELETE FROM axletter_rights WHERE user_id = {?}", $uid);
     }
 
     protected function subscriptionWhere()
@@ -200,22 +222,22 @@ class AXLetter extends MassMailer
     }
 
     static public function listSent()
-    {   
-        $res = XDB::query("SELECT  IF(shortname IS NULL, id, shortname) as id, date, subject AS titre
+    {
+        $res = XDB::query("SELECT  IF(short_name IS NULL, id, short_name) as id, date, subject AS titre
                              FROM  axletter
                             WHERE  NOT (FIND_IN_SET('new', bits))
                          ORDER BY  date DESC");
         return $res->fetchAllAssoc();
     }
-    
+
     static public function listAll()
-    {   
-        $res = XDB::query("SELECT  IF(shortname IS NULL, id, shortname) as id, date, subject AS titre
+    {
+        $res = XDB::query("SELECT  IF(short_name IS NULL, id, short_name) as id, date, subject AS titre
                              FROM  axletter
                          ORDER BY  date DESC");
         return $res->fetchAllAssoc();
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4:
+// vim:set et sw=4 sts=4 sws=4 enc=utf-8:
 ?>