diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index 038d835..23d49c9 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -76,52 +76,74 @@ class Posts public function entry() { - $categories = $this->post->showCategories(); + if (Session::exists('userid')) { + $categories = $this->post->showCategories(); - $user = Session::get('userid'); + $user = Session::get('userid'); - View::render('Data/entry_pengumuman.html', [ - 'categories' => $categories, - 'user' => $user, - 'token' => Token::generate() - ]); + View::render('Data/entry_pengumuman.html', [ + 'categories' => $categories, + 'user' => $user, + 'token' => Token::generate() + ]); - return true; + return true; + } else { + Redirect::to('/'); + } } public function edit($id) { - if ($id) { - if (is_array($id)) { - $id = implode('', $id); - } + if (Session::exists('userid')) { + if ($id) { + if (is_array($id)) { + $id = implode('', $id); + } + $categories = $this->post->showCategories(); + + $post = $this->post->showSingle($id); + $creator = $post['creator']; + $editor = $post['editor']; + + $creator = $this->access->showSingle($creator); + $editor = $this->access->showSingle($editor); + + $editor_now = Session::get('userid'); + + $date = new \DateTime(); + $timestamp = $date->format("Y-m-d"); + + View::render( + 'Data/edit_pengumuman.html', + [ + 'post' => $post, + 'categories' => $categories, + 'creator' => $creator, + 'editor' => $editor, + 'editor_now' => $editor_now, + 'timestamp' => $timestamp, + 'token' => Token::generate() + ] + ); + } + } else { + Redirect::to('/'); + } + } + + public function category() + { + if (Session::exists('userid')) { $categories = $this->post->showCategories(); - $post = $this->post->showSingle($id); - $creator = $post['creator']; - $editor = $post['editor']; - - $creator = $this->access->showSingle($creator); - $editor = $this->access->showSingle($editor); - - $editor_now = Session::get('userid'); - - $date = new \DateTime(); - $timestamp = $date->format("Y-m-d"); - - View::render( - 'Data/edit_pengumuman.html', - [ - 'post' => $post, - 'categories' => $categories, - 'creator' => $creator, - 'editor' => $editor, - 'editor_now' => $editor_now, - 'timestamp' => $timestamp, - 'token' => Token::generate() - ] - ); + View::render('Data/kategori.html', [ + 'categories' => $categories, + 'token' => Token::generate() + ]); + } else { + Redirect::to('/'); } } @@ -129,10 +151,19 @@ class Posts public function post($args = []) { $table = 'pengumuman'; + if (isset($args['_addon'])) { + $table = $args['_addon']; + unset($args['_addon']); + } if ($this->post->entry($table, $args)) { Session::flash('info', 'Data successfuly uploaded'); - Redirect::to('/'); + + if ($table = 'kategori') { + Redirect::to('/posts/category'); + } elseif ($table = 'pengumuman') { + Redirect::to('/'); + } } } @@ -154,12 +185,21 @@ class Posts public function delete($args = []) { $table = 'pengumuman'; + if (isset($args['_addon'])) { + $table = $args['_addon']; + unset($args['_addon']); + } $id = $args['id']; if ($this->post->delete($table, $id)) { Session::flash('info', 'Data successfuly removed'); - Redirect::to('/'); + + if ($table = 'kategori') { + Redirect::to('/posts/category'); + } elseif ($table = 'pengumuman') { + Redirect::to('/'); + } } } } diff --git a/App/Models/Post.php b/App/Models/Post.php index 5ad387e..0763307 100644 --- a/App/Models/Post.php +++ b/App/Models/Post.php @@ -29,6 +29,7 @@ class Post extends \Core\Model [ 'id int(3) NOT NULL AUTO_INCREMENT', 'category varchar(20) NOT NULL', + 'status tinyint NOT NULL DEFAULT 1', 'PRIMARY KEY (id)' ] ); @@ -88,7 +89,7 @@ class Post extends \Core\Model try { $db = static::connectDB(); - $sql = "SELECT * FROM kategori"; + $sql = "SELECT * FROM kategori WHERE status = 1"; $query = $db->prepare($sql); diff --git a/App/Views/Data/kategori.html b/App/Views/Data/kategori.html new file mode 100644 index 0000000..af1c548 --- /dev/null +++ b/App/Views/Data/kategori.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% block title %}Kategori{% endblock %} + +{% block body %} +
List Kategori:
+