- admin/quickTasks: list, create, save, delete - admin/scheduledTasks: list, save, delete, toggle, run, runDue - cron: expireStaleChats, expireTabs - receipt: public order receipt page (no auth, UUID-secured) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Returns scheduled task definitions for a business.
|
|
* GET/POST: { BusinessID }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$businessID = (int) ($data['BusinessID'] ?? headerValue('X-Business-ID') ?? $_GET['BusinessID'] ?? 0);
|
|
|
|
if ($businessID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'BusinessID is required']);
|
|
}
|
|
|
|
try {
|
|
$rows = queryTimed("
|
|
SELECT
|
|
st.ID,
|
|
st.Name,
|
|
st.TaskCategoryID AS CategoryID,
|
|
st.Title,
|
|
st.Details,
|
|
st.CronExpression,
|
|
COALESCE(st.ScheduleType, 'cron') AS ScheduleType,
|
|
st.IntervalMinutes,
|
|
st.IsActive,
|
|
st.LastRunOn,
|
|
st.NextRunOn,
|
|
st.CreatedOn,
|
|
tc.Name AS CategoryName,
|
|
tc.Color AS CategoryColor
|
|
FROM ScheduledTaskDefinitions st
|
|
LEFT JOIN TaskCategories tc ON st.TaskCategoryID = tc.ID
|
|
WHERE st.BusinessID = ?
|
|
ORDER BY st.IsActive DESC, st.Name
|
|
", [$businessID]);
|
|
|
|
$scheduledTasks = [];
|
|
foreach ($rows as $row) {
|
|
$scheduledTasks[] = [
|
|
'ScheduledTaskID' => (int) $row['ID'],
|
|
'Name' => $row['Name'],
|
|
'CategoryID' => $row['CategoryID'] ?? '',
|
|
'Title' => $row['Title'],
|
|
'Details' => $row['Details'] ?? '',
|
|
'CronExpression' => $row['CronExpression'],
|
|
'ScheduleType' => $row['ScheduleType'],
|
|
'IntervalMinutes' => $row['IntervalMinutes'] ?? '',
|
|
'IsActive' => (bool) $row['IsActive'],
|
|
'LastRunOn' => $row['LastRunOn'] ?? '',
|
|
'NextRunOn' => $row['NextRunOn'] ?? '',
|
|
'CreatedOn' => $row['CreatedOn'],
|
|
'CategoryName' => $row['CategoryName'] ?? '',
|
|
'CategoryColor' => $row['CategoryColor'] ?? '',
|
|
];
|
|
}
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'SCHEDULED_TASKS' => $scheduledTasks,
|
|
'COUNT' => count($scheduledTasks),
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]);
|
|
}
|