Primer commit del sistema separado falta mejorar mucho
This commit is contained in:
64
telegram/api/templates/list.php
Executable file
64
telegram/api/templates/list.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* API de Plantillas de Telegram - Listar
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
require_once __DIR__ . '/../../../shared/database/connection.php';
|
||||
|
||||
// Para depuración
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Verificar autenticación
|
||||
if (!isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar permiso
|
||||
if (!hasPermission('view_templates', 'telegram')) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => 'No tienes permiso para ver las plantillas de Telegram.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$db = getDB();
|
||||
|
||||
// Búsqueda (opcional, para futuras mejoras)
|
||||
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
|
||||
|
||||
$sql = "
|
||||
SELECT p.id, p.nombre, p.comando, p.fecha_modificacion, u.username
|
||||
FROM plantillas_telegram p
|
||||
LEFT JOIN usuarios u ON p.usuario_id = u.id
|
||||
";
|
||||
|
||||
$params = [];
|
||||
if (!empty($search)) {
|
||||
$sql .= " WHERE p.nombre LIKE ? OR p.comando LIKE ?";
|
||||
$params[] = "%{$search}%";
|
||||
$params[] = "%{$search}%";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY p.fecha_modificacion DESC";
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$templates = $stmt->fetchAll();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'templates' => $templates
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
error_log('Error en /telegram/api/templates/list.php: ' . $e->getMessage());
|
||||
echo json_encode(['success' => false, 'error' => 'Error del servidor al obtener las plantillas.']);
|
||||
}
|
||||
Reference in New Issue
Block a user