summaryrefslogtreecommitdiffstats
path: root/modules/news.inc.php
diff options
context:
space:
mode:
authorJonathan Bauer2014-06-05 16:19:38 +0200
committerJonathan Bauer2014-06-05 16:19:38 +0200
commitdd27c6d4a893beb0ec7dc558e14763652fa04a79 (patch)
treef3d355514bb19ca3dbe0babbd478b201694ce30c /modules/news.inc.php
parentDelete more old files (diff)
downloadslx-admin-dd27c6d4a893beb0ec7dc558e14763652fa04a79.tar.gz
slx-admin-dd27c6d4a893beb0ec7dc558e14763652fa04a79.tar.xz
slx-admin-dd27c6d4a893beb0ec7dc558e14763652fa04a79.zip
news tab for setting/viewing news
Diffstat (limited to 'modules/news.inc.php')
-rw-r--r--modules/news.inc.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/modules/news.inc.php b/modules/news.inc.php
new file mode 100644
index 00000000..03850527
--- /dev/null
+++ b/modules/news.inc.php
@@ -0,0 +1,61 @@
+<?php
+
+class Page_News extends Page
+{
+
+ private $latestNews = array();
+
+ 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
+ Util::redirect('?do=News');
+ }
+
+ }
+
+ protected function doRender()
+ {
+ // user must be logged in
+ if (!User::isLoggedIn()) {
+ Render::addTemplate('page-main-guest');
+ return;
+ }
+
+ // only admins should be able to edit news
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ return;
+ }
+
+ // fetch the latest news
+ $res = Database::simpleQuery('SELECT * FROM news ORDER BY dateline DESC LIMIT 1');
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $latestTitle = $row['title'];
+ $latestContent = $row['content'];
+ $latestDate = $row['dateline'];
+ }
+ // show it to the user
+ Render::addDialog('News Verwaltung', false, 'page-news', array(
+ 'token' => Session::get('token'),
+ 'latestDate' => DateTime::createFromFormat('U', $latestDate)->format('Y-m-d H:i:s'),
+ 'latestContent' => $latestContent,
+ 'latestTitle' => $latestTitle
+ ));
+
+ }
+
+}