fetch("SELECT * FROM terms_versions WHERE activa = 1 ORDER BY id DESC LIMIT 1");
// Construcción dinámica del WHERE
$where = [];
$params = [];
if ($filterEstado !== '') {
$where[] = 'ta.estado = :estado';
$params[':estado'] = $filterEstado;
}
if ($filterFecha !== '') {
$where[] = 'DATE(ta.fecha_envio) = :fecha';
$params[':fecha'] = $filterFecha;
}
if ($filterPhone !== '') {
$where[] = 'ta.phone_number LIKE :phone';
$params[':phone'] = '%' . $filterPhone . '%';
}
$whereClause = $where ? 'WHERE ' . implode(' AND ', $where) : '';
$total = (int)($db->fetch(
"SELECT COUNT(*) as c FROM terms_acceptance ta $whereClause",
$params
)['c'] ?? 0);
$rows = $db->fetchAll(
"SELECT ta.id, ta.phone_number, ta.estado, ta.fecha_envio, ta.fecha_respuesta,
tv.version AS terms_version,
u.name AS user_name
FROM terms_acceptance ta
LEFT JOIN terms_versions tv ON tv.id = ta.terms_version_id
LEFT JOIN users u ON u.id = ta.user_id
$whereClause
ORDER BY ta.id DESC
LIMIT $perPage OFFSET $offset",
$params
);
$totalPages = max(1, ceil($total / $perPage));
} catch (Exception $e) {
$rows = [];
$total = 0;
$totalPages = 1;
$activeVersion = null;
$dbError = $e->getMessage();
}
?>
Versión activa: = htmlspecialchars($activeVersion['version']) ?>
—
Ver documento
Re-aceptación forzada activa
= htmlspecialchars($dbError) ?>
fetchAll(
"SELECT estado, COUNT(*) as total FROM terms_acceptance GROUP BY estado"
) : [];
$stats = [];
foreach ($statsRaw as $s) $stats[$s['estado']] = (int)$s['total'];
?>
= $stats['aceptado'] ?? 0 ?>
Aceptaciones
= $stats['rechazado'] ?? 0 ?>
Rechazos
= $stats['pendiente'] ?? 0 ?>
Pendientes
= $total ?>
Total registros
| # |
Teléfono |
Nombre |
Versión |
Estado |
Enviado |
Respondido |
| No hay registros para los filtros seleccionados. |
| = (int)$r['id'] ?> |
= htmlspecialchars($r['phone_number']) ?> |
= htmlspecialchars($r['user_name'] ?: '—') ?> |
= htmlspecialchars($r['terms_version'] ?: '—') ?> |
= ucfirst(htmlspecialchars($r['estado'])) ?>
|
= $r['fecha_envio'] ? date('d/m/Y H:i', strtotime($r['fecha_envio'])) : '—' ?> |
= $r['fecha_respuesta'] ? date('d/m/Y H:i', strtotime($r['fecha_respuesta'])) : '—' ?> |
1): ?>