<?php


require_once( "_inc.php" );
$backUrl = !empty( $_GET['back'] ) ? trim( $_GET['back'] ) : base64_encode( "ad_list.php" );
$addUrl = !empty( $_GET['addUrl'] ) ? trim( $_GET['addUrl'] ) : base64_encode( $_SERVER['REQUEST_URI'] );
if ( !empty( $_GET['btnSubmit'] ) )
{
	util::auth( );
	$name = !empty( $_GET['name'] ) ? trim( $_GET['name'] ) : "";
	$code = !empty( $_GET['code'] ) ? trim( $_GET['code'] ) : "";
	if ( empty( $name ) )
	{
		$tpl->assign( "msg", "缺少参数。" );
		$tpl->display( "_msg.tpl" );
		exit( );
	}
	$exist = $db->fetchone( "SELECT f_id FROM ".$gDb['prefix'].( "ads WHERE (f_name='".$name."')" ) );
	if ( $exist )
	{
		$tpl->assign( "msg", "该广告位已存在。" );
		$tpl->assign( "addUrl", base64_decode( $addUrl ) );
		$tpl->assign( "backUrl", base64_decode( $backUrl ) );
		$tpl->display( "_msg.tpl" );
		exit( );
	}
	$sql = "INSERT INTO ".$gDb['prefix'].( "ads SET f_name='".$name."', f_code='{$code}'" );
	$db->query( $sql );
	$tpl->assign( "msg", "添加成功。" );
	$tpl->assign( "addUrl", base64_decode( $addUrl ) );
	$tpl->assign( "backUrl", base64_decode( $backUrl ) );
	$tpl->display( "_msg.tpl" );
	exit( );
}
$tpl->assign( "backUrl", $backUrl );
$tpl->assign( "addUrl", $addUrl );
$tpl->display( );
?>
