42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if (isset($_GET['id'])) {
|
|
header('Content-Type: application/json');
|
|
try {
|
|
$person_id = $_GET['id'];
|
|
$pdo = db();
|
|
|
|
// Fetch person details
|
|
$stmt = $pdo->prepare("SELECT * FROM people WHERE id = ?");
|
|
$stmt->execute([$person_id]);
|
|
$person = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch all functions
|
|
$stmt = $pdo->query("
|
|
SELECT f.id, f.name, bg.name as group_name
|
|
FROM functions f
|
|
LEFT JOIN bni_groups bg ON f.bni_group_id = bg.id
|
|
ORDER BY bg.display_order, f.display_order
|
|
");
|
|
$all_functions = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch person's functions
|
|
$stmt = $pdo->prepare("SELECT function_id FROM user_functions WHERE user_id = ?");
|
|
$stmt->execute([$person_id]);
|
|
$person_functions = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
|
|
|
$response = [
|
|
'person' => $person,
|
|
'all_functions' => $all_functions,
|
|
'person_functions' => $person_functions
|
|
];
|
|
|
|
echo json_encode($response);
|
|
} catch (PDOException $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
}
|
|
exit;
|
|
}
|
|
?>
|