diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php
index efc46e3..e52ee20 100644
--- a/App/Controllers/Posts.php
+++ b/App/Controllers/Posts.php
@@ -166,20 +166,24 @@ class Posts
// Methods
public function post($args = [])
{
- foreach ($args as $value) {
- if ($value == '') {
- Session::flash('info', 'All data must not be empty');
- Redirect::to('/');
- die();
- }
- }
-
$table = 'pengumuman';
if (isset($args['_addon'])) {
$table = $args['_addon'];
unset($args['_addon']);
}
+ foreach ($args as $value) {
+ if ($value == '') {
+ Session::flash('info', 'All data must not be empty');
+ if ($table == 'pengumuman') {
+ Redirect::to('/posts/entry');
+ } elseif ($table == 'kategori') {
+ Redirect::to('/posts/category');
+ }
+ die();
+ }
+ }
+
if ($this->post->entry($table, $args)) {
Session::flash('info', 'Data successfuly uploaded');
@@ -200,11 +204,38 @@ class Posts
$id = $args['id'];
unset($args['id']);
+ // Check if data same with old data
+ $old_data = [
+ $args['old_category'],
+ $args['old_content'],
+ $args['old_valid_at'],
+ $args['old_expired_at']
+ ];
+ $new_data = [
+ $args['category'],
+ $args['content'],
+ $args['valid_at'],
+ $args['expired_at']
+ ];
+
+ if ($old_data == $new_data) {
+ Session::flash('info', 'Data must not be same');
+ Redirect::to("./$id");
+ die();
+ }
+
+ $keys = array_keys($args);
+ if ($matches = preg_grep('/^old_/', $keys)) {
+ foreach ($matches as $match) {
+ unset($args[$match]);
+ }
+ }
+
if ($this->post->update($table, $args, $id)) {
Session::flash('info', 'Data successfuly updated');
Redirect::to('/');
} else {
- Session::flash('info', 'Error');
+ Session::flash('info', 'Data cannot be uploaded');
Redirect::to("./$id");
}
}
diff --git a/App/Views/Data/edit_pengumuman.html b/App/Views/Data/edit_pengumuman.html
index acf9017..3b5063c 100644
--- a/App/Views/Data/edit_pengumuman.html
+++ b/App/Views/Data/edit_pengumuman.html
@@ -18,11 +18,13 @@
{% endfor %}
+
+
@@ -42,11 +44,13 @@
+
+