feat: modo embebido de formulario por lugar (link vs iframe)
- Nueva columna turnero_lugares.formulario_modo (link|embebido) - Config: radio en modal de edición para elegir el modo - lugar.php: muestra iframe con ver_formulario_enviado al activar turno - API get_consent_token.php: crea/obtiene token para turno+lugar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
daa9827d93
commit
f8245b4d6f
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* GET ?turno_id=X&lugar_id=Y
|
||||
* Devuelve (o crea) el token de consentimiento para un turno+lugar en modo embebido.
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireTurnero();
|
||||
|
||||
$turnoId = (int)($_GET['turno_id'] ?? 0);
|
||||
$lugarId = (int)($_GET['lugar_id'] ?? 0);
|
||||
if (!$turnoId || !$lugarId) jsonError('turno_id y lugar_id requeridos');
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Obtener formulario configurado para el lugar
|
||||
$formRow = $pdo->prepare(
|
||||
"SELECT tlc.formulario_id FROM turnero_lugar_consentimientos tlc
|
||||
JOIN lab_formularios f ON f.id = tlc.formulario_id AND f.is_active = 1
|
||||
WHERE tlc.lugar_id = ?
|
||||
ORDER BY tlc.formulario_id ASC LIMIT 1"
|
||||
);
|
||||
$formRow->execute([$lugarId]);
|
||||
$form = $formRow->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$form) jsonError('No hay formulario configurado para este lugar', 404);
|
||||
|
||||
$formularioId = (int)$form['formulario_id'];
|
||||
|
||||
// Buscar token existente
|
||||
$existing = $pdo->prepare(
|
||||
"SELECT token FROM turnero_consentimientos WHERE turno_id = ? AND formulario_id = ? LIMIT 1"
|
||||
);
|
||||
$existing->execute([$turnoId, $formularioId]);
|
||||
$row = $existing->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($row) {
|
||||
jsonOk(['token' => $row['token'], 'nuevo' => false]);
|
||||
}
|
||||
|
||||
// Crear nuevo token
|
||||
$token = sprintf(
|
||||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
mt_rand(0,0xffff), mt_rand(0,0xffff),
|
||||
mt_rand(0,0xffff),
|
||||
mt_rand(0,0x0fff)|0x4000,
|
||||
mt_rand(0,0x3fff)|0x8000,
|
||||
mt_rand(0,0xffff), mt_rand(0,0xffff), mt_rand(0,0xffff)
|
||||
);
|
||||
$pdo->prepare(
|
||||
"INSERT IGNORE INTO turnero_consentimientos (turno_id, formulario_id, token, estado) VALUES (?, ?, ?, 'pendiente')"
|
||||
)->execute([$turnoId, $formularioId, $token]);
|
||||
|
||||
jsonOk(['token' => $token, 'nuevo' => true]);
|
||||
@@ -52,6 +52,8 @@ $sortOrder = (int)($input['sort_order'] ?? 99);
|
||||
$activo = (int)($input['activo'] ?? 1);
|
||||
$tipo = in_array($input['tipo'] ?? '', ['recepcion', 'muestras'], true)
|
||||
? $input['tipo'] : 'muestras';
|
||||
$formModo = in_array($input['formulario_modo'] ?? '', ['link', 'embebido'], true)
|
||||
? $input['formulario_modo'] : 'link';
|
||||
$formularioIds = isset($input['formulario_ids']) && is_array($input['formulario_ids'])
|
||||
? array_filter(array_map('intval', $input['formulario_ids']), fn($v) => $v > 0)
|
||||
: [];
|
||||
@@ -64,15 +66,15 @@ $pdo->beginTransaction();
|
||||
try {
|
||||
if ($id) {
|
||||
$stmt = $pdo->prepare(
|
||||
'UPDATE turnero_lugares SET nombre=?, tipo=?, descripcion=?, sort_order=?, activo=? WHERE id=?'
|
||||
'UPDATE turnero_lugares SET nombre=?, tipo=?, descripcion=?, sort_order=?, activo=?, formulario_modo=? WHERE id=?'
|
||||
);
|
||||
$stmt->execute([$nombre, $tipo, $desc ?: null, $sortOrder, $activo, $id]);
|
||||
$stmt->execute([$nombre, $tipo, $desc ?: null, $sortOrder, $activo, $formModo, $id]);
|
||||
$lugarId = $id;
|
||||
} else {
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO turnero_lugares (nombre, tipo, descripcion, sort_order, activo) VALUES (?, ?, ?, ?, ?)'
|
||||
'INSERT INTO turnero_lugares (nombre, tipo, descripcion, sort_order, activo, formulario_modo) VALUES (?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([$nombre, $tipo, $desc ?: null, $sortOrder, $activo]);
|
||||
$stmt->execute([$nombre, $tipo, $desc ?: null, $sortOrder, $activo, $formModo]);
|
||||
$lugarId = (int) $pdo->lastInsertId();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user