<?php
session_start();

if (!isset($_SESSION['member_id'])) {
    header("Location: login.php");
    exit;
}

require_once 'includes/config.php';

$id = $_SESSION['member_id'];

$stmt = $conn->prepare("SELECT * FROM members WHERE id=?");
$stmt->bind_param("i", $id);
$stmt->execute();

$result = $stmt->get_result();
$member = $result->fetch_assoc();

include 'includes/header.php';
?>

<div class="container mt-5">

    <h2 class="mb-4">
        👤 ข้อมูลสมาชิก
    </h2>
 <div class="text-center mb-4">

<?php
$photoPath = "uploads/profiles/" . $member['photo'];

if (!empty($member['photo']) && file_exists($photoPath)):
?>

    <img
        src="<?= $photoPath; ?>"
        class="rounded-circle shadow"
        style="width:200px;height:200px;object-fit:cover;">

<?php else: ?>

    <div
        class="rounded-circle bg-secondary text-white d-inline-flex
               justify-content-center align-items-center shadow"
        style="width:200px;height:200px;font-size:70px;">

        👤

    </div>

<?php endif; ?>

</div>   
 <div class="card shadow">

    <div class="card-body">

        <table class="table table-bordered">

            <tr>
                <th width="30%">รหัสนักศึกษา</th>
                <td><?= htmlspecialchars($member['student_id']); ?></td>
            </tr>

            <tr>
                <th>ชื่อ - นามสกุล</th>
                <td>
                    <?= htmlspecialchars($member['prefix']); ?>
                    <?= htmlspecialchars($member['first_name']); ?>
                    <?= htmlspecialchars($member['last_name']); ?>
                </td>
            </tr>

            <tr>
                <th>เพศ</th>
                <td><?= htmlspecialchars($member['gender']); ?></td>
            </tr>

            <tr>
                <th>คณะ</th>
                <td><?= htmlspecialchars($member['faculty']); ?></td>
            </tr>

            <tr>
                <th>สาขาวิชา</th>
                <td><?= htmlspecialchars($member['major']); ?></td>
            </tr>

            <tr>
                <th>ปีที่สำเร็จการศึกษา</th>
                <td><?= htmlspecialchars($member['graduation_year']); ?></td>
            </tr>

            <tr>
                <th>เบอร์โทรศัพท์</th>
                <td><?= htmlspecialchars($member['phone']); ?></td>
            </tr>

            <tr>
                <th>อีเมล</th>
                <td><?= htmlspecialchars($member['email']); ?></td>
            </tr>

            <tr>
                <th>ที่อยู่</th>
                <td><?= nl2br(htmlspecialchars($member['address'])); ?></td>
            </tr>

            <tr>
                <th>สถานที่ทำงาน</th>
                <td><?= htmlspecialchars($member['workplace']); ?></td>
            </tr>

            <tr>
                <th>ตำแหน่งงาน</th>
                <td><?= htmlspecialchars($member['position']); ?></td>
            </tr>

        </table>

        <div class="mt-4">

            <a href="edit_profile.php" class="btn btn-warning">
                ✏️ แก้ไขข้อมูล
            </a>

            <a href="change_password.php" class="btn btn-secondary">
                🔒 เปลี่ยนรหัสผ่าน
            </a>
            <a href="index.php" class="btn btn-primary">

🏠 หน้าแรก

</a>
        </div>

    </div>

</div>
</div>

<?php include 'includes/footer.php'; ?>   