From: x2003bruneau Date: Wed, 1 Nov 2006 14:18:25 +0000 (+0000) Subject: #525: Add a user-friendly Id for the NLs. X-Git-Tag: xorg/0.9.12~151 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ed76a506a12cf15a03232d142d5bfd0c2c882b92;p=platal.git #525: Add a user-friendly Id for the NLs. git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1041 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/ChangeLog b/ChangeLog index c6efa72..1021b37 100644 --- 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 diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index a60ecb3..236026c 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -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 = '
'.$this->title().'
'; $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(); } diff --git a/modules/events.php b/modules/events.php index 7e90996..eaee6ea 100644 --- a/modules/events.php +++ b/modules/events.php @@ -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'), diff --git a/templates/newsletter/edit.tpl b/templates/newsletter/edit.tpl index b19bfa3..2d6ca24 100644 --- a/templates/newsletter/edit.tpl +++ b/templates/newsletter/edit.tpl @@ -28,7 +28,7 @@

[liste] -[visualiser] +[visualiser]

@@ -48,6 +48,15 @@ + Nom + + + + (Ex : 2006-06 pour la NL de juin 2006) + + + + Titre diff --git a/templates/newsletter/show.tpl b/templates/newsletter/show.tpl index 6dce87a..833c88e 100644 --- a/templates/newsletter/show.tpl +++ b/templates/newsletter/show.tpl @@ -27,12 +27,12 @@

[liste des lettres] {if $smarty.get.text} -[version HTML] +[version HTML] {else} -[version Texte] +[version Texte] {/if} {if $smarty.session.perms eq admin} -[Editer] +[Editer] {/if}