<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canadmsqladd")="" Then
	ef=True
	ec="您没有此操作的权限。"
ElseIf Request.Form ("username")="" Then
	ef=True
	ec="请输入用户名！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="用户名中有非法字符！"
ElseIf Request.Form ("Sqltype")="" Then
	ef=True
	ec="请选择产品！"
ElseIf not IsNumeric(Request.Form ("Sqltype"))  Then
	ef=True
	ec="产品类型有非法字符！"
ElseIf Request.Form ("ServerlistID")="" Then
	ef=True
	ec="请选择服务器！"
ElseIf not IsNumeric(Request.Form ("ServerlistID"))  Then
	ef=True
	ec="服务器ID应该是数字！"
ElseIf not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
ElseIf Request.Form ("sqlname")="" Then
	ef=True
	ec="请设置数据库用户名！"
ElseIf IsNumeric(left(Request.Form ("sqlname"),1))  Then
	ef=True
	ec="数据库名不能只是数字，必须用字母开头！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="freehost" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="master" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="model" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="msdb" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="northwind" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="pubs" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="tempdb" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="root" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="sa" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="mysql" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf LCASE(trim(Request.Form ("sqlname")))="case" Then
	ef=True
	ec="不能用这个用户名，请用另一个用户名！"
ElseIf Request.Form ("sqlpassword")="" Then
	ef=True
	ec="请设置数据库密码！"
ElseIf Request.Form ("sqlpassword")<>Request.Form ("resqlpassword") Then
	ef=True
	ec="重复输入的数据库密码不一致！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("sqlname")) or Instr(1, Request.Form ("sqlname"), "'", 1)>0 or Instr(1, Request.Form ("sqlname"), "-", 1)>0 or Instr(1, Request.Form ("sqlname"), " ", 1)>0 or Instr(1, Request.Form ("sqlname"), "&", 1)>0 or Instr(1, Request.Form ("sqlname"), ".", 1)>0 or Instr(1, Request.Form ("sqlname"), "_", 1)>0 Then
	ef=True
	ec="数据库用户名中有非法字符！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("sqlpassword"))  or Request.Form ("sqlpassword")="123456" or Request.Form ("sqlpassword")="12345"  or len(Request.Form ("sqlpassword"))<4 Then
	ef=True
	ec="数据库密码有非法字符，只能是字母与数字/密码没填/或密码过于简单！"
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
	Set dsSqlpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SqlProductlist where id='"&Request.Form ("Sqltype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsSqlpdlist.Open Sql,conn,1,1
if dsSqlpdlist.Eof then
	ef=True
	ec="产品不存在！"
end if
end if

if not ef then
If Request.Form ("year")<>999 and Request.Form ("year")<>dsSqlpdlist("PAY_Month") and Request.Form ("year")<>dsSqlpdlist("PAY_Season")  and Request.Form ("year")<>dsSqlpdlist("PAY_halfyear") and Request.Form ("year")<>1 and Request.Form ("year")<>dsSqlpdlist("PAY_2year") and Request.Form ("year")<>dsSqlpdlist("PAY_3year") and Request.Form ("year")<>dsSqlpdlist("PAY_4year") and Request.Form ("year")<>dsSqlpdlist("PAY_5year") Then
	ef=True
	ec="请选择时间！"
end If
end if

if not ef then
If Request.Form ("usermoney")="" Then
cost=dsSqlpdlist("usermoney")
cost=cost*Request.Form ("year")
if Request.Form ("year")=999 then cost=0
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足！"
end if
else
cost=Clng(Request.Form ("usermoney"))
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足B！"
end if
end if
end if

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")
If Request.Form ("ServerlistID")="0" Then
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&dsSqlpdlist ("ServerlistID")&"'"
else
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&Request.Form ("ServerlistID")&"'"
end if
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
end if
end if

if not ef then
	Set dsphSQLname = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where sqlname='"&Request.Form ("sqlname")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsphSQLname.Open Sql,conn,1,1
if not dsphSQLname.Eof then
	ef=True
	ec="您输入的数据库用户名已存在，请另外输入一个！"
end if
dsphSQLname.close
end if

if not ef then

'开始扣费
olduser_money=ds("usermoney")
moneych=0
ds("usermoney") =ds("usermoney") -cost
moneych=-cost
ds.update

newuser_money=ds("usermoney")


	Set dsphSql = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql"
	dsphSql.Open Sql,conn,1,3
starttime=Now
'结束时间
y=Request.Form ("year")
if y=1 then temptime=dateadd("yyyy",1,now)
if y=dsSqlpdlist("PAY_2year") then temptime=dateadd("yyyy",2,now)
if y=dsSqlpdlist("PAY_3year") then temptime=dateadd("yyyy",3,now)
if y=dsSqlpdlist("PAY_4year") then temptime=dateadd("yyyy",4,now)
if y=dsSqlpdlist("PAY_5year") then temptime=dateadd("yyyy",5,now)
if y=dsSqlpdlist("PAY_Month") then temptime=dateadd("y",31,now)
if y=dsSqlpdlist("PAY_Season") then temptime=dateadd("y",92,now)
if y=dsSqlpdlist("PAY_halfyear") then temptime=dateadd("y",182,now)
if y=999 then
temptime=dateadd("y",Application("testtime"),now)
end if
if request.Form ("endtime")<>"" then temptime=request.Form ("endtime")
dsphSql.addnew
dsphSql("username")=ds("username")
dsphSql("ServerlistID")=dsserver("id")
dsphSql("Sqltype")=dsSqlpdlist("Sqltype")
dsphSql("starttime")=starttime
dsphSql("endtime")=temptime
if y=999 then
dsphSql("istest")="y"
dim isfortest
isfortest=true
else
dsphSql("istest")="n"
end if

temptime=dsphSql("endtime")

dsphSql("userspacelimt")=dsSqlpdlist("userspacelimt")
dsphSql("logspacelimt")=dsSqlpdlist("logspacelimt")
if Request.Form("userspacelimt")<>"" then dsphSql("userspacelimt")=Request.Form("userspacelimt")
if Request.Form("logspacelimt")<>"" then dsphSql("logspacelimt")=Request.Form("logspacelimt")

dsphSql("sqlname")=request.Form("sqlname")
dsphSql("sqlpassword")=request.Form("sqlpassword")
dsphSql("status")="等待开通"
if ds("agent1")<>"n" then
dsphSql("agent1")=ds("agent1")
else
dsphSql("agent1")="n"
end if
dsphSql.update

URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")
homedir=dsserver("homedir")
ip=dsserver("ip")
port=dsserver("port")
userspacelimt=dsphSql("userspacelimt")
logspacelimt=dsphSql("logspacelimt")
sqlname=dsphSql("sqlname")
sqlpassword=dsphSql("sqlpassword")

dim softtype,MySQLver,MSSQLver
softtype=dsserver("softtype")
MySQLver=dsserver("MySQLver")
MSSQLver=dsserver("MSSQLver")

if softtype="SQL2000" then
retsql=SqlAdd(URL,FreeHostsharekey,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
else
retsql=SqlAddmysql(URL,FreeHostsharekey,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
end if

FreeHost_oplog session("admusername"),"信息","管理员帮用户("&ds("username")&")开通,数据库名:"&sqlname&" 返回信息："&retsql

If Application("smssqlopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smssqlopencon")
'恭喜！您的数据库产品已经开通，用户名：#用户名#产品类型：#产品类型#到期时间：#到期时间#您的帐户余款是：#金额# 元
smsContent=Replace(smsContent,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#产品类型#",dsphSql("SQLtype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsphSql("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if


dsphSql.close
'log
	Set dsphSql = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where starttime='"&starttime&"' and username='"&ds("username")&"'"
	dsphSql.Open Sql,conn,1,3
	dsphSql("status")="正常"
	dsphSql.update

pdtype=dsphSql("Sqltype")
FreeHost_moneyNewlog conn,"y","n","y","n","n",isAgnHostSer,-moneych,dsphSql ("username"),session("admusername"),dsphSql ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,session("admusername"),"管理员新建数据库产品库名:"&sqlname,"管理员新建数据库产品库名:"&sqlname,"数据库产品",dsphSql("id"),pingzheng,type1,bank,haveget,havecheck

dim Subject,body
EmailUserSQLOpen
ret=Send2Mail(conn,ds("username"),Subject,body)

%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html8")%>
<%=htmlwrite("html9")%>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0 background="img/midtop4.gif">
  <TBODY>
    <TR>
      <TD width=53 align="left" background="img/midtop1.gif"><strong> 　 </strong><font color="#FFFFFF">─<strong>&gt;</strong></font> </TD>
      <TD align="left"><table height="59"  border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="7" background="img/midtop.gif">&nbsp;</td>
          <td width="90" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="admsql.asp"><font color="#FFFFFF"><strong>数据库管理</strong></font></a></td>
          <td width="5" background="img/midtop2.gif">&nbsp;</td>
        </tr>
      </table></TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83" align="left">&nbsp;</TD>
      <TD align="left">&nbsp;</TD>
      <TD width=23 align="right"><IMG height=59 
                  src="img/rtop4.jpg" 
                  width=19></TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
  <TBODY>
    <TR>
      <TD width=19 background="img/midlef.gif" id=rightid>&nbsp;</TD>
      <TD height="300" align="center" vAlign=top bgcolor="#FFFFFF">
	 <table width="65%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<br>
<DIV class="tableborder">
	<br>
<br>
服务器返回信息：<%=retsql%>
<br><br>
</div>
	
	</td>
  </tr>
</table> 

<table width="65%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	

	
	<br><DIV class="tableborder">
<table width="100%"  border="0" align="center" cellpadding="2" cellspacing="1">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="24" colspan="4" background="img/tablebg.gif"><font color="#990000"><font color="#FFFFFF">数据库添加成功，以下是相关的资料</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td width="47%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="53%" colspan="3"><%=olduser_money%> 元</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="41"><font color="#000000">　　　 用户的金额变化：</font></td>
    <td colspan="3"><font color=red><%=moneych%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 用户的新金额：</font></td>
    <td colspan="3"><%=newuser_money%> 元</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 数据库用户名：</font></td>
    <td colspan="3">　<font color="#000000"><%=sqlname%></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 数据库密码：</font></td>
    <td colspan="3">　<font color="#000000"><%=sqlpassword%></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 数据库名称：</font></td>
    <td colspan="3">　<font color="#000000"><%=sqlname%></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 数据库所在IP</font>：</td>
    <td colspan="3">　<font color="#000000"><%=ip%></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="39"><font color="#000000">　　　 所用的连接端口：</font></td>
    <td colspan="3">　<font color="#000000"><%=port%></font></td>
  </tr>
<%if softtype="SQL2000" then%>
  <tr align="center" bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="40"><font color="#000000">典型的ASP调用连接字符串</font>：</td>
    <td height="40" align="left"><font color="#000000">"provider=sqloledb;data source=<%=ip%>,<%=port%>;User ID=<%=sqlname%>;pwd=<%=sqlpassword%>;Initial Catalog=<%=sqlname%>" </font></td>
  </tr>
<%end if%>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000">　　　 </font><font color="#000000">现在的到期时间是:</font></td>
    <td colspan="3">　<%=temptime%></td>
  </tr>

  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37" colspan="4" align="right" bgcolor="#E4EAF2"><font color="#000000"> 　　　</font><a href="#top"><font color="#6B9EDE" face="Arial, Helvetica, sans-serif">Top↑</font></a>	</td>
    </tr>


</table>
	</div>

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

      </TD>
      <TD width=18 background="img/midri.gif">&nbsp;</TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
    <TR>
      <TD width=30><IMG height=19 
                  src="img/rb1.jpg" 
                  width=30></TD>
      <TD 
                background=img/rb2.jpg>&nbsp;</TD>
      <TD width=30><IMG height=19 
                  src="img/rb3.jpg" 
                  width=30></TD>
    </TR>
  </TBODY>
</TABLE>
<%=htmlwrite("html10")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
