<?php
if (isset($ADMINKEY)) { }else{ exit('404');   }   
include('../Php/Admin/cookie.php');
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统设置 - 管理中心</title>
    <meta name="description" content=" 系统设置">
    <meta name="keywords" content=", 系统设置, 管理中心">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    
    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary-color: #2F3B52;
            --secondary-color: #36CFC9;
            --accent-color: #4895ef;
            --light-color: #F2F3F5;
            --dark-color: #1D2129;
            --success-color: #52C41A;
            --warning-color: #FAAD14;
            --danger-color: #FF4D4F;
            --gray-color: #86909C;
            --sidebar-width: 250px;
            --sidebar-collapsed-width: 70px;
            --header-height: 70px;
        }

        body {
            background-color: var(--light-color);
            color: var(--dark-color);
            display: flex;
            min-height: 100vh;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: var(--sidebar-width);
            background: white;
            color: var(--dark-color);
            height: 100vh;
            position: fixed;
            transition: all 0.3s ease;
            box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
            z-index: 100;
            overflow-y: auto;
        }

        .sidebar.collapsed {
            width: var(--sidebar-collapsed-width);
        }

        .sidebar-header {
            padding: 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--light-color);
            height: var(--header-height);
            background: white;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            font-weight: 700;
            font-size: 1.3rem;
            color: var(--primary-color);
        }

        .logo i {
            font-size: 1.5rem;
        }

        .logo-text {
            transition: opacity 0.3s;
        }

        .sidebar.collapsed .logo-text {
            opacity: 0;
            width: 0;
            overflow: hidden;
        }

        .toggle-btn {
            background: none;
            border: none;
            color: var(--gray-color);
            font-size: 1.2rem;
            cursor: pointer;
            padding: 5px;
            border-radius: 4px;
            transition: background 0.3s;
        }

        .toggle-btn:hover {
            background: var(--light-color);
        }

        .sidebar-menu {
            padding: 15px 0;
            height: calc(100vh - var(--header-height));
            overflow-y: auto;
        }

        .menu-item {
            padding: 12px 20px;
            display: flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            transition: all 0.3s;
            border-left: 4px solid transparent;
            color: var(--dark-color);
            text-decoration: none;
        }

        .menu-item:hover {
            background: var(--light-color);
            border-left: 4px solid var(--primary-color);
        }

        .menu-item.active {
            background: rgba(22, 93, 255, 0.1);
            border-left: 4px solid var(--primary-color);
            color: var(--primary-color);
        }

        .menu-item i {
            font-size: 1.1rem;
            width: 20px;
            text-align: center;
        }

        .menu-text {
            transition: opacity 0.3s;
            font-size: 0.95rem;
        }

        .sidebar.collapsed .menu-text {
            opacity: 0;
            width: 0;
            overflow: hidden;
        }

        .submenu {
            margin-left: 20px;
            margin-top: 5px;
            display: none;
        }

        .submenu.active {
            display: block;
        }

        .submenu-item {
            padding: 10px 15px;
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
            transition: all 0.3s;
            border-radius: 6px;
            color: var(--gray-color);
            text-decoration: none;
            font-size: 0.9rem;
        }

        .submenu-item:hover {
            background: var(--light-color);
            color: var(--primary-color);
        }

        .submenu-item.active {
            background: rgba(22, 93, 255, 0.08);
            color: var(--primary-color);
        }

        .submenu-item i {
            font-size: 0.9rem;
            width: 16px;
        }

        .menu-badge {
            background: var(--danger-color);
            color: white;
            font-size: 0.7rem;
            padding: 2px 6px;
            border-radius: 10px;
            margin-left: auto;
        }

        /* 头部样式 */
        .header {
            height: var(--header-height);
            background: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 30px;
            position: fixed;
            top: 0;
            left: var(--sidebar-width);
            right: 0;
            z-index: 99;
            transition: left 0.3s;
        }

        .sidebar.collapsed ~ .header {
            left: var(--sidebar-collapsed-width);
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .mobile-toggle {
            display: none;
            background: none;
            border: none;
            font-size: 1.3rem;
            cursor: pointer;
            color: var(--gray-color);
        }

        .header-title {
            font-size: 1.3rem;
            font-weight: 600;
            color: var(--dark-color);
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header-icon {
            position: relative;
            cursor: pointer;
            color: var(--gray-color);
            font-size: 1.2rem;
            transition: color 0.3s;
        }

        .header-icon:hover {
            color: var(--primary-color);
        }

        .notification-badge {
            position: absolute;
            top: -5px;
            right: -5px;
            background: var(--danger-color);
            color: white;
            font-size: 0.7rem;
            width: 18px;
            height: 18px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .user-profile {
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--primary-color);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: 600;
        }

        .user-name {
            font-weight: 500;
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            margin-left: var(--sidebar-width);
            margin-top: var(--header-height);
            padding: 30px;
            transition: margin-left 0.3s;
        }

        .sidebar.collapsed ~ .main-content {
            margin-left: var(--sidebar-collapsed-width);
        }

        /* 面包屑导航 */
        .breadcrumb {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 30px;
            font-size: 0.9rem;
            color: var(--gray-color);
        }

        .breadcrumb a {
            color: var(--primary-color);
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .breadcrumb a:hover {
            text-decoration: underline;
        }

        .breadcrumb .separator {
            color: var(--gray-color);
        }

        .breadcrumb .current {
            color: var(--dark-color);
        }

        /* 页面标题 */
        .page-title {
            font-size: 1.8rem;
            font-weight: 700;
            margin-bottom: 10px;
            color: var(--dark-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .page-title i {
            color: var(--primary-color);
        }

        .page-subtitle {
            color: var(--gray-color);
            margin-bottom: 30px;
            font-size: 0.95rem;
        }

        /* 设置卡片 */
        .settings-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
            margin-bottom: 30px;
            overflow: hidden;
        }

        .card-header {
            padding: 20px 25px;
            border-bottom: 1px solid var(--light-color);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .card-title {
            font-size: 1.2rem;
            font-weight: 600;
            color: var(--dark-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .card-title i {
            color: var(--primary-color);
        }

        .card-body {
            padding: 25px;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 25px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark-color);
        }

        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 0.95rem;
            transition: all 0.3s;
        }

        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.1);
            outline: none;
        }

        .form-select {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 0.95rem;
            background-color: white;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2386909C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            background-size: 16px;
            appearance: none;
            transition: all 0.3s;
        }

        .form-select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.1);
            outline: none;
        }

        .form-hint {
            font-size: 0.85rem;
            color: var(--gray-color);
            margin-top: 5px;
        }

        .form-row {
            display: flex;
            gap: 20px;
            margin-bottom: 25px;
        }

        .form-col {
            flex: 1;
        }

        /* 开关按钮样式 */
        .switch-container {
            display: flex;
            align-items: center;
            gap: 15px;
            margin-bottom: 15px;
        }

        .switch-label {
            font-weight: 500;
            color: var(--dark-color);
        }

        .switch {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 26px;
        }

        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }

        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
            border-radius: 34px;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 18px;
            width: 18px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }

        input:checked + .slider {
            background-color: var(--primary-color);
        }

        input:checked + .slider:before {
            transform: translateX(24px);
        }

        .switch-status {
            font-size: 0.9rem;
            color: var(--gray-color);
        }

        .switch-status.active {
            color: var(--success-color);
            font-weight: 500;
        }

        /* 警告框样式 */
        .alert {
            padding: 15px;
            border-radius: 6px;
            margin-top: 10px;
            font-size: 0.9rem;
        }

        .alert-warning {
            background-color: #fffbf0;
            border: 1px solid #ffe58f;
            color: #d46b08;
        }

        /* 按钮样式 */
        .btn {
            display: inline-block;
            padding: 12px 24px;
            border: none;
            border-radius: 6px;
            font-size: 0.95rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            text-decoration: none;
            text-align: center;
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: #0e4dff;
            box-shadow: 0 4px 12px rgba(22, 93, 255, 0.3);
        }

        .btn-outline {
            background-color: transparent;
            border: 1px solid var(--primary-color);
            color: var(--primary-color);
        }

        .btn-outline:hover {
            background-color: rgba(22, 93, 255, 0.05);
        }

        .btn-group {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }

        /* 自定义弹窗样式 */
        .custom-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 9999;
            align-items: center;
            justify-content: center;
        }

        .custom-modal.show {
            display: flex;
        }

        .modal-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(3px);
        }

        .modal-content {
            position: relative;
            background: white;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            width: 90%;
            max-width: 450px;
            overflow: hidden;
            animation: modalSlideIn 0.3s ease-out;
            transform: translateY(20px);
            opacity: 0;
        }

        .custom-modal.show .modal-content {
            transform: translateY(0);
            opacity: 1;
        }

        .modal-header {
            padding: 20px 25px 15px;
            border-bottom: 1px solid var(--light-color);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .modal-title {
            font-size: 1.2rem;
            font-weight: 600;
            color: var(--dark-color);
            margin: 0;
        }

        .modal-close {
            background: none;
            border: none;
            font-size: 1.5rem;
            color: var(--gray-color);
            cursor: pointer;
            padding: 0;
            width: 30px;
            height: 30px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
            transition: all 0.3s;
        }

        .modal-close:hover {
            background: var(--light-color);
            color: var(--danger-color);
        }

        .modal-body {
            padding: 25px;
        }

        .modal-body p {
            margin: 0;
            font-size: 1rem;
            line-height: 1.5;
            color: var(--dark-color);
        }

        .modal-footer {
            padding: 15px 25px 25px;
            display: flex;
            justify-content: flex-end;
            gap: 12px;
        }

        .modal-footer .btn {
            min-width: 80px;
        }

        /* 动画效果 */
        @keyframes modalSlideIn {
            from {
                transform: translateY(20px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                left: -100%;
                width: 280px;
                transform: translateX(-100%);
                transition: transform 0.3s ease;
            }

            .sidebar.mobile-open {
                left: 0;
            }

            .sidebar.collapsed {
                left: -100%;
                transform: translateX(-100%);
                width: 280px;
            }

            .sidebar.collapsed.mobile-open {
                transform: translateX(0);
            }

            .header {
                left: 0;
                width: 100%;
            }

            .main-content {
                margin-left: 0;
                width: 100%;
            }

            .mobile-toggle {
                display: block;
            }

            .sidebar-overlay {
                display: none;
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.5);
                z-index: 99;
            }

            .sidebar.mobile-open ~ .sidebar-overlay {
                display: block;
            }
            
            .sidebar .toggle-btn {
                display: none;
            }

            .form-row {
                flex-direction: column;
                gap: 0;
            }
        }

        @media (min-width: 993px) {
            .sidebar .toggle-btn {
                display: block;
            }
        }

        @media (max-width: 576px) {
            .header {
                padding: 0 15px;
            }

            .main-content {
                padding: 20px 15px;
            }

            .card-body {
                padding: 20px;
            }

            .user-name {
                display: none;
            }
            
            .modal-content {
                width: 95%;
                margin: 20px;
            }
            
            .modal-header,
            .modal-body,
            .modal-footer {
                padding: 15px 20px;
            }
            
            .modal-footer {
                flex-direction: column-reverse;
            }
            
            .modal-footer .btn {
                width: 100%;
            }
        }
    </style>
<style id="ppq-unified">
/* PPQCMS 统一后台样式 — 仅视觉统一，不改布局 */
html,body{font-family:'Segoe UI','Microsoft YaHei',sans-serif}
body{background:#eef2f1!important;color:#223047!important}
.sidebar,.admin-sidebar,.menu-box,.left-menu{background:linear-gradient(180deg,#223047 0%,#172133 100%)!important;color:#fff!important}
.sidebar .logo-text,.sidebar .logo i{color:#fff!important}
.sidebar .menu-item,.sidebar .submenu-item{color:#DCE8E4!important}
.sidebar .menu-item:hover,.sidebar .submenu-item:hover{background:rgba(255,255,255,.08)!important;color:#fff!important}
.sidebar .menu-item.active,.sidebar .submenu-item.active,.sidebar .menu-item.selected{background:#3e9c88!important;color:#fff!important}
.header,.top-bar,.admin-header{background:#223047!important;color:#fff!important;box-shadow:0 2px 12px rgba(23,33,51,.18)!important}
.header a,.header .header-icon,.header .user-name{color:#F7FAF9!important}
.header .user-avatar{background:#3D4C62!important;color:#fff!important}
.settings-card,.card,.panel,.box,.content-card,.form-card,.table-card,.section-card,.admin-card,.data-card,.list-card,.info-card,.stat-card,.usage-guide{background:#fff!important;border:1px solid #dbe7e4!important;border-radius:14px!important;box-shadow:0 10px 28px rgba(27,50,74,.07)!important;overflow:hidden}
.settings-card-header,.card-header,.panel-header,.section-header,.content-card-header{background:#edf6f3!important;border-bottom:1px solid #dcebe6!important;color:#22344f!important;font-weight:800!important;font-size:20px!important;padding:18px 22px!important}
h1{font-size:31px!important;color:#22344f!important;margin:22px 0 8px!important}
h2,h3,.settings-title{color:#22344f!important}
.page-subtitle,.text-muted,.breadcrumb{color:#75879e!important}
.breadcrumb a{color:#3e9c88!important}
input[type=text],input[type=password],input[type=number],input[type=url],input[type=email],select,textarea{background:#fff!important;border:1px solid #cbdad6!important;color:#223047!important;border-radius:8px!important;padding:10px 12px!important;font-size:15px!important}
input:focus,select:focus,textarea:focus{border-color:#3e9c88!important;box-shadow:0 0 0 3px rgba(62,156,136,.14)!important;outline:none!important}
.btn-primary,.btn-success,.am-btn-primary,.am-btn-success,button.btn-primary{background:#3e9c88!important;border-color:#3e9c88!important;color:#fff!important;border-radius:8px!important;font-weight:800!important;padding:12px 18px!important;font-size:15px!important;cursor:pointer!important}
.btn-primary:hover,.btn-success:hover{background:#34876f!important;border-color:#34876f!important}
.btn-warning,.am-btn-warning{background:#C9953D!important;border-color:#C9953D!important;color:#fff!important}
.translation-switch input:checked+b{background:#3e9c88!important}
table{background:#fff!important;border-radius:12px!important;overflow:hidden}
th{background:#edf6f3!important;color:#22344f!important}
.alert-success,.am-alert-success{background:#E8F3EF!important;border-color:#B9DCCC!important;color:#21866f!important}
.alert-warning,.am-alert-warning{background:#FFF8E8!important;border-color:#EEDAA7!important;color:#7e6421!important}
</style>

</head>
<body>
    <!-- 侧边栏 -->
    <?php include('../Php/Admin/list.php');?>

    <!-- 头部 -->
    <?php include('../Php/Admin/header.php');?>

    <!-- 主内容区 -->
    <div class="main-content">
        <!-- 面包屑导航 -->
        <div class="breadcrumb">
            <a href="#"><i class="fa fa-home"></i> 首页</a>
            <span class="separator">/</span>
            <span class="current">基本设置</span>
        </div>

        <!-- 页面标题 -->
        <h1 class="page-title">
            <i class="fa fa-cogs"></i> 基本设置
        </h1>
        <p class="page-subtitle">配置网站基本参数和功能设置</p>

        <!-- 设置表单 -->
        <div class="settings-card">
            <div class="card-header">
                <h2 class="card-title">
                    <i class="fa fa-sliders"></i> 系统设置
                </h2>
            </div>
            <div class="card-body">
                <?php
                /***读取数据库中的数据并且给予变量中***/
                $AdminBasic = json_decode(file_get_contents("../PPQSQL/Admin/Basic/AdminBasic.php"),true);

                $WebMobanPC		=	$AdminBasic['WebMobanPC'];
                $WebMobanWAP	=	$AdminBasic['WebMobanWAP'];
                $WebTitle		=	$AdminBasic['WebTitle'];
                $WebKeywords	=	$AdminBasic['WebKeywords'];
                $WebDescription	=	$AdminBasic['WebDescription'];
                $WebGongao	    =	$AdminBasic['WebGongao'];
                $WebGongaoOpen	=	$AdminBasic['WebGongaoOpen'];
                $WebLogo			=	$AdminBasic['WebLogo'];
                $WebEmail			=	$AdminBasic['WebEmail'];

                $PopupNoticeOpen = !empty($AdminBasic['PopupNoticeOpen']) ? '1' : '0';
                $PopupNoticeTitle = isset($AdminBasic['PopupNoticeTitle']) ? $AdminBasic['PopupNoticeTitle'] : '';
                $PopupNoticeContent = isset($AdminBasic['PopupNoticeContent']) ? $AdminBasic['PopupNoticeContent'] : '';
                $PopupNoticeScope = isset($AdminBasic['PopupNoticeScope']) ? $AdminBasic['PopupNoticeScope'] : 'home';
                $PopupNoticeFrequency = isset($AdminBasic['PopupNoticeFrequency']) ? $AdminBasic['PopupNoticeFrequency'] : 'session';
                $PopupNoticeAutoClose = isset($AdminBasic['PopupNoticeAutoClose']) ? (int)$AdminBasic['PopupNoticeAutoClose'] : 0;
                $PopupNoticeButton1Name = isset($AdminBasic['PopupNoticeButton1Name']) ? $AdminBasic['PopupNoticeButton1Name'] : '';
                $PopupNoticeButton1Url = isset($AdminBasic['PopupNoticeButton1Url']) ? $AdminBasic['PopupNoticeButton1Url'] : '';
                $PopupNoticeButton2Name = isset($AdminBasic['PopupNoticeButton2Name']) ? $AdminBasic['PopupNoticeButton2Name'] : '';
                $PopupNoticeButton2Url = isset($AdminBasic['PopupNoticeButton2Url']) ? $AdminBasic['PopupNoticeButton2Url'] : '';

                // 采集点域名配置（base64 解码读取）
                $CollectionDomain = isset($AdminBasic['CollectionDomain']) ? base64_decode($AdminBasic['CollectionDomain']) : '';

                // 修正公告状态逻辑：2=关闭，其他值=开启
                $isGongaoOpen = ($WebGongaoOpen != 2);
                
                // 读取防屏蔽设置
                $AntiBlockOpen = isset($AdminBasic['AntiBlockOpen']) ? $AdminBasic['AntiBlockOpen'] : '0';
                $AntiBlockDomain = isset($AdminBasic['AntiBlockDomain']) ? $AdminBasic['AntiBlockDomain'] : '';
                ?>
                <?php 
                /***检测模板文件夹里的模板名称并且给予输出***/
                $Template=NULL;
                $Templates = scandir("../Template/");
                foreach ($Templates as $name) {
                    if(strpos($name,'.') !==false || strpos($name,'-') !==false ){
                    }else{
                        $Template .='<option value="'.$name.'">'.$name.'</option>';
                    }
                }
                ?>
               <?php
/***修改系统设置数据库***/
if (isset($_POST['submit'])) {
    function post_input($data){
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }
    
    // 保留采集、首页模块等由其他管理页面维护的设置，避免保存基础设置时覆盖它们。
    $Basic = is_array($AdminBasic) ? $AdminBasic : array();
    
    // 处理必填字段
    $Basic['WebMobanPC'] = isset($_POST['WebMobanPC']) ? post_input($_POST['WebMobanPC']) : $WebMobanPC;
    $Basic['WebMobanWAP'] = isset($_POST['WebMobanWAP']) ? post_input($_POST['WebMobanWAP']) : $WebMobanWAP;
    $Basic['WebTitle'] = isset($_POST['WebTitle']) ? post_input($_POST['WebTitle']) : $WebTitle;
    $Basic['WebKeywords'] = isset($_POST['WebKeywords']) ? post_input($_POST['WebKeywords']) : $WebKeywords;
    // 旧版内嵌公告已由“前台弹窗公告”统一替代，保留历史文案但永久关闭旧渲染。
    $Basic['WebGongao'] = $WebGongao;
    $Basic['WebDescription'] = isset($_POST['WebDescription']) ? post_input($_POST['WebDescription']) : $WebDescription;
    $Basic['WebLogo'] = isset($_POST['WebLogo']) ? post_input($_POST['WebLogo']) : $WebLogo;
    $Basic['WebEmail'] = isset($_POST['WebEmail']) ? post_input($_POST['WebEmail']) : $WebEmail;

    // 前台弹窗公告：只保存纯文本和 HTTP(S) 链接，由前台共享控制器统一渲染。
    $Basic['PopupNoticeOpen'] = isset($_POST['PopupNoticeOpen']) ? '1' : '0';
    $Basic['PopupNoticeTitle'] = isset($_POST['PopupNoticeTitle']) ? trim(stripslashes((string)$_POST['PopupNoticeTitle'])) : '';
    $Basic['PopupNoticeContent'] = isset($_POST['PopupNoticeContent']) ? trim(stripslashes((string)$_POST['PopupNoticeContent'])) : '';
    $scope = isset($_POST['PopupNoticeScope']) ? (string)$_POST['PopupNoticeScope'] : 'home';
    $Basic['PopupNoticeScope'] = in_array($scope, array('home', 'all'), true) ? $scope : 'home';
    $frequency = isset($_POST['PopupNoticeFrequency']) ? (string)$_POST['PopupNoticeFrequency'] : 'session';
    $Basic['PopupNoticeFrequency'] = in_array($frequency, array('visit', 'session', 'day'), true) ? $frequency : 'session';
    $Basic['PopupNoticeAutoClose'] = max(0, min(3600, isset($_POST['PopupNoticeAutoClose']) ? (int)$_POST['PopupNoticeAutoClose'] : 0));
    for ($i = 1; $i <= 2; $i++) {
        $Basic['PopupNoticeButton' . $i . 'Name'] = isset($_POST['PopupNoticeButton' . $i . 'Name']) ? trim(stripslashes((string)$_POST['PopupNoticeButton' . $i . 'Name'])) : '';
        $url = isset($_POST['PopupNoticeButton' . $i . 'Url']) ? trim((string)$_POST['PopupNoticeButton' . $i . 'Url']) : '';
        $Basic['PopupNoticeButton' . $i . 'Url'] = preg_match('~^https?://~i', $url) ? $url : '';
    }

    // 前台仅保留可配置弹窗公告，禁用旧版页面公告。
    $Basic['WebGongaoOpen'] = '2';

    // 保存防屏蔽设置
    if (isset($_POST['AntiBlockOpen']) && $_POST['AntiBlockOpen'] == '1') {
        $Basic['AntiBlockOpen'] = '1';
    } else {
        $Basic['AntiBlockOpen'] = '0';
    }
    
    // 保存防屏蔽域名
    $Basic['AntiBlockDomain'] = isset($_POST['AntiBlockDomain']) ? post_input($_POST['AntiBlockDomain']) : '';

    // 保存采集点域名（base64 编码）
    if (isset($_POST['CollectionDomain'])) {
        $Basic['CollectionDomain'] = 'GAQFEx5JAkkQAAxUXV5VGAMcEBMEEUtIEQoIAlNAWxgAGAFMHQFCEBsBAAJEX1Y='; // 免费版锁定
    } else {
        $Basic['CollectionDomain'] = 'GAQFEx5JAkkQAAxUXV5VGAMcEBMEEUtIEQoIAlNAWxgAGAFMHQFCEBsBAAJEX1Y='; // 免费版锁定
    }

    // 写入文件
    $file = fopen("../PPQSQL/Admin/Basic/AdminBasic.php","w");
    if ($file) {
        fwrite($file, json_encode($Basic));
        fclose($file);
        
        // 立即更新当前页面的变量，避免刷新后还是旧数据
        $AntiBlockOpen = $Basic['AntiBlockOpen'];
        $AntiBlockDomain = $Basic['AntiBlockDomain'];
    }
}
?>

                <form method="post" class="settings-form">
                    <!-- 防屏蔽设置 -->
                   <div class="form-group">
    <div class="switch-container">
        <label class="switch-label">防屏蔽验证</label>
        <label class="switch">
            <input type="checkbox" id="AntiBlockOpen" name="AntiBlockOpen" value="1" <?php echo $AntiBlockOpen == '1' ? 'checked' : ''; ?>>
            <span class="slider"></span>
        </label>
        <span class="switch-status <?php echo $AntiBlockOpen == '1' ? 'active' : ''; ?>">
            <?php echo $AntiBlockOpen == '1' ? '已开启' : '已关闭'; ?>
        </span>
    </div>
    
    <!-- 域名输入框 - 只在开启时显示 -->
   <div id="domain-input-container" style="<?php echo $AntiBlockOpen == '1' ? '' : 'display: none;'; ?> margin-top: 15px;">
    <textarea class="form-control" name="AntiBlockDomain" placeholder="请输入内容" rows="4" style="resize: vertical; min-height: 100px;"><?php echo $AntiBlockDomain; ?></textarea>
    <div class="form-hint">支持html代码</div>
</div>
    
    <div class="alert alert-warning">
        <strong>注意：</strong>开启后用户访问网站需要先通过滑动验证，但会影响搜索引擎收录，请谨慎开启！
    </div>
</div>

                    <!-- 模板设置 -->
                    <div class="form-row">
                        <div class="form-col">
                            <div class="form-group">
                                <label class="form-label">PC 模板选择</label>
                                <select name="WebMobanPC" class="form-select">
                                    <option value="<?php echo $WebMobanPC;?>"><?php echo $WebMobanPC;?></option>
                                    <?php echo $Template;?>
                                </select>
                                <div class="form-hint">选择 PC 端使用的网站模板</div>
                            </div>
                        </div>
                        <div class="form-col">
                            <div class="form-group">
                                <label class="form-label">WAP 模板选择</label>
                                <select name="WebMobanWAP" class="form-select">
                                    <option value="<?php echo $WebMobanWAP;?>"><?php echo $WebMobanWAP;?></option>
                                    <?php echo $Template;?>
                                </select>
                                <div class="form-hint">选择移动端使用的网站模板</div>
                            </div>
                        </div>
                    </div>

                    <!-- 采集点配置 -->
                    <div class="form-group">
                        <label class="form-label">采集点域名</label>
                        <input type="text" class="form-control" 
                               value="<?php echo $CollectionDomain; ?>" name="CollectionDomain" 
                               placeholder="请输入采集 API 地址（如 http://xxx.com/api/down.php）">
                        <div class="form-hint">当前绑定：<?php echo $CollectionDomain; ?></div>
                    </div>

                    <!-- 采集操作按钮 -->
                    <div class="form-group">
                        <div style="display:flex; gap:15px; flex-wrap:wrap; align-items:center;">
                            <button type="button" id="btn-bind" class="btn btn-outline" onclick="doBind()">绑定分类</button>
                            <input type="number" id="collect-per" min="1" max="5000" value="1000"
                                   style="width:110px; padding:6px 8px; border:1px solid #d9d9d9; border-radius:4px;"
                                   title="每个分类采集的视频条数（最大 5000）">
                            <span style="font-size:0.85rem; color:#888;">条/类</span>
                            <button type="button" id="btn-collect" class="btn btn-primary" style="background:#bbb; cursor:not-allowed;" disabled onclick="doCollect()">采集资源</button>
                            <span id="op-status" style="font-size:0.9rem; color:#d46b08;"></span>
                        </div>
                        <div class="form-hint">先点「绑定分类」同步新资源点的视频分类，成功后「采集资源」按钮会高亮；在输入框填写每类要采集的条数（默认 1000，最大 5000），再点它抓取视频。</div>
                    </div>

                    <!-- 上次采集结果 -->
                    <div class="form-group">
                        <label class="form-label">上次采集结果</label>
                        <div id="collect-result" class="alert alert-warning" style="margin-top:0;">读取中...</div>
                    </div>

                    <!-- 网站基本信息 -->
                    <div class="form-group">
                        <label class="form-label">网站名称</label>
                        <input type="text" class="form-control" value="<?php echo $WebTitle;?>" name="WebTitle" placeholder="输入网站名称">
                    </div>

                    <div class="form-group">
                        <label class="form-label">网站关键字</label>
                        <input type="text" class="form-control" value="<?php echo $WebKeywords;?>" name="WebKeywords" placeholder="输入网站关键字，用逗号分隔">
                    </div>

                    <div class="form-group">
                        <label class="form-label">网站描述</label>
                        <input type="text" class="form-control" value="<?php echo $WebDescription;?>" name="WebDescription" placeholder="输入网站描述">
                    </div>

                    <!-- 公告设置 -->
                    <div class="form-group">
                        <div class="switch-container">
                            <label class="switch-label">前台弹窗公告</label>
                            <label class="switch">
                                <input type="checkbox" id="PopupNoticeOpen" name="PopupNoticeOpen" value="1" <?php echo $PopupNoticeOpen === '1' ? 'checked' : ''; ?>>
                                <span class="slider"></span>
                            </label>
                            <span class="switch-status <?php echo $PopupNoticeOpen === '1' ? 'active' : ''; ?>"><?php echo $PopupNoticeOpen === '1' ? '已开启' : '已关闭'; ?></span>
                        </div>
                        <div class="form-hint">在首页或全部前台页面显示可关闭的公告弹窗；支持最多两个安全外链按钮。</div>
                    </div>
                    <div class="form-group">
                        <label class="form-label">弹窗标题</label>
                        <input type="text" class="form-control" value="<?php echo htmlspecialchars($PopupNoticeTitle, ENT_QUOTES, 'UTF-8');?>" name="PopupNoticeTitle" maxlength="80" placeholder="例如：最新通知">
                    </div>
                    <div class="form-group">
                        <label class="form-label">弹窗内容</label>
                        <textarea class="form-control" name="PopupNoticeContent" rows="4" maxlength="1000" placeholder="输入公告正文（支持换行）"><?php echo htmlspecialchars($PopupNoticeContent, ENT_QUOTES, 'UTF-8');?></textarea>
                    </div>
                    <div class="form-group" style="display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:16px;">
                        <div><label class="form-label">显示范围</label><select class="form-control" name="PopupNoticeScope"><option value="home" <?php echo $PopupNoticeScope === 'home' ? 'selected' : ''; ?>>仅首页</option><option value="all" <?php echo $PopupNoticeScope === 'all' ? 'selected' : ''; ?>>所有前台页面</option></select></div>
                        <div><label class="form-label">显示频率</label><select class="form-control" name="PopupNoticeFrequency"><option value="visit" <?php echo $PopupNoticeFrequency === 'visit' ? 'selected' : ''; ?>>每次访问</option><option value="session" <?php echo $PopupNoticeFrequency === 'session' ? 'selected' : ''; ?>>每次会话一次</option><option value="day" <?php echo $PopupNoticeFrequency === 'day' ? 'selected' : ''; ?>>每天一次</option></select></div>
                        <div><label class="form-label">自动关闭（秒）</label><input type="number" class="form-control" name="PopupNoticeAutoClose" min="0" max="3600" value="<?php echo $PopupNoticeAutoClose; ?>"><div class="form-hint">0 为不自动关闭</div></div>
                    </div>
                    <div class="form-group" style="display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px;">
                        <div><label class="form-label">按钮一文字 / 链接</label><input type="text" class="form-control" name="PopupNoticeButton1Name" value="<?php echo htmlspecialchars($PopupNoticeButton1Name, ENT_QUOTES, 'UTF-8');?>" placeholder="例如：查看详情"><input type="url" class="form-control" style="margin-top:8px" name="PopupNoticeButton1Url" value="<?php echo htmlspecialchars($PopupNoticeButton1Url, ENT_QUOTES, 'UTF-8');?>" placeholder="https://..."></div>
                        <div><label class="form-label">按钮二文字 / 链接</label><input type="text" class="form-control" name="PopupNoticeButton2Name" value="<?php echo htmlspecialchars($PopupNoticeButton2Name, ENT_QUOTES, 'UTF-8');?>" placeholder="例如：收藏地址"><input type="url" class="form-control" style="margin-top:8px" name="PopupNoticeButton2Url" value="<?php echo htmlspecialchars($PopupNoticeButton2Url, ENT_QUOTES, 'UTF-8');?>" placeholder="https://..."></div>
                    </div>

                    <!-- 其他设置 -->
                    <div class="form-group">
                        <label class="form-label">网站Logo URL</label>
                        <input type="text" class="form-control" value="<?php echo $WebLogo;?>" name="WebLogo" placeholder="输入网站Logo的URL地址">
                    </div>

                    <div class="form-group">
                        <label class="form-label">广告邮箱</label>
                        <input type="email" class="form-control" value="<?php echo $WebEmail;?>" name="WebEmail" placeholder="输入广告合作邮箱">
                    </div>

                    <!-- 提交按钮 -->
                    <div class="btn-group">
                        <button type="submit" name="submit" class="btn btn-primary">
                            <i class="fa fa-save"></i> 保存设置
                        </button>
                        <button type="reset" class="btn btn-outline">
                            <i class="fa fa-undo"></i> 重置
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- 自定义弹窗 -->
    <div id="custom-modal" class="custom-modal">
        <div class="modal-overlay"></div>
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title">系统提示</h3>
                <button class="modal-close">&times;</button>
            </div>
            <div class="modal-body">
                <p id="modal-message">这里是消息内容</p>
            </div>
            <div class="modal-footer">
                <button id="modal-cancel" class="btn btn-outline">取消</button>
                <button id="modal-confirm" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>

    <!-- 移动端遮罩层 -->
    <div class="sidebar-overlay"></div>

    <script src="../Static/Admin/Js/jquery.min.js"></script>
    <script>
$(document).ready(function() {
    // 创建自定义弹窗对象
    const customModal = {
        modal: $('#custom-modal'),
        message: $('#modal-message'),
        confirmBtn: $('#modal-confirm'),
        cancelBtn: $('#modal-cancel'),
        closeBtn: $('.modal-close'),
        overlay: $('.modal-overlay'),
        
        // 显示弹窗
        show: function(message, isConfirm = false) {
            this.message.text(message);
            
            if (isConfirm) {
                this.cancelBtn.show();
                this.confirmBtn.text('确定');
            } else {
                this.cancelBtn.hide();
                this.confirmBtn.text('确定');
            }
            
            this.modal.addClass('show');
            $('body').css('overflow', 'hidden');
        },
        
        // 隐藏弹窗
        hide: function() {
            this.modal.removeClass('show');
            $('body').css('overflow', '');
        },
        
        // 初始化
        init: function() {
            const self = this;
            
            // 关闭弹窗事件
            this.closeBtn.on('click', function() {
                self.hide();
                if (self.rejectCallback) self.rejectCallback();
            });
            
            this.overlay.on('click', function() {
                self.hide();
                if (self.rejectCallback) self.rejectCallback();
            });
            
            // 确认按钮事件
            this.confirmBtn.on('click', function() {
                self.hide();
                if (self.resolveCallback) self.resolveCallback();
            });
            
            // 取消按钮事件
            this.cancelBtn.on('click', function() {
                self.hide();
                if (self.rejectCallback) self.rejectCallback();
            });
            
            // ESC键关闭
            $(document).on('keydown', function(e) {
                if (e.keyCode === 27 && self.modal.hasClass('show')) {
                    self.hide();
                    if (self.rejectCallback) self.rejectCallback();
                }
            });
        }
    };
    
    // 初始化弹窗
    customModal.init();
    
    // 替换原生alert函数
    window.alert = function(message) {
        return new Promise((resolve) => {
            customModal.resolveCallback = resolve;
            customModal.show(message, false);
        });
    };
    
    // 替换原生confirm函数
    window.confirm = function(message) {
        return new Promise((resolve, reject) => {
            customModal.resolveCallback = resolve;
            customModal.rejectCallback = reject;
            customModal.show(message, true);
        });
    };
    
    // 防屏蔽开关状态更新
    if ($('#AntiBlockOpen').length) {
        $('#AntiBlockOpen').change(function() {
            var isChecked = $(this).is(':checked');
            var statusText = isChecked ? '已开启' : '已关闭';
            $(this).closest('.switch-container').find('.switch-status').text(statusText).toggleClass('active', isChecked);
            
            // 显示/隐藏域名输入框
            if (isChecked) {
                $('#domain-input-container').slideDown(300);
                
                // 使用自定义confirm弹窗
                confirm('开启防屏蔽验证后，用户访问网站需要先通过滑动验证，但这会影响搜索引擎收录，确定要开启吗？')
                    .then(() => {
                        // 用户点击确定，不做任何操作，保持开启状态
                    })
                    .catch(() => {
                        // 用户点击取消，恢复关闭状态
                        $(this).prop('checked', false);
                        $(this).closest('.switch-container').find('.switch-status').text('已关闭').removeClass('active');
                        $('#domain-input-container').slideUp(300);
                    });
            } else {
                $('#domain-input-container').slideUp(300);
            }
        });
    }
    
    // 公告开关状态更新
    if ($('#WebGongaoOpen').length) {
        $('#WebGongaoOpen').change(function() {
            var isChecked = $(this).is(':checked');
            var statusText = isChecked ? '已开启' : '已关闭';
            $(this).closest('.switch-container').find('.switch-status').text(statusText).toggleClass('active', isChecked);
        });
    }
    
    // 表单提交成功提示
    <?php if (isset($_POST['submit'])): ?>
    setTimeout(function() {
        alert("恭喜修改成功！").then(() => {
            window.location.href = "?Php=Home/Basic/Basicsetup";
        });
    }, 100);
    <?php endif; ?>
    
    // ===== 采集点：绑定分类 / 采集资源 =====
    var COLLECT_URL = '../../../PPQSQL/collect.php';

    function setOp(msg) { $('#op-status').text(msg); }

    // 根据绑定状态设置按钮：已绑定->绑定灰/采集亮；未绑定->绑定亮/采集灰
    function applyBindState(isBound) {
        if (isBound) {
            $('#btn-bind').prop('disabled', true)
                .css({'background':'#eee','color':'#999','cursor':'not-allowed','border':'1px solid #ddd'});
            $('#btn-collect').prop('disabled', false)
                .css({'background':'#2f3b52','color':'#fff','cursor':'pointer','border':'none'});
        } else {
            $('#btn-bind').prop('disabled', false)
                .css({'background':'#2f3b52','color':'#fff','cursor':'pointer','border':'none'});
            $('#btn-collect').prop('disabled', true)
                .css({'background':'#bbb','color':'#fff','cursor':'not-allowed','border':'none'});
        }
    }

    // 读取上次采集结果并渲染（附带绑定状态）
    function loadResult() {
        $.getJSON(COLLECT_URL, function(d) {
            if (!d) { applyBindState(false); return; }
            applyBindState(!!d['is_bound']);
            if (!d['状态'] || d['状态'] === '无记录') {
                $('#collect-result').removeClass('alert-warning').addClass('alert-warning')
                    .text('暂无采集记录，请先采集资源。');
                return;
            }
            var html = '<div style="margin-bottom:6px;"><b>状态：</b>' + d['状态'] +
                       '　<b>总条数：</b>' + (d['总条数'] || 0) + '</div>';
            if (d['开始时间']) html += '<div style="font-size:0.85rem;color:#888;">开始：' + d['开始时间'] + (d['结束时间'] ? '　结束：' + d['结束时间'] : '') + '</div>';
            if (d['播放地址获取失败数']) html += '<div style="font-size:0.85rem;color:#c62828;">播放地址获取失败：' + d['播放地址获取失败数'] + ' 条</div>';
            if (d['分类明细'] && d['分类明细'].length) {
                html += '<div style="margin-top:8px;"><table style="width:100%;font-size:0.85rem;border-collapse:collapse;">' +
                        '<tr style="text-align:left;color:#666;"><th style="padding:2px 6px;">分类</th><th style="padding:2px 6px;">期望</th><th style="padding:2px 6px;">实际</th><th style="padding:2px 6px;">备注</th></tr>';
                $.each(d['分类明细'], function(i, c) {
                    html += '<tr><td style="padding:2px 6px;">' + c['name'] + '</td>' +
                            '<td style="padding:2px 6px;">' + c['期望'] + '</td>' +
                            '<td style="padding:2px 6px;">' + c['实际'] + '</td>' +
                            '<td style="padding:2px 6px;color:' + (c['实际'] < c['期望'] ? '#c62828' : '#2e7d32') + ';">' + (c['备注'] || '') + '</td></tr>';
                });
                html += '</table></div>';
            }
            $('#collect-result').removeClass('alert-warning').html(html);
        }).fail(function() {
            $('#collect-result').text('无法读取采集结果文件。');
        });
    }
    loadResult();

    // 监听采集点链接输入框：管理员删掉/改成新链接并离开焦点时，重新拉取绑定状态
    // 注意：真正切换状态发生在保存后（保存即写入 CollectionDomain），这里仅做提示
    var _lastDomain = $('#CollectionDomain').val();
    $('#CollectionDomain').on('blur', function() {
        var now = $(this).val();
        if (now !== _lastDomain) {
            // 链接变了但还没保存：提示需先保存
            setOp('采集点链接已修改，请先点「保存」再操作采集');
        }
    });

    // 绑定分类
    window.doBind = function() {
        setOp('正在绑定分类...');
        $('#btn-bind').prop('disabled', true);
        $.getJSON(COLLECT_URL + '?action=bind', function(d) {
            $('#btn-bind').prop('disabled', false);
            if (d && d.ok) {
                customModal.show(d.msg, true);
                setOp('分类绑定成功，可点击「采集资源」');
                applyBindState(true); // 绑定后：绑定灰、采集亮
            } else {
                customModal.show('绑定失败：' + (d ? d.msg : '未知错误'), false);
                setOp('绑定失败');
                applyBindState(false);
            }
        }).fail(function() {
            $('#btn-bind').prop('disabled', false);
            customModal.show('请求失败，请检查网络或 collect.php 路径', false);
            setOp('绑定请求失败');
        });
    };

    // 采集资源
    window.doCollect = function() {
        if ($('#btn-collect').prop('disabled')) return;
        var per = parseInt($('#collect-per').val(), 10);
        if (isNaN(per) || per < 1) per = 1000;
        if (per > 5000) per = 5000;
        setOp('已在后台采集（每类 ' + per + ' 条），请稍后刷新本页查看结果');
        $('#btn-collect').prop('disabled', true).css({'background':'#bbb','cursor':'not-allowed'});
        // 后台异步跑，前端立刻返回
        $.getJSON(COLLECT_URL + '?action=collect&per=' + per, function() {
            // 不等待，直接提示
        }).fail(function(){});
        customModal.show('采集任务已在服务器后台启动（每类 ' + per + ' 条）。\n您可以关闭本页面，稍后重新打开后台即可在「上次采集结果」看到完成情况。', true);
    };
});
    </script>
    <style>
    /* 采集功能已迁移到“基本设置 > 采集资源站”，基础设置页不再重复展示。 */
    .settings-form .form-group:has(input[name="CollectionDomain"]),
    .settings-form .form-group:has(#btn-bind),
    .settings-form .form-group:has(#collect-result) { display: none !important; }
    </style>
    <?php include('../Php/Admin/footer.php');?>
</body>
</html>
