Close #648 and #649: Layout of nl/show (and ax/show)
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 9 Mar 2007 20:15:44 +0000 (20:15 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 9 Mar 2007 20:15:44 +0000 (20:15 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1561 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
htdocs/images/icons/resultset_next.gif
htdocs/images/icons/resultset_previous.gif [new file with mode: 0644]
include/massmailer.inc.php
include/newsletter.inc.php
modules/axletter/axletter.inc.php
templates/axletter/show.tpl
templates/include/massmailer-nav.tpl [new file with mode: 0644]
templates/newsletter/show.tpl

index 5ca1597..4b6ff78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,6 +33,10 @@ Bug/Wish:
     * Emails:
         - #595: Update antispam description                                -FRU
 
+    * Newsletter:
+        - #648: Add navigation link in preview page                        -FRU
+        - #649: Fix layout of preview page                                 -FRU
+
     * Profile:
         - Better checks on image type for photos                           -FRU
         - #646: Don't send a mail to an invalid address                    -FRU
index b71a4f7..6f84518 100644 (file)
Binary files a/htdocs/images/icons/resultset_next.gif and b/htdocs/images/icons/resultset_next.gif differ
diff --git a/htdocs/images/icons/resultset_previous.gif b/htdocs/images/icons/resultset_previous.gif
new file mode 100644 (file)
index 0000000..465328c
Binary files /dev/null and b/htdocs/images/icons/resultset_previous.gif differ
index fd5093d..fce33ca 100644 (file)
@@ -36,11 +36,16 @@ abstract class MassMailer
 
     public $_head;
 
-    function __construct($tpl, $css, $prefix)
+    protected $_table;
+    protected $_subscriptionTable;
+
+    function __construct($tpl, $css, $prefix, $tbl, $stbl)
     {
         $this->_tpl    = $tpl;
         $this->_css    = $css;
         $this->_prefix = $prefix;
+        $this->_table  = $tbl;
+        $this->_subscriptionTable = $stbl;
     }
 
     public function id()
@@ -48,6 +53,53 @@ abstract class MassMailer
         return is_null($this->_shortname) ? $this->_id : $this->_shortname;
     }
 
+    private function selectId($where)
+    {
+        $res = XDB::query("SELECT  IF (n.short_name IS NULL, n.id, n.short_name)
+                             FROM  {$this->_table} AS n
+                            WHERE  n.bits != 'new' AND {$where}
+                            LIMIT  1"); 
+        if ($res->numRows() != 1) {
+            return null;
+        }
+        return $res->fetchOneCell();
+    }
+
+    public function prev()
+    {
+        static $val;
+        if (!isset($val)) {
+            $val = $this->selectId("n.id < {$this->_id} ORDER BY n.id DESC");
+        }
+        return $val;
+    }
+
+    public function next()
+    {
+        static $val;
+        if (!isset($val)) {
+            $val = $this->selectId("n.id > {$this->_id} ORDER BY n.id");
+        }
+        return $val;
+    }
+
+    public function last()
+    {
+        static $val;
+        if (!isset($val)) {
+            $res = XDB::query("SELECT  MAX(n.id)
+                                 FROM  {$this->_table} AS n
+                                WHERE  n.bits != 'new' AND n.id > {?}",
+                              $this->_id);
+            if ($res->numRows() != 1) {
+                $val = null;
+            } else {
+                $val = $res->fetchOneCell();
+            }
+        }
+        return $val;
+    }
+
     public function title($mail = false)
     {
         return $mail ? $this->_title_mail : $this->_title;
@@ -126,7 +178,7 @@ abstract class MassMailer
                          u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
                          FIND_IN_SET('femme', u.flags),
                          q.core_mail_fmt AS pref, 0 AS hash
-                   FROM  {$this->subscriptionTable()}  AS ni
+                   FROM  {$this->_subscriptionTable}  AS ni
              INNER JOIN  auth_user_md5   AS u  USING(user_id)
              INNER JOIN  auth_user_quick AS q  ON(q.user_id = u.user_id)
              INNER JOIN  aliases         AS a  ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
@@ -149,7 +201,7 @@ abstract class MassMailer
                 $sent[] = "(user_id='$uid'" . (!$uid ? " AND email='$bestalias')": ')');
                 $this->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html', $hash);
             }
-            XDB::execute("UPDATE  {$this->subscriptionTable()}
+            XDB::execute("UPDATE  {$this->_subscriptionTable}
                              SET  last = {?}
                            WHERE " . implode(' OR ', $sent), $this->_id);
             
@@ -160,7 +212,6 @@ abstract class MassMailer
     abstract protected function assignData(&$smarty);
     abstract protected function setSent();
 
-    abstract protected function subscriptionTable();
     abstract protected function subscriptionWhere();
 }
 
index 02e5248..386ef16 100644 (file)
@@ -31,7 +31,7 @@ class NewsLetter extends MassMailer
 
     function __construct($id = null)
     {
-        parent::__construct('newsletter/nl.tpl', 'nl.css', 'nl/show');
+        parent::__construct('newsletter/nl.tpl', 'nl.css', 'nl/show', 'newsletter', 'newsletter_ins');
         if (isset($id)) {
             if ($id == 'last') {
                 $res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'");
@@ -146,11 +146,6 @@ class NewsLetter extends MassMailer
                             VALUES  ({?}, 0)", $user);
     }
 
-    protected function subscriptionTable()
-    {
-        return 'newsletter_ins';
-    }
-
     protected function subscriptionWhere()
     {
         return '1';
index e405f3b..af34cac 100644 (file)
@@ -33,7 +33,7 @@ class AXLetter extends MassMailer
 
     function __construct($id)
     {
-        parent::__construct('axletter/letter.tpl', 'ax.css', 'ax/show');
+        parent::__construct('axletter/letter.tpl', 'ax.css', 'ax/show', 'axletter', 'axletter_ins');
         $this->_head = '<cher> <prenom>,';
 
         if (!is_array($id)) {
@@ -184,11 +184,6 @@ class AXLetter extends MassMailer
         return XDB::execute("DELETE FROM axletter_rights WHERE user_id = {?}", $uid);
     }
 
-    protected function subscriptionTable()
-    {
-        return 'axletter_ins';
-    }
-
     protected function subscriptionWhere()
     {
         if (!$this->_promo_min && !$this->_promo_max) {
index 25ed9e0..08a46c6 100644 (file)
@@ -20,7 +20,7 @@
 {*                                                                        *}
 {**************************************************************************}
 
-<h1>
+<h1 style="clear: both">
   {if $am->_date}
   Lettre de l'AX du {$am->_date|date_format}
   {else}
@@ -28,8 +28,7 @@
   {/if}
 </h1>
 
-<p>
-[<a href='ax'>liste des lettres</a>]
+<p style="float: left">
 {if $smarty.get.text}
 [<a href='{$platal->pl_self()}'>version HTML</a>]
 {else}
 {/if}
 </p>
 
+{include file="include/massmailer-nav.tpl" mm=$am base=ax}
+
 <form method="post" action="{$platal->path}">
-  <div class='center'>
+  <div class='center' style="clear: both">
     <input type='submit' value="me l'envoyer" name='send' />
   </div>
 </form>
 
-<fieldset>
-<legend>{$am->title(true)}</legend>
-  {include file="axletter/letter.tpl"}
+<table class="bicol">
+  <tr><th>{$am->title(true)}</th></tr>
+  <tr>
+    <td>
+      {include file="axletter/letter.tpl"}
+    </td>
+  </tr>
 </fieldset>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
diff --git a/templates/include/massmailer-nav.tpl b/templates/include/massmailer-nav.tpl
new file mode 100644 (file)
index 0000000..ac68c62
--- /dev/null
@@ -0,0 +1,55 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<table style="float: right; text-align: center" id="letter_nav">
+  <tr>
+    {if $mm->prev() neq null}
+    <td rowspan="2" style="vertical-align: middle">
+      <a href="{$base}/show/{$mm->prev()}">
+      {icon name=resultset_previous title="Lettre précédente"}Lettre précédente
+      </a>
+    </td>
+    {/if}
+    <td>
+      [<a href="{$base}">Liste des lettres</a>]
+    </td>
+    {if $mm->next() neq null}
+    <td rowspan="2" style="vertical-align: middle">
+      <a href="{$base}/show/{$mm->next()}">
+      Lettre suivante{icon name=resultset_next title="Lettre suivante"}
+      </a>
+    </td>
+    {/if}
+  </tr>
+  {if $mm->last() neq null}
+  <tr>
+    <td>
+      <a href="{$base}/show/{$mm->last()}">
+        <img src="images/up.png" alt="" title="Liste des lettres" />Dernière lettre<img src="images/up.png" alt="" title="Liste des lettres" />
+      </a>
+    </td>
+  </tr>
+  {/if}
+</table>
+
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 3cf0ce9..71f2160 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<h1>
+<h1 style="clear: both">
   Lettre de Polytechnique.org du {$nl->_date|date_format}
 </h1>
 
-<p>
-[<a href='nl'>liste des lettres</a>]
-{if $smarty.get.text}
-[<a href='nl/show/{$nl->id()}'>version HTML</a>]
-{else}
-[<a href='nl/show/{$nl->id()}?text=1'>version Texte</a>]
-{/if}
-{if $smarty.session.perms->hasFlag('admin')}
-[<a href='admin/newsletter/edit/{$nl->id()}'>Editer</a>]
-{/if}
+<p style="float: left">
+  {if $smarty.get.text}
+  [<a href='nl/show/{$nl->id()}'>version HTML</a>]
+  {else}
+  [<a href='nl/show/{$nl->id()}?text=1'>version Texte</a>]
+  {/if}
+  {if $smarty.session.perms->hasFlag('admin')}
+  [<a href='admin/newsletter/edit/{$nl->id()}'>Editer</a>]
+  {/if}
 </p>
 
+{include file="include/massmailer-nav.tpl" mm=$nl base=nl}
+
 <form method="post" action="{$platal->path}">
-  <div class='center'>
+  <div class='center' style="clear: both">
     <input type='submit' value="me l'envoyer" name='send' />
   </div>
 </form>
 
-<fieldset>
-<legend>{$nl->title(true)}</legend>
-  {include file="newsletter/nl.tpl"}
-</fieldset>
+<table class="bicol">
+  <tr><th>{$nl->title(true)}</th></tr>
+  <tr>
+    <td>
+      {include file="newsletter/nl.tpl"}
+    </td>
+  </tr>
+</table>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}