//
        //====================================================================================================
        //
        public static string get(CoreController core)
        {
            string result = "";

            try {
                string Button = core.docProperties.getText("Button");
                if (Button == ButtonCancelAll)
                {
                    //
                    // Cancel to the admin site
                    return(core.webServer.redirect(core.appConfig.adminRoute, "Tools-List, cancel button"));
                }
                //
                const string RequestNameAddField     = "addfield";
                const string RequestNameAddFieldId   = "addfieldID";
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                Stream.add(AdminUIController.getHeaderTitleDescription("Configure Admin Listing", "Configure the Administration Content Listing Page."));
                //
                //   Load Request
                int    ToolsAction          = core.docProperties.getInteger("dta");
                int    TargetFieldID        = core.docProperties.getInteger("fi");
                int    ContentId            = core.docProperties.getInteger(RequestNameToolContentId);
                string FieldNameToAdd       = GenericController.toUCase(core.docProperties.getText(RequestNameAddField));
                int    FieldIDToAdd         = core.docProperties.getInteger(RequestNameAddFieldId);
                string ButtonList           = ButtonCancel + "," + ButtonSelect;
                bool   ReloadCDef           = core.docProperties.getBoolean("ReloadCDef");
                bool   AllowContentAutoLoad = false;
                //
                //--------------------------------------------------------------------------------
                // Process actions
                //--------------------------------------------------------------------------------
                //
                if (ContentId != 0)
                {
                    ButtonList = ButtonCancel + "," + ButtonSaveandInvalidateCache;
                    string ContentName = Local_GetContentNameByID(core, ContentId);
                    Processor.Models.Domain.ContentMetadataModel CDef = Processor.Models.Domain.ContentMetadataModel.create(core, ContentId, false, true);
                    string FieldName        = null;
                    int    ColumnWidthTotal = 0;
                    int    fieldId          = 0;
                    if (ToolsAction != 0)
                    {
                        //
                        // Block contentautoload, then force a load at the end
                        //
                        AllowContentAutoLoad = (core.siteProperties.getBoolean("AllowContentAutoLoad", true));
                        core.siteProperties.setProperty("AllowContentAutoLoad", false);
                        int    SourceContentId = 0;
                        string SourceName      = null;
                        //
                        // Make sure the FieldNameToAdd is not-inherited, if not, create new field
                        //
                        if (FieldIDToAdd != 0)
                        {
                            foreach (var keyValuePair in CDef.fields)
                            {
                                Processor.Models.Domain.ContentFieldMetadataModel field = keyValuePair.Value;
                                if (field.id == FieldIDToAdd)
                                {
                                    if (field.inherited)
                                    {
                                        SourceContentId = field.contentId;
                                        SourceName      = field.nameLc;
                                        using (var CSSource = new CsModel(core)) {
                                            CSSource.open("Content Fields", "(ContentID=" + SourceContentId + ")and(Name=" + DbController.encodeSQLText(SourceName) + ")");
                                            if (CSSource.ok())
                                            {
                                                using (var CSTarget = new CsModel(core)) {
                                                    CSTarget.insert("Content Fields");
                                                    if (CSTarget.ok())
                                                    {
                                                        CSSource.copyRecord(CSTarget);
                                                        CSTarget.set("ContentID", ContentId);
                                                        ReloadCDef = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        //
                        // Make sure all fields are not-inherited, if not, create new fields
                        //
                        int ColumnNumberMax = 0;
                        foreach (var keyValuePair in CDef.adminColumns)
                        {
                            Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass adminColumn = keyValuePair.Value;
                            Processor.Models.Domain.ContentFieldMetadataModel field = CDef.fields[adminColumn.Name];
                            if (field.inherited)
                            {
                                SourceContentId = field.contentId;
                                SourceName      = field.nameLc;
                                using (var CSSource = new CsModel(core)) {
                                    if (CSSource.open("Content Fields", "(ContentID=" + SourceContentId + ")and(Name=" + DbController.encodeSQLText(SourceName) + ")"))
                                    {
                                        using (var CSTarget = new CsModel(core)) {
                                            if (CSTarget.insert("Content Fields"))
                                            {
                                                CSSource.copyRecord(CSTarget);
                                                CSTarget.set("ContentID", ContentId);
                                                ReloadCDef = true;
                                            }
                                        }
                                    }
                                }
                            }
                            if (ColumnNumberMax < field.indexColumn)
                            {
                                ColumnNumberMax = field.indexColumn;
                            }
                            ColumnWidthTotal += adminColumn.Width;
                        }
                        //
                        // ----- Perform any actions first
                        //
                        int  columnPtr      = 0;
                        bool MoveNextColumn = false;
                        switch (ToolsAction)
                        {
                        case ToolsActionAddField: {
                            //
                            // Add a field to the Listing Page
                            //
                            if (FieldIDToAdd != 0)
                            {
                                columnPtr = 0;
                                if (CDef.adminColumns.Count > 1)
                                {
                                    foreach (var keyValuePair in CDef.adminColumns)
                                    {
                                        Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass adminColumn = keyValuePair.Value;
                                        Processor.Models.Domain.ContentFieldMetadataModel field = CDef.fields[adminColumn.Name];
                                        using (var csData = new CsModel(core)) {
                                            csData.openRecord("Content Fields", field.id);
                                            csData.set("IndexColumn", (columnPtr) * 10);
                                            csData.set("IndexWidth", Math.Floor((adminColumn.Width * 80) / (double)ColumnWidthTotal));
                                        }
                                        columnPtr += 1;
                                    }
                                }
                                using (var csData = new CsModel(core)) {
                                    if (csData.openRecord("Content Fields", FieldIDToAdd))
                                    {
                                        csData.set("IndexColumn", columnPtr * 10);
                                        csData.set("IndexWidth", 20);
                                        csData.set("IndexSortPriority", 99);
                                        csData.set("IndexSortDirection", 1);
                                    }
                                }
                                ReloadCDef = true;
                            }
                            //
                            break;
                        }

                        case ToolsActionRemoveField: {
                            //
                            // Remove a field to the Listing Page
                            //
                            if (CDef.adminColumns.Count > 1)
                            {
                                columnPtr = 0;
                                foreach (var keyValuePair in CDef.adminColumns)
                                {
                                    Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass adminColumn = keyValuePair.Value;
                                    Processor.Models.Domain.ContentFieldMetadataModel field = CDef.fields[adminColumn.Name];
                                    using (var csData = new CsModel(core)) {
                                        csData.openRecord("Content Fields", field.id);
                                        if (fieldId == TargetFieldID)
                                        {
                                            csData.set("IndexColumn", 0);
                                            csData.set("IndexWidth", 0);
                                            csData.set("IndexSortPriority", 0);
                                            csData.set("IndexSortDirection", 0);
                                        }
                                        else
                                        {
                                            csData.set("IndexColumn", (columnPtr) * 10);
                                            csData.set("IndexWidth", Math.Floor((adminColumn.Width * 100) / (double)ColumnWidthTotal));
                                        }
                                    }
                                    columnPtr += 1;
                                }
                                ReloadCDef = true;
                            }
                            break;
                        }

                        case ToolsActionMoveFieldRight: {
                            //
                            // Move column field right
                            //
                            if (CDef.adminColumns.Count > 1)
                            {
                                MoveNextColumn = false;
                                columnPtr      = 0;
                                foreach (var keyValuePair in CDef.adminColumns)
                                {
                                    Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass adminColumn = keyValuePair.Value;
                                    Processor.Models.Domain.ContentFieldMetadataModel field = CDef.fields[adminColumn.Name];
                                    FieldName = adminColumn.Name;
                                    using (var csData = new CsModel(core)) {
                                        csData.openRecord("Content Fields", field.id);
                                        if ((CDef.fields[FieldName.ToLowerInvariant()].id == TargetFieldID) && (columnPtr < CDef.adminColumns.Count))
                                        {
                                            csData.set("IndexColumn", (columnPtr + 1) * 10);
                                            //
                                            MoveNextColumn = true;
                                        }
                                        else if (MoveNextColumn)
                                        {
                                            //
                                            // This is one past target
                                            //
                                            csData.set("IndexColumn", (columnPtr - 1) * 10);
                                            MoveNextColumn = false;
                                        }
                                        else
                                        {
                                            //
                                            // not target or one past target
                                            //
                                            csData.set("IndexColumn", (columnPtr) * 10);
                                            MoveNextColumn = false;
                                        }
                                        csData.set("IndexWidth", Math.Floor((adminColumn.Width * 100) / (double)ColumnWidthTotal));
                                    }
                                    columnPtr += 1;
                                }
                                ReloadCDef = true;
                            }
                            // end case
                            break;
                        }

                        case ToolsActionMoveFieldLeft: {
                            //
                            // Move Index column field left
                            //
                            if (CDef.adminColumns.Count > 1)
                            {
                                MoveNextColumn = false;
                                columnPtr      = 0;
                                foreach (var keyValuePair in CDef.adminColumns.Reverse())
                                {
                                    Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass adminColumn = keyValuePair.Value;
                                    Processor.Models.Domain.ContentFieldMetadataModel field = CDef.fields[adminColumn.Name];
                                    FieldName = adminColumn.Name;
                                    using (var csData = new CsModel(core)) {
                                        csData.openRecord("Content Fields", field.id);
                                        if ((field.id == TargetFieldID) && (columnPtr < CDef.adminColumns.Count))
                                        {
                                            csData.set("IndexColumn", (columnPtr - 1) * 10);
                                            //
                                            MoveNextColumn = true;
                                        }
                                        else if (MoveNextColumn)
                                        {
                                            //
                                            // This is one past target
                                            //
                                            csData.set("IndexColumn", (columnPtr + 1) * 10);
                                            MoveNextColumn = false;
                                        }
                                        else
                                        {
                                            //
                                            // not target or one past target
                                            //
                                            csData.set("IndexColumn", (columnPtr) * 10);
                                            MoveNextColumn = false;
                                        }
                                        csData.set("IndexWidth", Math.Floor((adminColumn.Width * 100) / (double)ColumnWidthTotal));
                                    }
                                    columnPtr += 1;
                                }
                                ReloadCDef = true;
                            }
                            break;
                        }

                        default: {
                            // do nothing
                            break;
                        }
                        }
                        //
                        // Get a new copy of the content definition
                        //
                        CDef = Processor.Models.Domain.ContentMetadataModel.create(core, ContentId, false, true);
                    }
                    if (Button == ButtonSaveandInvalidateCache)
                    {
                        core.cache.invalidateAll();
                        core.clearMetaData();
                        return(core.webServer.redirect("?af=" + AdminFormToolConfigureListing + "&ContentID=" + ContentId, "Tools-ConfigureListing, Save and Invalidate Cache, Go to back ConfigureListing tools"));
                    }
                    //
                    //--------------------------------------------------------------------------------
                    //   Display the form
                    //--------------------------------------------------------------------------------
                    //
                    if (!string.IsNullOrEmpty(ContentName))
                    {
                        Stream.add("<br><br><B>" + ContentName + "</b><br>");
                    }
                    Stream.add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"99%\"><tr>");
                    Stream.add("<td width=\"5%\">&nbsp;</td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>10%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>20%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>30%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>40%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>50%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>60%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>70%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>80%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>90%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>100%</nobr></td>");
                    Stream.add("<td width=\"4%\" align=\"center\">&nbsp;</td>");
                    Stream.add("</tr></TABLE>");
                    //
                    Stream.add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"99%\"><tr>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.gif\" width=\"1\" height=\"10\"><IMG alt=\"\" src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/Images/spacer.gif\" width=\"100%\" height=\"10\"></nobr></td>");
                    Stream.add("</tr></TABLE>");
                    //
                    // print the column headers
                    //
                    ColumnWidthTotal = 0;
                    int InheritedFieldCount = 0;
                    if (CDef.adminColumns.Count > 0)
                    {
                        //
                        // Calc total width
                        //
                        foreach (KeyValuePair <string, Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass> kvp in CDef.adminColumns)
                        {
                            ColumnWidthTotal += kvp.Value.Width;
                        }
                        if (ColumnWidthTotal > 0)
                        {
                            Stream.add("<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"90%\">");
                            int ColumnCount = 0;
                            foreach (KeyValuePair <string, Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass> kvp in CDef.adminColumns)
                            {
                                //
                                // print column headers - anchored so they sort columns
                                //
                                int ColumnWidth = encodeInteger(100 * (kvp.Value.Width / (double)ColumnWidthTotal));
                                FieldName = kvp.Value.Name;
                                var tempVar = CDef.fields[FieldName.ToLowerInvariant()];
                                fieldId = tempVar.id;
                                string Caption = tempVar.caption;
                                if (tempVar.inherited)
                                {
                                    Caption             += "*";
                                    InheritedFieldCount += 1;
                                }
                                string AStart = "<A href=\"" + core.webServer.requestPage + "?" + RequestNameToolContentId + "=" + ContentId + "&af=" + AdminFormToolConfigureListing + "&fi=" + fieldId + "&dtcn=" + ColumnCount;
                                Stream.add("<td width=\"" + ColumnWidth + "%\" valign=\"top\" align=\"left\">" + SpanClassAdminNormal + Caption + "<br>");
                                Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/black.GIF\" width=\"100%\" height=\"1\">");
                                Stream.add(AStart + "&dta=" + ToolsActionRemoveField + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonDeleteUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A><br>");
                                Stream.add(AStart + "&dta=" + ToolsActionMoveFieldRight + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonMoveRightUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A><br>");
                                Stream.add(AStart + "&dta=" + ToolsActionMoveFieldLeft + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonMoveLeftUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A><br>");
                                Stream.add(AStart + "&dta=" + ToolsActionSetAZ + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonSortazUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A><br>");
                                Stream.add(AStart + "&dta=" + ToolsActionSetZA + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonSortzaUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A><br>");
                                Stream.add(AStart + "&dta=" + ToolsActionExpand + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonOpenUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A><br>");
                                Stream.add(AStart + "&dta=" + ToolsActionContract + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonCloseUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A>");
                                Stream.add("</SPAN></td>");
                                ColumnCount += 1;
                            }
                            Stream.add("</tr>");
                            Stream.add("</TABLE>");
                        }
                    }
                    //
                    // ----- If anything was inherited, put up the message
                    //
                    if (InheritedFieldCount > 0)
                    {
                        Stream.add("<P class=\"ccNormal\">* This field was inherited from the Content Definition's Parent. Inherited fields will automatically change when the field in the parent is changed. If you alter these settings, this connection will be broken, and the field will no longer inherit it's properties.</P class=\"ccNormal\">");
                    }
                    //
                    // ----- now output a list of fields to add
                    //
                    if (CDef.fields.Count == 0)
                    {
                        Stream.add(SpanClassAdminNormal + "This Content Definition has no fields</SPAN><br>");
                    }
                    else
                    {
                        Stream.add(SpanClassAdminNormal + "<br>");
                        bool skipField = false;
                        foreach (KeyValuePair <string, Processor.Models.Domain.ContentFieldMetadataModel> keyValuePair in CDef.fields)
                        {
                            Processor.Models.Domain.ContentFieldMetadataModel field = keyValuePair.Value;
                            //
                            // test if this column is in use
                            //
                            skipField = false;
                            if (CDef.adminColumns.Count > 0)
                            {
                                foreach (KeyValuePair <string, Processor.Models.Domain.ContentMetadataModel.MetaAdminColumnClass> kvp in CDef.adminColumns)
                                {
                                    if (field.nameLc == kvp.Value.Name)
                                    {
                                        skipField = true;
                                        break;
                                    }
                                }
                            }
                            //
                            // display the column if it is not in use
                            //
                            if (skipField)
                            {
                                if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileText)
                                {
                                    //
                                    // text filename can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (text file field)<br>");
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileCSS)
                                {
                                    //
                                    // text filename can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (css file field)<br>");
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileXML)
                                {
                                    //
                                    // text filename can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (xml file field)<br>");
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileJavascript)
                                {
                                    //
                                    // text filename can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (javascript file field)<br>");
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.LongText)
                                {
                                    //
                                    // long text can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (long text field)<br>");
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileImage)
                                {
                                    //
                                    // long text can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (image field)<br>");
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.Redirect)
                                {
                                    //
                                    // long text can not be search
                                    //
                                    Stream.add("<IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/Spacer.gif\" width=\"50\" height=\"15\" border=\"0\"> " + field.caption + " (redirect field)<br>");
                                }
                                else
                                {
                                    //
                                    // can be used as column header
                                    //
                                    Stream.add("<A href=\"" + core.webServer.requestPage + "?" + RequestNameToolContentId + "=" + ContentId + "&af=" + AdminFormToolConfigureListing + "&fi=" + field.id + "&dta=" + ToolsActionAddField + "&" + RequestNameAddFieldId + "=" + field.id + "\"><IMG src=\"https://s3.amazonaws.com/cdn.contensive.com/assets/20200122/images/LibButtonAddUp.gif\" width=\"50\" height=\"15\" border=\"0\"></A> " + field.caption + "<br>");
                                }
                            }
                        }
                    }
                }
                //
                //--------------------------------------------------------------------------------
                // print the content tables that have Listing Pages to Configure
                //--------------------------------------------------------------------------------
                //
                string FormPanel = SpanClassAdminNormal + "Select a Content Definition to Configure its Listing Page<br>";
                FormPanel += core.html.selectFromContent("ContentID", ContentId, "Content");
                Stream.add(core.html.getPanel(FormPanel));
                core.siteProperties.setProperty("AllowContentAutoLoad", AllowContentAutoLoad);
                Stream.add(HtmlController.inputHidden("ReloadCDef", ReloadCDef));
                result = AdminUIController.getToolForm(core, Stream.text, ButtonList);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
        //
        //====================================================================================================
        /// <summary>
        /// Get the Configure Edit
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public static string get(CPClass cp)
        {
            CoreController core = cp.core;

            try {
                KeyPtrController Index = new KeyPtrController();
                int    ContentId       = cp.Doc.GetInteger(RequestNameToolContentId);
                var    contentMetadata = ContentMetadataModel.create(core, ContentId, true, true);
                int    RecordCount     = 0;
                int    formFieldId     = 0;
                string StatusMessage   = "";
                string ErrorMessage    = "";
                bool   ReloadCDef      = cp.Doc.GetBoolean("ReloadCDef");
                if (contentMetadata != null)
                {
                    string ToolButton = cp.Doc.GetText("Button");
                    //
                    if (!string.IsNullOrEmpty(ToolButton))
                    {
                        bool AllowContentAutoLoad = false;
                        if (ToolButton != ButtonCancel)
                        {
                            //
                            // Save the form changes
                            //
                            AllowContentAutoLoad = cp.Site.GetBoolean("AllowContentAutoLoad", true);
                            cp.Site.SetProperty("AllowContentAutoLoad", "false");
                            //
                            // ----- Save the input
                            //
                            RecordCount = GenericController.encodeInteger(cp.Doc.GetInteger("dtfaRecordCount"));
                            if (RecordCount > 0)
                            {
                                int RecordPointer = 0;
                                for (RecordPointer = 0; RecordPointer < RecordCount; RecordPointer++)
                                {
                                    //
                                    string formFieldName = cp.Doc.GetText("dtfaName." + RecordPointer);
                                    CPContentBaseClass.FieldTypeIdEnum formFieldTypeId = (CPContentBaseClass.FieldTypeIdEnum)cp.Doc.GetInteger("dtfaType." + RecordPointer);
                                    formFieldId = GenericController.encodeInteger(cp.Doc.GetInteger("dtfaID." + RecordPointer));
                                    bool formFieldInherited = cp.Doc.GetBoolean("dtfaInherited." + RecordPointer);
                                    //
                                    // problem - looking for the name in the Db using the form's name, but it could have changed.
                                    // have to look field up by id
                                    //
                                    foreach (KeyValuePair <string, Processor.Models.Domain.ContentFieldMetadataModel> cdefFieldKvp in contentMetadata.fields)
                                    {
                                        if (cdefFieldKvp.Value.id == formFieldId)
                                        {
                                            //
                                            // Field was found in CDef
                                            //
                                            if (cdefFieldKvp.Value.inherited && (!formFieldInherited))
                                            {
                                                //
                                                // Was inherited, but make a copy of the field
                                                //
                                                using (var CSTarget = new CsModel(core)) {
                                                    if (CSTarget.insert("Content Fields"))
                                                    {
                                                        using (var CSSource = new CsModel(core)) {
                                                            if (CSSource.openRecord("Content Fields", formFieldId))
                                                            {
                                                                CSSource.copyRecord(CSTarget);
                                                            }
                                                        }
                                                        formFieldId = CSTarget.getInteger("ID");
                                                        CSTarget.set("ContentID", ContentId);
                                                    }
                                                    CSTarget.close();
                                                }
                                                ReloadCDef = true;
                                            }
                                            else if ((!cdefFieldKvp.Value.inherited) && (formFieldInherited))
                                            {
                                                //
                                                // Was a field, make it inherit from it's parent
                                                MetadataController.deleteContentRecord(core, "Content Fields", formFieldId);
                                                ReloadCDef = true;
                                            }
                                            else if ((!cdefFieldKvp.Value.inherited) && (!formFieldInherited))
                                            {
                                                //
                                                // not inherited, save the field values and mark for a reload
                                                //
                                                {
                                                    if (formFieldName.IndexOf(" ") != -1)
                                                    {
                                                        //
                                                        // remoave spaces from new name
                                                        //
                                                        StatusMessage = StatusMessage + "<LI>Field [" + formFieldName + "] was renamed [" + GenericController.strReplace(formFieldName, " ", "") + "] because the field name can not include spaces.</LI>";
                                                        formFieldName = GenericController.strReplace(formFieldName, " ", "");
                                                    }
                                                    //
                                                    string SQL = null;
                                                    //
                                                    if ((!string.IsNullOrEmpty(formFieldName)) && ((int)formFieldTypeId != 0) && ((cdefFieldKvp.Value.nameLc == "") || (cdefFieldKvp.Value.fieldTypeId == 0)))
                                                    {
                                                        //
                                                        // Create Db field, Field is good but was not before
                                                        //
                                                        core.db.createSQLTableField(contentMetadata.tableName, formFieldName, formFieldTypeId);
                                                        StatusMessage = StatusMessage + "<LI>Field [" + formFieldName + "] was saved to this content definition and a database field was created in [" + contentMetadata.tableName + "].</LI>";
                                                    }
                                                    else if ((string.IsNullOrEmpty(formFieldName)) || ((int)formFieldTypeId == 0))
                                                    {
                                                        //
                                                        // name blank or type=0 - do nothing but tell them
                                                        //
                                                        if (string.IsNullOrEmpty(formFieldName) && ((int)formFieldTypeId == 0))
                                                        {
                                                            ErrorMessage += "<LI>Field number " + (RecordPointer + 1) + " was saved to this content definition but no database field was created because a name and field type are required.</LI>";
                                                        }
                                                        else if (formFieldName == "unnamedfield" + formFieldId.ToString())
                                                        {
                                                            ErrorMessage += "<LI>Field number " + (RecordPointer + 1) + " was saved to this content definition but no database field was created because a field name is required.</LI>";
                                                        }
                                                        else
                                                        {
                                                            ErrorMessage += "<LI>Field [" + formFieldName + "] was saved to this content definition but no database field was created because a field type are required.</LI>";
                                                        }
                                                    }
                                                    else if ((formFieldName == cdefFieldKvp.Value.nameLc) && (formFieldTypeId != cdefFieldKvp.Value.fieldTypeId))
                                                    {
                                                        //
                                                        // Field Type changed, must be done manually
                                                        //
                                                        ErrorMessage += "<LI>Field [" + formFieldName + "] changed type from [" + DbBaseModel.getRecordName <ContentFieldTypeModel>(core.cpParent, (int)cdefFieldKvp.Value.fieldTypeId) + "] to [" + DbBaseModel.getRecordName <ContentFieldTypeModel>(core.cpParent, (int)formFieldTypeId) + "]. This may have caused a problem converting content.</LI>";
                                                        int DataSourceTypeId = core.db.getDataSourceType();
                                                        switch (DataSourceTypeId)
                                                        {
                                                        case DataSourceTypeODBCMySQL:
                                                            SQL = "alter table " + contentMetadata.tableName + " change " + cdefFieldKvp.Value.nameLc + " " + cdefFieldKvp.Value.nameLc + " " + core.db.getSQLAlterColumnType(formFieldTypeId) + ";";
                                                            break;

                                                        default:
                                                            SQL = "alter table " + contentMetadata.tableName + " alter column " + cdefFieldKvp.Value.nameLc + " " + core.db.getSQLAlterColumnType(formFieldTypeId) + ";";
                                                            break;
                                                        }
                                                        core.db.executeNonQuery(SQL);
                                                    }
                                                    SQL = "Update ccFields"
                                                          + " Set name=" + DbController.encodeSQLText(formFieldName)
                                                          + ",type=" + (int)formFieldTypeId
                                                          + ",caption=" + DbController.encodeSQLText(cp.Doc.GetText("dtfaCaption." + RecordPointer))
                                                          + ",DefaultValue=" + DbController.encodeSQLText(cp.Doc.GetText("dtfaDefaultValue." + RecordPointer))
                                                          + ",EditSortPriority=" + DbController.encodeSQLText(GenericController.encodeText(cp.Doc.GetInteger("dtfaEditSortPriority." + RecordPointer)))
                                                          + ",Active=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaActive." + RecordPointer))
                                                          + ",ReadOnly=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaReadOnly." + RecordPointer))
                                                          + ",Authorable=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaAuthorable." + RecordPointer))
                                                          + ",Required=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaRequired." + RecordPointer))
                                                          + ",UniqueName=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaUniqueName." + RecordPointer))
                                                          + ",TextBuffered=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaTextBuffered." + RecordPointer))
                                                          + ",Password="******"dtfaPassword." + RecordPointer))
                                                          + ",HTMLContent=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaHTMLContent." + RecordPointer))
                                                          + ",EditTab=" + DbController.encodeSQLText(cp.Doc.GetText("dtfaEditTab." + RecordPointer))
                                                          + ",Scramble=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaScramble." + RecordPointer)) + "";
                                                    if (core.session.isAuthenticatedAdmin())
                                                    {
                                                        SQL += ",adminonly=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaAdminOnly." + RecordPointer));
                                                    }
                                                    if (core.session.isAuthenticatedDeveloper())
                                                    {
                                                        SQL += ",DeveloperOnly=" + DbController.encodeSQLBoolean(cp.Doc.GetBoolean("dtfaDeveloperOnly." + RecordPointer));
                                                    }
                                                    SQL += " where ID=" + formFieldId;
                                                    core.db.executeNonQuery(SQL);
                                                    ReloadCDef = true;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            core.cache.invalidateAll();
                            core.clearMetaData();
                        }
                        if (ToolButton == ButtonAdd)
                        {
                            //
                            // ----- Insert a blank Field
                            var defaultValues = ContentMetadataModel.getDefaultValueDict(core, ContentFieldModel.tableMetadata.contentName);
                            var field         = ContentFieldModel.addDefault <ContentFieldModel>(core.cpParent, defaultValues);
                            field.name             = "unnamedField" + field.id.ToString();
                            field.contentId        = ContentId;
                            field.editSortPriority = 0;
                            field.save(core.cpParent);
                            ReloadCDef = true;
                        }
                        //
                        // ----- Button Reload CDef
                        if (ToolButton == ButtonSaveandInvalidateCache)
                        {
                            core.cache.invalidateAll();
                            core.clearMetaData();
                        }
                        //
                        // ----- Restore Content Autoload site property
                        //
                        if (AllowContentAutoLoad)
                        {
                            cp.Site.SetProperty("AllowContentAutoLoad", AllowContentAutoLoad.ToString());
                        }
                        //
                        // ----- Cancel or Save, reload CDef and go
                        //
                        if ((ToolButton == ButtonCancel) || (ToolButton == ButtonOK))
                        {
                            //
                            // ----- Exit back to menu
                            //
                            return(core.webServer.redirect(core.appConfig.adminRoute, "Tool-ConfigureContentEdit, ok or cancel button, go to root."));
                        }
                    }
                }
                //
                //   Print Output
                string description = ""
                                     + HtmlController.p("Use this tool to add or modify content definition fields and the underlying sql table fields.")
                                     + ((ContentId.Equals(0)) ? "" : ""
                                        + HtmlController.ul(""
                                                            + HtmlController.li(HtmlController.a("Edit Content", "?aa=0&cid=3&id=" + ContentId + "&tx=&ad=0&asf=1&af=4", "nav-link btn btn-primary"), "nav-item mr-1")
                                                            + HtmlController.li(HtmlController.a("Edit Records", "?cid=" + ContentId, "nav-link btn btn-primary"), "nav-item mr-1")
                                                            + HtmlController.li(HtmlController.a("Select Different Fields", "?af=105", "nav-link btn btn-primary"), "nav-item mr-1")
                                                            , "nav")
                                        );
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                Stream.add(AdminUIController.getHeaderTitleDescription("Manage Admin Edit Fields", description));
                //
                // -- status of last operation
                if (!string.IsNullOrEmpty(StatusMessage))
                {
                    Stream.add(AdminUIController.getToolFormRow(core, "<UL>" + StatusMessage + "</UL>"));
                }
                //
                // -- errors with last operations
                if (!string.IsNullOrEmpty(ErrorMessage))
                {
                    Stream.add(HtmlController.div("There was a problem saving these changes" + "<UL>" + ErrorMessage + "</UL>", "ccError"));
                }
                if (ReloadCDef)
                {
                    contentMetadata = Processor.Models.Domain.ContentMetadataModel.create(core, ContentId, true, true);
                }
                string ButtonList = ButtonCancel + "," + ButtonSelect;
                if (ContentId == 0)
                {
                    //
                    // content tables that have edit forms to Configure
                    bool isEmptyList = false;
                    Stream.add(AdminUIController.getToolFormInputRow(core, "Select a Content Definition to Configure", AdminUIEditorController.getLookupContentEditor(core, RequestNameToolContentId, ContentId, ContentMetadataModel.getContentId(core, "Content"), ref isEmptyList, false, "", "", false, "")));
                }
                else
                {
                    //
                    // Configure edit form
                    Stream.add(HtmlController.inputHidden(RequestNameToolContentId, ContentId));
                    Stream.add(core.html.getPanelTop());
                    ButtonList = ButtonCancel + "," + ButtonSave + "," + ButtonOK + "," + ButtonAdd;
                    //
                    // Get a new copy of the content definition
                    //
                    Stream.add(SpanClassAdminNormal + "<P><B>" + contentMetadata.name + "</b></P>");
                    Stream.add("<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">");
                    //
                    int  ParentContentId  = contentMetadata.parentId;
                    bool AllowCDefInherit = false;
                    Processor.Models.Domain.ContentMetadataModel ParentCDef = null;
                    if (ParentContentId == -1)
                    {
                        AllowCDefInherit = false;
                    }
                    else
                    {
                        AllowCDefInherit = true;
                        string ParentContentName = MetadataController.getContentNameByID(core, ParentContentId);
                        ParentCDef = Processor.Models.Domain.ContentMetadataModel.create(core, ParentContentId, true, true);
                    }
                    bool NeedFootNote1 = false;
                    bool NeedFootNote2 = false;
                    if (contentMetadata.fields.Count > 0)
                    {
                        //
                        // -- header row
                        Stream.add("<tr>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\"></td>");
                        if (!AllowCDefInherit)
                        {
                            Stream.add("<td valign=\"bottom\" width=\"100\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Inherited*</b></span></td>");
                            NeedFootNote1 = true;
                        }
                        else
                        {
                            Stream.add("<td valign=\"bottom\" width=\"100\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Inherited</b></span></td>");
                        }
                        Stream.add("<td valign=\"bottom\" width=\"100\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b><br>Field</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"100\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b><br>Caption</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"100\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b><br>Edit Tab</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"100\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b><br>Default</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b><br>Type</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b>Edit<br>Order</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Active</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b>Read<br>Only</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Auth</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Req</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Unique</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b>Text<br>Buffer</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b><br>Pass</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "<b>Text<br>Scrm</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b><br>HTML</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b>Admin<br>Only</b></span></td>");
                        Stream.add("<td valign=\"bottom\" width=\"50\" class=\"ccPanelInput\" align=\"left\">" + SpanClassAdminSmall + "<b>Dev<br>Only</b></span></td>");
                        Stream.add("</tr>");
                        RecordCount = 0;
                        //
                        // Build a select template for Type
                        //
                        string TypeSelectTemplate = core.html.selectFromContent("menuname", -1, "Content Field Types", "", "unknown");
                        //
                        // Index the sort order
                        //
                        List <FieldSortClass> fieldList = new List <FieldSortClass>();
                        int FieldCount = contentMetadata.fields.Count;
                        foreach (var keyValuePair in contentMetadata.fields)
                        {
                            FieldSortClass fieldSort = new FieldSortClass();
                            string         sortOrder = "";
                            fieldSort.field = keyValuePair.Value;
                            sortOrder       = "";
                            if (fieldSort.field.active)
                            {
                                sortOrder += "0";
                            }
                            else
                            {
                                sortOrder += "1";
                            }
                            if (fieldSort.field.authorable)
                            {
                                sortOrder += "0";
                            }
                            else
                            {
                                sortOrder += "1";
                            }
                            sortOrder     += fieldSort.field.editTabName + getIntegerString(fieldSort.field.editSortPriority, 10) + getIntegerString(fieldSort.field.id, 10);
                            fieldSort.sort = sortOrder;
                            fieldList.Add(fieldSort);
                        }
                        fieldList.Sort((p1, p2) => p1.sort.CompareTo(p2.sort));
                        StringBuilderLegacyController StreamValidRows = new StringBuilderLegacyController();
                        var contentFieldsCdef = Processor.Models.Domain.ContentMetadataModel.createByUniqueName(core, "content fields");
                        foreach (FieldSortClass fieldsort in fieldList)
                        {
                            StringBuilderLegacyController streamRow = new StringBuilderLegacyController();
                            bool rowValid = true;
                            //
                            // If Field has name and type, it is locked and can not be changed
                            //
                            bool FieldLocked = (fieldsort.field.nameLc != "") && (fieldsort.field.fieldTypeId != 0);
                            //
                            // put the menu into the current menu format
                            //
                            formFieldId = fieldsort.field.id;
                            streamRow.add(HtmlController.inputHidden("dtfaID." + RecordCount, formFieldId));
                            streamRow.add("<tr>");
                            //
                            // edit button
                            //
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\">" + AdminUIController.getRecordEditAnchorTag(core, contentFieldsCdef, formFieldId) + "</td>");
                            //
                            // Inherited
                            //
                            if (!AllowCDefInherit)
                            {
                                //
                                // no parent
                                //
                                streamRow.add("<td class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "False</span></td>");
                            }
                            else if (fieldsort.field.inherited)
                            {
                                //
                                // inherited property
                                //
                                streamRow.add("<td class=\"ccPanelInput\" align=\"center\">" + HtmlController.checkbox("dtfaInherited." + RecordCount, fieldsort.field.inherited) + "</td>");
                            }
                            else
                            {
                                Processor.Models.Domain.ContentFieldMetadataModel parentField = null;
                                //
                                // CDef has a parent, but the field is non-inherited, test for a matching Parent Field
                                //
                                if (ParentCDef == null)
                                {
                                    foreach (KeyValuePair <string, Processor.Models.Domain.ContentFieldMetadataModel> kvp in ParentCDef.fields)
                                    {
                                        if (kvp.Value.nameLc == fieldsort.field.nameLc)
                                        {
                                            parentField = kvp.Value;
                                            break;
                                        }
                                    }
                                }
                                if (parentField == null)
                                {
                                    streamRow.add("<td class=\"ccPanelInput\" align=\"center\">" + SpanClassAdminSmall + "False**</span></td>");
                                    NeedFootNote2 = true;
                                }
                                else
                                {
                                    streamRow.add("<td class=\"ccPanelInput\" align=\"center\">" + HtmlController.checkbox("dtfaInherited." + RecordCount, fieldsort.field.inherited) + "</td>");
                                }
                            }
                            //
                            // name
                            //
                            bool tmpValue = string.IsNullOrEmpty(fieldsort.field.nameLc);
                            rowValid = rowValid && !tmpValue;
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\"><nobr>");
                            if (fieldsort.field.inherited)
                            {
                                streamRow.add(SpanClassAdminSmall + fieldsort.field.nameLc + "&nbsp;</SPAN>");
                            }
                            else if (FieldLocked)
                            {
                                streamRow.add(SpanClassAdminSmall + fieldsort.field.nameLc + "&nbsp;</SPAN><input type=hidden name=dtfaName." + RecordCount + " value=\"" + fieldsort.field.nameLc + "\">");
                            }
                            else
                            {
                                streamRow.add(HtmlController.inputText_Legacy(core, "dtfaName." + RecordCount, fieldsort.field.nameLc, 1, 10));
                            }
                            streamRow.add("</nobr></td>");
                            //
                            // caption
                            //
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\"><nobr>");
                            if (fieldsort.field.inherited)
                            {
                                streamRow.add(SpanClassAdminSmall + fieldsort.field.caption + "</SPAN>");
                            }
                            else
                            {
                                streamRow.add(HtmlController.inputText_Legacy(core, "dtfaCaption." + RecordCount, fieldsort.field.caption, 1, 10));
                            }
                            streamRow.add("</nobr></td>");
                            //
                            // Edit Tab
                            //
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\"><nobr>");
                            if (fieldsort.field.inherited)
                            {
                                streamRow.add(SpanClassAdminSmall + fieldsort.field.editTabName + "</SPAN>");
                            }
                            else
                            {
                                streamRow.add(HtmlController.inputText_Legacy(core, "dtfaEditTab." + RecordCount, fieldsort.field.editTabName, 1, 10));
                            }
                            streamRow.add("</nobr></td>");
                            //
                            // default
                            //
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\"><nobr>");
                            if (fieldsort.field.inherited)
                            {
                                streamRow.add(SpanClassAdminSmall + GenericController.encodeText(fieldsort.field.defaultValue) + "</SPAN>");
                            }
                            else
                            {
                                streamRow.add(HtmlController.inputText_Legacy(core, "dtfaDefaultValue." + RecordCount, GenericController.encodeText(fieldsort.field.defaultValue), 1, 10));
                            }
                            streamRow.add("</nobr></td>");
                            //
                            // type
                            //
                            rowValid = rowValid && (fieldsort.field.fieldTypeId > 0);
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\"><nobr>");
                            if (fieldsort.field.inherited)
                            {
                                using (var csData = new CsModel(core)) {
                                    csData.openRecord("Content Field Types", (int)fieldsort.field.fieldTypeId);
                                    if (!csData.ok())
                                    {
                                        streamRow.add(SpanClassAdminSmall + "Unknown[" + fieldsort.field.fieldTypeId + "]</SPAN>");
                                    }
                                    else
                                    {
                                        streamRow.add(SpanClassAdminSmall + csData.getText("Name") + "</SPAN>");
                                    }
                                }
                            }
                            else if (FieldLocked)
                            {
                                streamRow.add(DbBaseModel.getRecordName <ContentFieldTypeModel>(core.cpParent, (int)fieldsort.field.fieldTypeId) + HtmlController.inputHidden("dtfaType." + RecordCount, (int)fieldsort.field.fieldTypeId));
                            }
                            else
                            {
                                string TypeSelect = TypeSelectTemplate;
                                TypeSelect = GenericController.strReplace(TypeSelect, "menuname", "dtfaType." + RecordCount, 1, 99, 1);
                                TypeSelect = GenericController.strReplace(TypeSelect, "=\"" + fieldsort.field.fieldTypeId + "\"", "=\"" + fieldsort.field.fieldTypeId + "\" selected", 1, 99, 1);
                                streamRow.add(TypeSelect);
                            }
                            streamRow.add("</nobr></td>");
                            //
                            // sort priority
                            //
                            streamRow.add("<td class=\"ccPanelInput\" align=\"left\"><nobr>");
                            if (fieldsort.field.inherited)
                            {
                                streamRow.add(SpanClassAdminSmall + fieldsort.field.editSortPriority + "</SPAN>");
                            }
                            else
                            {
                                streamRow.add(HtmlController.inputText_Legacy(core, "dtfaEditSortPriority." + RecordCount, fieldsort.field.editSortPriority.ToString(), 1, 10));
                            }
                            streamRow.add("</nobr></td>");
                            //
                            // active
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaActive." + RecordCount, fieldsort.field.active, fieldsort.field.inherited));
                            //
                            // read only
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaReadOnly." + RecordCount, fieldsort.field.readOnly, fieldsort.field.inherited));
                            //
                            // authorable
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaAuthorable." + RecordCount, fieldsort.field.authorable, fieldsort.field.inherited));
                            //
                            // required
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaRequired." + RecordCount, fieldsort.field.required, fieldsort.field.inherited));
                            //
                            // UniqueName
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaUniqueName." + RecordCount, fieldsort.field.uniqueName, fieldsort.field.inherited));
                            //
                            // text buffered
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaTextBuffered." + RecordCount, fieldsort.field.textBuffered, fieldsort.field.inherited));
                            //
                            // password
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaPassword." + RecordCount, fieldsort.field.password, fieldsort.field.inherited));
                            //
                            // scramble
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaScramble." + RecordCount, fieldsort.field.scramble, fieldsort.field.inherited));
                            //
                            // HTML Content
                            //
                            streamRow.add(configureEdit_CheckBox("dtfaHTMLContent." + RecordCount, fieldsort.field.htmlContent, fieldsort.field.inherited));
                            //
                            // Admin Only
                            //
                            if (core.session.isAuthenticatedAdmin())
                            {
                                streamRow.add(configureEdit_CheckBox("dtfaAdminOnly." + RecordCount, fieldsort.field.adminOnly, fieldsort.field.inherited));
                            }
                            //
                            // Developer Only
                            //
                            if (core.session.isAuthenticatedDeveloper())
                            {
                                streamRow.add(configureEdit_CheckBox("dtfaDeveloperOnly." + RecordCount, fieldsort.field.developerOnly, fieldsort.field.inherited));
                            }
                            //
                            streamRow.add("</tr>");
                            RecordCount = RecordCount + 1;
                            //
                            // rows are built - put the blank rows at the top
                            //
                            if (!rowValid)
                            {
                                Stream.add(streamRow.text);
                            }
                            else
                            {
                                StreamValidRows.add(streamRow.text);
                            }
                        }
                        Stream.add(StreamValidRows.text);
                        Stream.add(HtmlController.inputHidden("dtfaRecordCount", RecordCount));
                    }
                    Stream.add("</table>");
                    //
                    Stream.add(core.html.getPanelBottom());
                    if (NeedFootNote1)
                    {
                        Stream.add("<br>*Field Inheritance is not allowed because this Content Definition has no parent.");
                    }
                    if (NeedFootNote2)
                    {
                        Stream.add("<br>**This field can not be inherited because the Parent Content Definition does not have a field with the same name.");
                    }
                }
                Stream.add(HtmlController.inputHidden("ReloadCDef", ReloadCDef));
                //
                // -- assemble form
                return(AdminUIController.getToolForm(core, Stream.text, ButtonList));
            } catch (Exception ex) {
                LogController.logError(core, ex);
                return(toolExceptionMessage);
            }
        }
        //
        //=============================================================================
        //   Print the Configure Index Form
        //=============================================================================
        //
        public static string get(CPClass cp, CoreController core, AdminDataModel adminData)
        {
            string result = "";

            try {
                // todo refactor out
                ContentMetadataModel adminContent = adminData.adminContent;
                string Button = core.docProperties.getText(RequestNameButton);
                if (Button == ButtonOK)
                {
                    //
                    // -- Process OK, remove subform from querystring and return empty
                    cp.Doc.AddRefreshQueryString(RequestNameAdminSubForm, "");
                    return(result);
                }
                //
                //   Load Request
                if (Button == ButtonReset)
                {
                    //
                    // -- Process reset
                    core.userProperty.setProperty(AdminDataModel.IndexConfigPrefix + adminContent.id.ToString(), "");
                }
                IndexConfigClass IndexConfig         = IndexConfigClass.get(core, adminData);
                int          ToolsAction             = core.docProperties.getInteger("dta");
                int          TargetFieldId           = core.docProperties.getInteger("fi");
                string       TargetFieldName         = core.docProperties.getText("FieldName");
                int          ColumnPointer           = core.docProperties.getInteger("dtcn");
                const string RequestNameAddField     = "addfield";
                string       FieldNameToAdd          = GenericController.toUCase(core.docProperties.getText(RequestNameAddField));
                const string RequestNameAddFieldId   = "addfieldID";
                int          FieldIDToAdd            = core.docProperties.getInteger(RequestNameAddFieldId);
                bool         normalizeSaveLoad       = core.docProperties.getBoolean("NeedToReloadConfig");
                bool         AllowContentAutoLoad    = false;
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                string Title       = "Set Columns: " + adminContent.name;
                string Description = "Use the icons to add, remove and modify your personal column prefernces for this content (" + adminContent.name + "). Hit OK when complete. Hit Reset to restore your column preferences for this content to the site's default column preferences.";
                Stream.add(AdminUIController.getHeaderTitleDescription(Title, Description));
                //
                //--------------------------------------------------------------------------------
                // Process actions
                //--------------------------------------------------------------------------------
                //
                if (adminContent.id != 0)
                {
                    var CDef             = ContentMetadataModel.create(core, adminContent.id);
                    int ColumnWidthTotal = 0;
                    if (ToolsAction != 0)
                    {
                        //
                        // Block contentautoload, then force a load at the end
                        //
                        AllowContentAutoLoad = (core.siteProperties.getBoolean("AllowContentAutoLoad", true));
                        core.siteProperties.setProperty("AllowContentAutoLoad", false);
                        bool   reloadMetadata  = false;
                        int    SourceContentId = 0;
                        string SourceName      = null;
                        //
                        // Make sure the FieldNameToAdd is not-inherited, if not, create new field
                        //
                        if (FieldIDToAdd != 0)
                        {
                            foreach (KeyValuePair <string, ContentFieldMetadataModel> keyValuePair in adminContent.fields)
                            {
                                ContentFieldMetadataModel field = keyValuePair.Value;
                                if (field.id == FieldIDToAdd)
                                {
                                    if (field.inherited)
                                    {
                                        SourceContentId = field.contentId;
                                        SourceName      = field.nameLc;
                                        //
                                        // -- copy the field
                                        using (var CSSource = new CsModel(core)) {
                                            if (CSSource.open("Content Fields", "(ContentID=" + SourceContentId + ")and(Name=" + DbController.encodeSQLText(SourceName) + ")"))
                                            {
                                                using (var CSTarget = new CsModel(core)) {
                                                    if (CSTarget.insert("Content Fields"))
                                                    {
                                                        CSSource.copyRecord(CSTarget);
                                                        CSTarget.set("ContentID", adminContent.id);
                                                        reloadMetadata = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        //
                        // Make sure all fields are not-inherited, if not, create new fields
                        //
                        foreach (var column in IndexConfig.columns)
                        {
                            ContentFieldMetadataModel field = adminContent.fields[column.Name.ToLowerInvariant()];
                            if (field.inherited)
                            {
                                SourceContentId = field.contentId;
                                SourceName      = field.nameLc;
                                using (var CSSource = new CsModel(core)) {
                                    if (CSSource.open("Content Fields", "(ContentID=" + SourceContentId + ")and(Name=" + DbController.encodeSQLText(SourceName) + ")"))
                                    {
                                        using (var CSTarget = new CsModel(core)) {
                                            if (CSTarget.insert("Content Fields"))
                                            {
                                                CSSource.copyRecord(CSTarget);
                                                CSTarget.set("ContentID", adminContent.id);
                                                reloadMetadata = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //
                        // get current values for Processing
                        //
                        foreach (var column in IndexConfig.columns)
                        {
                            ColumnWidthTotal += column.Width;
                        }
                        //
                        // ----- Perform any actions first
                        //
                        switch (ToolsAction)
                        {
                        case ToolsActionAddField: {
                            //
                            // Add a field to the index form
                            //
                            if (FieldIDToAdd != 0)
                            {
                                IndexConfigColumnClass column = null;
                                foreach (var columnx in IndexConfig.columns)
                                {
                                    columnx.Width = encodeInteger((columnx.Width * 80) / (double)ColumnWidthTotal);
                                }
                                {
                                    column = new IndexConfigColumnClass();
                                    using (var csData = new CsModel(core)) {
                                        if (csData.openRecord("Content Fields", FieldIDToAdd))
                                        {
                                            column.Name  = csData.getText("name");
                                            column.Width = 20;
                                        }
                                    }
                                    IndexConfig.columns.Add(column);
                                    normalizeSaveLoad = true;
                                }
                            }
                            //
                            break;
                        }

                        case ToolsActionRemoveField: {
                            //
                            // Remove a field to the index form
                            int columnWidthTotal = 0;
                            var dstColumns       = new List <IndexConfigColumnClass>();
                            foreach (var column in IndexConfig.columns)
                            {
                                if (column.Name != TargetFieldName.ToLowerInvariant())
                                {
                                    dstColumns.Add(column);
                                    columnWidthTotal += column.Width;
                                }
                            }
                            IndexConfig.columns = dstColumns;
                            normalizeSaveLoad   = true;
                            break;
                        }

                        case ToolsActionMoveFieldLeft: {
                            if (IndexConfig.columns.First().Name != TargetFieldName.ToLowerInvariant())
                            {
                                int listIndex = 0;
                                foreach (var column in IndexConfig.columns)
                                {
                                    if (column.Name == TargetFieldName.ToLowerInvariant())
                                    {
                                        break;
                                    }
                                    listIndex += 1;
                                }
                                IndexConfig.columns.swap(listIndex, listIndex - 1);
                                normalizeSaveLoad = true;
                            }
                            break;
                        }

                        case ToolsActionMoveFieldRight: {
                            if (IndexConfig.columns.Last().Name != TargetFieldName.ToLowerInvariant())
                            {
                                int listIndex = 0;
                                foreach (var column in IndexConfig.columns)
                                {
                                    if (column.Name == TargetFieldName.ToLowerInvariant())
                                    {
                                        break;
                                    }
                                    listIndex += 1;
                                }
                                IndexConfig.columns.swap(listIndex, listIndex + 1);
                                normalizeSaveLoad = true;
                            }
                            break;
                        }

                        case ToolsActionExpand: {
                            foreach (var column in IndexConfig.columns)
                            {
                                if (column.Name == TargetFieldName.ToLowerInvariant())
                                {
                                    column.Width = Convert.ToInt32(Convert.ToDouble(column.Width) * 1.1);
                                }
                                else
                                {
                                    column.Width = Convert.ToInt32(Convert.ToDouble(column.Width) * 0.9);
                                }
                            }
                            normalizeSaveLoad = true;
                            break;
                        }

                        case ToolsActionContract: {
                            foreach (var column in IndexConfig.columns)
                            {
                                if (column.Name != TargetFieldName.ToLowerInvariant())
                                {
                                    column.Width = Convert.ToInt32(Convert.ToDouble(column.Width) * 1.1);
                                }
                                else
                                {
                                    column.Width = Convert.ToInt32(Convert.ToDouble(column.Width) * 0.9);
                                }
                            }
                            normalizeSaveLoad = true;
                            break;
                        }
                        }
                        //
                        // Reload CDef if it changed
                        //
                        if (reloadMetadata)
                        {
                            core.clearMetaData();
                            core.cache.invalidateAll();
                            CDef = ContentMetadataModel.createByUniqueName(core, adminContent.name);
                        }
                        //
                        // save indexconfig
                        //
                        if (normalizeSaveLoad)
                        {
                            //
                            // Normalize the widths of the remaining columns
                            ColumnWidthTotal = 0;
                            foreach (var column in IndexConfig.columns)
                            {
                                ColumnWidthTotal += column.Width;
                            }
                            foreach (var column in IndexConfig.columns)
                            {
                                column.Width = encodeInteger((1000 * column.Width) / (double)ColumnWidthTotal);
                            }
                            GetHtmlBodyClass.setIndexSQL_SaveIndexConfig(cp, core, IndexConfig);
                            IndexConfig = IndexConfigClass.get(core, adminData);
                        }
                    }
                    //
                    //--------------------------------------------------------------------------------
                    //   Display the form
                    //--------------------------------------------------------------------------------
                    //
                    Stream.add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"99%\"><tr>");
                    Stream.add("<td width=\"5%\">&nbsp;</td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>10%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>20%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>30%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>40%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>50%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>60%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>70%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>80%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>90%</nobr></td>");
                    Stream.add("<td width=\"9%\" align=\"center\" class=\"ccAdminSmall\"><nobr>100%</nobr></td>");
                    Stream.add("<td width=\"4%\" align=\"center\">&nbsp;</td>");
                    Stream.add("</tr></table>");
                    //
                    Stream.add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"99%\"><tr>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("<td width=\"9%\"><nobr><img src=\"" + cdnPrefix + "images/black.gif\" width=\"1\" height=\"10\" ><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"100%\" height=\"10\" ></nobr></td>");
                    Stream.add("</tr></table>");
                    //
                    // print the column headers
                    //
                    ColumnWidthTotal = 0;
                    int InheritedFieldCount = 0;
                    if (IndexConfig.columns.Count > 0)
                    {
                        //
                        // Calc total width
                        //
                        foreach (var column in IndexConfig.columns)
                        {
                            ColumnWidthTotal += column.Width;
                        }
                        if (ColumnWidthTotal > 0)
                        {
                            Stream.add("<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"90%\">");
                            //
                            // -- header
                            Stream.add("<tr>");
                            int    ColumnWidth = 0;
                            int    fieldId     = 0;
                            string Caption     = null;
                            foreach (var column in IndexConfig.columns)
                            {
                                //
                                // print column headers - anchored so they sort columns
                                //
                                ColumnWidth = encodeInteger(100 * (column.Width / (double)ColumnWidthTotal));
                                ContentFieldMetadataModel field = adminContent.fields[column.Name.ToLowerInvariant()];
                                fieldId = field.id;
                                Caption = field.caption;
                                if (field.inherited)
                                {
                                    Caption             = Caption + "*";
                                    InheritedFieldCount = InheritedFieldCount + 1;
                                }
                                Stream.add("<td class=\"small\" width=\"" + ColumnWidth + "%\" valign=\"top\" align=\"left\" style=\"background-color:white;border: 1px solid #555;\">" + Caption + "</td>");
                            }
                            Stream.add("</tr>");
                            //
                            // -- body
                            Stream.add("<tr>");
                            foreach (var column in IndexConfig.columns)
                            {
                                //
                                // print column headers - anchored so they sort columns
                                //
                                ColumnWidth = encodeInteger(100 * (column.Width / (double)ColumnWidthTotal));
                                ContentFieldMetadataModel field = adminContent.fields[column.Name.ToLowerInvariant()];
                                fieldId = field.id;
                                Caption = field.caption;
                                if (field.inherited)
                                {
                                    Caption             = Caption + "*";
                                    InheritedFieldCount = InheritedFieldCount + 1;
                                }
                                int    ColumnPtr = 0;
                                string link      = "?" + core.doc.refreshQueryString + "&FieldName=" + HtmlController.encodeHtml(field.nameLc) + "&fi=" + fieldId + "&dtcn=" + ColumnPtr + "&" + RequestNameAdminSubForm + "=" + AdminFormIndex_SubFormSetColumns;
                                Stream.add("<td width=\"" + ColumnWidth + "%\" valign=\"top\" align=\"left\">");
                                Stream.add(HtmlController.div(AdminUIController.getDeleteLink(link + "&dta=" + ToolsActionRemoveField), "text-center"));
                                Stream.add(HtmlController.div(AdminUIController.getArrowRightLink(link + "&dta=" + ToolsActionMoveFieldRight), "text-center"));
                                Stream.add(HtmlController.div(AdminUIController.getArrowLeftLink(link + "&dta=" + ToolsActionMoveFieldLeft), "text-center"));
                                Stream.add(HtmlController.div(AdminUIController.getExpandLink(link + "&dta=" + ToolsActionExpand), "text-center"));
                                Stream.add(HtmlController.div(AdminUIController.getContractLink(link + "&dta=" + ToolsActionContract), "text-center"));
                                Stream.add("</td>");
                            }
                            Stream.add("</tr>");
                            Stream.add("</table>");
                        }
                    }
                    //
                    // ----- If anything was inherited, put up the message
                    //
                    if (InheritedFieldCount > 0)
                    {
                        Stream.add("<p class=\"ccNormal\">* This field was inherited from the Content Definition's Parent. Inherited fields will automatically change when the field in the parent is changed. If you alter these settings, this connection will be broken, and the field will no longer inherit it's properties.</P class=\"ccNormal\">");
                    }
                    //
                    // ----- now output a list of fields to add
                    //
                    if (CDef.fields.Count == 0)
                    {
                        Stream.add(SpanClassAdminNormal + "This Content Definition has no fields</span><br>");
                    }
                    else
                    {
                        foreach (KeyValuePair <string, ContentFieldMetadataModel> keyValuePair in adminContent.fields)
                        {
                            ContentFieldMetadataModel field = keyValuePair.Value;
                            //
                            // display the column if it is not in use
                            if ((IndexConfig.columns.Find(x => x.Name == field.nameLc) == null))
                            {
                                if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.File)
                                {
                                    //
                                    // file can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileText)
                                {
                                    //
                                    // filename can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (text file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileHTML)
                                {
                                    //
                                    // filename can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (html file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileHTMLCode)
                                {
                                    //
                                    // filename can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (html code file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileCSS)
                                {
                                    //
                                    // css filename can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (css file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileXML)
                                {
                                    //
                                    // xml filename can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (xml file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileJavascript)
                                {
                                    //
                                    // javascript filename can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (javascript file field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.LongText)
                                {
                                    //
                                    // can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (long text field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.HTML)
                                {
                                    //
                                    // can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (html field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileImage)
                                {
                                    //
                                    // can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (image field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.Redirect)
                                {
                                    //
                                    // can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (redirect field)"));
                                }
                                else if (field.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.ManyToMany)
                                {
                                    //
                                    // many to many can not be search
                                    Stream.add(HtmlController.div(iconNotAvailable + "&nbsp;" + field.caption + " (many-to-many field)"));
                                }
                                else
                                {
                                    //
                                    // can be used as column header
                                    string link = "?" + core.doc.refreshQueryString + "&fi=" + field.id + "&dta=" + ToolsActionAddField + "&" + RequestNameAddFieldId + "=" + field.id + "&" + RequestNameAdminSubForm + "=" + AdminFormIndex_SubFormSetColumns;
                                    Stream.add(HtmlController.div(AdminUIController.getPlusLink(link, "&nbsp;" + field.caption)));
                                }
                            }
                        }
                    }
                }
                //
                //--------------------------------------------------------------------------------
                // print the content tables that have index forms to Configure
                //--------------------------------------------------------------------------------
                //
                core.siteProperties.setProperty("AllowContentAutoLoad", GenericController.encodeText(AllowContentAutoLoad));
                string Content = ""
                                 + Stream.text
                                 + HtmlController.inputHidden("cid", adminContent.id.ToString())
                                 + HtmlController.inputHidden(rnAdminForm, "1")
                                 + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormSetColumns)
                                 + "";
                //
                // -- assemble form
                result = AdminUIController.getToolForm(core, Content, ButtonOK + "," + ButtonReset);
                core.html.addTitle(Title);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }