Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT DISTINCT tb.* FROM (
- SELECT DISTINCT usuario.nome, sistema.* FROM usuario
- INNER JOIN usuario_unidade ON usuario_unidade.cpf_usuario = usuario.cpf
- INNER JOIN unidade ON unidade.id = usuario_unidade.id_unidade AND unidade.ativo = 'A'
- INNER JOIN unidade_sistema ON unidade_sistema.id_unidade = unidade.id
- INNER JOIN sistema ON sistema.id = unidade_sistema.id_sistema
- INNER JOIN sistema_menu_associacao ON sistema_menu_associacao.sistema_id = sistema.id AND sistema_menu_associacao.unidade_id = unidade.id
- INNER JOIN sistema_menu ON sistema_menu.id = sistema_menu_associacao.menu_id AND sistema_menu.ativo = TRUE
- WHERE usuario.cpf = '$cpf' AND usuario.senha = '$senha' AND NOT sistema.id IN (1, 6, 10, 16)
- AND EXISTS ( SELECT tb.* FROM
- DBLINK
- ( 'dbname='||sistema.banco_dados||'
- hostaddr=127.0.0.1
- user=postgres
- password=postgres
- port=5555'::text,
- 'SELECT cpf_usuario, id_empresa, id_menu FROM usuario_liberacao
- WHERE id_empresa = '||unidade.id::text
- ) AS tb ( cpf_usuario character varying(11),
- id_empresa integer,
- id_menu integer
- )
- INNER JOIN sistema_menu ON sistema_menu.id = tb.id_menu
- WHERE sistema_menu.sistema_id = sistema.id
- AND sistema.cliente <> 'S'
- AND tb.cpf_usuario = '$cpf'
- )
- UNION ALL
- SELECT usuario.nome, sistema.* FROM sistema
- INNER JOIN DBLINK
- ('dbname='||sistema.banco_dados||'
- hostaddr=127.0.0.1
- user=postgres
- password=postgres
- port=5555'::text,
- 'SELECT cpf, senha, nome FROM usuario_cliente'::text
- ) AS usuario ( cpf character varying(11),
- senha character varying(50),
- nome character varying(200))
- ON usuario.cpf = '06353864965' AND usuario.senha = 'Bud5029'
- WHERE (sistema.cliente = 'S' OR sistema.id IN (15)) AND NOT sistema.id IN (1, 6, 10, 16)
- ) AS tb
- ORDER BY tb.id ASC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement