<?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}link`";
	$row = $db->num_rows($db->query($sql));
	$mpurl =$PHP_SELF.'?action=link&do=list&';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}link LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 2;
	include template('link.htm');
	$db->close();
	exit;
}
elseif ($a == 'add')
{	
	$website = getgpc('website');
	$alt = getgpc('alt');
	$img = getgpc('pic');
	$url = getgpc('url');
	$db->query("INSERT INTO {$tablepre}link 
	(title,alt,url,img,time) VALUES 
	('$website','$alt','$url','$img','$timestamp')");
	$messageid = 13;
	include template('message.htm');
	exit;
}
elseif ($a == 'del')
{
	$uids = timplode(getgpc('id'));
	$rs = $db->query("DELETE FROM {$tablepre}link 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}link WHERE id = '{$id}'");
		include_once TM_ROOT.'./include/Editor.class.php';
		$editor=new sinaEditor('body');
		$editor->Value=$userlist[0][body];
		$editor->BasePath='.';
		$editor->Height=200;
		$editor->Width=700;
		$editor->AutoSave=false;
		$tplid = 1;
		include template('link.htm');
		exit;
	}
	else
	{
		$id = getgpc('id');
		$title = getgpc('title');
		$fl = getgpc('fl');
		$img = getgpc('pic');
		$body = getgpc('body');
		if(empty($title) or empty($body) )
		{
			$messageid = 14;
			include template('message.htm');
			exit;
		}
		$sql = "UPDATE {$tablepre}shop SET title = '{$title}',ssfl = '{$fl}',img = '{$img}',body = '{$body}' WHERE id ={$id};";
		$db->query($sql);
		$messageid = 6;
		include template('message.htm');
		exit;
    }
}
?>