//
        //=============================================================================
        // Create a child content
        //=============================================================================
        //
        public static string get(CPClass cp)
        {
            string result = "";

            try {
                //
                bool   IsEmptyList       = false;
                int    ParentContentId   = 0;
                string ChildContentName  = "";
                int    ChildContentId    = 0;
                bool   AddAdminMenuEntry = false;
                StringBuilderLegacyController Content = new StringBuilderLegacyController();
                string FieldValue   = null;
                bool   NewGroup     = false;
                int    GroupId      = 0;
                string NewGroupName = "";
                string Button       = null;
                string Caption      = null;
                string Description  = "";
                string ButtonList   = "";
                bool   BlockForm    = false;
                //
                Button = cp.core.docProperties.getText(RequestNameButton);
                if (Button == ButtonCancel)
                {
                    //
                    //
                    //
                    return(cp.core.webServer.redirect("/" + cp.core.appConfig.adminRoute, "GetContentChildTool, Cancel Button Pressed"));
                }
                else if (!cp.core.session.isAuthenticatedAdmin())
                {
                    //
                    //
                    //
                    ButtonList = ButtonCancel;
                    Content.add(AdminUIController.getFormBodyAdminOnly());
                }
                else
                {
                    //
                    if (Button != ButtonOK)
                    {
                        //
                        // Load defaults
                        //
                        ParentContentId = cp.core.docProperties.getInteger("ParentContentID");
                        if (ParentContentId == 0)
                        {
                            ParentContentId = ContentMetadataModel.getContentId(cp.core, "Page Content");
                        }
                        AddAdminMenuEntry = true;
                        GroupId           = 0;
                    }
                    else
                    {
                        //
                        // Process input
                        //
                        ParentContentId = cp.core.docProperties.getInteger("ParentContentID");
                        var parentContentMetadata = ContentMetadataModel.create(cp.core, ParentContentId);
                        ChildContentName  = cp.core.docProperties.getText("ChildContentName");
                        AddAdminMenuEntry = cp.core.docProperties.getBoolean("AddAdminMenuEntry");
                        GroupId           = cp.core.docProperties.getInteger("GroupID");
                        NewGroup          = cp.core.docProperties.getBoolean("NewGroup");
                        NewGroupName      = cp.core.docProperties.getText("NewGroupName");
                        //
                        if ((parentContentMetadata == null) || (string.IsNullOrEmpty(ChildContentName)))
                        {
                            Processor.Controllers.ErrorController.addUserError(cp.core, "You must select a parent and provide a child name.");
                        }
                        else
                        {
                            //
                            // Create Definition
                            //
                            Description = Description + "<div>&nbsp;</div>"
                                          + "<div>Creating content [" + ChildContentName + "] from [" + parentContentMetadata.name + "]</div>";
                            var childContentMetadata = parentContentMetadata.createContentChild(cp.core, ChildContentName, cp.core.session.user.id);

                            ChildContentId = ContentMetadataModel.getContentId(cp.core, ChildContentName);
                            //
                            // Create Group and Rule
                            //
                            if (NewGroup && (!string.IsNullOrEmpty(NewGroupName)))
                            {
                                using (var csData = new CsModel(cp.core)) {
                                    csData.open("Groups", "name=" + DbController.encodeSQLText(NewGroupName));
                                    if (csData.ok())
                                    {
                                        Description = Description + "<div>Group [" + NewGroupName + "] already exists, using existing group.</div>";
                                        GroupId     = csData.getInteger("ID");
                                    }
                                    else
                                    {
                                        Description = Description + "<div>Creating new group [" + NewGroupName + "]</div>";
                                        csData.close();
                                        csData.insert("Groups");
                                        if (csData.ok())
                                        {
                                            GroupId = csData.getInteger("ID");
                                            csData.set("Name", NewGroupName);
                                            csData.set("Caption", NewGroupName);
                                        }
                                    }
                                }
                            }
                            if (GroupId != 0)
                            {
                                using (var csData = new CsModel(cp.core)) {
                                    csData.insert("Group Rules");
                                    if (csData.ok())
                                    {
                                        Description = Description + "<div>Assigning group [" + MetadataController.getRecordName(cp.core, "Groups", GroupId) + "] to edit content [" + ChildContentName + "].</div>";
                                        csData.set("GroupID", GroupId);
                                        csData.set("ContentID", ChildContentId);
                                    }
                                }
                            }
                            //
                            // Add Admin Menu Entry
                            //
                            if (AddAdminMenuEntry)
                            {
                                //
                                // Add Navigator entries
                            }
                            //
                            Description = Description + "<div>&nbsp;</div>"
                                          + "<div>Your new content is ready. <a href=\"?" + rnAdminForm + "=22\">Click here</a> to create another Content Definition, or hit [Cancel] to return to the main menu.</div>";
                            ButtonList = ButtonCancel;
                            BlockForm  = true;
                        }
                        cp.core.clearMetaData();
                        cp.core.cache.invalidateAll();
                    }
                    //
                    // Get the form
                    //
                    if (!BlockForm)
                    {
                        string tableBody = "";
                        //
                        FieldValue = "<select size=\"1\" name=\"ParentContentID\" ID=\"\"><option value=\"\">Select One</option>";
                        FieldValue = FieldValue + GetContentChildTool_Options(cp, 0, ParentContentId);
                        FieldValue = FieldValue + "</select>";
                        tableBody += AdminUIController.getEditRowLegacy(cp.core, FieldValue, "Parent Content Name", "", false, false, "");
                        //
                        FieldValue = HtmlController.inputText_Legacy(cp.core, "ChildContentName", ChildContentName, 1, 40);
                        tableBody += AdminUIController.getEditRowLegacy(cp.core, FieldValue, "New Child Content Name", "", false, false, "");
                        //
                        FieldValue = ""
                                     + HtmlController.inputRadio("NewGroup", false.ToString(), NewGroup.ToString()) + cp.core.html.selectFromContent("GroupID", GroupId, "Groups", "", "", "", ref IsEmptyList) + "(Select a current group)"
                                     + "<br>" + HtmlController.inputRadio("NewGroup", true.ToString(), NewGroup.ToString()) + HtmlController.inputText_Legacy(cp.core, "NewGroupName", NewGroupName) + "(Create a new group)";
                        tableBody += AdminUIController.getEditRowLegacy(cp.core, FieldValue, "Content Manager Group", "", false, false, "");
                        //
                        Content.add(AdminUIController.editTable(tableBody));
                        Content.add("</td></tr>" + kmaEndTable);
                        //
                        ButtonList = ButtonOK + "," + ButtonCancel;
                    }
                    Content.add(HtmlController.inputHidden(rnAdminSourceForm, AdminFormContentChildTool));
                }
                //
                Caption     = "Create Content Definition";
                Description = "<div>This tool is used to create content definitions that help segregate your content into authorable segments.</div>" + Description;
                result      = AdminUIController.getToolBody(cp.core, Caption, ButtonList, "", false, false, Description, "", 0, Content.text);
            } catch (Exception ex) {
                LogController.logError(cp.core, ex);
            }
            return(result);
        }
Пример #2
0
        //
        //====================================================================================================
        /// <summary>
        /// Process manual changes needed for special cases
        /// </summary>
        /// <param name="isDelete"></param>
        /// <param name="contentName"></param>
        /// <param name="recordId"></param>
        /// <param name="recordName"></param>
        /// <param name="recordParentID"></param>
        /// <param name="useContentWatchLink"></param>
        public static void processAfterSave(CoreController core, bool isDelete, string contentName, int recordId, string recordName, int recordParentID, bool useContentWatchLink)
        {
            try {
                PageContentModel.markReviewed(core.cpParent, recordId);
                string tableName = MetadataController.getContentTablename(core, contentName);
                //
                // -- invalidate the specific cache for this record
                core.cache.invalidateDbRecord(recordId, tableName);
                //
                string tableNameLower = tableName.ToLower(CultureInfo.InvariantCulture);
                if (tableNameLower == AddonCollectionModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- addon collection
                    processAfterSave_AddonCollection(core, isDelete, contentName, recordId, recordName, recordParentID, useContentWatchLink);
                }
                else if (tableNameLower == LinkForwardModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- link forward
                    core.routeMapCacheClear();
                }
                else if (tableNameLower == LinkAliasModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- link alias
                    core.routeMapCacheClear();
                }
                else if (tableNameLower == AddonModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- addon
                    core.routeMapCacheClear();
                }
                else if (tableNameLower == PersonModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- PersonModel
                    var person = PersonModel.create <PersonModel>(core.cpParent, recordId);
                    if (person != null)
                    {
                        if (isDelete)
                        {
                            LogController.addSiteActivity(core, "deleting user #" + recordId + " (" + recordName + ")", recordId, person.organizationId);
                        }
                        else
                        {
                            LogController.addSiteActivity(core, "saving changes to user #" + recordId + " (" + recordName + ")", recordId, person.organizationId);
                        }
                    }
                }
                else if (tableNameLower == OrganizationModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- Log Activity for changes to people and organizattions
                    if (isDelete)
                    {
                        LogController.addSiteActivity(core, "deleting organization #" + recordId + " (" + recordName + ")", 0, recordId);
                    }
                    else
                    {
                        LogController.addSiteActivity(core, "saving changes to organization #" + recordId + " (" + recordName + ")", 0, recordId);
                    }
                }
                else if (tableNameLower == SitePropertyModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- Site Properties
                    switch (GenericController.toLCase(recordName))
                    {
                    case "allowlinkalias":
                        PageContentModel.invalidateCacheOfTable <PageContentModel>(core.cpParent);
                        break;

                    case "sectionlandinglink":
                        PageContentModel.invalidateCacheOfTable <PageContentModel>(core.cpParent);
                        break;

                    case Constants._siteproperty_serverPageDefault_name:
                        PageContentModel.invalidateCacheOfTable <PageContentModel>(core.cpParent);
                        break;
                    }
                }
                else if (tableNameLower == PageContentModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- set ChildPagesFound true for parent page
                    if (recordParentID > 0)
                    {
                        if (!isDelete)
                        {
                            core.db.executeNonQuery("update ccpagecontent set ChildPagesfound=1 where ID=" + recordParentID);
                        }
                    }
                    if (isDelete)
                    {
                        //
                        // Clear the Landing page and page not found site properties
                        if (recordId == GenericController.encodeInteger(core.siteProperties.getText("PageNotFoundPageID", "0")))
                        {
                            core.siteProperties.setProperty("PageNotFoundPageID", "0");
                        }
                        if (recordId == core.siteProperties.landingPageID)
                        {
                            core.siteProperties.setProperty("landingPageId", "0");
                        }
                        //
                        // Delete Link Alias entries with this PageID
                        core.db.executeNonQuery("delete from cclinkAliases where PageID=" + recordId);
                    }
                    DbBaseModel.invalidateCacheOfRecord <PageContentModel>(core.cpParent, recordId);
                }
                else if (tableNameLower == LibraryFilesModel.tableMetadata.tableNameLower)
                {
                    //
                    // --
                    processAfterSave_LibraryFiles(core, isDelete, contentName, recordId, recordName, recordParentID, useContentWatchLink);
                }
                //
                // Process Addons marked to trigger a process call on content change
                //
                Dictionary <string, string> instanceArguments;
                bool onChangeAddonsAsync = core.siteProperties.getBoolean("execute oncontentchange addons async", false);
                using (var csData = new CsModel(core)) {
                    int contentId = ContentMetadataModel.getContentId(core, contentName);
                    csData.open("Add-on Content Trigger Rules", "ContentID=" + contentId, "", false, 0, "addonid");
                    string Option_String = null;
                    if (isDelete)
                    {
                        instanceArguments = new Dictionary <string, string> {
                            { "action", "contentdelete" },
                            { "contentid", contentId.ToString() },
                            { "recordid", recordId.ToString() }
                        };
                        Option_String = ""
                                        + Environment.NewLine + "action=contentdelete"
                                        + Environment.NewLine + "contentid=" + contentId
                                        + Environment.NewLine + "recordid=" + recordId + "";
                    }
                    else
                    {
                        instanceArguments = new Dictionary <string, string> {
                            { "action", "contentchange" },
                            { "contentid", contentId.ToString() },
                            { "recordid", recordId.ToString() }
                        };
                        Option_String = ""
                                        + Environment.NewLine + "action=contentchange"
                                        + Environment.NewLine + "contentid=" + contentId
                                        + Environment.NewLine + "recordid=" + recordId + "";
                    }
                    while (csData.ok())
                    {
                        var addon = DbBaseModel.create <AddonModel>(core.cpParent, csData.getInteger("Addonid"));
                        if (addon != null)
                        {
                            if (onChangeAddonsAsync)
                            {
                                //
                                // -- execute addon async
                                core.addon.executeAsync(addon, instanceArguments);
                            }
                            else
                            {
                                //
                                // -- execute addon
                                core.addon.execute(addon, new CPUtilsBaseClass.addonExecuteContext {
                                    addonType             = CPUtilsBaseClass.addonContext.ContextOnContentChange,
                                    backgroundProcess     = false,
                                    errorContextMessage   = "",
                                    argumentKeyValuePairs = instanceArguments
                                });
                            }
                        }
                        csData.goNext();
                    }
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
        }
Пример #3
0
 //
 //====================================================================================================
 //
 public override void DeleteContent(string contentName)
 {
     DbBaseModel.delete <ContentModel>(cp, ContentMetadataModel.getContentId(cp.core, contentName));
 }
        //
        //====================================================================================================
        //
        public static string get(CoreController core)
        {
            string result = "";

            try {
                //
                int    ContentId   = 0;
                string TableName   = "";
                string ContentName = "";
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                string          ButtonList           = null;
                string          Description          = null;
                string          Caption     = null;
                int             NavId       = 0;
                int             ParentNavId = 0;
                DataSourceModel datasource  = DataSourceModel.create(core.cpParent, core.docProperties.getInteger("DataSourceID"));
                //
                ButtonList  = ButtonCancel + "," + ButtonRun;
                Caption     = "Create Content Definition";
                Description = "This tool creates a Content Definition. If the SQL table exists, it is used. If it does not exist, it is created. If records exist in the table with a blank ContentControlID, the ContentControlID will be populated from this new definition. A Navigator Menu entry will be added under Manage Site Content - Advanced.";
                //
                //   print out the submit form
                //
                if (core.docProperties.getText("Button") != "")
                {
                    //
                    // Process input
                    //
                    ContentName = core.docProperties.getText("ContentName");
                    TableName   = core.docProperties.getText("TableName");
                    //
                    Stream.add(SpanClassAdminSmall);
                    Stream.add("<P>Creating content [" + ContentName + "] on table [" + TableName + "] on Datasource [" + datasource.name + "].</P>");
                    if ((!string.IsNullOrEmpty(ContentName)) && (!string.IsNullOrEmpty(TableName)) && (!string.IsNullOrEmpty(datasource.name)))
                    {
                        using (var db = new DbController(core, datasource.name)) {
                            db.createSQLTable(TableName);
                        }
                        ContentMetadataModel.createFromSQLTable(core, datasource, TableName, ContentName);
                        core.cache.invalidateAll();
                        core.clearMetaData();
                        ContentId   = Processor.Models.Domain.ContentMetadataModel.getContentId(core, ContentName);
                        ParentNavId = MetadataController.getRecordIdByUniqueName(core, NavigatorEntryModel.tableMetadata.contentName, "Manage Site Content");
                        if (ParentNavId != 0)
                        {
                            ParentNavId = 0;
                            using (var csSrc = new CsModel(core)) {
                                if (csSrc.open(NavigatorEntryModel.tableMetadata.contentName, "(name=" + DbController.encodeSQLText("Advanced") + ")and(parentid=" + ParentNavId + ")"))
                                {
                                    ParentNavId = csSrc.getInteger("ID");
                                }
                            }
                            if (ParentNavId != 0)
                            {
                                using (var csDest = new CsModel(core)) {
                                    csDest.open(NavigatorEntryModel.tableMetadata.contentName, "(name=" + DbController.encodeSQLText(ContentName) + ")and(parentid=" + NavId + ")");
                                    if (!csDest.ok())
                                    {
                                        csDest.close();
                                        csDest.insert(NavigatorEntryModel.tableMetadata.contentName);
                                    }
                                    if (csDest.ok())
                                    {
                                        csDest.set("name", ContentName);
                                        csDest.set("parentid", ParentNavId);
                                        csDest.set("contentid", ContentId);
                                    }
                                }
                            }
                        }
                        ContentId = ContentMetadataModel.getContentId(core, ContentName);
                        Stream.add("<P>Content Definition was created. An admin menu entry for this definition has been added under 'Site Content', and will be visible on the next page view. Use the [<a href=\"?af=105&ContentID=" + ContentId + "\">Edit Content Definition Fields</a>] tool to review and edit this definition's fields.</P>");
                    }
                    else
                    {
                        Stream.add("<P>Error, a required field is missing. Content not created.</P>");
                    }
                    Stream.add("</SPAN>");
                }
                Stream.add(SpanClassAdminNormal);
                Stream.add("Data Source<br>");
                Stream.add(core.html.selectFromContent("DataSourceID", datasource.id, "Data Sources", "", "Default"));
                Stream.add("<br><br>");
                Stream.add("Content Name<br>");
                Stream.add(HtmlController.inputText_Legacy(core, "ContentName", ContentName, 1, 40));
                Stream.add("<br><br>");
                Stream.add("Table Name<br>");
                Stream.add(HtmlController.inputText_Legacy(core, "TableName", TableName, 1, 40));
                Stream.add("<br><br>");
                Stream.add("</SPAN>");
                result = AdminUIController.getToolBody(core, Caption, ButtonList, "", false, false, Description, "", 10, Stream.text);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
Пример #5
0
        //
        // ====================================================================================================
        /// <summary>
        /// Create the tabs for editing a record
        /// </summary>
        /// <param name="adminData.content"></param>
        /// <param name="editRecord"></param>
        /// <returns></returns>
        public static string get(CoreController core, AdminDataModel adminData)
        {
            string returnHtml = "";

            try {
                //
                if ((!core.doc.userErrorList.Count.Equals(0)) && adminData.editRecord.loaded)
                {
                    //
                    // block load if there was a user error and it is already loaded (assume error was from response )
                }
                else if (adminData.adminContent.id <= 0)
                {
                    //
                    // Invalid Content
                    Processor.Controllers.ErrorController.addUserError(core, "There was a problem identifying the content you requested. Please return to the previous form and verify your selection.");
                    return("");
                }
                else if (adminData.editRecord.loaded && !adminData.editRecord.saved)
                {
                    //
                    //   File types need to be reloaded from the Db, because...
                    //       LoadDb - sets them to the path-page
                    //       LoadResponse - sets the blank if no change, filename if there is an upload
                    //       SaveEditRecord - if blank, no change. If a filename it saves the uploaded file
                    //       GetForm_Edit - expects the Db value to be in EditRecordValueVariants (path-page)
                    //
                    // xx This was added to bypass the load for the editrefresh case (reload the response so the editor preference can change)
                    // xx  I do not know why the following section says "reload even if it is loaded", but lets try this
                    //
                    foreach (var keyValuePair in adminData.adminContent.fields)
                    {
                        ContentFieldMetadataModel field = keyValuePair.Value;
                        if ((keyValuePair.Value.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.File) || (keyValuePair.Value.fieldTypeId == CPContentBaseClass.FieldTypeIdEnum.FileImage))
                        {
                            adminData.editRecord.fieldsLc[field.nameLc].value = adminData.editRecord.fieldsLc[field.nameLc].dbValue;
                        }
                    }
                }
                else
                {
                    //
                    // otherwise, load the record, even if it was loaded during a previous form process
                    adminData.loadEditRecord(core, true);
                }
                if (!AdminDataModel.userHasContentAccess(core, ((adminData.editRecord.contentControlId.Equals(0)) ? adminData.adminContent.id : adminData.editRecord.contentControlId)))
                {
                    Processor.Controllers.ErrorController.addUserError(core, "Your account on this system does not have access rights to edit this content.");
                    return("");
                }
                //
                // Setup Edit Referer
                string EditReferer = core.docProperties.getText(RequestNameEditReferer);
                if (string.IsNullOrEmpty(EditReferer))
                {
                    EditReferer = core.webServer.requestReferer;
                    if (!string.IsNullOrEmpty(EditReferer))
                    {
                        //
                        // special case - if you are coming from the advanced search, go back to the list page
                        EditReferer = GenericController.strReplace(EditReferer, "&af=39", "");
                        //
                        // if referer includes AdminWarningMsg (admin hint message), remove it -- this edit may fix the problem
                        int Pos = EditReferer.IndexOf("AdminWarningMsg=", StringComparison.CurrentCulture);
                        if (Pos >= 0)
                        {
                            EditReferer = EditReferer.left(Pos - 2);
                        }
                    }
                }
                core.doc.addRefreshQueryString(RequestNameEditReferer, EditReferer);
                //
                // load user's editor preferences to fieldEditorPreferences() - this is the editor this user has picked when there are >1
                //   fieldId:addonId,fieldId:addonId,etc
                //   with custom FancyBox form in edit window with button "set editor preference"
                //   this button causes a 'refresh' action, reloads fields with stream without save
                //
                //
                // ----- determine contentType for editor
                //
                CPHtml5BaseClass.EditorContentType contentType;
                if (GenericController.toLCase(adminData.adminContent.name) == "email templates")
                {
                    contentType = CPHtml5BaseClass.EditorContentType.contentTypeEmailTemplate;
                }
                else if (GenericController.toLCase(adminData.adminContent.tableName) == "cctemplates")
                {
                    contentType = CPHtml5BaseClass.EditorContentType.contentTypeWebTemplate;
                }
                else if (GenericController.toLCase(adminData.adminContent.tableName) == "ccemail")
                {
                    contentType = CPHtml5BaseClass.EditorContentType.contentTypeEmail;
                }
                else
                {
                    contentType = CPHtml5BaseClass.EditorContentType.contentTypeWeb;
                }

                EditorEnvironmentModel editorEnv = new EditorEnvironmentModel {
                    allowHelpMsgCustom     = false,
                    editorAddonListJSON    = core.html.getWysiwygAddonList(contentType),
                    isRootPage             = adminData.adminContent.tableName.ToLowerInvariant().Equals(PageContentModel.tableMetadata.tableNameLower) && (adminData.editRecord.parentId == 0) && (adminData.editRecord.id != 0),
                    needUniqueEmailMessage = false,
                    record_readOnly        = adminData.editRecord.userReadOnly,
                    styleList       = "",
                    styleOptionList = "",
                    formFieldList   = ""
                };
                //
                // ----- determine access details
                var  userContentPermissions = PermissionController.getUserContentPermissions(core, adminData.adminContent);
                bool allowDelete            = adminData.adminContent.allowDelete && userContentPermissions.allowDelete && (adminData.editRecord.id != 0);
                bool allowAdd          = adminData.adminContent.allowAdd && userContentPermissions.allowAdd;
                var  editButtonBarInfo = new EditButtonBarInfoClass(core, adminData, allowDelete, true, userContentPermissions.allowSave, allowAdd);
                //
                string adminContentTableNameLc = adminData.adminContent.tableName.ToLowerInvariant();
                bool   allowLinkAlias          = adminContentTableNameLc.Equals(PageContentModel.tableMetadata.tableNameLower);
                bool   allowPeopleGroups       = adminContentTableNameLc.Equals(PersonModel.tableMetadata.tableNameLower);;
                //
                //-----Create edit page
                if (adminContentTableNameLc.Equals(EmailModel.tableMetadata.tableNameLower))
                {
                    //
                    LogController.logTrace(core, "getFormEdit, treat as email, adminContentTableNameLower [" + adminContentTableNameLc + "]");
                    //
                    // -- email
                    bool     emailSubmitted            = false;
                    bool     emailSent                 = false;
                    DateTime LastSendTestDate          = DateTime.MinValue;
                    bool     AllowEmailSendWithoutTest = (core.siteProperties.getBoolean("AllowEmailSendWithoutTest", false));
                    if (adminData.editRecord.fieldsLc.ContainsKey("lastsendtestdate"))
                    {
                        LastSendTestDate = GenericController.encodeDate(adminData.editRecord.fieldsLc["lastsendtestdate"].value);
                    }
                    if (adminData.adminContent.id.Equals(ContentMetadataModel.getContentId(core, "System Email")))
                    {
                        //
                        LogController.logTrace(core, "getFormEdit, System email");
                        //
                        // System Email
                        emailSubmitted = false;
                        if (adminData.editRecord.id != 0)
                        {
                            if (adminData.editRecord.fieldsLc.ContainsKey("testmemberid"))
                            {
                                if (encodeInteger(adminData.editRecord.fieldsLc["testmemberid"].value) == 0)
                                {
                                    adminData.editRecord.fieldsLc["testmemberid"].value = core.session.user.id;
                                }
                            }
                        }
                        editButtonBarInfo.allowSave     = (userContentPermissions.allowSave && adminData.editRecord.allowUserSave && (!emailSubmitted) && (!emailSent));
                        editButtonBarInfo.allowSendTest = ((!emailSubmitted) && (!emailSent));
                    }
                    else if (adminData.adminContent.id.Equals(ContentMetadataModel.getContentId(core, "Conditional Email")))
                    {
                        //
                        // Conditional Email
                        emailSubmitted            = false;
                        editorEnv.record_readOnly = adminData.editRecord.userReadOnly || emailSubmitted;
                        if (adminData.editRecord.id != 0)
                        {
                            if (adminData.editRecord.fieldsLc.ContainsKey("submitted"))
                            {
                                emailSubmitted = GenericController.encodeBoolean(adminData.editRecord.fieldsLc["submitted"].value);
                            }
                        }
                        editButtonBarInfo.allowActivate   = !emailSubmitted && ((LastSendTestDate != DateTime.MinValue) || AllowEmailSendWithoutTest);
                        editButtonBarInfo.allowDeactivate = emailSubmitted;
                        editButtonBarInfo.allowSave       = userContentPermissions.allowSave && adminData.editRecord.allowUserSave && !emailSubmitted;
                    }
                    else
                    {
                        //
                        // Group Email
                        if (adminData.editRecord.id != 0)
                        {
                            emailSubmitted = encodeBoolean(adminData.editRecord.fieldsLc["submitted"].value);
                            emailSent      = encodeBoolean(adminData.editRecord.fieldsLc["sent"].value);
                        }
                        editButtonBarInfo.allowSave     = !emailSubmitted && (userContentPermissions.allowSave && adminData.editRecord.allowUserSave);
                        editButtonBarInfo.allowSend     = !emailSubmitted && ((LastSendTestDate != DateTime.MinValue) || AllowEmailSendWithoutTest);
                        editButtonBarInfo.allowSendTest = !emailSubmitted;
                        editorEnv.record_readOnly       = adminData.editRecord.userReadOnly || emailSubmitted || emailSent;
                    }
                }
                else if (adminContentTableNameLc.Equals(PageContentModel.tableMetadata.tableNameLower))
                {
                    //
                    // Page Content
                    //
                    editButtonBarInfo.allowMarkReviewed = true;
                    editButtonBarInfo.isPageContent     = true;
                    editButtonBarInfo.hasChildRecords   = true;
                    allowLinkAlias = true;
                }
                else
                {
                    //
                    // All other tables (User definined)
                    var pageContentMetadata = ContentMetadataModel.createByUniqueName(core, "page content");
                    editButtonBarInfo.isPageContent     = pageContentMetadata.isParentOf(core, adminData.adminContent.id);
                    editButtonBarInfo.hasChildRecords   = adminData.adminContent.containsField(core, "parentid");
                    editButtonBarInfo.allowMarkReviewed = core.db.isSQLTableField(adminData.adminContent.tableName, "DateReviewed");
                }
                //
                // Print common form elements
                var Stream = new StringBuilderLegacyController();
                Stream.add("\r<input type=\"hidden\" name=\"fieldEditorPreference\" id=\"fieldEditorPreference\" value=\"\">");
                string editSectionButtonBar = AdminUIController.getSectionButtonBarForEdit(core, editButtonBarInfo);
                Stream.add(editSectionButtonBar);
                var headerInfo = new RecordEditHeaderInfoClass {
                    recordId              = adminData.editRecord.id,
                    recordLockById        = adminData.editRecord.editLock.editLockByMemberId,
                    recordLockExpiresDate = encodeDate(adminData.editRecord.editLock.editLockExpiresDate),
                    recordName            = adminData.editRecord.nameLc
                };
                string titleBarDetails = AdminUIController.getEditForm_TitleBarDetails(core, headerInfo, adminData.editRecord);
                Stream.add(AdminUIController.getSectionHeader(core, "", titleBarDetails));
                {
                    var editTabs = new EditTabModel();
                    EditViewTabList.addContentTabs(core, adminData, editTabs, editorEnv);
                    if (allowPeopleGroups)
                    {
                        EditViewTabList.addCustomTab(core, editTabs, "Groups", GroupRuleEditor.get(core, adminData));
                    }
                    if (allowLinkAlias)
                    {
                        EditViewTabList.addCustomTab(core, editTabs, "Link Aliases", LinkAliasEditor.getForm_Edit_LinkAliases(core, adminData, adminData.editRecord.userReadOnly));
                    }
                    EditViewTabList.addCustomTab(core, editTabs, "Control&nbsp;Info", EditViewTabControlInfo.get(core, adminData, editorEnv));
                    Stream.add(editTabs.getTabs(core));
                }
                Stream.add(editSectionButtonBar);
                Stream.add(HtmlController.inputHidden("FormFieldList", editorEnv.formFieldList));
                returnHtml = wrapForm(core, Stream.text, adminData, AdminFormEdit);
                //
                // -- update page title
                if (adminData.editRecord.id == 0)
                {
                    core.html.addTitle("Add " + adminData.adminContent.name);
                }
                else if (adminData.editRecord.nameLc == "")
                {
                    core.html.addTitle("Edit #" + adminData.editRecord.id + " in " + adminData.editRecord.contentControlId_Name);
                }
                else
                {
                    core.html.addTitle("Edit " + adminData.editRecord.nameLc + " in " + adminData.editRecord.contentControlId_Name);
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnHtml);
        }
Пример #6
0
 //
 //
 //
 //========================================================================
 /// <summary>
 /// Set a site property
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="Value"></param>
 public void setProperty(string propertyName, string Value)
 {
     try {
         if (dbNotReady)
         {
             //
             // -- cannot set property
             throw new GenericException("Cannot set site property before Db is ready.");
         }
         else
         {
             if (!string.IsNullOrEmpty(propertyName.Trim()))
             {
                 if (propertyName.ToLowerInvariant().Equals("adminurl"))
                 {
                     //
                     // -- intercept adminUrl for compatibility, always use admin route instead
                 }
                 else
                 {
                     //
                     // -- set value in Db
                     string SQLNow          = DbController.encodeSQLDate(core.dateTimeNowMockable);
                     string SQL             = "UPDATE ccSetup Set FieldValue=" + DbController.encodeSQLText(Value) + ",ModifiedDate=" + SQLNow + " WHERE name=" + DbController.encodeSQLText(propertyName);
                     int    recordsAffected = 0;
                     core.db.executeNonQuery(SQL, ref recordsAffected);
                     if (recordsAffected == 0)
                     {
                         SQL = "INSERT INTO ccSetup (ACTIVE,CONTENTCONTROLID,NAME,FIELDVALUE,ModifiedDate,DateAdded)VALUES("
                               + DbController.SQLTrue + "," + DbController.encodeSQLNumber(ContentMetadataModel.getContentId(core, "site properties")) + "," + DbController.encodeSQLText(propertyName.ToUpper()) + "," + DbController.encodeSQLText(Value) + "," + SQLNow + "," + SQLNow + ");";
                         core.db.executeNonQuery(SQL);
                     }
                     //
                     // -- set simple lazy cache
                     string cacheName = getNameValueDictKey(propertyName);
                     if (nameValueDict.ContainsKey(cacheName))
                     {
                         nameValueDict.Remove(cacheName);
                     }
                     nameValueDict.Add(cacheName, Value);
                 }
             }
         }
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
        //
        //=============================================================================
        /// <summary>
        /// Remove all Content Fields and rebuild them from the fields found in a table
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        //
        public static string get(CoreController core)
        {
            string result = "";

            try {
                string Button = core.docProperties.getText("Button");
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                //
                //   print out the submit form
                //
                Stream.add("<table border=\"0\" cellpadding=\"11\" cellspacing=\"0\" width=\"100%\">");
                //
                Stream.add("<tr><td colspan=\"2\">" + SpanClassAdminNormal);
                Stream.add("Delete the current content field definitions for this Content Definition, and recreate them from the table referenced by this content.");
                Stream.add("</SPAN></td></tr>");
                //
                Stream.add("<tr>");
                Stream.add("<TD>" + SpanClassAdminNormal + "Content Name</SPAN></td>");
                Stream.add("<TD><Select name=\"ContentName\">");
                int ItemCount = 0;
                using (var csData = new CsModel(core)) {
                    csData.open("Content", "", "name");
                    while (csData.ok())
                    {
                        Stream.add("<option value=\"" + csData.getText("name") + "\">" + csData.getText("name") + "</option>");
                        ItemCount = ItemCount + 1;
                        csData.goNext();
                    }
                }
                if (ItemCount == 0)
                {
                    Stream.add("<option value=\"-1\">System</option>");
                }
                Stream.add("</select></td>");
                Stream.add("</tr>");
                //
                Stream.add("<tr>");
                Stream.add("<TD>&nbsp;</td>");
                Stream.add("<TD>" + HtmlController.inputSubmit(ButtonCreateFields) + "</td>");
                Stream.add("</tr>");
                //
                Stream.add("<tr>");
                Stream.add("<td width=\"150\"><IMG alt=\"\" src=\"" + cdnPrefix + "Images/spacer.gif\" width=\"150\" height=\"1\"></td>");
                Stream.add("<td width=\"99%\"><IMG alt=\"\" src=\"" + cdnPrefix + "Images/spacer.gif\" width=\"100%\" height=\"1\"></td>");
                Stream.add("</tr>");
                Stream.add("</TABLE>");
                Stream.add("</form>");
                //
                //   process the button if present
                //
                if (Button == ButtonCreateFields)
                {
                    string ContentName = core.docProperties.getText("ContentName");
                    if (string.IsNullOrEmpty(ContentName))
                    {
                        Stream.add("Select a content before submitting. Fields were not changed.");
                    }
                    else
                    {
                        int ContentId = ContentMetadataModel.getContentId(core, ContentName);
                        if (ContentId == 0)
                        {
                            Stream.add("GetContentID failed. Fields were not changed.");
                        }
                        else
                        {
                            MetadataController.deleteContentRecords(core, "Content Fields", "ContentID=" + DbController.encodeSQLNumber(ContentId));
                            //
                            // todo -- looks like the tool code did not come with the migration ?
                            //
                        }
                    }
                }
                string ButtonList = "";
                result = AdminUIController.getToolForm(core, Stream.text, ButtonList);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }