// //======================================================================== // public static string get(CoreController core) { try { // string Button = null; string SQL = null; string RQS = null; int PageSize = 0; int PageNumber = 0; int TopCount = 0; int RowPointer = 0; int DataRowCount = 0; string PreTableCopy = ""; string PostTableCopy = ""; int ColumnPtr = 0; string[] ColCaption = null; string[] ColAlign = null; string[] ColWidth = null; string[,] Cells = null; string AdminURL = null; int RowCnt = 0; int RowPtr = 0; int ContentId = 0; string Format = null; string Name = null; string title = null; string Description = null; string ButtonCommaListLeft = null; string ButtonCommaListRight = null; int ContentPadding = 0; string ContentSummary = ""; StringBuilderLegacyController Tab0 = new StringBuilderLegacyController(); StringBuilderLegacyController Tab1 = new StringBuilderLegacyController(); string Content = ""; string SQLFieldName = null; var adminMenu = new EditTabModel(); // const int ColumnCnt = 4; // Button = core.docProperties.getText(RequestNameButton); ContentId = core.docProperties.getInteger("ContentID"); Format = core.docProperties.getText("Format"); // title = "Custom Report Manager"; Description = "Custom Reports are a way for you to create a snapshot of data to view or download. To request a report, select the Custom Reports tab, check the report(s) you want, and click the [Request Download] Button. When your report is ready, it will be available in the <a href=\"?" + rnAdminForm + "=30\">Download Manager</a>. To create a new custom report, select the Request New Report tab, enter a name and SQL statement, and click the Apply button."; ContentPadding = 0; ButtonCommaListLeft = ButtonCancel + "," + ButtonDelete + "," + ButtonRequestDownload; ButtonCommaListRight = ""; SQLFieldName = "SQLQuery"; // if (!core.session.isAuthenticatedAdmin()) { // // Must be a developer // Description = Description + "You can not access the Custom Report Manager because your account is not configured as an administrator."; } else { // // Process Requests // if (!string.IsNullOrEmpty(Button)) { switch (Button) { case ButtonCancel: return(core.webServer.redirect("/" + core.appConfig.adminRoute, "CustomReports, Cancel Button Pressed")); case ButtonDelete: RowCnt = core.docProperties.getInteger("RowCnt"); if (RowCnt > 0) { for (RowPtr = 0; RowPtr < RowCnt; RowPtr++) { if (core.docProperties.getBoolean("Row" + RowPtr)) { MetadataController.deleteContentRecord(core, "Custom Reports", core.docProperties.getInteger("RowID" + RowPtr)); } } } break; case ButtonRequestDownload: case ButtonApply: // Name = core.docProperties.getText("name"); SQL = core.docProperties.getText(SQLFieldName); if (!string.IsNullOrEmpty(Name) || !string.IsNullOrEmpty(SQL)) { if ((string.IsNullOrEmpty(Name)) || (string.IsNullOrEmpty(SQL))) { Processor.Controllers.ErrorController.addUserError(core, "A name and SQL Query are required to save a new custom report."); } else { int customReportId = 0; using (var csData = new CsModel(core)) { csData.insert("Custom Reports"); if (csData.ok()) { customReportId = csData.getInteger("id"); csData.set("Name", Name); csData.set(SQLFieldName, SQL); } csData.close(); } requestDownload(core, customReportId); } } // RowCnt = core.docProperties.getInteger("RowCnt"); if (RowCnt > 0) { for (RowPtr = 0; RowPtr < RowCnt; RowPtr++) { if (core.docProperties.getBoolean("Row" + RowPtr)) { int customReportId = core.docProperties.getInteger("RowID" + RowPtr); using (var csData = new CsModel(core)) { csData.openRecord("Custom Reports", customReportId); if (csData.ok()) { SQL = csData.getText(SQLFieldName); Name = csData.getText("Name"); } } requestDownload(core, customReportId); } } } break; } } // // Build Tab0 // Tab0.add("<p>The following is a list of available custom reports.</p>"); // RQS = core.doc.refreshQueryString; PageSize = core.docProperties.getInteger(RequestNamePageSize); if (PageSize == 0) { PageSize = 50; } PageNumber = core.docProperties.getInteger(RequestNamePageNumber); if (PageNumber == 0) { PageNumber = 1; } AdminURL = "/" + core.appConfig.adminRoute; TopCount = PageNumber * PageSize; // // Setup Headings // ColCaption = new string[ColumnCnt + 1]; ColAlign = new string[ColumnCnt + 1]; ColWidth = new string[ColumnCnt + 1]; Cells = new string[PageSize + 1, ColumnCnt + 1]; // ColCaption[ColumnPtr] = "Select<br><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=10 height=1>"; ColAlign[ColumnPtr] = "center"; ColWidth[ColumnPtr] = "10"; ColumnPtr = ColumnPtr + 1; // ColCaption[ColumnPtr] = "Name"; ColAlign[ColumnPtr] = "left"; ColWidth[ColumnPtr] = "100%"; ColumnPtr = ColumnPtr + 1; // ColCaption[ColumnPtr] = "Created By<br><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=100 height=1>"; ColAlign[ColumnPtr] = "left"; ColWidth[ColumnPtr] = "100"; ColumnPtr = ColumnPtr + 1; // ColCaption[ColumnPtr] = "Date Created<br><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=150 height=1>"; ColAlign[ColumnPtr] = "left"; ColWidth[ColumnPtr] = "150"; ColumnPtr = ColumnPtr + 1; // // Get Data // using (var csData = new CsModel(core)) { RowPointer = 0; if (!csData.open("Custom Reports")) { Cells[0, 1] = "There are no custom reports defined"; RowPointer = 1; } else { DataRowCount = csData.getRowCount(); while (csData.ok() && (RowPointer < PageSize)) { int customReportId = csData.getInteger("ID"); Cells[RowPointer, 0] = HtmlController.checkbox("Row" + RowPointer) + HtmlController.inputHidden("RowID" + RowPointer, customReportId); Cells[RowPointer, 1] = csData.getText("name"); Cells[RowPointer, 2] = csData.getText("CreatedBy"); Cells[RowPointer, 3] = csData.getDate("DateAdded").ToShortDateString(); RowPointer = RowPointer + 1; csData.goNext(); } } csData.close(); } string Cell = null; Tab0.add(HtmlController.inputHidden("RowCnt", RowPointer)); Cell = AdminUIController.getReport(core, RowPointer, ColCaption, ColAlign, ColWidth, Cells, PageSize, PageNumber, PreTableCopy, PostTableCopy, DataRowCount, "ccPanel"); Tab0.add("<div>" + Cell + "</div>"); // // Build RequestContent Form // Tab1.add("<p>Use this form to create a new custom report. Enter the SQL Query for the report, and a name that will be used as a caption.</p>"); // Tab1.add("<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">"); // Tab1.add("<tr>"); Tab1.add("<td align=right>Name</td>"); Tab1.add("<td>" + HtmlController.inputText_Legacy(core, "Name", "", 1, 40) + "</td>"); Tab1.add("</tr>"); // Tab1.add("<tr>"); Tab1.add("<td align=right>SQL Query</td>"); Tab1.add("<td>" + HtmlController.inputText_Legacy(core, SQLFieldName, "", 8, 40) + "</td>"); Tab1.add("</tr>"); // Tab1.add("<tr><td width=\"120\"><img alt=\"space\" src=\"" + cdnPrefix + "images/spacer.gif\" width=\"120\" height=\"1\"></td><td width=\"100%\"> </td></tr></table>"); // // Build and add tabs // adminMenu.addEntry("Custom Reports", Tab0.text, "ccAdminTab"); adminMenu.addEntry("Request New Report", Tab1.text, "ccAdminTab"); Content = adminMenu.getTabs(core); // } // core.html.addTitle("Custom Reports"); // return(AdminUIController.getToolBody(core, title, ButtonCommaListLeft, ButtonCommaListRight, true, true, Description, ContentSummary, ContentPadding, Content)); } catch (Exception ex) { LogController.logError(core, ex); return(toolExceptionMessage); } }
// // ==================================================================================================== /// <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 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); }