<?
require("datafile/config.php");
require("datafile/style.php");
require("global.php");
$add_title=" &gt; 注册程式";

$newuserfile = "datafile/newuser.php";

if ($login_status==0 && $step==2) {
	//--------进行注册-----------
	$check=1;

	//--------check--------
	$homepage	=	safe_convert($homepage);
	$signature	=	safe_convert($signature);
	$fromwhere	=	safe_convert($fromwhere);
	$addcomment	=	safe_convert($addcomment);

	if (file_exists("$id_unique/".$addusername)) {$reason="该用户已存在，如果您忘了密码，可以选择<a href=\"sendpwd.php\">密码发送</a>"; $check=0; }
	if (empty($addusername)) {$reason="用户名没有填写，请填写"; $check=0;} $addusername=str_replace("\t","",$addusername); $addusername=str_replace("\r","",$addusername); $addusername=str_replace("\n","",$addusername);
	if (strrpos($addusername,"|")!==false || strrpos($addusername,'.')!==false || strrpos($addusername,'/')!==false || strrpos($addusername,";")!==false || strrpos($addusername,",")!==false || strrpos($addusername,"<")!==false || strrpos($addusername,">")!==false) {$reason="用户名包含不可接受字符，请使用中文英文和数字"; $check=0;}
	if (empty($addpassword)) {$reason="密码没有填写，请填写"; $check=0;} $addpassword=str_replace("\t","",$addpassword); $addpassword=str_replace("\r","",$addpassword); $addpassword=str_replace("\n","",$addpassword);
	if (strrpos($addpassword,"|")!==false || strrpos($addpassword,"<")!==false || strrpos($addpassword,">")!==false) {$reason="密码包含不可接受字符，请使用英文和数字"; $check=0;}
	if (empty($addemail)) {$reason="信箱没有填写，请填写"; $check=0;}
	if (!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,3}$",$addemail)) {$reason="信箱不符合检查标准，请确认没有错误(拜托，假的也要像一点)"; $check=0;}
	if (!empty($publicmail) && $publicmail=="yes") $publicmail=1; else $publicmail=0;
	if (empty($receivemail)) $receivemail="text";
		elseif ($receivemail=="html") $receivemail="html";
		elseif ($receivemail=="none") $receivemail="none";
		else $receivemail="text";
	if (strlen($addcomment)>200) {$reason="自我介绍太长，请删掉一些，控制在100个字以内"; $check=0;}
	if (strlen($signature)>$max_sign_length) {$reason="签名档太长，请删掉一些，控制在100个字以内"; $check=0;}
	if (file_exists("datafile/bannames.php")) {
		include("datafile/bannames.php");
		if ($bannames && in_array($addusername,$bannames)) {$reason="此用户名被管理员禁止，请更改或向管理员咨询"; $check=0; }
	}
	if (!$oicqnumber) $oicqnumber="";
	if (!$homepage) $homepage="";
	if (!$signature) $signature="";
	if (!$fromwhere) $fromwhere="";
	if ($oicqnumber && !ereg("^[0-9]{5,}$",$oicqnumber)) {$reason="OICQ号码不正确"; $check=0;}
	$addusername=stripslashes($addusername);
	$addpassword=stripslashes($addpassword);
	$signature=stripslashes($signature);
	$homepage=stripslashes($homepage);
	$addcomment=stripslashes($addcomment);
	$fromwhere=stripslashes($fromwhere);
	$own_portait[0]=stripslashes($own_portait[0]);

	if ($own_portait[0]) {
	  if (!ereg("^[0-9]{1,2}$",$own_portait[1]) && $own_portait[1]!=100) {$reason="自定义头像宽度不正确"; $check=0;}
	  if (!ereg("^[0-9]{1,2}$",$own_portait[2]) && $own_portait[2]!=100) {$reason="自定义头像高度不正确"; $check=0;}
	  $own_portait[0]=safe_convert($own_portait[0]);
	  if (strrpos($own_portait[0],'%')!==false) {$reason="自定义头像包含不可接受字符，请使用正常URL"; $check=0;}
	}
	
	//--------------check complete---------

	if ($check==1) {
	//--------进行注册--
		if (!$usericon) $usericon="no_portait.gif";
		if ($own_portait) $usericon.="%$own_portait[0]%$own_portait[1]%$own_portait[2]";
		$date_reg=$timestamp;
		$user_info="$addusername|$addpassword|$usericon|$addemail|$oicqnumber|$date_reg|$signature|$homepage|$fromwhere|$addcomment|||0|$publicmail|$receivemail|";
		writetofile("$id_unique/".$addusername,$user_info);

		if (file_exists($newuserfile)) $newuserinfo=readfromfile($newuserfile);
		       	else $newuserinfo="|0|0";
		$newuser_info=explode("|",$newuserinfo);
		$newuser_info[1]++;
		$newuser_info[0]="$addusername";
		writetofile($newuserfile,$newuser_info[0]."|".$newuser_info[1]."|".$newuser_info[2]);
		writetofile('datafile/userlist.php',$addusername."\n",'a');

		$vibid=$addusername;
		$vibpwd=$adduserword;
		session_register("vibid");
		//session_register("vibpwd");
		add_online($addusername,getenv('REMOTE_ADDR'));
		jump_page("viboard.php","注册成功",'恭喜您，注册已经成功 <br><br>程式已经为您自动登录<br><br>现在可以开始使用您的会员权利了<br><ul><li><a href=viboard.php>点击这里进入论坛</a></li></ul>');
	}

	if ($check==0) {
		include("header.php");
		print_bar();
		print_fail();
		include("footer.php");
		exit;
	}
}

if ($login_status==1 && !$step) {
	getUserInfo();
	include("header.php");
	print_bar();
//-----下面输出不要注册页面----//
msg_box('警告： 你已经登录','<br>
您已经登录，这表明您已经是注册成员，请避免重复注册。<br>
<br>
如果确实需要，请先退出登录，再进行注册<br>
<br>
您可以选择：
<ul>
<li><a href="javascript:history.back(1)">不再注册，返回前页</a><br>
</li><br>
<li><a href="viblogin.php?job=quit">退出登录，重新注册</a></li>
<br><br>
<li><a href="vibprofile.php?job=kill">将现有用户注销</a></li>
</ul>');
include("footer.php");
exit;
}
if ($login_status==0 && !$step) {
//--------输出注册页面--------
	include("header.php");
	print_bar();
	print_form();
	include("footer.php");
	exit;
}
function print_bar() {
navi_bar('注册程式可以让你成为讨论区的新成员<br>请不要重复注册，以免造成系统资源浪费','注册程式');
}
function print_form() {
global $bordercolor,$subcolor,$titlecolor,$tablewidth,$sign_use_vibcode,$vibcode_sign,
$method,$max_sign_length,$use_own_portait;
if (!$method)  $sts='[<a href="register.php?method=full">点击这里打开完整信息表单</a>]';
	else $sts='[<a href="register.php">点击这里打开简略信息表单</a>]';
?><br>
<script language=JavaScript1.2>
var signmaxchars = <?=$max_sign_length?>;
function setrepeat() {
document.creator.addpassword2.value=document.creator.addpassword.value;
}
function validate(theform) {
	if (theform.addusername.value=="" || theform.addpassword.value=="") {
		alert("请完成名称和密码栏目.");
		return false; }
	if (signmaxchars != 0 && theform.signature) {
		if (theform.signature.value.length > <?=$max_sign_length?>) {
			alert("你的签名太长了.\n\n请限制在 <?=$max_sign_length?> 字节以内.\n当前已有 "+theform.signature.value.length+" 字节.");
			return false; }
		else { return true; }
	} else { return true; }
}
</script>
<table width=<?=$tablewidth?> border=0 cellspacing=0 cellpadding=0 align=center bgcolor=<?=$bordercolor?>>
<form action="register.php" method=post name="creator" onSubmit="return validate(this)">
 <tr>
  <td>
   <table width=100% border=0 cellspacing=1 cellpadding=3>
    <tr bgcolor=<?=$titlecolor?>>
     <td colspan=2 background=images/style/catbg.gif>请输入您的详细资料&nbsp; <?=$sts?></td>
    </tr>
    <tr bgcolor=FFFFFF>
     <td width=30% valign=middle> &nbsp;请填写您想用的名字：</td>
     <td width=70%><b><input type=text size=20 maxlength=14 name="addusername" value="" style="background-color:#ffffff; color:#FF90CD; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></b>(不能有空格，可以是中文)</td>
    </tr>
    <tr bgcolor=EEEEEE>
     <td valign=middle>&nbsp;您选择的密码：</td>
     <td><input onchange='setrepeat()' type=password size=20 maxlength=75 name="addpassword" style="background-color:#ffffff; color:#0000ff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">(最好是英文字母或数字等)</td>
    </tr>
    <tr bgcolor=EEEEEE>
     <td valign=middle>&nbsp;重复您的密码：</td>
     <td><input type=password size=20 maxlength=75 name="addpassword2" style="background-color:#ffffff; color:#0000ff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">(重复输入 :) )</td>
    </tr>
    <tr bgcolor=FFFFFF>
     <td valign=middle>&nbsp;您的E-MAIL：<br>(您可以选择不公开 )</td>
     <td><input type=text size=20 maxlength=75 name=addemail value=@ style="background-color:#ffffff; color:#ACC5FF; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">(很重要，用于寄送密码)<br>
<input type=checkbox name="publicmail" value="yes" checked>
<font color="#000000">公开邮箱 </font></td>
    </tr>
<?
if (!$method) {
print <<<EOT
    <tr bgcolor=$subcolor>
      <td align=center colspan=2>
	<input type=submit value="送出资料" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
	&nbsp; <input type=hidden value="2" name="step">
	<input type=reset value="清除重写" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
      </td>
    </tr>
   </table>
   </td>
 </tr></form>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=95% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>
EOT;
} else {
?>
    <tr bgcolor=EEEEEE> 
      <td>&nbsp;您的OICQ号码：</td>
      <td><b><input type=text size=20 maxlength=14 name="oicqnumber" value="" style="background-color:#ffffff; color:#0000ff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></b></td>
    </tr>
    <tr bgcolor=FFFFFF>
      <td>&nbsp;如果您有个人主页：</td>
      <td><b><input type=text size=20 maxlength=75 name="homepage" value="" style="background-color:#ffffff; color:#0000ff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></b></td>
    </tr>
    <tr bgcolor=EEEEEE>
      <td valign=middle>&nbsp;个性化签名：<br>&nbsp;将附在每篇文章后 <br>
&nbsp;<a href="javascript:openScript('vibfaq.php',700,500)"><font face=verdana>VIB Code</a> -
<?
if ($sign_use_vibcode) {
	echo ' 开启'; 
echo '<br>&nbsp;[img] &nbsp; -';
if ($vibcode_sign['pic']) echo ' 开启'; else echo ' 关闭';
echo '<br>&nbsp;[flash] -';
if ($vibcode_sign['flash']) echo " 开启"; else echo " 关闭";
echo '<br>&nbsp;[size]&nbsp; -';
if ($vibcode_sign['fontsize']) echo " 开启"; else echo " 关闭";
} else echo ' 关闭';
?></font>
</td>
      <td><b>
      <textarea cols=50 name="signature" style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver="this.style.backgroundColor = '#E5F0FF'" onMouseOut="this.style.backgroundColor = ''" rows="4"></textarea></b></td>
    </tr>
    <tr bgcolor=FFFFFF>
      <td valign=middle>&nbsp;来自：</td>
      <td><input type=text size=20 maxlength=20 name="fromwhere" style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></td>
    </tr>
    <tr bgcolor=EEEEEE>
      <td>&nbsp;自我简介：<br>&nbsp;限一百字</font></td>
      <td><textarea name=addcomment rows=4 cols=50 style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#f3f3f3'" onMouseOut = "this.style.backgroundColor = ''">我很懒,什么也不想写！</textarea></td>
    </tr>
    <tr align=left bgcolor=FFFFFF>
	<td align=left valign="middle">&nbsp;选择您的头像：<br>&nbsp;点<a href="javascript:openScript('listpic.php?dir=face',700,500)"><b>这里</b></a>看所有图<br>
	<br>&nbsp;<b>自定义头像：</b><br>
<?
if (!$use_own_portait) echo '&nbsp;- 被管理员关闭';
else echo '&nbsp;- 被管理员打开<br>你也可以在这里给出你自定义头像的 URL 地址，头像的高度和宽度(像素)。 如果不想要自定义头像，请将各选项留空';
?>
</td>
	<td valign=top>
<script language="javascript">
   function showimage(){
     document.images.useravatars.src="images/face/"+document.creator.usericon.options[document.creator.usericon.selectedIndex].value;}
</script>

	 <table width=100% border=0 cellspacing=0 cellpadding=0>
	  <tr>
	   <td width=22% align=center valign=middle> 
		<select value="no_portait.gif" name="usericon" onChange="showimage()">
<? 
	$dh=opendir("images/face");
	while ($imagefile=readdir($dh)) {
		if (($imagefile!=".") && ($imagefile!="..") && ($imagefile!="")) echo "<option value=\"$imagefile\">$imagefile</option>";
	}
	closedir($dh);
?> 
		</select>
	    </td>
	    <td width="78%" align=center valign=middle><img src="images/face/no_portait.gif" name="useravatars" border=0></td>
	   </tr>
	</table>
	<br>
<?
if ($use_own_portait) {
print <<<EOT
图像位置：<input type=text size=35 name=own_portait[0] style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">输入完整的 URL 路径。<br>
图像宽度：<input type=text size=2 maxlength=3 name=own_portait[1] style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">必须是 20 -- 100 之间的一个整数。<br>
图像高度：<input type=text size=2 maxlength=3 name=own_portait[2] style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">必须是 20 -- 100 之间的一个整数。
EOT;
}
?>
      </td>
    </tr>
    <tr bgcolor=EEEEEE> 
      <td align=center colspan=2>&nbsp;是否接受系统邮件： 
	<input type=radio name="receivemail" value="text" checked>
	接收文本邮件 
	<input type=radio name="receivemail" value="html">
	接收HTML邮件 
	<input type=radio name="receivemail" value="none">
	不接收邮件
      </td>
    </tr>
    <tr bgcolor=<?=$subcolor?>>
      <td align=center colspan=2>
	<input type=submit value="送出资料" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
	&nbsp; <input type=hidden value="2" name="step">
	<input type=reset value="清除重写" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
      </td>
    </tr>
   </table>
   </td>
 </tr></form>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=95% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>
<?
}
}
function print_fail() {
global $reason;
msg_box('注册出现错误',"错误原因：<br><br>$reason<br><br>请 <a href='javascript:history.back(1)'>返回</a> 并修正<br>");
}