<?php


require_once( "_inc.php" );
if ( !empty( $_POST['btnSubmit'] ) )
{
	$name = !empty( $_POST['name'] ) ? trim( $_POST['name'] ) : "";
	$url = !empty( $_POST['url'] ) ? trim( $_POST['url'] ) : "";
	$order = !empty( $_POST['order'] ) ? trim( $_POST['order'] ) : "1000";
	if ( empty( $name ) || empty( $url ) )
	{
		$tpl->assign( "msg", "缺少参数。" );
		$tpl->display( "_msg.tpl" );
		exit( );
	}
	$exist = $db->fetchone( "SELECT f_id FROM ".$gDb['prefix'].( "usersites WHERE (f_userId='".$dUserId."' AND f_name='{$name}')" ) );
	if ( $exist )
	{
		$tpl->assign( "msg", "该网址已存在。" );
		$tpl->display( "_msg.tpl" );
		exit( );
	}
	$now = time( );
	$sql = "INSERT INTO ".$gDb['prefix'].( "usersites SET f_name='".$name."', f_url='{$url}', f_userId='{$dUserId}', f_order='{$order}', f_addTime='{$now}'" );
	$db->query( $sql );
	header( "location:sites.php" );
	exit( );
}
$tpl->display( );
?>
