<?php
/**
 * @package iCMS
 * @copyright 2007-2010, iDreamSoft
 * @license http://www.idreamsoft.cn iDreamSoft
 * @author coolmoo <idreamsoft@qq.com>
 */
require_once("global.php");
$do=$_GET['do'];
if(empty($do)){
	$iCMS->iPrint("iTPL","register");
}elseif($do=='post'){
	if($_POST['action']=='save'){
		ckseccode($_POST['seccode']) && msgJson('seccode','error:seccode');
		$username=dhtmlspecialchars($_POST['username']);
	    $_POST['username']&&!eregi("^([_\.0-9a-z-]+)@([0-9a-z][0-9a-z-]+)\.([a-z]{2,6})$",$_POST['username']) && msgJson('username','register:emailerror');
		WordFilter($username) && msgJson('username','filter:username');
		$iCMS->db->getValue("SELECT uid FROM `#iCMS@__members` where `username`='$username'") && msgJson('username','register:usernameusr');
		$password=md5(trim($_POST['password']));
		$pwdrepeat=md5(trim($_POST['pwdrepeat']));
		$password!=$pwdrepeat && msgJson('pwdrepeat','register:different');
		
	    $gender=intval($_POST['gender']);
	    $nickname=dhtmlspecialchars($_POST['nickname']);
	    cstrlen($nickname)>12 && msgJson(0,'register:nicknamelong');
	    $_POST['icq'] && $info['icq']=intval($_POST['icq']);
		$_POST['home'] && $info['home']=dhtmlspecialchars(stripslashes($_POST['home']));
	    $_POST['year'] && $info['year']=intval($_POST['year']);
	    $_POST['month'] && $info['month']=intval($_POST['month']);
	    $_POST['day'] && $info['day']=intval($_POST['day']);
	    $_POST['from'] && $info['from']=dhtmlspecialchars(stripslashes($_POST['from']));
	    $_POST['signature'] && $info['signature']=dhtmlspecialchars(stripslashes($_POST['signature']));
	    $info=empty($info)?'':addslashes(serialize($info));
		$iCMS->db->query("INSERT INTO `#iCMS@__members` (`username`,`password`,`groupid`,`nickname`,`gender`,`info`,`power`,`cpower`,`lastip`,`lastlogintime`,`logintimes`,`post`) VALUES ('$username','$password', '4','$nickname','$gender','$info','','','".getip()."', '".time()."','0','0') ");
		//设置为登陆状态
		set_cookie('user',authcode($username.'#=iCMS!=#'.$password,'ENCODE'));
		set_cookie('username',empty($nickname)?$username:$nickname);
		msgJson(1,'register:finish');
	}
}