false, 'ERROR' => 'missing_params', 'MESSAGE' => 'BusinessID is required']); } try { $rows = queryTimed(" SELECT qt.ID, qt.Name, qt.TaskCategoryID AS CategoryID, qt.Title, qt.Details, qt.Icon, qt.Color, qt.SortOrder, qt.IsActive, tc.Name AS CategoryName, tc.Color AS CategoryColor FROM QuickTaskTemplates qt LEFT JOIN TaskCategories tc ON qt.TaskCategoryID = tc.ID WHERE qt.BusinessID = ? AND qt.IsActive = 1 ORDER BY qt.SortOrder, qt.ID ", [$businessID]); $templates = []; foreach ($rows as $row) { $templates[] = [ 'QuickTaskTemplateID' => (int) $row['ID'], 'Name' => $row['Name'], 'CategoryID' => $row['CategoryID'] ?? '', 'Title' => $row['Title'], 'Details' => $row['Details'] ?? '', 'Icon' => $row['Icon'] ?? 'add_box', 'Color' => $row['Color'] ?? '#6366f1', 'SortOrder' => (int) $row['SortOrder'], 'IsActive' => (int) $row['IsActive'], 'CategoryName' => $row['CategoryName'] ?? '', 'CategoryColor' => $row['CategoryColor'] ?? '', ]; } jsonResponse([ 'OK' => true, 'TEMPLATES' => $templates, 'COUNT' => count($templates), ]); } catch (Exception $e) { jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]); }