<?php
define('IN_ADMIN', true);
include("../includes/common.php");
$title='彩虹外链网盘管理中心';
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
<?php
$mysqlversion=$DB->getColumn("select VERSION()");
?>
<div id="popup-notice-modal"></div>
<div class="main-content">
<div id="browser-notice"></div>
<div class="stats-grid">
    <div class="stat-card">
        <div class="stat-card-header">
            <div class="stat-icon blue">
                <i class="fa fa-cloud"></i>
            </div>
            <div class="stat-info">
                <div class="stat-num" id="count1">0</div>
                <div class="stat-label">文件总数</div>
            </div>
        </div>
        <a href="file.php" class="stat-card-footer">
            <span>查看详情</span>
            <i class="fa fa-arrow-right"></i>
        </a>
    </div>
    <div class="stat-card">
        <div class="stat-card-header">
            <div class="stat-icon green">
                <i class="fa fa-cloud-upload"></i>
            </div>
            <div class="stat-info">
                <div class="stat-num" id="count2">0</div>
                <div class="stat-label">今日上传</div>
            </div>
        </div>
        <a href="file.php" class="stat-card-footer">
            <span>查看详情</span>
            <i class="fa fa-arrow-right"></i>
        </a>
    </div>
    <div class="stat-card">
        <div class="stat-card-header">
            <div class="stat-icon orange">
                <i class="fa fa-inbox"></i>
            </div>
            <div class="stat-info">
                <div class="stat-num" id="count3">0</div>
                <div class="stat-label">昨日上传</div>
            </div>
        </div>
        <a href="file.php" class="stat-card-footer">
            <span>查看详情</span>
            <i class="fa fa-arrow-right"></i>
        </a>
    </div>
    <div class="stat-card">
        <div class="stat-card-header">
            <div class="stat-icon red">
                <i class="fa fa-users"></i>
            </div>
            <div class="stat-info">
                <div class="stat-num" id="count4">0</div>
                <div class="stat-label">用户总数</div>
            </div>
        </div>
        <a href="user.php" class="stat-card-footer">
            <span>查看详情</span>
            <i class="fa fa-arrow-right"></i>
        </a>
    </div>
</div>
        <div class="dashboard-grid">
            <div class="dashboard-card notice-card">
                <div class="dashboard-card-header">
                    <div class="dashboard-card-icon info">
                        <i class="fa fa-bullhorn"></i>
                    </div>
                    <h3 class="dashboard-card-title">系统公告</h3>
                </div>
                <div class="dashboard-card-body" id="checkupdate">
                    <div class="notice-load">
                        <div class="notice-load-icon">
                            <i class="fa fa-spinner"></i>
                        </div>
                        <span class="notice-load-text">正在加载公告...</span>
                    </div>
                </div>
            </div>
            <div class="dashboard-card server-card">
                <div class="dashboard-card-header">
                    <div class="dashboard-card-icon primary">
                        <i class="fa fa-server"></i>
                    </div>
                    <h3 class="dashboard-card-title">服务器信息</h3>
                </div>
                <div class="dashboard-card-body">
                    <ul class="server-info-list">
                        <li class="server-info-item">
                            <span class="server-info-label">PHP 版本</span>
                            <span class="server-info-value"><?php echo phpversion() ?> <?php if(ini_get('safe_mode')) { echo '线程安全'; } else { echo '非线程安全'; } ?></span>
                        </li>
                        <li class="server-info-item">
                            <span class="server-info-label">MySQL 版本</span>
                            <span class="server-info-value"><?php echo $mysqlversion ?></span>
                        </li>
                        <li class="server-info-item">
                            <span class="server-info-label">WEB软件</span>
                            <span class="server-info-value"><?php echo $_SERVER['SERVER_SOFTWARE'] ?></span>
                        </li>
                        <li class="server-info-item">
                            <span class="server-info-label">服务器时间</span>
                            <span class="server-info-value"><?php echo $date ?></span>
                        </li>
                        <li class="server-info-item">
                            <span class="server-info-label">POST许可</span>
                            <span class="server-info-value"><?php echo ini_get('post_max_size'); ?></span>
                        </li>
                        <li class="server-info-item">
                            <span class="server-info-label">文件上传许可</span>
                            <span class="server-info-value"><?php echo ini_get('upload_max_filesize'); ?></span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
<script>
$(document).ready(function(){
    $.ajax({
        type : "GET",
        url : "ajax.php?act=getcount",
        dataType : 'json',
        async: true,
        success : function(data) {
            $('#count1').html(data.count1);
            $('#count2').html(data.count2);
            $('#count3').html(data.count3);
            $('#count4').html(data.count4);
        }
    });
    $.ajax({
        url: 'ajax.php?act=get_update_notice',
        type: 'get',
        dataType: 'json',
        success: function(data){
            if(data && data.code === 0 && data.msg){
                var content = '<div class="notice-list">' + data.msg + '</div>';
                $("#checkupdate").html(content);
            }else{
                $("#checkupdate").html('<div class="notice-none"><div class="notice-none-icon"><i class="fa fa-bell-slash"></i></div><span class="notice-none-text">暂无公告</span><span class="notice-none-hint">稍后再来看看吧</span></div>');
            }
        },
        error: function(){
            $("#checkupdate").html('<div class="notice-err"><div class="notice-err-icon"><i class="fa fa-exclamation-circle"></i></div><span class="notice-err-text">加载失败</span><span class="notice-err-hint">请检查网络连接后重试</span></div>');
        }
    });
    $.ajax({
        url: 'ajax.php?act=get_popup_notice',
        type: 'get',
        dataType: 'json',
        success: function(data){
            console.log('弹窗公告数据:', data);
            if(data && data.code === 0 && data.data){
                var popup = data.data;
                console.log('显示弹窗:', popup);
                var html = '<div class="popup-notice-modal-wrapper" id="popupNoticeModal">' +
                    '<div class="popup-notice-modal">' +
                    '<div class="popup-notice-header">' +
                    '<div class="popup-notice-icon"><i class="fa fa-bell"></i></div>' +
                    '<h4 class="popup-notice-title">' + (popup.title ? popup.title : '系统通知') + '</h4>' +
                    '<button type="button" class="popup-notice-close" id="popupNoticeX" aria-label="关闭"><i class="fa fa-times"></i></button>' +
                    '</div>' +
                    '<div class="popup-notice-body">' +
                    '<div class="popup-notice-content">' + (popup.content ? popup.content.replace(/\n/g, '<br>') : '') + '</div>' +
                    '</div>' +
                    '<div class="popup-notice-footer">' +
                    '<button type="button" class="popup-notice-btn-confirm" id="popupNoticeConfirm"><i class="fa fa-check"></i> 我知道了</button>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
                $("#popup-notice-modal").html(html);
                // 显示弹窗
                setTimeout(function() {
                    $("#popupNoticeModal").addClass('show');
                    console.log('弹窗已显示');
                }, 100);
                // 关闭弹窗函数
                function closePopup() {
                    $("#popupNoticeModal").removeClass('show');
                    setTimeout(function() {
                        $("#popup-notice-modal").html('');
                    }, 300);
                }
                // 绑定关闭事件
                $("#popupNoticeConfirm").click(closePopup);
                $("#popupNoticeX").click(closePopup);

            } else {
                console.log('没有弹窗公告或返回异常:', data);
            }
        },
        error: function(xhr, status, error){
            console.error('弹窗公告请求失败:', status, error);
        }
    });
});
</script>
<script>
function speedModeNotice(){
    var ua = window.navigator.userAgent;
    if(ua.indexOf('Windows NT')>-1 && ua.indexOf('Trident/')>-1){
        var html = "<div class=\"panel panel-default\"><div class=\"panel-body\">当前浏览器是兼容模式，为确保后台功能正常使用，请切换到<b style='color:#51b72f'>极速模式</b>！<br>操作方法：点击浏览器地址栏右侧的IE符号<b style='color:#51b72f;'><i class='fa fa-internet-explorer fa-fw'></i></b>→选择“<b style='color:#51b72f;'><i class='fa fa-flash fa-fw'></i></b><b style='color:#51b72f;'>极速模式</b>”</div></div>";
        $("#browser-notice").html(html)
    }
}
speedModeNotice();
</script>
