Example #1
0
        /// <summary> Refreshes the item list and aggregation/greenstone code information from the database on a regular basis </summary>
        /// <param name="Code_Manager"> [REF] List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
        /// <param name="All_Items_Lookup"> [REF] Lookup object used to pull basic information about any item loaded into this library </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool Refresh_Item_List_And_Aggregation_Codes(ref Aggregation_Code_Manager Code_Manager, ref Item_Lookup_Object All_Items_Lookup)
        {
            try
            {
                // Load SobekCM Codes to Greenstone Codes conversion again
                if (Code_Manager != null)
                {
                    lock (Code_Manager)
                    {
                        SobekCM_Database.Populate_Code_Manager(Code_Manager, null);
                    }
                }
                else
                {
                    Code_Manager = new Aggregation_Code_Manager();
                    SobekCM_Database.Populate_Code_Manager(Code_Manager, null);
                }

                //lock (item_list_lock_object)
                //{
                //    if (All_Items_Lookup == null)
                //        All_Items_Lookup = new Item_Lookup_Object();

                //    // Have the database popoulate the little bit of bibid/vid information we retain
                //    SobekCM_Database.Populate_Item_Lookup_Object(true, All_Items_Lookup, null);
                //}

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        /// <summary> Constructor for a new instance of the Aggregations_Mgmt_AdminViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="CurrentMode"> 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="Thematic_Headings"> Headings under which all the highlighted collections on the home page are organized </param>       
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <remarks> Postback from handling an edit or new aggregation is handled here in the constructor </remarks>
        public Aggregations_Mgmt_AdminViewer(User_Object User, SobekCM_Navigation_Object CurrentMode, Aggregation_Code_Manager Code_Manager, List<Thematic_Heading> Thematic_Headings, Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Aggregations_Mgmt_AdminViewer.Constructor", String.Empty);

            codeManager = Code_Manager;
            currentMode = CurrentMode;
            thematicHeadings = Thematic_Headings;

            // Set some defaults
            actionMessage = String.Empty;
            enteredCode = String.Empty;
            enteredParent = String.Empty;
            enteredType = String.Empty;
            enteredShortname = String.Empty;
            enteredName = String.Empty;
            enteredDescription = String.Empty;
            enteredIsActive = false;
            enteredIsHidden = false;

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

            // If this is a postback, handle any events first
            if (currentMode.isPostBack)
            {
                try
                {
                    // Pull the standard values
                    NameValueCollection form = HttpContext.Current.Request.Form;

                    string save_value = form["admin_aggr_tosave"].ToUpper().Trim();
                    string new_aggregation_code = String.Empty;
                    if ( form["admin_aggr_code"] != null )
                        new_aggregation_code = form["admin_aggr_code"].ToUpper().Trim();

                    // Check for reset request as well
                    string reset_aggregation_code = String.Empty;
                    if (form["admin_aggr_reset"] != null)
                        reset_aggregation_code = form["admin_aggr_reset"].ToLower().Trim();

                    string delete_aggregation_code = String.Empty;
                    if (form["admin_aggr_delete"] != null)
                        delete_aggregation_code = form["admin_aggr_delete"].ToLower().Trim();

                    // Was this to delete the aggregation?
                    if ( delete_aggregation_code.Length > 0)
                    {
                        string delete_error;
                        int errorCode = SobekCM_Database.Delete_Item_Aggregation(delete_aggregation_code, user.Is_System_Admin, user.Full_Name, Tracer, out delete_error);
                        if (errorCode <= 0)
                        {
                            string delete_folder = SobekCM_Library_Settings.Base_Design_Location + "aggregations\\" + delete_aggregation_code;
                            if (SobekCM_File_Utilities.Delete_Folders_Recursively(delete_folder))
                                actionMessage = "Deleted '" + delete_aggregation_code + "' aggregation<br /><br />Unable to remove aggregation directory<br /><br />Some of the files may be in use";
                            else
                                actionMessage = "Deleted '" + delete_aggregation_code + "' aggregation";
                        }
                        else
                        {
                            actionMessage = delete_error;
                        }

                        // Reload the list of all codes, to include this new one and the new hierarchy
                        lock (codeManager)
                        {
                            SobekCM_Database.Populate_Code_Manager(codeManager, Tracer);
                        }
                    }

                    // If there is a reset request here, purge the aggregation from the cache
                    if (reset_aggregation_code.Length > 0)
                    {
                        Cached_Data_Manager.Remove_Item_Aggregation(reset_aggregation_code, Tracer);
                    }

                    // If there was a save value continue to pull the rest of the data
                    if (save_value.Length > 0)
                    {

                        bool is_active = false;
                        bool is_hidden = true;

                        // Was this to save a new aggregation (from the main page) or edit an existing (from the popup form)?
                        if (save_value == new_aggregation_code)
                        {

                            // Pull the values from the submitted form
                            string new_type = form["admin_aggr_type"];
                            string new_parent = form["admin_aggr_parent"].Trim();
                            string new_name = form["admin_aggr_name"].Trim();
                            string new_shortname = form["admin_aggr_shortname"].Trim();
                            string new_description = form["admin_aggr_desc"].Trim();
                            string new_link = form["admin_aggr_link"].Trim();

                            object temp_object = form["admin_aggr_isactive"];
                            if (temp_object != null)
                            {
                                is_active = true;
                            }

                            temp_object = form["admin_aggr_ishidden"];
                            if (temp_object != null)
                            {
                                is_hidden = false;
                            }

                            // Convert to the integer id for the parent and begin to do checking
                            List<string> errors = new List<string>();
                            int parentid = -1;
                            if (new_parent.Length > 0)
                            {
                                try
                                {
                                    parentid = Convert.ToInt32(new_parent);
                                }
                                catch
                                {
                                    errors.Add("Invalid parent id selected!");
                                }
                            }
                            else
                            {
                                errors.Add("You must select a PARENT for this new aggregation");
                            }

                            // Validate the code
                            if (new_aggregation_code.Length > 20)
                            {
                                errors.Add("New aggregation code must be twenty characters long or less");
                            }
                            else if (new_aggregation_code.Length == 0)
                            {
                                errors.Add("You must enter a CODE for this item aggregation");

                            }
                            else if (codeManager[new_aggregation_code.ToUpper()] != null)
                            {
                                errors.Add("New code must be unique... <i>" + new_aggregation_code + "</i> already exists");
                            }
                            else if (SobekCM_Library_Settings.Reserved_Keywords.Contains(new_aggregation_code.ToLower()))
                            {
                                errors.Add("That code is a system-reserved keyword.  Try a different code.");
                            }

                            // Was there a type and name
                            if (new_type.Length == 0)
                            {
                                errors.Add("You must select a TYPE for this new aggregation");
                            }
                            if (new_description.Length == 0)
                            {
                                errors.Add("You must enter a DESCRIPTION for this new aggregation");
                            }
                            if (new_name.Length == 0)
                            {
                                errors.Add("You must enter a NAME for this new aggregation");
                            }
                            else
                            {
                                if (new_shortname.Length == 0)
                                    new_shortname = new_name;
                            }

                            if (errors.Count > 0)
                            {
                                // Create the error message
                                actionMessage = "ERROR: Invalid entry for new item aggregation<br />";
                                foreach (string error in errors)
                                    actionMessage = actionMessage + "<br />" + error;

                                // Save all the values that were entered
                                enteredCode = new_aggregation_code;
                                enteredDescription = new_description;
                                enteredIsActive = is_active;
                                enteredIsHidden = is_hidden;
                                enteredName = new_name;
                                enteredParent = new_parent;
                                enteredShortname = new_shortname;
                                enteredType = new_type;
                                enteredLink = new_link;
                            }
                            else
                            {
                                // Get the correct type
                                string correct_type = "Collection";
                                switch (new_type)
                                {
                                    case "coll":
                                        correct_type = "Collection";
                                        break;

                                    case "group":
                                        correct_type = "Collection Group";
                                        break;

                                    case "subcoll":
                                        correct_type = "SubCollection";
                                        break;

                                    case "inst":
                                        correct_type = "Institution";
                                        break;

                                    case "exhibit":
                                        correct_type = "Exhibit";
                                        break;

                                    case "subinst":
                                        correct_type = "Institutional Division";
                                        break;
                                }
                                // Make sure inst and subinst start with 'i'
                                if (new_type.IndexOf("inst") >= 0)
                                {
                                    if (new_aggregation_code[0] == 'I')
                                        new_aggregation_code = "i" + new_aggregation_code.Substring(1);
                                    if (new_aggregation_code[0] != 'i')
                                        new_aggregation_code = "i" + new_aggregation_code;
                                }

                                // Get the thematic heading id (no checks here)
                                int thematicHeadingId = -1;
                                if (form["admin_aggr_heading"] != null)
                                    thematicHeadingId = Convert.ToInt32(form["admin_aggr_heading"]);

                                // Try to save the new item aggregation
                                if (SobekCM_Database.Save_Item_Aggregation(new_aggregation_code, new_name, new_shortname, new_description, thematicHeadingId, correct_type, is_active, is_hidden, new_link, parentid, user.Full_Name, Tracer))
                                {
                                    // Ensure a folder exists for this, otherwise create one
                                    try
                                    {
                                        string folder = SobekCM_Library_Settings.Base_Design_Location + "aggregations\\" + new_aggregation_code.ToLower();
                                        if (!Directory.Exists(folder))
                                        {
                                            // Create this directory and all the subdirectories
                                            Directory.CreateDirectory(folder);
                                            Directory.CreateDirectory(folder + "/html");
                                            Directory.CreateDirectory(folder + "/images");
                                            Directory.CreateDirectory(folder + "/html/home");
                                            Directory.CreateDirectory(folder + "/images/buttons");
                                            Directory.CreateDirectory(folder + "/images/banners");

                                            // Create a default home text file
                                            StreamWriter writer = new StreamWriter(folder + "/html/home/text.html");
                                            writer.WriteLine("<br />New collection home page text goes here.<br /><br />To edit this, log on as the aggregation admin and hover over this text to edit it.<br /><br />");
                                            writer.Flush();
                                            writer.Close();

                                            // Copy the default banner and buttons from images
                                            if (File.Exists(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.png"))
                                                File.Copy(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.png", folder + "/images/buttons/coll.png");
                                            if (File.Exists(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.gif"))
                                                File.Copy(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.gif", folder + "/images/buttons/coll.gif");

                                            // Try to create a new custom banner
                                            bool custom_banner_created = false;
                                            // Create the banner with the name of the collection
                                            if (Directory.Exists(SobekCM_Library_Settings.Application_Server_Network + "\\default\\banner_images"))
                                            {
                                                try
                                                {
                                                    string[] banners = Directory.GetFiles(SobekCM_Library_Settings.Application_Server_Network + "\\default\\banner_images", "*.jpg");
                                                    if (banners.Length > 0)
                                                    {
                                                        Random randomizer = new Random();
                                                        string banner_to_use = banners[randomizer.Next(0, banners.Length - 1)];
                                                        Bitmap bitmap = (Bitmap)System.Drawing.Bitmap.FromFile(banner_to_use);

                                                        RectangleF rectf = new RectangleF(30, bitmap.Height - 55, bitmap.Width - 40, 40);
                                                        Graphics g = Graphics.FromImage(bitmap);
                                                        g.SmoothingMode = SmoothingMode.AntiAlias;
                                                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                                        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                                                        g.DrawString(new_name, new Font("Tahoma", 25, FontStyle.Bold), Brushes.Black, rectf);
                                                        g.Flush();

                                                        string new_file = folder + "/images/banners/coll.jpg";
                                                        if (!File.Exists(new_file))
                                                        {
                                                            bitmap.Save(new_file, ImageFormat.Jpeg);
                                                            custom_banner_created = true;
                                                        }
                                                    }
                                                }
                                                catch (Exception ee)
                                                {
                                                    string msg = ee.Message;
                                                }
                                            }

                                            if ((!custom_banner_created) && (!File.Exists(folder + "/images/banners/coll.jpg")))
                                            {
                                                if (File.Exists(SobekCM_Library_Settings.Base_Directory + "default/images/default_banner.jpg"))
                                                    File.Copy(SobekCM_Library_Settings.Base_Directory + "default/images/default_banner.jpg", folder + "/images/banners/coll.jpg");
                                            }

                                            // Now, try to create the item aggregation and write the configuration file
                                            Item_Aggregation itemAggregation = Item_Aggregation_Builder.Get_Item_Aggregation(new_aggregation_code, String.Empty, null, false, false, Tracer);
                                            itemAggregation.Write_Configuration_File(SobekCM_Library_Settings.Base_Design_Location + itemAggregation.ObjDirectory);
                                        }
                                    }
                                    catch
                                    {
                                        actionMessage = "ERROR saving the new item aggregation to the database";
                                    }

                                    // Reload the list of all codes, to include this new one and the new hierarchy
                                    lock (codeManager)
                                    {
                                        SobekCM_Database.Populate_Code_Manager(codeManager, Tracer);
                                    }
                                    if ( !String.IsNullOrEmpty(actionMessage))
                                        actionMessage = "New item aggregation <i>" + new_aggregation_code + "</i> saved successfully";
                                }
                                else
                                {
                                    actionMessage = "ERROR saving the new item aggregation to the database";
                                }
                            }
                        }
                    }
                }
                catch
                {
                    actionMessage = "General error while reading postback information";
                }
            }
        }
Example #3
0
        /// <summary> Verifies that each global object is built and builds them upon request </summary>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="Reload_All"> Flag indicates if everything should be reloaded/repopulated</param>
        /// <param name="Skins"> [REF] Collection of all the web skins </param>
        /// <param name="Translator"> [REF] Language support object which handles simple translational duties </param>
        /// <param name="Code_Manager"> [REF] List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
        /// <param name="All_Items_Lookup"> [REF] Lookup object used to pull basic information about any item loaded into this library </param>
        /// <param name="Icon_Dictionary"> [REF] Dictionary of information about every wordmark/icon in this digital library </param>
        /// <param name="Stats_Date_Range"> [REF] Object contains the start and end dates for the statistical data in the database </param>
        /// <param name="Thematic_Headings"> [REF] Headings under which all the highlighted collections on the main home page are organized </param>
        /// <param name="Aggregation_Aliases"> [REF] List of all existing aliases for existing aggregations </param>
        /// <param name="IP_Restrictions"> [REF] List of all IP Restriction ranges in use by this digital library </param>
        /// <param name="URL_Portals"> [REF] List of all web portals into this system </param>
        /// <param name="Mime_Types">[REF] Dictionary of MIME types by extension</param>
        public static void Build_Application_State(Custom_Tracer Tracer, bool Reload_All,
                                                   ref SobekCM_Skin_Collection Skins, ref Language_Support_Info Translator,
                                                   ref Aggregation_Code_Manager Code_Manager, ref Item_Lookup_Object All_Items_Lookup,
                                                   ref Dictionary <string, Wordmark_Icon> Icon_Dictionary,
                                                   ref Statistics_Dates Stats_Date_Range,
                                                   ref List <Thematic_Heading> Thematic_Headings,
                                                   ref Dictionary <string, string> Aggregation_Aliases,
                                                   ref IP_Restriction_Ranges IP_Restrictions,
                                                   ref Portal_List URL_Portals,
                                                   ref Dictionary <string, Mime_Type_Info> Mime_Types)
        {
            // Should we reload the data from the exteral configuraiton file?
            if (Reload_All)
            {
                SobekCM_Library_Settings.Read_Configuration_File();
                SobekCM_Database.Connection_String = SobekCM_Library_Settings.Database_Connection_String;
                SobekCM_Library_Settings.Refresh(SobekCM_Database.Get_Settings_Complete(null));
            }

            // If there is no database connection string, there is a problem
            if (String.IsNullOrEmpty(SobekCM_Library_Settings.Database_Connection_String))
            {
                throw new ApplicationException("Missing database connection string!");
            }

            // Set the database connection strings
            Resource_Object.Database.SobekCM_Database.Connection_String = SobekCM_Library_Settings.Database_Connection_String;
            SobekCM_Database.Connection_String = SobekCM_Library_Settings.Database_Connection_String;

            // Set the workflow and disposition types
            if ((SobekCM_Library_Settings.Need_Workflow_And_Disposition_Types) || (Reload_All))
            {
                SobekCM_Library_Settings.Set_Workflow_And_Disposition_Types(SobekCM_Database.All_WorkFlow_Types, SobekCM_Database.All_Possible_Disposition_Types);
            }

            // Set the metadata types
            if ((SobekCM_Library_Settings.Need_Metadata_Types) || (Reload_All))
            {
                SobekCM_Library_Settings.Set_Metadata_Types(SobekCM_Database.Get_Metadata_Fields(null));
            }

            // Set the search stop words
            if ((SobekCM_Library_Settings.Need_Search_Stop_Words) || (Reload_All))
            {
                SobekCM_Library_Settings.Search_Stop_Words = SobekCM_Database.Search_Stop_Words(Tracer);
            }

            // Check the list of thematic headings
            if ((Thematic_Headings == null) || (Reload_All))
            {
                if (Thematic_Headings != null)
                {
                    lock (Thematic_Headings)
                    {
                        if (!SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer))
                        {
                            Thematic_Headings = null;
                            throw SobekCM_Database.Last_Exception;
                        }
                    }
                }
                else
                {
                    Thematic_Headings = new List <Thematic_Heading>();
                    if (!SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer))
                    {
                        Thematic_Headings = null;
                        throw SobekCM_Database.Last_Exception;
                    }
                }
            }

            // Check the list of forwardings
            if ((Aggregation_Aliases == null) || (Reload_All))
            {
                if (Aggregation_Aliases != null)
                {
                    lock (Aggregation_Aliases)
                    {
                        SobekCM_Database.Populate_Aggregation_Aliases(Aggregation_Aliases, Tracer);
                    }
                }
                else
                {
                    Aggregation_Aliases = new Dictionary <string, string>();
                    SobekCM_Database.Populate_Aggregation_Aliases(Aggregation_Aliases, Tracer);
                }
            }

            // Check the list of constant skins
            if ((Skins == null) || (Skins.Count == 0) || (Reload_All))
            {
                if (Skins != null)
                {
                    lock (Skins)
                    {
                        SobekCM_Skin_Collection_Builder.Populate_Default_Skins(Skins, Tracer);
                    }
                }
                else
                {
                    Skins = new SobekCM_Skin_Collection();
                    SobekCM_Skin_Collection_Builder.Populate_Default_Skins(Skins, Tracer);
                }
            }

            // Check the list of all web portals
            if ((URL_Portals == null) || (URL_Portals.Count == 0) || (Reload_All))
            {
                if (URL_Portals != null)
                {
                    lock (URL_Portals)
                    {
                        SobekCM_Database.Populate_URL_Portals(URL_Portals, Tracer);
                    }
                }
                else
                {
                    URL_Portals = new Portal_List();
                    SobekCM_Database.Populate_URL_Portals(URL_Portals, Tracer);
                }
            }

            // Check the translation table has been loaded
            if ((Translator == null) || (Reload_All))
            {
                // Get the translation hashes into memory
                if (Translator != null)
                {
                    lock (Translator)
                    {
                        SobekCM_Database.Populate_Translations(Translator, Tracer);
                    }
                }
                else
                {
                    Translator = new Language_Support_Info();
                    SobekCM_Database.Populate_Translations(Translator, Tracer);
                }
            }

            // Check that the conversion from SobekCM Codes to Greenstone Codes has been loaded
            if ((Code_Manager == null) || (Reload_All))
            {
                if (Code_Manager != null)
                {
                    lock (Code_Manager)
                    {
                        SobekCM_Database.Populate_Code_Manager(Code_Manager, Tracer);
                    }
                }
                else
                {
                    Code_Manager = new Aggregation_Code_Manager();
                    SobekCM_Database.Populate_Code_Manager(Code_Manager, Tracer);
                }
            }

            // Check the statistics date range information
            if ((Stats_Date_Range == null) || (Reload_All))
            {
                if (Stats_Date_Range != null)
                {
                    // Get the translation hashes into memory
                    lock (Stats_Date_Range)
                    {
                        SobekCM_Database.Populate_Statistics_Dates(Stats_Date_Range, Tracer);
                    }
                }
                else
                {
                    Stats_Date_Range = new Statistics_Dates();
                    SobekCM_Database.Populate_Statistics_Dates(Stats_Date_Range, Tracer);
                }
            }

            // Get the Icon list
            if ((Icon_Dictionary == null) || (Reload_All))
            {
                if (Icon_Dictionary != null)
                {
                    // Get the translation hashes into memory
                    lock (Icon_Dictionary)
                    {
                        SobekCM_Database.Populate_Icon_List(Icon_Dictionary, Tracer);
                    }
                }
                else
                {
                    Icon_Dictionary = new Dictionary <string, Wordmark_Icon>();
                    SobekCM_Database.Populate_Icon_List(Icon_Dictionary, Tracer);
                }
            }

            // Check the list of ip range restrictions
            if ((IP_Restrictions == null) || (Reload_All))
            {
                if (IP_Restrictions != null)
                {
                    lock (IP_Restrictions)
                    {
                        DataTable ipRestrictionTbl = SobekCM_Database.Get_IP_Restriction_Ranges(Tracer);
                        if (ipRestrictionTbl != null)
                        {
                            IP_Restrictions.Populate_IP_Ranges(ipRestrictionTbl);
                        }
                    }
                }
                else
                {
                    DataTable ipRestrictionTbl = SobekCM_Database.Get_IP_Restriction_Ranges(Tracer);
                    if (ipRestrictionTbl != null)
                    {
                        IP_Restrictions = new IP_Restriction_Ranges();
                        IP_Restrictions.Populate_IP_Ranges(ipRestrictionTbl);
                    }
                }
            }


            // Get the MIME type list
            if ((Mime_Types == null) || (Reload_All))
            {
                if (Mime_Types != null)
                {
                    // Get the translation hashes into memory
                    lock (Mime_Types)
                    {
                        SobekCM_Database.Populate_MIME_List(Mime_Types, Tracer);
                    }
                }
                else
                {
                    Mime_Types = new Dictionary <string, Mime_Type_Info>();
                    SobekCM_Database.Populate_MIME_List(Mime_Types, Tracer);
                }
            }
        }
Example #4
0
        /// <summary> Constructor for a new instance of the Aggregations_Mgmt_AdminViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="currentMode"> 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>
        /// <remarks> Postback from handling an edit or new aggregation is handled here in the constructor </remarks>
        public Aggregations_Mgmt_AdminViewer(User_Object User, SobekCM_Navigation_Object currentMode, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Aggregations_Mgmt_AdminViewer.Constructor", String.Empty);

            codeManager = Code_Manager;

            // Set some defaults
            actionMessage      = String.Empty;
            enteredCode        = String.Empty;
            enteredParent      = String.Empty;
            enteredType        = String.Empty;
            enteredShortname   = String.Empty;
            enteredName        = String.Empty;
            enteredDescription = String.Empty;
            enteredIsActive    = false;
            enteredIsHidden    = false;

            // If the user cannot edit this, go back
            if ((!user.Is_System_Admin) && (!user.Is_Portal_Admin))
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }

            // If this is a postback, handle any events first
            if (currentMode.isPostBack)
            {
                try
                {
                    // Pull the standard values
                    NameValueCollection form = HttpContext.Current.Request.Form;

                    string save_value           = form["admin_aggr_tosave"].ToUpper().Trim();
                    string new_aggregation_code = String.Empty;
                    if (form["admin_aggr_code"] != null)
                    {
                        new_aggregation_code = form["admin_aggr_code"].ToUpper().Trim();
                    }

                    // Check for reset request as well
                    string reset_aggregation_code = String.Empty;
                    if (form["admin_aggr_reset"] != null)
                    {
                        reset_aggregation_code = form["admin_aggr_reset"].ToLower().Trim();
                    }

                    // If there is a reset request here, purge the aggregation from the cache
                    if (reset_aggregation_code.Length > 0)
                    {
                        Cached_Data_Manager.Remove_Item_Aggregation(reset_aggregation_code, Tracer);
                    }

                    // If there was a save value continue to pull the rest of the data
                    if (save_value.Length > 0)
                    {
                        bool   is_active = false;
                        bool   is_hidden = false;
                        object temp_object;


                        // Was this to save a new aggregation (from the main page) or edit an existing (from the popup form)?
                        if (save_value == new_aggregation_code)
                        {
                            // Pull the values from the submitted form
                            string new_type        = form["admin_aggr_type"];
                            string new_parent      = form["admin_aggr_parent"].Trim();
                            string new_name        = form["admin_aggr_name"].Trim();
                            string new_shortname   = form["admin_aggr_shortname"].Trim();
                            string new_description = form["admin_aggr_desc"].Trim();
                            string new_link        = form["admin_aggr_link"].Trim();

                            temp_object = form["admin_aggr_isactive"];
                            if (temp_object != null)
                            {
                                is_active = true;
                            }

                            temp_object = form["admin_aggr_ishidden"];
                            if (temp_object != null)
                            {
                                is_hidden = true;
                            }

                            // Convert to the integer id for the parent and begin to do checking
                            List <string> errors   = new List <string>();
                            int           parentid = -1;
                            if (new_parent.Length > 0)
                            {
                                try
                                {
                                    parentid = Convert.ToInt32(new_parent);
                                }
                                catch
                                {
                                    errors.Add("Invalid parent id selected!");
                                }
                            }
                            else
                            {
                                errors.Add("You must select a PARENT for this new aggregation");
                            }

                            // Get the list of all aggregations
                            if (new_aggregation_code.Length > 20)
                            {
                                errors.Add("New aggregation code must be twenty characters long or less");
                            }
                            else
                            {
                                if (codeManager[new_aggregation_code] != null)
                                {
                                    errors.Add("New code must be unique... <i>" + new_aggregation_code + "</i> already exists");
                                }
                            }

                            // Was there a type and name
                            if (new_type.Length == 0)
                            {
                                errors.Add("You must select a TYPE for this new aggregation");
                            }
                            if (new_description.Length == 0)
                            {
                                errors.Add("You must enter a DESCRIPTION for this new aggregation");
                            }
                            if (new_name.Length == 0)
                            {
                                errors.Add("You must enter a NAME for this new aggregation");
                            }
                            else
                            {
                                if (new_shortname.Length == 0)
                                {
                                    new_shortname = new_name;
                                }
                            }

                            if (errors.Count > 0)
                            {
                                // Create the error message
                                actionMessage = "ERROR: Invalid entry for new item aggregation<br />";
                                foreach (string error in errors)
                                {
                                    actionMessage = actionMessage + "<br />" + error;
                                }

                                // Save all the values that were entered
                                enteredCode        = new_aggregation_code;
                                enteredDescription = new_description;
                                enteredIsActive    = is_active;
                                enteredIsHidden    = is_hidden;
                                enteredName        = new_name;
                                enteredParent      = new_parent;
                                enteredShortname   = new_shortname;
                                enteredType        = new_type;
                                enteredLink        = new_link;
                            }
                            else
                            {
                                // Get the correct type
                                string correct_type = "Collection";
                                switch (new_type)
                                {
                                case "coll":
                                    correct_type = "Collection";
                                    break;

                                case "group":
                                    correct_type = "Collection Group";
                                    break;

                                case "subcoll":
                                    correct_type = "SubCollection";
                                    break;

                                case "inst":
                                    correct_type = "Institution";
                                    break;

                                case "exhibit":
                                    correct_type = "Exhibit";
                                    break;

                                case "subinst":
                                    correct_type = "Institutional Division";
                                    break;
                                }
                                // Make sure inst and subinst start with 'i'
                                if (new_type.IndexOf("inst") >= 0)
                                {
                                    if (new_aggregation_code[0] == 'I')
                                    {
                                        new_aggregation_code = "i" + new_aggregation_code.Substring(1);
                                    }
                                    if (new_aggregation_code[0] != 'i')
                                    {
                                        new_aggregation_code = "i" + new_aggregation_code;
                                    }
                                }

                                // Try to save the new item aggregation
                                if (SobekCM_Database.Save_Item_Aggregation(new_aggregation_code, new_name, new_shortname, new_description, correct_type, is_active, is_hidden, new_link, parentid, Tracer))
                                {
                                    // Ensure a folder exists for this, otherwise create one
                                    try
                                    {
                                        string folder = SobekCM_Library_Settings.Base_Design_Location + "aggregations\\" + new_aggregation_code.ToLower();
                                        if (!Directory.Exists(folder))
                                        {
                                            // Create this directory and all the subdirectories
                                            Directory.CreateDirectory(folder);
                                            Directory.CreateDirectory(folder + "/html");
                                            Directory.CreateDirectory(folder + "/images");
                                            Directory.CreateDirectory(folder + "/html/home");
                                            Directory.CreateDirectory(folder + "/images/buttons");
                                            Directory.CreateDirectory(folder + "/images/banners");

                                            // Create a default home text file
                                            StreamWriter writer = new StreamWriter(folder + "/html/home/text.html");
                                            writer.WriteLine("<br />New collection home page text goes here.<br /><br />To edit this, edit the following file: " + folder + "\\html\\home\\text.html.<br /><br />");
                                            writer.Flush();
                                            writer.Close();

                                            // Copy the default banner and buttons from images
                                            if (File.Exists(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.png"))
                                            {
                                                File.Copy(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.png", folder + "/images/buttons/coll.png");
                                            }
                                            if (File.Exists(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.gif"))
                                            {
                                                File.Copy(SobekCM_Library_Settings.Base_Directory + "default/images/default_button.gif", folder + "/images/buttons/coll.gif");
                                            }
                                            if (File.Exists(SobekCM_Library_Settings.Base_Directory + "default/images/default_banner.jpg"))
                                            {
                                                File.Copy(SobekCM_Library_Settings.Base_Directory + "default/images/default_banner.jpg", folder + "/images/banners/coll.jpg");
                                            }

                                            // Now, try to create the item aggregation and write the configuration file
                                            Item_Aggregation itemAggregation = Item_Aggregation_Builder.Get_Item_Aggregation(new_aggregation_code, String.Empty, null, false, Tracer);
                                            itemAggregation.Write_Configuration_File(SobekCM_Library_Settings.Base_Design_Location + itemAggregation.objDirectory);
                                        }
                                    }
                                    catch { }

                                    // Reload the list of all codes, to include this new one and the new hierarchy
                                    lock (codeManager)
                                    {
                                        SobekCM_Database.Populate_Code_Manager(codeManager, Tracer);
                                    }
                                    actionMessage = "New item aggregation <i>" + new_aggregation_code + "</i> saved successfully";
                                }
                                else
                                {
                                    actionMessage = "ERROR saving the new item aggregation to the database";
                                }
                            }
                        }
                    }
                }
                catch
                {
                    actionMessage = "General error while reading postback information";
                }
            }
        }