query("SELECT * FROM recurrent_messages ORDER BY name"); $templates = $stmt->fetchAll(); // Cargar imágenes de la galería $galleryPath = __DIR__ . '/galeria'; if (is_dir($galleryPath)) { $files = scandir($galleryPath); foreach ($files as $file) { if (in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), ['jpg', 'jpeg', 'png', 'gif', 'webp'])) { $galleryImages[] = $file; } } } } catch (Exception $e) { $error = $e->getMessage(); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if ($action === 'create') { $stmt = $pdo->prepare("INSERT INTO recurrent_messages (name, message_content, telegram_command, created_at, updated_at) VALUES (?, ?, ?, NOW(), NOW())"); $stmt->execute([ $_POST['name'], $_POST['message_content'], $_POST['telegram_command'] ?? null ]); logActivity(getCurrentUserId(), 'create_template', 'Plantilla creada: ' . $_POST['name']); header('Location: recurrentes.php'); exit; } elseif ($action === 'update') { $stmt = $pdo->prepare("UPDATE recurrent_messages SET name = ?, message_content = ?, telegram_command = ?, updated_at = NOW() WHERE id = ?"); $stmt->execute([ $_POST['name'], $_POST['message_content'], $_POST['telegram_command'] ?? null, $_POST['id'] ]); logActivity(getCurrentUserId(), 'update_template', 'Plantilla actualizada: ' . $_POST['name']); header('Location: recurrentes.php'); exit; } elseif ($action === 'delete') { $stmt = $pdo->prepare("DELETE FROM recurrent_messages WHERE id = ?"); $stmt->execute([$_POST['id']]); logActivity(getCurrentUserId(), 'delete_template', 'Plantilla eliminada ID: ' . $_POST['id']); header('Location: recurrentes.php'); exit; } } require_once __DIR__ . '/templates/header.php'; ?>
No hay plantillas creadas
Comando: #= htmlspecialchars($template['telegram_command'] ?? 'sin comando') ?>