diff options
author | Jonathan Bauer | 2014-06-06 17:28:36 +0200 |
---|---|---|
committer | Jonathan Bauer | 2014-06-06 17:28:36 +0200 |
commit | 4fa7e3e57cc1e85b4f07bb9ce3e87a33deed626a (patch) | |
tree | 2c4ce5c4b10732d8e4e83c918b27fbb66fb07c4a | |
parent | Started "System Status" page (diff) | |
download | slx-admin-4fa7e3e57cc1e85b4f07bb9ce3e87a33deed626a.tar.gz slx-admin-4fa7e3e57cc1e85b4f07bb9ce3e87a33deed626a.tar.xz slx-admin-4fa7e3e57cc1e85b4f07bb9ce3e87a33deed626a.zip |
news page now lists old news. Make use of actions.
-rw-r--r-- | inc/message.inc.php | 3 | ||||
-rw-r--r-- | modules/news.inc.php | 104 | ||||
-rw-r--r-- | templates/page-news.html | 82 |
3 files changed, 137 insertions, 52 deletions
diff --git a/inc/message.inc.php b/inc/message.inc.php index 6df7f07a..11735e1b 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -36,8 +36,9 @@ $error_text = array( 'taskmanager-format' => 'Taskmanager hat ungültige Daten zurückgeliefert', 'task-error' => 'Ausführung fehlgeschlagen: {{0}}', 'invalid-ip' => 'Kein Interface ist auf die Adresse {{0}} konfiguriert', - 'news-success' => 'News erfolgreich aktualisiert.', + 'news-set-success' => 'News erfolgreich aktualisiert.', 'news-empty' => 'Es wurde keine News in der Datenbank gefunden.', + 'news-del-success' => 'News gelöscht.', ); class Message diff --git a/modules/news.inc.php b/modules/news.inc.php index e08006dd..03eec580 100644 --- a/modules/news.inc.php +++ b/modules/news.inc.php @@ -2,28 +2,33 @@ class Page_News extends Page { + private $newsId = false; + private $newsTitle = false; + private $newsContent = false; + private $newsDate = false; protected function doPreprocess() { // load user, we will need it later User::load(); - // check if news content were set by the user - $newsTitle = Request::post('news-title'); - $newsContent = Request::post('news-content'); - 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(), - 'title' => $newsTitle, - 'content' => $newsContent - )); - // all done, redirect to main news page - Message::addSuccess('news-success'); - Util::redirect('?do=News'); - } + // get the newsid given per GET + $newsId = Request::get('newsid'); + if ($newsId !== false) $this->newsId = $newsId; + // check which action we need to do + $action = Request::get('action'); + if ($action === 'save') { + // save to DB + $this->saveNews(); + } elseif ($action === 'delete') { + // delete it + $this->delNews(); + } + } + + private function applyNews() { + } protected function doRender() @@ -40,24 +45,71 @@ class Page_News extends Page return; } - // fetch the latest news - $row = Database::queryFirst('SELECT * FROM news ORDER BY dateline DESC LIMIT 1'); + // 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) { - $latestTitle = $row['title']; - $latestContent = $row['content']; - $latestDate = $row['dateline']; + $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); + $res = $paginate->exec(); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $day = date('d.m.Y', $row['dateline']); + $row['date'] = $day . date(' H:i', $row['dateline']); - // show it to the user - Render::addDialog('bwLehrpool News Verwaltung', false, 'page-news', array( - 'token' => Session::get('token'), - 'latestDate' => date('Y-m-d H:i:s (T)', $latestDate), - 'latestContent' => $latestContent, - 'latestTitle' => $latestTitle + if ($row['newsid'] == $this->newsId) $row['active'] = "active"; + $lines[] = $row; + } + + $paginate->render('page-news', array( + 'token' => Session::get('token'), + 'latestDate' => date('Y-m-d H:i:s (T)', $this->newsDate), + 'latestContent' => $this->newsContent, + 'latestTitle' => $this->newsTitle, + 'list' => $lines )); } + 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) { + + // we got title and content, save it to DB + Database::exec("INSERT INTO news (dateline, title, content) VALUES (:dateline, :title, :content)", array( + 'dateline' => time(), + 'title' => $newsTitle, + 'content' => $newsContent + )); + // all done, redirect to main news page + Message::addSuccess('news-set-success'); + Util::redirect('?do=News'); + } + } + + private function delNews() + { + Database::exec("DELETE FROM news WHERE newsid = :newsid LIMIT 1", array( + 'newsid' => $this->newsId + )); + Message::addSuccess('news-del-success'); + Util::redirect('?do=News'); + } + } diff --git a/templates/page-news.html b/templates/page-news.html index bbf9fd6c..76692d29 100644 --- a/templates/page-news.html +++ b/templates/page-news.html @@ -1,28 +1,60 @@ -<p>Hier haben Sie die Möglichkeit, die von bwLehrpool-Clients angezeigten News zu editieren. -</p> -<form action="?do=News" method="post"> - - <div class="form-group"> - <div class="panel panel-default"> - <div class="panel-heading"> - <label for="news-title-id">Titel</label> - </div> - <div class="panel-body"> - <input type="text" name="news-title" id ="news-title-id" class="form-control" placeholder="Willkommen!" value="{{latestTitle}}"> - </div> - </div> - <div class="panel panel-default"> - <div class="panel-heading"> - <label for="news-content-id">Inhalt</label> - </div> - <div class="panel-body"> - <textarea name="news-content" id ="news-content-id" class="form-control" rows="5" cols="30" placeholder="Willkommen beim bwLehrpool-System!">{{latestContent}}</textarea> - </div> - </div> +<p>Hier haben Sie die Möglichkeit, die von bwLehrpool-Clients angezeigten News zu editieren.</p> +<div class="panel panel-default"> +<div class="panel-heading"> + <label>Aktive News</label> +</div> +<div class="panel-body"> +<form action="?do=News&action=save" method="post"> + <div class="form-group"> + <div class="panel panel-default"> + <div class="panel-heading"> + <label for="news-title-id">Titel</label> </div> - - <div>Letzte Aktualisierung: {{latestDate}}</div> - <br> + <div class="panel-body"> + <input type="text" name="news-title" id ="news-title-id" class="form-control" placeholder="Willkommen!" value="{{latestTitle}}"> + </div> + </div> + <div class="panel panel-default"> + <div class="panel-heading"> + <label for="news-content-id">Inhalt</label> + </div> + <div class="panel-body"> + <textarea name="news-content" id ="news-content-id" class="form-control" rows="5" cols="30" placeholder="Willkommen beim bwLehrpool-System!">{{latestContent}}</textarea> + </div> + </div> + </div> + <div>Letzte Aktualisierung: {{latestDate}}</div> + <br> + <button class="btn btn-primary btn-sm" type="submit">Speichern</button> <input type="hidden" name="token" value="{{token}}"> - <button class="btn btn-sm btn-primary" type="submit">Speichern</button> </form> +</div> +</div> + +<div class="panel panel-default"> +<div class="panel-heading"> + <label>Alte News</label> +</div> +<div class="panel-body"> +<table class="table table-stripped table-condensed"> + <thead> + <th class="col-sm-2">Datum</th> + <th class="col-sm-2">Titel</th> + <th class="col-sm-8">Inhalt</th> + <th></th> + <th></th> + </thead> + <tbody> + {{#list}} + <tr {{#active}}class="active"{{/active}}> + <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-danger btn-sm glyphicon glyphicon-remove" href="?do=news&newsid={{newsid}}&action=delete"> Löschen</a></td> + </tr> + {{/list}} + </tbody> +</table> +</div> +</div>
\ No newline at end of file |