<!--#include file="../../Inc/Cls_Main.Asp"-->
<!--#include file="../inc/Cls_Admin.Asp"-->
<!--#include file="../inc/Cls_MapPath.Asp"-->
<!--#include file="../Admin_Check.Asp"-->
<%
Dim CmsAdmin
'=============================================================================
Set CmsAdmin = New Cls_Admin
CmsAdmin.SetAdminTitle = CmsSiteName
CmsAdmin.SetBodyCssName = "mainbody"
CmsAdmin.SetAdminPath = CmsAdminMapPath
CmsAdmin.LoadHead()
'=============================================================================
Dim Action
'=============================================================================
Action = Easp.Get("action")
Select Case Action
    Case "savemain"
        Call SaveMain()
    Case Else
        Call PageLoad()
End Select
CmsAdmin.LoadFooter()
Set CmsAdmin = Nothing

Sub PageLoad()
    ChkSysAdminLevel "sys_config", "show"
    '=====================================================================
%>
<script src="<%=CmsAdminMapPath%>js/check/public.type.check.js"></script>
<form name="myform" id="myform" method="post" action="?action=savemain">
  <div class="navigation">插件管理 &gt; 恢复数据库</div>
  <div id="contentTab">
    <div class="content-tab">
      <ul class="tab_nav">
        <li><a onclick="tabs(this);" class="selected" href="javascript:void(0);">恢复数据库</a></li>
      </ul>
    </div>
    <div class="tab_con" style="display: block;">
      <table class="form_table">
        <col width="200px">
          </col>
        
        <tbody>
          <tr>
            <th> 备份数据库名称： </th>
            <td class="td2"><%=GetBakPath()%><span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 当前使用数据库： </th>
            <td class="td2"><input type="text" name="DataBaseFile" id="DataBaseFile" class="txtInput w350" autocomplete="off" datatype="*10-50" nullmsg="目标数据库路径必须填写" errormsg="至少10个字符,最多50个字符!" value="<%=DataBasePath%>" readonly="readonly" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th></th>
            <td><input type="submit" class="btnSubmit" value="开始恢复" /></td>
          </tr>
          <tr>
            <th></th>
            <td>1、本程序的默认备份数据库文件在bak目录下，请按照您的备份文件自行修改。<br/>
              2、您可以用这个功能来备份您的法规数据，以保证您的数据安全！<br/>
              3、注意：所有路径都是相对与程序空间根目录的相对路径。<br/>
              4、<font color="blue">建议使用之前所下载的备份数据库,替换原来的数据库即可。</font></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</form>
<%
End Sub

Sub SaveMain()
    ChkSysAdminLevel "sys_config", "edit"
    '=====================================================================
    Dim DataBaseFile, BackupName, Result
    DataBaseFile = Trim(Easp.Post("DataBaseFile:s"))
    BackupName = Trim(Easp.Post("BackupName:s"))
    '=====================================================================
    If Easp.IsN(BackupName) Then
        CmsAdmin.JscriptMsg "备份数据库名称必须填写！", "back", "Error", "null"
    End If
    If Easp.IsN(DataBaseFile) Then
        CmsAdmin.JscriptMsg "目标数据库路径必须填写！", "back", "Error", "null"
    End If
    '=====================================================================
    Easp.Use "fso"
    Result = Easp.Fso.CopyFile(BackupName, DataBaseFile)
    If Result Then
        CmsAdmin.JscriptMsg "恢复数据库成功！", "Admin.Data.Restore.Asp", "Success", "null"
    Else
        CmsAdmin.JscriptMsg "恢复数据库失败！", "back", "Error", "null"
    End If
    '=====================================================================
End Sub

Function GetBakPath()
    Dim strTemp
    strTemp = ""
    strTemp = strTemp & "<select name=""BackupName"" class=""select2"" datatype=""*"">" & vbCrLf
    strTemp = strTemp & "<option value="""">请选择备份数据库</option>" & vbCrLf
    Easp.Use "fso"
    If Easp.Fso.IsFolder(DataBaseBakPath) Then
        Dim BakPath, Flist, i
        BakPath = DataBaseBakPath
        Flist = Easp.Fso.List(BakPath, 1)
        For i = 0 To UBound(Flist, 2)
            strTemp = strTemp & "<option value="""& BakPath & Flist(0, i) &""">"& Flist(0, i) &"</option>" & vbCrLf
        Next
    End If
    strTemp = strTemp & "</select>"
    GetBakPath = strTemp
End Function
%>
