#525: Add a user-friendly Id for the NLs.
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 1 Nov 2006 14:18:25 +0000 (14:18 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 1 Nov 2006 14:18:25 +0000 (14:18 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1041 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
include/newsletter.inc.php
modules/events.php
templates/newsletter/edit.tpl
templates/newsletter/show.tpl

index c6efa72..1021b37 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,7 @@ Bug/Wish:
 
     * Events:
         - #517: URL catcher update (www).                                  -Car
+        - #525: Add a user-friendly id for newsletters                     -FRU
 
     * Lists:
         - #485: Can moderate pure-HTML mails                               -FRU
index a60ecb3..236026c 100644 (file)
@@ -38,6 +38,7 @@ class NewsLetter
     // {{{ properties
     
     var $_id;
+    var $_shortname;
     var $_date;
     var $_title;
     var $_head;
@@ -49,41 +50,42 @@ class NewsLetter
     
     function NewsLetter($id=null)
     {
-    if (isset($id)) {
-        if ($id == 'last') {
-        $res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'");
+        if (isset($id)) {
+            if ($id == 'last') {
+                $res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'");
                 $id  = $res->fetchOneCell();
+            }
+            $res = XDB::query("SELECT * FROM newsletter WHERE id={?} OR short_name={?} LIMIT 1", $id, $id);
+        } else {
+            $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
+            if (!$res->numRows()) {
+                insert_new_nl();
+            }
+            $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
         }
-        $res = XDB::query("SELECT * FROM newsletter WHERE id={?}", $id);
-    } else {
-        $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
-        if (!$res->numRows()) {
-            insert_new_nl();
-        }
-        $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
-    }
-    $nl = $res->fetchOneAssoc();
+        $nl = $res->fetchOneAssoc();
 
-    $this->_id    = $nl['id'];
-    $this->_date  = $nl['date'];
-    $this->_title = $nl['titre'];
-    $this->_head  = $nl['head'];
+        $this->_id        = $nl['id'];
+        $this->_shortname = $nl['short_name'];
+        $this->_date      = $nl['date'];
+        $this->_title     = $nl['titre'];
+        $this->_head      = $nl['head'];
 
-    $res = XDB::iterRow("SELECT cid,titre FROM newsletter_cat ORDER BY pos");
-    while (list($cid, $title) = $res->next()) {
-        $this->_cats[$cid] = $title;
-    }
+        $res = XDB::iterRow("SELECT cid,titre FROM newsletter_cat ORDER BY pos");
+        while (list($cid, $title) = $res->next()) {
+            $this->_cats[$cid] = $title;
+        }
     
-    $res = XDB::iterRow(
+        $res = XDB::iterRow(
                 "SELECT  a.title,a.body,a.append,a.aid,a.cid,a.pos
                    FROM  newsletter_art AS a
              INNER JOIN  newsletter     AS n USING(id)
              LEFT  JOIN  newsletter_cat AS c ON(a.cid=c.cid)
                   WHERE  a.id={?}
                ORDER BY  c.pos,a.pos", $this->_id);
-    while (list($title, $body, $append, $aid, $cid, $pos) = $res->next()) {
-        $this->_arts[$cid]["a$aid"] = new NLArticle($title, $body, $append, $aid, $cid, $pos);
-    }
+        while (list($title, $body, $append, $aid, $cid, $pos) = $res->next()) {
+            $this->_arts[$cid]["a$aid"] = new NLArticle($title, $body, $append, $aid, $cid, $pos);
+        }
     }
 
     // }}}
@@ -99,8 +101,16 @@ class NewsLetter
 
     function save()
     {
-    XDB::execute('UPDATE newsletter SET date={?},titre={?},head={?} WHERE id={?}',
-                     $this->_date, $this->_title, $this->_head, $this->_id);
+        XDB::execute('UPDATE newsletter SET date={?},titre={?},head={?},short_name={?} WHERE id={?}',
+                     $this->_date, $this->_title, $this->_head, $this->_shortname,$this->_id);
+    }
+
+    // }}}
+    // {{{ function id()
+
+    function id()
+    {
+        return is_null($this->_shortname) ? $this->_id : $this->_shortname;
     }
 
     // }}}
@@ -236,7 +246,7 @@ class NewsLetter
     
     function toHtml($prenom, $nom, $sexe, $body=false, $urlprefix = false)
     {
-        $u    = $urlprefix ? 'nl/show/'.$this->_id : '';
+        $u    = $urlprefix ? 'nl/show/'.$this->id() : '';
     $res  = '<div class="title">'.$this->title().'</div>';
     
     $head = $this->head();
@@ -443,13 +453,13 @@ function insert_new_nl()
 
 function get_nl_slist()
 {
-    $res = XDB::query("SELECT id,date,titre FROM newsletter ORDER BY date DESC");
+    $res = XDB::query("SELECT IF(short_name IS NULL, id,short_name) as id,date,titre FROM newsletter ORDER BY date DESC");
     return $res->fetchAllAssoc();
 }
 
 function get_nl_list()
 {
-    $res = XDB::query("SELECT id,date,titre FROM newsletter WHERE bits!='new' ORDER BY date DESC");
+    $res = XDB::query("SELECT IF(short_name IS NULL, id,short_name) as id,date,titre FROM newsletter WHERE bits!='new' ORDER BY date DESC");
     return $res->fetchAllAssoc();
 }
 
index 7e90996..eaee6ea 100644 (file)
@@ -376,10 +376,16 @@ class EventsModule extends PLModule
         }
         
         if($aid == 'update') {
-            $nl->_title = Post::v('title');
-            $nl->_date  = Post::v('date');
-            $nl->_head  = Post::v('head');
-            $nl->save();
+            $nl->_title     = Post::v('title');
+            $nl->_date      = Post::v('date');
+            $nl->_head      = Post::v('head');
+            $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null;
+            if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) {
+                $nl->save();
+            } else {
+                $page->trig('Le nom de la NL n\'est pas valide');
+                pl_redirect('admin/newsletter/edit/' . $nl->_id);
+            }
         }
         
         if(Post::v('save')) {
@@ -389,7 +395,7 @@ class EventsModule extends PLModule
             pl_redirect("admin/newsletter/edit/$nid");
         }
         
-        if($action == 'edit') {
+        if($action == 'edit' && $aid != 'update') {
             $eaid = $aid;
             if(Post::has('title')) {
                 $art  = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'),
index b19bfa3..2d6ca24 100644 (file)
@@ -28,7 +28,7 @@
 
 <p>
 [<a href="admin/newsletter">liste</a>]
-[<a href="nl/show/{$nl->_id}">visualiser</a>]
+[<a href="nl/show/{$nl->id()}">visualiser</a>]
 </p>
 
 <form action='admin/newsletter/edit/{$nl->_id}/update' method='post'>
     </tr>
     <tr>
       <td class='titre'>
+        Nom
+      </td>
+      <td>
+        <input type='text' size='16' name='shortname' value="{$nl->_shortname}" />
+        <span class="smaller">(Ex : 2006-06 pour la NL de juin 2006)</span>
+      </td>
+    </tr>
+    <tr>
+      <td class='titre'>
         Titre
       </td>
       <td>
index 6dce87a..833c88e 100644 (file)
 <p>
 [<a href='nl'>liste des lettres</a>]
 {if $smarty.get.text}
-[<a href='nl/show/{$nl->_id}'>version HTML</a>]
+[<a href='nl/show/{$nl->id()}'>version HTML</a>]
 {else}
-[<a href='nl/show/{$nl->_id}?text=1'>version Texte</a>]
+[<a href='nl/show/{$nl->id()}?text=1'>version Texte</a>]
 {/if}
 {if $smarty.session.perms eq admin}
-[<a href='admin/newsletter/edit/{$nl->_id}'>Editer</a>]
+[<a href='admin/newsletter/edit/{$nl->id()}'>Editer</a>]
 {/if}
 </p>