<?php 
include 'header.php'; // ใน header.php มี session_start() อยู่แล้ว
include 'connect.php'; 

// 1. ตรวจสอบสิทธิ์ Admin (ถ้าไม่ใช่ ให้เด้งกลับ)
if(!isset($_SESSION['username']) || $_SESSION['username'] !== 'admin'){
    echo "<script>alert('เฉพาะ Admin เท่านั้น'); window.location='index.php';</script>";
    exit();
}
?>

<div class="container">
    <h2 style="color: #4a148c; border-left: 5px solid #ffd54f; padding-left: 15px; margin: 30px 0;">เพิ่มข่าวสารและกิจกรรมใหม่</h2>
    
    <div style="background: white; padding: 30px; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);">
        <form action="send.php" method="POST" enctype="multipart/form-data">
            <div style="margin-bottom: 15px;">
                <label style="font-weight: bold; color: #444;">หัวข้อข่าว:</label>
                <input type="text" name="title" style="width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; margin-top: 5px;" required>
            </div>
            
            <div style="margin-bottom: 15px;">
                <label style="font-weight: bold; color: #444;">รายละเอียดข่าว:</label>
                <textarea name="detail" rows="5" style="width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; margin-top: 5px;" required></textarea>
            </div>

            <div style="margin-bottom: 25px; padding: 15px; background: #f9f9f9; border-radius: 8px; border: 1px dashed #8e24aa;">
                <label style="font-weight: bold; color: #4a148c;">📸 รูปภาพประกอบข่าว:</label>
                <input type="file" name="image" accept="image/*" style="width: 100%; margin-top: 10px;">
                <p style="font-size: 0.8rem; color: #666; margin-top: 5px;">* รองรับไฟล์นามสกุล .jpg, .jpeg, .png และ .gif</p>
            </div>

            <button type="submit" name="submit" style="padding: 12px 40px; background: #8e24aa; color: white; border: none; border-radius: 30px; cursor: pointer; font-weight: bold; font-size: 1rem; transition: 0.3s;">
                🚀 ลงประกาศข่าว
            </button>
            <a href="news.php" style="margin-left: 10px; text-decoration: none; color: #666;">ยกเลิก</a>
        </form>
    </div>
</div>

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