up
This commit is contained in:
@@ -118,7 +118,35 @@ try {
|
||||
|
||||
// Recuperar hash e id para la respuesta
|
||||
$db = Database::getInstance();
|
||||
$saved = $db->fetch('SELECT id, hash_verificacion FROM lab_form_envios WHERE token = ?', [$token]);
|
||||
$saved = $db->fetch('SELECT id, hash_verificacion, turnero_consentimiento_id FROM lab_form_envios WHERE token = ?', [$token]);
|
||||
|
||||
// Si este envío está vinculado a un consentimiento del turnero, marcarlo como firmado
|
||||
if (!empty($saved['turnero_consentimiento_id'])) {
|
||||
$pdo2 = $db->getConnection();
|
||||
$tc = $pdo2->prepare(
|
||||
"SELECT tc.id, t.sesion_id FROM turnero_consentimientos tc
|
||||
JOIN turnero_turnos t ON t.id = tc.turno_id
|
||||
WHERE tc.id = ? AND tc.estado != 'firmado'"
|
||||
);
|
||||
$tc->execute([(int)$saved['turnero_consentimiento_id']]);
|
||||
$tcRow = $tc->fetch(PDO::FETCH_ASSOC);
|
||||
if ($tcRow) {
|
||||
$datosRespuestasJson = !empty($datosCliente)
|
||||
? json_encode($datosCliente, JSON_UNESCAPED_UNICODE)
|
||||
: null;
|
||||
$pdo2->prepare(
|
||||
"UPDATE turnero_consentimientos
|
||||
SET estado='firmado', firmado_at=NOW(), firma_svg=?,
|
||||
ip_firma=?, ua_firma=?, datos_respuestas=?
|
||||
WHERE id=?"
|
||||
)->execute([$firmaSvg, $ip, substr($ua, 0, 500), $datosRespuestasJson, (int)$tcRow['id']]);
|
||||
// Notificar via SSE para actualizar lugar.php en tiempo real
|
||||
if ($tcRow['sesion_id']) {
|
||||
require_once __DIR__ . '/../../modules/turnero/api/_helpers.php';
|
||||
notificarSSE((int)$tcRow['sesion_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pubOk([
|
||||
'firmado' => (bool)$firmaSvg,
|
||||
|
||||
Reference in New Issue
Block a user