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.
77 lines
2 KiB
PHP
77 lines
2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
global $businessId;
|
|
|
|
$data = readJsonBody();
|
|
$bizId = $businessId;
|
|
if ($bizId <= 0) $bizId = (int) ($data['BusinessID'] ?? 0);
|
|
if ($bizId <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'no_business_selected']);
|
|
}
|
|
|
|
$onlyActive = true;
|
|
if (isset($data['onlyActive'])) {
|
|
$v = $data['onlyActive'];
|
|
if (is_bool($v)) $onlyActive = $v;
|
|
elseif (is_numeric($v)) $onlyActive = ((int) $v === 1);
|
|
elseif (is_string($v)) $onlyActive = (strtolower(trim($v)) === 'true');
|
|
}
|
|
|
|
$qBiz = queryOne("
|
|
SELECT b.ID, b.Name, b.BeaconShardID, b.BeaconMajor, bs.UUID AS ShardUUID
|
|
FROM Businesses b
|
|
LEFT JOIN BeaconShards bs ON bs.ID = b.BeaconShardID
|
|
WHERE b.ID = ?
|
|
LIMIT 1
|
|
", [$bizId]);
|
|
|
|
if (!$qBiz) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'business_not_found']);
|
|
}
|
|
|
|
$hasShard = ((int) ($qBiz['BeaconShardID'] ?? 0)) > 0;
|
|
$shardInfo = [
|
|
'ShardID' => $hasShard ? (int) $qBiz['BeaconShardID'] : 0,
|
|
'ShardUUID' => $hasShard ? $qBiz['ShardUUID'] : '',
|
|
'Major' => $hasShard ? (int) $qBiz['BeaconMajor'] : 0,
|
|
];
|
|
|
|
$sql = "
|
|
SELECT sp.ID AS ServicePointID, sp.Name, sp.BeaconMinor, sp.IsActive, sp.TypeID
|
|
FROM ServicePoints sp
|
|
WHERE sp.BusinessID = ? AND sp.BeaconMinor IS NOT NULL
|
|
";
|
|
$params = [$bizId];
|
|
if ($onlyActive) {
|
|
$sql .= " AND sp.IsActive = 1";
|
|
}
|
|
$sql .= " ORDER BY sp.BeaconMinor, sp.Name";
|
|
|
|
$rows = queryTimed($sql, $params);
|
|
|
|
$beacons = [];
|
|
foreach ($rows as $r) {
|
|
$beacons[] = [
|
|
'ServicePointID' => (int) $r['ServicePointID'],
|
|
'BusinessID' => $bizId,
|
|
'Name' => $r['Name'],
|
|
'UUID' => $shardInfo['ShardUUID'],
|
|
'Major' => $shardInfo['Major'],
|
|
'Minor' => (int) $r['BeaconMinor'],
|
|
'IsActive' => (bool) $r['IsActive'],
|
|
'TypeID' => (int) $r['TypeID'],
|
|
];
|
|
}
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'ERROR' => '',
|
|
'BusinessID' => $bizId,
|
|
'BusinessName' => $qBiz['Name'],
|
|
'COUNT' => count($beacons),
|
|
'BEACONS' => $beacons,
|
|
'HAS_SHARD' => $hasShard,
|
|
'SHARD_INFO' => $shardInfo,
|
|
]);
|