/// <summary> Refresh the URL portals list by pulling the data back from the database </summary>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool RefreshUrlPortals()
        {
            try
            {
                lock (portalsLock)
                {
                    if (portals == null)
                    {
                        portals = new Portal_List();
                    }

                    Engine_Database.Populate_URL_Portals(portals, null);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#2
0
        /// <summary> Constructor for a new instance of the Portals_AdminViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Portals_AdminViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Portals_AdminViewer.Constructor", String.Empty);

            // Set action message to nothing to start and some defaults
            actionMessage       = String.Empty;
            entered_portal_name = String.Empty;
            entered_sys_abbrev  = String.Empty;
            entered_web_skin    = String.Empty;
            entered_aggregation = String.Empty;
            entered_url_segment = String.Empty;
            entered_base_purl   = String.Empty;

            // If the RequestSpecificValues.Current_User cannot edit this, go back
            if ((RequestSpecificValues.Current_User == null) || ((!RequestSpecificValues.Current_User.Is_System_Admin) && (!RequestSpecificValues.Current_User.Is_Portal_Admin)))
            {
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.My_Sobek;
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            readOnlyMode = true;
            if (((RequestSpecificValues.Current_User.Is_System_Admin) && (!UI_ApplicationCache_Gateway.Settings.Servers.isHosted)) ||
                (RequestSpecificValues.Current_User.Is_Host_Admin))
            {
                readOnlyMode = false;
            }

            // Handle any post backs
            if (RequestSpecificValues.Current_Mode.isPostBack)
            {
                if (!readOnlyMode)
                {
                    try
                    {
                        // Pull the standard values from the form
                        NameValueCollection form = HttpContext.Current.Request.Form;
                        string save_value        = form["admin_portal_tosave"];
                        string action_value      = form["admin_portal_action"];

                        // Switch, depending on the request
                        if (action_value != null)
                        {
                            switch (action_value.Trim().ToLower())
                            {
                            case "edit":
                                // Get the values from the form for this new portal
                                string edit_name = form["form_portal_name"].Trim();
                                string edit_abbr = form["form_portal_abbr"].Trim();
                                string edit_skin = form["form_portal_skin"].Trim();
                                string edit_aggr = String.IsNullOrEmpty(form["form_portal_aggregation"]) ? String.Empty : form["form_portal_aggregation"].Trim();
                                string edit_url  = form["form_portal_url"].Trim();
                                string edit_purl = form["form_portal_purl"].Trim();
                                int    portalid  = Convert.ToInt32(save_value);

                                // Look for this to see if this was the pre-existing default
                                bool isDefault = UI_ApplicationCache_Gateway.URL_Portals.Default_Portal.ID == portalid;


                                // Don't edit if the URL segment is empty and this is NOT default
                                if ((!isDefault) && (edit_url.Trim().Length == 0))
                                {
                                    actionMessage = "ERROR: Non default portals MUST have a url segment associated.";
                                }
                                else if (edit_name.Length == 0)
                                {
                                    actionMessage = "ERROR: Portal name is a REQUIRED field.";
                                }
                                else if (edit_abbr.Length == 0)
                                {
                                    actionMessage = "ERROR: System abbreviation is a REQUIRED field";
                                }
                                else
                                {
                                    // Look for matching portal or URL segment names
                                    bool portal_name_match = false;
                                    bool url_segment_match = false;
                                    foreach (Portal thisPortal in UI_ApplicationCache_Gateway.URL_Portals.All_Portals)
                                    {
                                        if (thisPortal.ID != portalid)
                                        {
                                            if (String.Compare(thisPortal.Name, edit_name, true) == 0)
                                            {
                                                portal_name_match = true;
                                                break;
                                            }

                                            if (String.Compare(thisPortal.URL_Segment, edit_url, true) == 0)
                                            {
                                                url_segment_match = true;
                                                break;
                                            }
                                        }
                                    }

                                    if (portal_name_match)
                                    {
                                        actionMessage = "ERROR: Portal name must be unique, and that name is already in use";
                                    }
                                    else if (url_segment_match)
                                    {
                                        actionMessage = "ERROR: URL segment must be unique, and that URL segment already exists";
                                    }
                                    else
                                    {
                                        bool result = edit_abbr.All(C => Char.IsLetterOrDigit(C) || C == '_');
                                        if (!result)
                                        {
                                            actionMessage = "ERROR: System abbreviation must include only letters and numbers";
                                            edit_abbr     = edit_abbr.Replace("\"", "");
                                        }
                                        else
                                        {
                                            // Now, save this portal information
                                            int edit_id = SobekCM_Database.Edit_URL_Portal(portalid, edit_url, true, isDefault, edit_abbr, edit_name, edit_aggr, edit_skin, edit_purl, RequestSpecificValues.Tracer);
                                            if (edit_id > 0)
                                            {
                                                actionMessage = "Edited existing URL portal '" + edit_name + "'";
                                            }
                                            else
                                            {
                                                actionMessage = "Error editing URL portal.";
                                            }
                                        }
                                    }
                                }
                                break;

                            case "delete":
                                actionMessage = SobekCM_Database.Delete_URL_Portal(Convert.ToInt32(save_value), RequestSpecificValues.Tracer) ? "URL portal deleted" : "Error deleting the URL portal";
                                break;

                            case "new":
                                // Get the values from the form for this new portal
                                entered_portal_name = form["admin_portal_name"];
                                entered_sys_abbrev  = form["admin_portal_abbr"];
                                entered_web_skin    = form["admin_portal_skin"].ToLower();
                                entered_aggregation = form["admin_portal_aggregation"].ToLower();
                                entered_url_segment = form["admin_portal_url"];
                                entered_base_purl   = form["admin_portal_purl"];



                                if (entered_portal_name.Length == 0)
                                {
                                    actionMessage = "ERROR: Portal name is a REQUIRED field.";
                                }
                                else if (entered_sys_abbrev.Length == 0)
                                {
                                    actionMessage = "ERROR: System abbreviation is a REQUIRED field.";
                                }
                                else if (entered_web_skin.Length == 0)
                                {
                                    actionMessage = "ERROR: Default web skin is a REQUIRED field.";
                                }
                                else if (entered_url_segment.Length == 0)
                                {
                                    actionMessage = "ERROR: URL segment is a REQUIRED field.";
                                }
                                else
                                {
                                    // Look for matching portal or URL segment names
                                    bool portal_name_match = false;
                                    bool url_segment_match = false;
                                    foreach (Portal thisPortal in UI_ApplicationCache_Gateway.URL_Portals.All_Portals)
                                    {
                                        if (String.Compare(thisPortal.Name, entered_portal_name, true) == 0)
                                        {
                                            portal_name_match = true;
                                            break;
                                        }

                                        if (String.Compare(thisPortal.URL_Segment, entered_url_segment, true) == 0)
                                        {
                                            url_segment_match = true;
                                            break;
                                        }
                                    }

                                    if (portal_name_match)
                                    {
                                        actionMessage = "ERROR: Portal name must be unique, and that name is already in use";
                                    }
                                    else if (url_segment_match)
                                    {
                                        actionMessage = "ERROR: URL segment must be unique, and that URL segment already exists";
                                    }
                                    else
                                    {
                                        bool result = entered_sys_abbrev.All(C => Char.IsLetterOrDigit(C) || C == '_');
                                        if (!result)
                                        {
                                            actionMessage      = "ERROR: System abbreviation must include only letters and numbers";
                                            entered_sys_abbrev = entered_sys_abbrev.Replace("\"", "");
                                        }
                                        else
                                        {
                                            // Save this to the database
                                            int new_id = SobekCM_Database.Edit_URL_Portal(-1, entered_url_segment, true, false, entered_sys_abbrev, entered_portal_name, entered_aggregation, entered_web_skin, entered_base_purl, RequestSpecificValues.Tracer);
                                            if (new_id > 0)
                                            {
                                                actionMessage = "Saved new URL portal '" + entered_portal_name + "'";

                                                entered_portal_name = String.Empty;
                                                entered_sys_abbrev  = String.Empty;
                                                entered_web_skin    = String.Empty;
                                                entered_aggregation = String.Empty;
                                                entered_url_segment = String.Empty;
                                                entered_base_purl   = String.Empty;
                                            }
                                            else
                                            {
                                                actionMessage = "Error saving URL portal.";
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    catch
                    {
                        actionMessage = "Exception caught while handling request";
                    }

                    // Reload all the URL UI_ApplicationCache_Gateway.URL_Portals
                    Engine_Database.Populate_URL_Portals(UI_ApplicationCache_Gateway.URL_Portals, RequestSpecificValues.Tracer);
                }
            }
        }