86 lines
2.0 KiB
PHP
86 lines
2.0 KiB
PHP
<?php
|
|
|
|
class NewsController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->is(["Admin"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction() {
|
|
$this->layout()->setTemplate("News/Index");
|
|
|
|
$newss = NewsModel::getAll();
|
|
$this->layout()->set("newss", $newss);
|
|
}
|
|
|
|
protected function saveAction($request) {
|
|
if(!$this->me->isAdmin()) {
|
|
return $this->redirect("News");
|
|
}
|
|
|
|
$id = false;
|
|
|
|
$cl = new News();
|
|
|
|
$cl->subject = $request['subject'];
|
|
$cl->text = preg_replace('/<[^>]*script/','',$request['new_text']);
|
|
|
|
|
|
if(!$id) {
|
|
$cl->create_by = $this->me->id;
|
|
}
|
|
$cl->edit_by = $this->me->id;
|
|
|
|
if(!$cl->save()) {
|
|
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut!", "error");
|
|
$this->layout()->set("new_news", $cl);
|
|
$this->layout()->setTemplate("News/Index");
|
|
return true;
|
|
}
|
|
|
|
$this->layout()->setFlash("News gespeichert!","success");
|
|
$this->redirect("News");
|
|
|
|
}
|
|
|
|
protected function deleteAction($request) {
|
|
if(!$this->me->isAdmin()) {
|
|
$this->redirect("News");
|
|
}
|
|
|
|
if(!isset($request['id']) || !is_numeric($request['id']) || $request['id'] < 1) {
|
|
$this->layout()->setFlash("Eintrag nicht gefunden", "error");
|
|
$this->redirect("News");
|
|
}
|
|
$id = $request['id'];
|
|
|
|
$cl = new News($id);
|
|
$cl->delete();
|
|
$this->layout()->setFlash("Eintrag mit ID $id wurde gelöscht.","success");
|
|
$this->redirect("News");
|
|
|
|
}
|
|
|
|
private function getNews() {
|
|
$cl = [];
|
|
|
|
$res = $this->db()->select("News", "*", "1=1 ORDER BY `create` DESC");
|
|
if(!$this->db()->num_rows($res)) {
|
|
return [];
|
|
}
|
|
|
|
while($data = $this->db()->fetch_object($res)) {
|
|
$cl[] = new News($data);
|
|
}
|
|
|
|
return $cl;
|
|
}
|
|
} |