<?php
require_once "includes/common.inc.php";
if($aid) {
	$ad = $db -> queryarray("SELECT * FROM {$tablepre}ad WHERE aid='$aid'");
	if(!$ad) {
		msg('error');
	}
}
@include lang('themes');
$locations = array(
	'top' => $lang['allpage'] . $lang['top'],
	'main' => $lang['allpage'] . $lang['main'],
	'right' => $lang['allpage'] . $lang['right'],
	'bottom' => $lang['allpage'] . $lang['bottom'],
	'index_main' => $lang['index'] . $lang['main'],
	'index_right' => $lang['index'] . $lang['right'],
	'index_bottom' => $lang['index'] . $lang['bottom'],
	'list_main' => $lang['sort'] . $lang['main'],
	'list_right' => $lang['sort'] . $lang['right'],
	'list_bottom' => $lang['sort'] . $lang['bottom'],
	'view_main' => $lang['article'] . $lang['main'],
	'view_bottom' => $lang['article'] . $lang['bottom'],
	'default' => $lang['custom'] ,
);

if(checksubmit('postmsg')) {
		$username=trim($username);
		$email = trim($email);
		$company = trim($company);
		if(empty($username)){
			msg("nachen_empty");
		}
		if(strlen($username) > 15) {
			msg('nachen_too_long');
		}
		$guestexp = '\xA1\xA1|\xAC\xA3|^Guest|^\xD3\xCE\xBF\xCD|\xB9\x43\xAB\xC8';
		if(preg_match("/^\s*$|^c:\\con\\con$|[%,\*\"\s\t\<\>\&]|$guestexp/is", $username)) {
			msg('nachen_unaccepted');
		}
		$censorexp = '/('.str_replace("\r\n", '|', preg_quote($censoremail, '/')).')$/i';
		if(empty($email)  ||  !isemail($email)) {
			msg('email_unaccepted');
		}

		if(empty($adurl)  ||  !isurl($adurl)) {
			msg('link_sitename_empty');
		}
		if(empty($adpic)  ||  !isurl($adpic)) {
			msg('ad_logo_unaccepted');
		}
		if(!$locations[$newtype]) {
			msg('ad_localtion_unaccepted');
		}
		$phone=trim($phone);
		if(!empty($phone) &&  !ereg("(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)",$phone)){
			msg('phone_unaccepted');
		}
		$subject = htmlconvert(trim($subject));
		if($subject == '' || $msg == '') {
			msg('contents_unaccepted');
		}
		if(strlen($subject) >79){
			msg('subject_too_long');
		}
		if(strlen($msg) >1000){
			msg('contents_too_long');
		}
		$old = $db -> queryarray("SELECT postime FROM {$tablepre}adrequest WHERE postip='$onlineip' ORDER BY postime DESC LIMIT 1");
		if(($time - $old['postime'])<30){
			msg('post_water');
		}
		$adurl=htmlconvert($adurl);
		$adpic=htmlconvert($adpic);
		$company=htmlconvert($company);
		$address=htmlconvert($address);
		$postcode=htmlconvert($postcode);
		$email=htmlconvert($email);
		$oicq=htmlconvert($oicq);
		$phone=htmlconvert($phone);
		$connact=htmlconvert($connact);
		$msg=htmlconvert($msg);
		$mobile=htmlconvert($mobile);



		$db -> query("INSERT INTO {$tablepre}adrequest  (type, aid, adurl, adpic, username, company, subject, address, postcode, postime, postip, email, oicq, phone, mobile, connact, msg) VALUES ('$newtype', '$aid', '$adurl', '$adpic', '$username', '$company', '$subject', '$address', '$postcode', '$time', '$onlineip', '$email', '$oicq', '$phone','$mobile', '$connact', '$msg')");
		msg('thanks', mreferer());
}else{
		$useseccode && $seccode = random(4, 1);	
		$referer = mreferer();
	include theme('reggo');
}
?>