if (($login->admin & ADMIN_NEWS) != ADMIN_NEWS) { $tpl->error(ERROR_NO_ACCESS); } $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'display'; $id = isset($_REQUEST['id']) ? $_REQUEST['id'] + 0 : 0; if ($action == 'display') { action_display(); } else { if ($action == 'hide') { action_hide($id); } else { if ($action == 'show') { action_show($id); } else { if ($action == 'delete') { action_delete($id); } } } } $tpl->redirect('newsapprove.php'); function action_display() { global $tpl; $rs = sql('SELECT `news`.`id` AS `id`, `news`.`date_created` AS `date_created`, `news`.`content` AS `content`, `news`.`display` AS `display`, `news_topics`.`name` AS `topic` FROM `news` INNER JOIN `news_topics` ON `news`.`topic`=`news_topics`.`id` ORDER BY `news`.`date_created` DESC'); $tpl->assign_rs('newsentries', $rs); sql_free_result($rs); $tpl->display();
return "刪除成功"; } function action_update($dbObj) { $id = $_GET['id']; $position = $_GET['position']; $sqlCmd = "UPDATE user_position_table SET name='{$position}' WHERE id='{$id}'"; if (($success = $dbObj->Execute($sqlCmd)) != true) { return "Execute SQL Command failed: ({$sqlCmd})"; } return "更新成功"; } $dbObj = DatabaseInstance::GetInstance(); if ($_GET) { $action = $_GET['action']; $ret = ""; switch ($action) { case "add": $ret = action_add($dbObj); break; case "delete": $ret = action_delete($dbObj); break; case "update": $ret = action_update($dbObj); break; default: $ret = "No such action"; } echo $ret; }
<?php require_once "../models/db.php"; require_once "../models/articles.php"; $link = db_connect(); $action = isset($_GET['action']) ? $_GET['action'] : ""; switch ($action) { case "add": action_add(); break; case "edit": action_edit(); break; case "delete": action_delete(); break; default: action_list(); } function action_add() { global $link; if (!empty($_POST)) { articles_new($link, $_POST['title'], $_POST['date'], $_POST['content']); header("Location: index.php"); } $article['title'] = ""; $article['content'] = ""; $article['date'] = ""; require "../views/article_admin.php"; }