305 lines
9.7 KiB
PHP
Executable File
305 lines
9.7 KiB
PHP
Executable File
<?php
|
|
session_start();
|
|
|
|
// Habilitar logging para depuración
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
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 la página de comandos
|
|
if (!hasPermission('view_commands', 'telegram')) {
|
|
die('No tienes permiso para ver los comandos de Telegram.');
|
|
}
|
|
|
|
$db = getDB();
|
|
|
|
// Obtener comandos (plantillas con comando asignado)
|
|
$stmt = $db->query("
|
|
SELECT id, nombre, comando, fecha_creacion
|
|
FROM plantillas_telegram
|
|
WHERE comando IS NOT NULL AND comando != ''
|
|
ORDER BY comando ASC
|
|
");
|
|
$comandos = $stmt->fetchAll();
|
|
?>
|
|
<!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>Comandos 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);
|
|
}
|
|
|
|
.table-responsive {
|
|
overflow-x: auto;
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
|
|
th {
|
|
font-weight: 600;
|
|
color: #555;
|
|
background: #f8f9fa;
|
|
}
|
|
|
|
.command-tag {
|
|
background: #2b2d31;
|
|
color: #dbdee1;
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
font-family: monospace;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.btn {
|
|
padding: 10px 20px;
|
|
border-radius: 8px;
|
|
text-decoration: none;
|
|
transition: all 0.2s;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
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-danger {
|
|
background: #dc3545;
|
|
color: white;
|
|
padding: 5px 10px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.btn-edit {
|
|
background: #ffc107;
|
|
color: #212529;
|
|
padding: 5px 10px;
|
|
font-size: 12px;
|
|
margin-right: 5px;
|
|
}
|
|
|
|
/* Modal */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
z-index: 1000;
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
.modal-content {
|
|
background: white;
|
|
margin: 10% auto;
|
|
padding: 30px;
|
|
border-radius: 15px;
|
|
width: 90%;
|
|
max-width: 600px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.form-control {
|
|
width: 100%;
|
|
padding: 10px;
|
|
border: 2px solid #eee;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.close {
|
|
float: right;
|
|
font-size: 24px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1><i class="fas fa-terminal"></i> Comandos Telegram</h1>
|
|
<div style="display: flex; gap: 10px;">
|
|
<a href="/telegram/dashboard_telegram.php" class="btn btn-secondary">
|
|
<i class="fas fa-arrow-left"></i> Volver
|
|
</a>
|
|
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
|
<a href="/telegram/views/templates/create.php" class="btn btn-primary">
|
|
<i class="fas fa-plus"></i> Nuevo Comando (Plantilla)
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="card">
|
|
<?php if (empty($comandos)): ?>
|
|
<div style="text-align: center; padding: 40px; color: #666;">
|
|
<i class="fas fa-terminal" style="font-size: 48px; margin-bottom: 20px; color: #ddd;"></i>
|
|
<h3>No hay comandos configurados</h3>
|
|
<p>Los comandos se definen al crear o editar una plantilla.</p>
|
|
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
|
<a href="/telegram/views/templates/create.php" class="btn btn-primary" style="margin-top: 10px;">
|
|
Ir a Plantillas
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Comando</th>
|
|
<th>Plantilla Asociada</th>
|
|
<th>Fecha Creación</th>
|
|
<th>Acciones</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($comandos as $cmd): ?>
|
|
<tr>
|
|
<td>
|
|
<span class="command-tag"><?php echo htmlspecialchars($cmd['comando']); ?></span>
|
|
</td>
|
|
<td>
|
|
<i class="fas fa-file-alt"></i> <?php echo htmlspecialchars($cmd['nombre']); ?>
|
|
</td>
|
|
<td>
|
|
<?php echo date('d/m/Y', strtotime($cmd['fecha_creacion'])); ?>
|
|
</td>
|
|
<td>
|
|
<?php if (hasPermission('manage_templates', 'telegram')): ?>
|
|
<a href="/telegram/views/templates/edit.php?id=<?php echo $cmd['id']; ?>" class="btn btn-edit">
|
|
<i class="fas fa-edit"></i> Editar
|
|
</a>
|
|
<button onclick="deleteCommand(<?php echo $cmd['id']; ?>, '<?php echo htmlspecialchars($cmd['comando'], ENT_QUOTES); ?>')" class="btn btn-danger">
|
|
<i class="fas fa-trash"></i> Eliminar
|
|
</button>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Scripts eliminados ya que no se necesita modal local -->
|
|
|
|
<script>
|
|
async function deleteCommand(templateId, commandName) {
|
|
if (!confirm(`¿Estás seguro de eliminar el comando "${commandName}"? Esto eliminará también la plantilla asociada.`)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/telegram/api/templates/delete.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ id: templateId })
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
alert('Comando y plantilla eliminados correctamente.');
|
|
location.reload(); // Recargar la página para actualizar la lista
|
|
} else {
|
|
alert('Error al eliminar el comando: ' + (result.error || 'Error desconocido.'));
|
|
}
|
|
} catch (error) {
|
|
console.error('Error al enviar la solicitud de eliminación:', error);
|
|
alert('Error de conexión al intentar eliminar el comando.');
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|