<?php
require_once 'db_connection.php';

header('Content-Type: application/json');

try {
    $loggedInUserId = $_GET['user_id'];

    $query = "SELECT id, username, level, class_id FROM emails_v WHERE id != ?";
    $stmt = $pdo->prepare($query);
    $stmt->execute([$loggedInUserId]);

    $users = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode(['success' => true, 'users' => $users]);
} catch (PDOException $e) {
    echo json_encode(['success' => false, 'message' => 'Error fetching users: ' . $e->getMessage()]);
}
