<!--#include file="../inc/Conn.asp"-->
<!--#include file="inc/admin.asp"-->
<%
PurviewValue="Admin_Sql"
If not CheckAdmin(PurviewValue) then
Response.Write("<script language=""JavaScript"">alert(""越权操作!"");history.go(-1);")
response.end
End If
%>
<%
response.buffer=true	
Const strDBPath = "Databackup\"
%>
<%
Action=trim(request("Action"))
dim ObjInstalled
ObjInstalled=IsObjInstalled("Scripting.FileSystemObject")
%>
<!-- #include file="Inc/Head.asp" -->
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
	<tr>
		<td class="topbg" height="25" align="center" colspan="2"><strong>数 据 库 管 理</strong></td>
	</tr>
	<tr>
		<td width="96" height="30" class="tdbgl">&nbsp;<strong>管理导航：</strong></td>
    <td width="683" height="30" class="tdbg">&nbsp;<a href="Admin_Database.asp?Action=Backup">备份数据库</a> | <a href="Admin_Database.asp?Action=Restore">恢复数据库</a> | <a href="Admin_Database.asp?Action=Compact">压缩数据库</a> | <a href="Admin_Database.asp?Action=SpaceSize">系统空间占用情况</a>	  </td>
	</tr>
</table>
<BR>

<%
if Action="Backup" or Action="BackupData" then
	call ShowBackup()
	set conn=nothing 
elseif Action="Compact" or Action="CompactData" then
	call ShowCompact()
	set conn=nothing 
elseif Action="Restore" or Action="RestoreData" then
	call ShowRestore()
	set conn=nothing 
elseif Action="SpaceSize" then
	call SpaceSize()
	set conn=nothing 
else
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>错误参数！</li>"
	set conn=nothing 
end if
if FoundErr=True then
	call WriteErrMsg()
end if

'--------备份数据库--------
sub ShowBackup()
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
<form method="post" action="Admin_Database.asp?action=BackupData">
  <tr>
	<td colspan="3" align="center" height="25" class="topbg"><FONT COLOR="#ffffff"><b>备 份 数 据 库</b></FONT></td>
  </tr>
<%    
if request("action")="BackupData" then
	call backupdata()
else
%>
          <tr> 
            <td width="80" height="40" align="right" class="tdbgl">当前数据库：</td>
            <td class="tdbg"><input name="db" type="text" size="40" value="<%=db%>"></td>
            <td class="tdbg">相对路径目录</td>
          </tr>
          <tr> 
            <td width="80" height="40" align="right" class="tdbgl">备份目录：</td>
            <td class="tdbg"><input type=text size=40 name=bkfolder value="Databackup"></td>
            <td class="tdbg">相对路径目录，如目录不存在，将自动创建</td>
          </tr>
          <tr> 
            <td width="80" height="40" align="right" class="tdbgl">备份名称：</td>
            <td height="40" class="tdbg"><input type=text size=40 name=bkDBname value="#Data##Back"></td>
            <td height="40" class="tdbg">不用输入文件名后缀（默认为“.asa”）。如有同名文件，将覆盖</td>
          </tr>
          <tr> 
            <td colspan="3" align="center" class="tdbg"><input name="submit" type=submit value=" &nbsp;开始备份&nbsp; " <%If ObjInstalled=false Then response.Write "disabled"%> ></td>
          </tr>
<%
	If ObjInstalled=false Then
		Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
	end if
end if
%>
</form>
</table>
<%
end sub

'--------恢复数据库--------
sub ShowRestore()
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
<form method="post" action="Admin_Database.asp?action=RestoreData">
  <tr>
	<td colspan="2" align="center" height="25" class="topbg"><FONT COLOR="#ffffff"><b>数 据 库 恢 复</b></FONT></td>
  </tr>
<%
if request("action")="RestoreData" then
	call RestoreData()
else
%>
	<tr>
		<td width="150" height="40" align="right" class="tdbgl">备份数据库路径（相对）：</td>
	  <td height="40" class="tdbg"><input name=backpath1 type=text id="backpath1" value="Databackup/#Data##Back.asa" size=50 maxlength="200"></td>
	</tr>
	<tr>
		<td width="150" height="40" align="right" class="tdbgl">当前数据库路径（相对）：</td>
		<td class="tdbg"><input name="db" type="text" size="50" maxlength="200" value="<%=db%>"></td>
	</tr>
	<tr align="center" class="tdbg"> 
	  <td colspan="2" class="tdbg"><input name="submit" type=submit value=" &nbsp;恢复数据&nbsp; " <%If ObjInstalled=false Then Response.Write "disabled"%> ></td>
	</tr>
<%
	If ObjInstalled=false Then
		Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
	end if
end if
%>
</form>
</table>
<%
end sub

'--------压缩数据库--------
sub ShowCompact()
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
<form method="post" action="Admin_Database.asp?action=CompactData">
  <tr align="center">
	<td class="topbg" height="25"><FONT COLOR="#ffffff"><b>数 据 库 在 线 压 缩</b></FONT></td>
	</tr>
<%    
if request("action")="CompactData" then
	call CompactData()
else
%>
	<tr align="left" class="tdbg">
		<td valign="middle" class="tdbg" style="line-height: 150%"><font color="#FF6600"><b>注1：</b></font>压缩前，建议先备份数据库，以免发生意外错误。 <br>
	  <font color="#FF6600"><b>注2：</b></font>正在使用中数据库不能压缩,请选择备份数据库进行压缩操作(当前压缩数据库名为默认备份文件名)</td>
	</tr>
	<tr  align="left" class="tdbg">
		<td class="tdbg">数据库位置： 
	  <input name="db" type="text" id="db" size="50" value="Databackup/#Data##Back.asa"></td>
	</tr>
	<tr align="center" class="tdbg">
	  <td class="tdbg"><input name="submit" type=submit value=" &nbsp;压缩数据库&nbsp; " <%If ObjInstalled=false Then Response.Write "disabled"%> ></td>
	</tr>
<%
	If ObjInstalled=false Then
		Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
	end if
end if
%>
</form>
</table>
<%
end sub

'--------统空间占用情况--------
sub SpaceSize()
	on error resume next
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
  <tr>
	<td colspan="2" align="center" height="25" class="topbg"><FONT COLOR="#ffffff"><b>系 统 空 间 占 用 情 况</b></FONT></td>
  </tr>
  <tr> 
    <td  height="150" valign="middle" >
	  <table width="100%" border="0" cellpadding="0" cellspacing="1" class="a3">
        <tr>
          <td align="right" class="tdbgl">数据库占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../Databases")%> height=12>&nbsp;
            <%showSpaceinfo("../Databases")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">备份数据占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("databackup")%> height=12>&nbsp;
            <%showSpaceinfo("databackup")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">计数器占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../counter")%> height=12>&nbsp;
            <%showSpaceinfo("../counter")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">系统配置文件占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../Inc")%> height=12>&nbsp;
            <%showSpaceinfo("../Inc")%></td>
        </tr>
		 <tr>
          <td align="right" class="tdbgl">后台管理文件占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../admin")%> height=12>&nbsp;
            <%showSpaceinfo("../admin")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">配色模板占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../Skin")%> height=12>&nbsp;
            <%showSpaceinfo("../Skin")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">视频文件占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../Video")%> height=12>&nbsp;
            <%showSpaceinfo("../Video")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">系统图片images占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../images")%> height=12>&nbsp;
            <%showSpaceinfo("../images")%></td>
        </tr>
		        <tr>
          <td align="right" class="tdbgl">系统图片img占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../Img")%> height=12>&nbsp;
            <%showSpaceinfo("../Img")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">其他上传文件占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../UploadFiles")%> height=12>&nbsp;
            <%showSpaceinfo("../UploadFiles")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">产品上传图片占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../UploadProductPic")%> height=12>&nbsp;
            <%showSpaceinfo("../UploadProductPic")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">下载上传文件占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../UploadSoft")%> height=12>&nbsp;
            <%showSpaceinfo("../UploadSoft")%></td>
        </tr>
        <tr>
          <td align="right" class="tdbgl">系统占用空间总计：</td>
          <td class="tdbg"><img src="image/bar.gif" width=400 height=12>
            <%showspecialspaceinfo("All")%></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<%
end sub
%>
<!-- #include file="Inc/Foot.asp" -->
<%
'--------备份数据库--------
sub BackupData()
	dim bkfolder,bkdbname,fso
	db=trim(request.form("db"))
	bkfolder=trim(request("bkfolder"))
	bkdbname=trim(request("bkdbname"))
	if db="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定当数据库位置！</li>"
	end if
	if bkfolder="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定备份目录！</li>"
	end if
	if bkdbname="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定备份文件名</li>"
	end if
	if FoundErr=True then exit sub
	dbpath = server.mappath(db)
	bkfolder=server.MapPath(bkfolder)
	Set Fso=server.createobject("scripting.filesystemobject")
	if fso.FileExists(dbpath) then
		If fso.FolderExists(bkfolder)=false Then
			fso.CreateFolder(bkfolder)
		end if
		fso.copyfile dbpath,bkfolder & "\" & bkdbname & ".asa"
		response.write "<center>备份数据库成功，备份的数据库为 " & bkfolder & "\" & bkdbname & ".asa</center>"
	Else
		response.write "<center>找不到源数据库文件，请检查inc/conn.asp中的配置。</center>"
	End if
end sub
'--------恢复数据库--------
sub RestoreData() 
	dim backpath,fso
	backpath=request.form("backpath1")
	db=trim(request.form("db"))
	if backpath="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定原备份的数据库文件名！<li>"
		exit sub	
	end if
	if db="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定当前数据库文件名！<li>"
		exit sub	
	end if
	backpath=server.mappath(backpath)
	dbpath = server.mappath(db)
	Set Fso=server.createobject("scripting.filesystemobject")
	if fso.fileexists(backpath) then  					
		fso.copyfile Backpath,dbpath
		response.write "成功恢复数据！"
	else
		response.write "找不到指定的备份文件！"	
	end if
end sub
'--------压缩数据库--------
sub CompactData() 
	Dim fso, Engine,strDBPath
	DB=trim(request.form("db")) 
	DBPath = server.mappath(DB)
'	strDBPath = server.mappath("data_backup\")
	if instr(DBPath,"/") then 
		strDBPath = left(DBPath,instrrev(DBPath,"\"))
	else
		strDBPath = left(DBPath,instrrev(DBPath,"\"))
	end if
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
	If fso.FileExists(DBPath) Then
		Set Engine = CreateObject("JRO.JetEngine")
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath," Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
		fso.CopyFile strDBPath & "temp.mdb",DBPath
		fso.DeleteFile(strDBPath & "temp.mdb")
		Set fso = nothing
		Set Engine = nothing
		response.write "数据库压缩成功!"
	Else
		response.write "数据库没有找到!"
	End If
end sub
%>
<%
Sub ShowSpaceInfo(drvpath)
	dim fso,d,size,showsize
	set fso=server.createobject("scripting.filesystemobject") 		
	drvpath=server.mappath(drvpath) 		 		
	set d=fso.getfolder(drvpath) 		
	size=d.size
	showsize=size & "&nbsp;Byte" 
	if size>1024 then
	   size=(size\1024)
	   showsize=size & "&nbsp;KB"
	end if
	if size>1024 then
	   size=(size/1024)
	   showsize=formatnumber(size,2) & "&nbsp;MB"		
	end if
	if size>1024 then
	   size=(size/1024)
	   showsize=formatnumber(size,2) & "&nbsp;GB"	   
	end if   
	response.write "<font face=verdana>" & showsize & "</font>"
End Sub	

Sub Showspecialspaceinfo(method)
	dim fso,d,fc,f1,size,showsize,drvpath 		
	set fso=server.createobject("scripting.filesystemobject")
	drvpath=server.mappath("../Inc")
	drvpath=left(drvpath,(instrrev(drvpath,"\")-1))
	set d=fso.getfolder(drvpath) 		
	
	if method="All" then 		
		size=d.size
	elseif method="Program" then
		set fc=d.Files
		for each f1 in fc
			size=size+f1.size
		next	
	end if	
	
	showsize=size & "&nbsp;Byte" 
	if size>1024 then
	   size=(size\1024)
	   showsize=size & "&nbsp;KB"
	end if
	if size>1024 then
	   size=(size/1024)
	   showsize=formatnumber(size,2) & "&nbsp;MB"		
	end if
	if size>1024 then
	   size=(size/1024)
	   showsize=formatnumber(size,2) & "&nbsp;GB"	   
	end if   
	response.write "<font face=verdana>" & showsize & "</font>"
end sub 	 	 	

Function Drawbar(drvpath)
	dim fso,drvpathroot,d,size,totalsize,barsize
	set fso=server.createobject("scripting.filesystemobject")
	drvpathroot=server.mappath("../Inc")
	drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
	set d=fso.getfolder(drvpathroot)
	totalsize=d.size
	
	drvpath=server.mappath(drvpath) 		
	set d=fso.getfolder(drvpath)
	size=d.size
	
	barsize=cint((size/totalsize)*400)
	Drawbar=barsize
End Function 	

Function Drawspecialbar()
	dim fso,drvpathroot,d,fc,f1,size,totalsize,barsize
	set fso=server.createobject("scripting.filesystemobject")
	drvpathroot=server.mappath("../Inc")
	drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
	set d=fso.getfolder(drvpathroot)
	totalsize=d.size
	
	set fc=d.files
	for each f1 in fc
		size=size+f1.size
	next	
	
	barsize=cint((size/totalsize)*400)
	Drawspecialbar=barsize
End Function
%>
<%
'**************************************************
'函数名：IsObjInstalled
'作  用：检查组件是否已经安装
'参  数：strClassString ----组件名
'返回值：True  ----已经安装
'       False ----没有安装
'**************************************************
Function IsObjInstalled(strClassString)
	On Error Resume Next
	IsObjInstalled = False
	Err = 0
	Dim xTestObj
	Set xTestObj = Server.CreateObject(strClassString)
	If 0 = Err Then IsObjInstalled = True
	Set xTestObj = Nothing
	Err = 0
End Function
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
	dim fso
	folderpath=Server.MapPath(".")&"\"&folderpath
	Set fso1 = Server.CreateObject("Scripting.FileSystemObject")
	If fso.FolderExists(FolderPath) then
	'存在
		CheckDir = True
	Else
	'不存在
		CheckDir = False
	End if
	Set fso = nothing
End Function

'-------------根据指定名称生成目录---------
Function MakeNewsDir(foldername)
	dim fso,f
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set f = fso.CreateFolder(foldername)
    MakeNewsDir = True
	Set fso = nothing
End Function

'**************************************************
'过程名：WriteErrMsg
'作  用：显示错误提示信息
'参  数：无
'**************************************************
sub WriteErrMsg()
	dim strErr
	strErr=strErr & "<html><head><title>错误信息</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbcrlf
	strErr=strErr & "<link href='style.css' rel='stylesheet' type='text/css'></head><body><br><br>" & vbcrlf
	strErr=strErr & "<table cellpadding=2 cellspacing=1 border=0 width=400  align=center>" & vbcrlf
	strErr=strErr & "  <tr align='center' class='title'><td height='22'><strong>错误信息</strong></td></tr>" & vbcrlf
	strErr=strErr & "  <tr '><td height='100' valign='top'><b>产生错误的可能原因：</b>" & errmsg &"</td></tr>" & vbcrlf
	strErr=strErr & "  <tr align='center' '><td><a href='javascript:history.go(-1)'>&lt;&lt; 返回上一页</a></td></tr>" & vbcrlf
	strErr=strErr & "</table>" & vbcrlf
	strErr=strErr & "</body></html>" & vbcrlf
	response.write strErr
end sub
%>
