/// <summary> Constructor for a new instance of the Aggregation_Single_AdminViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <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="Thematic_Headings"> Headings under which all the highlighted collections on the home page are organized </param>
        /// <param name="Web_Skin_Collection">  Contains the collection of all the default skins and the data to create any additional skins on request</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 Aggregation_Single_AdminViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, Aggregation_Code_Manager Code_Manager, List<Thematic_Heading> Thematic_Headings, SobekCM_Skin_Collection Web_Skin_Collection, Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Aggregation_Single_AdminViewer.Constructor", String.Empty);

            // Save the parameters
            thematicHeadings = Thematic_Headings;
            webSkins = Web_Skin_Collection;
            codeManager = Code_Manager;
            currentMode = Current_Mode;

            // Set some defaults
            actionMessage = String.Empty;

            // Get the code for the aggregation being edited
            string code = currentMode.Aggregation;

            // If the user cannot edit this, go back
            if (!user.Is_Aggregation_Curator(code))
            {
                Current_Mode.Mode = Display_Mode_Enum.My_Sobek;
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                currentMode.Redirect();
                return;
            }

            // Load the item aggregation, either currenlty from the session (if already editing this aggregation )
            // or by reading all the appropriate XML and reading data from the database
            object possibleEditAggregation = HttpContext.Current.Session["Edit_Aggregation_" + code];
            Item_Aggregation cachedInstance = null;
            if (possibleEditAggregation != null)
                cachedInstance = (Item_Aggregation)possibleEditAggregation;

            itemAggregation = Item_Aggregation_Builder.Get_Item_Aggregation(code, String.Empty, cachedInstance, false, false, Tracer);

            // If unable to retrieve this aggregation, send to home
            if (itemAggregation == null)
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                currentMode.Redirect();
                return;
            }

            // Get the aggregation directory and ensure it exists
            aggregationDirectory = HttpContext.Current.Server.MapPath("design/aggregations/" + itemAggregation.Code );
            if (!Directory.Exists(aggregationDirectory))
                Directory.CreateDirectory(aggregationDirectory);

            // Determine the page
            page = 1;
            if (currentMode.My_Sobek_SubMode == "b")
                page = 2;
            else if (currentMode.My_Sobek_SubMode == "c")
                page = 3;
            else if (currentMode.My_Sobek_SubMode == "d")
                page = 4;
            else if (currentMode.My_Sobek_SubMode == "e")
                page = 5;
            else if (currentMode.My_Sobek_SubMode == "f")
                page = 6;
            else if (currentMode.My_Sobek_SubMode == "g")
                page = 7;
            else if (currentMode.My_Sobek_SubMode == "h")
                page = 8;
            else if (currentMode.My_Sobek_SubMode == "y")
                page = 9;
            else if (currentMode.My_Sobek_SubMode.IndexOf("g_") == 0)
                page = 10;

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

                    // Get the curret action
                    string action = form["admin_aggr_save"];

                    // If no action, then we should return to the current tab page
                    if (action.Length == 0)
                        action = currentMode.My_Sobek_SubMode;

                    // If this is to cancel, handle that here; no need to handle post-back from the
                    // editing form page first
                    if (action == "z")
                    {
                        // Clear the aggregation from the sessions
                        HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = null;
                        HttpContext.Current.Session["Item_Aggr_Edit_" + itemAggregation.Code + "_NewLanguages"] = null;

                        // Redirect the user
                        currentMode.Mode = Display_Mode_Enum.Aggregation;
                        currentMode.Aggregation_Type = Aggregation_Type_Enum.Home;
                        currentMode.Redirect();
                        return;
                    }

                    // Save the returned values, depending on the page
                    switch (page)
                    {
                        case 1:
                            Save_Page_1_Postback(form);
                            break;

                        case 2:
                            Save_Page_2_Postback(form);
                            break;

                        case 3:
                            Save_Page_3_Postback(form);
                            break;

                        case 4:
                            Save_Page_4_Postback(form);
                            break;

                        case 5:
                            Save_Page_5_Postback(form);
                            break;

                        case 6:
                            Save_Page_6_Postback(form);
                            break;

                        case 7:
                            Save_Page_7_Postback(form);
                            break;

                        case 8:
                            Save_Page_8_Postback(form);
                            break;

                        case 9:
                            Save_Page_CSS_Postback(form);
                            break;

                        case 10:
                            Save_Child_Page_Postback(form);
                            break;
                    }

                    // Should this be saved to the database?
                    if (action == "save")
                    {
                        // Save the new configuration file
                        bool successful_save = (itemAggregation.Write_Configuration_File(SobekCM_Library_Settings.Base_Design_Location + itemAggregation.ObjDirectory));

                        // Save to the database
                        if (!itemAggregation.Save_To_Database(user.Full_Name,null))
                            successful_save = false;

                        // Save the link between this item and the thematic heading
                        codeManager.Set_Aggregation_Thematic_Heading(itemAggregation.Code, itemAggregation.Thematic_Heading_ID);

                        // Clear the aggregation from the cache
                        Cached_Data_Manager.Remove_Item_Aggregation(itemAggregation.Code, null);

                        // Forward back to the aggregation home page, if this was successful
                        if (successful_save)
                        {
                            // Clear the aggregation from the sessions
                            HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = null;
                            HttpContext.Current.Session["Item_Aggr_Edit_" + itemAggregation.Code + "_NewLanguages"] = null;

                            // Redirect the user
                            currentMode.Mode = Display_Mode_Enum.Aggregation;
                            currentMode.Aggregation_Type = Aggregation_Type_Enum.Home;
                            currentMode.Redirect();
                        }
                        else
                        {
                            actionMessage = "Error saving aggregation information!";
                        }
                    }
                    else
                    {
                        // In some cases, skip this part
                        if (((page == 8) && (action == "h")) || ((page == 7) && (action == "g")))
                            return;

                        // Save to the admins session
                        HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = itemAggregation;
                        currentMode.My_Sobek_SubMode = action;
                        HttpContext.Current.Response.Redirect(currentMode.Redirect_URL(), false);
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        currentMode.Request_Completed = true;
                    }
                }
                catch
                {
                    actionMessage = "Unable to correctly parse postback data.";
                }
            }
        }
        /// <summary> Constructor for a new instance of the Aggregation_Single_AdminViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <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="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 Aggregation_Single_AdminViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, Aggregation_Code_Manager Code_Manager, List<Thematic_Heading> Thematic_Headings, SobekCM_Skin_Collection Web_Skin_Collection, Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Aggregation_Single_AdminViewer.Constructor", String.Empty);

            // Save the parameters
            thematicHeadings = Thematic_Headings;
            webSkins = Web_Skin_Collection;
            codeManager = Code_Manager;
            base.currentMode = Current_Mode;

            // Set some defaults
            actionMessage = String.Empty;

            // Get the code for the aggregation being edited
            string code = currentMode.Aggregation;

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

            // Load the item aggregation, either currenlty from the session (if already editing this aggregation )
            // or by reading all the appropriate XML and reading data from the database
            object possibleEditAggregation = HttpContext.Current.Session["Edit_Aggregation_" + code];
            Item_Aggregation cachedInstance = null;
            if (possibleEditAggregation != null)
                cachedInstance = (Item_Aggregation)possibleEditAggregation;

            itemAggregation = Item_Aggregation_Builder.Get_Item_Aggregation(code, String.Empty, cachedInstance, false, Tracer);

            // If unable to retrieve this aggregation, send to home
            if (itemAggregation == null)
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }

            // Determine the page
            page = 1;
            if (currentMode.My_Sobek_SubMode == "b" )
                page = 2;
            else if (currentMode.My_Sobek_SubMode == "c")
                page = 3;
            else if (currentMode.My_Sobek_SubMode == "d")
                page = 4;
            else if (currentMode.My_Sobek_SubMode == "e")
                page = 5;
            else if (currentMode.My_Sobek_SubMode == "f")
                page = 6;
            else if (currentMode.My_Sobek_SubMode == "g")
                page = 7;

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

                    // Get the curret action
                    string action = form["admin_aggr_save"];

                    // If this is to cancel, handle that here; no need to handle post-back from the
                    // editing form page first
                    if (action == "z")
                    {
                        // Clear the aggregation from the sessions
                        HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = null;
                        // Redirect the user
                        currentMode.Mode = Display_Mode_Enum.Aggregation_Home;
                        HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
                        return;
                    }

                    // Save the returned values, depending on the page
                    switch (page)
                    {
                        case 1:
                            Save_Page_1_Postback(form);
                            break;

                        case 2:
                            Save_Page_2_Postback(form);
                            break;

                        case 3:
                            Save_Page_3_Postback(form);
                            break;

                        case 4:
                            Save_Page_4_Postback(form);
                            break;

                        case 5:
                            Save_Page_5_Postback(form);
                            break;

                        case 6:
                            Save_Page_6_Postback(form);
                            break;

                        case 7:
                            Save_Page_7_Postback(form);
                            break;

                        default:
                            break;
                    }

                    // Should this be saved to the database?
                    if (action == "save")
                    {
                        // Save this aggregation information
                        bool successful_save = true;

                        // Save the new configuration file
                        itemAggregation.Write_Configuration_File(  SobekCM_Library_Settings.Base_Design_Location + itemAggregation.objDirectory );

                        // Save to the database
                        itemAggregation.Save_To_Database(null);

                        // Clear the aggregation from the cache
                        MemoryMgmt.Cached_Data_Manager.Remove_Item_Aggregation(itemAggregation.Code, null);

                        // Forward back to the aggregation home page, if this was successful
                        if (successful_save)
                        {
                            // Clear the aggregation from the sessions
                            HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = null;

                            // Redirect the user
                            currentMode.Mode = Display_Mode_Enum.Aggregation_Home;
                            HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
                        }
                    }
                    else
                    {
                        // Save to the admins session
                        HttpContext.Current.Session["Edit_Aggregation_" + itemAggregation.Code] = itemAggregation;
                        currentMode.My_Sobek_SubMode = action;
                        HttpContext.Current.Response.Redirect(currentMode.Redirect_URL(), false);
                    }
                }
                catch
                {
                    actionMessage = "Unable to correctly parse postback data.";
                }
            }
        }