<?php


require_once( "_inc.php" );
$name = !empty( $_POST['name'] ) ? trim( $_POST['name'] ) : "";
$url = !empty( $_POST['url'] ) ? trim( $_POST['url'] ) : "";
$description = !empty( $_POST['description'] ) ? trim( $_POST['description'] ) : "";
$category = !empty( $_POST['category'] ) ? trim( $_POST['category'] ) : "";
$ips = !empty( $_POST['ips'] ) ? trim( $_POST['ips'] ) : "";
$buildTime = !empty( $_POST['buildTime'] ) ? trim( $_POST['buildTime'] ) : "";
$contact = !empty( $_POST['contact'] ) ? trim( $_POST['contact'] ) : "";
$tel = !empty( $_POST['tel'] ) ? trim( $_POST['tel'] ) : "";
$qq = !empty( $_POST['qq'] ) ? trim( $_POST['qq'] ) : "";
$linked = !empty( $_POST['linked'] ) ? trim( $_POST['linked'] ) : "0";
$authCode = !empty( $_POST['authCode'] ) ? trim( $_POST['authCode'] ) : "";
if ( empty( $name ) || empty( $url ) || empty( $description ) || empty( $authCode ) )
{
	$msg = "请完整填写各项。";
	include( "apply.tpl" );
	exit( );
}
session_start( );
if ( $authCode != $_SESSION['ses_authCode'] )
{
	$msg = "验证码不正确。";
	include( "apply.tpl" );
	exit( );
}
require_once( $dRootDir."inc/classes/db.php" );
$db = new db( $gDb );
$exist = $db->fetchone( "SELECT f_id FROM ".$gDb['prefix'].( "sites WHERE (f_url='".$url."')" ) );
if ( $exist )
{
	$msg = "此网站已经被收录过了，请勿重复提交。";
	include( "apply.tpl" );
	exit( );
}
$exist = $db->fetchone( "SELECT f_id FROM ".$gDb['prefix'].( "applies WHERE (f_url='".$url."')" ) );
if ( $exist )
{
	$msg = "此网站已经提交过了，请勿重复提交。";
	include( "apply.tpl" );
	exit( );
}
$now = time( );
$addIp = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO ".$gDb['prefix'].( "applies SET f_name='".$name."', f_url='{$url}', f_description='{$description}', f_category='{$category}', f_ips='{$ips}', f_buildTime='{$buildTime}', f_contact='{$contact}', f_tel='{$tel}', f_qq='{$qq}', f_linked='{$linked}', f_addTime='{$now}', f_addIp='{$addIp}'" );
$db->query( $sql );
$msg = "提交成功！";
include( "apply.tpl" );
?>
