ÿþ<!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Teste Checklist - Debug</title> <style> body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; } .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; } .debug { background: #f0f0f0; padding: 15px; margin: 10px 0; border-radius: 5px; border-left: 4px solid #007bff; } .error { background: #ffebee; color: #c62828; border-left-color: #f44336; } .success { background: #e8f5e8; color: #2e7d32; border-left-color: #4caf50; } .warning { background: #fff3e0; color: #ef6c00; border-left-color: #ff9800; } .btn { padding: 10px 20px; margin: 5px; border: none; border-radius: 4px; cursor: pointer; } .btn-primary { background: #007bff; color: white; } .btn-success { background: #28a745; color: white; } .btn-warning { background: #ffc107; color: black; } .result { background: #f8f9fa; padding: 15px; border-radius: 5px; margin-top: 20px; } pre { background: #2d3748; color: #e2e8f0; padding: 15px; border-radius: 5px; overflow-x: auto; } </style> </head> <body> <div class="container"> <h1>=Ø'Ý Diagnóstico do Checklist - Viagem #<span id="viagemId">91</span></h1> <div class="debug"> <h3>=ØÍÜ Informações do Sistema</h3> <p><strong>URL atual:</strong> <span id="urlAtual"></span></p> <p><strong>Viagem ID:</strong> <span id="viagemIdDisplay"></span></p> <p><strong>Status:</strong> <span id="statusGeral">Carregando...</span></p> </div> <div> <button class="btn btn-primary" onclick="testarAPIs()">>ØêÝ Testar APIs</button> <button class="btn btn-success" onclick="buscarChecklist()" id="btnBuscar" disabled>=ØËÜ Buscar Checklist</button> <button class="btn btn-warning" onclick="limparLogs()">=ØÑÝþ Limpar Logs</button> </div> <div id="logs"></div> <div id="resultados" class="result" style="display: none;"> <h3>=ØÊÜ Resultados</h3> <div id="dadosResultado"></div> </div> </div> <script> // URLs para testar const API_URLS = [ '../api-checklist-v3.php', './api-checklist-v3.php', '/controlefrota/backend-php/api-checklist-v3.php', 'api-checklist-v3.php', '/backend-php/api-checklist-v3.php' ]; let API_FUNCIONANDO = null; let viagemId = new URLSearchParams(window.location.search).get('id') || '91'; // Inicializar document.addEventListener('DOMContentLoaded', function() { document.getElementById('viagemId').textContent = viagemId; document.getElementById('viagemIdDisplay').textContent = viagemId; document.getElementById('urlAtual').textContent = window.location.href; log('=Ø€Þ Sistema iniciado', 'success'); log(`<Ø¯ß Viagem ID: ${viagemId}`, 'info'); // Testar automaticamente setTimeout(testarAPIs, 1000); }); function log(mensagem, tipo = 'info') { const div = document.createElement('div'); div.className = `debug ${tipo}`; div.innerHTML = `<strong>${new Date().toLocaleTimeString()}</strong> - ${mensagem}`; document.getElementById('logs').appendChild(div); div.scrollIntoView({ behavior: 'smooth' }); } async function testarAPIs() { log('=ØÝ Iniciando teste das APIs...', 'info'); document.getElementById('statusGeral').textContent = 'Testando APIs...'; for (let i = 0; i < API_URLS.length; i++) { const url = API_URLS[i]; log(`=ØáÜ Testando ${i+1}/${API_URLS.length}: ${url}`, 'info'); try { const response = await fetch(`${url}?acao=checklist_veiculo&limit=1`); log(` Status: ${response.status}`, response.ok ? 'success' : 'warning'); if (response.ok) { const data = await response.json(); log(` Resposta: ${JSON.stringify(data).substring(0, 100)}...`, 'info'); if (data && data.success !== undefined) { log(`' API FUNCIONANDO: ${url}`, 'success'); API_FUNCIONANDO = url; document.getElementById('statusGeral').textContent = 'API encontrada!'; document.getElementById('btnBuscar').disabled = false; return; } } } catch (error) { log(` L' Erro: ${error.message}`, 'error'); } } log('L' NENHUMA API FUNCIONOU!', 'error'); document.getElementById('statusGeral').textContent = 'Erro: API não encontrada'; } async function buscarChecklist() { if (!API_FUNCIONANDO) { log('L' API não disponível. Execute o teste primeiro.', 'error'); return; } log(`<Ø¯ß Buscando checklist da viagem ${viagemId}...`, 'info'); try { const url = `${API_FUNCIONANDO}?acao=checklist_veiculo&viagem_id=${viagemId}`; log(`=ØáÜ URL: ${url}`, 'info'); const response = await fetch(url); const data = await response.json(); log(`=ØÊÜ Status: ${response.status}`, response.ok ? 'success' : 'error'); log(`=ØæÜ Dados recebidos:`, 'info'); document.getElementById('resultados').style.display = 'block'; document.getElementById('dadosResultado').innerHTML = `<pre>${JSON.stringify(data, null, 2)}</pre>`; if (data.success) { const checklists = data.data || []; log(`' Sucesso! Encontrados ${checklists.length} checklist(s)`, 'success'); if (checklists.length > 0) { log(`=ØËÜ Primeiro checklist: ${checklists[0].tipo_veiculo}, ${checklists[0].itens?.length || 0} itens`, 'info'); } else { log(`9!þ Esta viagem ainda não possui checklist`, 'warning'); } } else { log(`L' API retornou erro: ${data.message || 'Erro desconhecido'}`, 'error'); } } catch (error) { log(`=Ø¥Ü Erro na requisição: ${error.message}`, 'error'); } } function limparLogs() { document.getElementById('logs').innerHTML = ''; document.getElementById('resultados').style.display = 'none'; log('>ØùÝ Logs limpos', 'info'); } </script> </body> </html>