<?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>友情链接管理 - YUTUCMS管理中心</title>
    <meta name="description" content="YUTUCMS 管理中心">
    <meta name="keywords" content="YUTUCMS, 管理后台">
    <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: #165DFF;
            --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);
        }

        /* 页面标题和面包屑 */
        .page-header {
            margin-bottom: 30px;
        }

        .breadcrumb {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 15px;
            font-size: 0.9rem;
            color: var(--gray-color);
        }

        .breadcrumb a {
            color: var(--primary-color);
            text-decoration: none;
        }

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

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

        .page-title {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--dark-color);
            margin-bottom: 10px;
        }

        .page-subtitle {
            color: var(--gray-color);
            font-size: 1rem;
        }

        /* 内容卡片 */
        .content-card {
            background: white;
            border-radius: 10px;
            padding: 25px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
            margin-bottom: 30px;
        }

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

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

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

        .card-actions {
            display: flex;
            gap: 10px;
        }

        /* 按钮样式 */
        .btn {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 10px 16px;
            border: none;
            border-radius: 6px;
            font-size: 0.9rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            text-decoration: none;
        }

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

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

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

        .btn-success:hover {
            background: #389e0d;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(82, 196, 26, 0.3);
        }

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

        .btn-warning:hover {
            background: #d48806;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(250, 173, 20, 0.3);
        }

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

        .btn-danger:hover {
            background: #d9363e;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(255, 77, 79, 0.3);
        }

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

        .btn-outline:hover {
            border-color: var(--primary-color);
            color: var(--primary-color);
            transform: translateY(-2px);
        }

        .btn-sm {
            padding: 6px 12px;
            font-size: 0.8rem;
        }

        /* 表格样式 */
        .table-container {
            overflow-x: auto;
        }

        .data-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }

        .data-table th {
            background: var(--light-color);
            padding: 12px 15px;
            text-align: left;
            font-weight: 600;
            color: var(--dark-color);
            border-bottom: 1px solid #e1e5e9;
        }

        .data-table td {
            padding: 12px 15px;
            border-bottom: 1px solid #e1e5e9;
            vertical-align: middle;
        }

        .data-table tr:hover {
            background: #f8f9fa;
        }

        .data-table input[type="text"] {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #d9d9d9;
            border-radius: 4px;
            font-size: 0.9rem;
            transition: border 0.3s;
        }

        .data-table input[type="text"]:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.1);
        }

        /* 状态标签 */
        .status-badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.8rem;
            font-weight: 500;
        }

        .status-success {
            background: rgba(82, 196, 26, 0.1);
            color: var(--success-color);
        }

        .status-warning {
            background: rgba(250, 173, 20, 0.1);
            color: var(--warning-color);
        }

        .status-danger {
            background: rgba(255, 77, 79, 0.1);
            color: var(--danger-color);
        }

        .status-info {
            background: rgba(22, 93, 255, 0.1);
            color: var(--primary-color);
        }

        /* 文件上传样式 */
        .file-upload {
            position: relative;
            display: inline-block;
        }

        .file-input {
            position: absolute;
            left: -9999px;
        }

        .file-path {
            margin-left: 10px;
            font-size: 0.9rem;
            color: var(--gray-color);
        }

        /* 响应式设计 */
        @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;
            }
        }

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

        @media (max-width: 768px) {
            .card-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }

            .card-actions {
                width: 100%;
                justify-content: flex-start;
            }

            .data-table {
                font-size: 0.8rem;
            }

            .data-table th,
            .data-table td {
                padding: 8px 10px;
            }
        }

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

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

            .content-card {
                padding: 15px;
            }

            .btn {
                padding: 8px 12px;
                font-size: 0.8rem;
            }
        }
    </style>
</head>
<body>
    <!-- 侧边栏 -->
    <?php include('../Php/Admin/list.php');?>

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

    <!-- 主内容区 -->
    <div class="main-content">
        <!-- 页面标题 -->
        <div class="page-header">
            <div class="breadcrumb">
                <a href="#"><i class="fa fa-home"></i> 首页</a>
                <span class="divider">/</span>
                <span>友情链接</span>
                <span class="divider">/</span>
                <span class="active">友情链接设置</span>
            </div>
            <h1 class="page-title">友情链接管理</h1>
            <p class="page-subtitle">管理网站友情链接，支持批量导入导出</p>
        </div>

        <!-- 操作工具栏 -->
        <div class="content-card">
            <div class="card-header">
                <h2 class="card-title">
                    <i class="fa fa-link"></i>
                    友情链接设置
                </h2>
                <div class="card-actions">
                    <a href="?Php=Home/Ad/IeUrlAdd" class="btn btn-primary">
                        <i class="fa fa-plus"></i>
                        新增友链
                    </a>
                    <a href="?Php=Home/Ad/IeUrl&export=1" class="btn btn-success">
                        <i class="fa fa-download"></i>
                        导出友链
                    </a>
                    <button type="button" onclick="$('#friendLink').click()" class="btn btn-warning">
                        <i class="fa fa-upload"></i>
                        导入友链
                    </button>
                </div>
            </div>

            <!-- 进度提示 -->
            <?php
            $CdName = NULL;
            if (isset($_GET['Php']) && isset($_GET['Cd'])) {
                function post_input($data){$data = stripslashes($data);$data = htmlspecialchars($data);return $data;}    
                $Php = post_input($_GET["Php"]);    
                $Cd = post_input($_GET["Cd"]);    
                if($Php =="Home/Ad/IeUrl" || $Cd !== NULL ){
                    $AdminIeUrlCd = json_decode(file_get_contents("../JCSQL/Admin/Ad/AdminIeUrl.php"),true);
                    array_multisort(array_column($AdminIeUrlCd,'IeUrlId'),SORT_DESC,$AdminIeUrlCd);

                    $Cdcount     = count($AdminIeUrlCd);
                    $Cdcounts    = $Cdcount-1;
                    include('../Php/Public/Mysql.php');
                    include('../Php/Public/Curl.php');
                    if($Cd < $Cdcounts || $Cd == $Cdcounts){
                        $IeUrl        =    $AdminIeUrlCd[$Cd];    
                        $IeUrlId    =    $IeUrl['IeUrlId'];
                        $IeUrlName    =    $IeUrl['IeUrlName'];
                        $IeUrlWebUrl    =    $IeUrl['IeUrlWebUrl'];
                        $IeUrlState    =    $IeUrl['IeUrlState'];
                        $TestIeUrlState    =    isset($IeUrl['TestIeUrlState'])?$IeUrl['TestIeUrlState']:'yes';

                        $IeUrlCurl = Fcurl($IeUrlWebUrl,false);

                        if(strpos($IeUrlCurl,$_SERVER['SERVER_NAME']) !== false){ 
                            $TestIeUrlState    =    'ok';
                        }else{
                            $TestIeUrlState    =    'no';
                        }
                        $AdminIeUrlMod['IeUrlId'] = $IeUrlId;
                        $AdminIeUrlMod['IeUrlName'] = $IeUrlName;
                        $AdminIeUrlMod['IeUrlWebUrl'] = $IeUrlWebUrl;
                        $AdminIeUrlMod['TestIeUrlState'] = $TestIeUrlState;
                        $AdminIeUrlMod['IeUrlState'] = $IeUrlState;

                        $UPDATE=UPDATE($AdminIeUrlCd,$Cd,$AdminIeUrlMod); 
                        $file = fopen("../JCSQL/Admin/Ad/AdminIeUrl.php","w");
                        fwrite($file,json_encode($UPDATE));
                        fclose($file);  

                        $CD=$Cd+1;
                        $CdName='进度：'.$Cdcount.'条，完成'.$CD.'条';

                        echo '<meta http-equiv="Refresh" content="3; url=?Php=Home/Ad/IeUrl&Cd='.$CD.'"/>';
                    }else{
                        $CdName='检测完毕';
                        echo '<meta http-equiv="Refresh" content="1; url=?Php=Home/Ad/IeUrl"/>';
                    }
                }
            }    
            ?>

            <?php if($CdName): ?>
            <div class="progress-notice" style="background: #e8f4fd; border: 1px solid #b8daff; border-radius: 6px; padding: 12px 15px; margin-bottom: 20px;">
                <i class="fa fa-info-circle" style="color: var(--primary-color);"></i>
                <span><?php echo $CdName; ?></span>
            </div>
            <?php endif; ?>

            <!-- 导入说明 -->
            <div style="background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 6px; padding: 12px 15px; margin-bottom: 20px;">
                <i class="fa fa-exclamation-triangle" style="color: #856404;"></i>
                <span style="color: #856404; font-size: 0.9rem;">
                    注：排序是按照数字大小来排序的数字越大排在越前，默认为空显示最后。导入仅支持txt文件格式，内容格式：友链排序|友链标题|友链地址URL
                </span>
            </div>

            <!-- 友情链接表单 -->
            <form method="post" enctype="multipart/form-data" class="am-form">
                <!-- 文件上传 -->
                <div class="file-upload" style="margin-bottom: 20px;">
                    <input type="file" name="friendLink" id="friendLink" class="file-input" onchange="$('#path').val(this.value);$('#sureFriend').show()" multiple="multiple" accept=".txt" />
                    <input name="path" id="path" class="file-path" readonly style="width: 200px;">
                    <button id="sureFriend" name="submit" type="submit" class="btn btn-success" style="display: none;">
                        <i class="fa fa-check"></i>
                        确认导入
                    </button>
                </div>

                <!-- 友情链接表格 -->
                <div class="table-container">
                    <table class="data-table">
                        <thead>
                            <tr>
                                <th style="width: 100px;">友链排序</th>
                                <th style="width: 200px;">友链标题</th>
                                <th>友链地址URL</th>
                                <th style="width: 150px;">状态</th>
                                <th style="width: 150px;">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $AdminIeUrl = json_decode(file_get_contents("../JCSQL/Admin/Ad/AdminIeUrl.php"),true);
                            array_multisort(array_column($AdminIeUrl,'IeUrlId'),SORT_DESC,$AdminIeUrl);
                            $count     = count($AdminIeUrl);
                            for ($x=0; $x<=$count-1; $x++) {
                                $IeUrl        =    $AdminIeUrl[$x];    
                                $IeUrlId    =    $IeUrl['IeUrlId'];
                                $IeUrlName    =    $IeUrl['IeUrlName'];
                                $IeUrlWebUrl    =    $IeUrl['IeUrlWebUrl'];
                                $TestIeUrlState    =    isset($IeUrl['TestIeUrlState'])?$IeUrl['TestIeUrlState']:'yes';
                                $IeUrlState    =    $IeUrl['IeUrlState'];

                                date_default_timezone_set("Asia/Shanghai");

                                if($TestIeUrlState =='no'){
                                    $IeUrlStateName='<span class="status-badge status-danger">检测异常</span>';
                                }
                                if($TestIeUrlState =='ok'){
                                    $IeUrlStateName='<span class="status-badge status-success">检测正常</span>';
                                }
                            ?>
                            <tr>
                                <td>
                                    <input type="text" name="IeUrlId[]" value="<?php echo $IeUrlId?>" style="width: 80px;">
                                </td>
                                <td>
                                    <input type="text" name="IeUrlName[]" value="<?php echo $IeUrlName?>" style="width: 180px;">
                                </td>
                                <td>
                                    <input type="text" name="IeUrlWebUrl[]" value="<?php echo $IeUrlWebUrl?>" style="width: 100%;">
                                </td>
                                <td>
                                    <input type="hidden" name="TestIeUrlState[]" value="<?php echo $TestIeUrlState;?>" />
                                    <input type="hidden" name="IeUrlState[]" value="<?php echo $IeUrlState;?>" />
                                    <?php echo $IeUrlStateName?>
                                    <?php if ($IeUrlState == 'ok'): ?>
                                        <span class="status-badge status-success" style="margin-top: 5px; display: block;">显示中</span>
                                    <?php else: ?>
                                        <span class="status-badge status-warning" style="margin-top: 5px; display: block;">已隐藏</span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div style="display: flex; gap: 5px; flex-wrap: wrap;">
                                        <?php if ($IeUrlState == 'ok'): ?>
                                            <a href="?Php=Home/Ad/IeUrl&SId=<?php echo $x?>&Show=no" class="btn btn-outline btn-sm">
                                                <i class="fa fa-eye-slash"></i>
                                                隐藏
                                            </a>
                                        <?php else: ?>
                                            <a href="?Php=Home/Ad/IeUrl&SId=<?php echo $x?>&Show=ok" class="btn btn-outline btn-sm">
                                                <i class="fa fa-eye"></i>
                                                显示
                                            </a>
                                        <?php endif; ?>
                                        <a href="?Php=Home/Ad/IeUrl&Id=<?php echo $x?>" class="btn btn-danger btn-sm" onclick="return confirm('确定要删除这个友情链接吗？')">
                                            <i class="fa fa-trash"></i>
                                            删除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </div>

                <!-- 提交按钮 -->
                <div style="margin-top: 20px; text-align: center;">
                    <button name="submit" type="submit" class="btn btn-primary" style="min-width: 120px;">
                        <i class="fa fa-save"></i>
                        保存修改
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- 隐藏的下载链接 -->
    <?php
    if (isset($_GET['Php']) && isset($_GET['export'])) {
        $AdminIeUrlCd = json_decode(file_get_contents("../JCSQL/Admin/Ad/AdminIeUrl.php"),true);
        array_multisort(array_column($AdminIeUrlCd,'IeUrlId'),SORT_DESC,$AdminIeUrlCd);

        if ($AdminIeUrlCd){
            $file = fopen("../JCSQL/Admin/Ad/friendLink.txt","w");
            foreach ($AdminIeUrlCd as $value){
                $urlTxt ='';
                $IeUrlId = isset($value['IeUrlId'])?$value['IeUrlId']:'';
                $IeUrlName = isset($value['IeUrlName'])?$value['IeUrlName']:'';
                $IeUrlWebUrl = isset($value['IeUrlWebUrl'])?$value['IeUrlWebUrl']:'';
                $urlTxt.=$IeUrlId.'|'.$IeUrlName.'|'.$IeUrlWebUrl.PHP_EOL;
                fwrite($file,$urlTxt);
            }
            fclose($file);
        }
    ?>
    <a id="downLoad" href="/JCSQL/Admin/Ad/friendLink.txt" download></a>
    <script>
        var link = document.getElementById('downLoad');
        if(link) link.click();
    </script>
    <?php } ?>

    <script src="../Static/Admin/Js/jquery.min.js"></script>
    <?php include('../Php/Admin/footer.php');?>
</body>
</html>

<?php
// 处理表单提交
if (isset($_POST['submit']) && isset($_POST['IeUrlId']) && isset($_POST['IeUrlName']) && isset($_POST['IeUrlWebUrl']) && isset($_POST['IeUrlState'])) {

    $IeUrlId    =    $_POST['IeUrlId'];
    $IeUrlName    =    $_POST['IeUrlName'];
    $IeUrlWebUrl=    $_POST['IeUrlWebUrl'];
    $IeUrlState    =    $_POST['IeUrlState'];
    $TestIeUrlState    =    $_POST['TestIeUrlState'];

    if ($IeUrlId == null) { echo'<script language="javascript">alert("友链排序不可为空"); </script>';exit();}
    if ($IeUrlName == null) { echo'<script language="javascript">alert("友链标题不可为空"); </script>';exit();}
    if ($IeUrlWebUrl == null) { echo'<script language="javascript">alert("友链链接不可为空"); </script>';exit();}
    if ($IeUrlState == null) { echo'<script language="javascript">alert("状态不能为空，非法操作！"); </script>';exit();}    
    include('../Php/Public/Mysql.php');
    $AdminIeUrlcount     = count($IeUrlName);
    $AdminIeUrlINSERT    = NULL;
    for ($x=0; $x<=$AdminIeUrlcount-1; $x++) {
        $AdminIeUrlMod['IeUrlId'] = $IeUrlId[$x];
        $AdminIeUrlMod['IeUrlName'] = $IeUrlName[$x];
        $AdminIeUrlMod['IeUrlWebUrl'] = $IeUrlWebUrl[$x];
        $AdminIeUrlMod['IeUrlState'] = $IeUrlState[$x];
        $AdminIeUrlMod['TestIeUrlState'] = $TestIeUrlState[$x];
        $AdminIeUrlINSERT = INSERT($AdminIeUrlINSERT,$AdminIeUrlMod);
    }
    $file = fopen("../JCSQL/Admin/Ad/AdminIeUrl.php","w");
    fwrite($file,json_encode($AdminIeUrlINSERT));
    fclose($file);

    // 导入友链
    if ($_FILES["friendLink"]["error"] <= 0) {
        $dataStr = file_get_contents($_FILES["friendLink"]["tmp_name"]);
        $res = array();
        if ($dataStr){
            $data = array_filter(explode(PHP_EOL,$dataStr));
            if ($data){
                foreach ($data as $k => $v){
                    $item = explode('|',$v);
                    if (is_array($item) && count($item)==3){
                        $itemArray['IeUrlId'] = $item[0];
                        $itemArray['IeUrlName'] = $item[1];
                        $itemArray['IeUrlWebUrl'] = $item[2];
                        $itemArray['IeUrlState'] = 'ok';
                        $itemArray['TestIeUrlState'] = 'ok';
                        $res[] = $itemArray;
                    }
                }
            }
        }

        $AdminIeUrl = json_decode(file_get_contents("../JCSQL/Admin/Ad/AdminIeUrl.php"),true);
        array_multisort(array_column($AdminIeUrl,'IeUrlId'),SORT_DESC,$AdminIeUrl);
        $AdminIeUrl = array_merge($AdminIeUrl,$res);

        $file = fopen("../JCSQL/Admin/Ad/AdminIeUrl.php","w");
        fwrite($file,json_encode($AdminIeUrl));
        fclose($file);
    }
?>
    <script language="javascript"> 
        alert("恭喜操作成功！");
        window.location.href = "?Php=Home/Ad/IeUrl";
    </script> 
<?php
}

// 处理删除操作
if (isset($_GET['Php']) && isset($_GET['Id'])) {
    function post_input($data){$data = stripslashes($data);$data = htmlspecialchars($data);return $data;}
    $Php = post_input($_GET["Php"]);
    $Id = post_input($_GET["Id"]);
    if($Php =="Home/Ad/IeUrl" || $Id !== NULL ){
        $AdminIeUrl = json_decode(file_get_contents("../JCSQL/Admin/Ad/AdminIeUrl.php"),true);
        array_multisort(array_column($AdminIeUrl,'IeUrlId'),SORT_DESC,$AdminIeUrl);

        include('../Php/Public/Mysql.php');
        $file = fopen("../JCSQL/Admin/Ad/AdminIeUrl.php","w");
        fwrite($file,json_encode(DELETE($AdminIeUrl,$Id)));
        fclose($file);
?>
    <script language="javascript">
        alert("恭喜删除成功！");
        window.location.href="?Php=Home/Ad/IeUrl";
    </script>
<?php
    }
}

// 处理显示/隐藏操作
if (isset($_GET['Php']) && isset($_GET['SId']) && isset($_GET['Show'])) {
    function post_input($data){$data = stripslashes($data);$data = htmlspecialchars($data);return $data;}
    $Php = post_input($_GET["Php"]);
    $Id = post_input($_GET["SId"]);
    $Show = post_input($_GET["Show"]);

    if($Php =="Home/Ad/IeUrl" || $Id !== NULL ){
        include('../Php/Public/Mysql.php');
        $AdminIeUrl = json_decode(file_get_contents("../JCSQL/Admin/Ad/AdminIeUrl.php"),true);
        array_multisort(array_column($AdminIeUrl,'IeUrlId'),SORT_DESC,$AdminIeUrl);

        $IeUrl        =    $AdminIeUrl[$Id];
        $AdminIeUrlMod['IeUrlId'] = $IeUrl['IeUrlId'];
        $AdminIeUrlMod['IeUrlName'] = $IeUrl['IeUrlName'];
        $AdminIeUrlMod['IeUrlWebUrl'] = $IeUrl['IeUrlWebUrl'];
        $AdminIeUrlMod['TestIeUrlState'] = $IeUrl['TestIeUrlState'];
        $AdminIeUrlMod['IeUrlState'] = $Show;
        $UPDATE = UPDATE($AdminIeUrl,$Id,$AdminIeUrlMod);
        $file = fopen("../JCSQL/Admin/Ad/AdminIeUrl.php","w");
        fwrite($file,json_encode($UPDATE));
        fclose($file);
?>
    <script language="javascript">
        alert("恭喜操作成功！");
        window.location.href="?Php=Home/Ad/IeUrl";
    </script>
<?php
    }
}
?>