IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_cstbrowse_md]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_cstbrowse_md]
GO
create procedure [dbo].[mps_g_cstbrowse_md](
@cmpid int,
@useradmin int,
@terminal int,
@useruid int,
@ctid int  
)
as
begin
set nocount on
select * from mps_csttype where ct_id=@ctid
select * from mps_template where tmp_cmpid=@cmpid  and tmp_type='cstbrow' and tmp_objid=@ctid 
select * from mps_csttype_users 
where cp_ctid=@ctid  and  cp_cuid=@useruid

declare @mdtag varchar(100) 
-- 扩展功能功能 t5 
set @mdtag='cstbrow' 
if (@terminal=0) 
begin
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin order by mn_order 
end  else 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=0 order by mn_order 
end 
end else 
begin
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=@useradmin)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=@useradmin order by mn_order 
end  else 
begin
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=0)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=0 order by mn_order 
end else 
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin order by mn_order 
end else 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=0 order by mn_order 
end 
end 
end
-- 选中后功能 t5 
set @mdtag='cstbrowslt' 
if (@terminal=0) 
begin
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin order by mn_order 
end  else 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=0 order by mn_order 
end 
end else 
begin
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=@useradmin)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=@useradmin order by mn_order 
end  else 
begin
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=0)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=1 and mn_roleid=0 order by mn_order 
end else 
if (exists (select 1 from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin)) 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=@useradmin order by mn_order 
end else 
begin
select * from mps_menu where mn_cmpid=@cmpid and mn_flag=@mdtag+convert(varchar(10),@ctid) and mn_terminal=0 and mn_roleid=0 order by mn_order 
end 
end 
end
set nocount off
end