spEvtCalView_IsSubCalManager

Parameters

Parameter Parameter Type Mode Description
@SiteContentID int IN
@ClientUsersID int IN

Definition

Copy


            CREATE    PROCEDURE [dbo].[spEvtCalView_IsSubCalManager]
            (
                @SiteContentID int,
                @ClientUsersID int
            )  
            AS 
            -- This function is useful only in two places: 
            --        Event Calendar Group part and Event Calendar Highlight part
            -- The @SiteContentID parameter belongs to 
            --        a sub-calendar of a calendar group part, or,
            --        a source calendar of a calendar highlight part
            -- returns a number > 0 when the user has management rights to this calendar

            BEGIN
                set nocount on
                declare @docHandle int
                declare @xmlDocument nvarchar(4000)
                declare @roles varchar(512)

                select @xmlDocument = (select convert(nvarchar(4000), XMLData) from dbo.sitecontent where id = @SiteContentID)
                EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlDocument

                SELECT @roles = Value FROM OPENXML(@docHandle, N'/XMLHashTable/ItemArray/Item', 2
                    WITH (Name nchar(30) '@Name', Value nchar(512)) 
                    WHERE Name = 'EventCalendarManagerRoles'
                -- got a string like this: ';166;163'    // those are ClientRolesID in UserRoles table

                EXEC sp_xml_removedocument @docHandle 

                -- build a table using the @roles id string above
                -- match this table of IDs against the user's roles IDs
                -- return a count of matching IDs
                -- if returning at least 1, we know that the user is a manager of this calendar
                SELECT ids.id from dbo.fnMakeIDsTableFromString(@roles, ';') ids 
                    LEFT JOIN dbo.UserRoles ur on ur.ClientRolesID = ids.id 
                    WHERE ur.ClientUsersID = @ClientUsersID 
                    OR ids.id = 162  -- everyone role
            END