false, 'ERROR' => 'No request body provided']); } $businessId = (int) ($data['BusinessID'] ?? 0); if ($businessId <= 0) { apiAbort(['OK' => false, 'ERROR' => 'BusinessID is required']); } $hours = $data['Hours'] ?? []; if (!is_array($hours)) $hours = []; // Delete all existing hours queryTimed("DELETE FROM Hours WHERE BusinessID = ?", [$businessId]); // Insert new hours foreach ($hours as $h) { if (!is_array($h)) continue; $dayId = (int) ($h['dayId'] ?? 0); $open = $h['open'] ?? '09:00'; $close = $h['close'] ?? '17:00'; if ($dayId >= 1 && $dayId <= 7) { if (strlen($open) === 5) $open .= ':00'; if (strlen($close) === 5) $close .= ':00'; queryTimed(" INSERT INTO Hours (BusinessID, DayID, OpenTime, ClosingTime) VALUES (?, ?, ?, ?) ", [$businessId, $dayId, $open, $close]); } } jsonResponse(['OK' => true, 'hoursUpdated' => count($hours)]); } catch (Exception $e) { jsonResponse(['OK' => false, 'ERROR' => $e->getMessage()]); }