<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>管理配置</title>
    <link rel="stylesheet" type="text/css" href="assets/css/manage.css">
    <link href="https://gfonts.aby.pub" rel="preconnect" crossorigin />
    <link href="https://lf3-cdn-tos.bytecdntp.com" rel="preconnect" crossorigin />
    <link href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css" type="text/css" rel="stylesheet" />
    <link rel="icon" href="assets/html/favicon.ico" type="image/x-icon">
</head>
<body class="lxgw-wenkai-mono-tc-regular">
<script>
(function() {
    const savedTheme = localStorage.getItem('theme');
    if (savedTheme) {
        document.body.classList.add(savedTheme);
    } else {
        if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
            document.body.classList.add('dark');
        }
    }
})();
</script>
<div class="container">
    <div>
        <input type="checkbox" class="checkbox" id="themeSwitcher">
        <label for="themeSwitcher" class="checkbox-label">
            <i id="themeIcon"></i>
            <span class="label-text"></span>
            <span class="ball"></span>
        </label>
        <script>
            const theme = localStorage.getItem('theme');
            document.getElementById("themeIcon").className = `fas ${theme === 'dark' ? 'fa-moon' : theme === 'light' ? 'fa-sun' : 'fa-adjust'}`;
            document.querySelector('.label-text').textContent = (theme === 'dark' ? 'Dark' : theme === 'light' ? 'Light' : 'Auto');
        </script>
    </div>
    <h2>管理配置</h2>
    <form method="POST" id="settingsForm">
        <label for="xml_urls">【EPG地址】</label>
        <span class="blue-span" id="channelbind" onclick="showModal('channelbindepg')">（频道指定源）</span>
        <br><br>
        <textarea id="xml_urls" name="xml_urls" style="height: 122px;"><?php echo implode("\n", array_map('trim', $Config['xml_urls'])); ?></textarea>
        <br><br>

        <div class="form-row">
            <label for="days_to_keep" class="label-days-to-keep">数据保存天数</label>
            <label for="start_time" class="label-time custom-margin1">【定时任务】： 开始时间</label>
            <label for="end_time" class="label-time2 custom-margin2">结束时间</label>
            <label for="interval_time" class="label-time3 custom-margin3">间隔周期（选0小时0分钟取消）</label>
        </div>

        <div class="form-row">
            <select id="days_to_keep" name="days_to_keep" required>
                <?php for ($i = 1; $i <= 30; $i++): ?>
                    <option value="<?php echo $i; ?>" <?php echo $Config['days_to_keep'] == $i ? 'selected' : ''; ?>>
                        <?php echo $i; ?>
                    </option>
                <?php endfor; ?>
            </select>
            <input type="time" id="start_time" name="start_time" value="<?php echo $Config['start_time']; ?>" required>
            <input type="time" id="end_time" name="end_time" value="<?php echo $Config['end_time']; ?>" required>

            <!-- Interval Time Controls -->
            <select id="interval_hour" name="interval_hour" required>
                <?php for ($h = 0; $h < 24; $h++): ?>
                    <option value="<?php echo $h; ?>" <?php echo floor($Config['interval_time'] / 3600) == $h ? 'selected' : ''; ?>>
                        <?php echo $h; ?>
                    </option>
                <?php endfor; ?>
            </select> 小时
            <select id="interval_minute" name="interval_minute" required>
                <?php for ($m = 0; $m < 60; $m++): ?>
                    <option value="<?php echo $m; ?>" <?php echo (intval($Config['interval_time']) % 3600) / 60 == $m ? 'selected' : ''; ?>>
                        <?php echo $m; ?>
                    </option>
                <?php endfor; ?>
            </select> 分钟
        </div><br>

        <div class="flex-container">
            <div class="flex-item" style="width: 100%;">
                <label>【频道别名】</label>
                <span class="blue-span" id="channelInfi" onclick="showModal('channel')">（频道管理）</span>
                <span class="blue-span" id="iconInfo" onclick="showModal('icon')">（台标管理）</span>
                <span class="blue-span" id="liveInfo" onclick="showModal('live')">（直播源管理）</span>
                <br><br>
                <textarea id="channel_mappings" name="channel_mappings" style="height: 142px;"><?php 
                    echo implode("\n", array_map(function($search, $replace) {
                        return $search . ' => ' . $replace;
                    }, array_keys($Config['channel_mappings']), $Config['channel_mappings']));
                ?></textarea>
            </div>
        </div>
        <br>
        <input id="update_config" name="update_config" type="submit" value="保存配置">
        <br><br>
        <div class="button-container">
            <a href="update.php" target="_blank">更新数据</a>
            <button type="button" onclick="showModal('cron')">定时日志</button>
            <button type="button" onclick="showModal('update')">更新日志</button>
            <button type="button" onclick="showModal('moresetting')">更多设置</button>
            <button type="button" name="logoutbtn" onclick="logout()">退出</button>
        </div>
    </form>
</div>

<!-- 底部显示 -->
<footer class="footer">
    <a href="https://github.com/mxdabc/epgphp" target="_blank"><i class="fa-solid fa-server"></i>&nbsp;Crestekk Team EPG System for PHP.</a>
    <i class="fa-solid fa-grip-lines-vertical"></i>
    <a onclick="showVersionLog();">
        <span id="version"><i class="fa-regular fa-newspaper"></i>&nbsp;V3.0
        版本日志
    </a>
    <i class="fa-solid fa-grip-lines-vertical"></i>
    <a onclick="showHelpModal();"><i class="fa-solid fa-circle-question"></i>&nbsp;使用说明</a>
</footer>

<!-- 消息模态框 -->
<div id="messageModal" class="modal">
    <div class="modal-content message-modal-content">
        <span class="close" style="position: absolute; top: 0px; right: 10px;">&times;</span>
        <p id="messageModalMessage"></p>
    </div>
</div>

<!-- 版本日志模态框 -->
<div id="versionLogModal" class="modal">
    <div class="modal-content version-update-modal-content">
        <span class="close">&times;</span>
        <h2>版本日志</h2>
        <p id="versionLogMessage" style="height: 455px; overflow: auto;"></p>
    </div>
</div>

<!-- 使用说明模态框 -->
<div id="helpModal" class="modal">
    <div class="modal-content help-modal-content">
        <span class="close">&times;</span>
        <h2>使用说明</h2>
        <div style="height: 455px; overflow: auto; line-height: 1.7;">
            保存设置快捷键：Ctrl+S

            <h3 style="line-height: 0.5;">EPG地址</h3>
            支持 .xml 跟 .xml.gz 格式，地址前 # 临时停用，后 # 备注，快捷键：Ctrl+/<br>
            自定义 UA ： url #备注 #自定义UA（如：url #备注 #OKhttp/1.31）<br>
            只提取部分频道：频道名1, 频道名2 => 源地址<br>
            示例：tvmao, 频道id, [自定义:]频道id, ...<br>
            示例：cntv[:n], 频道id, [自定义:]频道id, ...<br>
            [] 表示可选（使用时不包含[]）， :n 表示未来 n 天数据，缺省为 1<br>
            频道指定 EPG 源：设置后，频道数据仅通过指定源更新<br>
            优先级：xml 源越靠前，优先级越高；tvmao 跟 cntv 强制覆盖已有数据

            <h3 style="line-height: 0.5;">频道别名</h3>
            格式：数据库频道名 => 频道别名1, 频道别名2, ...<br>
            支持正则表达式，如：$1 => regex:/^iHOT(.*)/i 将前缀 iHOT 去掉<br>
            建议使用「频道管理」页面修改
            
            <h3 style="line-height: 0.5;">台标管理</h3>
            默认列表：/assets/defaultList.json<br>
            台标列表：/data/iconList.json<br>
            优先读取 iconList.json<br>
            清理：删除服务器中未被使用的台标文件<br>
            全显：除了数据库频道列表外，同时显示无节目单的内置台标<br>
            转存：将远程台标转存到服务器上

            <h3 style="line-height: 0.5;">直播源管理</h3>
            支持 .txt 和 .m3u 格式，光标离开后自动保存<br>
            地址前 # 临时停用，后 # 备注并作为分组前缀，快捷键：Ctrl+/<br>
            示例：https://xxx.xx/xx.m3u #前缀1:<br>
            自定义 UA ： url #备注 #自定义UA（如：url #备注 #OKhttp/1.31）<br>
            在生成 m3u 文件时，「台标地址」、「tvg-id」、「tvg-name」字段可选<br>
            转换直播源：<?php echo $serverUrl . '/index.php?token=' . $Config['token']; ?>&live=txt/m3u&url=xxx<br>
            可添加 &latest=1 获取最新文件，不读取缓存<br>
            同步：更新数据时，同步更新直播源数据，默认关闭<br>
            改名：解析直播源数据时，使用数据库信息修正频道名，默认关闭<br>
            清理：删除未出现在列表中的直播源文件缓存、未出现在频道列表中的修改记录<br>
            停用：停用后不会出现在生成的直播源文件中，包括单个直播源<br>
            保持：直播地址不变时，重新解析保持修改不变<br>
            模板：生成直播源文件时仅包含模板数据，分组、频道名以模板为准<br>
            分组为「default」时，包含所有来源数据并使用原分组名称<br>
            模糊匹配：默认开启，选「否」进行精准匹配<br>
            线路备注：默认关闭，在直播地址后添加「$分组」<br>
            
            <h3 style="line-height: 0.5;">其他设置</h3>
            数据保存天数：清理超过设定天数的数据，包括节目单、定时日志、更新日志<br>
            生成 xml 文件：默认生成包含预告数据的 xml 跟 xml.gz 文件，可自行关闭<br>
            数据导入导出：包含 /data/ 文件夹的所有数据<br>
            返回此频道暂无预告或者您配置有误。：无数据时返回「此频道暂无预告或者您配置有误。」用于回放，默认关闭<br>
            Token 范围：点击后可修改 Token；可设置范围，默认「直播源」<br>
            User-Agent 范围：点击后可修改 UA，可用英文逗号分隔；可设置范围，默认「无」<br>
            全转简中：节目单、描述信息转简体中文，默认关闭<br>
            检查版本更新：进入设置界面后检测版本更新（仅提醒），默认打开<br>
            限定频道：可粘贴直播地址进行解析，生成 xml 时包含该部分信息<br>
            Memcached：已移除相关设置，默认打开，缓存在更新数据时清除
        </div>
    </div>
</div>

<!-- 频道 EPG 模态框 -->
<div id="epgModal" class="modal">
    <div class="modal-content epg-modal-content">
        <span class="close">&times;</span>
        <h2 id="epgTitle">频道名</h2>
        <span id="epgSource" style="word-break: break-all;">来源</span>
        <br><br>
        <span id="epgDate">日期</span>
        <span class="blue-span" id="prevDate" style="user-select: none; margin-left: 10px;">&#9664; 前一天</span>
        <span class="blue-span" id="nextDate" style="user-select: none; margin-left: 10px;">后一天 &#9654;</span>
        <br><br>
        <textarea id="epgContent" readonly style="width: 100%; height: 380px;"></textarea>
    </div>
</div>

<!-- 更新日志模态框 -->
<div id="updatelogModal" class="modal">
    <div class="modal-content update-log-modal-content">
        <span class="close">&times;</span>
        <h2>数据库更新日志</h2>
        <div class="table-container" id="log-table-container">
            <table id="logTable">
                <thead style="position: sticky; top: 0; background-color: white;">
                    <tr>
                        <th>时间</th>
                        <th>描述</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 数据由 JavaScript 动态生成 -->
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- 定时任务日志模态框 -->
<div id="cronlogModal" class="modal">
    <div class="modal-content cron-log-modal-content">
        <span class="close">&times;</span>
        <h2>定时任务日志</h2>
        <textarea id="cronLogContent" readonly style="width: 100%; height: 460px;"></textarea>
    </div>
</div>

<!-- 频道列表模态框 -->
<div id="channelModal" class="modal">
    <div class="modal-content channel-modal-content">
        <span class="close">&times;</span>
        <h2 id="channelModalTitle">频道列表</h2>
        <input type="text" id="channelSearchInput" placeholder="搜索频道名..." onkeyup="filterChannels('channel')">
        <div class="table-container" id="channel-table-container">
            <table id="channelTable">
                <thead style="position: sticky; top: 0; background-color: white;">
                    <tr>
                        <th>数据库频道名</th>
                        <th>频道别名</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 数据由 JavaScript 动态生成 -->
                </tbody>
            </table>
        </div>
        <br>
        <button id="saveConfig" type="button" onclick="updateChannelMapping();">保存配置</button>
    </div>
</div>

<!-- 台标列表模态框 -->
<div id="iconModal" class="modal">
    <div class="modal-content icon-modal-content">
        <span class="close">&times;</span>
        <h2 id="iconModalTitle">频道列表</h2>
        <div style="display: flex;">
            <input type="text" id="iconSearchInput" placeholder="搜索频道名..." onkeyup="filterChannels('icon')" style="flex: 1; margin-right: 10px;">
            <div style="width:auto; margin-right: 10px;">
                <button id="deleteUnusedIcons" type="button" onclick="deleteUnusedIcons()">清理</button>
            </div>
            <div style="width:auto; margin-right: 10px;">
                <button id="showAllIcons" type="button" onclick="showModal('allicon')">全显</button>
            </div>
            <div style="width:auto;">
                <button id="uploadAllIcons" type="button" onclick="uploadAllIcons();">转存</button>
            </div>
        </div>
        <div class="table-container" id="icon-table-container">
            <table id="iconTable">
                <thead style="position: sticky; top: 0; background-color: white;">
                    <tr>
                        <th>数据库频道名</th>
                        <th>台标地址</th>
                        <th>台标</th>
                        <th>上传</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 数据由 JavaScript 动态生成 -->
                </tbody>
            </table>
        </div>
        <br>
        <button id="saveConfig" type="button" onclick="updateIconListJsonFile(notify = true);">保存配置</button>
    </div>
</div>

<!-- 频道指定EPG模态框 -->
<div id="channelBindEPGModal" class="modal">
    <div class="modal-content channel-bind-epg-modal-content">
        <span class="close">&times;</span>
        <h2>频道指定EPG源<span style="font-size: 14px;">（无指定则按靠前的源更新）</span></h2>
        <div class="table-container" id="channel-bind-epg-table-container">
            <table id="channelBindEPGTable">
                <thead style="position: sticky; top: 0; background-color: white;">
                    <tr>
                        <th>指定EPG源</th>
                        <th>频道（可 , 分隔）</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 数据由 JavaScript 动态生成 -->
                </tbody>
            </table>
        </div>
        <br>
        <button id="saveConfig" type="button" onclick="updateConfig();">保存配置</button>
    </div>
</div>

<!-- 频道匹配结果模态框 -->
<div id="channelMatchModal" class="modal">
    <div class="modal-content channel-match-modal-content">
        <span class="close">&times;</span>
        <h2>频道匹配结果</h2>
        <div class="table-container" id="channel-match-table-container">
            <table id="channelMatchTable">
                <thead style="position: sticky; top: 0; background-color: white;">
                    <tr>
                        <th>原频道名</th>
                        <th>处理后频道名</th>
                        <th>匹配结果</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 数据由 JavaScript 动态生成 -->
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- 直播源管理模态框 -->
<div id="liveSourceManageModal" class="modal">
    <div class="modal-content live-source-modal-content">
        <span class="close">&times;</span>
        
        <!-- 输入框使用 textarea 用于输入直播源 URL -->
        <div class="input-container">
            <label for="sourceUrlTextarea">【直播源地址】</label><br>
            <textarea id="sourceUrlTextarea" style="height: 102px;"></textarea>
        </div>
        <br>
        
        <!-- 中间按钮区 -->
        <div class="button-container" style="width: 90%;">
            <input type="file" name="liveSourceFile" id="liveSourceFile" style="display: none;" accept=".m3u, .txt">
            <button id="uploadSourceBtn" onclick="document.getElementById('liveSourceFile').click()">上传源</button>
            <button id="parseSourceInfoBtn" onclick="parseSourceInfo()">解析源</button>
            <button id="showLiveUrlBtn" onclick="showLiveUrl(`<?php echo $Config['token']; ?>`, `<?php echo $serverUrl; ?>`, `<?php echo $Config['token_range']; ?>`)">访问地址</button>
            <button id="toggleLiveSourceSyncBtn" onclick="toggleStatus('toggleLiveSourceSyncBtn')">
                同步: <?php echo (isset($Config['live_source_auto_sync']) && $Config['live_source_auto_sync'] == 1 ? '是' : '否'); ?>
            </button>
            <button id="toggleLiveChannelNameProcessBtn" onclick="toggleStatus('toggleLiveChannelNameProcessBtn')">
                改名: <?php echo (isset($Config['live_channel_name_process']) && $Config['live_channel_name_process'] == 1 ? '是' : '否'); ?>
            </button>
            <button id="showLiveTemplateBtn" onclick="showLiveTemplate()">模板</button>
            <button id="cleanUnusedSourceBtn" onclick="cleanUnusedSource()">清理</button>
            <button id="saveSourceBtn" onclick="saveLiveSourceInfo()">保存</button>
        </div>
        <br>
        
        <!-- 表格显示解析结果 -->
        <div class="table-container" id="live-source-table-container">
            <table id="liveSourceTable">
                <thead class="sticky-header">
                    <tr>
                        <th style='width: 33px'>序号</th>
                        <th style='width: 10%'>分组</th>
                        <th style='width: 10%'>频道名</th>
                        <th>直播地址</th>
                        <th style='width: 20%'>台标地址<input type="checkbox" id="live_tvg_logo_enable" 
                            value="<?php echo isset($Config['live_tvg_logo_enable']) ? $Config['live_tvg_logo_enable'] : 1; ?>" 
                            <?php echo (!isset($Config['live_tvg_logo_enable']) || $Config['live_tvg_logo_enable'] == 1) ? 'checked' : ''; ?>
                            onchange="this.value = this.checked ? 1 : 0;">
                        </th>
                        <th style='width: 8%'>tvg-id<input type="checkbox" id="live_tvg_id_enable" 
                            value="<?php echo isset($Config['live_tvg_id_enable']) ? $Config['live_tvg_id_enable'] : 1; ?>" 
                            <?php echo (!isset($Config['live_tvg_id_enable']) || $Config['live_tvg_id_enable'] == 1) ? 'checked' : ''; ?>
                            onchange="this.value = this.checked ? 1 : 0;">
                        </th>
                        <th style='width: 12%'>tvg-name<input type="checkbox" id="live_tvg_name_enable" 
                            value="<?php echo isset($Config['live_tvg_name_enable']) ? $Config['live_tvg_name_enable'] : 1; ?>" 
                            <?php echo (!isset($Config['live_tvg_name_enable']) || $Config['live_tvg_name_enable'] == 1) ? 'checked' : ''; ?>
                            onchange="this.value = this.checked ? 1 : 0;">
                        </th>
                        <th style='width: 30px'>停用</th>
                        <th style='width: 30px'>保持</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 数据由 JavaScript 动态生成 -->
                </tbody>
            </table>
        </div>
        
        <!-- 分页控件 -->
        <div id="paginationContainer" style="margin-top: 15px; text-align: center;">
            <!-- 分页按钮由 JavaScript 动态生成 -->
        </div>
    </div>
</div>

<!-- 直播源模板模态框 -->
<div id="liveTemplateModal" class="modal">
    <div class="modal-content live-template-modal-content">
        <span class="close">&times;</span>
        <h2>直播源模板<span style="font-size: 14px;">（生成直播源文件时仅包含以下数据）</span></h2>
        <textarea id="liveTemplateTextarea" placeholder="#分组1&#10;频道1, 频道2&#10;频道3, 频道4&#10;&#10;#分组2&#10;&#10;#分组3, 来源1, 来源2&#10;&#10;#default, 来源3, 来源4&#10;&#10;..."
            style="width: 100%; height: 350px;"></textarea><br>
        <div class="row" style="margin-top: 15px; margin-bottom: 15px;">
            <div class="column">
                <label for="live_template_enable">启用模板：</label>
                <select id="live_template_enable" name="live_template_enable" required>
                    <option value="1" <?php if (!isset($Config['live_template_enable']) || $Config['live_template_enable'] == 1) echo 'selected'; ?>>是</option>
                    <option value="0" <?php if (isset($Config['live_template_enable']) && $Config['live_template_enable'] == 0) echo 'selected'; ?>>否</option>
                </select>
            </div>
            <div class="column">
                <label for="live_fuzzy_match">模糊匹配：</label>
                <select id="live_fuzzy_match" name="live_fuzzy_match" required>
                    <option value="1" <?php if (!isset($Config['live_fuzzy_match']) || $Config['live_fuzzy_match'] == 1) echo 'selected'; ?>>是</option>
                    <option value="0" <?php if (isset($Config['live_fuzzy_match']) && $Config['live_fuzzy_match'] == 0) echo 'selected'; ?>>否</option>
                </select>
            </div>
            <div class="column">
                <label for="live_url_comment">线路备注：</label>
                <select id="live_url_comment" name="live_url_comment" required>
                    <option value="0" <?php if (!isset($Config['live_url_comment']) || $Config['live_url_comment'] == 0) echo 'selected'; ?>>关闭</option>
                    <option value="1" <?php if (isset($Config['live_url_comment']) && $Config['live_url_comment'] == 1) echo 'selected'; ?>>TXT</option>
                    <option value="2" <?php if (isset($Config['live_url_comment']) && $Config['live_url_comment'] == 2) echo 'selected'; ?>>M3U</option>
                    <option value="3" <?php if (isset($Config['live_url_comment']) && $Config['live_url_comment'] == 3) echo 'selected'; ?>>全部</option>
                </select>
            </div>
            <div class="column">
            </div>
        </div>
        <button id="saveConfig" type="button" onclick="saveLiveTemplate();">保存配置</button>
    </div>
</div>

<!-- 更多设置模态框 -->
<div id="moreSettingModal" class="modal">
    <div class="modal-content more-setting-modal-content">
        <span class="close">&times;</span>
        <h2>更多设置</h2>

        <!-- 第一行 -->
        <div class="row">
            <div class="column">
                <label for="gen_xml">生成 xml 文件：</label>
                <select id="gen_xml" name="gen_xml" required>
                    <option value="1" <?php if ($Config['gen_xml'] == 1) echo 'selected'; ?>>是</option>
                    <option value="0" <?php if ($Config['gen_xml'] == 0) echo 'selected'; ?>>否</option>
                </select>
            </div>
            <div class="column">
                <label for="include_future_only">xml 内容：</label>
                <select id="include_future_only" name="include_future_only" required>
                    <option value="1" <?php if ($Config['include_future_only'] == 1) echo 'selected'; ?>>预告数据</option>
                    <option value="0" <?php if ($Config['include_future_only'] == 0) echo 'selected'; ?>>所有数据</option>
                </select>
            </div>
            <div class="column">
                <form id="importForm" method="post" enctype="multipart/form-data" style="display: inline-block;">
                    <input type="file" name="importFile" id="importFile" style="display: none;" accept=".gz">
                    <input type="hidden" name="importExport" id="formImportExport" value="">
                    <span class="blue-span" id="import" onclick="document.getElementById('importFile').click()" style="margin-right: 20px;">数据导入</span>
                    <span class="blue-span" id="export" onclick="document.getElementById('importForm').submit()">数据导出</span>
                </form>
            </div>
        </div>

        <!-- 第二行 -->
        <div class="row">
            <div class="column">
                <label for="ret_default">返回"无频道"字符串：</label>
                <select id="ret_default" name="ret_default" required>
                    <option value="1" <?php if (!isset($Config['ret_default']) || $Config['ret_default'] == 1) echo 'selected'; ?>>是</option>
                    <option value="0" <?php if (isset($Config['ret_default']) && $Config['ret_default'] == 0) echo 'selected'; ?>>否</option>
                </select>
            </div>
            <div class="column">
                <label for="token_range"><span class="blue-span" id="change_token_span" onclick="changeTokenUA('token', `<?php echo $Config['token']; ?>`)">Token</span> 范围：</label>
                <select id="token_range" name="token_range" required onchange="showTokenRangeMessage(`<?php echo $Config['token']; ?>`, `<?php echo $serverUrl; ?>`)">
                    <option value="0" <?php if (isset($Config['token_range']) && $Config['token_range'] == 0) echo 'selected'; ?>>无</option>
                    <option value="1" <?php if (!isset($Config['token_range']) || $Config['token_range'] == 1) echo 'selected'; ?>>直播源</option>
                    <option value="2" <?php if (isset($Config['token_range']) && $Config['token_range'] == 2) echo 'selected'; ?>>EPG</option>
                    <option value="3" <?php if (isset($Config['token_range']) && $Config['token_range'] == 3) echo 'selected'; ?>>全部</option>
                </select>
            </div>
            <div class="column">
                <label for="user_agent_range"><span class="blue-span" id="change_ua_span" onclick="changeTokenUA('user_agent', `<?php echo $Config['user_agent']; ?>`)">User-Agent</span> 范围：</label>
                <select id="user_agent_range" name="user_agent_range" required">
                    <option value="0" <?php if (!isset($Config['user_agent_range']) || $Config['user_agent_range'] == 0) echo 'selected'; ?>>无</option>
                    <option value="1" <?php if (isset($Config['user_agent_range']) && $Config['user_agent_range'] == 1) echo 'selected'; ?>>直播源</option>
                    <option value="2" <?php if (isset($Config['user_agent_range']) && $Config['user_agent_range'] == 2) echo 'selected'; ?>>EPG</option>
                    <option value="3" <?php if (isset($Config['user_agent_range']) && $Config['user_agent_range'] == 3) echo 'selected'; ?>>全部</option>
                </select>
            </div>
        </div>

        <!-- 第三行 -->
        <div class="row">
            <div class="column">
                <label for="all_chs" title="">全转简中：</label>
                <select id="all_chs" name="all_chs" required>
                    <option value="1" <?php if (isset($Config['all_chs']) && $Config['all_chs'] == 1) echo 'selected'; ?>>是</option>
                    <option value="0" <?php if (!isset($Config['all_chs']) || $Config['all_chs'] == 0) echo 'selected'; ?>>否</option>
                </select>
            </div>
            <div class="column">
                <label for="db_type">数据库：</label>
                <select id="db_type" name="db_type" required>
                    <option value="sqlite" <?php if (!isset($Config['db_type']) || $Config['db_type'] == 'sqlite') echo 'selected'; ?>>SQLite</option>
                    <option value="mysql" <?php if (isset($Config['db_type']) && $Config['db_type'] == 'mysql') echo 'selected'; ?>>MySQL</option>
                </select>
            </div>
            <div class="column">
                <label for="mysql_host">地址：</label>
                <textarea id="mysql_host"><?php echo htmlspecialchars($Config['mysql']['host'] ?? ''); ?></textarea>
            </div>
        </div>

        <!-- 第四行 -->
        <div class="row">
            <div class="column">
                <label for="mysql_dbname">库名：</label>
                <textarea id="mysql_dbname"><?php echo htmlspecialchars($Config['mysql']['dbname'] ?? ''); ?></textarea>
            </div>
            <div class="column">
                <label for="mysql_username">用户：</label>
                <textarea id="mysql_username"><?php echo htmlspecialchars($Config['mysql']['username'] ?? ''); ?></textarea>
            </div>
            <div class="column">
                <label for="mysql_password">密码：</label>
                <textarea id="mysql_password"><?php echo htmlspecialchars($Config['mysql']['password'] ?? ''); ?></textarea>
            </div>
        </div>

        <!-- 第五行 -->
        <div class="row">
            <div class="column">
                <label for="check_update">检查版本更新：</label>
                <select id="check_update" name="check_update" required>
                    <option value="1" <?php if (!isset($Config['check_update']) || $Config['check_update'] == 1) echo 'selected'; ?>>是</option>
                    <option value="0" <?php if (isset($Config['check_update']) && $Config['check_update'] == 0) echo 'selected'; ?>>否</option>
                </select>
            </div>
            <div class="column">
            </div>
            <div class="column">
            </div>
        </div>

        <!-- 其他设置 -->
        <label for="gen_list_text">仅生成以下频道数据：</label>
        <select id="gen_list_enable" name="gen_list_enable" style="width: 60px; margin-right: 0px;" required>
            <option value="1" <?php if (isset($Config['gen_list_enable']) && $Config['gen_list_enable'] == 1) echo 'selected'; ?>>是</option>
            <option value="0" <?php if (!isset($Config['gen_list_enable']) || $Config['gen_list_enable'] == 0) echo 'selected'; ?>>否</option>
        </select>
        <span>
            （粘贴m3u、txt地址或内容，<span class="blue-span" onclick="parseSource()">解析</span> 后
            <span class="blue-span" onclick="showModal('channelmatch')">查看匹配</span>）
        </span>
        <br>
        <textarea id="gen_list_text" style="margin-top: 12px; margin-bottom: 12px;"></textarea><br>

        <button id="saveConfig" type="button" onclick="setGenListAndUpdateConfig();">保存配置</button>
    </div>
</div>
<script src="assets/js/manage.js"></script>
<script src="static/js/mxd.js"></script>
</body>
</html>