<%
thispage="RegUser.asp"
%>
<%
'寻找注册来源，从来源判断代理商ID
Function GetAgentID()
	url=request.ServerVariables("HTTP_REFERER")
	url=Lcase(url)
	url=trim(replace(url,"http://",""))
	'如果来源为空，则为非法访问
	if url="" then
		ShowMsg "<strong><font color=red>严重警告：非法访问!</font></strong><br>以任何方式攻击、影响本站的正常运转都是一种犯法的行为，都将承担法律责任！"
	end if
	'在数据库中寻找来源
	strSQL="Select id From member Where m_webserver Like '%," &  url & ",%'"
	Set rsSub=Server.CreateObject("ADODB.RecordSet")
	rsSub.open strSQL,conn,1,1
	if rsSub.recordcount<=0 then
		ShowMsg "<strong><font color=red>错误提示：无法注册！</font></strong><br>出现这种现象的原因可能是因为：<li>1、该代理商尚未通过核实，或无效代理商！</li><li>2、数据服务器出现了问题!</li><br>请您及时向您的代理商反映，或Email:<a href=mailto:diy@jnbiz.com>diy@jnbiz.com</a>"
	end if
	GetAgentID=rsSub("id")
end Function
%>
<!--#Include File="conn.asp"-->
<!--#Include File="inc/const.asp"-->
<!--#Include File="inc/sub.asp"-->
<!--#Include File="inc/PrintMsg.asp"-->
<!--#Include File="CurrExecuteFile.asp"-->
<!--#include file="inc/char.asp"-->
<!--#include file="inc/email.asp"-->
<!--#include file="INC/md5.asp"-->

<%
	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"))

	'取得代理商ID
	Dim AgentID,AgentName
	AgentName = GetFormVariable("AgentName")
	if AgentName="" then
		AgentID = GetAgentID()
	else
		strSQL="Select id From member Where m_name='" & AgentName & "' And m_code>0"
		Set rsSub=Server.CreateObject("ADODB.RecordSet")
		rsSub.open strSQL,conn,1,1
		if rsSub.recordcount<=0 then
			ShowMsg "<strong><font color=red>错误提示：无法注册！</font></strong><br>出现这种现象的原因可能是因为：<li>1、该代理商尚未通过核实，或无效代理商！</li><li>2、数据服务器出现了问题!</li><br>请您及时向您的代理商反映，或Email:<a href=mailto:diy@jnbiz.com>diy@jnbiz.com</a>"
		end if
		AgentID=rsSub("id")
	end if

	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")=md5(password)
		end if

		rSub("m_email") = email
		rSub("m_oicq") = oicq
		rSub("m_AgentName") = Cint(AgentID)
		'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")="1"
		rSub("w_tel")=tel
		rSub("w_FootNote")="公司地址：未知<br>" & "电话：" & tel & " E-Mail:" & email & "<br>" & "Copyright&copy;" & year(date) & "-" & (year(date)+1) & " " & ComName & " All Rights Reserved."
	rSub.update
	rSub.close


	'添加该网站栏目
	'-----------------------------------------------------------------------
	
	'开始从模板中向栏目表中生成栏目
	strSQL="Select * From Templet_Menu Where t_code='1'"
	rSub.open strSQL,conn,1,1
	for i=1 to rSub.recordcount
		strSQL="Insert Into menu(m_id,tm_id,mn_index,mn_name,mn_href,mn_target,mn_class,mn_enable,mn_content) Values("	
		strSQL=strSQL & "" & strUserID & ","
		strSQL=strSQL & "'" & trim(rSub("id")) & "',"
		strSQL=strSQL & "" & trim(rSub("tm_index")) & ","
		strSQL=strSQL & "'" & trim(rSub("tm_text")) & "',"
		strSQL=strSQL & "'" & trim(rSub("tm_href")) & "',"
		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(LoginName,RealName,PassWord,m_id) Values('" & name & "','" & ComName & "','" & md5(password) & "'," & strUserID & ")"
	conn.execute strSQL,0,1
	
	
	strSQL="Select top 1 * From v_member Where m_name='" & name & "'"
	set rsMember=Server.CreateObject("ADODB.RecordSet")
	rsMember.open strSQL,conn,3,3
	Session("UserID")=trim(rsMember("id")) 					'账号ID
	Session("UserPass")=trim(rsMember("m_password"))			'账号密码
	Session("UserName")=trim(rsMember("m_name"))				'账号
	Session("UserCode")=trim(rsMember("m_code"))				'用户级别号
	Session("WebSiteID")=trim(rsMember("w_id"))				'用户站点ID
	Session("WebTitle")=trim(rsMember("w_Title"))				'网站标题
	Session("AgentID")=trim(rsMember("m_AgentName"))			'代理商ID
	Session("WebLanguage")=trim(rsMember("m_language"))		'用户网站所支持的语言
	Session("WebLamu")=trim(rsMember("m_lamu"))				'用户网站所支持的栏目
	Session("WebTemplet")=trim(rsMember("m_templet"))			'用户网站所支持模板
	Session("WebTplock")=trim(rsMember("m_tplock"))			'用户网站所支持模板
	rsMember.Close
	'mail服务器没配好，先不用
	'call easymail( email )
	strHOST=request.ServerVariables("SERVER_PORT")
	if strHOST<>"" And strHOST<>"80" then
		strHOST= ":" & strHOST
	else
		strHOST=""
	end if

	'发送一封 email 祝贺
	'------------------渀?潣潬??う?8?湯??錨?6?-----------------------------------------------------
	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>"

	strMyHome="http://" & request.ServerVariables("SERVER_NAME") & strHOST & "/Home/" & name 
	strOK= "<br><br><br><br>" &_
		"<font color=red>祝贺您，注册成功！</font><br><br>"&_
		"您的临时域名：<a href=" & strMyHome & " target=_blank>" &_
		"<font class=gface>" & strMyHome & "</font></a>" &_
		"，<br><br>您必须登录系统并设置网站属性后才能正常使用此站点" &_
		"，您也可以向您的服务商注册正式的域名。<br><br>" &_
		"您刚刚填写的注册资料已经发送到您指定的邮箱：<font class=gface>" & email & "</font><br><br>" &_
		"希望我们能为您提供最周到的服务，现在就开始建设您单位的网站吧，<a href=Admin_Manager.asp>网站建设</a>" &_
		"<br><br><br><br><br><br>"

%>
<!--#include file="CreateWebSite.asp"-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>电子商务自助建站--您理想的助手</title>
<link href="common/styleMain.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top">
<table width="100%" height="100" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td height="0" align="center"><table width="750" cellpadding="0" cellspacing="0" class="table001">
              <tbody>
				<form name="login" action="chklogin.asp" method="post">
                <tr> 
                  <td height="25" align=left class="white"> 　· 单位注册	
                  </td>
                  <td align=right class="white">&nbsp;	
                  </td>
                </tr>
				</form>
                <tr> 
                  <td height="6" colspan="2" align=left bgcolor="#bad2f0" class="white"></td>
                </tr>
            </table></td>
        </tr>
        <tr> 
          <td height="100%" align="center"><table border=0 cellpadding=0 cellspacing=0 class=table002>
              <tbody>
                <tr> 
                  <td width="100%" valign="middle" align="center"><%=strOK%></td>
                </tr>
              </tbody>
            </table></td>
        </tr>
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/bottom.asp"-->
		  </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
