2026-01-01 19:06:33 -05:00
|
|
|
<?php
|
|
|
|
|
session_start();
|
2026-01-01 19:18:57 -05:00
|
|
|
require_once dirname(__DIR__) . '/config/config.php';
|
2026-01-01 19:06:33 -05:00
|
|
|
require_once dirname(__DIR__) . '/models/UserModel.php';
|
|
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
|
|
// Check authentication
|
|
|
|
|
if (!isset($_SESSION['user']) || !isset($_SESSION['user']['user_id'])) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Not authenticated']);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create database connection
|
|
|
|
|
$conn = new mysqli(
|
|
|
|
|
$GLOBALS['config']['DB_HOST'],
|
|
|
|
|
$GLOBALS['config']['DB_USER'],
|
|
|
|
|
$GLOBALS['config']['DB_PASS'],
|
|
|
|
|
$GLOBALS['config']['DB_NAME']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($conn->connect_error) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Database connection failed']);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get all users
|
|
|
|
|
$userModel = new UserModel($conn);
|
|
|
|
|
$users = $userModel->getAllUsers();
|
|
|
|
|
|
|
|
|
|
$conn->close();
|
|
|
|
|
|
|
|
|
|
echo json_encode(['success' => true, 'users' => $users]);
|