DROP PROCEDURE [dbo].[Accordion]
GO

/****** Object:  StoredProcedure [dbo].[Accordion]    Script Date: 05/17/2013 17:55:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
==================================================
-- Autor:       Francis Antonio Bolaños Arias
-- Fecha:       27/02/2012 16:17:31
-- Descripción: Consultas de Cantones
-- @vOpcion: 0 = Todo,1 = Filtrado, 2 = Elemento, 
-- ===============================================
*/
CREATE PROCEDURE [dbo].[Accordion]
(
    @vIdUsuario INT,
    @vLangCode  VARCHAR(5)
)
AS

BEGIN

	IF @vIdUsuario = 0
	BEGIN

		SELECT     ac.IdOpcion,    ac.Icono, 
				   al.Descripcion, ac.Direccion, ac.Padre 
		FROM       SECUACCO ac 
		INNER JOIN SECUACCL al ON ac.IdOpcion = al.IdOpcion
		INNER JOIN SECULANG lg ON al.IdLang   = lg.IdLang
		WHERE lg.Codigo = @vLangCode
		ORDER BY CASE ac.Padre
					  WHEN 0 THEN ac.IdOpcion
					  ELSE ac.Padre
					  END, ac.Orden, al.Descripcion
	
	END
	ELSE
	BEGIN
		
		SELECT     -1 AS IdOpcion, 'user.png' AS Icono, 
				   'LblGENMyMenu' AS Descripcion, '' AS Direccion, 
				   0 AS Padre, -1 AS Orden
	    INTO #Menu
		UNION ALL
		SELECT     ac.IdOpcion,    ac.Icono, 
				   al.Descripcion, ac.Direccion, 
				   Padre = -1, au.Orden 
		FROM       SECUACCO ac 
		INNER JOIN SECUACCL al ON ac.IdOpcion = al.IdOpcion
		INNER JOIN SECULANG lg ON al.IdLang   = lg.IdLang
		INNER JOIN SECUACCU au ON ac.IdOpcion = au.IdOpcion
		WHERE lg.Codigo     = @vLangCode AND
		      au.IdOperador = @vIdUsuario
		--ORDER BY ac.Orden, al.Descripcion
		
		SELECT * FROM #Menu ORDER BY Orden, Descripcion
		
	END
    
END

--select * from SECUACCO