private string processSubmission()
        {
            StringBuilder html = new StringBuilder();
            string        CSV  = PageUtils.getFromForm("CSVPageInfo", "");

            string[] lines = CSV.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            html.Append("<table border=\"1\">");
            foreach (string line in lines)
            {
                string[] vals = line.Split(new char[] { '|' });
                if (vals.Length >= 7)
                {
                    string newPageName      = vals[0].Trim();
                    string newPageTitle     = vals[1].Trim();
                    string newPageMenuTitle = vals[2].Trim();
                    string newPageSearchEngineDescription = vals[3].Trim();
                    bool   newPageShowInMenu = Convert.ToBoolean(vals[4]);
                    string newPageTemplate   = vals[5].Trim();
                    int    newPageParentId   = Convert.ToInt32(vals[6]);

                    CmsCreateNewPageOptions newPageOpts      = CmsCreateNewPageOptions.GetInstanceWithNoUserPrompts(newPageName, newPageTitle, newPageMenuTitle, newPageSearchEngineDescription, newPageShowInMenu, newPageTemplate, newPageParentId);
                    NameValueCollection     createPageParams = newPageOpts.GetCreatePagePopupParams();

                    string link = CmsPageEditMenu.DefaultStandardActionRenderers.RenderLink("CreateNewPagePath", "/_admin/createPage", createPageParams, CmsContext.currentPage, CmsContext.currentLanguage, "Create Page");
                    html.Append("<tr>");
                    html.Append("<td>" + link + "</td>");
                    html.Append("<td>" + line + "</td>");
                    html.Append("</tr>");
                }
            }
            html.Append("</table>");

            return(html.ToString());
        }
        /// <summary>
        /// Adds the "Add a new job" menu item to the Edit Menu.
        /// </summary>
        /// <param name="pageToAddCommandTo"></param>
        /// <param name="jobAggregatorPage"></param>
        public static void AddJobPostingCommandToEditMenu(CmsPage pageToAddCommandTo, CmsPage jobAggregatorPage)
        {
            // -- only add the command if the user can author
            if (!pageToAddCommandTo.currentUserCanWrite)
            {
                return;
            }

            // -- base the command off the existing "create new sub-page" command
            CmsPageEditMenuAction createNewSubPage = pageToAddCommandTo.EditMenu.getActionItem(CmsEditMenuActionItem.CreateNewPage);

            if (createNewSubPage == null)
            {
                throw new Exception("Fatal Error in in JobPostingAggregator placeholder - could not get the existing CreateNewPage action");
            }

            CmsPageEditMenuAction CreateNewJobMenuAction = createNewSubPage.Copy(); // copy everything from the CreateNewPage entry

            // -- configure this command to not prompt authors for any information.
            //    the minimum information needed to create a page is the new page's filename (page.name)
            //      -- get the next unique filename
            string newPageName = "";

            for (int jobNum = 1; jobNum < int.MaxValue; jobNum++)
            {
                string pageNameToTest = "Job " + jobNum.ToString();
                if (!CmsContext.childPageWithNameExists(jobAggregatorPage.Id, pageNameToTest))
                {
                    newPageName = pageNameToTest;
                    break;
                }
            }


            string newPageTitle     = "";
            string newPageMenuTitle = "";
            string newPageSearchEngineDescription = "";
            bool   newPageShowInMenu = false;
            string newPageTemplate   = CmsConfig.getConfigValue("JobPosting.DetailsTemplateName", "_JobPosting");

            CreateNewJobMenuAction.CreateNewPageOptions = CmsCreateNewPageOptions.GetInstanceWithNoUserPrompts(newPageName, newPageTitle, newPageMenuTitle, newPageSearchEngineDescription, newPageShowInMenu, newPageTemplate, jobAggregatorPage.Id);

            CreateNewJobMenuAction.CreateNewPageOptions.ParentPageId = jobAggregatorPage.Id;
            CreateNewJobMenuAction.SortOrdinal      = createNewSubPage.SortOrdinal + 1;
            CreateNewJobMenuAction.doRenderToString = AddJobPostingEditMenuRender;

            pageToAddCommandTo.EditMenu.addCustomActionItem(CreateNewJobMenuAction);
        }
        /// <summary>
        /// Adds the "Add an image gallery" menu item to the Edit Menu.
        /// </summary>
        /// <param name="pageToAddCommandTo"></param>
        /// <param name="userImageGalleryAggregator"></param>
        public static void AddGalleryCommandToEditMenu(CmsPage pageToAddCommandTo, CmsPage userImageGalleryAggregator)
        {
            // -- only add the command if the user can author
            if (!pageToAddCommandTo.currentUserCanWrite)
            {
                return;
            }

            // -- base the command off the existing "create new sub-page" command
            CmsPageEditMenuAction createNewSubPage = pageToAddCommandTo.EditMenu.getActionItem(CmsEditMenuActionItem.CreateNewPage);

            if (createNewSubPage == null)
            {
                return;
            }

            CmsPageEditMenuAction newAction = createNewSubPage.Copy(); // copy everything from the CreateNewPage entry

            // -- configure this command to not prompt authors for any information.
            //    the minimum information needed to create a page is the new page's filename (page.name)
            //      -- get the next unique filename
            string newPageName = "";

            for (int eventNum = 1; eventNum < int.MaxValue; eventNum++)
            {
                string pageNameToTest = "Gallery" + eventNum.ToString();
                if (!CmsContext.childPageWithNameExists(userImageGalleryAggregator.ID, pageNameToTest))
                {
                    newPageName = pageNameToTest;
                    break;
                }
            }

            string newPageTitle     = "";
            string newPageMenuTitle = "";
            string newPageSearchEngineDescription = "";
            bool   newPageShowInMenu = true;
            string newPageTemplate   = CmsConfig.getConfigValue("UserImageGallery.DetailsTemplateName", "UserImageGallery");

            newAction.CreateNewPageOptions = CmsCreateNewPageOptions.GetInstanceWithNoUserPrompts(newPageName, newPageTitle, newPageMenuTitle, newPageSearchEngineDescription, newPageShowInMenu, newPageTemplate, userImageGalleryAggregator.ID);

            newAction.CreateNewPageOptions.ParentPageId = userImageGalleryAggregator.ID;
            newAction.SortOrdinal      = createNewSubPage.SortOrdinal + 1;
            newAction.doRenderToString = AddGalleryEditMenuRender;

            pageToAddCommandTo.EditMenu.addCustomActionItem(newAction);
        }
        public override string RenderToString(CmsControlDefinition controlDefnToRender, CmsLanguage langToRenderFor)
        {
            if (!CmsContext.currentUserIsLoggedIn)
            {
                return("Access Denied");
            }

            string action = PageUtils.getFromForm("CreateNewPageAction", "");

            CmsCreateNewPageOptions options = CmsCreateNewPageOptions.ReadFromQueryString();

            if (!options.RequiresUserInput() && (String.Compare(action, "createnew", true) != 0))
            {
                CmsPage pageToCreate = options.ToCmsPageObject();
                if (!pageToCreate.ParentPage.currentUserCanWrite)
                {
                    _errorMessage = "Access denied - you do not have access to create a page in this location.";
                }
                else if (CmsContext.childPageWithNameExists(pageToCreate.ParentID, pageToCreate.LanguageInfo))
                {
                    _errorMessage = "a page with the specified filename already exists!";
                }
                else if (StringUtils.IndexOf(CmsPage.InvalidPageNameChars, pageToCreate.Name, StringComparison.CurrentCulture) >= 0)
                {
                    _errorMessage = "The page's filename contains invalid characters. Invalid charactes include: " + StringUtils.Join("', '", "' and '", CmsPage.InvalidPageNameChars) + ". ";
                }
                else
                {
                    // -- page does not already exist, so create it
                    bool success = CmsPage.InsertNewPage(pageToCreate);
                    if (!success)
                    {
                        _errorMessage = "Database error: could not create new page.";
                    }
                    else
                    {
                        CmsContext.setEditModeAndRedirect(CmsEditMode.Edit, pageToCreate);
                    }
                }
            }

            // -- get the form variables
            string name       = PageUtils.getFromForm("_name", ""); name = name.Trim();
            string title      = PageUtils.getFromForm("_title", ""); title = title.Trim();
            string menuTitle  = PageUtils.getFromForm("_menuTitle", ""); menuTitle = menuTitle.Trim();
            bool   showInMenu = PageUtils.getFromForm("_showInMenu", options.ShowInMenu);
            string template   = PageUtils.getFromForm("_template", options.Template);
            string parent     = PageUtils.getFromForm("target", options.ParentPageId.ToString());

            // -- process the action
            if (String.Compare(action, "createnew", true) == 0)
            {
                if ((!options.PromptUserForFilename || isNotEmpty(name, "Please enter in the page's filename")) &&
                    (!options.PromptUserForTemplate || isNotEmpty(template, "Please enter in the page's template")) &&
                    (!options.PromptUserForParentPage || isNotEmpty(parent, "Please enter in the page's parent")) &&
                    (!options.PromptUserForTitle || isNotEmpty(title, "Please enter in the page's title")) &&
                    (!options.PromptUserForMenuTitle || isNotEmpty(menuTitle, "Please enter in the page's navigation menu text")) &&
                    nameDoesNotContainInvalidCharacters(name) &&
                    doesNotStartWithUnderscoreForNonSuperAdmin(name, "the filename can not start with an \"_\" character.")
                    ) // note when adding new restrictions for the filename, add them also to the RenamePagePopup control, and to the PageTitle placeholder getPageNameFromTitle() function!
                {
                    int     parentId = Convert.ToInt32(parent);
                    CmsPage newPage  = new CmsPage();

                    // -- setup the page's language info
                    List <CmsPageLanguageInfo> langInfos = new List <CmsPageLanguageInfo>();
                    foreach (CmsLanguage lang in CmsConfig.Languages)
                    {
                        CmsPageLanguageInfo langInfo = new CmsPageLanguageInfo();
                        langInfo.LanguageShortCode = lang.shortCode;
                        langInfo.Name      = name;
                        langInfo.MenuTitle = menuTitle;
                        langInfo.Title     = title;
                        langInfo.SearchEngineDescription = "";
                        langInfo.Page = newPage;

                        langInfos.Add(langInfo);
                    } // foreach languages
                    newPage.LanguageInfo = langInfos.ToArray();

                    newPage.ShowInMenu   = showInMenu;
                    newPage.ParentID     = parentId;
                    newPage.TemplateName = template;
                    newPage.ShowInMenu   = showInMenu;

                    // -- set sortOrdinal
                    CmsPage parentPage = CmsContext.getPageById(parentId);
                    int     highestSiblingSortOrdinal = -1;
                    foreach (CmsPage sibling in parentPage.ChildPages)
                    {
                        highestSiblingSortOrdinal = Math.Max(sibling.SortOrdinal, highestSiblingSortOrdinal);
                    }
                    if (highestSiblingSortOrdinal > -1)
                    {
                        newPage.SortOrdinal = highestSiblingSortOrdinal + 1;
                    }
                    else
                    {
                        newPage.SortOrdinal = 0;
                    }

                    if (CmsContext.childPageWithNameExists(parentId, name))
                    {
                        _errorMessage = "a page with the specified filename and parent already exists!";
                    }
                    else
                    {
                        // -- page does not already exist, so create it
                        bool success = CmsPage.InsertNewPage(newPage);
                        if (!success)
                        {
                            _errorMessage = "database could not create new page.";
                        }
                        else
                        {
                            // -- success: redirect main page to the new page, and close this window.
                            StringBuilder script = new StringBuilder();
                            script.Append("<script>" + Environment.NewLine);
                            script.Append("function go(url){" + Environment.NewLine);
                            script.Append("opener.location.href = url;" + Environment.NewLine);
                            script.Append("window.close();}" + Environment.NewLine);
                            script.Append("</script>" + Environment.NewLine);

                            // -- Switch to Edit Mode
                            NameValueCollection paramList = new NameValueCollection();
                            paramList.Add("target", newPage.Id.ToString());
                            string toggleEditUrl = CmsContext.getUrlByPagePath(CmsConfig.getConfigValue("GotoEditModePath", "/_admin/action/gotoEdit"), paramList);

                            script.Append("<center>");
                            script.Append("<b>Your new page has been created.</b><p>");
                            script.Append("<a href=\"#\" onclick=\"go('" + newPage.Url + "')\">");
                            script.Append("take me to this new page");
                            script.Append("</a><p>");

                            script.Append("<a href=\"#\" onclick=\"go('" + toggleEditUrl + "')\">");
                            script.Append("edit this new page");
                            script.Append("</a><p>");

                            script.Append("<a href=\"#\" onclick=\"opener.location.reload(); window.close()\">");
                            script.Append("close this window");
                            script.Append("</a><br>");
                            script.Append("</center>");


                            return(script.ToString());
                        }
                    }
                }
            } // if action is set

            // -- Render the page
            CmsPage page = CmsContext.currentPage;

            StringBuilder html    = new StringBuilder();
            string        newLine = Environment.NewLine;
            string        formId  = "createPage";

            html.Append(page.getFormStartHtml(formId));
            html.Append("<table width=\"100%\" cellpadding=\"1\" cellspacing=\"2\" border=\"0\">" + newLine);

            html.Append("<tr>" + newLine);
            html.Append("	<td colspan=\"2\" bgcolor=\"#ffffd6\"><strong>Create a new page</strong></td>"+ newLine);
            html.Append("</tr>" + newLine);
            if (_errorMessage != "")
            {
                html.Append("<tr>" + newLine);
                html.Append("	<td colspan=\"2\">");
                html.Append("<span style=\"color: red;\">" + _errorMessage + "</span>");
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }

            if (options.PromptUserForFilename)
            {
                html.Append("<tr>" + newLine);
                html.Append("	<td>");
                html.Append("	Filename: </td><td>"+ PageUtils.getInputTextHtml("_name", "fn", name, 20, 255));
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }
            else
            {
                html.Append(PageUtils.getHiddenInputHtml("_name", options.NewPageLanguageInfos[0].Name));
            }

            if (options.PromptUserForTitle)
            {
                html.Append("<tr>" + newLine);
                html.Append("	<td>");
                html.Append("	Title: </td><td>"+ PageUtils.getInputTextHtml("_title", "ft", title, 20, 255));
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }
            else
            {
                html.Append(PageUtils.getHiddenInputHtml("_title", options.NewPageLanguageInfos[0].Title));
            }

            if (options.PromptUserForMenuTitle)
            {
                html.Append("<tr>" + newLine);
                html.Append("	<td>");
                html.Append("	Navigation Menu Text: </td><td>"+ PageUtils.getInputTextHtml("_menutitle", "mt", title, 20, 255));
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }
            else
            {
                html.Append(PageUtils.getHiddenInputHtml("_menutitle", options.NewPageLanguageInfos[0].MenuTitle));
            }

            if (options.PromptUserForShowInMenu)
            {
                html.Append("<tr>");
                html.Append("	<td>");
                NameValueCollection ynOptions = new NameValueCollection();
                ynOptions.Add("1", "Yes");
                ynOptions.Add("0", "No");
                html.Append("	Show In Menu: </td><td>"+ PageUtils.getRadioListHtml("_showInMenu", "mt", ynOptions, Convert.ToInt32(showInMenu).ToString(), "", " "));
                html.Append("	</td>");
                html.Append("</tr>");
            }
            else
            {
                html.Append(PageUtils.getHiddenInputHtml("_showInMenu", Convert.ToInt32(options.ShowInMenu)));
            }

            if (options.PromptUserForTemplate)
            {
                string[] templates = CmsContext.getTemplateNamesForCurrentUser();
                html.Append("<tr>" + newLine);
                html.Append("	<td>");
                html.Append("	Template: </td><td>"+ PageUtils.getDropDownHtml("_template", "ft", templates, template));
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }
            else
            {
                html.Append(PageUtils.getHiddenInputHtml("_template", options.Template));
            }

            if (options.PromptUserForParentPage)
            {
                html.Append("<tr>" + newLine);
                html.Append("	<td>");
                html.Append("	Parent Page: </td><td>"+ PageUtils.getDropDownHtml("target", "fp", getParentPageOptions(CmsContext.HomePage), parent));
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }
            else
            {
                html.Append("<tr>" + newLine);
                html.Append("	<td>");
                html.Append("	Parent Page: </td><td>"+ CmsContext.getPageById(Convert.ToInt32(parent)).Path);
                html.Append(PageUtils.getHiddenInputHtml("target", "fp", parent));
                html.Append("	</td>");
                html.Append("</tr>" + newLine);
            }
            html.Append("</table>");
            html.Append("<p><em>All fields are required</em></p>");

            NameValueCollection optionParams = options.GetCreatePagePopupParams();

            foreach (string key in optionParams.AllKeys)
            {
                html.Append(PageUtils.getHiddenInputHtml(key, "option_" + key, optionParams[key]));
            }


            html.Append(PageUtils.getHiddenInputHtml("CreateNewPageAction", "createNew"));
            html.Append("<input type=\"submit\" value=\"create new page\">");
            html.Append("<input type=\"button\" value=\"cancel\" onclick=\"window.close()\">");
            html.Append(page.getFormCloseHtml(formId));


            return(html.ToString());
        }