54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* API - Obtener menús
|
|
* Fecha: 13 de noviembre de 2025
|
|
*/
|
|
|
|
require_once '../config/config.php';
|
|
|
|
// Verificar autenticación
|
|
requireAuthentication();
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
try {
|
|
$db = Database::getInstance();
|
|
|
|
$menus = $db->fetchAll(
|
|
"SELECT
|
|
id,
|
|
name,
|
|
title,
|
|
description,
|
|
parent_id,
|
|
is_root,
|
|
is_active,
|
|
order_position,
|
|
created_at,
|
|
updated_at
|
|
FROM menus
|
|
ORDER BY order_position ASC, title ASC"
|
|
);
|
|
|
|
// Obtener opciones de cada menú
|
|
foreach ($menus as &$menu) {
|
|
$options = $db->fetchAll(
|
|
"SELECT * FROM menu_options
|
|
WHERE menu_id = :menu_id
|
|
ORDER BY option_number ASC",
|
|
['menu_id' => $menu['id']]
|
|
);
|
|
$menu['options'] = $options;
|
|
}
|
|
|
|
echo json_encode($menus);
|
|
|
|
} catch (Exception $e) {
|
|
error_log("Error in get_menus.php: " . $e->getMessage());
|
|
http_response_code(500);
|
|
echo json_encode(['error' => 'Error interno del servidor']);
|
|
}
|
|
?>
|