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()]); }