Huge updates:
1. Redesigned the web 2. Fixed logging in redirect issue 3. Added new route 4. Fixed sql issue on entry 5. Fixed typos
This commit is contained in:
@@ -25,7 +25,7 @@ class Posts
|
||||
|
||||
$valid = $this->model->showAll([
|
||||
['valid_at', '<=', $now],
|
||||
['status', '!=', 3]
|
||||
['status', '!=', 0]
|
||||
]);
|
||||
if ($valid) {
|
||||
foreach ($valid as $fields) {
|
||||
@@ -40,7 +40,7 @@ class Posts
|
||||
|
||||
$not_valid = $this->model->showAll([
|
||||
['valid_at', '>', $now],
|
||||
['status', '!=', 3]
|
||||
['status', '!=', 0]
|
||||
]);
|
||||
if ($not_valid) {
|
||||
foreach ($not_valid as $fields) {
|
||||
@@ -55,7 +55,7 @@ class Posts
|
||||
|
||||
$expired = $this->model->showAll([
|
||||
['expired_at', '<', $now],
|
||||
['status', '!=', 3]
|
||||
['status', '!=', 0]
|
||||
]);
|
||||
if ($expired) {
|
||||
foreach ($expired as $fields) {
|
||||
@@ -70,7 +70,7 @@ class Posts
|
||||
}
|
||||
|
||||
/* Routes */
|
||||
public function index()
|
||||
public function index($args = '')
|
||||
{
|
||||
$this->checkValid();
|
||||
|
||||
@@ -83,11 +83,16 @@ class Posts
|
||||
$url = 'Data/pengumuman.html';
|
||||
|
||||
$status = '';
|
||||
$privilage = '';
|
||||
$privilege = '';
|
||||
|
||||
if (Session::exists('userid')) {
|
||||
$post = $this->model->showAll();
|
||||
$privilage = Session::get('privilage');
|
||||
if ($args != '') {
|
||||
$post = $this->model->showAll([
|
||||
['status', '=', $args]
|
||||
]);
|
||||
}
|
||||
$privilege = Session::get('privilege');
|
||||
$status = 'loggedin';
|
||||
}
|
||||
|
||||
@@ -106,7 +111,8 @@ class Posts
|
||||
View::render($url, [
|
||||
'posts' => $posts,
|
||||
'status' => $status,
|
||||
'privilage' => $privilage
|
||||
'privilege' => $privilege,
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -204,7 +210,7 @@ class Posts
|
||||
public function category()
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
if (Session::get('privilage') != 1) {
|
||||
if (Session::get('privilege') != 1) {
|
||||
Session::flash('info', 'Hanya admin yang bisa mengatur kategori');
|
||||
Redirect::to('/');
|
||||
die();
|
||||
@@ -266,12 +272,13 @@ class Posts
|
||||
die();
|
||||
}
|
||||
|
||||
public function put($args = [])
|
||||
public function put($args)
|
||||
{
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
|
||||
$this->model->update(['status' => 1], $args['id'], $table);
|
||||
$this->model->update($args, $args['id'], $table);
|
||||
|
||||
Session::flash('info', 'Data berhasil diaktifkan');
|
||||
Redirect::to('/posts/category');
|
||||
@@ -285,32 +292,37 @@ class Posts
|
||||
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', 'Tidak ada data yang diubah');
|
||||
Redirect::to("./$id");
|
||||
die();
|
||||
}
|
||||
|
||||
$keys = array_keys($args);
|
||||
$old_data = [];
|
||||
|
||||
if ($matches = preg_grep('/^old_/', $keys)) {
|
||||
foreach ($matches as $match) {
|
||||
$old_data[] = $args[$match];
|
||||
unset($args[$match]);
|
||||
}
|
||||
$new_data = [
|
||||
$args['category'],
|
||||
$args['content'],
|
||||
$args['valid_at'],
|
||||
$args['expired_at']
|
||||
];
|
||||
if ($old_data == $new_data) {
|
||||
Session::flash('info', 'Tidak ada data yang diubah');
|
||||
Redirect::to("./$id");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($args as $key => $val) {
|
||||
if (strpos($val, "##date##") !== false) {
|
||||
$date = new \DateTime();
|
||||
$now = $date->format("Y-m-d");
|
||||
$args[$key] = $now;
|
||||
}
|
||||
}
|
||||
|
||||
var_dump($args);
|
||||
|
||||
if ($this->model->update($args, $id)) {
|
||||
Session::flash('info', 'Data berhasil diperbarui');
|
||||
Redirect::to('/');
|
||||
@@ -329,11 +341,12 @@ class Posts
|
||||
}
|
||||
|
||||
$id = $args['id'];
|
||||
unset($args['id']);
|
||||
|
||||
if ($table) {
|
||||
$delete = $this->model->delete($id, 0, $table);
|
||||
if (isset($table)) {
|
||||
$delete = $this->model->update($args, $id, $table);
|
||||
} else {
|
||||
$delete = $this->model->delete($id);
|
||||
$delete = $this->model->update($args, $id);
|
||||
}
|
||||
|
||||
if ($delete == true) {
|
||||
@@ -344,7 +357,7 @@ class Posts
|
||||
|
||||
Session::flash('info', $info);
|
||||
|
||||
if ($table) {
|
||||
if (isset($table)) {
|
||||
Redirect::to("/posts/category");
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
|
||||
Reference in New Issue
Block a user