require_once '../../session.php'; // 管理者ページへのリダイレクト関数 function redirect_admin_page() { header('HTTP/1.1 303 See Other'); header('Location: ./'); exit; } // ログイン済みの場合は管理者ページへ if (isset($_SESSION['login']) && $_SESSION['login']) { redirect_admin_page(); } // Smarty読み込み&準備 require_once '../../setup.php'; $smarty = new Smarty_Assignment('Assignment | ログイン'); $smarty->assign('error_message', ''); // HTTPメソッドがGETの場合や、パラメーターが不足している場合は、ログイン画面を表示 if ($_SERVER['REQUEST_METHOD'] != 'POST' || !isset($_POST['user_id']) || !isset($_POST['password'])) { $smarty->displayBase('admin/login.tpl'); exit; } require_once '../../db.php'; $db = null; try { $db = new Assigment_DB(); } catch (PDOException $e) { // echo 'PDOException: ' . $e->getMessage(); header("HTTP/1.1 500 Internal Server Error"); $smarty->displayBase('server_error.tpl'); exit; }
<?php require_once '../../session.php'; require_once 'is_login.php'; // Smarty読み込み&準備 require_once '../../setup.php'; $smarty = new Smarty_Assignment('Assignment | 記事編集'); $smarty->assign('is_new', false); $smarty->assign('error_message', ''); $smarty->assign('error_title', ''); $smarty->assign('error_content', ''); $smarty->assign('error_publication_date', ''); $smarty->assign('error_publication_time', ''); require_once '../../db.php'; $db = null; try { $db = new Assigment_DB(); } catch (PDOException $e) { // echo 'PDOException: ' . $e->getMessage(); header("HTTP/1.1 500 Internal Server Error"); $smarty->displayBase('server_error.tpl'); exit; } // HTTPメソッドがPOST以外の場合は編集画面表示 if ($_SERVER['REQUEST_METHOD'] != 'POST') { $article = null; if (isset($_GET['id'])) { $smarty->assign('article_id', $_GET['id']); // 記事取得 $article = $db->get_one_article($_GET['id']); }
try { $db = new Assigment_DB(); } catch (PDOException $e) { // echo 'PDOException: ' . $e->getMessage(); header("HTTP/1.1 500 Internal Server Error"); $smarty->displayBase('server_error.tpl'); exit; } if ($_SERVER['REQUEST_METHOD'] != 'POST') { if (!isset($_GET['id'])) { header('HTTP/1.1 303 See Other'); header('Location ./'); exit; } $comments = $db->get_comments_by_article_id($_GET['id']); $tmp_comments = array(); foreach ($comments as $comment) { $created_at_unixtimestamp = strtotime($comment['created_at']); $comment['created_at_date'] = date('Y/m/d', $created_at_unixtimestamp); $comment['created_at_time'] = date('H:i:s', $created_at_unixtimestamp); $tmp_comments[] = $comment; } $smarty->assign('comments', $tmp_comments); $smarty->displayBase('admin/delete_comment.tpl'); exit; } if (isset($_POST['comment_id']) && $_POST['comment_id'] != '') { $db->delete_comment($_POST['comment_id']); } header('HTTP/1.1 303 See Other'); header('Location: ./delete_comment.php?id=' . $_GET['id']);
if (!isset($_GET['id']) || $_GET['id'] == '') { header('HTTP/1.1 303 See Other'); header('Location: ./'); exit; } require_once '../db.php'; $db = null; try { $db = new Assigment_DB(); } catch (PDOException $e) { // echo 'PDOException: ' . $e->getMessage(); header("HTTP/1.1 500 Internal Server Error"); $smarty->displayBase('server_error.tpl'); exit; } $article = $db->get_one_article($_GET['id']); $publication_unixtimestamp = strtotime($article['publication_datetime']); $article['publication_date'] = date('Y/m/d', $publication_unixtimestamp); $article['publication_time'] = date('H:i', $publication_unixtimestamp); $smarty->assign('article', $article); $smarty->assign('title', 'Assignment | ' . $article['title']); $comments = $db->get_comments_by_article_id($_GET['id']); $tmp_comments = array(); foreach ($comments as $comment) { $created_at_unixtimestamp = strtotime($comment['created_at']); $comment['created_at_date'] = date('Y/m/d', $created_at_unixtimestamp); $comment['created_at_time'] = date('H:i:s', $created_at_unixtimestamp); $tmp_comments[] = $comment; } $smarty->assign('comments', $tmp_comments); $smarty->displayBase('detail_article.tpl');
<?php require_once '../../session.php'; require_once 'is_login.php'; // Smarty読み込み&準備 require_once '../../setup.php'; $smarty = new Smarty_Assignment('Assignment | 新規作成'); $smarty->assign('is_new', true); $smarty->assign('error_message', ''); $smarty->assign('error_title', ''); $smarty->assign('error_content', ''); $smarty->assign('error_publication_date', ''); $smarty->assign('error_publication_time', ''); $smarty->assign('article_title', ''); $smarty->assign('article_content', ''); $smarty->assign('publication_date', date('Y/m/d')); $smarty->assign('publication_time', date('H:i')); // HTTPメソッドがPOST以外の場合は投稿画面表示 if ($_SERVER['REQUEST_METHOD'] != 'POST') { $smarty->displayBase('admin/edit_article.tpl'); exit; } // パラーメーターをチェックして、不備があればエラーメッセージを表示 $is_exist_error = false; if (!isset($_POST['title']) || $_POST['title'] === '') { $is_exist_error = true; $smarty->assign('error_title', '入力されていません'); } else { $smarty->assign('article_title', $_POST['title']); } if (!isset($_POST['content']) || $_POST['content'] === '') {
<?php require_once '../../session.php'; require_once 'is_login.php'; // Smarty読み込み&準備 require_once '../../setup.php'; $smarty = new Smarty_Assignment('Assignment | 管理者ページ'); require_once '../../db.php'; $db = null; try { $db = new Assigment_DB(); } catch (PDOException $e) { // echo 'PDOException: ' . $e->getMessage(); header("HTTP/1.1 500 Internal Server Error"); $smarty->displayBase('server_error.tpl'); exit; } // 記事一覧取得 $articles = $db->get_all_article_for_admin(); $tmp_articles = array(); foreach ($articles as $article) { $article['content'] = strip_tags($article['content']); $publication_unixtimestamp = strtotime($article['publication_datetime']); $article['publication_date'] = date('Y/m/d', $publication_unixtimestamp); $article['publication_time'] = date('H:i', $publication_unixtimestamp); $tmp_articles[] = $article; } $smarty->assign('articles', $tmp_articles); $smarty->displayBase('admin/index.tpl');