<!--#include file="conn.asp"-->
<%
'如果已经选好语言，改变用户致相应应该的位置
if GetVariable("txtAction")="next" then

	strUserName=trim(Session("UserName"))
	strGBName=strUserName
	pn=instr(strUserName,"_")
	if pn>0 then
		strUserName=left(strUserName,pn-1)
		strGBName=strUserName
	end if
	
	'如果选择为空，表示默认语言
	if GetFormVariable("rdlanguage")<>"" then
		strUserName=strUserName & "_" & GetFormVariable("rdlanguage")
		strSQL="Select id,m_name,w_id,w_Title From v_member Where m_name='" & strUserName & "'" 
		set rs=Server.CreateObject("ADODB.RecordSet")
		rs.open strSQL,conn,1,1

		'如果所选的语言没有创建，则需要创建相关注册资料
		if rs.recordcount<=0 then
			rs.close
			'==========================================================================================
				'添加该网站管理者信息
				'-----------------------------------------------------------------------
				rSub.open "select * from [member]",conn,1,3
				rSub.addnew
					rSub("m_name")=strUserName
					rSub("m_password") = Session("UserPass")
					'rSub("m_oicq") = ""
					'rSub("m_AgentName") = Cint(Session("AgentID"))
				rSub.update
				rSub.close
			
				'先取得用户的ID
				strSQL="Select id From member Where m_name='" & strUserName  & "'"
				rSub.open strSQL,conn,1,1
				strUserID=rSub("id")
				rSub.close()
				
				Session("UserID")=strUserID 					'账号ID
				Session("UserName")=strUserName 				'用户名称

				
				'添加该网站基本信息
				'-----------------------------------------------------------------------
				strTemplet=Left(GetFormVariable("rdlanguage"),3) & "1"
				rSub.open "select * from [website]",conn,,3
				rSub.addnew
					rSub("m_id")=strUserID
					rSub("w_ComName")=Session("WebTitle")
					'rSub("w_Mail")=email
					rSub("w_templet")=strTemplet
					'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
				
				'先取得用户WebSit的ID
				strSQL="Select id From [website] Where m_id=" & strUserID  & " And w_templet='" & strTemplet & "'"
				rSub.open strSQL,conn,1,1
				strWebSiteID=rSub("id")
				rSub.close()
				Session("WebSiteID")=strWebSiteID			'用户站点ID
			
				'添加该网站栏目
				'-----------------------------------------------------------------------
				
				'开始从模板中向栏目表中生成栏目
				strSQL="Select * From Templet_Menu Where t_code='" & strTemplet & "'"
				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('" & strGBName & "','" & Session("WebTitle") & "','" & Session("UserPass") & "'," & strUserID & ")"
				'conn.execute strSQL,0,1
				
				
				'生成原始站点
				response.Redirect("Admin_Attrib.asp?action=createsite")
							
			'==========================================================================================
			
		else
			'该语言用户已经存在
			Session("UserID")=trim(rs("id"))				'账号ID
			Session("UserName")=trim(rs("m_name")) 		'用户名称
			Session("WebSiteID")=trim(rs("w_id"))			'用户站点ID
			Session("WebTitle")=trim(rs("w_Title"))		'网站标题
		end if
	else
		'使用默认语言
		if Instr(Session("UserName"),"_")>0 then
			strSQL="Select id,m_name,w_id,w_Title From v_member Where m_name='" & strUserName & "'" 
			set rs=Server.CreateObject("ADODB.RecordSet")
			rs.open strSQL,conn,1,1	
			Session("UserID")=trim(rs("id")) 				'账号ID
			Session("UserName")=trim(rs("m_name")) 		'用户名称
			Session("WebSiteID")=trim(rs("w_id"))			'用户站点ID
			Session("WebTitle")=trim(rs("w_Title"))		'网站标题
		end if
	end if
	
	response.Redirect("Admin_Attrib.asp")
end if

'如果是修改域名
if GetVariable("txtAction")="save" then

	strSQL="Select id From  v_website Where m_name='" & GetFormVariable("txtUserName") & "'"
	rs.open strSQL,conn,1,1
	if rs.recordcount<=0 then
		ShowMsg "对不起，不能给没有生成内容的语言版本绑定域名，请先对其设置并生成相应网站！"
	end if
	
	strSQL="Update v_website Set w_domain='" & GetFormVariable("txtDomain") & "' Where m_name='" & GetFormVariable("txtUserName") & "'"
	conn.execute strSQL,0,1
	
end if
%>

<%
	'检查用户对语言的支持
	if instr(Session("WebLanguage"),"GB")<=0 then
		strGB="Disabled"
	end if
	if instr(Session("WebLanguage"),"Big5")<=0 then
		strBig5="Disabled"
	end if
	if instr(Session("WebLanguage"),"Eng")<=0 then
		strEng="Disabled"
	end if
	if instr(Session("WebLanguage"),"Jap")<=0 then
		strJap="Disabled"
	end if
	if instr(Session("WebLanguage"),"Kor")<=0 then
		strKor="Disabled"
	end if

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>电子商务自助建站--您理想的助手</title>
<link href="common/styleMain.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function SaveDomain(strUserName,strDomain){
	form1.txtUserName.value=strUserName;
	form1.txtDomain.value=strDomain;
	form1.txtAction.value="save";
}
function GoNext(){
	form1.txtAction.value="next";
}
</script>
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/top.asp"-->
          </td>
        </tr>
        <tr> 
          <td height="100%" align="center" valign="top">
<TABLE class=table002 cellSpacing=0 cellPadding=0 border=0>
              <TBODY>
                <TR> 
                  <!--左边开始-->
                  <TD vAlign=top align=right width="20%">
					  <!--#include file="common/left.asp"-->
				  </TD>
                  <!--左边结束-->
                  <TD width="2%" background="images/rowline.gif">&nbsp;</TD>
                  <!--右边开始-->
                  <TD vAlign=top align=middle width="78%">
				  
				  <form name="form1" method="post" action="?">
                      <TABLE width="100%" height="100%" border=0 cellPadding=6 cellSpacing=0>
                        <TBODY>
                          <TR> 
                            <TD vAlign=top align=left bgColor=#ffffff><B>选择网站语言</B><BR> 
                              <HR SIZE=1>
                              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr> 
                                  <td width="20%">＞请选择网站语言：</td>
                                  <td width="80%">&nbsp;</td>
                                </tr>
                                <tr align="center"> 
                                  <td colspan="2"> 
                                    <table width="82%" border="0">
                                      <tr> 
                                        <td><input name="txtAction" type="hidden" id="txtAction">
                                          <input name="txtUserName" type="hidden" id="txtUserName">
                                          <input name="txtDomain" type="hidden" id="txtDomain"></td>
                                      </tr>
                                      <tr> 
                                        <td>　　以下是您可以选择的网站语言，请从中选择一项，如果您想要的语言在列表中不可用，请与我们的代理商联系<strong>！</strong></td>
                                      </tr>
                                      <tr> 
                                        <td height="0" align="center"> 
                                          <fieldset>
                                          <legend><strong>目前所支持网站语言</strong></legend>
                                          <table width="85%" border="0" cellpadding="5">
                                            <tr> 
											<%
											strUserName=trim(Session("UserName"))
											pn=instr(strUserName,"_")
											if pn>0 then
												strUserName=left(strUserName,pn-1)
											end if
											%>
                                              <td width="42%"><input name="rdlanguage" type="radio" value="" checked>
                                                中文版</td>
                                              <td width="58%">
											  <%
											  strSQL="Select w_domain From v_website Where m_name='" & strUserName & "'"
											  Set rsSub = Server.CreateObject("ADODB.RecordSet")
											  rsSub.open strSQL,conn,1,1
											  if rsSub.recordcount>0 then
												  strDomain=Trim(rsSub("w_domain"))
											  else
											  	 strDomain=""
											  end if
											  rsSub.close
											  %>
											  <input name="txtDomain_GB" type="text" id="txtDomain_GB" value="<%=strDomain%>" size="25" maxlength="100">
                                              <input type="submit" name="Submit" value="绑定" onClick="SaveDomain('<%=strUserName%>',form1.txtDomain_GB.value)"></td>
                                            </tr>
                                            
                                            <tr> 
                                              <td><input name="rdlanguage" type="radio" value="Eng" <%=strEng%>>
                                                英文（English）</td>
                                              <td>
											  <%
											  strSQL="Select w_domain From v_website Where m_name='" & strUserName & "_Eng'"
											  Set rsSub = Server.CreateObject("ADODB.RecordSet")
											  rsSub.open strSQL,conn,1,1
											  if rsSub.recordcount>0 then
												  strDomain=Trim(rsSub("w_domain"))
											  else
											  	 strDomain=""
											  end if
											  rsSub.close
											  %>
											  <input name="txtDomain_Eng" type="text" id="txtDomain_Eng" value="<%=strDomain%>" size="25" maxlength="100" <%=strEng%>>
                                                <input type="submit" name="Submit23" value="绑定" onClick="SaveDomain('<%=strUserName%>_Eng',form1.txtDomain_Eng.value)" <%=strEng%>></td>
                                            </tr>
                                            <tr> 
                                              <td><input name="rdlanguage" type="radio" value="Kor" <%=strKor%>>
                                                韩国文 （Korean）</td>
                                              <td>
											  <%
											  strSQL="Select w_domain From v_website Where m_name='" & strUserName & "_Kor'"
											  Set rsSub = Server.CreateObject("ADODB.RecordSet")
											  rsSub.open strSQL,conn,1,1
											  if rsSub.recordcount>0 then
												  strDomain=Trim(rsSub("w_domain"))
											  else
											  	 strDomain=""
											  end if
											  rsSub.close
											  %>
											  <input name="txtDomain_Kor" type="text" id="txtDomain_Kor" value="<%=strDomain%>" size="25" maxlength="100" <%=strKor%>>
                                                <input type="submit" name="Submit232" value="绑定" onClick="SaveDomain('<%=strUserName%>_Kor',form1.txtDomain_Kor.value)" <%=strKor%>></td>
                                            </tr>
                                            <tr> 
                                              <td><input name="rdlanguage" type="radio" value="Jap" <%=strJap%>>
                                                日文 （Japanese）</td>
                                              <td>
											  <%
											  strSQL="Select w_domain From v_website Where m_name='" & strUserName & "_Jap'"
											  Set rsSub = Server.CreateObject("ADODB.RecordSet")
											  rsSub.open strSQL,conn,1,1
											  if rsSub.recordcount>0 then
												  strDomain=Trim(rsSub("w_domain"))
											  else
											  	 strDomain=""
											  end if
											  rsSub.close
											  %>
											  <input name="txtDomain_Jap" type="text" id="txtDomain_Jap" value="<%=strDomain%>" size="25" maxlength="100" <%=strJap%>>
                                                <input type="submit" name="Submit2322" value="绑定" onClick="SaveDomain('<%=strUserName%>_Jap',form1.txtDomain_Jap.value)" <%=strJap%>></td>
                                            </tr>
                                            <tr> 
                                              <td height="5" colspan="2"></td>
                                            </tr>
                                          </table>
                                          </fieldset>
                                          <legend></legend> 
                                        </td>
                                      </tr>
                                      <tr>
                                        <td height="46" align="right">[如果您想要的不在这里，请与您的代理商联系！] 
                                        </td>
                                      </tr>
                                    </table>
                                  </td>
                                </tr>
                              </table> 
                              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr> 
                                  <td height="13" align="center"> </input> </td>
                                </tr>
                                <tr> 
                                  <td height="40" align="center"> 
                                    <input type=submit value=" 选好啦，下一步 " name=Submit22 onClick="GoNext()">
                                    　</td>
                                </tr>
                              </table> 
                            </TD>
                          </TR>
                        </TBODY>
                      </TABLE>
                    </form></TD>
                </TR>
              </TBODY>
            </TABLE></td>
        </tr>
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/bottom.asp"-->
		  </td>
        </tr>
      </table></td>
  </tr>
</table>
<%
'如果是选择了绑定语言，则重新应用网站，但跳过生成菜单步骤
if GetVariable("txtAction")="save" then
	response.Write("<iframe src='update.asp?js=1' width='0' height='0' frameborder='0'></iframe>")
end if
%>

<%
Sub bdDomain()
	Dim strUserName,strGBName
	strUserName=trim(Session("UserName"))
	
	'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	'处理多语言问题
	pn=instr(strUserName,"_")
	if pn>0 then
		strGBName=left(strUserName,pn-1)
	else
		strGBName=strUserName
	end if
				
	strJsText=strJsText & vbCrLf & "//处理多语言问题"  & vbCrLf
	strDoMain=request.ServerVariables("SERVER_NAME")
	if request.ServerVariables("SERVER_PORT")<>"" then
		strDoMain=strDoMain & ":" & request.ServerVariables("SERVER_PORT")
	end if
	strDoMain="http://" & strDoMain & "/Home/" & strGBName
				
	'中文简体
	strSQL="Select w_domain From v_website Where m_name='" & strGBName & "'"
	Set rsSub=Server.CreateObject("ADODB.RecordSet")
	rsSub.open strSQL,conn,1,1
	if rsSub.RecordCount>0 then
		if Trim(rsSub("w_domain"))="" then
			strJsText=strJsText & "	lgGB2312=""" & strDoMain & """;" & vbCrLf
		else
			strJsText=strJsText & "	lgGB2312=""" & Trim(rsSub("w_domain")) & """;" & vbCrLf
		end if
	else
		strJsText=strJsText & "	lgGB2312=null;" & vbCrLf
	end if
	rsSub.Close
				
	'中文繁体
	strSQL="Select w_domain From v_website Where m_name='" & strGBName & "_Big5'"
	Set rsSub=Server.CreateObject("ADODB.RecordSet")
	rsSub.open strSQL,conn,1,1
	if rsSub.RecordCount>0 then
		if Trim(rsSub("w_domain"))="" then
			strJsText=strJsText & "	lgBig5=""" & strDoMain & "_Big5"";" & vbCrLf
		else
			strJsText=strJsText & "	lgBig5=""" & Trim(rsSub("w_domain")) & """;" & vbCrLf
		end if
	else
		strJsText=strJsText & "	lgBig5=null;" & vbCrLf
	end if
				rsSub.Close
				
				strSQL="Select w_domain From v_website Where m_name='" & strGBName & "_Eng'"
				Set rsSub=Server.CreateObject("ADODB.RecordSet")
				rsSub.open strSQL,conn,1,1
				if rsSub.RecordCount>0 then
					if Trim(rsSub("w_domain"))="" then
						strJsText=strJsText & "	lgEnglish=""" & strDoMain & "_Eng"";" & vbCrLf
					else
						strJsText=strJsText & "	lgEnglish=""" & Trim(rsSub("w_domain")) & """;" & vbCrLf
					end if
				else
					strJsText=strJsText & "	lgEnglish=null;" & vbCrLf
				end if
				rsSub.Close
				
				strSQL="Select w_domain From v_website Where m_name='" & strGBName & "_Kor'"
				Set rsSub=Server.CreateObject("ADODB.RecordSet")
				rsSub.open strSQL,conn,1,1
				if rsSub.RecordCount>0 then
					if Trim(rsSub("w_domain"))="" then
						strJsText=strJsText & "	lgKorean=""" & strDoMain & "_Kor"";" & vbCrLf
					else
						strJsText=strJsText & "	lgKorean=""" & Trim(rsSub("w_domain")) & """;" & vbCrLf
					end if
				else
					strJsText=strJsText & "	lgKorean=null;" & vbCrLf
				end if
				rsSub.Close
				
				strSQL="Select w_domain From v_website Where m_name='" & strGBName & "_Jap'"
				Set rsSub=Server.CreateObject("ADODB.RecordSet")
				rsSub.open strSQL,conn,1,1
				if rsSub.RecordCount>0 then
					if Trim(rsSub("w_domain"))="" then
						strJsText=strJsText & "	lgJapanese=""" & strDoMain & "_Jap"";" & vbCrLf
					else
						strJsText=strJsText & "	lgJapanese=""" & Trim(rsSub("w_domain")) & """;" & vbCrLf
					end if
				else
					strJsText=strJsText & "	lgJapanese=null;" & vbCrLf
				end if
				rsSub.Close
				

		'把init.JS菜单配置部份取出，下面和语言配置一起写到init.js
		JsFile=Server.MapPath( "home/" & strUserName  & "/common/init.js" )
		set objTextFile=fs.OpenTextFile(JsFile,1)
		strAllText=objTextFile.ReadAll
		objTextFile.close
		pn=instr(strAllText,"//处理多语言问题")
		strStarText=left(strAllText,pn-1)
	
		'写文件Init.js
		JsFile=Server.MapPath( "home/" & strUserName  & "/common/init.js" )
		set objTextFile=fs.OpenTextFile(JsFile,2)
		objTextFile.WriteLine strStarText & strJsText & strEndText
		objTextFile.close
		
End Sub
%>

</body>
</html>
