<?php
session_start();
require '../auth/config.php'; // 引入数据库配置

if (!isset($_SESSION['user_id']) || !isset($_SESSION['username'])) {
    header("Location: ../auth/");
    exit();
}

$user_id = $_SESSION['user_id'];
function get_user_full_info($conn, $user_id) {
    $stmt = $conn->prepare("SELECT 
        username, 
        level, 
        points, 
        email, 
        register_time, 
        organization, 
        development_field, 
        skill_tags 
        FROM users 
        WHERE id = ?");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $result = $stmt->get_result();
    if ($row = $result->fetch_assoc()) {
        return $row;
    }
    return [
        'username' => '未授权人员',
        'level' => 1,
        'points' => 0,
        'email' => 'NULL',
        'register_time' => 'NULL',
        'organization' => 'NULL',
        'development_field' => 'NULL',
        'skill_tags' => 'NULL'
    ];
}

$user_info = get_user_full_info($conn, $user_id);
$username = $user_info['username'];
$level = $user_info['level'];
$email = $user_info['email'];
$levelDescriptions = [1 => '云境初探者', 2 => '云境行者', 3 => '云智大师', 4 => '云核守护者'];
$userLevelDescription = $levelDescriptions[$level] ?? '未知等级';

$conn->close();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户身份ID卡</title>
    <style>
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background-color: #f5f6fa;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }

        .id-card {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            width: 300px;
            padding: 15px;
            position: relative;
            border: 1px solid #e0e0e0;
            margin: 20px;
        }

        .card-header {
            background: linear-gradient(135deg, #4e27eb, #9c3cec);
            color: white;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 10px;
            text-align: center;
            font-weight: bold;
        }

        .card-photo {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            margin: 10px auto;
            overflow: hidden;
            background-position: center;
            background-size: cover;
        }

        .card-info {
            text-align: left;
            padding: 0 10px;
        }

        .card-info p {
            margin: 5px 0;
            display: flex;
            justify-content: space-between;
            border-bottom: 1px dashed #e0e0e0;
            padding-bottom: 5px;
        }

        .card-info-label {
            color: #666;
            font-weight: bold;
            width: 60px;
        }
    </style>
</head>
<body>
    <div class="id-card">
        <div class="card-header">用户ID卡</div>
        <div class="card-photo" style="background-image: url('https://i.bobopic.com/small/87673990.jpg');"></div>
        <div class="card-info">
            <p><span class="card-info-label">名称：</span><span class="card-info-value"><?php echo htmlspecialchars($username); ?></span></p>
            <p><span class="card-info-label">ID：</span><span class="card-info-value"><?php echo htmlspecialchars($user_id); ?></span></p>
            <p><span class="card-info-label">等级：</span><span class="card-info-value"><?php echo htmlspecialchars($userLevelDescription); ?></span></p>
            <p><span class="card-info-label">邮箱：</span><span class="card-info-value"><?php echo htmlspecialchars($email); ?></span></p>
        </div>
    </div>
</body>
</html>