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.
65 lines
2.4 KiB
PHP
65 lines
2.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
try {
|
|
$data = readJsonBody();
|
|
$businessID = (int) ($data['BusinessID'] ?? 0);
|
|
$servicePointID = (int) ($data['ServicePointID'] ?? 0);
|
|
$userID = (int) ($data['UserID'] ?? 0);
|
|
|
|
if ($businessID === 0) apiAbort(['OK' => false, 'ERROR' => 'missing_BusinessID']);
|
|
|
|
if ($servicePointID > 0) {
|
|
$qPresence = queryTimed("
|
|
SELECT up.UserID, up.ServicePointID, up.LastSeenOn,
|
|
u.FirstName, u.LastName, u.ImageExtension,
|
|
sp.Name AS ServicePointName
|
|
FROM UserPresence up
|
|
JOIN Users u ON u.ID = up.UserID
|
|
LEFT JOIN ServicePoints sp ON sp.ID = up.ServicePointID
|
|
WHERE up.BusinessID = ? AND up.ServicePointID = ?
|
|
AND up.LastSeenOn >= DATE_SUB(NOW(), INTERVAL 30 MINUTE)
|
|
AND up.UserID != ?
|
|
ORDER BY up.LastSeenOn DESC
|
|
", [$businessID, $servicePointID, $userID]);
|
|
} else {
|
|
$qPresence = queryTimed("
|
|
SELECT up.UserID, up.ServicePointID, up.LastSeenOn,
|
|
u.FirstName, u.LastName, u.ImageExtension,
|
|
sp.Name AS ServicePointName
|
|
FROM UserPresence up
|
|
JOIN Users u ON u.ID = up.UserID
|
|
LEFT JOIN ServicePoints sp ON sp.ID = up.ServicePointID
|
|
WHERE up.BusinessID = ?
|
|
AND up.LastSeenOn >= DATE_SUB(NOW(), INTERVAL 30 MINUTE)
|
|
AND up.UserID != ?
|
|
ORDER BY up.LastSeenOn DESC
|
|
", [$businessID, $userID]);
|
|
}
|
|
|
|
$users = [];
|
|
foreach ($qPresence as $row) {
|
|
$qOnTab = queryOne("
|
|
SELECT t.ID AS TabID FROM TabMembers tm
|
|
JOIN Tabs t ON t.ID = tm.TabID
|
|
WHERE tm.UserID = ? AND tm.StatusID = 1 AND t.StatusID = 1 LIMIT 1
|
|
", [$row['UserID']]);
|
|
|
|
$users[] = [
|
|
'UserID' => (int) $row['UserID'],
|
|
'FirstName' => $row['FirstName'],
|
|
'LastName' => $row['LastName'],
|
|
'ImageExtension' => $row['ImageExtension'] ?? '',
|
|
'ServicePointID' => (int) ($row['ServicePointID'] ?? 0),
|
|
'ServicePointName' => $row['ServicePointName'] ?? '',
|
|
'LastSeenOn' => toISO8601($row['LastSeenOn']),
|
|
'IsOnTab' => $qOnTab !== null,
|
|
];
|
|
}
|
|
|
|
jsonResponse(['OK' => true, 'USERS' => $users]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]);
|
|
}
|