From ffda892859a28ac1becfa964a60c2c0078abd1e6 Mon Sep 17 00:00:00 2001 From: nickpons666 Date: Fri, 30 Jan 2026 22:52:32 -0600 Subject: [PATCH] fix: Corregir orden de ayudantes en PDFs y bot de Telegram MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Cambiar getAyudantesActivos() por getAyudantesPorOrden() en todos los PDFs y bot - Añadir tabla 'Turnos de Ayudantes' en ambos PDFs (ayudante y admin) - Mostrar 4 próximas fechas para cada ayudante en orden correcto - En PDF de ayudante: resaltar fila del usuario con badge 'Tu' - Corregir sendPDF() y sendPDFGeneral() en bot de Telegram - Asegurar consistencia: Ana → Esperanza → Mary → Bety → Mariela - Sincronizar completamente web, PDFs y bot con nuevo orden de rotación --- bot/TelegramBot.php | 12 ++++++----- public/admin/export-pdf.php | 36 ++++++++++++++++++++++++++++++++- public/export-pdf.php | 40 ++++++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 7 deletions(-) diff --git a/bot/TelegramBot.php b/bot/TelegramBot.php index 1037b90..41cc910 100755 --- a/bot/TelegramBot.php +++ b/bot/TelegramBot.php @@ -20,14 +20,16 @@ class TelegramBot { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // --- MEJORAS --- - // 1. Forzar el uso de IPv4. Un problema común en entornos Docker - // es un timeout al intentar resolver AAAA (IPv6) antes de usar A (IPv4). + // 1. Forzar el uso de IPv4. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - // 2. Añadir timeouts para evitar que el script se cuelgue indefinidamente. + // 2. Añadir timeouts de seguridad. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // 5 segundos para conectar curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 10 segundos para la transferencia total + // 3. (ÚLTIMO INTENTO) Forzar versión de TLS. + curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + if ($httpMethod === 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); @@ -269,7 +271,7 @@ class TelegramBot { $db = \Database::getInstance()->getConnection(); $horarios = $horariosModel->getActivos(); - $ayudantes = $userModel->getAyudantesActivos(); + $ayudantes = $asignacionModel->getAyudantesPorOrden(); $semanasFuturas = []; $hoy = new DateTime(); @@ -398,7 +400,7 @@ class TelegramBot { $db = \Database::getInstance()->getConnection(); $horarios = $horariosModel->getActivos(); - $ayudantes = $userModel->getAyudantesActivos(); + $ayudantes = $asignacionModel->getAyudantesPorOrden(); $semanasFuturas = []; $hoy = new DateTime(); diff --git a/public/admin/export-pdf.php b/public/admin/export-pdf.php index d274b4a..3024251 100644 --- a/public/admin/export-pdf.php +++ b/public/admin/export-pdf.php @@ -22,7 +22,7 @@ $totalAyudantes = count($userModel->getAyudantesActivos()); $totalHorarios = count($horariosModel->getAll()); $asignacionActual = $asignacionModel->getAsignacionActual(); -$ayudantes = $userModel->getAyudantesActivos(); +$ayudantes = $asignacionModel->getAyudantesPorOrden(); $horarios = $horariosModel->getAll(); $asignaciones = $asignacionModel->getTodasAsignaciones(); @@ -89,6 +89,40 @@ foreach ($asignacionesLimit as $a) { $html .= ''; +$html .= '

Turnos de Ayudantes

'; +$html .= ''; +$html .= ''; +$html .= ''; + +foreach ($ayudantes as $ayudante) { + $stmt = $db->prepare(" + SELECT semana_inicio, semana_fin + FROM asignaciones_turnos + WHERE user_id = ? AND semana_inicio >= CURDATE() + ORDER BY semana_inicio + LIMIT 4 + "); + $stmt->execute([$ayudante['id']]); + $turnos = $stmt->fetchAll(); + + $html .= ''; + $html .= ''; + + for ($i = 0; $i < 4; $i++) { + $html .= ''; + } + $html .= ''; +} + +$html .= '
AyudanteFecha 1Fecha 2Fecha 3Fecha 4
' . htmlspecialchars($ayudante['nombre']) . ''; + if (isset($turnos[$i])) { + $html .= date('d/m/Y', strtotime($turnos[$i]['semana_inicio'])) . ' - '; + $html .= date('d/m/Y', strtotime($turnos[$i]['semana_fin'])); + } else { + $html .= '-'; + } + $html .= '
'; + $html .= PDFGenerator::getFooter(); $pdf = new PDFGenerator(); diff --git a/public/export-pdf.php b/public/export-pdf.php index 0190208..fd71f11 100644 --- a/public/export-pdf.php +++ b/public/export-pdf.php @@ -21,7 +21,7 @@ $db = Database::getInstance()->getConnection(); $horarios = $horariosModel->getActivos(); $userModel = new User(); -$ayudantes = $userModel->getAyudantesActivos(); +$ayudantes = $asignacionModel->getAyudantesPorOrden(); $semanasFuturas = []; $hoy = new DateTime(); @@ -127,6 +127,44 @@ foreach ($semanasFuturas as $index => $semana) { $html .= ''; } +$html .= ''; + +$html .= '

Turnos de Ayudantes

'; +$html .= ''; +$html .= ''; +$html .= ''; + +foreach ($ayudantes as $ayudante) { + $stmt = $db->prepare(" + SELECT semana_inicio, semana_fin + FROM asignaciones_turnos + WHERE user_id = ? AND semana_inicio >= CURDATE() + ORDER BY semana_inicio + LIMIT 4 + "); + $stmt->execute([$ayudante['id']]); + $turnos = $stmt->fetchAll(); + + $html .= ''; + $html .= ''; + + for ($i = 0; $i < 4; $i++) { + $html .= ''; + } + $html .= ''; +} + $html .= '
AyudanteFecha 1Fecha 2Fecha 3Fecha 4
' . htmlspecialchars($ayudante['nombre']); + if ($ayudante['id'] == $user['id']) { + $html .= ' Tu'; + } + $html .= ''; + if (isset($turnos[$i])) { + $html .= date('d/m/Y', strtotime($turnos[$i]['semana_inicio'])) . ' - '; + $html .= date('d/m/Y', strtotime($turnos[$i]['semana_fin'])); + } else { + $html .= '-'; + } + $html .= '
'; $html .= PDFGenerator::getFooter();