<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-5-20
 */
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$message = '';
$error = '';

$backupDir = dirname(__DIR__) . '/backup/';
if (!is_dir($backupDir)) {
    @mkdir($backupDir, 0755, true);
}

$licenseInfo = $license->getStatus();
$currentLevel = isset($licenseInfo['level']) ? $licenseInfo['level'] : 1;
$canBackup = $currentLevel >= 2;

if ($action === 'backup') {
    $dbName = $db->getConfig()['database'];
    $filename = $dbName . '_' . date('Ymd_His') . '_' . strtoupper(substr(md5(uniqid()), 0, 6)) . '.sql';
    $filepath = $backupDir . $filename;

    $host = $db->getConfig()['host'];
    $port = $db->getConfig()['port'];
    $user = $db->getConfig()['username'];
    $pass = $db->getConfig()['password'];

    $cmd = sprintf(
        'mysqldump --host=%s --port=%s --user=%s --password=%s --databases %s --single-transaction --hex-blob 2>&1',
        escapeshellarg($host),
        escapeshellarg($port),
        escapeshellarg($user),
        escapeshellarg($pass),
        escapeshellarg($dbName)
    );

    $output = shell_exec($cmd);

    if ($output === null || strlen($output) < 100) {
        $tables = $db->fetchAll("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'");
        $sqlContent = "-- ECMS Database Backup\n-- Date: " . date('Y-m-d H:i:s') . "\n-- Database: {$dbName}\n\n";
        $sqlContent .= "SET NAMES utf8mb4;\nSET FOREIGN_KEY_CHECKS = 0;\n\n";
        foreach ($tables as $tblRow) {
            $tname = array_values((array)$tblRow)[0];
            $sqlContent .= "-- Table: {$tname}\n";
            $sqlContent .= "DROP TABLE IF EXISTS `{$tname}`;\n";
            $create = $db->fetch("SHOW CREATE TABLE `{$tname}`");
            $createSql = array_values((array)$create)[1];
            $sqlContent .= $createSql . ";\n\n";
            $rows = $db->fetchAll("SELECT * FROM `{$tname}`");
            foreach ($rows as $row) {
                $fields = array_keys($row);
                $values = array_map(function($v) {
                    if (is_null($v)) return 'NULL';
                    return "'" . str_replace(["\r","\n","\t"], ["\\r","\\n","\\t"], addslashes($v)) . "'";
                }, array_values($row));
                $sqlContent .= sprintf("INSERT INTO `%s` (`%s`) VALUES (%s);\n", $tname, implode('`,`', $fields), implode(',', $values));
            }
            $sqlContent .= "\n";
        }
        $sqlContent .= "SET FOREIGN_KEY_CHECKS = 1;\n";

        if (@file_put_contents($filepath, $sqlContent)) {
            $message = "备份成功：{$filename}";
            addLog('备份', '数据库', "备份数据库：{$dbName}");
        } else {
            $error = '备份文件写入失败，请检查 backup 目录权限';
        }
    } else {
        if (@file_put_contents($filepath, $output)) {
            $message = "备份成功：{$filename}";
            addLog('备份', '数据库', "备份数据库：{$dbName}");
        } else {
            $error = '备份文件写入失败';
        }
    }
    $action = 'list';
}

if ($action === 'restore') {
    if (!isset($_POST['backup_file']) || empty($_POST['backup_file'])) {
        $error = '请选择要恢复的备份文件';
    } else {
        $filename = basename($_POST['backup_file']);
        $filepath = $backupDir . $filename;
        if (!file_exists($filepath)) {
            $error = '备份文件不存在';
        } else {
            $sql = @file_get_contents($filepath);
            if ($sql) {
                $statements = array_filter(array_map('trim', explode(';', $sql)));
                foreach ($statements as $stmt) {
                    if (strlen($stmt) < 5) continue;
                    if (stripos($stmt, 'DROP TABLE') === false && stripos($stmt, 'CREATE TABLE') === false && stripos($stmt, 'INSERT INTO') === false) continue;
                    try { $db->query($stmt); } catch (Exception $e) {}
                }
                $message = "恢复成功：{$filename}";
                addLog('恢复', '数据库', "恢复数据库：{$filename}");
            } else {
                $error = '备份文件读取失败';
            }
        }
    }
    $action = 'list';
}

if ($action === 'delete_backup') {
    $f = basename(isset($_GET['file']) ? $_GET['file'] : '');
    $fp = $backupDir . $f;
    if ($f && file_exists($fp) && preg_match('/\.sql$/i', $f)) {
        @unlink($fp);
        $message = "已删除：{$f}";
        addLog('删除', '数据库', "删除备份文件：{$f}");
    }
    $action = 'list';
}

if ($action === 'save_auto_backup') {
    if (!$canBackup) {
        $error = '权限不足，自动备份需要基础版及以上版本';
    } else {
        $enabled = isset($_POST['enabled']) ? 1 : 0;
        $interval = trim(isset($_POST['interval']) ? $_POST['interval'] : 'daily');
        $maxCount = max(1, intval(isset($_POST['max_count']) ? $_POST['max_count'] : 10));
        $saveConfig = function($key, $val) use ($db) {
            $row = $db->fetch("SELECT id FROM {$db->table('config')} WHERE config_key = ?", [$key]);
            if ($row) {
                $db->update('config', ['config_value' => $val], 'config_key = ?', [$key]);
            } else {
                $db->insert('config', ['config_key' => $key, 'config_value' => $val, 'config_type' => 'text', 'config_group' => 'backup']);
            }
        };
        $saveConfig('auto_backup_enabled', $enabled);
        $saveConfig('auto_backup_interval', $interval);
        $saveConfig('auto_backup_max_count', $maxCount);
        $message = '自动备份设置已保存';
        addLog('设置', '数据库', '修改自动备份设置：' . ($enabled ? '启用' : '禁用') . " | 周期:{$interval} | 保留:{$maxCount}份");
    }
    $action = 'list';
}

if ($action === 'list') {
    $dbName = $db->getConfig()['database'];
    $tables = $db->fetchAll("SHOW TABLE STATUS FROM `{$dbName}`");
    $dbSize = $db->fetch("SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) as size FROM information_schema.tables WHERE table_schema = ?", [$dbName]);
    $dbSize = isset($dbSize['size']) ? $dbSize['size'] : 0;

    $backups = [];
    $dh = @opendir($backupDir);
    if ($dh) {
        while (($file = readdir($dh)) !== false) {
            if (preg_match('/\.sql$/i', $file) && is_file($backupDir . $file)) {
                $backups[] = ['name' => $file, 'size' => filesize($backupDir . $file), 'time' => filemtime($backupDir . $file)];
            }
        }
        closedir($dh);
    }
    usort($backups, function($a, $b) { return $b['time'] - $a['time']; });
    $totalBackupSize = array_sum(array_column($backups, 'size'));

    $autoEnabled = $db->fetch("SELECT config_value FROM {$db->table('config')} WHERE config_key = 'auto_backup_enabled'");
    $autoEnabled = isset($autoEnabled['config_value']) ? $autoEnabled['config_value'] : '0';
    $autoInterval = $db->fetch("SELECT config_value FROM {$db->table('config')} WHERE config_key = 'auto_backup_interval'");
    $autoInterval = isset($autoInterval['config_value']) ? $autoInterval['config_value'] : 'daily';
    $autoMaxCount = $db->fetch("SELECT config_value FROM {$db->table('config')} WHERE config_key = 'auto_backup_max_count'");
    $autoMaxCount = isset($autoMaxCount['config_value']) ? $autoMaxCount['config_value'] : '10';
    ?>
    <div class="page-container fade-in">
        <div class="page-header">
            <div class="page-title">
                <div class="page-icon"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg></div>
                <div>
                    <h1>数据库管理</h1>
                    <p style="font-size:12px;color:var(--gray-500);margin:0;">数据表管理与备份恢复</p>
                </div>
            </div>
        </div>

        <?php if ($error): ?>
        <div style="padding:14px 18px;background:#fef2f2;color:#dc2626;border:1px solid #fecaca;border-radius:8px;margin-bottom:20px;"><?php echo htmlspecialchars($error); ?></div>
        <?php endif; ?>
        <?php if ($message): ?>
        <div style="padding:14px 18px;background:#f0fdf4;color:#16a34a;border:1px solid #bbf7d0;border-radius:8px;margin-bottom:20px;"><?php echo htmlspecialchars($message); ?></div>
        <?php endif; ?>

        <div class="stats-grid" style="margin-bottom:20px;">
            <div class="stat-card">
                <div class="stat-icon" style="background:#eff6ff;color:#2563eb;"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg></div>
                <div class="stat-info"><div class="stat-value"><?php echo $dbSize; ?> MB</div><div class="stat-label">数据库大小</div></div>
            </div>
            <div class="stat-card">
                <div class="stat-icon" style="background:#ecfdf5;color:#16a34a;"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg></div>
                <div class="stat-info"><div class="stat-value"><?php echo count($tables); ?></div><div class="stat-label">数据表数量</div></div>
            </div>
            <div class="stat-card">
                <div class="stat-icon" style="background:#fdf4ff;color:#9333ea;"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="21 8 21 21 3 21 3 8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/></svg></div>
                <div class="stat-info"><div class="stat-value"><?php echo count($backups); ?></div><div class="stat-label">备份文件</div></div>
            </div>
            <div class="stat-card">
                <div class="stat-icon" style="background:#fffbeb;color:#d97706;"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="22" y1="12" x2="2" y2="12"/><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></svg></div>
                <div class="stat-info"><div class="stat-value"><?php echo round($totalBackupSize / 1024 / 1024, 2); ?> MB</div><div class="stat-label">备份总大小</div></div>
            </div>
        </div>

        <!-- 备份操作区 -->
        <div style="background:#fff;border:1px solid var(--border-light);border-radius:12px;padding:20px;margin-bottom:20px;">
            <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:16px;flex-wrap:wrap;gap:12px;">
                <div style="font-size:14px;font-weight:600;color:var(--gray-800);display:flex;align-items:center;gap:8px;">
                    <svg style="width:16px;height:16px;color:#2563eb;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg> 备份管理
                </div>
                <div style="display:flex;gap:10px;">
                    <a href="?act=database&action=backup" class="btn btn-primary" onclick="return confirm('确定执行完整备份？')"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg> 手动备份</a>
                    <?php if ($canBackup): ?>
                    <button class="btn btn-secondary" onclick="toggleAutoBackup()"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg> 自动备份</button>
                    <?php else: ?>
                    <button class="btn btn-secondary" disabled title="需要基础版或专业版授权"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> 自动备份（需授权）</button>
                    <?php endif; ?>
                </div>
            </div>

            <div id="autoBackupPanel" style="display:none;border-top:1px solid var(--border-light);padding-top:16px;margin-top:4px;">
                <form method="post" action="?act=database&action=save_auto_backup">
                    <div style="display:grid;grid-template-columns:1fr 1fr 1fr auto;gap:14px;align-items:end;flex-wrap:wrap;">
                        <div>
                            <label style="display:block;font-size:12px;color:var(--gray-500);margin-bottom:6px;">自动备份</label>
                            <label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
                                <input type="checkbox" name="enabled" value="1" id="autoEnabledCheck" <?php echo $autoEnabled == '1' ? 'checked' : ''; ?>>
                                <span id="autoStatusLabel" style="font-size:13px;color:<?php echo $autoEnabled == '1' ? 'var(--success)' : 'var(--gray-400)'; ?>;"><?php echo $autoEnabled == '1' ? '已启用' : '未启用'; ?></span>
                            </label>
                        </div>
                        <div>
                            <label style="display:block;font-size:12px;color:var(--gray-500);margin-bottom:6px;">备份周期</label>
                            <select name="interval" class="form-control" style="width:100%;">
                                <option value="hourly" <?php echo $autoInterval == 'hourly' ? 'selected' : ''; ?>>每小时</option>
                                <option value="daily" <?php echo $autoInterval == 'daily' ? 'selected' : ''; ?>>每天</option>
                                <option value="weekly" <?php echo $autoInterval == 'weekly' ? 'selected' : ''; ?>>每周</option>
                                <option value="monthly" <?php echo $autoInterval == 'monthly' ? 'selected' : ''; ?>>每月</option>
                            </select>
                        </div>
                        <div>
                            <label style="display:block;font-size:12px;color:var(--gray-500);margin-bottom:6px;">保留份数</label>
                            <select name="max_count" class="form-control" style="width:100%;">
                                <?php foreach ([5, 10, 20, 30] as $c): ?>
                                <option value="<?php echo $c; ?>" <?php echo $autoMaxCount == $c ? 'selected' : ''; ?>><?php echo $c; ?> 份</option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div>
                            <button type="submit" class="btn btn-success" style="white-space:nowrap;"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg> 保存设置</button>
                        </div>
                    </div>
                    <div style="margin-top:10px;font-size:11px;color:var(--gray-400);">说明：自动备份由系统定时任务触发，需确保服务器定时执行 CMS cron 接口方可生效。</div>
                </form>
            </div>
        </div>

        <!-- 备份文件列表 -->
        <?php if (!empty($backups)): ?>
        <div class="content-card" style="margin-bottom:20px;">
            <div style="padding:16px 20px;border-bottom:1px solid var(--border-light);">
                <div style="font-size:14px;font-weight:600;color:var(--gray-800);display:flex;align-items:center;gap:8px;">
                    <svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="21 8 21 21 3 21 3 8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/></svg> 备份记录
                </div>
            </div>
            <div style="padding:16px 20px;">
                <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:12px;">
                    <?php foreach ($backups as $bf): ?>
                    <div style="border:1px solid var(--border-light);border-radius:8px;padding:14px 16px;display:flex;flex-direction:column;gap:10px;transition:all 0.15s;" class="hover-lift">
                        <div style="display:flex;align-items:center;gap:10px;">
                            <div style="width:40px;height:40px;background:#fdf4ff;border-radius:8px;display:flex;align-items:center;justify-content:center;flex-shrink:0;">
                                <svg style="width:20px;height:20px;color:#9333ea;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
                            </div>
                            <div style="flex:1;min-width:0;">
                                <div style="font-size:13px;font-weight:500;color:var(--gray-800);word-break:break-all;" title="<?php echo htmlspecialchars($bf['name']); ?>"><?php echo htmlspecialchars($bf['name']); ?></div>
                                <div style="font-size:11px;color:var(--gray-500);margin-top:2px;">
                                    <?php echo round($bf['size'] / 1024, 1); ?> KB · <?php echo date('Y-m-d H:i', $bf['time']); ?>
                                </div>
                            </div>
                        </div>
                        <div style="display:flex;gap:8px;">
                            <form method="post" action="?act=database&action=restore" style="flex:1;" onsubmit="return confirm('确定恢复此备份？当前数据将被覆盖！');">
                                <input type="hidden" name="backup_file" value="<?php echo htmlspecialchars($bf['name']); ?>">
                                <button type="submit" class="btn btn-sm btn-secondary" style="width:100%;"><svg style="width:12px;height:12px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg> 恢复</button>
                            </form>
                            <a href="/backup/<?php echo rawurlencode($bf['name']); ?>" class="btn btn-sm btn-primary" download style="flex:1;text-align:center;"><svg style="width:12px;height:12px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg> 下载</a>
                            <a href="?act=database&action=delete_backup&file=<?php echo rawurlencode($bf['name']); ?>" class="btn btn-sm btn-danger" onclick="return confirm('确定删除此备份？')"><svg style="width:12px;height:12px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg> 删除</a>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php endif; ?>

        <!-- 数据表列表 -->
        <div class="content-card">
            <div style="padding:16px 20px;border-bottom:1px solid var(--border-light);">
                <div style="font-size:14px;font-weight:600;color:var(--gray-800);display:flex;align-items:center;gap:8px;">
                    <svg style="width:16px;height:16px;color:#2563eb;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2v-4M9 21H5a2 2 0 0 1-2-2v-4m0-6v6"/></svg> 数据表
                    <span style="font-weight:400;font-size:12px;color:var(--gray-500);margin-left:auto;"><?php echo count($tables); ?> 张表</span>
                </div>
            </div>
            <?php if (empty($tables)): ?>
            <div class="empty-state">
                <div class="empty-icon"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg></div>
                <h3>暂无数据表</h3>
                <p>数据库连接可能异常</p>
            </div>
            <?php else: ?>
            <div style="overflow-x:auto;">
            <table class="data-table" style="min-width:700px;">
                <thead>
                    <tr>
                        <th class="id-cell" style="width:50px;">#</th>
                        <th>数据表</th>
                        <th style="width:90px;text-align:right;">行数</th>
                        <th style="width:110px;text-align:right;">大小</th>
                        <th style="width:120px;text-align:center;">编码</th>
                        <th style="width:160px;text-align:center;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($tables as $i => $tbl): ?>
                    <tr style="transition:background 0.1s;">
                        <td class="id-cell"><?php echo $i + 1; ?></td>
                        <td><code style="background:#f1f5f9;padding:4px 10px;border-radius:5px;font-size:12px;color:#334155;font-family:monospace;"><?php echo htmlspecialchars($tbl['Name']); ?></code></td>
                        <td style="text-align:right;font-family:monospace;color:var(--gray-600);"><?php echo number_format(isset($tbl['Rows']) ? $tbl['Rows'] : 0); ?></td>
                        <td style="text-align:right;font-family:monospace;color:var(--gray-600);"><?php echo round((isset($tbl['Data_length']) ? $tbl['Data_length'] : 0) / 1024, 1); ?> KB</td>
                        <td style="text-align:center;font-size:11px;color:var(--gray-500);"><?php echo isset($tbl['Collation']) ? $tbl['Collation'] : '-'; ?></td>
                        <td>
                            <div class="btn-group" style="justify-content:center;">
                                <a href="?act=database&action=optimize&table=<?php echo urlencode($tbl['Name']); ?>" class="btn btn-sm btn-secondary" onclick="return confirm('优化表 <?php echo htmlspecialchars($tbl['Name']); ?>？')" title="优化"><svg style="width:12px;height:12px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> 优化</a>
                                <a href="?act=database&action=repair&table=<?php echo urlencode($tbl['Name']); ?>" class="btn btn-sm btn-secondary" onclick="return confirm('修复表 <?php echo htmlspecialchars($tbl['Name']); ?>？')" title="修复"><svg style="width:12px;height:12px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg> 修复</a>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            </div>
            <?php endif; ?>
        </div>
    </div>
    <?php
}
?>
<style>
.btn-group{display:flex;gap:6px;align-items:center;}
.btn-sm{padding:5px 10px;font-size:12px;}
</style>
<script>function toggleAutoBackup(){var p=document.getElementById('autoBackupPanel');p.style.display=p.style.display==='none'?'block':'none';}document.getElementById('autoEnabledCheck')&&document.getElementById('autoEnabledCheck').addEventListener('change',function(){var l=document.getElementById('autoStatusLabel');l.textContent=this.checked?'已启用':'未启用';l.style.color=this.checked?'var(--success)':'var(--gray-400)';});lucide.createIcons();</script>
