<!--#include file="Conn.asp"-->
<!--#include file="cookies.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<TITLE>商奇软件 www.583344.com</TITLE>
<LINK href="images/Admin_css.css" type=text/css rel=stylesheet>
</head>

<body>
<%
select case request("action")
    case "SpaceSize"
	    SpaceSize()
	case "CompressData"
		if IsSqlDataBase = 1 then
			SQLUserReadme()
		else
			CompressData()
		end if
	case "BackupData"
	    if request("act")="Backup" then
			call updata()
		else
			call BackupData()
		end if
	case "RestoreData"
			if request("act")="Restore" then
				dim Dbpath,backpath,fso
				Dbpath=request.form("Dbpath")
				backpath=request.form("backpath")
				if dbpath="" then
				Call Alert("请输入您要恢复的数据库路径及名称!","-1")	
				else
				Dbpath=server.mappath(Dbpath)
				end if
				backpath=server.mappath(backpath)
			
				Set Fso=Server.CreateObject("Scripting.FileSystemObject")
				if fso.fileexists(dbpath) then  					
					fso.copyfile Dbpath,Backpath
Response.Write "<script language=javascript>alert('成功恢复数据!');this.location.href='sd_Admin_Data.asp?action=SpaceSize';</script>"

				else
Response.Write "<script language=javascript>alert('备份目录下并无您的备份文件!');history.go(-1);</script>"
					Call Alert("","-1")	
				end if
			else
				call RestoreData()
			end if
end select
%>
<%
'====================压缩数据库 =========================
sub CompressData()
%>
<table border="0"  cellspacing="1" cellpadding="3" height="1" class="admintable1">
<form action="sd_Admin_Data.asp?action=CompressData" method="post">
<tr>
<td class="admintitle">压缩数据库</td>
</tr><tr>
<td height=30 bgcolor="#FFFFFF" class="td"><b>注意：</b>输入数据库所在相对路径,并且输入数据库名称（正在使用中数据库可能会压缩失败，请选择备份数据库进行压缩操作） </td>
</tr>
<tr>
<td height="30" bgcolor="#FFFFFF" class="td">压缩数据库：<input name="dbpath" type="text" value="../Data/<%=DataName%>" size="50">
&nbsp;
<input type="submit" class="bnt" value="开始压缩"></td>
</tr>
<tr>
<td height="30" bgcolor="#FFFFFF" class="td"><input name="boolIs97" type="checkbox" class="noborder" value="True">如果使用 Access 97 数据库请选择
(默认为 Access 2000 数据库)<br></td>
</tr>
<tr>
  <td height="30" bgcolor="#FFFFFF" class="td">注：请尽量用ftp下载回数据库后压缩，以免出错！如果你非要使用此功能，请备份后再压缩！<strong>数据库出错本程序作者概不负责!</strong></td>
</tr>
</form>
</table>
<%
dim dbpath,boolIs97
dbpath = request("dbpath")
boolIs97 = request("boolIs97")

If dbpath <> "" Then
dbpath = server.mappath(dbpath)
	response.write(CompactDB(dbpath,boolIs97))
End If

end sub

'=====================压缩参数=========================
Function CompactDB(dbPath, boolIs97)
	Dim fso, Engine, strDBPath,JET_3X
	strDBPath = left(dbPath,instrrev(DBPath,"\"))
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
	
	If fso.FileExists(dbPath) Then
		fso.CopyFile dbpath,strDBPath & "temp.mdb"
		Set Engine = CreateObject("JRO.JetEngine")
	
		If boolIs97 = "True" Then
			Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
			"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb;" _
			& "Jet OLEDB:Engine Type=" & JET_3X
		Else
			Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
			"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
		End If
	
		fso.CopyFile strDBPath & "temp1.mdb",dbpath
		fso.DeleteFile(strDBPath & "temp.mdb")
		fso.DeleteFile(strDBPath & "temp1.mdb")
		Set fso = nothing
		Set Engine = nothing
Response.Write "<script language=javascript>alert('压缩成功!');this.location.href='sd_Admin_data.asp?action=SpaceSize';</script>"

	Else
Response.Write "<script language=javascript>alert('数据库名称或路径不正确. 请重试!');history.go(-1);</script>"

	End If
End Function
%>
<%
'====================备份数据库=========================
sub BackupData()
%>
	<table border="0"  cellspacing="1" cellpadding="3" class="admintable1">
	  <tr>
		  <td colspan="2" class="admintitle" >备份网站系统数据( 需要FSO支持，FSO相关帮助请看微软网站 )</td>
	  	</tr>
  				<form method="post" action="sd_Admin_Data.asp?action=BackupData&act=Backup">
  				<tr>
  				  <td width="19%" height="30" align="center" bgcolor="#FFFFFF" class="td">当前数据库路径(相对)：</td>
				  <td width="81%" bgcolor="#FFFFFF" class="td"><input name=DBpath type=text id="DBpath" Readonly="true" value="../Data/<%=DataName%>" size="40" /></td>
  				</tr>
  				<tr>
  				  <td height="30" align="center" bgcolor="#FFFFFF" class="td">备份数据库目录(相对)：</td>
				  <td bgcolor="#FFFFFF" class="td"><input name=bkfolder type=text value="../Databackup/" size="40" Readonly="true"/>
&nbsp;如目录不存在，程序将自动创建</td>
  				</tr>
  				<tr>
  				  <td height="30" align="center" bgcolor="#FFFFFF" class="td">备份数据库名称(名称)：</td>
				  <td bgcolor="#FFFFFF" class="td"><input name=bkDBname type=text value="<%=year(Now)&month(Now)&day(Now)&"_"&hour(Now)&Minute(Now)&Second(Now)%>.mdb" size="40" />
&nbsp;如备份目录有该文件，将覆盖，如没有，将自动创建</td>
  				</tr>
  				<tr>
  				  <td height="30" bgcolor="#FFFFFF" class="td">&nbsp;</td>
				  <td bgcolor="#FFFFFF" class="td"><input type=submit class="bnt" value="确定" /></td>
  				</tr>
  				<tr>
  				  <td height="30" bgcolor="#FFFFFF" class="td">&nbsp;</td>
				  <td bgcolor="#FFFFFF" class="td">注意：所有路径都是相对与程序空间根目录的相对路径 </td>
  				</tr>	
  				</form>
  </table>
<%
end sub

sub updata()
	dim Dbpath,bkfolder,bkdbname,fso
	Dbpath="../Data/"&DataName&""
	Dbpath=server.mappath(Dbpath)
	bkfolder=request.form("bkfolder")
	bkdbname=request.form("bkdbname")
	Set Fso=Server.CreateObject("Scripting.FileSystemObject")
	if fso.fileexists(dbpath) then
		If CheckDir(bkfolder) = True Then
		fso.copyfile dbpath,bkfolder& "\"& bkdbname
		else
		MakeNewsDir bkfolder
		fso.copyfile dbpath,bkfolder& "\"& bkdbname
		end if		
Response.Write "<script language=javascript>alert('备份数据库成功!');this.location.href='sd_Admin_data.asp?action=SpaceSize';</script>"

	Else
Response.Write "<script language=javascript>alert('数据库路径错误');history.go(-1);</script>"

	End if
end sub
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
    dim fso1
	folderpath=Server.MapPath(".")&"\"&folderpath
    Set fso1 = Server.CreateObject("Scripting.FileSystemObject")
    If fso1.FolderExists(FolderPath) then
       '存在
       CheckDir = True
    Else
       '不存在
       CheckDir = False
    End if
    Set fso1 = nothing
End Function
'-------------根据指定名称生成目录-----------------------
Function MakeNewsDir(foldername)
	dim f,fso1
    Set fso1 = Server.CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function
%>
<%
'====================恢复数据库=========================
sub RestoreData()
%>
<table border="0"  cellspacing="1" cellpadding="3" class="admintable1">
	<tr>
		<td colspan="2" class="admintitle">恢复网站系统数据( 需要FSO支持，FSO相关帮助请看微软网站 )</td>
    </tr>
<form method="post" action="sd_Admin_Data.asp?action=RestoreData&act=Restore">
<tr>
  <td width="19%" height="30" align="center" bgcolor="#FFFFFF" class="td">备份数据库路径(相对)：</td>
  <td width="81%" bgcolor="#FFFFFF" class="td"><input name=DBpath type=text id="DBpath" value="../DataBackup/<%=year(Now)&"-"&month(Now)&"-"&day(Now)%>.MDB" size=40 /> 
  找到的备份数据库：<%=FileList("../Databackup","mdb")%></td>
</tr>
<tr>
  <td height="30" align="center" bgcolor="#FFFFFF" class="td">目标数据库路径(相对)：</td>
  <td bgcolor="#FFFFFF" class="td"><input type=text size=40 name=backpath value="../Data/<%=DataName%>" /></td>
</tr>
<tr>
  <td height="30" bgcolor="#FFFFFF" class="td">&nbsp;</td>
  <td bgcolor="#FFFFFF" class="td"><input type=submit class="bnt" value="恢复数据" /></td>
</tr>
<tr>
  <td height="30" bgcolor="#FFFFFF" class="td">&nbsp;</td>
  <td bgcolor="#FFFFFF" class="td">请谨慎操作！</td>
</tr>	
</form>
</table>
<%
end sub
sub SpaceSize()
%>
<table height="1" border="0" cellpadding="3"  cellspacing="1" bgcolor="#F2F9E8" class="admintable1">
  <tr>
    <td colspan="2" class="admintitle">程序占用空间情况 </td>
  </tr>
  <tr>
    <td width="19%" height="30" align="center" bgcolor="#FFFFFF">系统占用空间总计：</td>
    <td width="81%" bgcolor="#FFFFFF"><img src="images/bar1.gif" width=400 height=9 />&nbsp;
    <%allsize()%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#FFFFFF">法规数据占用空间：</td>
    <td bgcolor="#FFFFFF"><img src="images/bar1.gif" width=<%=drawbar("Data")%> height=9 />&nbsp;<%othersize("Data")%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#FFFFFF">备份数据占用空间：</td>
    <td bgcolor="#FFFFFF"><img src="images/bar1.gif" width=<%=drawbar("Databackup")%> height=9 />&nbsp;<%othersize("Databackup")%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#FFFFFF">系统图片占用空间：</td>
    <td bgcolor="#FFFFFF"><img src="images/bar1.gif" width=<%=drawbar("Images")%> height=9 />&nbsp;<%othersize("Images")%></td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#FFFFFF">广告图片占用空间：</td>
    <td bgcolor="#FFFFFF"><img src="images/bar1.gif" width=<%=drawbar("ad")%> height=9 />&nbsp;<%othersize("ad")%></td>
  </tr>
</table>
<%end sub%>
<%
sub othersize(names)
	dim fso,path,ml,mlsize,dx,d,size
	set fso=Server.CreateObject("Scripting.FileSystemObject")
	path=server.mappath("..\Images")
	ml=left(path,(instrrev(path,"\")-1))&"\"&names
	
	On Error Resume Next
	set d=fso.getfolder(ml) 
	If Err Then
		err.Clear
		Response.Write "<font color=red>提示：没有“"&names&"”目录</font>"					
		'Response.End()
	End If
	mlsize=d.size
	size=mlsize
	dx=size & "&nbsp;Byte" 
	if size>1024 then
	   size=(Size/1024)
	   dx=formatnumber(size,2) & "&nbsp;KB"
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;MB"		
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;GB"	   
	end if   
	response.write dx
end sub

sub allsize()
	dim fso,path,ml,mlsize,dx,d,size
	set fso=Server.CreateObject("Scripting.FileSystemObject")
	path=server.mappath("../index.asp")
	ml=left(path,(instrrev(path,"\")-1))
	set d=fso.getfolder(ml) 
	mlsize=d.size
	size=mlsize
	dx=size & "&nbsp;Byte" 
	if size>1024 then
	   size=(Size/1024)
	   dx=size & "&nbsp;KB"
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;MB"		
	end if
	if size>1024 then
	   size=(size/1024)
	   dx=formatnumber(size,2) & "&nbsp;GB"	   
	end if   
	response.write dx
end sub

Function Drawbar(drvpath)
	dim fso,drvpathroot,d,size,totalsize,barsize
	set fso=Server.CreateObject("Scripting.FileSystemObject")
	drvpathroot=server.mappath("../Images")
	drvpathroot=left(drvpathroot,(instrrev(drvpathroot,"\")-1))
	set d=fso.getfolder(drvpathroot)
	totalsize=d.size
	
	On Error Resume Next
	drvpath=server.mappath("../"&drvpath)
	If Err Then
		err.Clear
		Response.Write "没有名为“"&drvpath&"”的目录，您可以修改文件以正确显示该目录的使用量。"			
		Response.End()
	End If
	set d=fso.getfolder(drvpath)
	size=d.size
	
	barsize=cint((size/totalsize)*400)
	Drawbar=barsize
End Function 

Function FileList(FolderUrl,FileExName)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set folder=fso.GetFolder(Server.MapPath(Trim(FolderUrl)))
Set file=folder.Files
FileList=""
For Each FileName in file
If Trim(FileExName)<>"" Then
	If InStr(Trim(FileExName),Trim(Mid(FileName.Name,InStr(FileName.Name,".")+1,len(FileName.Name))))>0 Then
    	FileList=FileList&""&FileName.Name&"|"
	End If
Else
     FileList=FileList&"<a href='#'>"&FileName.Name&"</a><br>"
End If
Next
Set file=Nothing
Set folder=Nothing
Set fso=Nothing
End Function
%>
<!--#include file="sd_copy.asp"-->
</body>
</html>
