<?php
define('SUPPRESS_ERRORS', true);
session_start();
header('Content-Type: application/json');

include_once('../includes/config.php');

if (!isset($_SESSION['uid'])) {
    echo json_encode(['success' => false, 'message' => 'Unauthorized access']);
    exit();
}

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    echo json_encode(['success' => false, 'message' => 'Invalid user ID']);
    exit();
}

$userId = (int)$_GET['id'];

$query = "SELECT ID, UserName, FullName, UserType, MobileNumber, Email, RegDate 
          FROM tblusers 
          WHERE ID = $userId";

$result = mysqli_query($con, $query);

if (!$result) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . mysqli_error($con)]);
    exit();
}

if (mysqli_num_rows($result) == 0) {
    echo json_encode(['success' => false, 'message' => 'User not found']);
    exit();
}

$user = mysqli_fetch_assoc($result);

echo json_encode([
    'success' => true,
    'user' => $user
]);
?>
