Skip to content

Anylu27/ticket-system

Repository files navigation

false, 'message' => 'Método no permitido']); exit(); } // Obtener parámetros $evento_id = isset($_GET['id']) ? (int)$_GET['id'] : 0; $tipo_evento = isset($_GET['tipo']) ? trim($_GET['tipo']) : ''; // Validar parámetros if (!$evento_id || !$tipo_evento) { echo json_encode(['success' => false, 'message' => 'ID y tipo de evento son requeridos']); exit(); } if (!in_array($tipo_evento, ['correctivo', 'preventivo'])) { echo json_encode(['success' => false, 'message' => 'Tipo de evento inválido']); exit(); } try { // Consultar según el tipo de evento if ($tipo_evento === 'correctivo') { $stmt = $pdo->prepare(" SELECT c.*, cl.nombre as cliente_nombre, p.nombre as proyecto_nombre, cat.nombre as categoria_nombre, u.nombre as asignado_nombre, resp.nombre as responsable_nombre FROM correctivos c LEFT JOIN clientes cl ON c.cliente_id = cl.id LEFT JOIN proyectos p ON c.proyecto_id = p.id LEFT JOIN categorias cat ON c.categoria_id = cat.id LEFT JOIN usuarios u ON c.asignado_a = u.id LEFT JOIN usuarios resp ON c.responsable = resp.id WHERE c.id = ? "); } else { $stmt = $pdo->prepare(" SELECT p.*, cl.nombre as cliente_nombre, pr.nombre as proyecto_nombre, cat.nombre as categoria_nombre, u.nombre as asignado_nombre, resp.nombre as responsable_nombre FROM preventivos p LEFT JOIN clientes cl ON p.cliente_id = cl.id LEFT JOIN proyectos pr ON p.proyecto_id = pr.id LEFT JOIN categorias cat ON p.categoria_id = cat.id LEFT JOIN usuarios u ON p.asignado_a = u.id LEFT JOIN usuarios resp ON p.responsable = resp.id WHERE p.id = ? "); } $stmt->execute([$evento_id]); $evento = $stmt->fetch(PDO::FETCH_ASSOC); if (!$evento) { echo json_encode(['success' => false, 'message' => 'Evento no encontrado']); exit(); } // Generar HTML para mostrar los detalles $html = generarHtmlEvento($evento, $tipo_evento); echo json_encode([ 'success' => true, 'titulo' => $evento['titulo'], 'html' => $html, 'evento' => $evento ]); } catch (Exception $e) { error_log("Error obteniendo evento: " . $e->getMessage()); echo json_encode([ 'success' => false, 'message' => 'Error al obtener el evento' ]); } function generarHtmlEvento($evento, $tipo) { $estado_class = strtolower(str_replace(' ', '-', $evento['estado'])); $tipo_icono = $tipo === 'correctivo' ? 'fas fa-tools' : 'fas fa-calendar-check'; $tipo_color = $tipo === 'correctivo' ? '#17a2b8' : '#5cb85c'; $html = '
'; // Header del evento $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '

' . htmlspecialchars($evento['titulo']) . '

'; $html .= '

ID: ' . $evento['id'] . ' • ' . ucfirst($tipo) . '

'; $html .= '
'; $html .= '
'; $html .= '
'; // Información básica $html .= '
'; $html .= '
'; // Estado $html .= '
'; $html .= 'Estado'; $html .= '
' . $evento['estado'] . '
'; $html .= '
'; // Solicitante $html .= '
'; $html .= 'Solicitante'; $html .= '
' . htmlspecialchars($evento['solicitante']) . '
'; $html .= '
'; // Cliente if ($evento['cliente_nombre']) { $html .= '
'; $html .= 'Cliente'; $html .= '
' . htmlspecialchars($evento['cliente_nombre']) . '
'; $html .= '
'; } // Proyecto if ($evento['proyecto_nombre']) { $html .= '
'; $html .= 'Proyecto'; $html .= '
' . htmlspecialchars($evento['proyecto_nombre']) . '
'; $html .= '
'; } // Asignado a if ($evento['asignado_nombre']) { $html .= '
'; $html .= 'Asignado a'; $html .= '
' . htmlspecialchars($evento['asignado_nombre']) . '
'; $html .= '
'; } $html .= '
'; // Cerrar info-grid // Fechas específicas según el tipo if ($tipo === 'correctivo') { $html .= '
'; $html .= '

Información de Fechas

'; $html .= '
'; $html .= '
'; $html .= 'Fecha de Creación'; $html .= '
' . date('d/m/Y H:i', strtotime($evento['fecha_creacion'] . ' ' . $evento['hora_creacion'])) . '
'; $html .= '
'; if ($evento['fecha_resolucion']) { $html .= '
'; $html .= 'Fecha de Resolución'; $html .= '
' . date('d/m/Y H:i', strtotime($evento['fecha_resolucion'])) . '
'; $html .= '
'; } $html .= '
'; $html .= '
'; } else { $html .= '
'; $html .= '

Programación

'; $html .= '
'; if ($evento['fecha_programada']) { $html .= '
'; $html .= 'Fecha Programada'; $html .= '
' . date('d/m/Y', strtotime($evento['fecha_programada'])); if ($evento['hora_programada']) { $html .= ' ' . date('H:i', strtotime($evento['hora_programada'])); } $html .= '
'; $html .= '
'; } if ($evento['fecha_reprogramada']) { $html .= '
'; $html .= 'Fecha Reprogramada'; $html .= '
' . date('d/m/Y', strtotime($evento['fecha_reprogramada'])); if ($evento['hora_reprogramada']) { $html .= ' ' . date('H:i', strtotime($evento['hora_reprogramada'])); } $html .= '
'; $html .= '
'; } $html .= '
'; $html .= '
'; } // Descripción if ($evento['descripcion']) { $html .= '
'; $html .= '

Descripción

'; $html .= '
'; $html .= nl2br(htmlspecialchars($evento['descripcion'])); $html .= '
'; $html .= '
'; } // Resolución (solo para correctivos) if ($tipo === 'correctivo' && $evento['resolucion']) { $html .= '
'; $html .= '

Resolución

'; $html .= '
'; $html .= nl2br(htmlspecialchars($evento['resolucion'])); $html .= '
'; $html .= '
'; } // Acciones $html .= '
'; $html .= ''; $html .= ' Editar'; $html .= ''; if ($evento['estado'] !== 'Resuelto' && $evento['estado'] !== 'Cerrado') { $html .= ''; $html .= ' Marcar Resuelto'; $html .= ''; } $html .= '
'; $html .= '
'; // Cerrar evento-info $html .= '
'; // Cerrar evento-detalle return $html; } ?>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors