<?php require_once '../../session.php'; require_once 'is_login.php'; if (isset($_GET['id']) && $_GET['id'] != '') { 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; } $db->delete_article($_GET['id']); } header('HTTP/1.1 303 See Other'); header('Location: ./');
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; // セッションIDを再生成 session_regenerate_id(); redirect_admin_page(); } else { // ログインに失敗した場合はエラーメッセージを表示 $smarty->assign('error_message', 'ユーザーIDやパスワードが間違っています');
<?php require_once '../session.php'; 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 (isset($_POST['article_id']) && $_POST['article_id'] != '' && isset($_POST['content']) && $_POST['content'] != '' && $db->is_exist_article($_POST['article_id'], true)) { $name = '名無しさん'; if (isset($_POST['name']) && $_POST['name'] != '') { $name = $_POST['name']; } $db->insert_comment($_POST['article_id'], $name, $_POST['content']); } header('HTTP/1.1 303 See Other'); header('Location: ' . (isset($_POST['article_id']) ? 'detail_article.php?id=' . $_POST['article_id'] : './'));
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']); } // 取得失敗(指定したIDが存在しない等)
<?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'; // 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']);
$smarty->assign('error_publication_time', '入力されていません'); } else { $smarty->assign('publication_time', $_POST['publication_time']); if (preg_match('/^(0[0-9]{1}|1[0-9]{1}|2[0-3]{1}):(0[0-9]{1}|[1-5]{1}[0-9]{1})$/', $_POST['publication_time']) !== 1) { $is_exist_error = true; $smarty->assign('error_publication_time', '無効なフォーマットです'); } } if ($is_exist_error === true) { $smarty->displayBase('admin/edit_article.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; } // 公開日時のパラメーターをPostgresのdatetime用に加工 $datetime_unixtimestamp = strtotime($_POST['publication_date'] . ' ' . $_POST['publication_time']); $datetime_for_postgres = date('Y-m-d H:i:s', $datetime_unixtimestamp); // 新規作成が成功した場合は管理者トップページへ if ($db->insert_new_article($_POST['title'], $_POST['content'], $datetime_for_postgres)) { header('HTTP/1.1 303 See Other'); header('Location: ./'); exit; } else {
<?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');
<?php require_once '../session.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(); $tmp_articles = array(); foreach ($articles as $article) { $article['content'] = strip_tags($article['content']); $tmp_articles[] = $article; } $smarty->assign('articles', $tmp_articles); $smarty->displayBase('index.tpl');