Register  Login  
  July 29, 2010  
Search_Blog Minimize
Print  

Blog_Archive Minimize
Print  

Blog    
View_Blog Minimize
Aug 5

Written by: host
Wednesday, August 05, 2009 10:42 PM 

I have been working on skinning and playing with menus. Menus of empty pages.  I manually would create a structure and then work the skin and menu classes to define the look wanted. If you want a good tutorial on menus, see DNNCreative's #47 edition -- good stuff.  

But after creating these empty pages over and over ... I got thinking there must be a better way. I binged and googled (boogled it?) and found no hits, so it was time to play around in T-SQL again.

I developed a procedure called CreateEmptyPage that takes 3 paramters: the portalID, the Parent TabID, and the TabName. The procedure returned the newly created tabid. 

All aspects of the page are defaulted or set to open - for example the created page has "All Users" set to view.  The TabName is used for the Title, Description and Keywords.

No default Text/HTML module is added to the page as it is an Empty page.

Here is the procedure:


Create Procedure CreateEmptyPage
    @PortalID int,
    @ParentId int,
    @TabName  nvarchar(50)
as

set nocount on

Declare @TabID    int
Declare @IsVisible          bit
Declare @DisableLink        bit
Declare @IconFile           nvarchar(100)
Declare @Title              nvarchar(200)
Declare @Description        nvarchar(500)
Declare @KeyWords           nvarchar(500)
Declare @Url                nvarchar(255)
Declare @SkinSrc            nvarchar(200)
Declare @ContainerSrc       nvarchar(200)
Declare @TabPath            nvarchar(255)
Declare @StartDate          datetime
Declare @EndDate            datetime
Declare @RefreshInterval    int
Declare @PageHeadText     nvarchar(500)
Declare @IsSecure           bit
Declare @PermanentRedirect bit

if @ParentID = -1
  begin
    Set @ParentId = Null  -- int value or Null for Root
  end

set @TabID = 0  -- will be defined upon valid insert

Set @Title = @TabName
Set @Description = @TabName + ' created by CreateEmptyPage'
Set @Keywords = @TabName

Set @TabPath = '//' + @TabName

set @Url = ''
Set @IconFile = ''

set @SkinSrc = Null
set @ContainerSrc = Null
set @StartDate = Null
set @EndDate = Null
set @RefreshInterval = Null
set @PageHeadText = Null

Set @IsVisible = 1
Set @DisableLink = 0
set @IsSecure = 0
set @PermanentRedirect = 0

INSERT INTO dbo.Tabs (
  PortalId,
  TabName,
  IsVisible,
  DisableLink,
  ParentId,
  IconFile,
  Title,
  Description,
  KeyWords,
  IsDeleted,
  Url,
  SkinSrc,
  ContainerSrc,
  TabPath,
  StartDate,
  EndDate,
  RefreshInterval,
  PageHeadText,
  IsSecure,
  PermanentRedirect
 )
VALUES (
  @PortalId,
  @TabName,
  @IsVisible,
  @DisableLink,
  @ParentId,
  @IconFile,
  @Title,
  @Description,
  @KeyWords,
  0,
  @Url,
  @SkinSrc,
  @ContainerSrc,
  @TabPath,
  @StartDate,
  @EndDate,
  @RefreshInterval,
  @PageHeadText,
  @IsSecure,
  @PermanentRedirect
)

Set @TabID = (SELECT SCOPE_IDENTITY())

Declare @Temp nvarchar(255)
Declare @TabLevel int
Declare @TabOrder int

if @ParentID is not null
  begin
    set @Temp = (select TabPath from Tabs where TabID = @ParentID)
    if @temp is null set @Temp = ''
    set @TabPath = @Temp + '//' + @TabName
  end
else
  begin
    set @TabPath = '//' + @TabName
  end

set @TabLevel = 0
if @ParentID is not null
  begin
    set @TabLevel = (select [Level] from Tabs where TabID = @ParentID)
    if @TabLevel is null set @TabLevel = 0
    set @TabLevel = @TabLevel + 1
  end

set @TabOrder = (select Max(TabOrder) from Tabs where PortalID = @PortalID and Taborder < 10000 )
 
if @TabID > 0
  begin
    UPDATE dbo.Tabs
    SET  
      TabOrder = @TabOrder,
      [Level] = @TabLevel,
      ParentId = @ParentId,
      TabPath = @TabPath
    WHERE  TabId = @TabId
 
end

Declare @AllUsers int
Declare @Admins   int
Declare @View     int
Declare @Edit     int

Set @AllUsers = -1
Set @Admins = 0
Set @View = 3
Set @Edit = 4

if @TabID > 0
Begin
    INSERT INTO dbo.TabPermission ([TabID],[PermissionID],[RoleID],[AllowAccess],[UserID])
       VALUES (@TabID, @View, @Admins, 1,Null)
    INSERT INTO dbo.TabPermission ([TabID],[PermissionID],[RoleID],[AllowAccess],[UserID])
       VALUES (@TabID, @Edit, @Admins, 1,Null)
    INSERT INTO dbo.TabPermission ([TabID],[PermissionID],[RoleID],[AllowAccess],[UserID])
       VALUES (@TabID, @View, @AllUsers, 1,Null)
End

Return @TabID
GO

The procedure inserts a record into the Tabs table defining a Page and adds 3 records into the TabPermission table defining the User Access. 

And here is how I created a simple collection of pages. Page_1 and Page_3 are on the root as their ParentID's are -1.  Page_2 is under Page_1 and Page_4 and Page_5 are under Page_3.  Lastly, Page_6 is under Page_5.

declare @p1 int, @p2 int, @p3 int, @p4 int, @p5 int, @p6 int

exec @p1 = [dbo].[CreateEmptyPage] 0,  -1, 'Page_1'
exec @p2 = [dbo].[CreateEmptyPage] 0, @p1, 'Page_2'
exec @p3 = [dbo].[CreateEmptyPage] 0,  -1, 'Page_3'
exec @p4 = [dbo].[CreateEmptyPage] 0, @p3, 'Page_4'
exec @p5 = [dbo].[CreateEmptyPage] 0, @p3, 'Page_5'
exec @p6 = [dbo].[CreateEmptyPage] 0, @p5, 'Page_6'

select * from tabs where portalid = 0 and tabid > 75
go

Notice that I used the returned TabID to define the parent of certain pages.  You need to perform an Application Restart to clear the cached tabs otherwise you will not see the new pages for a while.

Lastly, if you need to remove the pages created by CreateEmptyPage you can use the following delete statements. The deletes use a string I placed in the Description to determine what pages to delete.  If you do add content to the pages, do not use these statements to remove the pages.

delete tabpermission where tabid in (select TabID from Tabs where [Description] like '%created by CreateEmptyPage%')
delete tabs          where tabid in (select TabID from Tabs where [Description] like '%created by CreateEmptyPage%')

At this point it's time to remind you that this works for me, your mileage may vary and if it causes problems for you ... ooops sorry.  I would only use the procedure on a test system and not in production until you are confident it does what you want.

Hope this helps,
Paul.

Tags:

1 comment(s) so far...

Re: Creating Emptiness ... or a Stored Proc to create empty pages.

Great job! Thanks.
www.pdfqueen.com

By Emerson on   Wednesday, December 16, 2009 8:55 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 

Blog_List Maximize
Print  

  Home | Blog | Forum | Subscriptions | Free Modules   Page generated in 0.0701008 seconds.
  Copyright 2010 by TressleWorks   Terms Of Use | Privacy Statement