diff options
author | Jonathan Bauer | 2014-06-06 17:37:02 +0200 |
---|---|---|
committer | Jonathan Bauer | 2014-06-06 17:37:02 +0200 |
commit | 104caa9407b86eaa4971750a183bef0e5891f959 (patch) | |
tree | 7e17a391f016c52266588d38de89d3c35a72d93d | |
parent | news page now lists old news. Make use of actions. (diff) | |
download | slx-admin-104caa9407b86eaa4971750a183bef0e5891f959.tar.gz slx-admin-104caa9407b86eaa4971750a183bef0e5891f959.tar.xz slx-admin-104caa9407b86eaa4971750a183bef0e5891f959.zip |
better action handling for news
-rw-r--r-- | modules/news.inc.php | 55 | ||||
-rw-r--r-- | templates/page-news.html | 2 |
2 files changed, 31 insertions, 26 deletions
diff --git a/modules/news.inc.php b/modules/news.inc.php index 03eec580..2f9aa985 100644 --- a/modules/news.inc.php +++ b/modules/news.inc.php @@ -17,20 +17,21 @@ class Page_News extends Page if ($newsId !== false) $this->newsId = $newsId; // check which action we need to do - $action = Request::get('action'); - if ($action === 'save') { + $action = Request::any('action', 'show'); + if ($action === 'show') { + // show news + $this->showNews(); + } elseif ($action === 'save') { // save to DB $this->saveNews(); } elseif ($action === 'delete') { // delete it $this->delNews(); + } else { + Message::addError('invalid-action', $action); } } - private function applyNews() { - - } - protected function doRender() { // user must be logged in @@ -45,23 +46,7 @@ class Page_News extends Page return; } - // check to see if we need to request a specific newsid - if ($this->newsId !== false) { - $whereClause = "WHERE newsid = $this->newsId "; - } else { - $whereClause = ""; - } - - // fetch the news to be shown - $row = Database::queryFirst("SELECT * FROM news $whereClause ORDER BY dateline DESC LIMIT 1"); - if ($row !== false) { - $this->newsTitle = $row['title']; - $this->newsContent = $row['content']; - $this->newsDate = $row['dateline']; - } else { - Message::addError('news-empty'); - } - + // prepare the list of the older news $lines = array(); $paginate = new Paginate("SELECT newsid, dateline, title, content FROM news ORDER BY dateline DESC", 10); @@ -83,14 +68,34 @@ class Page_News extends Page )); } + + private function showNews() + { + // check to see if we need to request a specific newsid + if ($this->newsId !== false) { + $whereClause = "WHERE newsid = $this->newsId "; + } else { + $whereClause = ""; + } + + // fetch the news to be shown + $row = Database::queryFirst("SELECT * FROM news $whereClause ORDER BY dateline DESC LIMIT 1"); + if ($row !== false) { + $this->newsTitle = $row['title']; + $this->newsContent = $row['content']; + $this->newsDate = $row['dateline']; + } else { + Message::addError('news-empty'); + } + + } private function saveNews() { // check if news content were set by the user $newsTitle = Request::post('news-title'); $newsContent = Request::post('news-content'); - if ($newsContent !== false && $newsTitle !== false) { - + if ($newsContent !== false && $newsTitle !== false) { // we got title and content, save it to DB Database::exec("INSERT INTO news (dateline, title, content) VALUES (:dateline, :title, :content)", array( 'dateline' => time(), diff --git a/templates/page-news.html b/templates/page-news.html index 76692d29..c3826c4f 100644 --- a/templates/page-news.html +++ b/templates/page-news.html @@ -50,7 +50,7 @@ <td class="text-left" nowrap="nowrap">{{date}}</td> <td>{{title}}</td> <td>{{content}}</td> - <td><a class="btn btn-primary btn-sm glyphicon glyphicon-share-alt" href="?do=news&newsid={{newsid}}&action=apply"> Übernehmen</a></td> + <td><a class="btn btn-primary btn-sm glyphicon glyphicon-share-alt" href="?do=news&newsid={{newsid}}&action=show"> Übernehmen</a></td> <td><a class="btn btn-danger btn-sm glyphicon glyphicon-remove" href="?do=news&newsid={{newsid}}&action=delete"> Löschen</a></td> </tr> {{/list}} |