<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
selectedserverid=0'默认首选的服务器ID
'canselectdb=true'改成false时将会送两个数据库(此设置在2008-2-19后改为在管理区，产品管理，虚拟主机中设置)
isagentpd=false
If session("agentusername")<>"" Then Response.Redirect "/agent/admhost2.asp?username="&session("agentusername")&"&id="&Request.QueryString ("id")
If session("username")="" Then
If Application("hpsystem")=false And Application("canuseorder")=true and Request.ServerVariables("HTTP_FreeHostAPI")<>"7i24.com" Then Response.Redirect "order.asp?type=虚拟主机&id="&Request.QueryString ("id")
	ef=True
	ec="请您先登陆会员区。"
ElseIf Request.QueryString ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request.QueryString ("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request.QueryString ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsHostpdlist = Server.CreateObject("ADODB.Recordset")

agentname=session("agentname")
if session("AgnRunasUser")=True then 
	Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent where username='"&agentname&"'"
		dsagent.Open Sql,conn,1,1
if Not dsagent.eof then
Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"&dsagent("agenttype")&"'" 
		dsagnettype.Open Sql,conn,1,1
if Not dsagnettype.eof Then
canshowagnpric=True
Else
canshowagnpric=false
End if
end If
dsagent.close
end If

	Sql="Select * from FreeHost.FreeHost_HostProductlist where id='"&Request.QueryString ("id")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsHostpdlist.Open Sql,conn,1,1
if dsHostpdlist.Eof then
	ef=True
	ec="产品不存在！"
Else
Hosttype=dsHostpdlist("Hosttype")
If dsHostpdlist("cantwodb")=true Then
canselectdb=false
else
canselectdb=true
End If
If dsHostpdlist ("isagentpd")=True Then isagentpd=true'代理的产品
'读取月付
PAY_Month=dsHostpdlist("PAY_Month")
PAY_Season=dsHostpdlist("PAY_Season")
PAY_halfyear=dsHostpdlist("PAY_halfyear")
PAY_Nextyear=dsHostpdlist("PAY_Nextyear")
PAY_2year=dsHostpdlist("PAY_2year")
PAY_3year=dsHostpdlist("PAY_3year")
PAY_4year=dsHostpdlist("PAY_4year")
PAY_5year=dsHostpdlist("PAY_5year")
end if
end if

if not ef then
if agentname<>"n" then
	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist_AGN where id='"&dsHostpdlist ("id")&"' and agent1='"&agentname&"'"
	agnserverid.Open Sql,conn,1,1
dim isAgnHostSer
if not agnserverid.Eof then
Hosttype=agnserverid("Hosttype")
if agnserverid ("ServerlistID")<>0 then
ServerlistID=agnserverid ("ServerlistID")
isAgnHostSer=true
else
isAgnHostSer=false
end if
end if
end if
end if

if not ef Then
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>
　虚拟主机自助开通
<%=htmlwrite("html3")%>
<br>
<script>
function Createregxml()
{
	try{
		regxml = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		try{

		regxml = new ActiveXObject("Msxm12.XMLHTTP");
		}catch(E){
		    regxml = false;
		}
	}
	
	if(!regxml && typeof XMLHttpRequest != 'undefined')
	{
	 regxml =new XMLHttpRequest();
	}
	return regxml;
}

function returnI()
{
	if(regxml.readyState == 4)
	{
	    var Data = regxml.responseText;
		if( Data == "ok")
		{
		  var divobj = document.getElementById("divusername");  
		   divobj.innerHTML = "<font color=greed>√</font>可以使用检查通过。";
		}
		else
		{
		   var divobj = document.getElementById("divusername");
		   divobj.style.display = "block";
		   divobj.innerHTML = "<font color=red>×</font>这个FTP名已经被使用了，请换一个";
		}
	}
}

function checkabc(tempstr)
{
	ptempstr=new String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
	for(i=0;i<tempstr.length;i++)
	{
		if(ptempstr.indexOf(tempstr.charAt(i))==-1)
		{
			return false;
		}
	}
	
	return true;
}
function checkusername(name)
{
	if (name.length>14 |name.length<6)
	{
	   var divobj = document.getElementById("divusername");
       divobj.innerHTML = "<font color=red>X</font>FTP名长度需要在6-14之间!";

	}
	else
	{
		if(checkabc(name))
		{
			regxml = Createregxml();
			regxml.onreadystatechange=returnI;
			<%If isagentpd=false Then%>
			var url = "/api/checkftpname.asp?";
			<%else%>
			var url = "/api/checkftpname.asp?isagentpd=yes&pdid=<%=dsHostpdlist("id")%>&";			
			<%end if%>
			regxml.open("GET",url+"ftpname="+name);
			regxml.send(null);

			 
		}
		else
		{
		   var divobj = document.getElementById("divusername");
		   divobj.innerHTML = "<font color=red>×</font>FTP名只能包含数字和字母";
		}
	}
}
function Iusername()
{
		  var divobj = document.getElementById("divusername");
		  divobj.innerHTML = "提醒：6-14个数字和字母。";
}

</script>
<form action="selfhost2.asp" method="post" name="autoopen">
<TABLE 
            width="100%" border=1 align=center cellPadding=0 cellSpacing=0 borderColorLight=#cccccc borderColorDark=#fbfbfb>
  <TBODY>
    <TR>
      <TD width="18%" rowspan="2" vAlign=middle bgColor=#9E9E9E>&nbsp; <font color="#FFFFFF">填写资料：</font></TD>
      <TD width="18%" height="40" bgColor=#ffffff><font color="#000000">　产品名：</font></TD>
      <TD width="64%" height="40" colspan="2" bgColor=#ffffff>　<%=Hosttype%></TD>
    </TR>
    <TR>
      <TD height="40" bgColor=#ffffff><font color="#000000">　绑定域名：</font></TD>
      <TD width="64%" height="40" colspan="2" bgColor=#ffffff><%if Application("openmustre")=true then%>
        请您在开通虚拟主机后，再到自助管理中绑定域名
          <%else%>
          <input name="hostname1" type="text" id="host1" size="25">
          <input name="txtinfo" type="text" value="(没有域名可以不用填写)" size="20" readonly="true" style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" >
        <%end if%></TD>
    </TR>
    <TR>
      <TD width="18%" rowspan="7" vAlign=middle bgColor=#EEEEEE>&nbsp;</TD>
      <TD height="40" bgColor=#ffffff><font color="#000000">　FTP用户名：</font></TD>
      <TD width="90" height="40" bgColor=#ffffff><input name="Ftpname" type="text" id="Ftpname" size="10" maxlength="14"  onblur=checkusername(this.value) onfocus=Iusername()></TD>
      <TD bgColor=#ffffff>
<div id="divusername">(6至14个字母或数字)</div>
		</TD>
    </TR>

    <TR>
      <TD height="40" bgColor=#ffffff><font color="#000000">　FTP密 码：</font></TD>
      <TD width="64%" height="40" colspan="2" bgColor=#ffffff>由系统自动分配
        <%
If canselectdb then
	Set dsSqlpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dsHostpdlist("Hosttype")&"' and isbyhost='y' order by orderbyid desc"
	dsSqlpdlist.Open Sql,conn,1,1
if not dsSqlpdlist.Eof Then
havesql=true%>
　　附送：
<select name="dsSqlpdlistID"><%end if%>
<%while not dsSqlpdlist.Eof
	Set dsSqlserver = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Serversqllist where id='"&dsSqlpdlist ("ServerlistID")&"'"
		dsSqlserver.Open Sql,conn,1,1
while not dsSqlserver.Eof

if dsSqlserver("softtype")="SQL2000" and dsSqlserver("MSSQLver")="2000" then softtype="SQL2000"
if dsSqlserver("softtype")="SQL2000" and dsSqlserver("MSSQLver")="2005" then softtype="SQL2005"
if dsSqlserver("softtype")="SQL2000" and dsSqlserver("MSSQLver")="2008" then softtype="SQL2008"
if dsSqlserver("softtype")="SQL2000" and dsSqlserver("MSSQLver")="2012" then softtype="SQL2012"
if dsSqlserver("softtype")="SQL2000" and dsSqlserver("MSSQLver")="2014" then softtype="SQL2014"
if dsSqlserver("softtype")="MySQL" and dsSqlserver("MySQLver")="5.0" then softtype="MySQL5.0"
if dsSqlserver("softtype")="MySQL" and dsSqlserver("MySQLver")="5.1" then softtype="MySQL5.1"
if dsSqlserver("softtype")="MySQL" and dsSqlserver("MySQLver")="5.5" then softtype="MySQL5.5"

%>
<option value="<%=dsSqlpdlist("id")%>"><%=softtype%> [大小<%=dsSqlpdlist("userspacelimt")%>M]</option>
<%dsSqlserver.movenext
wend
dsSqlserver.close
dsSqlpdlist.movenext
wend%>
<%If havesql=True then%></select> 注意选择后不能更改<%End if%>
<%dsSqlpdlist.close

End if
%>

	  
	  
	  </TD>
    </TR>
    <TR>
      <TD height="50" bgColor=#ffffff><font color="#000000">　有效期限：</font></TD>
      <TD width="64%" height="50" colspan="2" bgColor=#ffffff> 
<select name="year"  onChange="chusrm(this.options[this.options.selectedIndex].value)">
<option value="0" selected>请您选择</option>
<%if dsHostpdlist("cantest")="y" then%>
        <option value="999">试用<%=Application("testtime")%>天</option>
<%end if%>
<%if dsHostpdlist("canmonth")="y" then%>
		<option value="<%=PAY_Month%>">一个月</option>
<%end if%>
<%if dsHostpdlist("canseason")="y" then%>
		<option value="<%=PAY_Season%>">三个月</option>
<%end if%>
<%if dsHostpdlist("canhalfyear")="y" then%>
        <option value="<%=PAY_halfyear%>">半年</option>
<%end if%>
<option value="1">一年</option>
<option value="<%=PAY_2year%>">两年</option>
<option value="<%=PAY_3year%>">三年</option>
<option value="<%=PAY_4year%>">四年</option>
<option value="<%=PAY_5year%>">五年</option>
</select>
<input type="hidden" name="id" value="<%=Request.QueryString ("id")%>"> 
<%
usermoney=dsHostpdlist("usermoney")
if agentname<>"n" then
	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='虚拟主机' and username='"&agentname&"' and id="&dsHostpdlist("id")&""
		dsendmoney.Open Sql,conn,1,1
if not dsendmoney.eof then
usermoney=dsendmoney("usermoney")
end if
dsendmoney.close
end If

if canshowagnpric then%>　　<font color=red>(代理成本价格
<%
	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='虚拟主机' and username='"&agentname&"' and id="&dsHostpdlist("id")&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof then
usermoney=dsHostpdlist("usermoney")*dsagnettype("pers")
else
usermoney=dsagnpri("usermoney")
end if
dsagnpri.close
%>)</font><%End if%>
<%
If canshowagnpric And isAgnHostSer then%>
(<font color=red>当前此产品为独立模式产品</font>)
<%
usermoney=0
End if%>

<input name="moneynow" type="text" value="" size="7" readonly="true" style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" ></TD>
    </TR>
<%if isAgnHostSer=false then%>
    <TR>
      <TD height="50" bgColor=#ffffff>　请选择机房：</TD>
      <TD height="50" colspan="2" bgColor=#ffffff>
<%
	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Serverlist where agent1='n' order by orderbyid desc"
if isAgnHostSer then Sql="Select * from FreeHost.FreeHost_Serverlist where agent1='"&agentname&"' order by orderbyid desc"
		dsX.Open Sql,conn,1,1
If dsX.Eof Then%>
列表为空.
<%else%>
<select name="ServerlistID" id="ServerlistID">
<%while not dsX.Eof%>
<%if dsHostpdlist("ServerlistID")=dsX("id") or dsHostpdlist("ServerlistID2")=dsX("id") or dsHostpdlist("ServerlistID3")=dsX("id") or dsHostpdlist("ServerlistID4")=dsX("id") or dsHostpdlist("ServerlistID5")=dsX("id") then%>
  <option value="<%=dsX("id")%>" <%if dsX("id")=selectedserverid then%>selected<%end if%>><%=dsX("netby")%></option>
<%end if%> 
<%
dsX.movenext
wend%>
</select>
<%end if%>
</TD>
    </TR>
<%end if%>
    <TR>
      <TD height="50" bgColor=#ffffff>　服务条款：</TD>
      <TD height="50" colspan="2" bgColor=#ffffff><input name="tiaokuan" type="checkbox" value="y" checked>
        我已阅读并同意了<a href="/user/tiaokuan.asp" target="_blank"><b>《服务条款》</b></a></TD>
    </TR>
    <TR>
      <TD height="40" colspan="3" bgColor=#ffffff>　
<input name="openX" type="submit" value="马上实时开通虚拟主机" onClick="document.autoopen.openX.value ='请等待不要重复刷新！....';document.autoopen.openX.disabled=true;document.autoopen.submit()"></TD>
    </TR>
  </TBODY>
</TABLE>
<p><br>
  </p>
</form>
<script language="JavaScript" type="text/JavaScript">
//document.openX.moneynow.value=<%=usermoney%>;
function chusrm(s)
{

	document.all.moneynow.value=Math.round((s*<%=usermoney%>))+' 元';
	<%if isnull(Application("openmustre")) or Application("openmustre")=false then%>
		document.autoopen.hostname1.disabled=false;
			document.autoopen.hostname1.style.display='';
				document.autoopen.txtinfo.value='(没有域名可以不用填写)';
			<%end if%>
	if (s==999)
	{document.all.moneynow.value='0'+' 元';
	<%if isnull(Application("testhostcandomain")) or Application("testhostcandomain")=false then%>
	<%if isnull(Application("openmustre")) or Application("openmustre")=false then%>
try{
	document.autoopen.hostname1.value='';
	document.autoopen.hostname1.disabled=true;
	document.autoopen.hostname1.style.display='none';
	document.autoopen.txtinfo.value='试用虚拟主机不能绑域名';
	}
	catch(eeee)
	{}
	<%end if%>
	<%end if%>
	}
}
</script>
<%=htmlwrite("html4")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
