<?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}about`";
	$row = $db->num_rows($db->query($sql));
	$mpurl =$PHP_SELF.'?action=about&a=list&';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}about LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 1;
	include template('about.htm');
	$db->close();
	exit;
}
elseif ($a == 'add')
{
	if (empty($_POST['Submit']))
	{
		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('about.htm');
		exit;
	}
	else
	{
		$tiele = getgpc('title');
		$body = getgpc('body');
		if(empty($tiele) or empty($body) )
		{
			$messageid = 14;
			include template('message.htm');
			exit;
		}
		$db->query("INSERT INTO {$tablepre}about (title,body) VALUES ('$tiele','$body')");
		$messageid = 13;
		include template('message.htm');
		exit;
	}
}
elseif ($a == 'del')
{
	$uids = timplode(getgpc('delete'));
	$rs = $db->query("DELETE FROM {$tablepre}about 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}about WHERE id = '{$id}'");
		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('about.htm');
		exit;
	}
	else
	{
		$id = getgpc('id');
		$title = getgpc('title');
		$body = getgpc('body');
		if(empty($title) or empty($body) )
		{
			$messageid = 14;
			include template('message.htm');
			exit;
		}
		$sql = "UPDATE {$tablepre}about SET title = '{$title}',body = '{$body}' WHERE id ={$id};";
		$db->query($sql);
		$messageid = 6;
		include template('message.htm');
		exit;
    }
}
elseif ($a == 'menu')
{
	$page = getgpc('page');
	if(isset($page)){ $page = intval($page); }else{ $page = 1; }
	$page_size = 15; 
	$sql = "SELECT * FROM `{$tablepre}menu`";
	$row = $db->num_rows($db->query($sql));
	$mpurl =$PHP_SELF.'?action=about&do=menu&a=list';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}menu ORDER BY `listid` ASC  LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 1;
	include template('menu.htm');
	$db->close();
	exit;
}
elseif ($a == 'menudel')
{
	$uids = timplode(getgpc('id'));
	$rs = $db->query("DELETE FROM {$tablepre}menu WHERE id IN ($uids) ");
	if (!$rs) 
	{
		$messageid = 22;
		include template('message.htm');
		exit;
	}
	$messageid = 21;
	include template('message.htm');
	$db->close();
	exit;
}
elseif ($a == 'menuedit')
{
	$id = getgpc('id');
	$title = getgpc('title');
	$url = getgpc('url');
	$target = getgpc('target');
	$listid = getgpc('listid');
	if(empty($title) or empty($url))
	{
		$messageid = 8;
		include template('message.htm');
		exit;
	}
	$sql = "UPDATE {$tablepre}menu SET title = '{$title}',url = '{$url}',target = '{$target}',listid = '{$listid}' WHERE id ={$id};";
	$db->query($sql);
	$messageid = 6;
	include template('message.htm');
	exit;
}
elseif ($a == 'menuadd')
{
	$title = getgpc('title');
	$url = getgpc('url');
	$target = getgpc('target');
	$listid = getgpc('listid');
if(empty($title) or empty($url))
	{
		$messageid = 8;
		include template('message.htm');
		exit;
	}
	$db->query("INSERT INTO {$tablepre}menu (title,url,target,listid) VALUES ('$title','$url','$target','$listid')");
	$messageid = 13;
	include template('message.htm');
	exit;
}
?>