<!--#include file="../Include/conn.asp"-->
<!--#include file="../Include/ConnDatabase.asp"-->
<!--#include file="CheckAdmin.asp"-->
<%
'=====================================
'天天企业网站管理系统  TianTianCMS
'天天网络科技工作室版权所有
'官方客服中心 http://www.ip126.com
'微信公众号 ip126com
'QQ:530051328 mail:bbfhq@163.com
'=====================================
%>
<%
if Instr(session("AdminPurview"),"|49,")=0 then 
  response.write ("<font color='red')>你不具有该管理模块的操作权限，请返回！</font>")
  response.end
end if
'========判断是否具有管理权限
%>
<link rel="stylesheet" href="Images/Admin.css">
<script language="javascript" src="../Script/Admin.js"></script>
<style type="text/css">
<!--
.STYLE1 {color: #2f2f2f}
.STYLE2 {color: #FF0000}
-->
</style>
<html>   
<head>   
<meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
<title>数据库管理</title>   
 </head>       
<body class="ss">
<table border="0" width="95%" align="center" cellspacing="0" cellpadding="0">
        <tr>
          <td  height="2"></td>
        </tr>
</table>
<%If SystemDatabaseType = 1 Then%>
<table border="0" width="95%" style="font-size: 12px; border-bottom:#D6DDE9 2px solid; border-left:#D6DDE9 1px solid; border-top:#D6DDE9 1px solid; border-right:#D6DDE9 2px solid"  align="center" cellpadding="4" cellspacing="0"  bordercolorlight="#D6DDE9" bordercolordark="#ffffff">
      <tr>
          <td  align="center">
	<li>本功能只适应ACCESS数据库，目前数据库为MS SQL，不能使用此功能!<br>MS SQL数据库管理可通过空间商给的数据库管理后台或远程桌面管理（要有权限才行）进行。具体咨询空间商。<br>
	
	</td>
        </tr>
</table>
<%response.End
End if
Dim action,dbpath,temp,fileext,file1,file2,Engine   
Dim   fso,   f,   f1,   fc 
Call OpenConn
on error resume next
action=request.QueryString("action")
'filename=request("filename")  
select   case   action   
case   "beifen" 
Set   fso   =   CreateObject("Scripting.FileSystemObject")   
file1=fso.GetParentfoldername(server.MapPath(".\"))&"\"&Replace(SiteDataPath,"../","")   
file2=fso.GetParentfoldername(server.MapPath("./"))&"\Databasebak\"&request.Form("filename")   
fso.copyfile   file1,file2   
set   fso=nothing   
response.write "<script language='javascript'>" & chr(13)
response.write "alert('数据库备份成功！');" & Chr(13)
response.write "window.document.location.href='admin_data.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End()   
case   "yasuo"

dim founderr,errmsg
founderr=false
errmsg=""

dim boolIs97
dbpath = "/"&strInstallDir&"Databasebak/"&request("filename")
boolIs97 = request("boolIs97")
If dbpath <> "" Then
dbpath = server.mappath(dbpath)
	response.write(CompactDB(dbpath,boolIs97))
End If

Const JET_3X = 4

Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next 
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")

	If boolIs97 = "True" Then
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
		"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
		& "Jet OLEDB:Engine Type=" & JET_3X
	Else
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
		"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
	End If

fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")

if err.number="0" then
	response.write "<li>你的数据库"&dbpath&"已经压缩成功!<br>"
	response.end

else
	response.write "<li>压缩过程中出现错误!<br>"
	response.end
end if
Set fso = nothing
Set Engine = nothing
Else
	response.write "<li>数据库名称或路径不正确. 请重试!"
	response.end
End If

End Function


Response.End()  
case   "huanyuan"   
Set   fso   =   CreateObject("Scripting.FileSystemObject")   
file1=fso.GetParentfoldername(server.MapPath("./"))&"\"&Replace(SiteDataPath,"../","")   
file2=fso.GetParentfoldername(server.MapPath("./"))&"\Databasebak\"&request.Form("filename")   
fso.copyfile   file2,file1   
set   fso=nothing   
response.write "<script language='javascript'>" & chr(13)
response.write "alert('还原完成！');" & Chr(13)
response.write "window.document.location.href='admin_data.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End() 

case   "del"
	Set fso=Server.CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(Server.mappath("..\Databasebak\"&request.Form("filename")&"")) Then
       fso.DeleteFile Server.mappath("..\Databasebak\"&request.Form("filename")&"")
    End If
response.write "<script language='javascript'>" & chr(13)
response.write "alert('删除完成！');" & Chr(13)
response.write "window.document.location.href='admin_data.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End()

case   else   
dataform   
end   select   
    
function   dataform()   
%>   
<table class="tableborder" width="95%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr>
    <th>网站数据库管理</th>
  </tr>
  <tr>
    <td height="24" align="center" nowrap="nowrap"  class="forumrow">注：操作仅对标准版ACCESS数据库有效，对企业版MS SQL数据库不能操作！MS SQL数据库管理可通过空间商给的数据库管理后台或远程桌面管理（要有权限才行）进行。具体咨询空间商。</td>
  </tr>
</table>
<br>

<table class="tableborder" width="95%" border="0" align="center" cellpadding="3" cellspacing="1">
    
      <tr>   
          <td   width="30%" height="50" align="right"  class="forumrow"><strong><img src="images/Dot_Info.gif" width="16" height="16">&nbsp;备份：&nbsp;</strong></td>   
          <form   name="form1"   method="post"   action="admin_data.asp?action=beifen"><td width="70%" align="left"   class="forumrow">   
              <input   name="filename" type="text"  id="filename"   style="width:200px" readonly value="<%=filename()%>">   
              <input   type="submit"  name="Submit"  value="开始备份"  class="button1" onmouseover=this.className="button2";   onmouseout=this.className="button1"; style="height:26px;line-height:20px"> <br> 注：数据库名称由系统自动生成！  
          </form></td>   
             
      </tr>   
     
      <tr>   
          <td   width="30%" height="50" align="right"  class="forumrow"><strong><img src="images/Dot_Info.gif" width="16" height="16" class="forumrow">&nbsp;还原：&nbsp;</strong></td>   
          <form   name="form3"   method="post"   action="admin_data.asp?action=huanyuan"><td width="70%" align="left" class="forumrow">   
              <select   name="filename"   id="filename"   style="width:200px   ">   
<%   
Dim   fso,   f,   f1,   fc   
Set   fso   =   CreateObject("Scripting.FileSystemObject")   
dbpath=fso.GetParentfoldername(server.MapPath("./"))&"\Databasebak"   
Set   f   =   fso.GetFolder(dbpath)   
Set   fc   =   f.Files   
For   Each   f1   in   fc   
temp=split(f1.name,".")   
fileext=temp(ubound(temp))   
if   fileext="asa"   then   
response.Write("<option   value='"&f1.name&"'>"&f1.name&"</option>")   
end   if   
next   
set   fso=nothing   
%>   
      </select>   
              &nbsp;<input   type="submit"   name="Submit"   value="开始还原"   class="button1"   onmouseover=this.className="button2";   onmouseout=this.className="button1";   onClick="if(confirm('真的还原吗？')){return   true;}else{return   false;}" style="height:26px;line-height:20px"> <br> 注：还原时请慎重正确选择源数据库！ 
          </td></form>   
          
      </tr> 
         <tr>   
          <td   width="30%" height="50" align="right"  class="forumrow"><strong><img src="images/Dot_Info.gif" width="16" height="16"   class="forumrow">&nbsp;压缩：&nbsp;</strong></td>   
          <form   name="form2"   method="post"   action="admin_data.asp?action=yasuo"><td width="70%" align="left"  class="forumrow">
		                <select   name="filename"   id="filename"   style="width:200px   ">   
<%   

Set   fso   =   CreateObject("Scripting.FileSystemObject")   
dbpath=fso.GetParentfoldername(server.MapPath("./"))&"\Databasebak"   
Set   f   =   fso.GetFolder(dbpath)   
Set   fc   =   f.Files   
For   Each   f1   in   fc   
temp=split(f1.name,".")   
fileext=temp(ubound(temp))   
if   fileext="asa"   then   
response.Write("<option   value='"&f1.name&"'>"&f1.name&"</option>")   
end   if   
next   
set   fso=nothing   
%>   
      </select>   
	  
              <!--input   name="filename"   type="text"   id="filename"   style="width:200px   "   value="<%=SiteDataPath%>" readonly="readonly"-->   
              <input   type="submit"   name="Submit"   value="开始压缩"   class="button1"   onmouseover=this.className="button2";   onmouseout=this.className="button1"; style="height:26px;line-height:20px"><br>
			  <input type="checkbox" name="boolIs97" value="True">如果使用 Access 97 数据库请选择
(默认为 Access 2000 数据库)<br>注：只能对备份的数据库进行压缩！   
          </td></form>   
          
      </tr>
	  
      <tr>   
          <td   width="30%" height="50" align="right"  class="forumrow"><strong><img src="images/Dot_Info.gif" width="16" height="16">&nbsp;删除：&nbsp;</strong></td>   
          <form   name="form3"   method="post"   action="admin_data.asp?action=del"><td width="70%" align="left"  class="forumrow">   
              <select   name="filename"   id="filename"   style="width:200px   ">   
<%   
Set   fso   =   CreateObject("Scripting.FileSystemObject")   
dbpath=fso.GetParentfoldername(server.MapPath("./"))&"\Databasebak"   
Set   f   =   fso.GetFolder(dbpath)   
Set   fc   =   f.Files   
For   Each   f1   in   fc   
temp=split(f1.name,".")   
fileext=temp(ubound(temp))   
if   fileext="asa"   then   
response.Write("<option   value='"&f1.name&"'>"&f1.name&"</option>")   
end   if   
next   
set   fso=nothing   
%>   
      </select>   
              &nbsp;<input   type="submit"   name="Submit"   value="开始删除"   class="button1"   onmouseover=this.className="button2";   onmouseout=this.className="button1";   onClick="if(confirm('真的删除吗？')){return   true;}else{return   false;}" style="height:26px;line-height:20px"> <br> <font color=red>注：删除选定的备份数据库，要看清那个是最新的！</font> 
          </td></form>   
         
      </tr> 

</table>   
<%   
end   function   
    
function   filename()   
filename=year(now)   
if   len(month(now))=1   then   
filename=filename&"0"&month(now)   
else   
filename=filename&month(now)   
end   if   
if   len(day(now))=1   then   
filename=filename&"0"&day(now)   
else   
filename=filename&day(now)   
end   if   
if   len(hour(now))=1   then   
filename=filename&"0"&hour(now)   
else   
filename=filename&hour(now)   
end   if   
if   len(minute(now))=1   then   
filename=filename&"0"&minute(now)   
else   
filename=filename&minute(now)   
end   if   
if   len(second(now))=1   then   
filename=filename&"0"&second(now)   
else   
filename=filename&second(now)   
end   if   
filename=filename&"."&"asa"   
end   function   
%></td>   
 </tr>
</table>   
</body>   
</html> 