2010年2月25日木曜日

edittopic.php トピック編集画面

<?
require("MySmarty.class.php");
require('Settings.class.php');
require('Categories.class.php');
require('Topic.class.php');


$smarty = new MySmarty();
$settings  = new Settings;
$categories  = new Categories;
$topic  = new Topic;

session_start();
$id = $_SESSION['id'];
$pass = $_SESSION['pass'];
// ユーザチェック
if( ( $id == '' ) || ( !$settings->isValidUser($id,$pass) ) ){
    header("Location: login.php" );
    exit;
}

$settings->loadSettings();
//
if( $_SERVER['REQUEST_METHOD'] == 'GET' ){
    if( !isset( $_GET['topicid'] ) || ( $_GET['topicid'] == 0 ) ) {
        // 新規トピックの編集
        $smarty->assign( "topicid", "0" );
        $smarty->assign( "title" , "" );
        $smarty->assign( "body" , "" );
        $smarty->assign( "fdelete", "" );
    } else {
        $err = $topic->loadTopic( $_GET['topicid'] );
        $err_msg = $topic->errorm;
        $smarty->assign( "topicid", $topic->topicid );
        $smarty->assign( "title" , $topic->title );
        $smarty->assign( "body" , $topic->body  );
        $smarty->assign( "fdelete", $topic->fdelete );
    }
} else {
    //ここは入力されたPOSTからのトピック情報の再表示処理
    $smarty->assign('topicid', $_POST['topicid']);
    $smarty->assign('title', $_POST['title']);
    $smarty->assign('body', $_POST['body']);
    $smarty->assign('fdelete', $_POST['fdelete']);
    //submitが無しでなければPOSTで受け取る
    if( $_POST['submit'] != '' ){
//        $err_msg = check_input();
        if( $err_msg == '' ){
            $topic->topicid = $_POST['topicid'];
            $topic->title = $_POST['title'];
            $topic->body = $_POST['body'];
            $topic->catid = $_POST['catid'];
            $topic->fdelete = $_POST['fdelete'];
            $topic->saveTopic();
            $err_msg = $topic->errorm;
        }
        if( $err_msg == '' ){
            $gen_msg = "日記書き込み完了しました。";
        }
    }
}
//edittopic.htmlに渡すSmartyでの表示の処理
$smarty->assign('categories_list', $categories->makeSelect($topic->catid));
$smarty->assign( "maintitle", $settings->maintitle );

$smarty->assign('error_message', $err_msg);

$smarty->assign('general_message', $gen_msg);

if( $topic->topicid == 0 ){
    $smarty->assign('mode', "追加");
} else {
    $smarty->assign('mode', "編集");
}
$smarty->display( "edittopic.html" );

?>

0 件のコメント:

コメントを投稿