/// <summary>
        /// The BindData helper method is used to update the tab's
        /// layout panes with the current configuration information
        /// </summary>
        private void BindData()
        {
            PageSettings tab = this.PortalSettings.ActivePage;

            // Populate Page Names, etc.
            tabName.Text = "New Page";
            mobilePageName.Text = "";
            showMobile.Checked = false;

            // Populate the "ParentPage" Data
            PagesDB t = new PagesDB();
            IList<PageItem> items = t.GetPagesParent( this.PortalSettings.PortalID, PageID );
            parentPage.DataSource = items;
            parentPage.DataBind();

            // Translate
            if ( parentPage.Items.FindByText( " ROOT_LEVEL" ) != null )
                parentPage.Items.FindByText( " ROOT_LEVEL" ).Text =
                    General.GetString( "ROOT_LEVEL", "Root Level", parentPage );

            // Populate checkbox list with all security roles for this portal
            // and "check" the ones already configured for this tab
            UsersDB users = new UsersDB();
            IList<AppleseedRole> roles = users.GetPortalRoles( this.PortalSettings.PortalAlias );

            // Clear existing items in checkboxlist
            authRoles.Items.Clear();

            foreach ( AppleseedRole role in roles ) {
                ListItem item = new ListItem();
                item.Text = role.Name;
                item.Value = role.Id.ToString();

                if ( ( tab.AuthorizedRoles.LastIndexOf( item.Text ) ) > -1 )
                    item.Selected = true;

                authRoles.Items.Add( item );
            }
        }
        private int getPageOrder(int idToSearch)
        {
            List<PageItem> pages = new PagesDB().GetPagesFlat(this.PortalSettings.PortalID);

            while (pages.Count > 0)
            {
                PageItem page = pages.First<PageItem>();
                pages.Remove(page);
                if (page.ID == idToSearch)
                {
                    return page.Order;
                }
            }
            return -1;
        }
        public JsonResult remove(int id)
        {
            try
            {
                var tabs = new PagesDB();
                tabs.DeletePage(id);

                return Json(new {error = false});
            }
            catch (SqlException)
            {
                string errorMessage = General.GetString("TAB_DELETE_FAILED", "Failed to delete Page", this);
                return Json(new { error = true, errorMess = errorMessage });
            }
        }
        public void moveNode(int pageID, int newParent, int idOldNode)
        {
            PagesDB db = new PagesDB();
            this.PortalPages = db.GetPagesFlat(this.PortalSettings.PortalID);

            db.UpdatePageParent(pageID, newParent, this.PortalSettings.PortalID);
            int order;
            if (idOldNode == -1)
            {
                order = 9999;
            }
            else
            {
                order = this.getPageOrder(idOldNode) - 1;
            }

            db.UpdatePageOrder(pageID, order);
            this.OrderPages();
        }
        public JsonResult GetTreeModule(string result, int pageId)
        {
            List<PageItem> pages = new PagesDB().GetPagesFlat(this.PortalSettings.PortalID);
            var page = pages.First(p => p.ID == pageId);

            JsTreeModel[] child = getChildrenTree(page);
            List<JsTreeModel> child2 = new List<JsTreeModel>();
            var panelist = result.Split('+').ToList();
            var panetopage = ModelServices.GetPageModules(pageId);
            var lowerpane = panelist.ConvertAll(d => d.ToLower());
            var i = 0;
            foreach (var pane in panelist)
            {
                JsTreeModel[] childm = getModuleToPane(pane, pageId);
                JsTreeModel nodem = new JsTreeModel
                    {
                        data = pane,
                        attr = new JsTreeAttribute {id = "pjson_pane_" + i, rel= "folder"},
                        children = childm
                    };
                child2.Add(nodem);
                i++;
            }
            // add other pane.
            foreach (var pane in panetopage)
            {
                if (!lowerpane.Contains(pane.Key))
                {
                    JsTreeModel[] childm = getModuleToPane(pane.Key, pageId);
                    JsTreeModel nodem = new JsTreeModel
                    {
                        data = pane.Key + "  [Not present in current layout]",
                        attr = new JsTreeAttribute { id = "pjson_pane_" + i, rel = "folder2" },
                        children = childm
                    };
                    child2.Add(nodem);
                    i++;
                }
                    panelist.Add(pane.Key);
            }
            var childlist = child.ToList();
            foreach (var childmod in child2)
            {
                childlist.Add(childmod);
            }
            child = childlist.ToArray<JsTreeModel>();
            return Json(child);
        }
        public JsonResult GetTreeData()
        {
            List<PageItem> pages = new PagesDB().GetPagesFlat(this.PortalSettings.PortalID);
            List<JsTreeModel> lstTree = new List<JsTreeModel>();
            foreach (PageItem page in pages)
            {
                if (page.NestLevel == 0)
                {
                    //JsTreeModel[] child = getChildrenTree(page);
                    JsTreeModel node = new JsTreeModel {
                                                    data = page.Name,
                                                    attr = new JsTreeAttribute { id = "pjson_" + page.ID.ToString()},
                                                    //children = child,
                                                    state = "closed"};
                    lstTree.Add(node);
                }
            }
            int root = 0;
            JsTreeModel rootNode = new JsTreeModel
            {
                data = "Root",
                attr = new JsTreeAttribute { id = "pjson_" + root.ToString(), rel = "root"},
                children = lstTree.ToArray<JsTreeModel>(),
            };

            return Json(rootNode);
        }
        public int CreatePortal(int solutionId, string portalAlias, string portalName, string portalPath)
        {
            var tabs = new PagesDB();
            var modules = new ModulesDB();

            // Create a new portal
            var portalId = this.AddPortal(portalAlias, portalName, portalPath);

            // get module definitions
            foreach (var solutionModuleDefinition in modules.GetSolutionModuleDefinitions(solutionId))
            {
                modules.UpdateModuleDefinitions(solutionModuleDefinition.GeneralModuleDefinitionId, portalId, true);
            }

            if (!Config.UseSingleUserBase)
            {
                const string AdminEmail = "*****@*****.**";

                // Create the stradmin User for the new portal
                var user = new UsersDB();

                // Create the "Admins" role for the new portal
                var roleId = user.AddRole(portalAlias, "Admins");
                var userId = user.AddUser(StringsAdmin, AdminEmail, StringsAdmin, portalAlias);

                // Create the "Admins" profile for the new portal
                var profile = ProfileBase.Create(AdminEmail);
                profile.SetPropertyValue("Email", AdminEmail);
                profile.SetPropertyValue("Name", "admin");
                try {
                    profile.Save();

                } catch (Exception exc) {

                }

                // Create a new row in a many to many table (userroles)
                // giving the "admins" role to the stradmin user
                user.AddUserRole(roleId, userId, portalAlias);
            }

            // Create a new Page "home"
            var homePageId = tabs.AddPage(portalId, "Home", 1);

            // Create a new Page "admin"
            var localizedString = General.GetString("ADMIN_TAB_NAME");
            var adminPageId = tabs.AddPage(portalId, localizedString, StrAdmins, 9999);

            // Add Modules for portal use
            // Html Document
            modules.UpdateModuleDefinitions(new Guid(StrGuidhtmlDocument), portalId, true);

            // Add Modules for portal administration
            // Site Settings (Admin)
            localizedString = General.GetString("MODULE_SITE_SETTINGS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidSiteSettings), portalId, true);
            modules.AddModule(
                adminPageId,
                1,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSiteSettings)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Pages (Admin)
            localizedString = General.GetString("MODULE_TABS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidPages), portalId, true);
            modules.AddModule(
                adminPageId,
                2,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidPages)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Roles (Admin)
            localizedString = General.GetString("MODULE_SECURITY_ROLES");
            modules.UpdateModuleDefinitions(new Guid(StrGuidSecurityRoles), portalId, true);
            modules.AddModule(
                adminPageId,
                3,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSecurityRoles)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Manage Users (Admin)
            localizedString = General.GetString("MODULE_MANAGE_USERS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidManageUsers), portalId, true);
            modules.AddModule(
                adminPageId,
                4,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidManageUsers)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Module Definitions (Admin)
            localizedString = General.GetString("MODULE_MODULES");
            modules.UpdateModuleDefinitions(new Guid(StrGuidModules), portalId, true);
            modules.AddModule(
                adminPageId,
                1,
                StringsRightPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidModules)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // End Change [email protected]
            // Change by [email protected]
            // Add Signin Module and put it on the hometab
            // Signin
            localizedString = General.GetString("MODULE_LOGIN", "Login");
            modules.UpdateModuleDefinitions(new Guid(StrGuidLogin), portalId, true);
            modules.AddModule(
                homePageId,
                -1,
                StrLeftPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidLogin)),
                0,
                StrAdmins,
                "Unauthenticated Users;Admins;",
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Add language switcher to available modules
            // Language Switcher
            modules.UpdateModuleDefinitions(new Guid(StrGuidLanguageSwitcher), portalId, true);

            // End of change by [email protected]
            // Create paths
            this.CreatePortalPath(portalPath);
            return portalId;
        }
Exemple #8
0
        public int CreatePortal(int solutionId, string portalAlias, string portalName, string portalPath)
        {
            var tabs    = new PagesDB();
            var modules = new ModulesDB();

            // Create a new portal
            var portalId = this.AddPortal(portalAlias, portalName, portalPath);

            // get module definitions
            foreach (var solutionModuleDefinition in modules.GetSolutionModuleDefinitions(solutionId))
            {
                modules.UpdateModuleDefinitions(solutionModuleDefinition.GeneralModuleDefinitionId, portalId, true);
            }

            if (!Config.UseSingleUserBase)
            {
                const string AdminEmail = "*****@*****.**";

                // Create the stradmin User for the new portal
                var user = new UsersDB();

                // Create the "Admins" role for the new portal
                var roleId = user.AddRole(portalAlias, "Admins");
                var userId = user.AddUser(StringsAdmin, AdminEmail, StringsAdmin, portalAlias);

                // Create the "Admins" profile for the new portal
                var profile = ProfileBase.Create(AdminEmail);
                profile.SetPropertyValue("Email", AdminEmail);
                profile.SetPropertyValue("Name", "admin");
                try {
                    profile.Save();
                } catch  {
                }

                // Create a new row in a many to many table (userroles)
                // giving the "admins" role to the stradmin user
                user.AddUserRole(roleId, userId, portalAlias);
            }

            // Create a new Page "home"
            var homePageId = tabs.AddPage(portalId, "Home", 1);

            // Create a new Page "admin"
            var localizedString = General.GetString("ADMIN_TAB_NAME");
            var adminPageId     = tabs.AddPage(portalId, localizedString, StrAdmins, 9999);

            // Add Modules for portal use
            // Html Document
            modules.UpdateModuleDefinitions(new Guid(StrGuidhtmlDocument), portalId, true);

            // Add Modules for portal administration
            // Site Settings (Admin)
            localizedString = General.GetString("MODULE_SITE_SETTINGS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidSiteSettings), portalId, true);
            modules.AddModule(
                adminPageId,
                1,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSiteSettings)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Pages (Admin)
            localizedString = General.GetString("MODULE_TABS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidPages), portalId, true);
            modules.AddModule(
                adminPageId,
                2,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidPages)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Roles (Admin)
            localizedString = General.GetString("MODULE_SECURITY_ROLES");
            modules.UpdateModuleDefinitions(new Guid(StrGuidSecurityRoles), portalId, true);
            modules.AddModule(
                adminPageId,
                3,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSecurityRoles)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Manage Users (Admin)
            localizedString = General.GetString("MODULE_MANAGE_USERS");
            modules.UpdateModuleDefinitions(new Guid(StrGuidManageUsers), portalId, true);
            modules.AddModule(
                adminPageId,
                4,
                StrContentPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidManageUsers)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Module Definitions (Admin)
            localizedString = General.GetString("MODULE_MODULES");
            modules.UpdateModuleDefinitions(new Guid(StrGuidModules), portalId, true);
            modules.AddModule(
                adminPageId,
                1,
                StringsRightPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidModules)),
                0,
                StrAdmins,
                StrAllUsers,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // End Change [email protected]
            // Change by [email protected]
            // Add Signin Module and put it on the hometab
            // Signin
            localizedString = General.GetString("MODULE_LOGIN", "Login");
            modules.UpdateModuleDefinitions(new Guid(StrGuidLogin), portalId, true);
            modules.AddModule(
                homePageId,
                -1,
                StrLeftPane,
                localizedString,
                modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidLogin)),
                0,
                StrAdmins,
                "Unauthenticated Users;Admins;",
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                StrAdmins,
                false,
                string.Empty,
                false,
                false,
                false);

            // Add language switcher to available modules
            // Language Switcher
            modules.UpdateModuleDefinitions(new Guid(StrGuidLanguageSwitcher), portalId, true);

            // End of change by [email protected]
            // Create paths
            this.CreatePortalPath(portalPath);
            return(portalId);
        }
Exemple #9
0
        /// <summary>
        /// Handles the BeginRequest event of the AppleseedApplication control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected void AppleseedApplication_BeginRequest(object sender, EventArgs e)
        {
            string rawUrlLower = Request.RawUrl.ToLower();

            if (rawUrlLower != "/" && !rawUrlLower.Contains("/installer") && !rawUrlLower.Contains("/webresource.axd") && !File.Exists(Server.MapPath(rawUrlLower.Split('?')[0])))
            {
                Appleseed.Framework.Site.Data.PagesDB pagedb = new Framework.Site.Data.PagesDB();
                string redirectToUrl = pagedb.GetDynamicPageUrl(rawUrlLower);
                if (!string.IsNullOrEmpty(redirectToUrl))
                {
                    Response.Redirect(redirectToUrl, true);
                    return;
                }
            }
            //Appleseed.Framework.Site.Data.PagesDB pagedb = new Framework.Site.Data.PagesDB();
            //string redirectToUrl = pagedb.GetDynamicPageUrl(Request.RawUrl);
            //if (!string.IsNullOrEmpty(redirectToUrl))
            //{
            //    Response.Redirect(redirectToUrl, true);
            //    return;
            //}
            string Addwww = System.Configuration.ConfigurationManager.AppSettings.Get("AddWwwToRequest");

            if (Addwww != null && Addwww.Equals("true"))
            {
                if (!Request.IsSecureConnection)
                {
                    if (!Request.Url.AbsoluteUri.ToLower().Contains("www"))
                    {
                        var newUrl = Request.Url.AbsoluteUri.Replace("http://", "http://www.");
                        Response.Redirect(newUrl, true);
                    }
                }
            }

            /*Send a signal to allow custom js registration (not enabled yet)*/
            Bus.Send(new JSRegisterDescriptor()
            {
                Scripts = new List <string>()
            });

            var contextReader = new Reader(new WebContextReader());
            var context       = contextReader.Current;

            var currentUrl = context.Request.Path.ToLower();

            if (Debugger.IsAttached && currentUrl.Contains("trace.axd"))
            {
                return;
            }

            context.Trace.Warn("Application_BeginRequest :: " + currentUrl);
            if (Portal.PageID > 0)
            {
                var physicalPath = context.Server.MapPath(currentUrl.Substring(currentUrl.LastIndexOf("/") + 1));

                if (!File.Exists(physicalPath))
                {
                    // Rewrites the path
                    context.RewritePath("~/default.aspx?" + context.Request.ServerVariables["QUERY_STRING"]);
                }
            }
            else
            {
                var pname = currentUrl.Substring(currentUrl.LastIndexOf("/") + 1);

                // if the request was not caused by an MS Ajax Client script invoking a WS.
                if (!currentUrl.ToLower().EndsWith(".asmx/js"))
                {
                    if (!String.IsNullOrEmpty(pname) && pname.Length > 5)
                    {
                        pname = pname.Substring(0, pname.Length - 5);
                    }

                    if (Regex.IsMatch(pname, @"^\d+$"))
                    {
                        context.RewritePath(
                            string.Format(
                                "~/default.aspx?pageid={0}&{1}", pname, context.Request.ServerVariables["QUERY_STRING"]));
                    }
                }
            }

            // 1st Check: is it a dangerously malformed request?
            #region
            // Important patch http://support.microsoft.com/?kbid=887459
            if (context.Request.Path.IndexOf('\\') >= 0 ||
                Path.GetFullPath(context.Request.PhysicalPath) != context.Request.PhysicalPath)
            {
                throw new AppleseedRedirect(LogLevel.Warn, HttpStatusCode.NotFound, "Malformed request", null);
            }

            #endregion

            // 2nd Check: is the AllPortals Lock switched on?
            // let the user through if client IP address is in LockExceptions list, otherwise throw...
            #region
            if (Config.LockAllPortals)
            {
                var rawUrl       = context.Request.RawUrl.ToLower(CultureInfo.InvariantCulture);
                var lockRedirect = Config.LockRedirect;
                if (!rawUrl.EndsWith(lockRedirect))
                {
                    // construct IPList
                    var lockKeyHolders = Config.LockKeyHolders.Split(new[] { ';' });
                    var ipList         = new IPList();
                    foreach (var lockKeyHolder in lockKeyHolders)
                    {
                        if (lockKeyHolder.IndexOf("-") > -1)
                        {
                            ipList.AddRange(
                                lockKeyHolder.Substring(0, lockKeyHolder.IndexOf("-")),
                                lockKeyHolder.Substring(lockKeyHolder.IndexOf("-") + 1));
                        }
                        else
                        {
                            ipList.Add(lockKeyHolder);
                        }
                    }

                    // check if requestor's IP address is in allowed list
                    if (!ipList.CheckNumber(context.Request.UserHostAddress))
                    {
                        throw new PortalsLockedException();
                    }
                }
            }
            #endregion

            // 3rd Check: is database/code version correct?
            var requestUri      = context.Request.Url;
            var requestPath     = requestUri.AbsolutePath.ToLower(CultureInfo.InvariantCulture);
            var returnToRequest = CheckAndUpdateDB(context, requestPath);


            if (returnToRequest)
            {
                return;
            }

            // Get portalsettings and add both key "PortalSettings","PortalID" into the Context.Item if not exisit
            // All neccessory checks and oprations are managed by this method
            //[email protected] - 2014/12/16 - Get portalsettings by pageid and portal id
            PortalSettings portalSettings = PortalSettings.GetPortalSettingsbyPageID(Portal.PageID, Portal.UniqueID);

            Membership.Provider.ApplicationName     = portalSettings.PortalAlias;
            ProfileManager.Provider.ApplicationName = portalSettings.PortalAlias;
            Roles.ApplicationName = portalSettings.PortalAlias;

            var smartErrorRedirect = Config.SmartErrorRedirect;
            if (smartErrorRedirect.StartsWith("~/"))
            {
                smartErrorRedirect = smartErrorRedirect.TrimStart(new[] { '~' });
            }

            if (requestPath.EndsWith(smartErrorRedirect.ToLower(CultureInfo.InvariantCulture)))
            {
                return; // this is SmartError page... so continue
            }

            // WLF: This was backwards before so it would always set refreshSite true because the cookie was changed before it was checked.
            // WLF: REVIEW: This whole section needs a code review.
            // Try to get alias from cookie to determine if alias has been changed
            var refreshSite       = false;
            var portalAliasCookie = context.Request.Cookies["PortalAlias"];
            if (portalAliasCookie != null && portalAliasCookie.Value.ToLower() != Portal.UniqueID)
            {
                refreshSite = true; // Portal has changed since last page request
            }

            if (portalSettings != null)
            {
                portalAliasCookie = new HttpCookie("PortalAlias")
                {
                    Path = "/", Value = portalSettings.PortalAlias
                };
                if (context.Response.Cookies["PortalAlias"] == null)
                {
                    context.Response.Cookies.Add(portalAliasCookie);
                }
                else
                {
                    context.Response.Cookies.Set(portalAliasCookie);
                }
            }

            // if switching portals then clean parameters [TipTopWeb]
            // Must be the last instruction in this method
            var refreshedCookie = context.Request.Cookies["refreshed"];

            // 5/7/2006 Ed Daniel
            // Added hack for Http 302 by extending condition below to check for more than 3 cookies
            if (refreshSite && context.Request.Cookies.Keys.Count > 3)
            {
                // Sign out and force the browser to refresh only once to avoid any dead-lock
                if (refreshedCookie == null || refreshedCookie.Value == "false")
                {
                    var rawUrl             = context.Request.RawUrl;
                    var newRefreshedCookie = new HttpCookie("refreshed", "true")
                    {
                        Path    = "/",
                        Expires = DateTime.Now.AddMinutes(1)
                    };
                    if (refreshedCookie == null)
                    {
                        context.Response.Cookies.Add(newRefreshedCookie);
                    }
                    else
                    {
                        context.Response.Cookies.Set(newRefreshedCookie);
                    }

                    var msg =
                        string.Format(
                            "User logged out on global.asax line 423. Values -> refreshsite: {0}, context.Request.Cookies.Keys.count: {1}, rawurl: {2}",
                            refreshSite,
                            context.Request.Cookies.Keys.Count,
                            rawUrl);

                    ErrorHandler.Publish(
                        LogLevel.Warn,
                        msg);

                    // sign-out, if refreshed parameter on the command line we will not call it again
                    PortalSecurity.SignOut(rawUrl, false);
                }
            }

            // invalidate cookie, so the page can be refreshed when needed
            refreshedCookie = context.Request.Cookies["refreshed"];
            if (refreshedCookie != null && context.Request.Cookies.Keys.Count > 3)
            {
                var newRefreshedCookie = new HttpCookie("refreshed", "false")
                {
                    Path    = "/",
                    Expires = DateTime.Now.AddMinutes(1)
                };
                context.Response.Cookies.Set(newRefreshedCookie);
            }

            // This is done in order to allow the sitemap to reference a page that is outside this website.
            var targetPage = this.Request.Params["sitemapTargetPage"];
            if (!string.IsNullOrEmpty(targetPage))
            {
                int mvcPageId;
                if (int.TryParse(targetPage, out mvcPageId))
                {
                    var url = HttpUrlBuilder.BuildUrl(mvcPageId);
                    this.Response.Redirect(url);
                }
            }
        }
        /// <summary>
        /// The BindData helper method is used to update the tab's
        /// layout panes with the current configuration information
        /// </summary>
        private void BindData()
        {
            // Populate the "ParentTab" Data
            DataTable dt_Pages = new PagesDB().GetPagesFlatTable(this.PortalSettings.PortalID);
            DataColumn[] keys = new DataColumn[2];
            keys[0] = dt_Pages.Columns["PageID"];
            dt_Pages.PrimaryKey = keys;

            parentTabDropDown.DataSource = dt_Pages;
            parentTabDropDown.DataValueField = "PageID";
            parentTabDropDown.DataTextField = "PageOrder1";
            parentTabDropDown.DataBind();
            parentTabDropDown.Items.Insert(0, new ListItem(General.GetString("ROOT_LEVEL", "Root Level"), "0"));
        }
        /// <summary>
        /// The AddTabButton_Click server event handler 
        /// on this page is used to add a new portal module 
        /// into the tab
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTabButton_Click(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // Hide error message in case there was a previous error.
                moduleError.Visible = false;

                // This allows the user to pick what type of people can view the module being added.
                // If Authorised Roles is selected from the dropdown then every role that has view permission for the
                // Add Role module will be added to the view permissions of the module being added.
                string viewPermissionRoles = PermissionDropDown.SelectedValue.ToString();
                if (viewPermissionRoles == "Authorised Roles")
                {
                    viewPermissionRoles = PortalSecurity.GetViewPermissions(ModuleID);
                }

                try
                {
                    // New tabs go to the end of the list
                    PageItem t = new PageItem();
                    t.Name = TabTitleTextBox.Text;
                    t.ID = -1;
                    t.Order = 990000;

                    // Get Parent Tab Id Convert only once used many times
                    var parentTabID = int.Parse(parentTabDropDown.SelectedValue);

                    // write tab to database
                    PagesDB tabs = new PagesDB();
                    t.ID =
                        tabs.AddPage(this.PortalSettings.PortalID, parentTabID, t.Name, t.Order, viewPermissionRoles,
                                     cb_ShowMobile.Checked, tb_MobileTabName.Text);

                    CurrentCache.RemoveAll("_TabNavigationSettings_");

                    AppleseedSiteMapProvider.ClearAllAppleseedSiteMapCaches();

                    //Jump to Page option
                    string returnTab = string.Empty;
                    if (rbl_JumpToTab.SelectedValue.ToString() == "Yes")
                    {
                        // Redirect to New Page/Tab - Mike Stone 30/12/2004
                        // modified by Hongwei Shen 9/25/2005
                        // returnTab = HttpUrlBuilder.BuildUrl(""~/"+HttpUrlBuilder.DefaultPage", t.ID, "SelectedTabID=" + t.ID.ToString());
                        string newPage = "~/" + t.Name.Trim().Replace(" ", "_") + ".aspx";
                        returnTab = HttpUrlBuilder.BuildUrl(newPage, t.ID);
                    }
                    else
                    {
                        // Do NOT Redirect to New Form - Mike Stone 30/12/2004
                        // I guess every .aspx page needs to have a module tied to it.
                        // or you will get an error about edit access denied.

                        // Modified by Hongwei Shen 9/25/2005 to fix: QueryString["tabID"] maybe null.
                        // returnTab = HttpUrlBuilder.BuildUrl("~/"+HttpUrlBuilder.DefaultPage, int.Parse(Request.QueryString["tabID"]), "SelectedTabID=" + t.ID.ToString());
                        returnTab =
                            HttpUrlBuilder.BuildUrl("~/" + HttpUrlBuilder.DefaultPage, PageID, "SelectedTabID=" + t.ID.ToString());
                    }
                    Response.Redirect(returnTab);
                }
                catch (Exception ex)
                {
                    moduleError.Visible = true;
                    ErrorHandler.Publish(LogLevel.Error,
                                         "There was an error with the Add Tab Module while trying to add a new tab.", ex);
                    return;
                }
                // Reload page to pick up changes
                Response.Redirect(Request.RawUrl, false);
            }
        }
        /// <summary>
        /// Creates the portal.
        /// </summary>
        /// <param name="templateID">The template ID.</param>
        /// <param name="templateAlias">The template alias.</param>
        /// <param name="portalAlias">The portal alias.</param>
        /// <param name="portalName">Name of the portal.</param>
        /// <param name="portalPath">The portal path.</param>
        /// <returns></returns>
        private int CreatePortal(int templateID, string templateAlias, string portalAlias, string portalName,
            string portalPath)
        {
            int newPortalID;

            PortalsDB portals = new PortalsDB();
            PagesDB tabs = new PagesDB();
            ModulesDB modules = new ModulesDB();
            UsersDB users = new UsersDB();

            // create an Array to stores modules ID and GUID for finding them later
            ArrayList templateModules = new ArrayList();
            moduleTemplate module;
            // create an Array to stores tabs ID for finding them later
            ArrayList templateTabs = new ArrayList();
            tabTemplate tab;

            // Create a new portal
            newPortalID = portals.AddPortal(portalAlias, portalName, portalPath);

            // Open the connection to the PortalTemplates Database
            SqlConnection myConnection = GetConnection();
            SqlConnection my2ndConnection = GetConnection();
            SqlConnection my3rdConnection = GetConnection();
            myConnection.Open();
            my2ndConnection.Open();
            my3rdConnection.Open();

            // get module definitions and save them in the new portal
            SqlDataReader myReader = GetTemplateModuleDefinitions(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                module.id = (int)myReader["ModuleDefID"];
                module.GuidID = GetGeneralModuleDefinitionByName(myReader["FriendlyName"].ToString(), my2ndConnection);
                try {
                    // save module definitions in the new portal
                    modules.UpdateModuleDefinitions(module.GuidID, newPortalID, true);
                    // Save the modules into a list for finding them later
                    templateModules.Add(module);
                } catch {
                    // tried to add a Module thas doesn´t exists in this implementation of the portal
                }
            }

            myReader.Close();

            // TODO: Is this still valid? Admin user will be created the first time the portal is accessed
            //if (!Config.UseSingleUserBase)
            //{
            //    // TODO: multiple portals still not supported
            //    Guid userID;

            //    // Create the "admin" User for the new portal
            //    string AdminEmail = "*****@*****.**";
            //    userID = users.AddUser("admin", AdminEmail, "admin", newPortalID);

            //    // Create a new row in a many to many table (userroles)
            //    // giving the "admins" role to the "admin" user
            //    users.AddUserRole("admin", userID);
            //}

            // Get all the Tabs in the Template Portal, store IDs in a list for finding them later
            // and create the Tabs in the new Portal
            myReader = GetTabsByPortal(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                // Save the tabs into a list for finding them later
                tab.oldID = (int)myReader["PageID"];
                tab.newID =
                    tabs.AddPage(newPortalID, myReader["PageName"].ToString(),
                                 Int32.Parse(myReader["PageOrder"].ToString()));
                templateTabs.Add(tab);
            }
            myReader.Close();

            //Clear SiteMaps Cache
            AppleseedSiteMapProvider.ClearAllAppleseedSiteMapCaches();

            // now I have to get them again to set up the ParentID for each Tab
            myReader = GetTabsByPortal(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                // Find the news TabID and ParentTabID
                IEnumerator myEnumerator = templateTabs.GetEnumerator();
                int newTabID = -1;
                int newParentTabID = -1;

                while (myEnumerator.MoveNext() && (newTabID == -1 || newParentTabID == -1)) {
                    tab = (tabTemplate)myEnumerator.Current;
                    if (tab.oldID == (int)myReader["PageID"])
                        newTabID = tab.newID;
                    if (tab.oldID == Int32.Parse("0" + myReader["ParentPageID"]))
                        newParentTabID = tab.newID;
                }

                if (newParentTabID == -1)
                    newParentTabID = 0;

                // Update the Tab in the new portal
                tabs.UpdatePage(newPortalID, newTabID, newParentTabID, myReader["PageName"].ToString(),
                                Int32.Parse(myReader["PageOrder"].ToString()), myReader["AuthorizedRoles"].ToString(),
                                myReader["MobilePageName"].ToString(), (bool)myReader["ShowMobile"]);

                // Finally use GetPortalSettings to access each Tab and its Modules in the Template Portal
                // and create them in the new Portal
                SqlDataReader result;

                try {
                    result = GetPageModules(Int32.Parse(myReader["PageID"].ToString()), my2ndConnection);

                    object myValue;

                    while (result.Read()) {
                        ModuleSettings m = new ModuleSettings();
                        m.ModuleID = (int)result["ModuleID"];
                        m.ModuleDefID = (int)result["ModuleDefID"];
                        m.PageID = newTabID;
                        m.PaneName = (string)result["PaneName"];
                        m.ModuleTitle = (string)result["ModuleTitle"];

                        myValue = result["AuthorizedEditRoles"];
                        m.AuthorizedEditRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedViewRoles"];
                        m.AuthorizedViewRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedAddRoles"];
                        m.AuthorizedAddRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedDeleteRoles"];
                        m.AuthorizedDeleteRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedPropertiesRoles"];
                        m.AuthorizedPropertiesRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedMoveModuleRoles"];
                        m.AuthorizedMoveModuleRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedDeleteModuleRoles"];
                        m.AuthorizedDeleteModuleRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["AuthorizedPublishingRoles"];
                        m.AuthorizedPublishingRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["SupportWorkflow"];
                        m.SupportWorkflow = !Convert.IsDBNull(myValue) ? (bool)myValue : false;

                        myValue = result["AuthorizedApproveRoles"];
                        m.AuthorizedApproveRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty;

                        myValue = result["WorkflowState"];
                        m.WorkflowStatus = !Convert.IsDBNull(myValue)
                                               ? (WorkflowState)(0 + (byte)myValue)
                                               : WorkflowState.Original;

                        try {
                            myValue = result["SupportCollapsable"];
                        } catch {
                            myValue = DBNull.Value;
                        }
                        m.SupportCollapsable = DBNull.Value != myValue ? (bool)myValue : false;

                        try {
                            myValue = result["ShowEveryWhere"];
                        } catch {
                            myValue = DBNull.Value;
                        }
                        m.ShowEveryWhere = DBNull.Value != myValue ? (bool)myValue : false;

                        m.CacheTime = int.Parse(result["CacheTime"].ToString());
                        m.ModuleOrder = int.Parse(result["ModuleOrder"].ToString());

                        myValue = result["ShowMobile"];
                        m.ShowMobile = !Convert.IsDBNull(myValue) ? (bool)myValue : false;

                        // Find the new ModuleDefID assigned to the module in the new portal
                        myEnumerator = templateModules.GetEnumerator();
                        int newModuleDefID = 0;

                        while (myEnumerator.MoveNext() && newModuleDefID == 0) {
                            module = (moduleTemplate)myEnumerator.Current;
                            if (module.id == m.ModuleDefID)
                                newModuleDefID = modules.GetModuleDefinitionByGuid(newPortalID, module.GuidID);
                        }

                        if (newModuleDefID > 0) {
                            // add the module to the new tab
                            int newModuleID = modules.AddModule(newTabID, m.ModuleOrder, m.PaneName, m.ModuleTitle,
                                                                newModuleDefID, m.CacheTime, m.AuthorizedEditRoles,
                                                                m.AuthorizedViewRoles,
                                                                m.AuthorizedAddRoles, m.AuthorizedDeleteRoles,
                                                                m.AuthorizedPropertiesRoles,
                                                                m.AuthorizedMoveModuleRoles,
                                                                m.AuthorizedDeleteModuleRoles,
                                                                m.ShowMobile, m.AuthorizedPublishingRoles,
                                                                m.SupportWorkflow,
                                                                m.ShowEveryWhere, m.SupportCollapsable);
                            // At the end, get all ModuleSettings and save them in the new module
                            SqlDataReader dr = GetModuleSettings(m.ModuleID, my3rdConnection);

                            while (dr.Read()) {
                                Framework.Site.Configuration.ModuleSettings.UpdateModuleSetting(newModuleID, dr["SettingName"].ToString(),
                                                                   dr["SettingValue"].ToString());
                            }
                            dr.Close();
                        }
                    }

                    result.Close();
                } catch {
                    // Error? ignore Tab ...
                }
            }
            myReader.Close();

            // Set the CustomSettings of the New Portal based in the Template Portal
            myReader = GetPortalCustomSettings(templateID, myConnection);

            // Always call Read before accessing data.
            while (myReader.Read()) {
                PortalSettings.UpdatePortalSetting(newPortalID, myReader["SettingName"].ToString(),
                                                   myReader["SettingValue"].ToString());
            }

            myReader.Close();

            // close the conections
            myConnection.Close();
            myConnection.Dispose();
            my2ndConnection.Close();
            my2ndConnection.Dispose();
            my3rdConnection.Close();
            my3rdConnection.Dispose();

            // Create paths
            portals.CreatePortalPath(portalPath);

            return newPortalID;
        }
        /// <summary>
        /// The SavePageData helper method is used to persist the
        /// current tab settings to the database.
        /// </summary>
        /// <returns></returns>
        private int SavePageData()
        {
            // Construct Authorized User Roles string
            string authorizedRoles = "";

            foreach ( ListItem item in authRoles.Items ) {
                if ( item.Selected == true ) {
                    authorizedRoles = authorizedRoles + item.Text + ";";
                }
            }

            // Add Page info in the database
            int NewPageID =
                new PagesDB().AddPage(this.PortalSettings.PortalID, Int32.Parse(parentPage.SelectedItem.Value), tabName.Text,
                                      990000, authorizedRoles, showMobile.Checked, mobilePageName.Text);
            //Clear SiteMaps Cache
            AppleseedSiteMapProvider.ClearAllAppleseedSiteMapCaches();

            // Update custom settings in the database
            EditTable.UpdateControls();
            return NewPageID;
        }
        /// <summary>
        /// The OrderPages helper method is used to reset
        ///   the display order for tabs within the portal
        /// </summary>
        /// <remarks>
        /// </remarks>
        private void OrderPages()
        {
            var i = 1;
            this.PortalPages = new PagesDB().GetPagesFlat(this.PortalSettings.PortalID);
            this.PortalPages.Sort();

            foreach (var t in this.PortalPages)
            {
                // number the items 1, 3, 5, etc. to provide an empty order
                // number when moving items up and down in the list.
                t.Order = i;
                i += 2;

                // rewrite tab to database
                var tabs = new PagesDB();

                // 12/16/2002 Start - Cory Isakson
                tabs.UpdatePageOrder(t.ID, t.Order);

                // 12/16/2002 End - Cory Isakson
            }
            CurrentCache.RemoveAll("_PageNavigationSettings_");
        }
        public JsonResult create(int id)
        {
            PagesDB db = new PagesDB();

            this.PortalPages = db.GetPagesFlat(this.PortalSettings.PortalID);
            var t = new PageItem
            {
                Name = General.GetString("TAB_NAME", "New Page Name"),
                ID = -1,
                Order = 990000
            };

            this.PortalPages.Add(t);

            var tabs = new PagesDB();
            t.ID = tabs.AddPage(this.PortalSettings.PortalID, t.Name, t.Order);

            db.UpdatePageParent(t.ID, id, this.PortalSettings.PortalID);

            this.OrderPages();
            //JsonResult treeData = GetTreeData();
            return Json("");
        }
        public JsonResult Clone(int id, int parentId)
        {
            try
            {
                var generalModuleDef = Guid.Parse("F9F9C3A4-6E16-43B4-B540-984DDB5F1CD2");
                object[] queryargs = { generalModuleDef, PortalSettings.PortalID };

                int moduleDefinition;

                try
                {
                    moduleDefinition =
                        new rb_ModuleDefinitions().All(where: "GeneralModDefID = @0 and PortalID = @1", args: queryargs).Single().ModuleDefID;
                }
                catch(Exception e)
                {
                    // Shortcut module doesn't exist in current Portal

                    var modules = new ModulesDB();

                    modules.UpdateModuleDefinitions(
                            generalModuleDef,
                            PortalSettings.PortalID,
                            true);

                    moduleDefinition =
                        new rb_ModuleSettings().All(where: "GeneralModDefID = @0 and PortalID = @1", args: queryargs).Single().ModuleDefID;

                }

                var db = new PagesDB();

                PortalPages = db.GetPagesFlat(PortalSettings.PortalID);
                var t = new PageItem
                            {
                                Name = General.GetString("TAB_NAME", "New Page Name"),
                                ID = -1,
                                Order = 990000
                            };

                PortalPages.Add(t);

                var tabs = new PagesDB();
                t.ID = tabs.AddPage(PortalSettings.PortalID, t.Name, t.Order);

                db.UpdatePageParent(t.ID, parentId, PortalSettings.PortalID);

                OrderPages();
                //JsonResult treeData = GetTreeData();

                // Coping Modules

                var pagesModules = new rb_Modules().All(where: "TabID = @0", args: id);

                foreach (var module in pagesModules)
                {
                    var m = new ModuleItem();
                    m.Title = module.ModuleTitle;
                    m.ModuleDefID = moduleDefinition;
                    m.Order = module.ModuleOrder;

                    // save to database
                    var mod = new ModulesDB();

                    m.ID = mod.AddModule(
                        t.ID,
                        m.Order,
                        module.PaneName,
                        module.ModuleTitle,
                        m.ModuleDefID,
                        0,
                        module.AuthorizedEditRoles,
                        module.AuthorizedViewRoles,
                        module.AuthorizedAddRoles,
                        module.AuthorizedDeleteRoles,
                        module.AuthorizedPropertiesRoles,
                        module.AuthorizedMoveModuleRoles,
                        module.AuthorizedDeleteModuleRoles,
                        false,
                        PortalSecurity.GetDeleteModulePermissions(module.ModuleID),
                        false,
                        false,
                        false);

                    var settings = new rb_ModuleSettings();
                    settings.Insert(new { ModuleID = m.ID, SettingName = "LinkedModule", SettingValue = module.ModuleID });

                }

                return Json(new {pageId = t.ID});
            }
            catch(Exception e)
            {
                ErrorHandler.Publish(LogLevel.Error, e);
                Response.StatusCode = 500;
                return Json("");
            }
        }
        public JsTreeModel[] getChildrenTree(PageItem page)
        {
            List<PageStripDetails> childPages = new PagesDB().GetPagesinPage(this.PortalSettings.PortalID, page.ID);
            int count = 0;
            List<JsTreeModel> lstTree = new List<JsTreeModel>();

            foreach (PageStripDetails childPage in childPages)
            {
                PageItem aux = new PageItem ();
                aux.ID = childPage.PageID;
                aux.Name = childPage.PageName;

                //JsTreeModel[] childs = getChildrenTree(aux);
                JsTreeModel node = new JsTreeModel
                {
                    data = aux.Name,
                    attr = new JsTreeAttribute { id = "pjson_" + aux.ID.ToString()},
                    //children = childs,
                    state = "closed"
                };

                lstTree.Add(node);
                count++;
            }
            JsTreeModel[] tree = lstTree.ToArray<JsTreeModel>();

            return tree;
        }
        /// <summary>
        /// The BindData helper method is used to update the tab's
        ///   layout panes with the current configuration information
        /// </summary>
        /// <remarks>
        /// </remarks>
        private void BindData()
        {
            var page = this.PortalSettings.ActivePage;

            // Populate Page Names, etc.
            this.tabName.Text = page.PageName;
            this.mobilePageName.Text = page.MobilePageName;
            this.showMobile.Checked = page.ShowMobile;

            // Populate the "ParentPage" Data
            var t = new PagesDB();
            var items = t.GetPagesParent(this.PortalSettings.PortalID, this.PageID);
            this.parentPage.DataSource = items;
            this.parentPage.DataBind();

            if (this.parentPage.Items.FindByValue(page.ParentPageID.ToString()) != null)
            {
                // parentPage.Items.FindByValue( tab.ParentPageID.ToString() ).Selected = true;
                this.parentPage.SelectedValue = page.ParentPageID.ToString();
            }

            // Translate
            if (this.parentPage.Items.FindByText(" ROOT_LEVEL") != null)
            {
                this.parentPage.Items.FindByText(" ROOT_LEVEL").Text = General.GetString(
                    "ROOT_LEVEL", "Root Level", this.parentPage);
            }

            // Populate checkbox list with all security roles for this portal
            // and "check" the ones already configured for this tab
            var users = new UsersDB();
            var roles = users.GetPortalRoles(this.PortalSettings.PortalAlias);

            // Clear existing items in checkboxlist
            this.authRoles.Items.Clear();

            foreach (var role in roles)
            {
                var item = new ListItem();
                item.Text = role.Name;
                item.Value = role.Id.ToString();

                if (page.AuthorizedRoles.LastIndexOf(item.Text) > -1)
                {
                    item.Selected = true;
                }

                this.authRoles.Items.Add(item);
            }

            // Populate the "Add Module" Data
            var m = new ModulesDB();
            var modules = new SortedList<string, string>();
            var drCurrentModuleDefinitions = m.GetCurrentModuleDefinitions(this.PortalSettings.PortalID);
            //if (PortalSecurity.IsInRoles("Admins") || !bool.Parse(drCurrentModuleDefinitions["Admin"].ToString()))
            //{
            var htmlId = "0";
            try {
                while (drCurrentModuleDefinitions.Read()) {
                    if ((!modules.ContainsKey(drCurrentModuleDefinitions["FriendlyName"].ToString())) &&
                        (PortalSecurity.IsInRoles("Admins") || !bool.Parse(drCurrentModuleDefinitions["Admin"].ToString()))) {
                        modules.Add(
                            // moduleType.Items.Add(
                            // new ListItem(drCurrentModuleDefinitions["FriendlyName"].ToString(),
                            // drCurrentModuleDefinitions["ModuleDefID"].ToString()));
                            drCurrentModuleDefinitions["FriendlyName"].ToString(),
                            drCurrentModuleDefinitions["ModuleDefID"].ToString());
                        if (drCurrentModuleDefinitions["FriendlyName"].ToString().Equals("HTML Content"))
                            htmlId = drCurrentModuleDefinitions["ModuleDefID"].ToString();
                    }
                }
            }
            finally {
                drCurrentModuleDefinitions.Close();
            }
            //}

            // Dictionary<string, string> actions = ModelServices.GetMVCActionModules();
            // foreach (string key in actions.Keys) {
            // modules.Add(key, actions[key]);
            // }
            this.moduleType.DataSource = modules;
            this.moduleType.DataBind();
            this.moduleType.SelectedValue = htmlId;

            // Now it's the load is by ajax 1/september/2011
            // Populate Top Pane Module Data
            //this.topList = this.GetModules("TopPane");
            //this.topPane.DataBind();

            //// Populate Left Hand Pane Module Data
            //this.leftList = this.GetModules("LeftPane");
            //this.leftPane.DataBind();

            //// Populate Content Pane Module Data
            //this.contentList = this.GetModules("ContentPane");
            //this.contentPane.DataBind();

            //// Populate Right Hand Module Data
            //this.rightList = this.GetModules("RightPane");
            //this.rightPane.DataBind();

            //// Populate Bottom Module Data
            //this.bottomList = this.GetModules("BottomPane");
            //this.bottomPane.DataBind();
        }
        /// <summary>
        /// The AddPage_Click server event handler is used
        ///   to add a new tab for this portal
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> instance containing the event data.
        /// </param>
        /// <remarks>
        /// </remarks>
        protected void AddPageClick(object sender, EventArgs e)
        {
            if (this.Settings["TAB_VERSION"] == null)
            {
                return;
            }

            if (this.Settings["TAB_VERSION"].ToString().ToLowerInvariant() == "true")
            {
                // Use Old Version
                // New tabs go to the end of the list
                var t = new PageItem
                    {
                        // Just in case it comes to be empty
                        Name = General.GetString("TAB_NAME", "New Page Name"),
                        ID = -1,
                        Order = 990000
                    };
                this.PortalPages.Add(t);

                // write tab to database
                var tabs = new PagesDB();
                t.ID = tabs.AddPage(this.PortalSettings.PortalID, t.Name, t.Order);

                // Reset the order numbers for the tabs within the list
                this.OrderPages();

                // Clear SiteMaps Cache
                AppleseedSiteMapProvider.ClearAllAppleseedSiteMapCaches();

                // Redirect to edit page
                // 3_aug_2004 Cory Isakson added returntabid so that PageLayout could return to the tab it was called from.
                // added mID by Mario Endara <*****@*****.**> to support security check (2004/11/09)
                this.Response.Redirect(
                    HttpUrlBuilder.BuildUrl(
                        "~/DesktopModules/CoreModules/Pages/PageLayout.aspx",
                        t.ID,
                        "mID=" + this.ModuleID + "&returntabid=" + this.Page.PageID));
            }
            else
            {
                // Redirect to New Form - Mike Stone 19/12/2004
                this.Response.Redirect(
                    HttpUrlBuilder.BuildUrl(
                        "~/DesktopModules/CoreModules/Pages/AddPage.aspx",
                        "mID=" + this.ModuleID + "&returntabid=" + this.Page.PageID));
            }
        }