<?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/ads.class.php';
$ads = new ads();
if(!isset($action)) $action = 'list';
switch ($action){
	case 'add':
            if($dosubmit){
                if(empty($info)) showmessage('操作失败', 'goback');
        		require_once TM_ROOT.'include/upload.class.php';
        		$upload = new upload('uploadfile', 'jpg|jpeg|gif|bmp|png', 1);   
				$img = $upload->up();	   
        		$info['img'] = $img;  
				$info['time'] = TIME;   
				if(!$ads->add($info)) {
					showmessage('添加失败,请检查输入是否正确!','goback');
				}
				showmessage('添加成功！', 'goback');
            }else{   
                include admin_tpl('ads');
            }
	break;

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

    case 'edit':
        if($dosubmit){
        	if($_FILES){
        		require_once TM_ROOT.'include/upload.class.php';
        		$upload = new upload('uploadfile', 'jpg|jpeg|gif|bmp|png', 1);   
				$img = $upload->up();
        		$info['img'] = $img;    
        	}
        	if(!$ads->updata(intval($id),$info)){
        		showmessage('请确认您的填写是否正确！', 'goback');
        	} 
        	showmessage('保存成功！', 'goback');
        }else{
        	$ns = $ads->get(intval($id)); 
            include admin_tpl('ads');
        }
	break;
	case 'del':
		$u = $ads->del(intval($id));
	    if(!$u){
	    	showmessage('删除失败！', 'goback');
	    }
	    showmessage('删除成功！', 'goback');
	break;
}
?>