<cfif form.Type EQ "Patch">
	<cfinclude template="patch_15.5.01.cfm">
</cfif>

<cfquery datasource="#application.config.DSN#" name="qryAppVersion">
    SELECT Top 1 Value
    FROM Appsetting
    WHERE Name = 'Version'
</cfquery>


<!--- Beginning of new kudo app. Only run code if version lower than 15.5.2 --->
<cfif qryAppVersion.Value EQ "15.5.0" OR qryAppVersion.Value EQ "15.5.1" >

    <!--- Case RR-2463 - Employee Recognition Photos in Widget --->
    <cftransaction>
    <cfquery datasource="#application.config.DSN#" name="createWidgetPhotoFields">
            IF NOT EXISTS (
            SELECT
                *
            FROM
                INFORMATION_SCHEMA.COLUMNS
            WHERE
                TABLE_NAME = 'Widget' AND COLUMN_NAME = 'ShowEmployeePhoto')
            BEGIN
                ALTER TABLE Widget ADD ShowEmployeePhoto bit NULL CONSTRAINT D_Widget_ShowEmployeePhoto DEFAULT (0)
            END

            IF NOT EXISTS (
            SELECT
                *
            FROM
                INFORMATION_SCHEMA.COLUMNS
            WHERE
                TABLE_NAME = 'AppbuilderFields' AND COLUMN_NAME = 'EmployeeWidgetPictureOn')
            BEGIN
                ALTER TABLE AppbuilderFields ADD EmployeeWidgetPictureOn bit NULL CONSTRAINT D_AppbuilderFields_EmployeeWidgetPictureOn DEFAULT (0)
            END

    </cfquery>
    </cftransaction>

    <!--- Case RR-2463 - Create Employee Recognition App template --->
    <cftransaction>
    <cfquery datasource="#application.config.DSN#" name="qryFirstAdmin">
        SELECT TOP 1 UserId
        FROM UserProfile
        WHERE Administrator = 1
    </cfquery>

    <cfquery datasource="#application.config.DSN#" name="qryNewKudoAppID">

    INSERT [Asset] ([AssetTypeID], [ParentSiteID], [Title], [Description], [Icon], [CreatedDate], [CreatedByID], [ModifiedDate], [ModifiedByID], [DisplayTitle], [HeaderGraphic], [HeaderGraphicHeight], [HeaderGraphicWidth], [InMenu])
    VALUES (2, 1,'Employee Kudos', N'Have your employees recognize and celebrate their colleagues on your intranet. ', N'trophypicture.png', GETDATE(), <cfqueryparam value="#qryFirstAdmin.UserId#" cfsqltype="cf_sql_integer">, NULL, NULL, 1, NULL, NULL, NULL, 0)
    SELECT SCOPE_IDENTITY() AS Value

    </cfquery>

    <cfquery datasource="#application.config.DSN#" name="qryNewKudoAppSQLDependencies">

    INSERT [Application] ([AppID], [AppTypeID], [Template], [Disabled], [AppFolder], [FilesFolder], [FileLinkTarget], [DefaultView], [CleanUp], [HasCollection], [TableName1], [TableName2], [TableName3], [TableName4], [TableName5], [TableName6], [TableName7], [TableName8], [TableName9], [ShowFolderTree], [FolderItemCount], [FolderSubFolderCount], [CategoryColumns], [SubCategoryColumns], [SubCategoryThreshold], [CategoryPageInfo], [CategoryPageGraphic], [CategoryPageAlign], [CategoryPageWidth], [Pagination], [PaginationType], [PaginationLocation], [PaginationPageSetCount], [PaginationItemsPerPage], [AdvertiseArchiveDays], [AdvertiseGraphic], [AdvertiseThumbnail], [AdvertiseDefaultNow], [Add_Allowed], [Updating_Allowed], [Deleting_Allowed], [Password], [ADNumber]) 
    VALUES (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 31, 1, 0, N'Apps', N'', N'_blank', NULL, 0, 0, N'AppbuilderData', N'AppbuilderCategories', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, 0, NULL, 4, 40, N'0', N'0', N'top', N'25%', 0, 1, NULL, NULL, 25, 7, NULL, 0, 0, 0, 0, 0, NULL, NULL)

    INSERT [AppbuilderSettings] ([MenuID], [ShowTitle], [ShowHeader], [ShowAppDesc], [LandingPageDisplay], [LayoutCategoryType], [Versioning], [Description], [LayoutSearchType], [WidgetColumnWidth], [HideWarning], [PushDescToAllPages], [PushDescOverrideFolderDesc], [FormFieldLabelWidth], [FormFieldLabelWidthType], [ReadConfirmation], [GroupByFolder], [ArchiveNotification], [ArchiveItemDays]) 
    VALUES (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 1, 1, 1, 3, 1, 0, N'', 1, 250, 0, 0, 0, 25, 2, NULL, 0, 1, 7)

    INSERT [AppbuilderLanguage] ([MenuID], [LTree], [LFolders], [LFolder], [LAnonymous], [LSelectAFolder], [LSubfolder], [LSubfolders], [LFiles], [LVersioning], [LLinkAddress], [LLinkText], [LFileName], [LFileDesc], [LAttachFile], [LVersionStatus], [LVersion], [LHistory], [LCheckIn], [LCheckOut], [LCheckedOutBy], [LUploadNewVersion], [LVersioningIsOn], [LVersionNotes], [LVersionNumber], [LCurrent], [LArchives], [LAllItems], [LRevised], [LRevisedBy], [LLastEdited], [LDetails], [LRatings], [LTitle], [LOneLineDesc], [LCreatedBy], [LCreatedDate], [LModifiedBy], [LModifiedDate], [LGraphic], [LArchiveDate], [LPublishDate], [LFileUpload], [LFileSize], [LFileType], [LKeywords], [LThisIsAFileUpload], [LALinkWasEntered], [LCustomFields], [LSystemFields], [LReadConfirmedAgreement], [LReviewDate]) 
    VALUES (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 'Home', 'Folders', 'Folder', 'Anonymous', 'Select A Folder', 'Subfolder', 'Subfolders', 'Items', 'Versioning', 'Link Address', 'Link Text', 'File Name', 'File Desc', 'Attach File', 'Version Status', 'Version', 'History', 'Check In', 'Check Out', 'Checked Out By', 'Upload New Version', 'Versioning Is On', 'File Version Notes', 'File Version', 'Current', 'Archives', 'All Items', 'Revised', 'Revised By', 'Last Edited', 'Details', 'Ratings', 'Title', 'Short Description', 'Created By', 'Created Date', 'Modified By', 'Modified Date', 'Graphic', 'Archive Date', 'Publish Date', 'File Upload', 'File Size', 'File Type', 'Keywords', 'This is a file upload', 'A link was entered', 'Custom Fields', 'System Fields', 'I confirm I have read this item', 'Review Date')

    IF EXISTS(SELECT * FROM sys.tables WHERE name = 'AppbuilderData#qryNewKudoAppID.Value#')
    BEGIN
        DROP TABLE [AppbuilderData#qryNewKudoAppID.Value#]
    END

    CREATE TABLE [AppbuilderData#qryNewKudoAppID.Value#]
    (
    [ID] [int] NOT NULL IDENTITY(1, 1),
    [Title] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [OneLineDesc] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [CategoryID] [int] NULL,
    [Creator] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [UserID] [int] NULL,
    [EditUserID] [int] NULL,
    [DateEntered] [datetime] NULL,
    [DateModified] [datetime] NULL,
    [Keywords] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Post] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [ArchiveDate] [datetime] NULL,
    [ArchiveNotification] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [PublishDate] [datetime] NULL,
    [FileUploadID] [int] NULL,
    [VersionStatus] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [GraphicID] [int] NULL,
    [CreatedByAnonName] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [CreatedByAnonEmail] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [ReadConfirmation] [int] NULL,
    [ReviewDate] [datetime] NULL,
    [ReviewDateComment] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [WorkflowSetIDInstance] [int] NULL
    )

    IF EXISTS(SELECT * FROM sys.tables WHERE name = 'AppbuilderCategories#qryNewKudoAppID.Value#')
    BEGIN
        DROP TABLE [AppbuilderCategories#qryNewKudoAppID.Value#]
    END

    CREATE TABLE [AppbuilderCategories#qryNewKudoAppID.Value#]
    (
    [CategoryID] [int] NOT NULL IDENTITY(1, 1),
    [Category] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [ShortDesc] [varchar] (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Advertise] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [ParentID] [int] NULL,
    [ArchiveUserToggle] [int] NULL,
    [ArchiveDefaultUnchecked] [int] NULL,
    [WorkflowSetIDTemplate] [int] NULL
    )

    INSERT [AssetSocialSettings] ([AssetID], [Comments], [CommentsModerator], [CommentsAnonymous], [CommentsPublic], [CommentsAlwaysShow], [ThumbsUp], [ThumbsDown], [ThumbsAnonymous], [ThumbsPublic], [Tags], [TagsPublisherAdd], [TagsInTables]) 
    VALUES (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 1, N'', 0, 1, 0, 1, 0, 0, 1, 1, 1, 1)

    INSERT [AppbuilderFields] ([MenuID], [Label], [SortOrder], [FieldTypeID], [FieldTypeName], [Size], [MaxChars], [Width], [Height], [Cols], [Rows], [DropdownID], [ShowTime], [CalDefaultAddDays], [Regex], [Required], [Disabled], [Searchable], [Hidden], [DisplaySortOrder], [DisplaySortDirection], [SearchSortOrder], [SearchSortDirection], [Deleted], [FieldHint], [EmployeeNotify], [EmployeeNotifyMsg], [EmployeeNotifyMsgEditable], [EmployeeWidgetPictureOn])
    VALUES 
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 'Employee', 170, 14, 'employee', NULL, NULL, 150, NULL, NULL, NULL, NULL, NULL, NULL, '', 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, '[The person receiving the kudo]', NULL, NULL, NULL, 1),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 'Brief', 10, 50, 'brief', 40, 250, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', 1, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, '', NULL, 0),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 'Short Story', 20, 51, 'summary', NULL, 350, NULL, NULL, 50, 3, NULL, NULL, NULL, '', 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, '', NULL, 0),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 'Nominated By', 60, 52, 'nominated by', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, '', NULL, 0),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 'Created Date', 9999, 53, 'createdDate', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, '', NULL, '', NULL, 0)

    INSERT [AppbuilderFields] ([MenuID], [Label], [SortOrder], [FieldTypeID], [FieldTypeName], [Size], [MaxChars], [Width], [Height], [Cols], [Rows], [DropdownID], [ShowTime], [CalDefaultAddDays], [Regex], [Required], [Disabled], [Searchable], [Hidden], [DisplaySortOrder], [DisplaySortDirection], [SearchSortOrder], [SearchSortDirection], [Deleted], [FieldHint], [EmployeeNotify], [EmployeeNotifyMsg], [EmployeeNotifyMsgEditable], [LinkType], [LinkFieldID], [EmployeeNotifySubj], [EmployeeWidgetPictureOn]) 
    VALUES 
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, N'Tags', 9999, 63, N'tags', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, N'', NULL, N'', NULL, NULL, NULL, NULL, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, N'Ratings', 9999, 64, N'ratings', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, N'', NULL, N'', NULL, NULL, NULL, NULL, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, N'Comments', 9999, 68, N'comments', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, N'', NULL, N'', NULL, NULL, NULL, NULL, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, N'Modified By', 9999, 54, N'modifiedBy', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, N'', NULL, N'', NULL, NULL, NULL, NULL, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, N'Modified Date', 9999, 55, N'modifiedDate', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, N'', NULL, N'', NULL, NULL, NULL, NULL, NULL)

    INSERT [AppbuilderLayouts] ([MenuID], [LayoutPageID], [LayoutTypeID], [ShowBorder], [SnapToGrid], [Collapsed], [ColumnWidthType], [LabelWidth], [TitleHeader], [BorderPadding], [NoBorderPadding], [BorderGroupPadding], [NoBorderGroupPadding], [TruncateCharsDefault]) 
    VALUES 
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 1, 1, 0, 0, NULL, NULL, 150, 0, 10, 5, 2, 1, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 2, 2, 1, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 3, 1, 1, 0, 0, 2, 0, 0, NULL, NULL, NULL, NULL, NULL),
    (<cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">, 2, 1, 1, NULL, 0, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

    </cfquery>

    <cfquery datasource="#application.config.DSN#" name="qrynewAppFields">

    SELECT FieldID, FieldTypeID
    FROM AppbuilderFields
    WHERE MenuID = <cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">

    </cfquery>

    <cfquery datasource="#application.config.DSN#" name="qrynewLayouts">

    SELECT LayoutID, LayoutTypeID, LayoutPageID
    FROM AppbuilderLayouts
    WHERE MenuID = <cfqueryparam value="#qryNewKudoAppID.Value#" cfsqltype="cf_sql_integer">

    </cfquery>

    <cfloop query="qrynewLayouts">
        <cfif qrynewLayouts.LayoutTypeID EQ 1 AND qrynewLayouts.LayoutPageID EQ 1>
            <cfloop query="qrynewAppFields">
                <cfswitch expression="#qrynewAppFields.FieldTypeID#">
                    <cfcase value="14"> <!--- Employee --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 1, 1, 0, 0, 1, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="50"> <!--- Title / Brief --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 2, 1, 1, 0, 0, 1, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="51"> <!--- Summary --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 3, 1, 1, 0, 0, 1, NULL, 1, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="52"> <!--- Given By --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">,  4, 2, 1, 0, 0, 1, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="64"> <!--- Ratings --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime]) 
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 4, 1, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="68"> <!--- Comments --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime]) 
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 4, 1, 2, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                </cfswitch>
            </cfloop>
        <cfelseif qrynewLayouts.LayoutTypeID EQ 2 AND qrynewLayouts.LayoutPageID EQ 2>
                <cfloop query="qrynewAppFields">
                <cfswitch expression="#qrynewAppFields.FieldTypeID#">
                    <cfcase value="14"> <!--- Employee --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 3, 1, 1, 0, 0, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="50"> <!--- Title / Brief --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">,  1, 1, 1, 1, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
                        </cfquery>
                    </cfcase>
                    <cfcase value="51"> <!--- Summary --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">,  2, 1, 1, 0, 1, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="52"> <!--- Given By --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 4, 1, 1, 0, 0, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="64"> <!--- Ratings --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime]) 
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 5, 1, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="68"> <!--- Comments --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime]) 
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 6, 1, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                </cfswitch>
            </cfloop>
        <cfelseif qrynewLayouts.LayoutTypeID EQ 1 AND qrynewLayouts.LayoutPageID EQ 3>
                <cfloop query="qrynewAppFields">
                <cfswitch expression="#qrynewAppFields.FieldTypeID#">
                    <cfcase value="14"> <!--- Employee --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 1, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="50"> <!--- Title / Brief --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 2, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="51"> <!--- Summary --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 3, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="52"> <!--- Given By --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 4, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                </cfswitch>
            </cfloop>
        <cfelseif qrynewLayouts.LayoutTypeID EQ 1 AND qrynewLayouts.LayoutPageID EQ 2>
            <cfloop query="qrynewAppFields">
                <cfswitch expression="#qrynewAppFields.FieldTypeID#">
                    <cfcase value="14"> <!--- Employee --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 1, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="50"> <!--- Title / Brief --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 2, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="51"> <!--- Summary --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 3, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="52"> <!--- Given By --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime])
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 4, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="64"> <!--- Ratings --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime]) 
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 5, 1, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                    <cfcase value="68"> <!--- Comments --->
                        <cfquery datasource="#application.config.DSN#">
                        INSERT [AppbuilderLayoutFields] ([LayoutID], [FieldID], [FieldRow], [FieldColumn], [SortOrder], [HideLabel], [BoldLabel], [HideFieldNoData], [MaxChars], [ShowContentUnder], [ColumnWidthPixel], [ColumnWidthPercent], [HighlightLabel], [GraphicMaxWidth], [GraphicMaxHeight], [GraphicAlign], [ShowLinkAsIcon], [ShowLabelLinkOnly], [ShowTime]) 
                        VALUES (<cfqueryparam value="#qrynewLayouts.LayoutID#" cfsqltype="cf_sql_integer">, <cfqueryparam value="#qrynewAppFields.FieldID#" cfsqltype="cf_sql_integer">, 1, 5, 2, 1, NULL, NULL, NULL, NULL, 150, 25, NULL, NULL, NULL, NULL, 0, 0, 0)
                        </cfquery>
                    </cfcase>
                </cfswitch>
            </cfloop>
        </cfif>
    </cfloop>
    </cftransaction>

</cfif>
<!--- End of New Kudo App --->