up
This commit is contained in:
+159
-17
@@ -793,6 +793,9 @@ class SimpleWhatsAppManager {
|
||||
} catch (error) {
|
||||
this.showError('Error cargando configuraciones: ' + error.message);
|
||||
}
|
||||
|
||||
// Cargar siempre el estado del documento de términos
|
||||
if (typeof loadTermsDoc === 'function') loadTermsDoc();
|
||||
}
|
||||
|
||||
updatesystem_configForm(data) {
|
||||
@@ -805,7 +808,9 @@ class SimpleWhatsAppManager {
|
||||
{ id: 'webhook-token', value: data.webhook_verify_token },
|
||||
{ id: 'api-url', value: data.api_url },
|
||||
{ id: 'business-name', value: data.business_name },
|
||||
{ id: 'welcome-message', value: data.welcome_message }
|
||||
{ id: 'welcome-message', value: data.welcome_message },
|
||||
{ id: 'terms-message', value: data.terms_message },
|
||||
{ id: 'terms-rejected-message', value: data.terms_rejected_message }
|
||||
];
|
||||
|
||||
fields.forEach(field => {
|
||||
@@ -829,7 +834,9 @@ class SimpleWhatsAppManager {
|
||||
webhook_verify_token: document.getElementById('webhook-token').value,
|
||||
api_url: document.getElementById('api-url').value,
|
||||
business_name: document.getElementById('business-name').value,
|
||||
welcome_message: document.getElementById('welcome-message').value
|
||||
welcome_message: document.getElementById('welcome-message').value,
|
||||
terms_message: document.getElementById('terms-message')?.value || '',
|
||||
terms_rejected_message: document.getElementById('terms-rejected-message')?.value || ''
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -1949,22 +1956,9 @@ class SimpleWhatsAppManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Cargar usuarios administradores del sistema
|
||||
// Gestión de usuarios centralizada en lab_usuarios.php
|
||||
async loadAdminUsers() {
|
||||
this.log('Cargando usuarios administradores...');
|
||||
|
||||
try {
|
||||
const response = await this.apiCall('list_admin_users.php');
|
||||
|
||||
if (response && response.success && response.data) {
|
||||
renderAdminUsersTable(response.data);
|
||||
} else {
|
||||
this.showError('Error cargando usuarios administradores');
|
||||
}
|
||||
} catch (error) {
|
||||
this.log('Error cargando usuarios administradores: ' + error.message, 'error');
|
||||
this.showError('Error cargando usuarios: ' + error.message);
|
||||
}
|
||||
// No-op: la UI redirige a lab_usuarios.php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3436,6 +3430,141 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
});
|
||||
|
||||
// ─── Gestión del documento PDF de Términos y Condiciones ─────────────────────
|
||||
(function () {
|
||||
function showTermsStatus(msg, type) {
|
||||
const el = document.getElementById('terms-upload-status');
|
||||
if (!el) return;
|
||||
el.style.display = 'block';
|
||||
el.className = 'mt-2 small text-' + (type || 'secondary');
|
||||
el.textContent = msg;
|
||||
}
|
||||
|
||||
function _fallbackCopy(text) {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.style.cssText = 'position:fixed;top:-999px;left:-999px;opacity:0;';
|
||||
document.body.appendChild(ta);
|
||||
ta.focus();
|
||||
ta.select();
|
||||
try {
|
||||
const ok = document.execCommand('copy');
|
||||
showTermsStatus(ok ? '✔ URL copiada al portapapeles.' : '✖ No se pudo copiar.', ok ? 'success' : 'danger');
|
||||
} catch (e) {
|
||||
showTermsStatus('✖ No se pudo copiar: ' + text, 'danger');
|
||||
}
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
|
||||
async function loadTermsDoc() {
|
||||
try {
|
||||
const res = await fetch('api/get_terms_config.php');
|
||||
const json = await res.json();
|
||||
if (!json.success || !json.data) return;
|
||||
|
||||
const d = json.data;
|
||||
const nameEl = document.getElementById('terms-doc-name');
|
||||
const verEl = document.getElementById('terms-doc-version');
|
||||
const linkEl = document.getElementById('terms-doc-link');
|
||||
const copyBtn = document.getElementById('terms-doc-copy-btn');
|
||||
const currentEl = document.getElementById('terms-doc-current');
|
||||
const msgAcEl = document.getElementById('terms-message');
|
||||
const msgRjEl = document.getElementById('terms-rejected-message');
|
||||
|
||||
if (nameEl) nameEl.textContent = d.documento_nombre || '(sin nombre)';
|
||||
if (verEl) verEl.textContent = d.version || '—';
|
||||
if (linkEl) linkEl.href = d.documento_url || '#';
|
||||
if (currentEl) currentEl.style.display = d.documento_url ? '' : 'none';
|
||||
|
||||
// Rellenar textos si están en terms_versions (no sobreescribir si ya se cargaron)
|
||||
if (msgAcEl && !msgAcEl.value && d.mensaje_aceptacion) {
|
||||
msgAcEl.value = d.mensaje_aceptacion;
|
||||
}
|
||||
if (msgRjEl && !msgRjEl.value && d.mensaje_rechazo) {
|
||||
msgRjEl.value = d.mensaje_rechazo;
|
||||
}
|
||||
|
||||
if (copyBtn && d.documento_url) {
|
||||
copyBtn.onclick = () => {
|
||||
const url = d.documento_url;
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(url)
|
||||
.then(() => showTermsStatus('✔ URL copiada al portapapeles.', 'success'))
|
||||
.catch(() => _fallbackCopy(url));
|
||||
} else {
|
||||
_fallbackCopy(url);
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('loadTermsDoc error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadTermsDocument() {
|
||||
const fileInput = document.getElementById('terms-pdf-file');
|
||||
const versionEl = document.getElementById('terms-new-version');
|
||||
const forceEl = document.getElementById('terms-force-reaccept');
|
||||
const msgAcEl = document.getElementById('terms-message');
|
||||
const msgRjEl = document.getElementById('terms-rejected-message');
|
||||
|
||||
const formData = new FormData();
|
||||
if (fileInput && fileInput.files.length > 0) {
|
||||
formData.append('pdf', fileInput.files[0]);
|
||||
}
|
||||
if (versionEl) formData.append('version', versionEl.value.trim());
|
||||
if (forceEl) formData.append('forzar_reenvio', forceEl.checked ? '1' : '0');
|
||||
if (msgAcEl) formData.append('mensaje_aceptacion', msgAcEl.value);
|
||||
if (msgRjEl) formData.append('mensaje_rechazo', msgRjEl.value);
|
||||
|
||||
showTermsStatus('Guardando…', 'secondary');
|
||||
|
||||
try {
|
||||
const res = await fetch('api/upload_terms_document.php', { method: 'POST', body: formData });
|
||||
const json = await res.json();
|
||||
if (json.success) {
|
||||
showTermsStatus('✔ ' + (json.message || 'Guardado correctamente.'), 'success');
|
||||
if (json.documento_url) {
|
||||
const linkEl = document.getElementById('terms-doc-link');
|
||||
if (linkEl) linkEl.href = json.documento_url;
|
||||
document.getElementById('terms-doc-current').style.display = '';
|
||||
const nameEl = document.getElementById('terms-doc-name');
|
||||
if (nameEl && fileInput && fileInput.files[0]) nameEl.textContent = fileInput.files[0].name;
|
||||
const verEl = document.getElementById('terms-doc-version');
|
||||
if (verEl && versionEl) verEl.textContent = versionEl.value || '—';
|
||||
}
|
||||
// Limpiar inputs de archivo
|
||||
if (fileInput) fileInput.value = '';
|
||||
if (forceEl) forceEl.checked = false;
|
||||
} else {
|
||||
showTermsStatus('✖ ' + (json.error || 'Error al guardar.'), 'danger');
|
||||
}
|
||||
} catch (e) {
|
||||
showTermsStatus('✖ Error de red: ' + e.message, 'danger');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const uploadBtn = document.getElementById('terms-upload-btn');
|
||||
if (uploadBtn) uploadBtn.addEventListener('click', uploadTermsDocument);
|
||||
|
||||
// Cargar estado del documento cuando se activa el tab de configuración
|
||||
const cfgTab = document.querySelector('[data-bs-target="#system-config"], [href="#system-config"]');
|
||||
if (cfgTab) {
|
||||
cfgTab.addEventListener('shown.bs.tab', loadTermsDoc);
|
||||
}
|
||||
// Si el tab ya está activo al cargar la página
|
||||
const cfgPanel = document.getElementById('system-config');
|
||||
if (cfgPanel && cfgPanel.classList.contains('active')) {
|
||||
loadTermsDoc();
|
||||
}
|
||||
});
|
||||
|
||||
// Exponer para que loadsystem_config() pueda llamarla
|
||||
window.loadTermsDoc = loadTermsDoc;
|
||||
})();
|
||||
// ─── / Términos ───────────────────────────────────────────────────────────────
|
||||
|
||||
// Funciones globales para gestión de usuarios
|
||||
|
||||
// Función para editar usuario
|
||||
@@ -4526,6 +4655,19 @@ window.refreshData = function() {
|
||||
};
|
||||
|
||||
// Función para exportar usuarios
|
||||
window.exportConversations = function(filters) {
|
||||
const params = new URLSearchParams(filters || {});
|
||||
const url = (window.whatsappManager ? window.whatsappManager.apiBaseUrl : 'api/') + 'export_conversations.php';
|
||||
const full = params.toString() ? url + '?' + params.toString() : url;
|
||||
const a = document.createElement('a');
|
||||
a.href = full;
|
||||
a.download = '';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
if (window.whatsappManager) window.whatsappManager.showSuccess('Descarga de conversaciones iniciada');
|
||||
};
|
||||
|
||||
window.exportUsers = function() {
|
||||
console.log('Exportando usuarios...');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user