<?php
session_start();
include('../../../includes/config.php');
if (!isset($_SESSION['user_id'])) {
    header('Location: ../../../index.php');
    exit;
}

// Fetch all users for recipient dropdown
$users = $conn->query("SELECT id, CONCAT(first_name, ' ', last_name) AS name FROM users WHERE id != {$_SESSION['user_id']}");
?>

<!DOCTYPE html>
<html>
<head>
    <title>Compose Message</title>
</head>
<body>
<h2>Compose Message</h2>
<form action="send_message.php" method="POST">
    <label>To:</label>
    <select name="receiver_id" required>
        <?php while ($row = $users->fetch_assoc()): ?>
            <option value="<?= $row['id'] ?>"><?= htmlspecialchars($row['name']) ?></option>
        <?php endwhile; ?>
    </select><br><br>
    
    <label>Subject:</label><br>
    <input type="text" name="subject" required><br><br>

    <label>Message:</label><br>
    <textarea name="message" rows="6" cols="50" required></textarea><br><br>

    <button type="submit">Send</button>
</form>
</body>
</html>
