<?php
if(!defined('IN_ADMIN')) exit('Access Denied');
if($_SESSION["admin"]!="NewsTeng")showmessage('请登陆', SCRIPT_NAME.'?file=login');
@set_time_limit(0);
require_once TM_ROOT.'include/page.class.php';
$pages = new page();
if(!isset($action)) $action = 'list';
switch ($action){
	case 'add':
            if($dosubmit){
                if(empty($info)) showmessage('操作失败', 'goback');    	
				if(!$pages->add($info)) {
					showmessage('添加失败,请检查输入是否正确!','goback');
				}
				showmessage('添加成功！', 'goback');
            }else{    
            	include_once TM_ROOT.'./include/editor.class.php';
				$editor=new editor('info[body]');
				$editor->BasePath='.';
				$editor->Height=500;
				$editor->Width=700;
				$editor->AutoSave=false; 
                include admin_tpl('page');
            }
	break;

    case 'list':
    	$page = max(intval($page), 1);
    	$page_size = 15;
    	$row = $pages->get_row();
    	$mpurl =SCRIPT_NAME.'?file='.$file.'&action=list&';
    	$dispage =  page($row,$page_size,$page,$mpurl);
    	$p = $pages->listinfo('', 'id DESC', $page, $page_size);
        include admin_tpl('page');
	break;

    case 'edit':
        if($dosubmit){
        	
        	if(!$pages->updata(intval($id),$info)){
        		showmessage('请确认您的填写是否正确！', 'goback');
        	}
        	showmessage('保存成功！', 'goback');
        }else{
        	$p = $pages->get(intval($id)); 
        	include_once TM_ROOT.'./include/editor.class.php';
			$editor=new editor('info[body]');
			$editor->Value=$p['body'];
			$editor->BasePath='.';
			$editor->Height=500;
			$editor->Width=700;
			$editor->AutoSave=false; 
            include admin_tpl('page');
        }
	break;
	case 'del':
		$u = $pages->del(intval($id));
	    if(!$u){
	    	showmessage('删除失败！', 'goback');
	    }
	    showmessage('删除成功！', 'goback');
	break;
}
?>