<!-- #include file="conn.asp" -->
<!-- #include file="check.asp" -->

<% 
 '===========================================================================================
	'软件名称：126 cms 视频影视管理系统
	'程序版权：126电影               '咨询QQ：479025
	'开发作者：magicblack(479025)    '官方网站：http://www.126oo.com/
	'Copyright (C) 2009 - ... 126oo.com  All Rights Reserved.
	'郑重声明:
	'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
	'    2、任何个人或组织不得以盈利为目的发布,修改,本软件及其他副本上一切关于版权的信息；
	'    3、126电影保留此软件的法律追究权利；
'==========================================================================================
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>数据库管理 - 后台管理中心 - 126电影程序CMS</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="images/css_body.css" type=text/css rel=stylesheet>
<script language="javascript" src="images/admin.js"></script>
</HEAD>
<BODY>
<DIV class=bodytitle>
<DIV class=bodytitleleft></DIV>
<DIV class=bodytitletxt>数据库管理</DIV>
<DIV class=bodytitletxt2><a href="admin_database.asp?action=Restore">还原数据库</a> | <a href="admin_database.asp?action=BackupData">备份数据库</a> | <a href="admin_database.asp?action=Compact">压缩数据库</a></DIV>
</DIV>


<%
response.Charset="GBK"
dim action
action = SafeData("RQ","action",0)

Select Case action
Case "BackupData"
	call BackupData()
Case "Compact"
	call ShowCompact()
Case "CompactData"
	call CompactData()
Case "Restore"
	call ShowRestore()
Case "RestoreData"
	call RestoreData()
Case "delback"
	call DelBackup()
Case else
	ShowMsg "错误参数!","admin_database.asp?action=Backup"
End Select

Function TimeName(DataBackName)
	DataBackName=Replace(DataBackName,"-","")
	DataBackName=Replace(DataBackName,":","")
	DataBackName=Replace(DataBackName," ","")
	TimeName=DataBackName
end Function

sub BackupData()
	dim DataBackName,DataBackDir,fso
	DataBackDir ="../dbback"
	DataBackName = TimeName(Now())&"_bak.bak"
	DataBackDir = server.MapPath(DataBackDir)
	Set Fso=server.createobject("Scripting.FileSystemObject")
	If fso.FolderExists(DataBackDir)=false Then
		fso.CreateFolder(DataBackDir)
	end if
	fso.copyfile server.mappath("../"&app_dbpath),DataBackDir & "\" & DataBackName
	ShowMsg "备份的数据库为"&DataBackName&"","admin_database.asp?action=Restore"

	Set fso = Nothing
end sub

 sub CompactData()
	Dim fso, Engine, strapp_dbpath,app_dbpathx
	app_dbpathx=Server.mappath("../"&app_dbpath)
	strapp_dbpath = left(app_dbpathx,instrrev(app_dbpathx,"\"))
	on error resume next
	Set Conn = Nothing
	Set Fso=server.createobject("Scripting.FileSystemObject")
	If fso.FileExists(app_dbpathx) Then
		Set Engine = CreateObject("JRO.JetEngine")
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & app_dbpathx," Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strapp_dbpath & "temp.mdb"
		fso.CopyFile strapp_dbpath & "temp.mdb",app_dbpathx
		fso.DeleteFile(strapp_dbpath & "temp.mdb")
		Set fso = Nothing
		Set Engine = Nothing
		ShowMsg "数据库压缩成功！","admin_database.asp?action=Compact"
	Else
		ShowMsg "没有找到数据库！","admin_database.asp?action=Compact"
	End If
end sub 

sub RestoreData()
	dim backpath,fso
	backpath="../dbback/"&Request.QueryString("file")
	if backpath="" then
		FoundErr=True
		ShowMsg "请指定原备份的数据库文件名！","admin_database.asp?action=Restore"
		exit sub	
	end if
	backpath=server.mappath(backpath)
	on error resume next
	Set Conn = Nothing
	Set Fso=server.createobject("Scripting.FileSystemObject")
	if fso.fileexists(backpath) then  					
		fso.copyfile Backpath,Server.mappath("../"&app_dbpath)
		ShowMsg "成功恢复数据！","admin_database.asp?action=Restore"
	else
		ShowMsg "找不到指定的备份文件！","admin_database.asp?action=Restore"
	end if
	Set Fso=Nothing
end sub

Sub DelBackup()
	dim Document,fso,backpath
	backpath="../dbback/"&Request.QueryString("file")
	if backpath="" then
		FoundErr=True
		ShowMsg "请指定备份的数据库文件名！","admin_database.asp?action=Restore"
		exit sub	
	end if
	Set Fso=server.createobject("Scripting.FileSystemObject")

	fso.DeleteFile(server.mappath(backpath))
		ShowMsg "删除备份数据库成功！","admin_database.asp?action=Restore"
	Set Fso=Nothing
End sub

sub ShowRestore()
%>
<TABLE width="96%" border=0 align=center cellpadding="5" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
  <TBODY>
    <TR bgColor=#f5fafe>
      <TD align="center">备份文件名</TD>
      <TD width="20%" align="center">备份时间</TD>
      <TD width="15%" align="center">操作</TD>
    </TR>
    <% Dim Fso,i
	Set Fso=server.createobject("Scripting.FileSystemObject")
	dim theFolder,theFile,strFileType
	if Not fso.FolderExists(Server.MapPath("../dbback")) then
		response.write "找不到数据库备份文件夹"
		response.end
	end if
	Set theFolder=fso.GetFolder(Server.MapPath("../dbback"))
	For Each theFile In theFolder.Files%>
    <TR bgcolor="#FFFFFF">
      <TD align="center"><%=theFile.Name%></TD>
      <TD align="center"><%=theFile.DateLastModified%></TD>
      <TD align="center"><a href="admin_database.asp?action=RestoreData&file=<%=theFile.Name%>">还原</a> | <a href="admin_database.asp?action=delback&file=<%=theFile.Name%>">删除</a></TD>
	</TR>
	<%Next
Set Fso=Nothing%>
  </TBODY>
</TABLE>
<%end sub
 sub ShowCompact()%>
<TABLE width="96%" border=0 align=center cellpadding="4" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
  <form action="?action=CompactData" method="post">
  <TBODY>
    <TR>
      <TD vAlign=center bgColor=#f5fafe><strong>压缩数据库</strong></TD>
      </TR>
    <TR>
      <TD align="center" bgColor=#f5fafe>压缩前，建议先备份数据库，以免发生意外错误。 </TD>
      </TR>
    <TR align="center" bgcolor="#f8fbfb">
      <TD><INPUT class=inputbut type=submit value=压缩数据库 name=Submit></TD>
    </TR>
  </TBODY>
  </form>
</TABLE>
 <%end sub
%>
</BODY>
</HTML>
