<!--#include file="../inc/Conn.asp"-->
<!--#include file="../inc/MelyySoft.ReName.Asp"-->
<!--#include file="Inc/Admin.Asp"-->
<%
response.buffer=true	
Const strDBPath = "Databackup"
%>
<%
dim Action
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="?Action=ReName">更改数据库(安全!)</a> | <a href="?Action=Backup">备份数据库</a> | <a href="?Action=Restore">恢复数据库</a> | <a href="?Action=Compact">压缩数据库</a> | <a href="?Action=SpaceSize">系统空间占用情况</a>	  </td>
	</tr>
</table>
<BR>

<%
if Action="Backup" or Action="BackupData" then
	call ShowBackup()
	set conn=nothing
elseif Action="ReName" then
	If ObjInstalled=false Then
	   Founderr=True
	   ErrMsg=ErrMsg+"<li>组件不支持，无法进行操作"
	end if
	DbNewName=Generator(16)&".mdb"
	FileValue=Conn_Path(DbConnFile,dbpath,dbnewname)
	Call CloseConn()
	Call CreateFile(Installdir&DbConnFile,FileValue)
	Call RenameFile(Installdir&dbpath,dbname,DbNewName)
	Call ShowReName()
Elseif request("action")="DelBackup" then
    dim backpath
	backpath=request.form("backpath")
	if backpath="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定数据库文件名！<li>"	
	end if
	call DeleteFile(backpath)
	Call ShowReName()	
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 ShowReName()
    	
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
  <tr>
	<td colspan="3" align="center" height="25" class="topbg"><FONT COLOR="#ffffff"><b>更 改 数 据 库</b></FONT></td>
  </tr>
<%If not Founderr then
%>
<tr> 
	<td width="20%" height="40" align="right" class="tdbgl"></td>
	<td class="tdbg" colspan="2" align="center">操作成功</td>
  </tr>
<%
else%>
   <tr> 
	<td width="20%" height="40" align="right" class="tdbgl"></td>
	<td class="tdbg" colspan="2" align="center"><%=ErrMsg%></td>
  </tr>
<%end If%> 
</table>
<%
end sub
'--------备份数据库--------
sub ShowBackup()
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
<form method="post" action="?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="155" 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="155" 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>
		  <%
		  Dim BackDbName
		  BackDbName=Replace(Now(),":","-")
		  %>
          <tr> 
            <td width="155" height="40" align="right" class="tdbgl">备份名称：</td>
            <td height="40" class="tdbg"><input type=text size=40 name=bkDBname value="<%=BackDbName%>"></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()
%>
<br />
<table width="100%" class="border" border="0" align="center" cellpadding="0" cellspacing="1">
	<tr class="title"> 
	 <td align="center" height="22" valign="middle"><b>数据库恢复</b></td>
	</tr>
	<tr class="tdbg">
	   <td align="center" valign="middle"> 
	<%
if request("action")="RestoreData" then
	call RestoreData()
else
	Dim Fso
	Set Fso=server.createobject("Scripting.FileSystemObject")
	dim theFolder,theFile,strFileType
	if Not fso.FolderExists(Server.MapPath(strDBPath)) then
		response.write "找不到数据库备份文件夹（"&strDBPath&"）！"
		response.end
	end if
	Set theFolder=fso.GetFolder(Server.MapPath(strDBPath))
	For Each theFile In theFolder.Files
	strFileType=lcase(mid(theFile.name,instrrev(theFile.name,".")+1))
	if strFileType="asa" Then
	%>
	<br />
	<fieldset><legend align="center"><strong><%=theFile.name%></strong></legend>
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border">
		<tr class="tdbg">
		  <td align="right">文 件 名：</td>
		  <td><font color=#ff6600><%=theFile.name%></font></td>
		  <td align="right">文件大小：</td>
		  <td><%=round(theFile.size/1024) & " K"%></td>
		  <td align="right">修改时间：</td>
		  <td><%=theFile.DateLastModified%></td>
		</tr>
		<tr class="tdbg">
		  <td align="right">操作选项：</td>
		  <td colspan="5" valign="middle">
			<form method="Post" action="?action=RestoreData" onSubmit="return confirm('确定恢复数据库吗？，此操作将替换现在使用中的数据库！');">
				<input name="backpath" type="text" id="backpath" value="<%=strDBPath%>\<%=theFile.name%>" size=50 maxlength="200" readonly>
				<input name="submit" type="submit" value=" 恢复数据 " <%If ObjInstalled=false Then response.Write "disabled"%>>
			</form>
			<form method="Post" action="?action=DelBackup" onSubmit="return confirm('确定删除备份文件吗？');">
				<input name="backpath" type="text" id="backpath" value="<%=strDBPath%>\<%=theFile.name%>" size=50 maxlength="200" readonly>
				<input name="Del" type="submit" value=" 删除备份 " <%If ObjInstalled=false Then response.Write "disabled"%>>
			</form>
		</td>
		</tr>
	</table>
	</fieldset>
	<%
	end if
	Next
	If ObjInstalled=false Then
		Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
    End If
end if			
%>
			</td>
		</tr>
</table>
<%
end sub
'--------恢复数据库--------
sub ShowRestore1()
%>
<table cellpadding="0" cellspacing="1" border="0" width="90%" align="center" class="border">
<form method="post" action="?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="155" height="40" align="right" class="tdbgl">备份数据库路径（相对）：</td>
		<td height="40" class="tdbg"><input name=backpath type=text id="backpath" value="Databackup/DataBack.asa" size=50 maxlength="200"></td>
	</tr>
	<tr>
		<td width="155" 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="?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/DataBack.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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" align="right" class="tdbgl">WEB编辑器占用空间：</td>
          <td class="tdbg"><img src="image/bar.gif" width=<%=drawbar("../Editor")%> height=12>&nbsp;
            <%showSpaceinfo("../Editor")%></td>
        </tr>
		 <tr>
          <td width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 width="155" 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 Lcase(StrReverse(Split(StrReverse(db),".")(0)))<>"mdb" And Lcase(StrReverse(Split(StrReverse(db),".")(0)))<>"asa"  then
	    FoundErr=True
		ErrMsg=ErrMsg & "<br><li>备份文件必须是.asa或.mdb文件</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("backpath")
	if backpath="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定原备份的数据库文件名！<li>"
		exit sub	
	end if
	if Lcase(StrReverse(Split(StrReverse(backpath),".")(0)))<>"mdb" And Lcase(StrReverse(Split(StrReverse(backpath),".")(0)))<>"asa"  then
	    FoundErr=True
		ErrMsg=ErrMsg & "<br><li>备份文件必须是.asa或.mdb文件</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

%>