Primer commit del sistema separado falta mejorar mucho
This commit is contained in:
519
telegram/views/templates/create.php
Executable file
519
telegram/views/templates/create.php
Executable file
@@ -0,0 +1,519 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
|
||||
$userData = JWTAuth::requireAuth();
|
||||
|
||||
// Verificar permiso para ver y crear plantillas
|
||||
if (!hasPermission('manage_templates', 'telegram')) {
|
||||
die('No tienes permiso para crear plantillas de Telegram.');
|
||||
}
|
||||
|
||||
// PHP logic for initial display, not for form processing
|
||||
$error = $_GET['error'] ?? '';
|
||||
$success = $_GET['success'] ?? '';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?php echo $userData->idioma ?? 'es'; ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Crear Plantilla - Telegram</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.css" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--telegram-color: #0088cc;
|
||||
--telegram-dark: #006699;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, var(--telegram-color) 0%, var(--telegram-dark) 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 20px 30px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
color: var(--telegram-color);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 40px;
|
||||
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group input[type="text"] {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input[type="text"]:focus {
|
||||
outline: none;
|
||||
border-color: var(--telegram-color);
|
||||
}
|
||||
|
||||
.form-help {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #fee;
|
||||
color: #c33;
|
||||
border-left: 4px solid #c33;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: #efe;
|
||||
color: #3c3;
|
||||
border-left: 4px solid #3c3;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--telegram-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: var(--telegram-dark);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #5a6268;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background: #218838;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.note-editor {
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.note-editor.note-frame {
|
||||
border-color: var(--telegram-color);
|
||||
}
|
||||
|
||||
/* Modal de galería */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 9999;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
margin: 50px auto;
|
||||
padding: 30px;
|
||||
border-radius: 15px;
|
||||
width: 90%;
|
||||
max-width: 900px;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
color: var(--telegram-color);
|
||||
}
|
||||
|
||||
.close {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.gallery-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.gallery-item {
|
||||
cursor: pointer;
|
||||
border: 3px solid transparent;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.gallery-item:hover {
|
||||
border-color: var(--telegram-color);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.gallery-item img {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.upload-area {
|
||||
border: 2px dashed #ddd;
|
||||
border-radius: 10px;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.upload-area:hover {
|
||||
border-color: var(--telegram-color);
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.upload-area input[type="file"] {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1><i class="fas fa-plus"></i> Crear Plantilla Telegram</h1>
|
||||
<a href="list.php" class="btn btn-secondary">
|
||||
<i class="fas fa-arrow-left"></i> Volver
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="form-container">
|
||||
<div id="alert-messages">
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success"><?php echo htmlspecialchars($success); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<form id="createTemplateForm">
|
||||
<div class="form-group">
|
||||
<label for="nombre">Nombre de la Plantilla *</label>
|
||||
<input type="text" id="nombre" name="nombre" required value="">
|
||||
<div class="form-help">Nombre descriptivo para identificar la plantilla</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="comando">Comando (opcional)</label>
|
||||
<input type="text" id="comando" name="comando" placeholder="Ej: /start, /help" value="">
|
||||
<div class="form-help">Comando para invocar esta plantilla en Telegram. Debe ser único.</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="contenido">Contenido *</label>
|
||||
<button type="button" onclick="openGallery()" class="btn btn-success" style="margin-bottom: 10px;">
|
||||
<i class="fas fa-images"></i> Insertar Imagen
|
||||
</button>
|
||||
<textarea id="contenido" name="contenido"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-save"></i> Guardar Plantilla
|
||||
</button>
|
||||
<button type="button" onclick="previewContent()" class="btn btn-secondary">
|
||||
<i class="fas fa-eye"></i> Vista Previa
|
||||
</button>
|
||||
<a href="list.php" class="btn btn-secondary">
|
||||
<i class="fas fa-times"></i> Cancelar
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal de Galería -->
|
||||
<div id="galleryModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2><i class="fas fa-images"></i> Galería de Imágenes</h2>
|
||||
<span class="close" onclick="closeGallery()">×</span>
|
||||
</div>
|
||||
|
||||
<div class="upload-area" onclick="document.getElementById('fileInput').click()">
|
||||
<i class="fas fa-cloud-upload-alt" style="font-size: 48px; color: #ddd;"></i>
|
||||
<p style="margin-top: 10px; color: #666;">Haz clic para subir una imagen o arrastra aquí</p>
|
||||
<input type="file" id="fileInput" accept="image/*" onchange="uploadImage(this)">
|
||||
</div>
|
||||
|
||||
<div class="gallery-grid" id="galleryGrid">
|
||||
<p style="text-align: center; color: #999;">Cargando imágenes...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#contenido').summernote({
|
||||
height: 300,
|
||||
toolbar: [
|
||||
['style', ['style']],
|
||||
['font', ['bold', 'underline', 'clear']],
|
||||
['color', ['color']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['table', ['table']],
|
||||
['insert', ['link']],
|
||||
['view', ['fullscreen', 'codeview', 'help']]
|
||||
],
|
||||
placeholder: 'Escribe el contenido de tu plantilla aquí...'
|
||||
});
|
||||
|
||||
// Handle form submission via Fetch API
|
||||
$('#createTemplateForm').on('submit', async function(e) {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
const nombre = $('#nombre').val();
|
||||
const comando = $('#comando').val();
|
||||
const contenido = $('#contenido').summernote('code'); // Get content from Summernote
|
||||
|
||||
// Clear previous alerts
|
||||
$('#alert-messages').empty();
|
||||
|
||||
if (!nombre || !contenido) {
|
||||
showAlert('El nombre y el contenido son obligatorios.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/telegram/api/templates/create.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ nombre, comando, contenido })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Plantilla creada correctamente.', 'success');
|
||||
setTimeout(() => {
|
||||
window.location.href = 'list.php';
|
||||
}, 1500); // Redirect after a short delay
|
||||
} else {
|
||||
showAlert(result.error || 'Error desconocido al crear la plantilla.', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error al enviar la solicitud:', error);
|
||||
showAlert('Error de conexión al guardar la plantilla.', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function openGallery() {
|
||||
document.getElementById('galleryModal').style.display = 'block';
|
||||
loadGallery();
|
||||
}
|
||||
|
||||
function closeGallery() {
|
||||
document.getElementById('galleryModal').style.display = 'none';
|
||||
}
|
||||
|
||||
async function loadGallery() {
|
||||
try {
|
||||
const response = await fetch('/gallery/api/list.php');
|
||||
const data = await response.json();
|
||||
|
||||
const grid = document.getElementById('galleryGrid');
|
||||
|
||||
if (data.success && data.images.length > 0) {
|
||||
grid.innerHTML = data.images.map(img => `
|
||||
<div class="gallery-item" onclick="insertImage('${img.url}')">
|
||||
<img src="${img.url_thumbnail}" alt="${img.nombre_original}">
|
||||
</div>
|
||||
`).join('');
|
||||
} else {
|
||||
grid.innerHTML = '<p style="text-align: center; color: #999;">No hay imágenes disponibles</p>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error cargando galería:', error);
|
||||
document.getElementById('galleryGrid').innerHTML = '<p style="text-align: center; color: #c33;">Error cargando imágenes</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function insertImage(url) {
|
||||
const fullUrl = window.location.origin + url;
|
||||
$('#contenido').summernote('insertImage', fullUrl);
|
||||
closeGallery();
|
||||
}
|
||||
|
||||
async function uploadImage(input) {
|
||||
if (!input.files || !input.files[0]) return;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('image', input.files[0]);
|
||||
|
||||
try {
|
||||
const response = await fetch('/gallery/api/upload.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
alert('Imagen subida correctamente');
|
||||
loadGallery();
|
||||
} else {
|
||||
alert('Error: ' + data.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error al subir la imagen');
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
function previewContent() {
|
||||
const content = $('#contenido').summernote('code');
|
||||
const win = window.open('', 'Preview', 'width=800,height=600');
|
||||
win.document.write(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Vista Previa</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
.preview-container {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="preview-container">
|
||||
${content}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
}
|
||||
|
||||
// Cerrar modal al hacer clic fuera
|
||||
window.onclick = function(event) {
|
||||
const modal = document.getElementById('galleryModal');
|
||||
if (event.target == modal) {
|
||||
closeGallery();
|
||||
}
|
||||
}
|
||||
|
||||
function showAlert(message, type) {
|
||||
const alertDiv =
|
||||
`<div class="alert alert-" + type + ">
|
||||
` + message + `
|
||||
</div>`
|
||||
$('#alert-messages').html(alertDiv);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
540
telegram/views/templates/edit.php
Executable file
540
telegram/views/templates/edit.php
Executable file
@@ -0,0 +1,540 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
require_once __DIR__ . '/../../../shared/database/connection.php';
|
||||
|
||||
$userData = JWTAuth::requireAuth();
|
||||
|
||||
// Verificar permiso para ver y editar plantillas
|
||||
if (!hasPermission('manage_templates', 'telegram')) {
|
||||
die('No tienes permiso para editar plantillas de Telegram.'); // Mensaje de error más general para evitar leaks
|
||||
}
|
||||
|
||||
// Obtener ID de la plantilla
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
header('Location: list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare("SELECT * FROM plantillas_telegram WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$plantilla = $stmt->fetch();
|
||||
|
||||
if (!$plantilla) {
|
||||
header('Location: list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar propiedad de la plantilla si no es Admin
|
||||
if ($userData->rol !== 'Admin' && $plantilla['usuario_id'] != $userData->userId) {
|
||||
die('No tienes permiso para editar esta plantilla, ya que no te pertenece.');
|
||||
}
|
||||
|
||||
$error = $_GET['error'] ?? '';
|
||||
$success = $_GET['success'] ?? '';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?php echo $userData->idioma ?? 'es'; ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Editar Plantilla - Telegram</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.css" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--telegram-color: #0088cc;
|
||||
--telegram-dark: #006699;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, var(--telegram-color) 0%, var(--telegram-dark) 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 20px 30px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
color: var(--telegram-color);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 40px;
|
||||
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group input[type="text"] {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input[type="text"]:focus {
|
||||
outline: none;
|
||||
border-color: var(--telegram-color);
|
||||
}
|
||||
|
||||
.form-help {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #fee;
|
||||
color: #c33;
|
||||
border-left: 4px solid #c33;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: #efe;
|
||||
color: #3c3;
|
||||
border-left: 4px solid #3c3;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--telegram-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: var(--telegram-dark);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #5a6268;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background: #218838;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.note-editor {
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.note-editor.note-frame {
|
||||
border-color: var(--telegram-color);
|
||||
}
|
||||
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 9999;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
margin: 50px auto;
|
||||
padding: 30px;
|
||||
border-radius: 15px;
|
||||
width: 90%;
|
||||
max-width: 900px;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
color: var(--telegram-color);
|
||||
}
|
||||
|
||||
.close {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.gallery-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.gallery-item {
|
||||
cursor: pointer;
|
||||
border: 3px solid transparent;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.gallery-item:hover {
|
||||
border-color: var(--telegram-color);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.gallery-item img {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.upload-area {
|
||||
border: 2px dashed #ddd;
|
||||
border-radius: 10px;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.upload-area:hover {
|
||||
border-color: var(--telegram-color);
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.upload-area input[type="file"] {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1><i class="fas fa-edit"></i> Editar Plantilla</h1>
|
||||
<a href="list.php" class="btn btn-secondary">
|
||||
<i class="fas fa-arrow-left"></i> Volver
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="form-container">
|
||||
<div id="alert-messages">
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success"><?php echo htmlspecialchars($success); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<form id="editTemplateForm">
|
||||
<input type="hidden" id="templateId" value="<?php echo htmlspecialchars($plantilla['id']); ?>">
|
||||
<div class="form-group">
|
||||
<label for="nombre">Nombre de la Plantilla *</label>
|
||||
<input type="text" id="nombre" name="nombre" required value="<?php echo htmlspecialchars($plantilla['nombre']); ?>">
|
||||
<div class="form-help">Nombre descriptivo para identificar la plantilla</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="comando">Comando (opcional)</label>
|
||||
<input type="text" id="comando" name="comando" placeholder="Ej: /comandos, #asedio" value="<?php echo htmlspecialchars($plantilla['comando'] ?? ''); ?>">
|
||||
<div class="form-help">Comando para invocar esta plantilla en Telegram. Debe ser único.</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="contenido">Contenido *</label>
|
||||
<button type="button" onclick="openGallery()" class="btn btn-success" style="margin-bottom: 10px;">
|
||||
<i class="fas fa-images"></i> Insertar Imagen
|
||||
</button>
|
||||
<textarea id="contenido" name="contenido"><?php echo htmlspecialchars($plantilla['contenido']); ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-save"></i> Guardar Cambios
|
||||
</button>
|
||||
<button type="button" onclick="previewContent()" class="btn btn-secondary">
|
||||
<i class="fas fa-eye"></i> Vista Previa
|
||||
</button>
|
||||
<a href="list.php" class="btn btn-secondary">
|
||||
<i class="fas fa-times"></i> Cancelar
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal de Galería -->
|
||||
<div id="galleryModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2><i class="fas fa-images"></i> Galería de Imágenes</h2>
|
||||
<span class="close" onclick="closeGallery()">×</span>
|
||||
</div>
|
||||
|
||||
<div class="upload-area" onclick="document.getElementById('fileInput').click()">
|
||||
<i class="fas fa-cloud-upload-alt" style="font-size: 48px; color: #ddd;"></i>
|
||||
<p style="margin-top: 10px; color: #666;">Haz clic para subir una imagen o arrastra aquí</p>
|
||||
<input type="file" id="fileInput" accept="image/*" onchange="uploadImage(this)">
|
||||
</div>
|
||||
|
||||
<div class="gallery-grid" id="galleryGrid">
|
||||
<p style="text-align: center; color: #999;">Cargando imágenes...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#contenido').summernote({
|
||||
height: 300,
|
||||
toolbar: [
|
||||
['style', ['style']],
|
||||
['font', ['bold', 'underline', 'clear']],
|
||||
['color', ['color']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['table', ['table']],
|
||||
['insert', ['link']],
|
||||
['view', ['fullscreen', 'codeview', 'help']]
|
||||
]
|
||||
});
|
||||
|
||||
// Handle form submission via Fetch API
|
||||
$('#editTemplateForm').on('submit', async function(e) {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
const id = $('#templateId').val();
|
||||
const nombre = $('#nombre').val();
|
||||
const comando = $('#comando').val();
|
||||
const contenido = $('#contenido').summernote('code'); // Get content from Summernote
|
||||
|
||||
// Clear previous alerts
|
||||
$('#alert-messages').empty();
|
||||
|
||||
if (!nombre || !contenido) {
|
||||
showAlert('El nombre y el contenido son obligatorios.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/telegram/api/templates/edit.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ id, nombre, comando, contenido })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('Plantilla actualizada correctamente.', 'success');
|
||||
// Optionally redirect or update UI
|
||||
} else {
|
||||
showAlert(result.error || 'Error desconocido al actualizar la plantilla.', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error al enviar la solicitud:', error);
|
||||
showAlert('Error de conexión al guardar los cambios.', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function openGallery() {
|
||||
document.getElementById('galleryModal').style.display = 'block';
|
||||
loadGallery();
|
||||
}
|
||||
|
||||
function closeGallery() {
|
||||
document.getElementById('galleryModal').style.display = 'none';
|
||||
}
|
||||
|
||||
async function loadGallery() {
|
||||
try {
|
||||
const response = await fetch('/gallery/api/list.php');
|
||||
const data = await response.json();
|
||||
|
||||
const grid = document.getElementById('galleryGrid');
|
||||
|
||||
if (data.success && data.images.length > 0) {
|
||||
grid.innerHTML = data.images.map(img => `
|
||||
<div class="gallery-item" onclick="insertImage('${img.url}')">
|
||||
<img src="${img.url_thumbnail}" alt="${img.nombre_original}">
|
||||
</div>
|
||||
`).join('');
|
||||
} else {
|
||||
grid.innerHTML = '<p style="text-align: center; color: #999;">No hay imágenes disponibles</p>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error cargando galería:', error);
|
||||
document.getElementById('galleryGrid').innerHTML = '<p style="text-align: center; color: #c33;">Error cargando imágenes</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function insertImage(url) {
|
||||
const fullUrl = window.location.origin + url;
|
||||
$('#contenido').summernote('insertImage', fullUrl);
|
||||
closeGallery();
|
||||
}
|
||||
|
||||
async function uploadImage(input) {
|
||||
if (!input.files || !input.files[0]) return;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('image', input.files[0]);
|
||||
|
||||
try {
|
||||
const response = await fetch('/gallery/api/upload.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
alert('Imagen subida correctamente');
|
||||
loadGallery();
|
||||
} else {
|
||||
alert('Error: ' + data.error);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error al subir la imagen');
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
function previewContent() {
|
||||
const content = $('#contenido').summernote('code');
|
||||
const win = window.open('', 'Preview', 'width=800,height=600');
|
||||
win.document.write(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Vista Previa</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
padding: 20px;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
.preview-container {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="preview-container">
|
||||
${content}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
}
|
||||
|
||||
window.onclick = function(event) {
|
||||
const modal = document.getElementById('galleryModal');
|
||||
if (event.target == modal) {
|
||||
closeGallery();
|
||||
}
|
||||
}
|
||||
|
||||
function showAlert(message, type) {
|
||||
const alertDiv =
|
||||
`<div class="alert alert-" + type + ">
|
||||
` + message + `
|
||||
</div>
|
||||
`;
|
||||
$('#alert-messages').html(alertDiv);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
335
telegram/views/templates/list.php
Executable file
335
telegram/views/templates/list.php
Executable file
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Cargar variables de entorno
|
||||
if (file_exists(__DIR__ . '/../../../.env')) {
|
||||
$lines = file(__DIR__ . '/../../../.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
if (strpos(trim($line), '#') === 0) continue;
|
||||
if (strpos($line, '=') === false) continue;
|
||||
list($key, $value) = explode('=', $line, 2);
|
||||
$_ENV[trim($key)] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
|
||||
$userData = JWTAuth::requireAuth();
|
||||
|
||||
// Verificar permiso para ver la página de plantillas
|
||||
if (!hasPermission('view_templates', 'telegram')) {
|
||||
die('No tienes permiso para ver las plantillas de Telegram.');
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?php echo $userData->idioma ?? 'es'; ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Plantillas Telegram - Sistema de Bots</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<style>
|
||||
:root {
|
||||
--telegram-color: #0088cc;
|
||||
--telegram-dark: #006699;
|
||||
}
|
||||
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, var(--telegram-color) 0%, var(--telegram-dark) 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 20px 30px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header h1 { color: var(--telegram-color); font-size: 24px; }
|
||||
|
||||
.container { max-width: 1200px; margin: 0 auto; }
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 25px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.btn-primary { background: var(--telegram-color); color: white; }
|
||||
.btn-secondary { background: #6c757d; color: white; }
|
||||
.btn-danger { background: #dc3545; color: white; }
|
||||
|
||||
#templates-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.template-card {
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
border: 2px solid #eee;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.template-card:hover {
|
||||
border-color: var(--telegram-color);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.template-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.template-title {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.template-meta {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.template-preview-content {
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 15px;
|
||||
max-height: 100px;
|
||||
overflow: hidden;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
position: relative;
|
||||
}
|
||||
.template-preview-content::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, white);
|
||||
}
|
||||
|
||||
.template-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.empty-state, .loading-state, .error-state {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
padding: 60px 40px;
|
||||
text-align: center;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.empty-state i, .loading-state i, .error-state i {
|
||||
font-size: 64px;
|
||||
color: #ddd;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.empty-state h2, .loading-state h2, .error-state h2 {
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.empty-state p, .loading-state p, .error-state p {
|
||||
color: #999;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1><i class="fas fa-file-alt"></i> Plantillas de Telegram</h1>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
||||
<a href="create.php" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i> Nueva Plantilla
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<a href="/telegram/dashboard_telegram.php" class="btn btn-secondary">
|
||||
<i class="fas fa-arrow-left"></i> Volver
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div id="templates-container">
|
||||
<!-- Templates will be loaded here by JavaScript -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', loadTemplates);
|
||||
|
||||
function escapeHTML(str) {
|
||||
if (str === null || str === undefined) return '';
|
||||
return str.toString().replace(/[&<>"']/g, function(match) {
|
||||
return {
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
||||
}[match];
|
||||
});
|
||||
}
|
||||
|
||||
async function loadTemplates() {
|
||||
const container = document.getElementById('templates-container');
|
||||
container.innerHTML = `
|
||||
<div class="loading-state">
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
<h2>Cargando Plantillas...</h2>
|
||||
</div>`;
|
||||
|
||||
try {
|
||||
const response = await fetch('/telegram/api/templates/list.php');
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Failed to load templates');
|
||||
}
|
||||
|
||||
if (result.templates.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-file-alt"></i>
|
||||
<h2>No hay plantillas creadas</h2>
|
||||
<p>Crea tu primera plantilla para empezar a enviar mensajes en Telegram</p>
|
||||
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
||||
<a href="create.php" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i> Crear Primera Plantilla
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = '<div class="templates-grid"></div>'; // Clear loading state and add grid
|
||||
const templatesGrid = container.querySelector('.templates-grid');
|
||||
result.templates.forEach(template => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'template-card';
|
||||
|
||||
const commandHTML = template.comando
|
||||
? `<span class="template-command" style="background: #e3f2fd; color: var(--telegram-color); padding: 4px 12px; border-radius: 12px; font-size: 13px; font-weight: 600; font-family: monospace;">${escapeHTML(template.comando)}</span>`
|
||||
: '';
|
||||
|
||||
const contentPreview = document.createElement('div');
|
||||
// Telegram doesn't use HTML in the same way, but it can use Markdown.
|
||||
// For preview, we'll just show plain text or stripped HTML.
|
||||
contentPreview.innerHTML = template.contenido;
|
||||
|
||||
card.innerHTML = `
|
||||
<div class="template-header">
|
||||
<div>
|
||||
<div class="template-title">${escapeHTML(template.nombre)}</div>
|
||||
${commandHTML}
|
||||
</div>
|
||||
</div>
|
||||
<div class="template-meta">
|
||||
<i class="fas fa-user"></i> ${escapeHTML(template.username) || 'Desconocido'}
|
||||
<br>
|
||||
<i class="fas fa-clock"></i> ${new Date(template.fecha_modificacion).toLocaleString()}
|
||||
</div>
|
||||
<div class="template-preview-content">
|
||||
${escapeHTML(contentPreview.textContent || '')}
|
||||
</div>
|
||||
<div class="template-actions">
|
||||
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
||||
<a href="edit.php?id=${template.id}" class="btn btn-primary" style="font-size: 12px; padding: 5px 10px;">
|
||||
<i class="fas fa-edit"></i> Editar
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (hasPermission('view_templates', 'telegram')): ?>
|
||||
<a href="preview.php?id=${template.id}" class="btn btn-secondary" style="font-size: 12px; padding: 5px 10px;" target="_blank">
|
||||
<i class="fas fa-eye"></i> Vista Previa
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
||||
<button onclick="deleteTemplate(${template.id}, '${escapeHTML(template.nombre)}') " class="btn btn-danger" style="font-size: 12px; padding: 5px 10px;">
|
||||
<i class="fas fa-trash"></i> Eliminar
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
`;
|
||||
templatesGrid.appendChild(card);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading templates:', error);
|
||||
container.innerHTML = `
|
||||
<div class="error-state">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
<h2>Error al Cargar</h2>
|
||||
<p>No se pudieron cargar las plantillas. Revisa la consola para más detalles.</p>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTemplate(id, nombre) {
|
||||
if (!confirm(\`¿Estás seguro de eliminar la plantilla "\${nombre}"?\`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/telegram/api/templates/delete.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: id })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
alert('Plantilla eliminada correctamente');
|
||||
loadTemplates(); // Reload the list dynamically
|
||||
} else {
|
||||
alert('Error al eliminar: ' + (data.error || 'Error desconocido'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting template:', error);
|
||||
alert('Error de conexión al intentar eliminar la plantilla.');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
24
telegram/views/templates/php_errors.log
Executable file
24
telegram/views/templates/php_errors.log
Executable file
@@ -0,0 +1,24 @@
|
||||
[29-Nov-2025 14:32:40 America/Mexico_City] PHP Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.creador_id' in 'on clause' in /var/www/html/bot/telegram/views/templates/list.php:27
|
||||
Stack trace:
|
||||
#0 /var/www/html/bot/telegram/views/templates/list.php(27): PDO->query()
|
||||
#1 {main}
|
||||
thrown in /var/www/html/bot/telegram/views/templates/list.php on line 27
|
||||
[29-Nov-2025 14:32:47 America/Mexico_City] PHP Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.creador_id' in 'on clause' in /var/www/html/bot/telegram/views/templates/list.php:27
|
||||
Stack trace:
|
||||
#0 /var/www/html/bot/telegram/views/templates/list.php(27): PDO->query()
|
||||
#1 {main}
|
||||
thrown in /var/www/html/bot/telegram/views/templates/list.php on line 27
|
||||
[29-Nov-2025 14:36:22 America/Mexico_City] PHP Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.creador_id' in 'on clause' in /var/www/html/bot/telegram/views/templates/list.php:27
|
||||
Stack trace:
|
||||
#0 /var/www/html/bot/telegram/views/templates/list.php(27): PDO->query()
|
||||
#1 {main}
|
||||
thrown in /var/www/html/bot/telegram/views/templates/list.php on line 27
|
||||
[29-Nov-2025 14:36:39 America/Mexico_City] PHP Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.creador_id' in 'on clause' in /var/www/html/bot/telegram/views/templates/list.php:27
|
||||
Stack trace:
|
||||
#0 /var/www/html/bot/telegram/views/templates/list.php(27): PDO->query()
|
||||
#1 {main}
|
||||
thrown in /var/www/html/bot/telegram/views/templates/list.php on line 27
|
||||
[29-Nov-2025 14:38:04 America/Mexico_City] PHP Warning: file_put_contents(/var/www/html/bot/shared/utils/../logs/telegram/templates.log): Failed to open stream: No such file or directory in /var/www/html/bot/shared/utils/helpers.php on line 40
|
||||
[29-Nov-2025 14:38:38 America/Mexico_City] PHP Warning: file_put_contents(/var/www/html/bot/shared/utils/../logs/telegram/templates.log): Failed to open stream: No such file or directory in /var/www/html/bot/shared/utils/helpers.php on line 40
|
||||
[29-Nov-2025 14:38:47 America/Mexico_City] PHP Warning: file_put_contents(/var/www/html/bot/shared/utils/../logs/telegram/templates.log): Failed to open stream: No such file or directory in /var/www/html/bot/shared/utils/helpers.php on line 40
|
||||
[29-Nov-2025 18:03:02 America/Mexico_City] PHP Warning: file_put_contents(/var/www/html/bot/shared/utils/../logs/telegram/templates.log): Failed to open stream: No such file or directory in /var/www/html/bot/shared/utils/helpers.php on line 40
|
||||
130
telegram/views/templates/preview.php
Executable file
130
telegram/views/templates/preview.php
Executable file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
require_once __DIR__ . '/../../../shared/database/connection.php';
|
||||
|
||||
// Verificar autenticación
|
||||
$userData = JWTAuth::requireAuth();
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
die('ID no proporcionado');
|
||||
}
|
||||
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare("SELECT * FROM plantillas_telegram WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$plantilla = $stmt->fetch();
|
||||
|
||||
if (!$plantilla) {
|
||||
die('Plantilla no encontrada');
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?php echo $userData->idioma ?? 'es'; ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vista Previa: <?php echo htmlspecialchars($plantilla['nombre']); ?></title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
background-color: #313338;
|
||||
color: #dbdee1;
|
||||
padding: 20px;
|
||||
margin: 0;
|
||||
line-height: 1.375rem;
|
||||
}
|
||||
|
||||
.telegram-message {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
background: #313338;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
font-size: 1rem;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
/* Estilos básicos para simular Telegram */
|
||||
strong { font-weight: 700; }
|
||||
em { font-style: italic; }
|
||||
u { text-decoration: underline; }
|
||||
|
||||
a {
|
||||
color: #00a8fc;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #2b2d31;
|
||||
padding: 2px;
|
||||
border-radius: 3px;
|
||||
font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier, monospace;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #2b2d31;
|
||||
border: 1px solid #1e1f22;
|
||||
border-radius: 4px;
|
||||
padding: 8px;
|
||||
margin: 6px 0;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
pre code {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0;
|
||||
padding: 0 0 0 4px;
|
||||
border-left: 4px solid #4e5058;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 4px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
h1, h2, h3 {
|
||||
margin: 8px 0;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
h1 { font-size: 1.5rem; }
|
||||
h2 { font-size: 1.25rem; }
|
||||
h3 { font-size: 1rem; }
|
||||
|
||||
ul, ol {
|
||||
margin: 8px 0;
|
||||
padding-left: 24px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="telegram-message">
|
||||
<div class="message-content">
|
||||
<?php echo $plantilla['contenido']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user