Beispiel #1
0
        /// <summary>
        /// The Page_Load server event handler on this user control is used
        ///  to populate the current portals list from the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            portals = new ArrayList();
            PortalsDB     portalsDb = new PortalsDB();
            SqlDataReader dr        = portalsDb.GetPortals();

            try
            {
                while (dr.Read())
                {
                    PortalItem p = new PortalItem();
                    p.Name = dr["PortalName"].ToString();
                    p.Path = dr["PortalPath"].ToString();
                    p.ID   = Convert.ToInt32(dr["PortalID"].ToString());
                    portals.Add(p);
                }
            }
            finally
            {
                dr.Close();                 //by Manu, fixed bug 807858
            }

            // If this is the first visit to the page, bind the tab data to the page listbox
            if (Page.IsPostBack == false)
            {
                portalList.DataBind();
            }
        }
Beispiel #2
0
        /// <summary>
        /// OnDelete
        /// </summary>
        override protected void OnDelete()
        {
            if (portalList.SelectedIndex != -1)
            {
                try
                {
                    // must delete from database too
                    PortalItem p         = (PortalItem)portals[portalList.SelectedIndex];
                    PortalsDB  portalsdb = new PortalsDB();
                    //Response.Write("Will delete " + p.Name);
                    portalsdb.DeletePortal(p.ID);

                    // remove item from list
                    portals.RemoveAt(portalList.SelectedIndex);
                    // rebind list
                    portalList.DataBind();
                }
                catch (System.Data.SqlClient.SqlException sqlex)
                {
                    Rainbow.Configuration.ErrorHandler.HandleException(Esperantus.Localize.GetString("DELETE_PORTAL_ERROR", "There was an error on deleting the portal", this), sqlex);
                    Controls.Add(new LiteralControl("<br><span class=NormalRed>" + Esperantus.Localize.GetString("DELETE_PORTAL_ERROR", "There was an error on deleting the portal", this) + "<br>"));
                }
            }
            base.OnDelete();
        }
        /// <summary>
        /// OnDelete
        /// </summary>
        protected override void OnDelete()
        {
            if (portalList.SelectedIndex != -1)
            {
                try
                {
                    // must delete from database too
                    PortalItem p         = (PortalItem)portals[portalList.SelectedIndex];
                    PortalsDB  portalsdb = new PortalsDB();
                    //Response.Write("Will delete " + p.Name);
                    portalsdb.DeletePortal(p.ID);

                    // remove item from list
                    portals.RemoveAt(portalList.SelectedIndex);
                    // rebind list
                    portalList.DataBind();
                }
                catch (SqlException sqlex)
                {
                    string aux =
                        General.GetString("DELETE_PORTAL_ERROR", "There was an error on deleting the portal", this);
                    Rainbow.Framework.ErrorHandler.Publish(Rainbow.Framework.LogLevel.Error, aux, sqlex);
                    Controls.Add(new LiteralControl("<br><span class=NormalRed>" + aux + "<br>"));
                }
            }
            base.OnDelete();
        }
        /// <summary>
        /// The Page_Load server event handler on this user control is used
        /// to populate the current portals list from the database
        /// </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>
        private void Page_Load(object sender, EventArgs e)
        {
            portals = new ArrayList();
            PortalsDB     portalsDb = new PortalsDB();
            SqlDataReader dr        = portalsDb.GetPortals();

            try
            {
                while (dr.Read())
                {
                    PortalItem p = new PortalItem();
                    p.Name = dr["PortalName"].ToString();
                    p.Path = dr["PortalPath"].ToString();
                    p.ID   = Convert.ToInt32(dr["PortalID"].ToString());
                    portals.Add(p);
                }
            }
            finally
            {
                dr.Close(); //by Manu, fixed bug 807858
            }

            // If this is the first visit to the page, bind the tab data to the page listbox
            if (Page.IsPostBack == false)
            {
                portalList.DataBind();
            }
            EditBtn.ImageUrl   = CurrentTheme.GetImage("Buttons_Edit", "Edit.gif").ImageUrl;
            DeleteBtn.ImageUrl = CurrentTheme.GetImage("Buttons_Delete", "Delete.gif").ImageUrl;
            DeleteBtn.Attributes.Add("onclick", "return confirmDelete();");
        }
Beispiel #5
0
        private int CreatePortal(out bool createdOk)
        {
            string fileName    = ddlXMLTemplates.Text;
            string portalAlias = AliasField.Text;
            string portalName  = TitleField.Text;
            string portalPath  = "/" + PathField.Text;
            IPortalTemplateRepository repository = new PortalTemplateRepository();
            IPortalTemplateServices   services   = PortalTemplateFactory.GetPortalTemplateServices(repository);
            int newPortalID = 1;

            createdOk = services.DeserializePortal(fileName, portalName, portalAlias, portalPath, PortalSettings.PortalFullPath, out newPortalID);
            if (createdOk && !Config.UseSingleUserBase)
            {
                string AdminEmail = "*****@*****.**";

                // Create the stradmin User for the new portal
                UsersDB User = new UsersDB();
                // Create the "Admins" role for the new portal
                Guid roleID = User.AddRole(portalAlias, "Admins");
                Guid userID = User.AddUser("admin", AdminEmail, "admin", portalAlias);
                // Create a new row in a many to many table (userroles)
                // giving the "admins" role to the stradmin user
                User.AddUserRole(roleID, userID, portalAlias);
                PortalsDB portals = new PortalsDB();

                portals.CreatePortalPath(portalPath);
            }
            return(newPortalID);
        }
Beispiel #6
0
        /// <summary>
        /// OnUpdate
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected override void OnUpdate(EventArgs e)
        {
            base.OnUpdate(e);

            if (Page.IsValid)
            {
                //Get Solutions
                PortalsDB portals = new PortalsDB();

                try {
                    PathField.Text = PathField.Text.Replace("/", string.Empty);
                    PathField.Text = PathField.Text.Replace("\\", string.Empty);
                    PathField.Text = PathField.Text.Replace(".", string.Empty);

                    if (!chkUseXMLTemplate.Checked)
                    {
                        // Create portal the "old" way
                        int NewPortalID =
                            portals.CreatePortal(this.PortalSettings.PortalID, AliasField.Text, TitleField.Text, PathField.Text);

                        // Update custom settings in the database
                        EditTable.ObjectID = NewPortalID;
                        EditTable.UpdateControls();
                    }
                    else
                    {
                        bool createdOk   = true;
                        int  newPortalID = CreatePortal(out createdOk);
                        if (!createdOk)
                        {
                            string aux = General.GetString("NEW_PORTAL_ERROR", "There was an error on creating the portal", this);

                            ErrorMessage.Visible = true;
                            ErrorMessage.Text    = aux + "<br>";
                            return;
                        }
                    }


                    // Redirect back to calling page
                    RedirectBackToReferringPage();
                } catch (Exception ex) {
                    string aux =
                        General.GetString("NEW_PORTAL_ERROR", "There was an error on creating the portal", this);
                    ErrorHandler.Publish(LogLevel.Error, aux, ex);

                    ErrorMessage.Visible = true;
                    ErrorMessage.Text    = aux + "<br>";
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// OnUpdate
        /// </summary>
        protected override void OnUpdate(EventArgs e)
        {
            base.OnUpdate(e);

            if (Page.IsValid)
            {
                //Get Solutions
                PortalsDB portals = new PortalsDB();

                try
                {
                    PathField.Text = PathField.Text.Replace("/", string.Empty);
                    PathField.Text = PathField.Text.Replace("\\", string.Empty);
                    PathField.Text = PathField.Text.Replace(".", string.Empty);
                    if (chkUseTemplate.Checked == false)
                    {
                        // Create portal the "old" way
                        int NewPortalID = portals.CreatePortal(Convert.ToInt32(SolutionsList.SelectedItem.Value), AliasField.Text, TitleField.Text, PathField.Text);

                        // Update custom settings in the database
                        EditTable.ObjectID = NewPortalID;
                        EditTable.UpdateControls();
                    }
                    else
                    {
                        //Create portal based on the selected portal
                        int NewPortalID = CreatePortal(Convert.ToInt32(SolutionsList.SelectedItem.Value),
                                                       SolutionsList.SelectedItem.Text, AliasField.Text, TitleField.Text, PathField.Text);
                    }

                    // Redirect back to calling page
                    RedirectBackToReferringPage();
                }
                catch (Exception ex)
                {
                    Rainbow.Configuration.ErrorHandler.HandleException(Esperantus.Localize.GetString("NEW_PORTAL_ERROR", "There was an error on creating the portal", this), ex);

                    ErrorMessage.Visible = true;
                    ErrorMessage.Text    = Esperantus.Localize.GetString("NEW_PORTAL_ERROR", "There was an error on creating the portal", this) + "<br>";
                    //ErrorMessage.Text += ex.Message;
                }
            }
        }
Beispiel #8
0
        private void LoadPortalList()
        {
            portals = new ArrayList();
            PortalsDB     portalsDb = new PortalsDB();
            SqlDataReader dr        = portalsDb.GetPortals();

            try {
                while (dr.Read())
                {
                    PortalItem p = new PortalItem();
                    p.Name = dr["PortalName"].ToString();
                    p.Path = dr["PortalPath"].ToString();
                    p.ID   = Convert.ToInt32(dr["PortalID"].ToString());
                    portals.Add(p);
                }
            } finally {
                dr.Close(); //by Manu, fixed bug 807858
            }
        }
Beispiel #9
0
        private int CreatePortal(int templateID, string templateAlias, string portalAlias, string portalName, string portalPath)
        {
            int newPortalID;

            PortalsDB portals = new PortalsDB();
            TabsDB    tabs    = new TabsDB();
            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();

            if (!PortalSettings.UseSingleUserBase)
            {
                int roleID;
                int userID;
                int adminRoleID = 0;

                // get roles and save them in the new portal
                myReader = GetPortalRoles(templateID, myConnection);

                // Always call Read before accessing data.
                while (myReader.Read())
                {
                    roleID = users.AddRole(newPortalID, myReader["RoleName"].ToString());
                    if (myReader["RoleName"].ToString() == "Admins")
                    {
                        adminRoleID = roleID;
                    }
                }

                myReader.Close();

                // 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(adminRoleID, 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["TabID"];
                tab.newID = tabs.AddTab(newPortalID, myReader["TabName"].ToString(), Int32.Parse(myReader["TabOrder"].ToString()));
                templateTabs.Add(tab);
            }
            myReader.Close();

            // 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
                System.Collections.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["TabID"])
                    {
                        newTabID = tab.newID;
                    }
                    if (tab.oldID == Int32.Parse("0" + myReader["ParentTabID"]))
                    {
                        newParentTabID = tab.newID;
                    }
                }

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

                // Update the Tab in the new portal
                tabs.UpdateTab(newPortalID, newTabID, newParentTabID, myReader["TabName"].ToString(),
                               Int32.Parse(myReader["TabOrder"].ToString()), myReader["AuthorizedRoles"].ToString(),
                               myReader["MobileTabName"].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 = GetTabModules(Int32.Parse(myReader["TabID"].ToString()), my2ndConnection);

                    object myValue;

                    while (result.Read())
                    {
                        ModuleSettings m = new ModuleSettings();
                        m.ModuleID    = (int)result["ModuleID"];
                        m.ModuleDefID = (int)result["ModuleDefID"];
                        m.TabID       = 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())
                            {
                                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);
        }