Наследование: iSerializationEvents
 /// <summary> Constructor for a new instance of the Citation_ItemViewer class </summary>
 /// <param name="Translator"> Language support object which handles simple translational duties </param>
 /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
 /// <param name="User_Can_Edit_Item"> Flag indicates if the current user can edit the citation information </param>
 public Citation_ItemViewer(Language_Support_Info Translator, Aggregation_Code_Manager Code_Manager, bool User_Can_Edit_Item )
 {
     translator = Translator;
     this.Code_Manager = Code_Manager;
     userCanEditItem = User_Can_Edit_Item;
     citationType = Citation_Type.Standard;
 }
        /// <summary> Parse the query and set the internal variables </summary>
        /// <param name="QueryString"> QueryString collection passed from the main page </param>
        /// <param name="Navigator"> Navigation object to hold the mode information </param>
        /// <param name="Base_URL">Requested base URL (without query string, etc..)</param>
        /// <param name="User_Languages"> Languages preferred by user, per their browser settings </param>
        /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections </param>
        /// <param name="Aggregation_Aliases"> List of all existing aliases for existing aggregationPermissions</param>
        /// <param name="All_Items_Lookup"> [REF] Lookup object used to pull basic information about any item loaded into this library</param>
        /// <param name="URL_Portals"> List of all web portals into this system </param>
        /// <param name="WebHierarchy"> Hierarchy of all non-aggregational web content pages and redirects </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        public static void Parse_Query(NameValueCollection QueryString,
			Navigation_Object Navigator,
			string Base_URL,
			string[] User_Languages,
			Aggregation_Code_Manager Code_Manager,
			Dictionary<string, string> Aggregation_Aliases,
			Item_Lookup_Object All_Items_Lookup,
			Portal_List URL_Portals,
            WebContent_Hierarchy WebHierarchy,
			Custom_Tracer Tracer )
        {
            if (Tracer != null)
                Tracer.Add_Trace("QueryString_Analyzer.Parse_Query", "Parse the query into the provided Navigation_Object");

            // Set default mode to error
            Navigator.Mode = Display_Mode_Enum.Error;

            // If this has 'verb' then this is an OAI-PMH request
            if ( QueryString["verb"] != null )
            {
                Navigator.Writer_Type = Writer_Type_Enum.OAI;
                return;
            }

            // Is there a TOC state set?
            if (QueryString["toc"] != null)
            {
                if (QueryString["toc"] == "y")
                {
                    Navigator.TOC_Display = TOC_Display_Type_Enum.Show;
                }
                else if ( QueryString["toc"] == "n" )
                {
                    Navigator.TOC_Display = TOC_Display_Type_Enum.Hide;
                }
            }

            // Determine the default language, per the browser settings
            if (User_Languages != null)
            {
                foreach (string thisLanguage in User_Languages)
                {
                    if (thisLanguage.IndexOf("en") == 0)
                    {
                        Navigator.Default_Language = Web_Language_Enum.English;
                        break;
                    }

                    if (thisLanguage.IndexOf("fr") == 0)
                    {
                        Navigator.Default_Language = Web_Language_Enum.French;
                        break;
                    }

                    if (thisLanguage.IndexOf("es") == 0)
                    {
                        Navigator.Default_Language = Web_Language_Enum.Spanish;
                        break;
                    }
                }
            }

            // Is there a language defined?  If so, load right into the navigator
            Navigator.Language = Navigator.Default_Language;
            if ( !String.IsNullOrEmpty(QueryString["l"]))
            {
                Navigator.Language = Web_Language_Enum_Converter.Code_To_Enum(QueryString["l"]);
            }

            // If there is flag indicating to show the trace route, save it
            if (QueryString["trace"] != null)
            {
                Navigator.Trace_Flag = QueryString["trace"].ToUpper() == "NO" ? Trace_Flag_Type_Enum.No : Trace_Flag_Type_Enum.Explicit;
            }
            else
            {
                Navigator.Trace_Flag = Trace_Flag_Type_Enum.Unspecified;
            }

            // Did the user request to have it render like it would for a search robot?
            if (QueryString["robot"] != null)
            {
                Navigator.Is_Robot = true;
            }

            // Was a fragment specified in the query string?
            if (QueryString["fragment"] != null)
            {
                Navigator.Fragment = QueryString["fragment"];
            }

            // Get the valid URL Portal
            Navigator.Default_Aggregation = "all";
            Portal urlPortal = URL_Portals.Get_Valid_Portal(Base_URL);
            Navigator.Instance_Abbreviation = urlPortal.Abbreviation;
            Navigator.Instance_Name = urlPortal.Name;
            if ( !String.IsNullOrEmpty(urlPortal.Base_PURL ))
                Navigator.Portal_PURL = urlPortal.Base_PURL;
            if (String.IsNullOrEmpty(urlPortal.Default_Aggregation))
            {
                Navigator.Aggregation = "";
            }
            else
            {
                Navigator.Default_Aggregation = urlPortal.Default_Aggregation;
                Navigator.Aggregation = urlPortal.Default_Aggregation;
            }
            if (!String.IsNullOrEmpty(urlPortal.Default_Web_Skin))
            {
                Navigator.Default_Skin = urlPortal.Default_Web_Skin;
                Navigator.Skin = urlPortal.Default_Web_Skin;
                Navigator.Skin_In_URL = false;
            }

            // Collect the interface string
            if (QueryString["n"] != null)
            {
                string currSkin = QueryString["n"].ToLower().Replace("'", "");

                // Save the interface
                if (currSkin.Length > 0)
                {
                    if (currSkin.IndexOf(",") > 0)
                        currSkin = currSkin.Substring(0, currSkin.IndexOf(","));
                    Navigator.Skin = currSkin.ToLower();
                    Navigator.Skin_In_URL = true;
                }
            }

            // Parse URL request different now, depending on if this is a legacy URL type or the new URL type
            Navigator.Mode = Display_Mode_Enum.None;

            // CHECK FOR LEGACY VALUES
            // Check for legacy bibid / vid information, since this will be supported indefinitely
            if (( QueryString["b"] != null ) || ( QueryString["bib"] != null ))
            {
                Navigator.BibID = QueryString["b"] ?? QueryString["bib"];

                if ( Navigator.BibID.Length > 0 )
                {
                    Navigator.Mode = Display_Mode_Enum.Item_Display;

                    if ( QueryString["v"] != null )
                        Navigator.VID = QueryString["v"];
                    else if ( QueryString["vid"] != null )
                        Navigator.VID = QueryString["vid"];
                }

                // No other item information is collected here anymore.. just return
                return;
            }

            // Set the default mode
            Navigator.Mode = Display_Mode_Enum.Aggregation;
            Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
            Navigator.Home_Type = Home_Type_Enum.List;

            // Get any url rewrite which occurred
            if (QueryString["urlrelative"] != null)
            {
                string urlrewrite = QueryString["urlrelative"].ToLower();
                if (urlrewrite.Length > 0)
                {
                    // Split the url relative list
                    string[] url_relative_info = urlrewrite.Split("/".ToCharArray());
                    List<string> url_relative_list = (from thisPart in url_relative_info where thisPart.Length > 0 select thisPart.ToLower()).ToList();

                    // Determine the main writer (html, json, xml, oai-pmh, etc..)
                    Navigator.Writer_Type = Writer_Type_Enum.HTML;
                    if ( url_relative_list.Count > 0 )
                    {
                        switch (url_relative_list[0])
                        {
                            case "l":
                                Navigator.Writer_Type = Writer_Type_Enum.HTML_LoggedIn;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "my":
                                Navigator.Writer_Type = Writer_Type_Enum.HTML_LoggedIn;
                                break;

                            case "json":
                                Navigator.Writer_Type = Writer_Type_Enum.JSON;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "dataset":
                                Navigator.Writer_Type = Writer_Type_Enum.DataSet;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "dataprovider":
                                Navigator.Writer_Type = Writer_Type_Enum.Data_Provider;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "xml":
                                Navigator.Writer_Type = Writer_Type_Enum.XML;
                                url_relative_list.RemoveAt(0);
                                break;

                            case "textonly":
                                Navigator.Writer_Type = Writer_Type_Enum.Text;
                                url_relative_list.RemoveAt(0);
                                break;
                        }
                    }

                    // Is the first part of the list one of these constants?
                    if (( url_relative_list.Count > 0 ) && ( url_relative_list[0].Length > 0 ))
                    {
                        switch ( url_relative_list[0] )
                        {
                            case "shibboleth":
                                Navigator.Mode = Display_Mode_Enum.My_Sobek;
                                Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Shibboleth_Landing;
                                break;

                            case "internal":
                                Navigator.Mode = Display_Mode_Enum.Internal;
                                Navigator.Internal_Type = Internal_Type_Enum.Aggregations_List;
                                if ( url_relative_list.Count > 1 )
                                {
                                    switch( url_relative_list[1] )
                                    {
                                        case "aggregations":
                                            Navigator.Internal_Type = Internal_Type_Enum.Aggregations_List;
                                            if (url_relative_list.Count > 2)
                                            {
                                                if (url_relative_list[2] == "tree")
                                                {
                                                    Navigator.Internal_Type = Internal_Type_Enum.Aggregations_Tree;
                                                }
                                            }
                                            break;

                                        case "cache":
                                            Navigator.Internal_Type = Internal_Type_Enum.Cache;
                                            break;

                                        case "new":
                                            Navigator.Internal_Type = Internal_Type_Enum.New_Items;
                                            if (url_relative_list.Count > 2)
                                            {
                                                Navigator.Info_Browse_Mode = url_relative_list[2];
                                            }
                                            break;

                                        case "failures":
                                            Navigator.Internal_Type = Internal_Type_Enum.Build_Failures;
                                            if (url_relative_list.Count > 2)
                                                Navigator.Info_Browse_Mode = url_relative_list[2];
                                            break;

                                        case "wordmarks":
                                            Navigator.Internal_Type = Internal_Type_Enum.Wordmarks;
                                            break;
                                    }
                                }
                                break;

                            case "contact":
                                Navigator.Mode = Display_Mode_Enum.Contact;
                                if ( url_relative_list.Count > 1 )
                                {
                                    if (url_relative_list[1] == "sent")
                                    {
                                        Navigator.Mode = Display_Mode_Enum.Contact_Sent;
                                    }
                                    else
                                    {
                                        Navigator.Aggregation = url_relative_list[1];
                                    }
                                }
                                if (QueryString["em"] != null)
                                    Navigator.Error_Message = QueryString["em"];
                                break;

                            case "folder":
                                Navigator.Mode = Display_Mode_Enum.Public_Folder;
                                if (url_relative_list.Count >= 2)
                                {
                                    try
                                    {
                                        Navigator.FolderID = Convert.ToInt32(url_relative_list[1]);
                                    }
                                    catch
                                    {
                                        Navigator.FolderID = -1;
                                    }

                                    // Look for result display type
                                    if (url_relative_list.Count >=3 )
                                    {
                                        switch (url_relative_list[2])
                                        {
                                            case "brief":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                                break;
                                            case "export":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Export;
                                                break;
                                            case "citation":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Citation;
                                                break;
                                            case "image":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Image;
                                                break;
                                            case "map":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Map;
                                                break;
                                            case "mapbeta":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Map_Beta;
                                                break;
                                            case "table":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Table;
                                                break;
                                            case "thumbs":
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Thumbnails;
                                                break;
                                            default:
                                                Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                                break;
                                        }
                                    }

                                    // Look for a page number
                                    if (url_relative_list.Count >= 4 )
                                    {
                                        string possible_page = url_relative_list[3];
                                        if ((possible_page.Length > 0) && (is_String_Number(possible_page)))
                                        {
                                            ushort page_result;
                                            UInt16.TryParse(possible_page, out page_result);
                                            Navigator.Page = page_result;
                                        }
                                    }
                                }
                                break;

                            case "register":
                                Navigator.Mode = Display_Mode_Enum.My_Sobek;
                                Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Preferences;
                                break;

                            case "my":
                                Navigator.Mode = Display_Mode_Enum.My_Sobek;
                                Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                                if (QueryString["return"] != null)
                                    Navigator.Return_URL = QueryString["return"];
                                if ( url_relative_list.Count > 1 )
                                {
                                    switch( url_relative_list[1] )
                                    {
                                        case "logon":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Logon;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "home":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "delete":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Delete_Item;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            break;

                                        case "submit":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.New_Item;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "itempermissions":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Permissions;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "behaviors":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Behaviors;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "edit":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Item_Metadata;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "files":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.File_Management;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "images":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Page_Images_Management;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.VID = url_relative_list[3];
                                            if (url_relative_list.Count > 4)
                                                Navigator.My_Sobek_SubMode = url_relative_list[4];
                                            break;

                                        case "addvolume":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Group_Add_Volume;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "autofill":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Group_AutoFill_Volumes;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "massupdate":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Group_Mass_Update_Items;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "groupbehaviors":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Group_Behaviors;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "serialhierarchy":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Edit_Group_Serial_Hierarchy;
                                            if (url_relative_list.Count > 2)
                                                Navigator.BibID = url_relative_list[2].ToUpper();
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "bookshelf":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Folder_Management;
                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Bookshelf;
                                            if (url_relative_list.Count > 2)
                                            {
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                                if (url_relative_list.Count > 3)
                                                {
                                                    switch (Navigator.My_Sobek_SubMode)
                                                    {
                                                        case "brief":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Brief;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "export":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Export;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "thumbs":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Thumbnails;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "table":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Table;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "citation":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Citation;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        case "image":
                                                            Navigator.Result_Display_Type = Result_Display_Type_Enum.Full_Image;
                                                            Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                            break;

                                                        default:
                                                            if (is_String_Number(url_relative_list[3]))
                                                            {
                                                                ushort page_result;
                                                                UInt16.TryParse(url_relative_list[3], out page_result);
                                                                Navigator.Page = page_result;
                                                            }
                                                            break;
                                                    }
                                                }
                                                if ((url_relative_list.Count > 4) && ( is_String_Number( url_relative_list[4] )))
                                                {
                                                    ushort page_result;
                                                    UInt16.TryParse(url_relative_list[4], out page_result);
                                                    Navigator.Page = page_result;
                                                }
                                            }
                                            break;

                                        case "preferences":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Preferences;
                                            break;

                                        case "logout":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Log_Out;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "shibboleth":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Shibboleth_Landing;
                                            if (QueryString["return"] != null)
                                                Navigator.Return_URL = QueryString["return"];
                                            break;

                                        case "itemtracking":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Item_Tracking;
                                            //if(url_relative_list.Count>3 && is_String_Number(url_relative_list[3]))
                                            //    Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "searches":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.Saved_Searches;
                                            break;

                                        case "tags":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.User_Tags;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "stats":
                                            Navigator.My_Sobek_Type = My_Sobek_Type_Enum.User_Usage_Stats;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;
                                    }
                                }
                                break;

                            case "admin":
                                Navigator.Mode = Display_Mode_Enum.Administrative;
                                Navigator.Admin_Type = Admin_Type_Enum.Home;
                                if (QueryString["return"] != null)
                                    Navigator.Return_URL = QueryString["return"];
                                if (url_relative_list.Count > 1)
                                {
                                    switch (url_relative_list[1])
                                    {
                                        case "builder":
                                            Navigator.Admin_Type = Admin_Type_Enum.Builder_Status;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;
                                            break;

                                        case "addcoll":
                                            Navigator.Admin_Type = Admin_Type_Enum.Add_Collection_Wizard;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "aggregations":
                                            Navigator.Admin_Type = Admin_Type_Enum.Aggregations_Mgmt;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "editaggr":
                                            Navigator.Admin_Type = Admin_Type_Enum.Aggregation_Single;
                                            if (url_relative_list.Count > 2)
                                                Navigator.Aggregation = url_relative_list[2];
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[3];
                                            break;

                                        case "aliases":
                                            Navigator.Admin_Type = Admin_Type_Enum.Aliases;
                                            break;

                                        case "webskins":
                                            Navigator.Admin_Type = Admin_Type_Enum.Skins_Mgmt;
                                            break;

                                        case "editskin":
                                            Navigator.Admin_Type = Admin_Type_Enum.Skins_Single;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            if (url_relative_list.Count > 3)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2] + "/" + url_relative_list[3];
                                            break;

                                        case "defaults":
                                            Navigator.Admin_Type = Admin_Type_Enum.Default_Metadata;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "restrictions":
                                            Navigator.Admin_Type = Admin_Type_Enum.IP_Restrictions;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "portals":
                                            Navigator.Admin_Type = Admin_Type_Enum.URL_Portals;
                                            break;

                                        case "users":
                                            Navigator.Admin_Type = Admin_Type_Enum.Users;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "groups":
                                            Navigator.Admin_Type = Admin_Type_Enum.User_Groups;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "permissions":
                                            Navigator.Admin_Type = Admin_Type_Enum.User_Permissions_Reports;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "webadd":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Add_New;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "webcontent":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Mgmt;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "webhistory":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_History;
                                            break;

                                        case "websingle":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Single;
                                            if (url_relative_list.Count > 2)
                                            {
                                                int possiblewebid;
                                                if (Int32.TryParse(url_relative_list[2], out possiblewebid))
                                                {
                                                    Navigator.WebContentID = possiblewebid;
                                                }
                                                if (url_relative_list.Count > 3)
                                                {
                                                    Navigator.My_Sobek_SubMode = url_relative_list[3];
                                                }
                                            }
                                            if ( Navigator.WebContentID < 1 )
                                                Navigator.Admin_Type = Admin_Type_Enum.WebContent_Mgmt;
                                            break;

                                        case "webusage":
                                            Navigator.Admin_Type = Admin_Type_Enum.WebContent_Usage;
                                            break;

                                        case "wordmarks":
                                            Navigator.Admin_Type = Admin_Type_Enum.Wordmarks;
                                            break;

                                        case "reset":
                                            Navigator.Admin_Type = Admin_Type_Enum.Reset;
                                            break;

                                        case "headings":
                                            Navigator.Admin_Type = Admin_Type_Enum.Thematic_Headings;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;

                                        case "settings":
                                            Navigator.Admin_Type = Admin_Type_Enum.Settings;
                                            if (url_relative_list.Count > 2)
                                                Navigator.My_Sobek_SubMode = url_relative_list[2];
                                            break;
                                    }
                                }
                                break;

                            case "preferences":
                                Navigator.Mode = Display_Mode_Enum.Preferences;
                                break;

                            case "reports":
                                Navigator.Mode = Display_Mode_Enum.Reports;
                                if (url_relative_list.Count > 1)
                                {
                                    Navigator.Report_Name = url_relative_list[1];
                                }
                                break;

                            case "stats":
                            case "statistics":
                                Navigator.Mode = Display_Mode_Enum.Statistics;
                                Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Standard_View;
                                if ( url_relative_list.Count > 1 )
                                {
                                    switch( url_relative_list[1] )
                                    {
                                        case "itemcount":
                                            Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Standard_View;
                                            if ( url_relative_list.Count > 2 )
                                            {
                                                switch( url_relative_list[2])
                                                {
                                                    case "arbitrary":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Arbitrary_View;
                                                        if (url_relative_list.Count > 3)
                                                        {
                                                            Navigator.Info_Browse_Mode = url_relative_list[3];
                                                        }
                                                        break;

                                                    case "growth":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Growth_View;
                                                        break;

                                                    case "text":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Text;
                                                        break;

                                                    case "standard":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Item_Count_Standard_View;
                                                        break;
                                                }
                                            }
                                            break;

                                        case "searches":
                                            Navigator.Statistics_Type = Statistics_Type_Enum.Recent_Searches;
                                            break;

                                        case "usage":
                                            Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Overall;
                                            if ( url_relative_list.Count > 2 )
                                            {
                                                switch( url_relative_list[2])
                                                {
                                                    case "all":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Overall;
                                                        break;

                                                    case "history":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Collection_History;
                                                        if ( url_relative_list.Count > 3 )
                                                        {
                                                            switch( url_relative_list[3] )
                                                            {
                                                                case "text":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Collection_History_Text;
                                                                    break;

                                                                default:
                                                                    Navigator.Info_Browse_Mode = url_relative_list[3];
                                                                    break;
                                                            }

                                                            if ((String.IsNullOrEmpty(Navigator.Info_Browse_Mode)) && (url_relative_list.Count > 4))
                                                                Navigator.Info_Browse_Mode = url_relative_list[4];
                                                        }
                                                        break;

                                                    case "collections":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Collections_By_Date;
                                                        if (url_relative_list.Count > 3)
                                                            Navigator.Info_Browse_Mode = url_relative_list[3];
                                                        break;

                                                    case "definitions":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Definitions;
                                                        break;

                                                    case "titles":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Titles_By_Collection;
                                                        if (( String.IsNullOrEmpty( Navigator.Info_Browse_Mode )) && ( url_relative_list.Count > 4 ))
                                                            Navigator.Info_Browse_Mode = url_relative_list[4];
                                                        break;

                                                    case "items":
                                                        Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Item_Views_By_Date;
                                                        if ( url_relative_list.Count > 3 )
                                                        {
                                                            switch( url_relative_list[3] )
                                                            {
                                                                case "date":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Item_Views_By_Date;
                                                                    break;

                                                                case "top":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_Items_By_Collection;
                                                                    break;

                                                                case "text":
                                                                    Navigator.Statistics_Type = Statistics_Type_Enum.Usage_By_Date_Text;
                                                                    break;

                                                                default:
                                                                    Navigator.Info_Browse_Mode = url_relative_list[3];
                                                                    break;
                                                            }

                                                            if (( String.IsNullOrEmpty( Navigator.Info_Browse_Mode )) && ( url_relative_list.Count > 4 ))
                                                                Navigator.Info_Browse_Mode = url_relative_list[4];
                                                        }
                                                        break;

                                                }
                                            }
                                            break;
                                    }
                                }
                                break;

                            case "partners":
                                if (( String.IsNullOrEmpty(Navigator.Default_Aggregation)) || ( Navigator.Default_Aggregation == "all"))
                                {
                                    Navigator.Mode = Display_Mode_Enum.Aggregation;
                                    Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                    Navigator.Aggregation = String.Empty;
                                    Navigator.Home_Type = Home_Type_Enum.Partners_List;
                                    if ((url_relative_list.Count > 1) && (url_relative_list[1] == "thumbs"))
                                    {
                                        Navigator.Home_Type = Home_Type_Enum.Partners_Thumbnails;
                                    }
                                }
                                else
                                {
                                    aggregation_querystring_analyze(Navigator, QueryString, Navigator.Default_Aggregation, url_relative_list);
                                }
                                break;

                            case "tree":
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation = String.Empty;
                                Navigator.Home_Type = Home_Type_Enum.Tree;
                                break;

                            case "brief":
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation = String.Empty;
                                Navigator.Home_Type = Home_Type_Enum.Descriptions;
                                break;

                            case "personalized":
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation = String.Empty;
                                Navigator.Home_Type = Home_Type_Enum.Personalized;
                                break;

                            case "inprocess":
                                Navigator.Aggregation = String.Empty;
                                Navigator.Mode = Display_Mode_Enum.Aggregation;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Home;
                                Navigator.Aggregation_Type = Aggregation_Type_Enum.Private_Items;
                                Navigator.Page = 1;
                                if (url_relative_list.Count > 1)
                                {
                                    if (is_String_Number(url_relative_list[1]))
                                        Navigator.Page = Convert.ToUInt16(url_relative_list[1]);
                                }
                                if ((QueryString["o"] != null) && (is_String_Number(QueryString["o"])))
                                {
                                    Navigator.Sort = Convert.ToInt16(QueryString["o"]);
                                }
                                else
                                {
                                    Navigator.Sort = 0;
                                }
                                break;

                            case "all":
                            case "new":
                            case "edit":
                            case "map":
                            case "mapbeta":
                            case "advanced":
                            case "text":
                            case "results":
                            case "contains":
                            case "exact":
                            case "resultslike":
                            case "browseby":
                            case "info":
                            case "aggrmanage":
                            case "aggrhistory":
                            case "aggrpermissions":
                            case "geography":
                                aggregation_querystring_analyze(Navigator, QueryString, Navigator.Default_Aggregation, url_relative_list);
                                break;

                            // This was none of the main constant mode settings,
                            default:
                                // Always check the top-level static web content pages and redirects hierarchy first
                                if ((WebHierarchy != null) && (WebHierarchy.Root_Count > 0))
                                {
                                    WebContent_Hierarchy_Node matchedNode = WebHierarchy.Find(url_relative_list);
                                    if (matchedNode != null)
                                    {
                                        // Maybe this is a web content / info page
                                        Navigator.Mode = Display_Mode_Enum.Simple_HTML_CMS;

                                        // Get the URL reassembled
                                        string possible_info_mode = String.Empty;
                                        if (url_relative_list.Count == 1)
                                            possible_info_mode = url_relative_list[0];
                                        else if (url_relative_list.Count == 2)
                                            possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1];
                                        else if (url_relative_list.Count == 3)
                                            possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2];
                                        else if (url_relative_list.Count == 4)
                                            possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2] + "/" + url_relative_list[3];
                                        else if (url_relative_list.Count > 4)
                                        {
                                            StringBuilder possibleInfoModeBuilder = new StringBuilder();
                                            if (url_relative_list.Count > 0)
                                            {
                                                possibleInfoModeBuilder.Append(url_relative_list[0]);
                                            }
                                            for (int i = 1; i < url_relative_list.Count; i++)
                                            {
                                                possibleInfoModeBuilder.Append("/" + url_relative_list[i]);
                                            }
                                            possible_info_mode = possibleInfoModeBuilder.ToString().Replace("'", "").Replace("\"", "");
                                        }

                                        // Set the source location
                                        Navigator.Info_Browse_Mode = possible_info_mode;
                                        Navigator.Page_By_FileName = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design\\webcontent\\" + possible_info_mode.Replace("/","\\") + "\\default.html";
                                        Navigator.WebContentID = matchedNode.WebContentID;
                                        Navigator.Redirect = matchedNode.Redirect;

                                        //// If it is missing, mark that
                                        //if ((!File.Exists(Navigator.Page_By_FileName)) && ( String.IsNullOrEmpty(Navigator.Redirect)))
                                        //{
                                        //    Navigator.Missing = true;
                                        //    Navigator.Info_Browse_Mode = possible_info_mode;
                                        //    Navigator.Page_By_FileName = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design\\webcontent\\missing.html";
                                        //}

                                        // If something was found, then check for submodes
                                        Navigator.WebContent_Type = WebContent_Type_Enum.Display;
                                        if (!String.IsNullOrEmpty(QueryString["mode"]))
                                        {
                                            switch (QueryString["mode"].ToLower())
                                            {
                                                case "edit":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Edit;
                                                    break;

                                                case "menu":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Manage_Menu;
                                                    break;

                                                case "milestones":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Milestones;
                                                    break;

                                                case "permissions":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Permissions;
                                                    break;

                                                case "usage":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Usage;
                                                    break;

                                                case "verify":
                                                    Navigator.WebContent_Type = WebContent_Type_Enum.Delete_Verify;
                                                    break;
                                            }
                                        }

                                        return;
                                    }
                                }

                                // Check to see if the first term was an item aggregation alias, which
                                // allows for the alias to overwrite an existing aggregation code (limited usability
                                // but can be used to hide an existing aggregation easily)
                                if (Aggregation_Aliases.ContainsKey(url_relative_list[0]))
                                {
                                    // Perform all aggregation_style checks next
                                    string aggregation_code = Aggregation_Aliases[url_relative_list[0]];
                                    Navigator.Aggregation_Alias = url_relative_list[0];
                                    aggregation_querystring_analyze( Navigator, QueryString, aggregation_code, url_relative_list.GetRange(1, url_relative_list.Count - 1));
                                }
                                else if ( Code_Manager.isValidCode( url_relative_list[0] ))
                                {
                                    // This is an item aggregation call
                                    // Perform all aggregation_style checks next
                                    aggregation_querystring_analyze( Navigator, QueryString, url_relative_list[0], url_relative_list.GetRange(1, url_relative_list.Count - 1 ));
                                }
                                else if ((Engine_Database.Verify_Item_Lookup_Object(false, true, All_Items_Lookup, Tracer)) && (All_Items_Lookup.Contains_BibID(url_relative_list[0].ToUpper())))
                                {
                                    // This is a BibID for an existing title with at least one public item
                                    Navigator.BibID = url_relative_list[0].ToUpper();
                                    Navigator.Mode = Display_Mode_Enum.Item_Display;

                                    // Is the next part a VID?
                                    int current_list_index = 1;
                                    if (url_relative_list.Count > 1)
                                    {
                                        string possible_vid = url_relative_list[1].Trim().PadLeft(5, '0');
                                        if ((All_Items_Lookup.Contains_BibID_VID(Navigator.BibID, possible_vid)) || ( possible_vid == "00000" ))
                                        {
                                            Navigator.VID = possible_vid;
                                            current_list_index++;
                                        }
                                    }

                                    // Look for the item print mode now
                                    if ((url_relative_list.Count > current_list_index) && (url_relative_list[current_list_index] == "print"))
                                    {
                                        // This is an item print request
                                        Navigator.Mode = Display_Mode_Enum.Item_Print;

                                        // Since we need special characters for ranges, etc.. the viewer code
                                        // is in the options query string variable in this case
                                        if (QueryString["options"] != null)
                                        {
                                            Navigator.ViewerCode = QueryString["options"];
                                        }
                                    }
                                    else
                                    {
                                        // Look for the viewercode next
                                        if (url_relative_list.Count > current_list_index)
                                        {
                                            string possible_viewercode = url_relative_list[current_list_index].Trim();

                                            // Get the view code
                                            if (possible_viewercode.Length > 0)
                                            {
                                                // Get the viewer code
                                                Navigator.ViewerCode = possible_viewercode;

                                                // Now, get the page
                                                if ((Navigator.ViewerCode.Length > 0) && (Char.IsNumber(Navigator.ViewerCode[0])))
                                                {
                                                    // Look for the first number
                                                    int numberEnd = Navigator.ViewerCode.Length;
                                                    int count = 0;
                                                    foreach (char thisChar in Navigator.ViewerCode)
                                                    {
                                                        if (!Char.IsNumber(thisChar))
                                                        {
                                                            numberEnd = count;
                                                            break;
                                                        }
                                                        count++;
                                                    }

                                                    // Get the page
                                                    ushort testPage;
                                                    if (UInt16.TryParse(Navigator.ViewerCode.Substring(0, numberEnd), out testPage))
                                                        Navigator.Page = testPage;
                                                }
                                            }
                                            else
                                            {
                                                // Sequence is set to 1
                                                Navigator.Page = 1;
                                            }

                                            // Used or discarded the possible viewer code (used unless length of zero )
                                            current_list_index++;

                                            // Look for a subpage now, if there since there was a (possible) viewer code
                                            if (url_relative_list.Count > current_list_index)
                                            {
                                                string possible_subpage = url_relative_list[current_list_index].Trim();
                                                if (is_String_Number(possible_subpage))
                                                {
                                                    ushort testSubPage;
                                                    if (UInt16.TryParse(possible_subpage, out testSubPage))
                                                        Navigator.SubPage = testSubPage;
                                                }
                                            }
                                        }
                                    }

                                    // Collect number of thumbnails per page
                                    if (QueryString["nt"] != null)
                                    {
                                        short nt_temp;
                                        if (short.TryParse(QueryString["nt"], out nt_temp))
                                            Navigator.Thumbnails_Per_Page = nt_temp;
                                    }

                                    // Collect size of thumbnails per page
                                    if (QueryString["ts"] != null)
                                    {
                                        short ts_temp;
                                        if (short.TryParse(QueryString["ts"], out ts_temp))
                                            Navigator.Size_Of_Thumbnails = ts_temp;
                                    }

                                    // Collect the text search string
                                    if (QueryString["search"] != null)
                                        Navigator.Text_Search = QueryString["search"].Replace("+"," ");

                                    // If coordinates were here, save them
                                    if (QueryString["coord"] != null)
                                        Navigator.Coordinates = QueryString["coord"];

                                    // If a page is requested by filename (rather than sequenc), collect that
                                    if (QueryString["file"] != null)
                                        Navigator.Page_By_FileName = QueryString["file"];
                                }
                                else if ((String.IsNullOrEmpty(Navigator.Page_By_FileName)) && ((String.IsNullOrEmpty(Navigator.Default_Aggregation)) || (Navigator.Default_Aggregation == "all")))
                                {
                                    // This may be a top-level aggregation call
                                    // aggregation_querystring_analyze(Navigator, QueryString, Navigator.Default_Aggregation, url_relative_list);

                                    // Pass this unmatched query to the simple html cms to show the missing (custom) screen
                                    Navigator.Mode = Display_Mode_Enum.Simple_HTML_CMS;

                                    string possible_info_mode = String.Empty;
                                    if (url_relative_list.Count == 1)
                                        possible_info_mode = url_relative_list[0];
                                    else if (url_relative_list.Count == 2)
                                        possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1];
                                    else if (url_relative_list.Count == 3)
                                        possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2];
                                    else if (url_relative_list.Count == 4)
                                        possible_info_mode = url_relative_list[0] + "/" + url_relative_list[1] + "/" + url_relative_list[2] + "/" + url_relative_list[3];
                                    else if ( url_relative_list.Count > 4)
                                    {
                                        StringBuilder possibleInfoModeBuilder = new StringBuilder();
                                        if (url_relative_list.Count > 0)
                                        {
                                            possibleInfoModeBuilder.Append(url_relative_list[0]);
                                        }
                                        for (int i = 1; i < url_relative_list.Count; i++)
                                        {
                                            possibleInfoModeBuilder.Append("/" + url_relative_list[i]);
                                        }
                                        possible_info_mode = possibleInfoModeBuilder.ToString().Replace("'", "").Replace("\"", "");
                                    }

                                    string base_source = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design\\webcontent";

                                    // Set the source location
                                    Navigator.Missing = true;
                                    Navigator.Info_Browse_Mode = possible_info_mode;
                                    Navigator.WebContent_Type = WebContent_Type_Enum.Display;
                                    Navigator.Page_By_FileName = base_source + "\\missing.html";
                                    Navigator.WebContentID = -1;
                                }
                                break;
                        }
                    }
                }
            }
        }
 /// <summary> Sets the list of all valid codes for this element from the main aggregation table </summary>
 /// <param name="codeManager"> Code manager with list of all aggregationPermissions </param>
 internal void Add_Codes(Aggregation_Code_Manager codeManager)
 {
     //if (items.Count == 0)
     //{
     //    SortedList<string, string> tempItemList = new SortedList<string, string>();
     //    ReadOnlyCollection<Item_Aggregation_Related_Aggregations> subcollections = codeManager.All_Aggregations;
     //    foreach (Item_Aggregation_Related_Aggregations thisAggr in subcollections)
     //    {
     //        if (!tempItemList.ContainsKey(thisAggr.Code))
     //        {
     //            tempItemList.Add(thisAggr.Code, thisAggr.Code);
     //        }
     //    }
     //    IList<string> keys = tempItemList.Keys;
     //    foreach (string thisKey in keys)
     //    {
     //        items.Add(tempItemList[thisKey].ToUpper());
     //    }
     //}
 }
        /// <summary> Refresh the aggregation code list by pulling the data back from the database </summary>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool RefreshCodes()
        {
            try
            {
                lock (codesLock)
                {
                    if (codes == null)
                    {
                        codes = new Aggregation_Code_Manager();
                    }

                    Engine_Database.Populate_Code_Manager(codes, null);
                }

                return true;
            }
            catch ( Exception ee )
            {
                return ee.Message.Length > 0 ;
            }
        }
 /// <summary> Method adds aggregation codes to the pertinent element objects ( i.e., collections, subcollecctions, etc.. ) </summary>
 /// <param name="CodeManager"> Code manager object with aggregation codes </param>
 internal void Add_Codes(Aggregation_Code_Manager CodeManager)
 {
     // Go through each of the elements and prepare to save
     foreach (abstract_Element thisElement in templatePages.SelectMany(ThisPage => ThisPage.Panels.SelectMany(ThisPanel => ThisPanel.Elements)))
     {
         if (thisElement.Type == Element_Type.Aggregations)
             ((Aggregations_Element)thisElement).Add_Codes(CodeManager);
         if ( thisElement.Type == Element_Type.Source )
             ((Source_Element)thisElement).Add_Codes(CodeManager);
         if (thisElement.Type == Element_Type.Holding)
             ((Holding_Element)thisElement).Add_Codes(CodeManager);
     }
 }
 /// <summary> Constructor for a new instance of the Tracking_ItemViewer class </summary>
 /// <param name="Translator"> Language support object which handles simple translational duties </param>
 /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
 /// <param name="User_Can_Edit_Item"> Flag indicates if the current user can edit the citation information </param>
 public Tracking_ItemViewer(Language_Support_Info Translator, Aggregation_Code_Manager Code_Manager, bool User_Can_Edit_Item)
 {
     translator = Translator;
     this.Code_Manager = Code_Manager;
     userCanEditItem = User_Can_Edit_Item;
 }
        /// <summary> Sets the list of all valid codes for this element from the main aggregation table </summary>
        /// <param name="CodeManager"> Code manager with list of all aggregationPermissions </param>
        internal void Add_Codes(Aggregation_Code_Manager CodeManager)
        {
            codeToNameDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            if (possible_select_items.Count <= 2)
            {
                SortedList<string, string> tempItemList = new SortedList<string, string>();
                foreach (string thisType in CodeManager.All_Types)
                {
                    if (thisType.IndexOf("Institution") >= 0)
                    {
                        ReadOnlyCollection<Item_Aggregation_Related_Aggregations> matchingAggr = CodeManager.Aggregations_By_Type(thisType);
                        foreach (Item_Aggregation_Related_Aggregations thisAggr in matchingAggr)
                        {
                            if (thisAggr.Code.Length > 1)
                            {
                                if ((thisAggr.Code[0] == 'i') || (thisAggr.Code[0] == 'I'))
                                {
                                    if (!tempItemList.ContainsKey(thisAggr.Code.Substring(1)))
                                    {
                                        codeToNameDictionary[thisAggr.Code.Substring(1).ToUpper()] = thisAggr.Name;
                                        tempItemList.Add(thisAggr.Code.Substring(1), thisAggr.Code.Substring(1));
                                    }
                                }
                                else
                                {
                                    if (!tempItemList.ContainsKey(thisAggr.Code))
                                    {
                                        codeToNameDictionary[thisAggr.Code.ToUpper()] = thisAggr.Name;
                                        tempItemList.Add(thisAggr.Code, thisAggr.Code);
                                    }
                                }
                            }
                        }
                    }
                }

                IList<string> keys = tempItemList.Keys;
                foreach (string thisKey in keys)
                {
                    possible_select_items.Add(tempItemList[thisKey].ToUpper());
                    if (codeToNameDictionary.ContainsKey(thisKey))
                    {
                        Add_Code_Statement_Link(thisKey, codeToNameDictionary[thisKey]);
                    }
                }

            }
        }
        /// <summary> Gets the item aggregation and search fields for the current item aggregation </summary>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <param name="Aggregation_Object"> [OUT] Fully-built object for the current aggregation object </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        /// <remarks> This attempts to pull the objects from the cache.  If unsuccessful, it builds the objects from the
        /// database and hands off to the <see cref="CachedDataManager" /> to store in the cache. </remarks>
        public bool Get_Entire_Collection_Hierarchy(Navigation_Object Current_Mode, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer, out Item_Aggregation Aggregation_Object)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("SobekCM_Assistant.Get_Entire_Collection_Hierarchy", String.Empty);
            }

            string languageCode = Web_Language_Enum_Converter.Enum_To_Code(Current_Mode.Language);

            // If there is an aggregation listed, try to get that now
            if ((Current_Mode.Aggregation.Length > 0) && (Current_Mode.Aggregation != "all"))
            {
                // Try to pull the aggregation information
                Aggregation_Object = Get_Item_Aggregation(Current_Mode.Aggregation, languageCode, Current_Mode.Is_Robot, Tracer );

                // Return if this was valid
                if (Aggregation_Object != null)
                {
                    if ((Current_Mode.Skin_In_URL != true) && ( !String.IsNullOrEmpty(Aggregation_Object.Default_Skin )))
                    {
                        Current_Mode.Skin = Aggregation_Object.Default_Skin.ToLower();
                    }
                    return true;
                }

                Current_Mode.Error_Message = "Invalid item aggregation '" + Current_Mode.Aggregation + "' referenced.";
                return false;
            }
            // Get the collection group
            Aggregation_Object = Get_All_Collections(languageCode, Current_Mode.Is_Robot, Tracer );

            // If this is null, just stop
            if (Aggregation_Object == null)
            {
                Current_Mode.Error_Message = "Unable to pull the item aggregation corresponding to all collection groups";
                return false;
            }

            return true;
        }
        /// <summary> Populates the code manager object for translating SobekCM codes to greenstone collection codes </summary>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <param name="Codes"> Code object to populate with the all the code and aggregation information</param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        /// <remarks> This calls the 'SobekCM_Get_Item_Aggregation_AllCodes' stored procedure </remarks> 
        public static bool Populate_Code_Manager(Aggregation_Code_Manager Codes, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("Engine_Database.Populate_Code_Manager", String.Empty);
            }

            // Create the database agnostic reader
            EalDbReaderWrapper readerWrapper = EalDbAccess.ExecuteDataReader(DatabaseType, Connection_String, CommandType.StoredProcedure, "SobekCM_Get_Item_Aggregation_AllCodes");

            // Pull out the database reader
            DbDataReader reader = readerWrapper.Reader;

            // Clear the codes list and then move in the new data
            Codes.Clear();

            // get the column indexes out
            const int CODE_COL = 0;
            const int TYPE_COL = 1;
            const int NAME_COL = 2;
            const int SHORT_NAME_COL = 3;
            const int IS_ACTIVE_COL = 4;
            const int HIDDEN_COL = 5;
            const int ID_COL = 6;
            const int DESC_COL = 7;
            const int THEME_COL = 8;
            const int LINK_COL = 9;
            const int THEME_NAME_COL = 12;
            const int PARENT_SHORT_NAME = 13;
            const int PARENT_NAME = 14;
            const int PARENT_CODE = 15;

            Item_Aggregation_Related_Aggregations lastAggr = null;

            while (reader.Read())
            {
                // Get the list key values out
                string code = reader.GetString(CODE_COL).ToUpper();
                string type = reader.GetString(TYPE_COL);

                if ((lastAggr != null) && (lastAggr.Code == code))
                {
                    if (!reader.IsDBNull(PARENT_CODE))
                    {
                        string second_parent_code = reader.GetString(PARENT_CODE).ToUpper();
                        string second_parent_name = reader.GetString(PARENT_NAME).ToUpper();
                        string second_parent_short = reader.GetString(PARENT_SHORT_NAME);
                        lastAggr.Add_Parent_Aggregation(second_parent_code, second_parent_name, second_parent_short);
                    }
                }
                else
                {
                    // Only do anything else if this is not somehow a repeat
                    if (!Codes.isValidCode(code))
                    {
                        // Create the object
                        lastAggr =
                            new Item_Aggregation_Related_Aggregations(code, reader.GetString(NAME_COL),
                                reader.GetString(SHORT_NAME_COL), type,
                                reader.GetBoolean(IS_ACTIVE_COL),
                                reader.GetBoolean(HIDDEN_COL),
                                reader.GetString(DESC_COL),
                                (ushort) reader.GetInt32(ID_COL));

                        if (!reader.IsDBNull(LINK_COL))
                            lastAggr.External_Link = reader.GetString(LINK_COL);

                        if (!reader.IsDBNull(THEME_NAME_COL))
                        {
                            string theme_name = reader.GetString(THEME_NAME_COL);
                            int theme = reader.GetInt32(THEME_COL);
                            if (theme > 0)
                            {
                                lastAggr.Thematic_Heading = new Thematic_Heading(theme, theme_name);
                            }
                        }

                        if (!reader.IsDBNull(PARENT_CODE))
                        {
                            string parent_code = reader.GetString(PARENT_CODE).ToUpper();
                            string parent_name = reader.GetString(PARENT_NAME).ToUpper();
                            string parent_short = reader.GetString(PARENT_SHORT_NAME);
                            lastAggr.Add_Parent_Aggregation(parent_code, parent_name, parent_short);
                        }

                        // Add this to the codes manager
                        Codes.Add_Collection(lastAggr);
                    }
                }
            }

            // Close the reader (which also closes the connection)
            readerWrapper.Close();

            // Succesful
            return true;
        }
 /// <summary> Sets the list of all valid codes for this element from the main aggregation table </summary>
 /// <param name="codeManager"> Code manager with list of all aggregationPermissions </param>
 internal void Add_Codes(Aggregation_Code_Manager codeManager)
 {
     if (items.Count == 0)
     {
         SortedList<string, string> tempItemList = new SortedList<string, string>();
         List<Item_Aggregation_Related_Aggregations> subcollections = codeManager.All_Aggregations;
         foreach (Item_Aggregation_Related_Aggregations thisAggr in subcollections)
         {
             if (!tempItemList.ContainsKey(thisAggr.Code))
             {
                 tempItemList.Add(thisAggr.Code, thisAggr.Code);
             }
         }
         IList<string> keys = tempItemList.Keys;
         foreach (string thisKey in keys)
         {
             items.Add(tempItemList[thisKey].ToUpper());
         }
     }
 }