<!--#include file="base.asp"-->
<!--#include file="inc/char.asp"-->
<!--#include file="inc/email.asp"-->
<%
	const ThisPage = "reg.asp"
%>

<SCRIPT language=JavaScript>
function CheckIfEnglish( String ){ 
	var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
	var i;
	var c;
	if(String.length>30) return false;
	for( i=0; i<String.length; i++ ) {
		c = String.charAt( i );
		if( Letters.indexOf( c ) < 0 ) return false;
	}
	return true;
}

function submitchecken() {
	if(document.reg.name.value == "") {
		alert("请输入一个用户名。");
		document.reg.name.focus();
		return false;
	}
	if(document.reg.password.value == "") {
		alert("请输入一个密码。");
		document.reg.password.focus();
		return false;
	}
	if(document.reg.confirmPwd.value == "") {
		alert("请输入一个验证密码。");
		document.reg.confirmPwd.focus();
		return false;
	}

	if(document.reg.ComName.value == "") {
		alert("请输入您单位的名称。");
		document.reg.ComName.focus();
		return false;
	}

	if( !CheckIfEnglish(document.reg.name.value ) ) {
		alert("用户名只能是英文、数字和下划线并且少于 30 个字符！");
		document.reg.name.focus();
		return false;
	}

	return true;
}
</SCRIPT>


<table border=0 cellpadding=0 cellspacing=0 class=table002>
<tbody>
  <tr>
    <td width="100%" valign="top" align="center">

<%
if GetVariable("action")="SaveAdd" then
	Call saveuser()
else
	Call adduser()
end if
%>

    </td>
  </tr>
</tbody>
</table>



<!--#include file=footer.asp-->




<%
'添加用户开始
Sub AddUser()
%>

<table border="0" cellspacing="1" cellpadding="1"  align=center>
<form method="post" name="reg" action=<%=ThisPage%>?action=SaveAdd>
  <tr> 
	<td height="60" colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;请注意您注册即为遵守我们的协议</td>
  </tr>

  <tr>
	<td align=right width=30%><font color=#FF0000>*</font>单位域名：</td>
	<td width=70%><input type=text name="name" value="" size=19 class=Input_line><font face=verdana color=red><b>.<%=HOST%></b></font> <span class=gray>::<span class=Vgray>≤30</span> 个英文或数字</span></td>
  </tr>

  <tr>
	<td align=right width=30%><font color=#FF0000>*</font>单位名称：</td>
	<td width=70%><input type=text name="ComName" value="" size=30> <span class=gray>::<span class=Vgray>≤100</span> 个字符</span></td>
  </tr>

  <tr>
	<td align=right><font color=#FF0000>*</font>密 &nbsp;码：</td>
	<td><input type="password" name="password" value="" size=30> 
		<span class=gray>::<span class=Vgray>≤20</span> 个字符，前后不允许有空格
	</td>
  </tr>

  <tr>
	<td align=right><font color=#FF0000>*</font>验证密码：</td>
	<td><input type="password" name="confirmPwd" size=30></td>
  </tr>

  <tr>
	<td align=right><font color=#FF0000>*</font><font face=verdana>e-mail</font>：</td>
	<td><input type=text name="email" value="" size=30></td>
  </tr>

  <tr>
	<td align=right>联系电话：</td>
	<td><INPUT type=text name="tel" value="" size=30></td>
  </tr>

  <tr>
	<td align=right>OICQ号码：</td>
	<td><INPUT type=text name="oicq" value="" size=30></td>
  </tr>

  <tr>
	<td colspan=2 align=center height=90>
	<input type=hidden name="AgentName" value="<%=Lcase(Trim(GetVariable("AgentName")))%>">
	<input type=hidden name="FriendName" value="<%=Lcase(Trim(GetVariable("FriendName")))%>">
	<input type="submit" name="Submit" value="提 交" onClick="return submitchecken();"> 
	<input type="reset" name="reset" value="重 填">
	</td>
  </tr>
</form>
</table>
<%
End Sub
'添加用户结束




'修改用户开始
Sub saveuser()
'	if Session("RegLimit")("RegDate") <> "" then
'		PrintMsg "一台电脑每天只能注册一位用户。"
'	end if

	name=Lcase(trim(GetVariable("name")))
	ComName = trim(GetVariable("ComName"))
	password = trim(GetVariable("password"))
	confirmPwd = trim(GetVariable("confirmPwd"))

	email = trim(GetVariable("email"))
	tel = trim(GetVariable("tel"))
	oicq = trim(GetVariable("oicq"))

	AgentName = Lcase( Trim(GetVariable("AgentName")) )
	FriendName = Lcase( Trim(GetVariable("FriendName")) )

	if name="" then
		OutMsg=OutMsg+"\n"+"    请输入用户名。"
		founderr=true
	elseif not IfEnglish(name) then
		OutMsg=OutMsg+"\n"+"    单位域名只能是英文、数字和下划线并且少于 30 个字符！"
		founderr=true
	end if

	if ComName="" then
		OutMsg=OutMsg+"\n"+"    请输入单位名称。"
		founderr=true
	elseif len(ComName)>100 then
		OutMsg=OutMsg+"\n"+"    单位名称不能大于 100 个字符。"
		founderr=true
	end if



	if password="" then
		OutMsg=OutMsg+"\n"+"    请输入一个密码。"
		founderr=true
	elseif not IfEnglish( password ) then
		OutMsg=OutMsg+"\n"+"    密码必须为字符、数字和下划线的组合。"
		founderr=true
	elseif confirmPwd<>password then
		OutMsg=OutMsg+"\n"+"    密码和验证密码不一样，请输入正确的验证密码。"
		founderr=true
	elseif len(password)>20 or len(confirmPwd)>20 then
		OutMsg=OutMsg+"\n"+"    您输入的密码或验证密码太长，已经超过 20 个字符。"
		founderr=true
	end if


	if email="" then
		OutMsg=OutMsg+"\n"+"    请输入一个邮箱地址。"
		founderr=true
	elseif not IsValidEmail(email) then
		OutMsg=OutMsg+"\n"+"    请输入一个合法的邮箱地址。"
		founderr=true
	end if

	if len(tel)>50 then
		OutMsg=OutMsg+"\n"+"    您的电话号码是通向河外星系的吧，50多位了呀！"
		founderr=true
	end if

	if len(oicq)>20 then
		OutMsg=OutMsg+"\n"+"    您的 OICQ 号太长，已经超过 20位。"
		founderr=true
	end if

	if founderr=true then
		Call PrintMsg(OutMsg)
	end if


	'验证帐号是否存在
	'-----------------------------------------------------------------------
	rSub.Open "select m_name from [member] where m_name='"&name&"'",conn,1,1
		if not(rSub.eof or rSub.bof) then
			Call PrintMsg("该用户名已经存在，请选择其他用户名！")
		end if
	rSub.close

	rSub.Open "select m_email from [member] where m_email='"&email&"'",conn,1,1
		if not(rSub.eof or rSub.bof) then
			Call PrintMsg("一个邮件地址只能注册一位用户！")
		end if
	rSub.close


	'受到保护的帐号
	'-----------------------------------------------------------------------
	if not chkProtectName(name) then
		PrintMsg "该用户名已经存在！"
	end if





	'添加该网站管理者信息
	'-----------------------------------------------------------------------
	rSub.open "select * from [member]",conn,1,3
	rSub.addnew
		rSub("m_name")=name
		if password<>"" then
			rSub("m_password")=password
		end if

		rSub("m_email") = email
		rSub("m_oicq") = oicq
		rSub("m_AgentName") = AgentName
		'rSub("FriendName") = FriendName

	rSub.update
	rSub.close

	'先取得用户的ID
	strSQL="Select id From member Where m_name='" & name  & "'"
	rSub.open strSQL,conn,1,1
	strUserID=rSub("id")
	rSub.close()

	'添加该网站基本信息
	'-----------------------------------------------------------------------
	rSub.open "select * from [website]",conn,1,3
	rSub.addnew
		rSub("m_id")=strUserID
		rSub("w_ComName")=ComName
		rSub("w_Mail")=email
		rSub("w_templet")="2"
		rSub("w_tel")=tel
	rSub.update
	rSub.close


	'添加该网站栏目
	'-----------------------------------------------------------------------
	
	'开始从模板中向栏目表中生成栏目
	strSQL="Select * From Templet_Menu Where t_code='2'"
	rSub.open strSQL,conn,1,1
	for i=1 to rSub.recordcount
		strSQL="Insert Into menu(m_id,l_code,mn_index,mn_name,mn_href,mn_target,mn_class,mn_enable,mn_content) Values("	
		strSQL=strSQL & "" & strUserID & ","
		strSQL=strSQL & "'" & trim(rSub("l_code")) & "',"
		strSQL=strSQL & "" & trim(rSub("tm_index")) & ","
		strSQL=strSQL & "'" & trim(rSub("tm_text")) & "',"
		strSQL=strSQL & "'" & trim(rSub("tm_herf")) & "',"
		strSQL=strSQL & "'" & trim(rSub("tm_target")) & "',"
		strSQL=strSQL & "'" & trim(rSub("tm_class")) & "',"
		strSQL=strSQL & "" & rSub("tm_enable") & ","
		strSQL=strSQL & "'" & trim(rSub("tm_content")) & "')"
		conn.execute strSQL,0,1
		rSub.movenext
	next
	rSub.close
	
	'初始化网站管理员
	'strSQL="insert into web_admin(realname, m_id) Values('" & name & "', " & strUserID & ")"
	'conn.execute strSQL,0,1


	'用 Cookies 限制每台计算机每天只能注册一个用户（其实没有用）
	'-----------------------------------------------------------------------
'	Session("RegLimit").Expires=now()+10
'	Session("RegLimit")("RegDate") = now()



	'发送一封 email 祝贺
	'-----------------------------------------------------------------------
	topic = "企业上网平台祝贺信！"
	mailbody = "尊敬的 " & ComName & "：<br>" &_
		"&nbsp;&nbsp;&nbsp;&nbsp;您好！<br>" &_
		"&nbsp;&nbsp;&nbsp;&nbsp;感谢您注册我们的企业上网系统，为了防止遗忘，现在将您的注册时填写的资料发到您指定的信箱。<br><br>" &_
		"&nbsp;&nbsp;&nbsp;&nbsp;您的资料如下：<UL type=square>" &_
		"<LI>单位域名：<a href=""http://" & name & "." & HOST & """ target=_blank>" &_
		"http://" & name & "." & HOST & "</a></LI>" &_
		"<LI>用 户 名：" & name & "</LI>" &_
		"<LI>管理密码：" & password & "</LI>" &_
		"<LI>OICQ号码：" & oicq & "</LI>" &_
		"<LI>电话号码：" & tel & "</LI>" &_
		"<br><br><LI>网站管理入口：" &_
		"<a href=""http://" & HOST & """ target=_blank>http://" & HOST & "</a></LI>" &_
		"</UL>"

	'mail服务器没配好，先不用
	'call easymail( email )





	response.write "<br><br><br><br><br><br>" &_
		"<font color=red>祝贺您，注册成功！</font><br><br>"&_
		"你单位的域名是：<a href=""http://" & name & "." & HOST & """ target=_blank>" &_
		"<font class=gface>" & name & "." & HOST & "</font></a>" &_
		"，您现在就可以浏览它 ，点击一下，瞧瞧吧 ^_^<br><br>" &_
		"你刚刚填写的注册资料已经发送到您指定的邮箱：<font class=gface>" & email & "</font><br><br>" &_
		"希望我们能为您提供最周到的服务，现在就开始建设您单位的网站吧，<a href=" & ThisPage & ">点击登录</a>" &_
		"<br><br><br><br><br><br><br><br>"

end sub
'修改用户结束



function chkProtectName(NewName) '-------new
	dim ArrProtectName,ProtectName
	chkProtectName=false
	ProtectName="www|web|8n6|admin|webmaster|master|test|info|home|news|go|asp|bbs|forum|girl|boy|sex|sexy"

	ArrProtectName=split(ProtectName,"|")
	for i=0 to ubound(ArrProtectName)
		if trim(ArrProtectName(i))=trim(NewName) then
			chkProtectName=false
		else
			chkProtectName=true
		end if
		if chkProtectName=false then exit for
	next
end function
%>
