fix(turnero): restaurar dos plantillas WhatsApp en tab Sesión
- Plantilla con consentimiento (turnero_wa_template) - Plantilla muestra pendiente (turnero_wa_template_muestra) - sesion_turno.php guarda ambas en lab_config Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
a592ddb30d
commit
98507ad1a5
@@ -80,15 +80,19 @@ if ($accion === 'reabrir') {
|
||||
|
||||
// ── CONFIG WHATSAPP ──────────────────────────────────────────
|
||||
if ($accion === 'config_wa') {
|
||||
$template = trim($input['template'] ?? '');
|
||||
$lang = trim($input['lang'] ?? 'es_CO');
|
||||
$waKiosko = (int)($input['wa_kiosko'] ?? 0);
|
||||
$waConsent = (int)($input['wa_consent'] ?? 0);
|
||||
$template = trim($input['template'] ?? '');
|
||||
$templateMuestra = trim($input['template_muestra'] ?? '');
|
||||
$lang = trim($input['lang'] ?? 'es_CO');
|
||||
$waKiosko = (int)($input['wa_kiosko'] ?? 0);
|
||||
$waConsent = (int)($input['wa_consent'] ?? 0);
|
||||
|
||||
if ($template === '') jsonError('El nombre de plantilla es requerido');
|
||||
if (!preg_match('/^[a-z0-9_]{1,64}$/i', $template)) {
|
||||
jsonError('Nombre de plantilla inválido — solo letras, números y guiones bajos');
|
||||
}
|
||||
if ($templateMuestra !== '' && !preg_match('/^[a-z0-9_]{1,64}$/i', $templateMuestra)) {
|
||||
jsonError('Nombre de plantilla muestra inválido — solo letras, números y guiones bajos');
|
||||
}
|
||||
if (!preg_match('/^[a-z]{2}_[A-Z]{2}$/i', $lang)) {
|
||||
jsonError('Código de idioma inválido (formato: es_CO)');
|
||||
}
|
||||
@@ -99,6 +103,7 @@ if ($accion === 'config_wa') {
|
||||
ON DUPLICATE KEY UPDATE valor = VALUES(valor)'
|
||||
);
|
||||
$upsert->execute(['turnero_wa_template', $template]);
|
||||
$upsert->execute(['turnero_wa_template_muestra', $templateMuestra]);
|
||||
$upsert->execute(['turnero_wa_lang', $lang]);
|
||||
$upsert->execute(['turnero_wa_kiosko_enabled', (string)$waKiosko]);
|
||||
$upsert->execute(['turnero_wa_consent_enabled', (string)$waConsent]);
|
||||
|
||||
@@ -760,12 +760,19 @@ $tab = $_GET['tab'] ?? 'lugares';
|
||||
</div>
|
||||
|
||||
<div class="row g-2">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-semibold">Nombre de plantilla Meta aprobada</label>
|
||||
<div class="col-md-5">
|
||||
<label class="form-label small fw-semibold">Plantilla con consentimiento</label>
|
||||
<input type="text" id="wa-template" class="form-control form-control-sm"
|
||||
value="<?= htmlspecialchars($cfg['turnero_wa_template'] ?? 'consentimiento_turno') ?>"
|
||||
placeholder="consentimiento_turno">
|
||||
<small class="text-muted">Nombre exacto en Meta Business Manager</small>
|
||||
<small class="text-muted">Consulta, toma de muestra, etc. — incluye link de firma</small>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small fw-semibold">Plantilla muestra pendiente</label>
|
||||
<input type="text" id="wa-template-muestra" class="form-control form-control-sm"
|
||||
value="<?= htmlspecialchars($cfg['turnero_wa_template_muestra'] ?? 'turno_muestra_pendiente') ?>"
|
||||
placeholder="turno_muestra_pendiente">
|
||||
<small class="text-muted">Solo notifica turno, sin consentimiento</small>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small fw-semibold">Código de idioma</label>
|
||||
@@ -773,16 +780,16 @@ $tab = $_GET['tab'] ?? 'lugares';
|
||||
value="<?= htmlspecialchars($cfg['turnero_wa_lang'] ?? 'es_CO') ?>"
|
||||
placeholder="es_CO">
|
||||
</div>
|
||||
<div class="col-md-3 d-flex align-items-end">
|
||||
<button class="btn btn-primary btn-sm w-100" onclick="guardarWhatsApp()">
|
||||
<i class="fas fa-save me-1"></i>Guardar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end mt-2">
|
||||
<button class="btn btn-primary btn-sm" onclick="guardarWhatsApp()">
|
||||
<i class="fas fa-save me-1"></i>Guardar configuración
|
||||
</button>
|
||||
</div>
|
||||
<div class="alert alert-info py-2 px-3 mt-3" style="font-size:.82rem">
|
||||
<i class="fas fa-info-circle me-1"></i>
|
||||
La plantilla debe estar aprobada en Meta y contener una variable de URL
|
||||
(<code>{{1}}</code>) para el enlace de firma del consentimiento.
|
||||
La plantilla con consentimiento debe contener una variable de URL
|
||||
(<code>{{1}}</code>) para el enlace de firma.
|
||||
El sistema usará texto plano como fallback si la plantilla falla.
|
||||
</div>
|
||||
</div>
|
||||
@@ -1173,16 +1180,17 @@ async function borrarTvVideo() {
|
||||
}
|
||||
|
||||
async function guardarWhatsApp() {
|
||||
const template = document.getElementById('wa-template')?.value.trim();
|
||||
const lang = document.getElementById('wa-lang')?.value.trim();
|
||||
const waKiosko = document.getElementById('chk-wa-kiosko')?.checked ? 1 : 0;
|
||||
const waConsent = document.getElementById('chk-wa-consent')?.checked ? 1 : 0;
|
||||
const template = document.getElementById('wa-template')?.value.trim();
|
||||
const templateMuestra = document.getElementById('wa-template-muestra')?.value.trim();
|
||||
const lang = document.getElementById('wa-lang')?.value.trim();
|
||||
const waKiosko = document.getElementById('chk-wa-kiosko')?.checked ? 1 : 0;
|
||||
const waConsent = document.getElementById('chk-wa-consent')?.checked ? 1 : 0;
|
||||
if (!template) { toast('El nombre de plantilla es requerido', 'error'); return; }
|
||||
|
||||
try {
|
||||
const res = await fetch(API + 'sesion_turno.php', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ accion: 'config_wa', template, lang, wa_kiosko: waKiosko, wa_consent: waConsent })
|
||||
body: JSON.stringify({ accion: 'config_wa', template, template_muestra: templateMuestra, lang, wa_kiosko: waKiosko, wa_consent: waConsent })
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.ok) { toast(json.error || 'Error', 'error'); return; }
|
||||
|
||||
Reference in New Issue
Block a user