<?php
if(!defined('IN_TM')) 
{
	exit('Access Denied');
}
if($_SESSION["admin"]!="Silence")
{
	include template('login.htm');
    exit;
}
//¹ÜÀíÔ±²Ù×÷
$a = getgpc('do');
if($a == 'list')
{
	$page = getgpc('page');
	if(isset($page)){ $page = intval($page); }else{ $page = 1; }
	$page_size = 15; 
	$sql = "SELECT * FROM `{$tablepre}news`";
	$row = $db->num_rows($db->query($sql));
	$mpurl =$PHP_SELF.'?action=news&do=list&';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}news LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 1;
	include template('news.htm');
	$db->close();
	exit;
}
elseif ($a == 'add')
{
	if (empty($_POST['Submit']))
	{
		$fl = $db->fetch_all("SELECT * FROM {$tablepre}news_fl");
		include_once TM_ROOT.'./include/Editor.class.php';
		$editor=new sinaEditor('body');
		$editor->BasePath='.';
		$editor->Height=500;
		$editor->Width=700;
		$editor->AutoSave=false;
		$tplid = 2;
		include template('news.htm');
		exit;
	}
	else
	{
		
		$tiele = getgpc('title');
		$fl = getgpc('fl');
		$zz = getgpc('zz');
		$ly = getgpc('ly');
		$body = getgpc('body');
		if(empty($tiele) or empty($body) )
		{
			$messageid = 14;
			include template('message.htm');
			exit;
		}
		$db->query("INSERT INTO {$tablepre}news (title,ssfl,zz,ly,body,time) VALUES ('$tiele','$fl','$zz','$ly','$body','$timestamp')");
		$messageid = 13;
		include template('message.htm');
		exit;
	}
}
elseif ($a == 'del')
{
	$uids = timplode(getgpc('delete'));
	$rs = $db->query("DELETE FROM {$tablepre}news WHERE id IN ($uids) ");
	if (!$rs) 
	{
		$messageid = 22;
		include template('message.htm');
		exit;
	}
	$messageid = 21;
	include template('message.htm');
	$db->close();
	exit;
}
elseif ($a == 'edit')
{
	if (empty($_POST['Submit']))
	{
		$id = getgpc('id');
		$userlist = $db->fetch_all("SELECT * FROM {$tablepre}news WHERE id = '{$id}'");
		$fl = $db->fetch_all("SELECT * FROM {$tablepre}news_fl");
		include_once TM_ROOT.'./include/Editor.class.php';
		$editor=new sinaEditor('body');
		$editor->Value=$userlist[0][body];
		$editor->BasePath='.';
		$editor->Height=500;
		$editor->Width=700;
		$editor->AutoSave=false;
		$tplid = 3;
		include template('news.htm');
		exit;
	}
	else
	{
		$id = getgpc('id');
		$title = getgpc('title');
		$fl = getgpc('fl');
		$zz = getgpc('zz');
		$ly = getgpc('ly');
		$body = getgpc('body');
		if(empty($title) or empty($body) )
		{
			$messageid = 14;
			include template('message.htm');
			exit;
		}
		$sql = "UPDATE {$tablepre}news SET title = '{$title}',ssfl = '{$fl}',zz = '{$zz}',ly = '{$ly}',body = '{$body}' WHERE id ={$id};";
		$db->query($sql);
		$messageid = 6;
		include template('message.htm');
		exit;
    }
}
elseif ($a == 'fl')
{
	$page = getgpc('page');
	if(isset($page)){ $page = intval($page); }else{ $page = 1; }
	$page_size = 15; 
	$row = $db->num_rows($db->query("SELECT * FROM `{$tablepre}news_fl`"));
	$mpurl =$PHP_SELF.'?action=news&do=fl&a=list';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}news_fl LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 4;
	include template('news.htm');
	$db->close();
	exit;
}
elseif ($a == 'newsfldel')
{
	$id = getgpc('id');
	$uids = timplode(getgpc('id'));
	$row_num = $db->num_rows($db->query("SELECT * FROM {$tablepre}news where ssfl='$id'"));
	if($row_num > 0){
 		$messageid = 15;
 		include template('message.htm');
 		return;
 	}else{
 		$rs = $db->query("DELETE FROM {$tablepre}news_fl WHERE id IN ($uids) ");
		if (!$rs) 
		{
			$messageid = 22;
			include template('message.htm');
			exit;
		}
		$messageid = 21;
		include template('message.htm');
		$db->close();
		exit;
	}
}
elseif ($a == 'newsfledit')
{
	$id = getgpc('id');
	$title = getgpc('title');
	$listid = getgpc('listid');
	if(empty($title))
	{
		$messageid = 8;
		include template('message.htm');
		exit;
	}
	$sql = "UPDATE {$tablepre}news_fl SET title = '{$title}',listid = '{$listid}' WHERE id ={$id};";
	$db->query($sql);
	$messageid = 6;
	include template('message.htm');
	exit;
}
elseif ($a == 'newsfladd')
{
	$title = getgpc('title');
	$listid = getgpc('listid');
if(empty($title))
	{
		$messageid = 8;
		include template('message.htm');
		exit;
	}
	$db->query("INSERT INTO {$tablepre}news_fl (title,listid) VALUES ('$title','$listid')");
	$messageid = 13;
	include template('message.htm');
	exit;
}
?>