Mithril as main method

This commit is contained in:
2017-10-25 12:08:41 +07:00
parent 6040809710
commit d1d5ee1b0c
157 changed files with 19593 additions and 716 deletions

View File

@@ -1,16 +1,8 @@
<?php
namespace App\Controllers;
use App\Models\ApiModel;
class Api
{
private $model;
public function __construct()
{
$this->model = new ApiModel();
}
public function index()
{
@@ -27,48 +19,47 @@ class Api
echo json_encode($index, JSON_UNESCAPED_SLASHES);
}
// public function posts($args = ['id' => '1'])
// {
// $get = [];
//
// if ($args['id'] == 3) {
// $get['data'] = $this->model->showJoin();
// } else {
// $get['data'] = $this->model->showJoin([
// ['pengumuman.status', '=', $args['id']]
// ]);
// }
//
// if ($get['data'] == false) {
// $get['data']['content'] = 'Tidak ada pengumuman';
// $get['data']['valid_at'] = '';
// $get['data']['expired_at'] = '';
// $get['data']['status'] = 0;
// $get['data']['background'] = '#333';
// $get['data']['foreground'] = '#888';
// }
//
// if (array_key_exists(0, $get['data']) == false) {
// $temp_data = $get['data'];
// unset($get['data']);
// $get['data'][] = $temp_data;
// $temp_data = [];
// }
//
// header('Content-Type: application/json');
// echo json_encode($get);
// }
public function get($table, $id = "")
public function get($table, $id = "", $args = [])
{
$get = [];
$get['data'] = $this->model->showAll(
($id == "") ? [] : [
['id', '=', $id]
], $table
);
$model = 'App\Models\ApiModel';
if ($table == 'pengumuman') {
$model = 'App\Models\Pengumuman';
}
if ($args == []) {
$get['data'] = $id == "" ? $model::showAll($table) : $model::fetch(
$table,
[
[$table.'.id', '=', $id]
]);
} else {
if ($args['status'] != 3) {
$get['data'] = $model::showAll($table, [
["$table.status", '=', $args['status']]
]);
} else {
$get['data'] = $model::showAll($table);
}
}
$get['count'] = count($get['data']);
if ($table == 'kategori') {
if (isset($get['data'][0])) {
for ($i=0; $i < count($get['data']); $i++) {
$get['data'][$i]['posts'] = count(\App\Models\Pengumuman::showAll('pengumuman', [
['pengumuman.status', '=', 1],
['pengumuman.category', '=', $get['data'][$i]['id']]
]));
}
} else {
$get['data']['posts'] = count(\App\Models\Pengumuman::showAll('pengumuman', [
['pengumuman.status', '=', 1],
['pengumuman.category', '=', $get['data']['id']]
]));
}
}
header('Content-Type: application/json');
echo json_encode($get);
}
@@ -80,8 +71,17 @@ class Api
$args = file_get_contents("php://input");
$args = json_decode($args, true);
$put['data'] = $this->model->update($table, $args);
$put['count'] = count($put['data']);
if (isset($args['posts'])) unset($args['posts']);
$update = \App\Models\ApiModel::update($table, $args);
if (!is_array($update)) {
$put['status'] = false;
$put['message'] = $update;
} else {
$put['status'] = true;
$put['data'] = $update;
$put['count'] = count($put['data']);
}
header('Content-Type: application/json');
echo json_encode($put);
@@ -93,11 +93,18 @@ class Api
$args = file_get_contents("php://input");
$args = json_decode($args, true);
$post['data'] = $this->model->entry($table, $args);
$post['data'] = $this->model->showAll([
['id', '=', $post['data'][0]]
], $table);
$post['count'] = count($post['data']);
$entry = \App\Models\ApiModel::entry($table, $args);
$entry = \App\Models\ApiModel::showAll($table, [
['id', '=', $entry[0]]
]);
if (!is_array($entry)) {
$post['status'] = false;
$post['message'] = $entry;
} else {
$post['status'] = true;
$post['data'] = $entry;
$post['count'] = count($post['data']);
}
header('Content-Type: application/json');
echo json_encode($post);
@@ -109,8 +116,15 @@ class Api
$args = file_get_contents("php://input");
$args = json_decode($args, true);
$delete['data'] = $this->model->remove($table, $args['id']);
$delete['count'] = count($delete['data']);
$remove = \App\Models\ApiModel::remove($table, $args['id']);
if (!is_array($delete['data'])) {
$delete['status'] = false;
$delete['messsage'] = $remove;
} else {
$delete['status'] = true;
$delete['data'] = $remove;
$delete['count'] = count($delete['data']);
}
header('Content-Type: application/json');
echo json_encode($delete);

View File

@@ -3,20 +3,23 @@ namespace App\Controllers;
use Core\View;
use App\Models\Access;
use App\Models\ClientSession;
use Core\Token;
use Core\Session;
use Core\Redirect;
use Core\Hash;
use Core\XSS;
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;
class Home
{
public $model;
public function __construct()
{
$this->model = new Access();
}
// public $model;
//
// public function __construct()
// {
// $this->model = new Access();
// }
/* Routes */
public function index()
@@ -27,14 +30,16 @@ class Home
public function login($args = [])
{
if (Session::exists('userid')) {
Session::flash('info', 'Anda telah masuk');
Redirect::to('/');
die();
}
// if (Session::exists('userid')) {
// Session::flash('info', 'Anda telah masuk');
// Redirect::to('/');
// die();
// }
// Login
if ($args) {
$logged_in = ['status' => false];
// Avoid XSS
$args['exclude'] = [
'password'
@@ -44,31 +49,44 @@ class Home
$username = $args['username'];
$password = $args['password'];
$user = $this->model->showAll([
['username', '=', $username]
$user = Access::showAll([
['username', '=', $username],
['flag', '=', 0]
]);
if ($user == false) {
$info = "Username/password salah";
$logged_in['status'] = $info;
} else {
$hash = Hash::compare($password, $user['salt'], $user['password']);
if ($hash == true) {
if ($user['max_user'] <= 0) {
$info = "Telah mencapai maksimal user yang diizinkan - Silahkan logout pada perangkat lain terlebih dahulu";
if ($user['flag'] != 0) {
$info = "User telah login";
} else {
$max_user = $user['max_user'] - 1;
if ($this->model->update(['max_user' => $max_user], $user['id']) == true) {
Session::put('userid', $user['id']);
Session::put('username', $user['username']);
Session::put('full_name', $user['full_name']);
Session::put('privilege', $user['privilege']);
if (Access::update(['flag' => 1], $user['id'])) {
$ip_address = isset($_SERVER['HTTP_X_FORWADED_FOR']) ? $_SERVER['HTTP_X_FORWADED_FOR'] : $_SERVER['REMOTE_ADDR'];
ClientSession::entry([
'ip_address' => $ip_address,
'uid' => $user['id']
]);
$session = ClientSession::fetch(['uid' => $user['id']]);
setcookie('signal', $user['privilege']);
$info = "Berhasil masuk";
$logged_in['status'] = true;
$logged_in['redirect_to'] = '/?s='.$session['id']."&u=".$session['uid'];
}
}
} else {
$info = "Username/password salah";
$logged_in['status'] = $info;
}
}
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($logged_in); die();
}
Session::flash('info', $info);
Redirect::to('/');
die();
@@ -79,16 +97,27 @@ class Home
}
}
public function logout() {
if ($this->delete() != true) {
$info = "Terjadi kesalahan. Silahkan coba lagi dalam beberapa saat";
} else {
Session::delete('userid');
Session::delete('username');
Session::delete('full_name');
Session::delete('privilege');
public function logout($id = '') {
$logged_out = ['status' => false];
try {
if ($id) {
$this->delete($id);
} else {
$this->delete();
}
session_destroy();
header('X-Token: ');
setcookie('signal', '', time()-3600);
$info = "Berhasil keluar";
$logged_out['status'] = true;
$logged_out['redirect_to'] = '/';
} catch (\Exception $e) {
$logged_out['status'] = $e->getMessage();
}
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($logged_out);die();
}
Session::flash('info', $info);
Redirect::to('/');
@@ -108,9 +137,16 @@ class Home
/* Methods */
public function post($args = [])
{
$registered = [];
foreach ($args as $value) {
if ($value == '') {
Session::flash('info', 'Semua data harus diisi');
$info = 'Semua data harus diisi';
$registered['status'] = 'false';
$registered['message'] = $info;
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($registered);die();
}
Session::flash('info', $info);
Redirect::to('./register');
die();
}
@@ -133,7 +169,7 @@ class Home
];
$args = XSS::avoid($args);
$data = $this->model->showAll();
$data = Access::showAll();
foreach ($data as $users) {
if (is_array($users)) {
$known_uname = $users['username'];
@@ -141,38 +177,71 @@ class Home
$known_uname = $data['username'];
}
if ($args['username'] == $known_uname) {
Session::flash('info', 'Username telah digunakan. Silahkan gunakan username lain');
$info = 'Username telah digunakan. Silahkan gunakan username lain';
$registered['status'] = false;
$registered['message'] = $info;
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($registered);die();
}
Session::flash('info', $info);
Redirect::to('./register');
die();
}
}
$this->model->entry($args);
Access::entry($args);
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode([
'status' => true,
'route_to' => ''
]);die();
}
Session::flash('info', 'Registrasi berhasil');
Redirect::to('/');
die();
}
public function delete()
public function delete($id = '')
{
if (Session::exists('userid') == false) {
throw new \Exception("Bad request but thrown as 404", 404);
}
$userid = Session::get('userid');
// if (Session::exists('userid') == false) {
// throw new \Exception("Bad request but thrown as 404", 404);
// }
// $client = ClientSession::fetch([
//
// ])
// $userid = Session::get('userid');
//
// $user = Access::showAll([
// ['id', '=', $userid]
// ]);
// $max_user = $user['max_user'] + 1;
//
// if (Access::update(
// [
// 'max_user' => $max_user
// ],
// $userid
// ) != true) {
// throw new \Exception("Bad request", 400);
// }
// return true;
$user = $this->model->showAll([
['id', '=', $userid]
]);
$max_user = $user['max_user'] + 1;
if ($this->model->update(
[
'max_user' => $max_user
],
$userid
) != true) {
throw new \Exception("Bad request", 400);
if ($id) {
$uid = $id;
} elseif (isset($_SERVER['HTTP_X_TOKEN'])) {
$token = Token::fetch($_SERVER['HTTP_X_TOKEN']);
if ($token == '') {
throw new \Exception("Token invalid");
}
$uid = $token['uid'];
} elseif (isset($_SERVER['HTTP_X_QUERY'])) {
$query_string = $_SERVER['HTTP_X_QUERY'];
$exploded = explode('&', $query_string);
$uid = $exploded[1];
}
ClientSession::remove($uid);
Access::update(['flag' => 0], $uid);
return true;
}
@@ -186,7 +255,7 @@ class Home
} else {
$user = false;
}
View::render('Data/mithril.html', [
'user' => $user
]);

View File

@@ -124,8 +124,7 @@ class Posts
View::render($url, [
'posts' => $datas,
'user' => $user,
'token' => Token::generate()
'user' => $user
]);
}
@@ -263,8 +262,26 @@ class Posts
}
/* Methods */
public function post($args = [])
public function post($args)
{
$post = [];
if ($args == [] || count($args) < 4) {
$post['status'] = false;
$post['message'] = 'Semua data harus diisi ya broo';
$post['data'] = $args;
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($post);
die();
}
Session::flash('info', 'Semua data harus diisi');
if (isset($table)) {
Redirect::to("/posts/category");
} else {
Redirect::to('/posts/entry');
}
die();
}
if (isset($args['_addon'])) {
$table = $args['_addon'];
unset($args['_addon']);
@@ -272,6 +289,12 @@ class Posts
foreach ($args as $value) {
if ($value == '') {
$post['status'] = false;
$post['message'] = 'Semua data harus diisi';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($post);
die();
}
Session::flash('info', 'Semua data harus diisi');
if (isset($table)) {
Redirect::to("/posts/category");
@@ -282,6 +305,12 @@ class Posts
}
}
$query_string = $_SERVER['HTTP_X_QUERY'];
$exploded = explode('&', $query_string);
$args['creator'] = substr_replace($exploded[1], '', 0, 2);
$args['created_at'] = date('Y-m-d H:i:s');
$args['edited_at'] = $args['created_at'];
// Avoid XSS attack
$args = XSS::avoid($args);
@@ -297,16 +326,27 @@ class Posts
$length = strlen($args['content']);
$args['delay'] = $length * 84;
if ($this->model->entry($args)) {
Session::flash('info', 'Data berhasil diunggah');
Redirect::to('/');
try {
$this->model->entry($args);
} catch (Exception $e) {
$post['message'] = $e->getMessage();
}
$post['status'] = true;
$post['route_to'] = '';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($post);
die();
}
Session::flash('info', 'Data berhasil diunggah');
Redirect::to('/');
}
die();
}
public function put($args)
{
$update = [];
if (isset($args['_addon'])) {
$table = $args['_addon'];
unset($args['_addon']);
@@ -318,6 +358,11 @@ class Posts
die();
}
if (isset($args['categoryName'])) { unset($args['categoryName']); }
if (isset($args['creatorName'])) { unset($args['creatorName']); }
if (isset($args['background'])) { unset($args['background']); }
if (isset($args['foreground'])) { unset($args['foreground']); }
// Avoid XSS attack
$args = XSS::avoid($args);
@@ -361,6 +406,12 @@ class Posts
$args['delay'] = $length * 84;
if ($this->model->update($args, $id)) {
$update['status'] = true;
$update['route_to'] = '';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($update);
die();
}
Session::flash('info', 'Data berhasil diperbarui');
Redirect::to('/');
} else {

View File

@@ -1,56 +1,26 @@
<?php
namespace App\Models;
class Access extends \Core\Model
use App\Config;
class Access
{
public function __construct()
private static $conn;
private static function connectDB()
{
$this->createTable(
[
'id int(3) NOT NULL AUTO_INCREMENT',
'username varchar(25) NOT NULL',
'password char(13) NOT NULL',
'salt char(23) NOT NULL',
'full_name varchar(50) NOT NULL',
'registered_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
'privilege tinyint(1) NOT NULL DEFAULT 0',
'max_user int(1) NOT NULL DEFAULT 5',
'PRIMARY KEY (id)'
]
);
}
protected function createTable($fields, $table = 'users') {
try {
if ($fields == []) {
return false;
if (!self::$conn) {
$dsn = 'mysql:host='.Config::DB_HOST.';dbname='.Config::DB_DB;
self::$conn = new \PDO($dsn, Config::DB_UNAME, Config::DB_PWD);
self::$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
$sql = "CREATE TABLE IF NOT EXISTS {$table} (".implode(',', $fields).") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$db = static::connectDB();
$query = $db->prepare($sql);
$query->execute();
return true;
return self::$conn;
} catch (PDOException $e) {
throw new \Exception($e->getMessage(), 444);
throw new \Exception($e->getMessage, 444);
}
}
protected function dropTable($table = 'users') {
try {
$sql = "DROP TABLE IF EXISTS {$table}";
$db = static::connectDB();
$query = $db->prepare($sql);
$query->execute();
return true;
} catch (PDOException $e) {
throw new \Exception($e->getMessage(), 444);
}
}
public function showAll($conditions = [], $table = 'users')
public static function showAll($conditions = [], $table = 'users')
{
try {
$db = static::connectDB();
@@ -100,7 +70,7 @@ class Access extends \Core\Model
}
}
public function entry($args, $table = 'users')
public static function entry($args, $table = 'users')
{
if (count($args)) {
$keys = '`'.implode('`, `', array_keys($args)).'`';
@@ -168,7 +138,7 @@ class Access extends \Core\Model
return false;
}
public function update($args, $id, $table = 'users')
public static function update($args, $id, $table = 'users')
{
if (count($args)) {
$keys = array_keys($args);
@@ -187,7 +157,7 @@ class Access extends \Core\Model
try {
$db = static::connectDB();
$result = $this->showAll([
$result = self::showAll([
['id', '=', $id]
]);
@@ -210,16 +180,15 @@ class Access extends \Core\Model
return false;
}
public function delete($id, $status, $table = 'users')
public static function delete($id)
{
try {
$db = static::connectDB();
$sql = "UPDATE {$table} SET status = ? WHERE id = ?";
$sql = "UPDATE `users` SET `flag` = 0 WHERE id = ?";
$query = $db->prepare($sql);
$query->bindValue(1, $status);
$query->bindValue(2, $id);
$query->bindValue(1, $id);
$query->execute();
return true;

View File

@@ -22,7 +22,49 @@ class ApiModel
}
}
public function showAll($conditions = [], $table)
public static function fetch($table, $conditions = [])
{
$sql = "SELECT * FROM {$table}";
if ($conditions) {
$sql .= " WHERE";
foreach ($conditions as $condition) {
$keys[] = $condition[0];
$operators[] = $condition[1];
$values[] = $condition[2];
}
$x = 0;
foreach ($keys as $key) {
$sql .= " $key $operators[$x] ?";
$x++;
if ($x < count($keys)) {
$sql .= " AND";
}
}
}
try {
$con = static::connectDB();
$query = $con->prepare($sql);
if (count($conditions)) {
$x = 1;
foreach ($values as $value) {
$query->bindValue($x, $value);
$x++;
}
}
$query->execute();
return $query->fetch(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}
}
public static function showAll($table, $conditions = [])
{
$sql = "SELECT * FROM {$table}";
@@ -64,7 +106,7 @@ class ApiModel
}
}
public function update($table, $args)
public static function update($table, $args)
{
$sql = "UPDATE {$table} SET";
@@ -96,15 +138,15 @@ class ApiModel
$query->execute();
return $this->showAll([
return self::showAll($table, [
['id', '=', $id]
], $table);
]);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}
}
public function entry($table, $args)
public static function entry($table, $args)
{
$sql = "INSERT INTO {$table}";
@@ -141,7 +183,7 @@ class ApiModel
}
}
public function remove($table, $id)
public static function remove($table, $id)
{
$sql = "UPDATE {$table} SET `status` = 0 WHERE `id` = ?";
try {
@@ -151,7 +193,9 @@ class ApiModel
$query->bindValue(1, $id);
$query->execute();
return true;
return self::showAll($table, [
['id', '=', $id]
]);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}

View File

@@ -0,0 +1,94 @@
<?php
namespace App\Models;
use App\Config;
class ClientSession
{
protected static $conn = null;
protected static function connectDB()
{
try {
if (!self::$conn) {
$dsn = 'mysql:host='.Config::DB_HOST.';dbname='.Config::DB_DB;
self::$conn = new \PDO($dsn, Config::DB_UNAME, Config::DB_PWD);
self::$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
return self::$conn;
} catch (PDOException $e) {
throw new \Exception($e->getMessage, 444);
}
}
public static function fetch($args)
{
$sql = "SELECT * FROM `client_session` WHERE ";
$x = 0;
foreach ($args as $key => $value) {
$sql .= "$key=?";
if ($x < count($args)-1) {
$sql .= " AND ";
}
$x++;
}
try {
$db = static::connectDB();
$query = $db->prepare($sql);
$x = 1;
foreach ($args as $value) {
$query->bindValue($x, $value);
$x++;
}
$query->execute();
$result = $query->fetch(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$result = $e->getMessage();
}
return $result;
}
public static function entry($args)
{
$sql = "INSERT INTO `client_session` (`ip_address`, `uid`) VALUES (?, ?)";
try {
$db = static::connectDB();
$query = $db->prepare($sql);
$query->bindValue(1, $args['ip_address']);
$query->bindValue(2, $args['uid']);
$query->execute();
$last_entry = "SELECT LAST_INSERT_ID()";
$last_entry = $db->prepare($last_entry);
$last_entry->execute();
$result = $last_entry->fetch(\PDO::FETCH_ASSOC);
return true;
} catch (PDOException $e) {
$result = $e->getMessage();
}
return $result;
}
public static function remove($id)
{
$sql = "DELETE FROM `client_session` WHERE `uid` = ?";
try {
$db = static::connectDB();
$query = $db->prepare($sql);
$query->bindValue(1, $id);
$query->execute();
$result = self::fetch(['uid' => $id]);
} catch (PDOException $e) {
$result = $e->getMessage();
}
return $result;
}
}

117
App/Models/Pengumuman.php Normal file
View File

@@ -0,0 +1,117 @@
<?php
namespace App\Models;
use App\Config;
class Pengumuman
{
protected static $conn = null;
protected static function connectDB()
{
try {
if (!self::$conn) {
$dsn = 'mysql:host='.Config::DB_HOST.';dbname='.Config::DB_DB;
self::$conn = new \PDO($dsn, Config::DB_UNAME, Config::DB_PWD);
self::$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
return self::$conn;
} catch (PDOException $e) {
throw new \Exception($e->getMessage, 444);
}
}
public static function fetch($table, $conditions = [])
{
$sql = "SELECT
pengumuman.id, pengumuman.category as category,
kategori.category as categoryName, kategori.background as background, kategori.foreground as foreground,
pengumuman.created_at, pengumuman.valid_at, pengumuman.expired_at, pengumuman.creator, pengumuman.edited_at, pengumuman.content, pengumuman.status, pengumuman.delay
FROM pengumuman INNER JOIN kategori ON pengumuman.category = kategori.id";
if ($conditions) {
$sql .= " WHERE";
foreach ($conditions as $condition) {
$keys[] = $condition[0];
$operators[] = $condition[1];
$values[] = $condition[2];
}
$x = 0;
foreach ($keys as $key) {
$sql .= " $key $operators[$x] ?";
$x++;
if ($x < count($keys)) {
$sql .= " AND";
}
}
}
try {
$con = static::connectDB();
$query = $con->prepare($sql);
if (count($conditions)) {
$x = 1;
foreach ($values as $value) {
$query->bindValue($x, $value);
$x++;
}
}
$query->execute();
return $query->fetch(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}
}
public static function showAll($table, $conditions = [])
{
$sql = "SELECT
pengumuman.id, pengumuman.category as category,
kategori.background as background, kategori.foreground as foreground,
created_at, valid_at, expired_at, creator, edited_at, content, pengumuman.status, delay,
users.full_name as creatorName
FROM pengumuman INNER JOIN kategori ON pengumuman.category = kategori.id INNER JOIN users ON pengumuman.creator = users.id";
if ($conditions) {
$sql .= " WHERE";
foreach ($conditions as $condition) {
$keys[] = $condition[0];
$operators[] = $condition[1];
$values[] = $condition[2];
}
$x = 0;
foreach ($keys as $key) {
$sql .= " $key $operators[$x] ?";
$x++;
if ($x < count($keys)) {
$sql .= " AND";
}
}
}
try {
$con = static::connectDB();
$query = $con->prepare($sql);
if (count($conditions)) {
$x = 1;
foreach ($values as $value) {
$query->bindValue($x, $value);
$x++;
}
}
$query->execute();
return $query->fetchAll(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}
}
}

View File

@@ -174,12 +174,12 @@ class Post extends \Core\Model
$values = '';
// This is if want to insert multiple rows
foreach ($args as $key => $val) {
if (preg_match('/,/', $val)) {
$val = explode(',', $val);
$args[$key] = $val;
}
}
// foreach ($args as $key => $val) {
// if (preg_match('/,/', $val)) {
// $val = explode(',', $val);
// $args[$key] = $val;
// }
// }
$x = 1;
foreach ($args as $field) {
@@ -198,6 +198,7 @@ class Post extends \Core\Model
try {
$sql = "INSERT INTO {$table} ({$keys}) VALUES {$values}";
$db = static::connectDB();
$query = $db->prepare($sql);
@@ -214,6 +215,8 @@ class Post extends \Core\Model
$x++;
}
}
// var_dump($x);die();
$query->execute();
return true;

View File

@@ -18,7 +18,7 @@
<br>
<label for="expired_at">Berlaku dari: </label>
<label for="valid_at">Berlaku dari: </label>
<input id="left" name="valid_at" value="{{ timestamp }}">
<br>

View File

@@ -86,9 +86,9 @@
{% if cat.status == 1 %}
<i class="fa fa-times-circle-o fa-fw"></i>
<span class="font-size:smaller;">Matikan</span>
<span style="font-size:smaller;">Matikan</span>
{% elseif cat.status == 0 %}
<i class="fa fa-check fa-fw"></i>
<i style="fa fa-check fa-fw"></i>
<span class="font-size:smaller;">Aktifkan</span>
{% endif %}

View File

@@ -1,34 +1,3 @@
{% extends "base.html" %}
{% extends "legacy.html" %}
{% block title %}Mithril{% endblock %}
{% block nav %}
<input type="checkbox" id="bmenug" class="show">
<label for="bmenug" class="burger pseudo button"><i class="fa fa-bars" aria-hidden="true"></i></label>
<div class="menu">
{% if user.privilege != "" %}
{% if user.privilege == 1 %}
<a href="/posts/category" class="navy button" data-tooltip="Kategori"><i class="fa fa-list-ul" aria-hidden="true"></i>&nbsp;Kategori</a>
<a href="/register" class="navy button" data-tooltip="User Baru"><i class="fa fa-user-plus" aria-hidden="true"></i>&nbsp;User</a>
{% endif %}
<a href="/logout" class="navy button" data-tooltip="Keluar"><i class="fa fa-sign-out" aria-hidden="true"></i>&nbsp;Keluar</a>
{% else %}
<a href="/login" class="navy hidden-hover button" data-tooltip="Masuk">
<i class="fa fa-sign-in" aria-hidden="true"></i>&nbsp;Masuk
</a>
{% endif %}
</div>
{% endblock %}
{% block body %}
<main class="documentation">
<div id="nouser" style="text-align:left;width:100%;">
<div style="background:#fff;text-align:left;width:100%;padding:10vh 0 0;">
<div id='navigasi'>
</div>
<div id="mit">
</div>
</div>
</div>
</main>
{% endblock %}

View File

@@ -6,6 +6,7 @@
<input type="checkbox" id="bmenug" class="show">
<label for="bmenug" class="burger pseudo button"><i class="fa fa-bars" aria-hidden="true"></i></label>
<div class="menu">
<a href="https://backup.lepisi.ac.id/gregorio/lepisi-pengumuman/blob/master/README.md#dokumentasi" class="navy button" data-tooltip="Dokumentasi"><i class="fa fa-dot-circle-o" aria-hidden="true"></i></a>
{% if user.privilege != "" %}
{% if user.privilege == 1 %}
<a href="/posts/category" class="navy button" data-tooltip="Kategori"><i class="fa fa-list-ul" aria-hidden="true"></i>&nbsp;Kategori</a>
@@ -125,9 +126,6 @@
{% endif %}
</div>
</main>
<footer class="cp">
Copyright 2017. Perguruan Tinggi Lepisi. Bingung? Lihat <a href="https://backup.lepisi.ac.id/gregorio/lepisi-pengumuman/blob/master/README.md#dokumentasi" target="_blank">dokumentasi</a>.
</footer>
<script>
if (document.getElementById('slidr-div')) {
slidr.create('slidr-div', {

View File

@@ -7,195 +7,8 @@
<link rel="stylesheet" href="/css/picnic.min.css">
<link rel="stylesheet" href="/css/rome.css">
<link rel="stylesheet" href="/css/simplemde.min.css">
<link rel="stylesheet" href="/css/index.css">
<title>{% block title %}{% endblock %}</title>
<style>
@font-face {
font-family: 'Lobster';
font-style: normal;
font-weight: 400;
src: local('Lobster'), local('Lobster-Regular'), url(/font/Lobster.woff) format('woff');
}
.documentation > section {
background: #fff;
text-align: left;
width: 90%;
max-width: 960px;
margin: 0 auto;
padding: 80px 0 0;
}
.flex>* {
padding-right: .6em;
}
.flex>h1, .flex>span {
padding: 0;
}
nav.transparent {
box-shadow: none;
background: none;
}
.pseudo.button {
background: transparent;
color: #111;
}
.shyButton {
font-size: .75em;
}
.shyFont {
font-size: .65em;
}
.top {
z-index: 10001;
}
td, th {
padding: .3em .45em .3em .6em;
}
.fitty {
display: inline-block;
white-space: normal;
line-height: 1em;
padding-bottom: .1em;
text-align: center;
}
#slidr-div p,
.fitty p {
margin: 0;
text-align: center;
line-height: 1;
}
@media screen and (orientation: landscape) {
#slidr-div p,
.fitty p {
font-size: 8vw;
}
}
@media screen and (orientation: portrait) {
#slidr-div p,
.fitty p {
font-size: 10vh;
}
}
.title {
font-family: 'Lobster', cursive;
font-size: x-large;
}
nav .menu>.navy {
color: #000;
background-color: transparent;
margin-right: 2.5em;
}
nav .menu>.navy:hover {
background-color: rgba(17, 17, 17, .15);
}
.navy:hover, .title:hover {
color: rgba(17, 17, 17, .3);
}
.hidden-hover {
opacity: 0;
}
.hidden-hover:hover {
opacity: 1;
}
.filter a {
text-align: center;
}
.card footer {
position: absolute;
bottom: 0;
padding-left: 0;
padding-bottom: 0;
}
.card-wrapper {
margin: 0 auto;
}
.box {
padding: 1em;
background-color: rgba(17, 17, 17, .1);
border: none;
height: 17em;
width: 17em;
margin: .6em auto;
}
.new i {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
.box:hover {
background-color: rgba(17, 17, 17, .05);
}
nav {
max-width: 100vw;
}
.pengumuman {
width: 100%;
}
#info span {
width: 98%;
padding: .7em 0;
margin: 0;
}
nav a {
color: inherit;
}
.filter > div {
text-align: center;
}
.rd-month button {
color: #000;
}
.rd-container {
z-index: 5;
}
h1 {
padding: .2em 0;
}
.cp {
width: 100%;
font-size: small;
text-align: center;
position: fixed;
bottom: 0;
padding: .3em;
}
.swiper-container {
height: 100vh;
}
</style>
</head>
<body>
<nav>
@@ -204,15 +17,7 @@
</span>
{% block nav %}{% endblock %}
</nav>
{% block body %}
{% endblock %}
{% if user %}
<script src="/js/index.js"></script>
{% else %}
<script src="/js/landing.js"></script>
{% endif %}
{% block body %}{% endblock %}
<script>
function fadeOutEffect() {

32
App/Views/legacy.html Normal file
View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/picnic.min.css">
<link rel="stylesheet" href="/css/rome.css">
<link rel="stylesheet" href="/css/simplemde.min.css">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<script src="/js/landing.js"></script>
<script>
function fadeOutEffect() {
var fadeTarget = document.getElementById("info");
var fadeEffect = setInterval(function () {
if (!fadeTarget.style.opacity) {
fadeTarget.style.opacity = 1;
}
if (fadeTarget.style.opacity < 0.1) {
clearInterval(fadeEffect);
fadeTarget.remove();
} else {
fadeTarget.style.opacity -= 0.1;
}
}, 50);
}
</script>
</body>
</html>