<?php
session_start();
include_once('../includes/config.php');

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

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

if (!isset($_GET['id'])) {
    echo json_encode(['success' => false, 'message' => 'Item ID is required']);
    exit();
}

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

$query = "SELECT * FROM tblitems WHERE ID = $itemId";
$result = mysqli_query($con, $query);

if ($result && mysqli_num_rows($result) > 0) {
    $item = mysqli_fetch_assoc($result);
    echo json_encode(['success' => true, 'data' => $item]);
} else {
    echo json_encode(['success' => false, 'message' => 'Item not found']);
}
?>
