<!-- #include file="include/onlogin.asp" -->
<!-- #include file="include/conn.asp" -->
<%
tit="<a href='admin_data.asp'>数据更新</a> ┋ " & _
      "<a href='admin_sql.asp'>执行SQL</a> ┋ " & _
      "<a href='admin_datamanage.asp?action=BackupData'>备份数据库</a> ┋ " & _
      "<a href='admin_datamanage.asp?action=CompressData'>压缩数据库</a> ┋ " & _
      "<a href='admin_datamanage.asp?action=RestoreData'>恢复数据库</a> ┋ " & _
      "<a href='admin_datamanage.asp?action=SpaceSize'>系统空间占用</a>"
response.write header(10,tit)

dim dbpath,bkfolder,bkdbname,fso,fso1

select case action
case "CompressData"
		if request("act")="Compress" then
		call CompactDB()
		else
		dim tmprs
		dim allarticle
		dim Maxid
		dim topic,username,dateandtime,body
		call CompressData()
		end if

case "BackupData"
		if request("act")="Backup" then
		call updata()
		else
		call BackupData()
		end if

case "RestoreData"
dim backpath
		if request("act")="Restore" then
		call restore()
		else
		call RestoreData()
		end if

 case "SpaceSize"	
		call SpaceSize()

end select

conn.close
set conn=nothing

response.write ender()

'====================系统空间占用=======================
sub SpaceSize()
on error resume next
%>
<table border=1 cellspacing=0 cellpadding=3 width=600 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>
<tr>
<td height=25 align=center>
<b>系统空间占用</b>
</td>
</tr> 	
<tr><td>
<blockquote><br>
<b>系统文件占用空间情况：</b><br><br>
程序文件占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawspecialbar%> height=10>&nbsp;<%showSpecialSpaceinfo("Program")%><br><br> 			
数据文件占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("data")%> height=10>&nbsp;<%showSpaceinfo("data")%><br><br>
备份数据占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("databackup")%> height=10>&nbsp;<%showSpaceinfo("databackup")%><br><br>
网站广告占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("ads")%> height=10>&nbsp;<%showSpaceinfo("ads")%><br><br>
站点图片占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("images")%> height=10>&nbsp;<%showSpaceinfo("images")%><br><br>
<b>上传文件占用空间情况：</b><br><br>
用户上传头像空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/userface")%> height=10>&nbsp;<%showSpaceinfo("upload/userface")%><br><br>
新闻图片占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/news")%> height=10>&nbsp;<%showSpaceinfo("upload/news")%><br><br>
文章图片占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/article")%> height=10>&nbsp;<%showSpaceinfo("upload/article")%><br><br>
下载图片文件占用：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/down")%> height=10>&nbsp;<%showSpaceinfo("upload/down")%><br><br>
影视图片文件占用：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/video")%> height=10>&nbsp;<%showSpaceinfo("upload/video")%><br><br>
下载软件文件占用：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("softdown")%> height=10>&nbsp;<%showSpaceinfo("softdown")%><br><br>
交易系统占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/business")%> height=10>&nbsp;<%showSpaceinfo("upload/business")%><br><br>
论坛上传占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/forum")%> height=10>&nbsp;<%showSpaceinfo("upload/forum")%><br><br>
动画图片占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/flash")%> height=10>&nbsp;<%showSpaceinfo("upload/flash")%><br><br>
图库文件占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/gallery")%> height=10>&nbsp;<%showSpaceinfo("upload/gallery")%><br><br>
网站推荐占用空间：&nbsp;<img src="images/forum/bar7.gif" width=<%=drawbar("upload/website")%> height=10>&nbsp;<%showSpaceinfo("upload/website")%><br><br>
<b>系统占用空间总计：</b><br><br><img src="images/forum/bar7.gif" width=<%=showspecialspaceinfo("All")%> height=10> <%showspecialspaceinfo("All")%>
</blockquote> 	
</td></tr>
</table>
<%
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;字节" 
 		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("images")
 		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("images")
 		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("images")
 		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

'====================恢复数据库=========================
sub RestoreData()
%>
<p><b>本功能需要FSO支持，FSO相关帮助请看微软网站</b></p>
<table border=1 cellspacing=0 cellpadding=3 width=600 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>
<tr><td width="100%" align="center" height="30" valign="middle" ><B>恢复备份数据库</B></td></tr>
<tr><td align=center>
<table cellpadding=3 cellspacing=1 border=0>
<form method="post" action="admin_datamanage.asp?action=RestoreData&act=Restore">
<tr><td height=90>
备份数据库路径(相对)：<input type=text size=40 name=DBpath value="databackup\$%@#<%=date()%>www.edxsky.cn.data.mdb">&nbsp;&nbsp;<BR>
目标数据库路径(相对)：<input type=text size=40 name="backpath" value="<%=web_var(web_config,6)%>">

</td></tr></table></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<b>注意：</b><br>
&nbsp;&nbsp;&nbsp;● <b>默认情况下目标数据库为当前系统数据库，也可使用新名称自行命名（需修改conn.asp文件）</b><br>
&nbsp;&nbsp;&nbsp;● 所有路径都是相对于程序空间根目录的相对路径<br>
&nbsp;&nbsp;&nbsp;● 您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br>
</td></tr>
<tr><td align=center>
<input type=submit value="恢 复 数 据">
</td></tr></form>
</table>
</td></tr></table>
<%
end sub

sub restore()
			Dbpath=request.form("Dbpath")
			backpath=request.form("backpath")
			if dbpath="" then
			response.write "请输入备份数据库的路径和全名<br><br>"	
			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 "<font color='#FF0000'><b>数据库已成功恢复！</b></font><br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
			else
			response.write "<font color='#FF0000'><b>没有找到备份数据库文件！</b></font><br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"	
			end if
end sub

'====================备份数据库=========================
sub BackupData()
%>
<p><b>本功能需要FSO支持，FSO相关帮助请看微软网站</b></p>
<table border=1 cellspacing=0 cellpadding=3 width=600 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>
<tr><td width="100%" align="center" height="30" valign="middle" ><B>备份数据库</B></td></tr>
<tr><td align=center>
<table cellpadding=3 cellspacing=1 border=0>
<form method="post" action="admin_datamanage.asp?action=BackupData&act=Backup">
<tr><td height=90>
当前数据库地址(相对路径)：<input type=text size=40 name=dbpath value="<%=web_var(web_config,6)%>"><BR>
备份数据库目录(相对路径)：<input type=text size=30 name=bkfolder value=databackup>&nbsp;如目录不存在，程序将自动创建<BR>
备份数据库名称(文件全名)：<input type=text size=30 name=bkDBname value="$%@#<%=date()%>www.edxsky.cn.data.mdb">&nbsp;如该文件存在将会被覆盖，如没有将自动创建<BR>
</td></tr></table></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<b>注意：</b><br>
&nbsp;&nbsp;&nbsp;● 所有路径都是相对于程序空间根目录的相对路径<br>
&nbsp;&nbsp;&nbsp;● <b>请尽量避免使用 .mdb 的后缀名命名备份数据库</b><br>
&nbsp;&nbsp;&nbsp;● 您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br>
</td></tr>
<tr><td align=center>
<input type=submit value="开 始 备 份">
</td></tr></form>
</table>
</td></tr></table>
<%
end sub

sub updata()
	    dbpath=server.mappath(request.form("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 "<font color='#FF0000'><b>备份数据库成功！</b></font> 您备份的数据库地址为：<br><br>" &bkfolder& "\"& bkdbname &"<br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
		Else
			response.write "找不到您所需要备份的数据库文件。<br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
		End if
end sub
'------------------检查某一目录是否存在-------------------
Function CheckDir(FolderPath)
	folderpath=Server.MapPath(".")&"\"&folderpath
    Set fso1 = 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
    Set fso1 = CreateObject("Scripting.FileSystemObject")
        Set f = fso1.CreateFolder(foldername)
        MakeNewsDir = True
    Set fso1 = nothing
End Function


'====================压缩数据库 =========================
sub CompressData()
%>
<p><b>本功能需要FSO支持，FSO相关帮助请看微软网站</b></p>
<table border=1 cellspacing=0 cellpadding=3 width=600 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>
<tr><td width="100%" align="center" height="30" valign="middle" ><B>压缩数据库</B></td></tr>
<tr><td align=center>
<table cellpadding=3 cellspacing=1 border=0>
<form action="admin_datamanage.asp?action=CompressData&act=Compress" method="post">
<tr><td height=90 align=center>
压缩数据库地址(相对路径)：<input type="text" name="dbpath" value='databackup\$%@#<%=date()%>www.edxsky.cn.data.mdb' size=40><br><br><br>
<b>注意：</b>正在使用中的数据库不能压缩，请选择备份数据库进行压缩操作
</td></tr></table></td></tr>
<tr><td align=center>
<input type=submit value="开 始 压 缩">
</td></tr></form>
</table>
</td></tr></table>
<%
end sub

'=====================压缩参数=========================
Function CompactDB()
	Dim Engine, strDBPath
	dbpath=server.mappath(request.form("dbpath"))
	strDBPath = left(dbPath,instrrev(DBPath,"\"))
	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 "<font color=#FF0000><b>数据库压缩成功！</b></font> 您压缩的数据库地址为：<br><br>" & dbpath &"<br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
	Else
		response.write "<font color=#FF0000><b>数据库没有找到！</b></font><br><br><a href='javascript:history.back(-1)'><<返回上一页</a>"
	End If
End Function 	
%>