diff --git a/views/admin/horario/calendar.php b/views/admin/horario/calendar.php index a064a35..40feed0 100644 --- a/views/admin/horario/calendar.php +++ b/views/admin/horario/calendar.php @@ -56,7 +56,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && in_array($_POST['action'] ?? '', [' if ($id < 0 || !array_key_exists($dia, $dias)) $fail(422, 'Dados inválidos'); if (!preg_match($hhmm, $hi) || !preg_match($hhmm, $hf)) $fail(422, 'Horas inválidas'); if ($hf <= $hi) $fail(422, 'A hora de fim deve ser depois do início'); - if (mb_strlen($local) > 50) $fail(422, 'Sala inválida'); + if (!array_key_exists($local, $salas)) $fail(422, 'Sala inválida'); // enum membership if ($mod < 1 || !db_modalidades_get($pdo, $mod)) $fail(422, 'Modalidade inválida'); $payload = [ 'id_modalidade' => $mod, @@ -71,8 +71,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && in_array($_POST['action'] ?? '', [' break; } } catch (Throwable $e) { + // Surface the real cause: log it (same sink as the global handler) so a + // failed save on prod is diagnosable, and echo the detail back in dev. + if (function_exists('_error_log_write')) { + _error_log_write(get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); + } else { + error_log('[horario/calendar save] ' . $e->getMessage()); + } http_response_code(500); - echo json_encode(['ok' => false, 'error' => 'Erro ao guardar']); + $detail = (defined('APP_ENV') && APP_ENV === 'prod') ? 'Erro ao guardar' : $e->getMessage(); + echo json_encode(['ok' => false, 'error' => $detail]); } exit; }