<?php

/*
	[Discuz!] (C)2001-2007 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$RCSfile: ajax.php,v $
	$Revision: 1.30.2.4 $
	$Date: 2007/03/21 15:52:04 $
*/

define('NOROBOT', TRUE);
require_once './include/common.inc.php';

if($action == 'updatesecqaa') {

	require_once DISCUZ_ROOT.'./forumdata/cache/cache_secqaa.php';
	$seccode = random(1, 1) * 1000000 + substr($seccode, -6);
	showmessage($_DCACHE['secqaa'][substr($seccode, 0, 1)]['question']);

} elseif(in_array($action, array('checkseccode', 'checksecanswer', 'checkusername', 'checkemail'))) {

	if($action == 'checkseccode') {
		$tmp = $seccode;
		seccodeconvert($tmp);
		if(strtoupper($seccodeverify) != $tmp) {
			showmessage('submit_seccode_invalid');
		}

	} elseif($action == 'checksecanswer') {

		require_once DISCUZ_ROOT.'./forumdata/cache/cache_secqaa.php';
		if(!$headercharset) {
			@dheader('Content-Type: text/html; charset='.$charset);
		}
		if(md5($secanswer) != $_DCACHE['secqaa'][$seccode{0}]['answer']) {
			showmessage('submit_secqaa_invalid');
		}

	} elseif($action == 'checkusername') {

		$username = trim($username);

		$guestexp = '\xA1\xA1|^Guest|^\xD3\xCE\xBF\xCD|\xB9\x43\xAB\xC8';
		$censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array('.*', '|', ''), preg_quote(($censoruser = trim($censoruser)), '/')).')$/i';
		if(preg_match("/^\s*$|^c:\\con\\con$|[%,\*\"\s\t\<\>\&]|$guestexp/is", $username) || ($censoruser && @preg_match($censorexp, $username))) {
			showmessage('profile_username_illegal');
		}

		$query = $db->query("SELECT uid FROM {$tablepre}members WHERE username='$username'");
		$username = dhtmlspecialchars(stripslashes($username));

		if($db->num_rows($query)) {
			showmessage('register_check_found');
		}

	} elseif($action == 'checkemail' && !$doublee) {

		$email = trim($email);

		$query = $db->query("SELECT uid FROM {$tablepre}members WHERE email='$email' LIMIT 1");
		if($db->num_rows($query)) {
			showmessage('profile_email_duplicate');
		}
	}
}

showmessage('succeed');

?>