<?php

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

	$RCSfile: ajax.php,v $
	$Revision: 1.30.2.2 $
	$Date: 2007/03/12 14:11:21 $
*/

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(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');

?>