<?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}shop`";
	$row = $db->num_rows($db->query($sql));
	$mpurl =$PHP_SELF.'?action=shop&do=list&';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}shop LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 1;
	include template('shop.htm');
	$db->close();
	exit;
}
elseif ($a == 'add')
{
	if (empty($_POST['Submit']))
	{
		$fl = $db->fetch_all("SELECT * FROM {$tablepre}shop_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('shop.htm');
		exit;
	}
	else
	{	
		$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;
		}
		$db->query("INSERT INTO {$tablepre}shop (title,ssfl,img,body,time) VALUES ('$title','$fl','$img','$body','$timestamp')");
		$messageid = 13;
		include template('message.htm');
		exit;
	}
}
elseif ($a == 'del')
{
	$uids = timplode(getgpc('delete'));
	$rs = $db->query("DELETE FROM {$tablepre}shop 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}shop WHERE id = '{$id}'");
		$fl = $db->fetch_all("SELECT * FROM {$tablepre}shop_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('shop.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;
    }
}
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}shop_fl`"));
	$mpurl =$PHP_SELF.'?action=shop&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}shop_fl LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 4;
	include template('shop.htm');
	$db->close();
	exit;
}
elseif ($a == 'shopfldel')
{
	$id = getgpc('id');
	$uids = timplode(getgpc('id'));
	$row_num = $db->num_rows($db->query("SELECT * FROM {$tablepre}shop where ssfl='$id'"));
	if($row_num > 0){
 		$messageid = 15;
 		include template('message.htm');
 		return;
 	}else{
 		$rs = $db->query("DELETE FROM {$tablepre}shop_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 == 'shopfledit')
{
	$id = getgpc('id');
	$title = getgpc('title');
	$listid = getgpc('listid');
	if(empty($title))
	{
		$messageid = 8;
		include template('message.htm');
		exit;
	}
	$sql = "UPDATE {$tablepre}shop_fl SET title = '{$title}',listid = '{$listid}' WHERE id ={$id};";
	$db->query($sql);
	$messageid = 6;
	include template('message.htm');
	exit;
}
elseif ($a == 'shopfladd')
{
	$title = getgpc('title');
	$listid = getgpc('listid');
if(empty($title))
	{
		$messageid = 8;
		include template('message.htm');
		exit;
	}
	$db->query("INSERT INTO {$tablepre}shop_fl (title,listid) VALUES ('$title','$listid')");
	$messageid = 13;
	include template('message.htm');
	exit;
}
?>