Example #1
0
 //
 public static string get(CoreController core)
 {
     try {
         StringBuilderLegacyController result_reset = new StringBuilderLegacyController();
         result_reset.add(AdminUIController.getHeaderTitleDescription("IIS Reset", "Reset the webserver."));
         //
         // Process the form
         //
         string Button = core.docProperties.getText("button");
         if (Button == ButtonIISReset)
         {
             //
             //
             //
             LogController.logDebug(core, "Restarting IIS");
             core.webServer.redirect("" + cdnPrefix + "Popup/WaitForIISReset.htm", "Redirect to iis reset");
             Thread.Sleep(2000);
             var cmdDetail = new TaskModel.CmdDetailClass {
                 addonId   = 0,
                 addonName = "GetForm_IISReset",
                 args      = new Dictionary <string, string>()
             };
             TaskSchedulerController.addTaskToQueue(core, cmdDetail, false);
         }
         //
         // Display form
         //
         return(AdminUIController.getToolForm(core, result_reset.text, ButtonCancel + "," + ButtonIISReset));
     } catch (Exception ex) {
         LogController.logError(core, ex);
         return(string.Empty);
     }
 }
Example #2
0
 //
 //====================================================================================================
 //
 public override void ExportCsv(string sql, string exportName, string filename)
 {
     try {
         var ExportCSVAddon = DbBaseModel.create <AddonModel>(cp, addonGuidExportCSV);
         if (ExportCSVAddon == null)
         {
             LogController.logError(cp.core, new GenericException("ExportCSV addon not found. Task could not be added to task queue."));
         }
         else
         {
             var cmdDetail = new TaskModel.CmdDetailClass {
                 addonId   = ExportCSVAddon.id,
                 addonName = ExportCSVAddon.name,
                 args      = new Dictionary <string, string> {
                     { "sql", sql },
                     { "ExportName", exportName },
                     { "filename", filename }
                 }
             };
             TaskSchedulerController.addTaskToQueue(cp.core, cmdDetail, false, exportName, filename);
         }
     } catch (Exception) {
         throw;
     }
 }
Example #3
0
        //
        //========================================================================
        //
        public static void requestDownload(CoreController core, int customReportId)
        {
            //
            // Request the download
            //
            var customReport = DbBaseModel.create <CustomReportModel>(core.cpParent, customReportId);

            if (customReport != null)
            {
                var ExportCSVAddon = DbBaseModel.create <AddonModel>(core.cpParent, addonGuidExportCSV);
                if (ExportCSVAddon == null)
                {
                    LogController.logError(core, new GenericException("ExportCSV addon not found. Task could not be added to task queue."));
                }
                else
                {
                    var docProperties = new Dictionary <string, string> {
                        { "sql", customReport.sqlQuery },
                        { "datasource", "default" }
                    };
                    var cmdDetail = new TaskModel.CmdDetailClass {
                        addonId   = ExportCSVAddon.id,
                        addonName = ExportCSVAddon.name,
                        args      = docProperties
                    };
                    string ExportFilename = "CustomReport_" + customReport.id.ToString("00000000") + ".csv";
                    string reportName     = customReport.name ?? "#" + customReport.id;
                    TaskSchedulerController.addTaskToQueue(core, cmdDetail, false, "Custom Report, " + reportName, ExportFilename);
                }
            }
        }
Example #4
0
        public override ConsoleResultModel Run()
        {
            var controller     = new TaskSchedulerController();
            var tasks          = new List <TaskModelBase>();
            var schedulerItems = controller.GetScheduleItems(this.Enabled, "", this.TaskName?.Replace("*", ""));

            tasks.AddRange(schedulerItems.Select(x => new TaskModelBase(x)));
            return(new ConsoleResultModel(string.Format(this.LocalizeString("Prompt_TasksFound"), tasks.Count))
            {
                Data = tasks,
                Records = tasks.Count,
            });
        }
        //
        //=============================================================================
        // Find and Replace launch tool
        //=============================================================================
        //
        public static string get(CoreController core)
        {
            string result = "";

            try {
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                //
                Stream.add(AdminUIController.getHeaderTitleDescription("Find and Replace", "This tool runs a find and replace operation on content throughout the site."));
                //
                // Process the form
                //
                string Button      = core.docProperties.getText("button");
                bool   IsDeveloper = core.session.isAuthenticatedDeveloper();
                int    RowPtr      = 0;
                string CDefList    = "";
                string FindText    = "";
                string ReplaceText = "";
                string lcName      = null;
                if (Button == ButtonFindAndReplace)
                {
                    int RowCnt = core.docProperties.getInteger("CDefRowCnt");
                    if (RowCnt > 0)
                    {
                        for (RowPtr = 0; RowPtr < RowCnt; RowPtr++)
                        {
                            if (core.docProperties.getBoolean("Cdef" + RowPtr))
                            {
                                lcName = GenericController.toLCase(core.docProperties.getText("CDefName" + RowPtr));
                                if (IsDeveloper || (lcName == "page content") || (lcName == "copy content") || (lcName == "page templates"))
                                {
                                    CDefList = CDefList + "," + lcName;
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(CDefList))
                        {
                            CDefList = CDefList.Substring(1);
                        }
                        FindText    = core.docProperties.getText("FindText");
                        ReplaceText = core.docProperties.getText("ReplaceText");
                        //string QS = "app=" + encodeNvaArgument(core.appConfig.name) + "&FindText=" + encodeNvaArgument(FindText) + "&ReplaceText=" + encodeNvaArgument(ReplaceText) + "&CDefNameList=" + encodeNvaArgument(CDefList);
                        var cmdDetail = new TaskModel.CmdDetailClass {
                            addonId   = 0,
                            addonName = "GetForm_FindAndReplace",
                            args      = new System.Collections.Generic.Dictionary <string, string> {
                                { "app", core.appConfig.name },
                                { "FindText", FindText },
                                { "ReplaceText", ReplaceText },
                                { "CDefNameList", CDefList }
                            }
                        };
                        TaskSchedulerController.addTaskToQueue(core, cmdDetail, false);
                        Stream.add("Find and Replace has been requested for content definitions [" + CDefList + "], finding [" + FindText + "] and replacing with [" + ReplaceText + "]");
                    }
                }
                else
                {
                    CDefList    = "Page Content,Copy Content,Page Templates";
                    FindText    = "";
                    ReplaceText = "";
                }
                //
                // Display form
                //
                int FindRows = core.docProperties.getInteger("SQLRows");
                if (FindRows == 0)
                {
                    FindRows = core.userProperty.getInteger("FindAndReplaceFindRows", 1);
                }
                else
                {
                    core.userProperty.setProperty("FindAndReplaceFindRows", FindRows.ToString());
                }
                int ReplaceRows = core.docProperties.getInteger("ReplaceRows");
                if (ReplaceRows == 0)
                {
                    ReplaceRows = core.userProperty.getInteger("FindAndReplaceReplaceRows", 1);
                }
                else
                {
                    core.userProperty.setProperty("FindAndReplaceReplaceRows", ReplaceRows.ToString());
                }
                //
                Stream.add("<div>Find</div>");
                Stream.add("<TEXTAREA NAME=\"FindText\" ROWS=\"" + FindRows + "\" ID=\"FindText\" STYLE=\"width: 800px;\">" + FindText + "</TEXTAREA>");
                Stream.add("&nbsp;<INPUT TYPE=\"Text\" TabIndex=-1 NAME=\"FindTextRows\" SIZE=\"3\" VALUE=\"" + FindRows + "\" ID=\"\"  onchange=\"FindText.rows=FindTextRows.value; return true\"> Rows");
                Stream.add("<br><br>");
                //
                Stream.add("<div>Replace it with</div>");
                Stream.add("<TEXTAREA NAME=\"ReplaceText\" ROWS=\"" + ReplaceRows + "\" ID=\"ReplaceText\" STYLE=\"width: 800px;\">" + ReplaceText + "</TEXTAREA>");
                Stream.add("&nbsp;<INPUT TYPE=\"Text\" TabIndex=-1 NAME=\"ReplaceTextRows\" SIZE=\"3\" VALUE=\"" + ReplaceRows + "\" ID=\"\"  onchange=\"ReplaceText.rows=ReplaceTextRows.value; return true\"> Rows");
                Stream.add("<br><br>");
                string TopHalf    = "";
                string BottomHalf = "";
                //
                using (var csData = new CsModel(core)) {
                    csData.open("Content");
                    while (csData.ok())
                    {
                        string RecordName = csData.getText("Name");
                        lcName = GenericController.toLCase(RecordName);
                        if (IsDeveloper || (lcName == "page content") || (lcName == "copy content") || (lcName == "page templates"))
                        {
                            int RecordId = csData.getInteger("ID");
                            if (GenericController.strInstr(1, "," + CDefList + ",", "," + RecordName + ",") != 0)
                            {
                                TopHalf = TopHalf + "<div>" + HtmlController.checkbox("Cdef" + RowPtr, true) + HtmlController.inputHidden("CDefName" + RowPtr, RecordName) + "&nbsp;" + csData.getText("Name") + "</div>";
                            }
                            else
                            {
                                BottomHalf = BottomHalf + "<div>" + HtmlController.checkbox("Cdef" + RowPtr, false) + HtmlController.inputHidden("CDefName" + RowPtr, RecordName) + "&nbsp;" + csData.getText("Name") + "</div>";
                            }
                        }
                        csData.goNext();
                        RowPtr += 1;
                    }
                }
                Stream.add(TopHalf + BottomHalf + HtmlController.inputHidden("CDefRowCnt", RowPtr));
                //
                result = AdminUIController.getToolForm(core, Stream.text, ButtonCancel + "," + ButtonFindAndReplace);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
Example #6
0
        //
        //=============================================================================
        //   Export the Admin List form results
        //=============================================================================
        //
        public static string get(CoreController core, AdminDataModel adminData)
        {
            string result = "";

            try {
                //
                bool   AllowContentAccess                    = false;
                string ButtonCommaList                       = "";
                string ExportName                            = null;
                string Description                           = null;
                string Content                               = "";
                string Button                                = null;
                int    RecordLimit                           = 0;
                int    recordCnt                             = 0;
                string sqlFieldList                          = "";
                string SQLFrom                               = "";
                string SQLWhere                              = "";
                string SQLOrderBy                            = "";
                bool   IsLimitedToSubContent                 = false;
                string ContentAccessLimitMessage             = "";
                Dictionary <string, bool> FieldUsedInColumns = new Dictionary <string, bool>();
                Dictionary <string, bool> IsLookupFieldValid = new Dictionary <string, bool>();
                IndexConfigClass          IndexConfig        = null;
                string          SQL                          = null;
                bool            IsRecordLimitSet             = false;
                string          RecordLimitText              = null;
                var             cacheNameList                = new List <string>();
                DataSourceModel datasource                   = DataSourceModel.create(core.cpParent, adminData.adminContent.dataSourceId, ref cacheNameList);
                //
                // ----- Process Input
                //
                Button = core.docProperties.getText("Button");
                if (Button == ButtonCancelAll)
                {
                    //
                    // Cancel out to the main page
                    //
                    return(core.webServer.redirect("?", "CancelAll button pressed on Index Export"));
                }
                else if (Button != ButtonCancel)
                {
                    //
                    // get content access rights
                    //
                    var userContentPermissions = PermissionController.getUserContentPermissions(core, adminData.adminContent);
                    if (!userContentPermissions.allowEdit)
                    {
                        //
                        // You must be a content manager of this content to use this tool
                        //
                        Content = ""
                                  + "<p>You must be a content manager of " + adminData.adminContent.name + " to use this tool. Hit Cancel to return to main admin page.</p>"
                                  + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                        ButtonCommaList = ButtonCancelAll;
                    }
                    else
                    {
                        IsRecordLimitSet = false;
                        if (string.IsNullOrEmpty(Button))
                        {
                            //
                            // Set Defaults
                            //
                            ExportName      = "";
                            RecordLimit     = 0;
                            RecordLimitText = "";
                        }
                        else
                        {
                            ExportName      = core.docProperties.getText("ExportName");
                            RecordLimitText = core.docProperties.getText("RecordLimit");
                            if (!string.IsNullOrEmpty(RecordLimitText))
                            {
                                IsRecordLimitSet = true;
                                RecordLimit      = GenericController.encodeInteger(RecordLimitText);
                            }
                        }
                        if (string.IsNullOrEmpty(ExportName))
                        {
                            ExportName = adminData.adminContent.name + " export for " + core.session.user.name;
                        }
                        //
                        // Get the SQL parts
                        //
                        IndexConfig = IndexConfigClass.get(core, adminData);
                        ListView.setIndexSQL(core, adminData, IndexConfig, ref AllowContentAccess, ref sqlFieldList, ref SQLFrom, ref SQLWhere, ref SQLOrderBy, ref IsLimitedToSubContent, ref ContentAccessLimitMessage, ref FieldUsedInColumns, IsLookupFieldValid);
                        if (!AllowContentAccess)
                        {
                            //
                            // This should be caught with check earlier, but since I added this, and I never make mistakes, I will leave this in case there is a mistake in the earlier code
                            //
                            Processor.Controllers.ErrorController.addUserError(core, "Your account does not have access to any records in '" + adminData.adminContent.name + "'.");
                        }
                        else
                        {
                            //
                            // Get the total record count
                            //
                            SQL = "select count(" + adminData.adminContent.tableName + ".ID) as cnt from " + SQLFrom + " where " + SQLWhere;
                            using (var csData = new CsModel(core)) {
                                csData.openSql(SQL, datasource.name);
                                if (csData.ok())
                                {
                                    recordCnt = csData.getInteger("cnt");
                                }
                            }
                            //
                            // Build the SQL
                            //
                            SQL = "select";
                            if (IsRecordLimitSet && (datasource.dbTypeId != DataSourceTypeODBCMySQL))
                            {
                                SQL += " Top " + RecordLimit;
                            }
                            SQL += " " + adminData.adminContent.tableName + ".* From " + SQLFrom + " WHERE " + SQLWhere;
                            if (!string.IsNullOrEmpty(SQLOrderBy))
                            {
                                SQL += " Order By" + SQLOrderBy;
                            }
                            if (IsRecordLimitSet && (datasource.dbTypeId == DataSourceTypeODBCMySQL))
                            {
                                SQL += " Limit " + RecordLimit;
                            }
                            //
                            // Assumble the SQL
                            //
                            if (recordCnt == 0)
                            {
                                //
                                // There are no records to request
                                //
                                Content = ""
                                          + "<p>This selection has no records. Hit Cancel to return to the " + adminData.adminContent.name + " list page.</p>"
                                          + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                                ButtonCommaList = ButtonCancel;
                            }
                            else if (Button == ButtonRequestDownload)
                            {
                                //
                                // Request the download
                                //
                                var ExportCSVAddon = DbBaseModel.create <AddonModel>(core.cpParent, addonGuidExportCSV);
                                if (ExportCSVAddon == null)
                                {
                                    LogController.logError(core, new GenericException("ExportCSV addon not found. Task could not be added to task queue."));
                                }
                                else
                                {
                                    var docProperties = new Dictionary <string, string> {
                                        { "sql", SQL },
                                        { "datasource", "default" }
                                    };
                                    var cmdDetail = new TaskModel.CmdDetailClass {
                                        addonId   = ExportCSVAddon.id,
                                        addonName = ExportCSVAddon.name,
                                        args      = docProperties
                                    };
                                    TaskSchedulerController.addTaskToQueue(core, cmdDetail, false, ExportName, "export_" + adminData.adminContent.name.Replace(" ", "_") + ".csv");
                                }
                                //
                                Content = ""
                                          + "<p>Your export has been requested and will be available shortly in the <a href=\"?" + rnAdminForm + "=" + AdminFormDownloads + "\">Download Manager</a>. Hit Cancel to return to the " + adminData.adminContent.name + " list page.</p>"
                                          + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                                //
                                ButtonCommaList = ButtonCancel;
                            }
                            else
                            {
                                //
                                // no button or refresh button, Ask are you sure
                                //
                                Content += HtmlController.div(
                                    HtmlController.label("Export Name", "export-name")
                                    + HtmlController.inputText(core, "ExportName", ExportName, "form-control", "export-name")
                                    , "form-group");
                                Content += HtmlController.div(
                                    HtmlController.label("Records Found", "records-found")
                                    + HtmlController.inputText(core, "RecordCnt", recordCnt.ToString(), "form-control", "records-found", true)
                                    , "form-group");
                                Content += HtmlController.div(
                                    HtmlController.label("Record Limit", "record-limit")
                                    + HtmlController.inputText(core, "RecordLimit", RecordLimitText, "form-control", "record-limit")
                                    , "form-group");
                                if (core.session.isAuthenticatedDeveloper())
                                {
                                    Content += HtmlController.div(
                                        HtmlController.label("Results SQL", "export-query")
                                        + HtmlController.inputTextarea(core, "sql", SQL, 4, -1, "export-query", false, false, "form-control")
                                        , "form-group");
                                }
                                //
                                Content = ""
                                          //+ "\r<style>"
                                          //+ cr2 + ".exportTblCaption {width:100px;}"
                                          //+ cr2 + ".exportTblInput {}"
                                          //+ "\r</style>"
                                          + Content + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                                ButtonCommaList = ButtonCancel + "," + ButtonRequestDownload;
                                if (core.session.isAuthenticatedDeveloper())
                                {
                                    ButtonCommaList = ButtonCommaList + "," + ButtonRefresh;
                                }
                            }
                        }
                    }
                    //
                    Description = "<p>This tool creates an export of the current admin list page results. If you would like to download the current results, select a format and press OK. Your search results will be submitted for export. Your download will be ready shortly in the download manager. To exit without requesting an output, hit Cancel.</p>";
                    result      = AdminUIController.getToolBody(core, adminData.adminContent.name + " Export", ButtonCommaList, "", false, false, Description, "", 10, Content);
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }