<?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/type.class.php';
$type = new type();
if(!isset($action)) $action = 'list';
switch ($action){
	case 'add':
            if($dosubmit){
				if(!$type->add($info)) {
					showmessage('添加失败,请检查输入是否正确!','goback');
				}
				showmessage('添加成功！', 'goback');
            }else{     
                include admin_tpl('type');
            }
	break;

    case 'list':
    	$page = max(intval($page), 1);
    	$page_size = 15;
    	$r = $db->get_one("SELECT count(*) as num FROM ".DB_PRE."type where lx=".$lx);
    	$mpurl =SCRIPT_NAME.'?file=type&action=list&lx='.$lx.'&';
    	$dispage =  page($r['num'],$page_size,$page,$mpurl);
      	$t = $type->listinfo('where lx='.$lx, 'id DESC', $page, $page_size);
        include admin_tpl('type');
	break;

    case 'edit':
        if($dosubmit){
        	if(!$type->updata(intval($id),$info[title])){
        		showmessage('请确认您的填写是否正确！', 'goback');
        	}
        	showmessage('保存成功！', 'goback');
        }else{
        	$ty = $type->get(intval($id)); 
            include admin_tpl('type');
        }
	break;
	case 'del':
		$u = $type->del(intval($id));
	    if(!$u){
	    	showmessage('删除失败！', 'goback');
	    }
	    showmessage('删除成功！', 'goback');
	break;
}
?>