<?php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../config/auth.php';
$user = requireAuth();
$db   = getDB();

$myOnly = post('my_only', 'NOT_SENT');
$roleId = $user['role_id'];

$rows = [];
try {
    $s = $db->prepare("SELECT action, allowed FROM role_permissions WHERE role_id=? AND module='jobcards'");
    $s->execute([$roleId]);
    $rows = $s->fetchAll();
} catch(Exception $e) { $rows = ['error' => $e->getMessage()]; }

apiSuccess([
    'user_id'    => $user['id'],
    'role_id'    => $roleId,
    'my_only_received' => $myOnly,
    'my_only_type'     => gettype($myOnly),
    'my_only_truthy'   => (bool)$myOnly,
    'db_permissions'   => $rows,
]);