ALTER TABLE {databaseOwner}{objectQualifier}DMX_Entries ADD
 [Thumbnail] VARCHAR (200),
 [Hidden] BIT
GO

UPDATE {databaseOwner}{objectQualifier}DMX_Entries
SET Hidden=0
GO

IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}DMX_AddEntry') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_AddEntry
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_AddEntry
 @Author NVARCHAR (500),
 @CollectionId INT,
 @Deleted BIT,
 @Entry NVARCHAR (2000),
 @EntryType NVARCHAR (150),
 @FileSize BIGINT,
 @Created DATETIME,
 @IsApproved BIT,
 @Keywords NVARCHAR (255),
 @LastModified DATETIME,
 @LastVersionId INT,
 @LockedBy INT,
 @LockedUntil DATETIME,
 @LockKey UNIQUEIDENTIFIER,
 @MD5Hash NVARCHAR (50),
 @OriginalFileName NVARCHAR (255),
 @Owner INT,
 @PortalId INT,
 @State NVARCHAR (50),
 @Version INT,
 @VersionsToKeep INT,
 @WorkflowId NVARCHAR (50),
 @Path VARCHAR (4000),
 @PermissionsOnlyByAdmin BIT,
 @InheritAttributes BIT,
 @StorageProviderID INT,
 @Thumbnail VARCHAR (200),
 @Hidden BIT
AS

INSERT INTO {databaseOwner}{objectQualifier}DMX_Entries (
 [Author],
 [CollectionId],
 [Deleted],
 [Entry],
 [EntryType],
 [FileSize],
 [Created],
 [IsApproved],
 [Keywords],
 [LastModified],
 [LastVersionId],
 [LockedBy],
 [LockedUntil],
 [LockKey],
 [MD5Hash],
 [OriginalFileName],
 [Owner],
 [PortalId],
 [State],
 [Version],
 [VersionsToKeep],
 [WorkflowId],
 [Path],
 [PermissionsOnlyByAdmin],
 [InheritAttributes],
 [StorageProviderID],
 [Thumbnail],
 [Hidden]
)
 VALUES (

 @Author,
 @CollectionId,
 @Deleted,
 @Entry,
 @EntryType,
 @FileSize,
 @Created,
 @IsApproved,
 @Keywords,
 @LastModified,
 @LastVersionId,
 @LockedBy,
 @LockedUntil,
 @LockKey,
 @MD5Hash,
 @OriginalFileName,
 @Owner,
 @PortalId,
 @State,
 @Version,
 @VersionsToKeep,
 @WorkflowId,
 @Path,
 @PermissionsOnlyByAdmin,
 @InheritAttributes,
 @StorageProviderID,
 @Thumbnail,
 @Hidden
)


select SCOPE_IDENTITY()
GO


IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}DMX_UpdateEntry') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_UpdateEntry
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_UpdateEntry
 @EntryId INT,
 @Author NVARCHAR (500),
 @CollectionId INT,
 @Deleted BIT,
 @Entry NVARCHAR (2000),
 @EntryType NVARCHAR (150),
 @FileSize BIGINT,
 @Created DATETIME,
 @IsApproved BIT,
 @Keywords NVARCHAR (255),
 @LastModified DATETIME,
 @LastVersionId INT,
 @LockedBy INT,
 @LockedUntil DATETIME,
 @LockKey UNIQUEIDENTIFIER,
 @MD5Hash NVARCHAR (50),
 @OriginalFileName NVARCHAR (255),
 @Owner INT,
 @PortalId INT,
 @State NVARCHAR (50),
 @Version INT,
 @VersionsToKeep INT,
 @WorkflowId NVARCHAR (50),
 @Path VARCHAR (4000),
 @PermissionsOnlyByAdmin BIT,
 @InheritAttributes BIT,
 @StorageProviderID INT,
 @Thumbnail VARCHAR (200),
 @Hidden BIT
AS

UPDATE {databaseOwner}{objectQualifier}DMX_Entries SET
 [Author] = @Author,
 [CollectionId] = @CollectionId,
 [Deleted] = @Deleted,
 [Entry] = @Entry,
 [EntryType] = @EntryType,
 [FileSize] = @FileSize,
 [Created] = @Created,
 [IsApproved] = @IsApproved,
 [Keywords] = @Keywords,
 [LastModified] = @LastModified,
 [LastVersionId] = @LastVersionId,
 [LockedBy] = @LockedBy,
 [LockedUntil] = @LockedUntil,
 [LockKey] = @LockKey,
 [MD5Hash] = @MD5Hash,
 [OriginalFileName] = @OriginalFileName,
 [Owner] = @Owner,
 [PortalId] = @PortalId,
 [State] = @State,
 [Version] = @Version,
 [VersionsToKeep] = @VersionsToKeep,
 [WorkflowId] = @WorkflowId,
 [Path] = @Path,
 [PermissionsOnlyByAdmin] = @PermissionsOnlyByAdmin,
 [InheritAttributes] = @InheritAttributes,
 [StorageProviderID] = @StorageProviderID,
 [Thumbnail] = @Thumbnail,
 [Hidden] = @Hidden
WHERE
 [EntryId] = @EntryId
GO


IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{objectQualifier}DMX_GetEntryBranch') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_GetEntryBranch
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_GetEntryBranch
	@PortalId INT,
	@EntryId INT,
	@AllVersions BIT,
 @IncludeSelf BIT,
	@Locale NVARCHAR(6)
AS

EXEC {databaseOwner}{objectQualifier}DMX_UpdatePaths @PortalId, @EntryId;

DECLARE @Path VARCHAR(4000)
SELECT @Path=[Path] FROM {databaseOwner}{objectQualifier}DMX_Entries WHERE EntryId=@EntryID AND PortalId=@PortalID;

SELECT e.*, ISNULL(stLoc.[Text], stDef.[Text]) Title, ISNULL(ltLoc.[Text], ltDef.[Text]) Remarks
FROM {databaseOwner}{objectQualifier}DMX_Entries e
 LEFT JOIN {databaseOwner}{objectQualifier}DMX_ShortTexts stDef ON e.EntryId=stDef.ObjectId AND stDef.TypeKey='ENT' AND stDef.SubTypeKey='TITLE' AND stDef.Locale=''
 LEFT JOIN {databaseOwner}{objectQualifier}DMX_ShortTexts stLoc ON e.EntryId=stLoc.ObjectId AND stLoc.TypeKey='ENT' AND stLoc.SubTypeKey='TITLE' AND stLoc.Locale=@Locale
 LEFT JOIN {databaseOwner}{objectQualifier}DMX_LongTexts ltDef ON e.EntryId=ltDef.ObjectId AND ltDef.TypeKey='ENT' AND ltDef.SubTypeKey='REMARKS' AND ltDef.Locale=''
 LEFT JOIN {databaseOwner}{objectQualifier}DMX_LongTexts ltLoc ON e.EntryId=ltLoc.ObjectId AND ltLoc.TypeKey='ENT' AND ltLoc.SubTypeKey='REMARKS' AND ltLoc.Locale=@Locale
WHERE ((e.[Path] LIKE @Path+'%') OR (e.LastVersionId=@EntryId AND @AllVersions=1 AND @IncludeSelf=1))
 AND (@IncludeSelf=1 OR (NOT e.[Path]=@Path))
 AND (e.Version=(SELECT MAX(Version) FROM {databaseOwner}{objectQualifier}DMX_Entries e2 WHERE e2.LastVersionId=e.LastVersionId) OR @AllVersions=1)
GO

IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}DMX_SetEntryThumbnail') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_SetEntryThumbnail
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_SetEntryThumbnail
 @PortalId INT,
 @EntryId INT,
 @Thumbnail VARCHAR(200)
AS

UPDATE {databaseOwner}{objectQualifier}DMX_Entries
SET Thumbnail = @Thumbnail
WHERE PortalId = @PortalId
 AND EntryId = @EntryId
GO

INSERT INTO {databaseOwner}{objectQualifier}DMX_Extensions ([AccessRights], [Addon], [ControlToLoad], [Custom], [EntryTypes], [ExtensionKey], [IsPrivate], [PortalId], [ResourceFile])
SELECT '-1;', 'Core', 'Bring2mind.DNN.Modules.DMX.Services.Thumbnails.ThumbnailController, BRING2MIND.DNN.MODULES.DMX.CORE', '0', 'File.Jpg;File.Png;File.Tiff;File.Gif;File.Bmp;', 'EntryProcessor.Thumbnail.Core', 0, p.PortalId, 'DesktopModules/Bring2mind/DMX/App_LocalResources/SharedResources'
FROM {databaseOwner}{objectQualifier}Portals p
GO

