public function route($url = "index") { $url = explode('/', $url); $user = new \Turner\System\User(); if (is_null($user::getID())) { if (isset($_POST['username']) && isset($_POST['password'])) { // Kalau dia mau login $user->loadSession($_POST['username'], $_POST['password']); // cobalah untuk membuat session tersedia } else { if (empty($_POST) && $url[0] != 'login') { // Jika ternyata yang diakses bukanlah halaman login header('Location: ' . \Turner\System\App::$information['serverAddr'] . '/login'); } else { if ($url[0] == 'login') { // Jika sudah ada di login include 'magician/login.php'; } } } // tulis isi login.php return true; } else { if (class_exists('\\Turner\\Helper\\' . $url[0]) && count($url) > 0) { if (!isset($url[1]) || $url[1] == "") { $url[1] = 'index'; } $url[0] = "\\Turner\\Helper\\" . $url[0]; $url[1] = strtolower($url[1]) . "Function"; if (method_exists($url[0], $url[1]) && is_callable([$url[0], $url[1]])) { $calledClass = new $url[0](); call_user_func_array([$calledClass, $url[1]], array_slice($url, 2)); return true; /* catch (\Exception $e) { // error_log($e); return false; } */ } } else { if ($url[0] == "logout") { \Turner\System\User::clearsessionFunction(); return true; } else { foreach (self::$singlePage as $link => $directTo) { if (strcmp(strtolower($url[0]), strtolower($link)) == 0) { \Turner\System\App::render($directTo); return true; } } } } } include 'magician/Error.php'; http_response_code(404); }
public static function indexFunction() { if (!isset(self::access()[User::getRole()])) { // Tidak dapat memanggil prosedur di bawah ini dengan error HP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.'. Jika ada yang dapat menjalankan query di bawah ini, tolong beritahu saya. // $cat = Database::execQuery("CALL categoryTree(0)"); App::render('magician/category/index.php', ['category' => $cat]); } else { // Jika bukan admin atau editor include "magician/Error.php"; } }
public static function editFunction($slug = false) { $category = []; $post = []; if (!is_bool($slug)) { $post = Database::execQuery("SELECT id, title, content, comment_status, post_status FROM post WHERE slug = '" . htmlspecialchars($slug, ENT_QUOTES) . "'", \PDO::FETCH_ASSOC); } if (is_bool($post) || count($post) <= 0 || count($post) <= 0) { include 'magician/Error.php'; return; } foreach (Database::execQuery("SELECT id, name, parent_id " . (count($post) > 0 ? ", EXISTS(SELECT category_id from post_category WHERE post_id = " . $post[0]['id'] . " AND category_id = category.id) as 'Selected'" : "") . "FROM category ORDER BY parent_id asc", \PDO::FETCH_ASSOC) as $data) { $category[$data['id']] = $data; if (intval($data['parent_id']) !== 0) { $category[$data['parent_id']]['childCategory'][] = $data['id']; } } App::render('magician/post/edit.php', ['data' => $post[0], 'slug' => $slug, 'category' => $category]); }