<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="Backup.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Sys.Backup" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
<dl class="ui-tabs">
    <dt><a href="javascript:" class="on">系统备份操作</a></dt>    
    <dd>
        <div class="m-content">
            <table class="m-list" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th width="15%" class="g-fleft">操作名</th>
                    <th width="40%" class="g-fleft">说明</th>
                    <th width="20%">自动备份</th>
                    <th width="10%">最后备份时间</th>
                    <th width="15%">操作</th>
                </tr>
               <tr>
                   <td class="g-fleft">数据库备份</td>
                   <td class="g-fleft">将站点数据库全量容灾备份，在发生严重数据灾难时可以恢复到备份时的状态。</td>
                   <td>
                       <div class="ui-checkbox">
                           <% =HtmlHelper.CheckBox("autoBackDB", "开启", GlobalSetting.Get<bool>(GlobalSetting.Keys.Site.AutoBackDB, true)) %>
                       </div>                       
                   </td>
                   <td><% var last = WAP2P.Web.Task.BackupDB.GetLastBackupFile(); Response.Write(string.IsNullOrEmpty(last) ? "从未" : System.IO.File.GetLastWriteTime(last).ToDateTimeString()); %></td>
                   <td><input type="button" value="&#xe643; 立即备份" id="btnBackupDb" class="btn-base c-important iconfont" /></td>
               </tr>
            </table>
        </div>
    </dd>
</dl>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script>
        function setSetting(type, value) {
            $.ajax({
                url: "?action=" + type,
                dataType: "json",
                data: { value: value },
                success: function (res) {
                    if (res.Success)
                        $(document.body).tips('success', '设置成功');
                    else
                        $.jError(res.Message);
                }
            });
        };

        $('#autoBackDB').click(function () {
            var that = this;
            if (!that.checked) {
                $.jConfirm('为确保系统安全，我们强烈建议您开启自动备份！取消后不再自动备份，一定要取消吗？', function () {
                    setSetting('autoBackDB', 'false');
                }, function () {
                    that.checked = true;
                });
            } else
                setSetting('autoBackDB', 'true');
        });

        $('#btnBackupDb').click(function () {
            var me = $(this);
            $.ajax({
                url: "?action=backupdb",
                beforeSend: function () {
                    me.attr('disabled', 'disabled').val('备份中..');
                },
                dataType: "json",
                success: function (res) {
                    if (res.Success) {
                        $.jSuccess('备份成功。');
                        me.closest('td').prev().text(res.Message);
                    }
                    else
                        $.jError(res.Message);
                },
                complete: function () {
                    me.val('立即备份').removeAttr('disabled');
                }
            });
        });
    </script>
</asp:Content>