Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3. Shared helpers in api/helpers.php (DB, auth, request/response, security). PDO prepared statements throughout. Same JSON response shapes as CFML.
35 lines
723 B
PHP
35 lines
723 B
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
global $userId;
|
|
|
|
// Also check request body for UserID
|
|
$userID = $userId;
|
|
if ($userID <= 0) {
|
|
$data = readJsonBody();
|
|
$userID = (int) ($data['UserID'] ?? 0);
|
|
}
|
|
|
|
if ($userID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_logged_in', 'MESSAGE' => 'User not authenticated']);
|
|
}
|
|
|
|
$rows = queryTimed(
|
|
"SELECT b.ID, b.Name FROM Businesses b WHERE b.UserID = ? ORDER BY b.Name",
|
|
[$userID]
|
|
);
|
|
|
|
$businesses = [];
|
|
foreach ($rows as $row) {
|
|
$businesses[] = [
|
|
'BusinessID' => (int) $row['ID'],
|
|
'Name' => $row['Name'],
|
|
];
|
|
}
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'BUSINESSES' => $businesses,
|
|
'COUNT' => count($businesses),
|
|
]);
|