{ 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; } // ログインに成功した場合は管理者ページへ if ($db->login($_POST['user_id'], $_POST['password'])) { $_SESSION['login'] = true;
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']); } // 取得失敗(指定したIDが存在しない等) if ($article === false) { $smarty->assign('error_message', '記事が存在しません'); $smarty->assign('article_title', ''); $smarty->assign('article_content', '');
// Smarty読み込み&準備 require_once '../setup.php'; $smarty = new Smarty_Assignment('Assignment'); 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;
<?php require_once '../../session.php'; require_once 'is_login.php'; 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; } 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);
<?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');