SELECT
IF(s.id_permiso IS NULL, 'NO', s.id_permiso) AS id_permiso,
IF(s.id_usuario IS NULL, CONCAT('$LL','AVE'), s.id_usuario) AS id_usuario,
m.id_menu AS id_menu,
(SELECT nombre FROM sys_menus WHERE id_menu=m.menu_padre),
m.nombre AS nombre_permiso,
IF(s.ver IS NULL, 0, s.ver) AS ver,
IF(s.modificar IS NULL, 0, s.modificar) AS modificar,
IF(s.eliminar IS NULL, 0, s.eliminar) AS eliminar,
IF(s.nuevo IS NULL, 0, s.nuevo) AS nuevo,
IF(s.imprimir IS NULL, 0, s.imprimir) AS imprimir,
IF(s.generar IS NULL, 0, s.generar) AS generar
FROM sys_menus m
LEFT JOIN sys_permisos s ON m.id_menu = s.id_menu AND s.id_usuario='$llave'
WHERE m.en_permisos = 1
AND m.id_menu != m.menu_padre
AND m.menu_padre > 0
