<?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}ads`";
	$row = $db->num_rows($db->query($sql));
	$mpurl =$PHP_SELF.'?action=ads&do=list&';
	$dispage =  page($row,$page_size,$page,$mpurl);
	$page_get_start = page_get_start($page,$page_size,$row);
	$sql = "SELECT * FROM {$tablepre}ads LIMIT $page_get_start, $page_size";
	$userlist = $db->fetch_all($sql);
	$a = 'Y-m-d H:i';
	$tplid = 1;
	include template('ads.htm');
	$db->close();
	exit;
}
elseif ($a == 'add')
{
	if (empty($_POST['Submit']))
	{
		$tplid = 2;
		include template('ads.htm');
		exit;
	}
	else
	{	
		$title = getgpc('title');
		$url = getgpc('url');
		$img = getgpc('pic');
		$listid = getgpc('listid');
		if(empty($title) or empty($url) )
		{
			$messageid = 14;
			include template('message.htm');
			exit;
		}
		$db->query("INSERT INTO {$tablepre}ads (title,link,img,listid,time) VALUES ('$title','$url','$img','$listid','$timestamp')");
		$messageid = 13;
		include template('message.htm');
		exit;
	}
}
elseif ($a == 'del')
{
	$uids = timplode(getgpc('id'));
	$rs = $db->query("DELETE FROM {$tablepre}ads 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')
{
		$id = getgpc('id');
		$title = getgpc('title');
		$link = getgpc('link');
		$listid = getgpc('listid');
		$sql = "UPDATE {$tablepre}ads SET title = '{$title}',link = '{$link}',listid = '{$listid}' WHERE id ={$id};";
		$db->query($sql);
		$messageid = 6;
		include template('message.htm');
		exit;
}
?>