/// <summary> Constructor for a new instance of the Text_Search_ItemViewer class, which allows the full text of an
        /// individual resource to be searched and individual matching pages are displayed with page thumbnails </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Text_Search_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Text_Search_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem      = BriefItem;
            this.CurrentUser    = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            if (!String.IsNullOrWhiteSpace(CurrentRequest.Text_Search))
            {
                List <string> terms      = new List <string>();
                List <string> web_fields = new List <string>();

                // Split the terms correctly
                SobekCM_Assistant.Split_Clean_Search_Terms_Fields(CurrentRequest.Text_Search, "ZZ", Search_Type_Enum.Basic, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Performing Solr/Lucene search");

                int page = CurrentRequest.SubPage.HasValue ? Math.Max(CurrentRequest.SubPage.Value, ((ushort)1)) : 1;
                results = Solr_Page_Results.Search(BriefItem.BibID, BriefItem.VID, terms, 20, page, false);

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Completed Solr/Lucene search in " + results.QueryTime + "ms");
            }
        }
Esempio n. 2
0
        private string compute_text_redirect_stem()
        {
            // Split the parts
            List <string> terms  = new List <string>();
            List <string> fields = new List <string>();

            // Split the terms correctly
            SobekCM_Assistant.Split_Clean_Search_Terms_Fields(RequestSpecificValues.Current_Mode.Search_String, RequestSpecificValues.Current_Mode.Search_Fields, RequestSpecificValues.Current_Mode.Search_Type, terms, fields, UI_ApplicationCache_Gateway.Search_Stop_Words, RequestSpecificValues.Current_Mode.Search_Precision, ',');

            // See about a text search string
            StringBuilder textSearcher = new StringBuilder();

            // Step through each term and field
            bool text_included_in_search = false;

            for (int i = 0; (i < terms.Count) && (i < fields.Count); i++)
            {
                if ((fields[i].Length > 1) && (terms[i].Length > 1))
                {
                    // If this is either for ANYWHERE or for TEXT, include it
                    if (((fields[i].IndexOf("TX") >= 0) || (fields[i].IndexOf("ZZ") >= 0)) && (fields[i][0] != '-'))
                    {
                        if (textSearcher.Length > 0)
                        {
                            textSearcher.Append("+=" + terms[i].Replace("\"", "%22"));
                        }
                        else
                        {
                            textSearcher.Append(terms[i].Replace("\"", "%22"));
                        }
                    }

                    // See if this was explicitly a search against full text
                    if (fields[i].IndexOf("TX") >= 0)
                    {
                        text_included_in_search = true;
                    }
                }
            }

            string url_options = UrlWriterHelper.URL_Options(RequestSpecificValues.Current_Mode);

            if (!String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Coordinates))
            {
                return((url_options.Length > 0) ? "?coord=" + RequestSpecificValues.Current_Mode.Coordinates + "&" + url_options : "?coord=" + RequestSpecificValues.Current_Mode.Coordinates);
            }

            if (textSearcher.Length > 0)
            {
                if ((RequestSpecificValues.Current_Mode.Search_Type == Search_Type_Enum.Full_Text) || (text_included_in_search))
                {
                    return((url_options.Length > 0) ? "/search?search=" + textSearcher + "&" + url_options :  "/search?search=" + textSearcher);
                }

                return((url_options.Length > 0) ? "?search=" + textSearcher + "&" + url_options : "?search=" + textSearcher);
            }
            return((url_options.Length > 0) ?  "?" + url_options :  String.Empty);
        }
Esempio n. 3
0
        /// <summary> This provides an opportunity for the viewer to perform any pre-display work
        /// which is necessary before entering any of the rendering portions </summary>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <remarks> This method his class pulls any full-text search results for this single item from the Solr/Lucene engine </remarks>
        public override void Perform_PreDisplay_Work(Custom_Tracer Tracer)
        {
            if (CurrentMode.Text_Search.Length > 0)
            {
                List <string> terms      = new List <string>();
                List <string> web_fields = new List <string>();

                // Split the terms correctly
                SobekCM_Assistant.Split_Clean_Search_Terms_Fields(CurrentMode.Text_Search, "ZZ", Search_Type_Enum.Basic, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

                Tracer.Add_Trace("Text_Search_Item_Viewer.Perform_PreDisplay_Work", "Performing Solr/Lucene search");

                results = Solr_Page_Results.Search(CurrentItem.BibID, CurrentItem.VID, terms, 20, CurrentMode.SubPage, false);

                Tracer.Add_Trace("Text_Search_Item_Viewer.Perform_PreDisplay_Work", "Completed Solr/Lucene search in " + results.QueryTime + "ms");
            }
        }
        /// <summary> Constructor for a new instance of the Folder_Mgmt_MySobekViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Folder_Mgmt_MySobekViewer(RequestCache RequestSpecificValues)
            : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Folder_Mgmt_MySobekViewer.Constructor", String.Empty);

            properFolderName = String.Empty;
            int current_folder_id = -1;
            if ( !String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.My_Sobek_SubMode))
            {
                // Try to get this RequestSpecificValues.Current_User folder from the RequestSpecificValues.Current_User object
                User_Folder userFolder = RequestSpecificValues.Current_User.Get_Folder( RequestSpecificValues.Current_Mode.My_Sobek_SubMode );

                // If the RequestSpecificValues.Current_User folder is null, then this folder is not in the current RequestSpecificValues.Current_User object
                // This may still be a valid folder though.  Check this by pulling folder list for this
                // RequestSpecificValues.Current_User again
                if (userFolder == null)
                {
                    // Get the RequestSpecificValues.Current_User from the database again
                    User_Object checkFolderUser = Engine_Database.Get_User(RequestSpecificValues.Current_User.UserID, RequestSpecificValues.Tracer);

                    // Look for this folder in the new RequestSpecificValues.Current_User object
                    userFolder = checkFolderUser.Get_Folder(RequestSpecificValues.Current_Mode.My_Sobek_SubMode);
                    if (userFolder == null)
                    {
                        // Invalid folder.. should not have gotten this far though
                        HttpContext.Current.Response.Redirect(RequestSpecificValues.Current_Mode.Base_URL, false);
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        RequestSpecificValues.Current_Mode.Request_Completed = true;
                        return;
                    }

                    // Save this to the RequestSpecificValues.Current_User so this does not have to happen again
                    RequestSpecificValues.Current_User.Add_Folder(userFolder);
                }

                // Get the proper name and folder id
                Debug.Assert(userFolder != null, "userFolder != null");
                properFolderName = userFolder.Folder_Name;
                current_folder_id = userFolder.Folder_ID;
            }

            if ((RequestSpecificValues.Current_Mode.isPostBack) || ((HttpContext.Current.Request.Form["item_action"] != null) && (HttpContext.Current.Request.Form["item_action"].Length > 0 )))
            {
                try
                {
                    // Pull the standard values
                    NameValueCollection form = HttpContext.Current.Request.Form;

                    string item_action = form["item_action"].Replace(",","").ToUpper().Trim();
                    string bookshelf_items = form["bookshelf_items"].Trim().Replace("%22", "\"").Replace("%27", "'").Replace("%3D", "=").Replace("%26", "&");
                    string bookshelf_params = form["bookshelf_params"].Trim();
                    string add_bookshelf = String.Empty;
                    if ( form["add_bookshelf"] != null )
                        add_bookshelf = form["add_bookshelf"].Trim();

                    if (item_action == "REFRESH_FOLDER")
                    {
                         refresh_user_folders(RequestSpecificValues.Current_User, RequestSpecificValues.Tracer);
                         CachedDataManager.Remove_All_User_Folder_Browses(RequestSpecificValues.Current_User.UserID, RequestSpecificValues.Tracer);
                    }

                    if (item_action == "DELETE_FOLDER")
                    {
                        int folder_id = Convert.ToInt32(bookshelf_items);

                        SobekCM_Database.Delete_User_Folder(RequestSpecificValues.Current_User.UserID, folder_id, RequestSpecificValues.Tracer);
                        CachedDataManager.Clear_Public_Folder_Info(folder_id, RequestSpecificValues.Tracer);
                        refresh_user_folders(RequestSpecificValues.Current_User, RequestSpecificValues.Tracer);
                    }

                    if (item_action == "NEW_BOOKSHELF")
                    {
                        string folder_name = form["new_bookshelf_name"].Trim().Replace("<", "(").Replace(">", ")");
                        int parent_id = Convert.ToInt32(form["new_bookshelf_parent"]);

                        if (SobekCM_Database.Edit_User_Folder(-1, RequestSpecificValues.Current_User.UserID, parent_id, folder_name, false, String.Empty, RequestSpecificValues.Tracer) > 0)
                        {
                            refresh_user_folders(RequestSpecificValues.Current_User, RequestSpecificValues.Tracer);
                        }
                    }

                    if ( item_action == "FOLDER_VISIBILITY" )
                    {
                        User_Folder thisFolder = RequestSpecificValues.Current_User.Get_Folder(bookshelf_items);
                        if (bookshelf_params.ToUpper() == "PRIVATE")
                        {
                            if (SobekCM_Database.Edit_User_Folder(thisFolder.Folder_ID, RequestSpecificValues.Current_User.UserID, -1, thisFolder.Folder_Name, false, String.Empty, RequestSpecificValues.Tracer) >= 0)
                                thisFolder.IsPublic = false;

                            CachedDataManager.Clear_Public_Folder_Info(thisFolder.Folder_ID, RequestSpecificValues.Tracer);
                        }

                        if (bookshelf_params.ToUpper() == "PUBLIC")
                        {
                            if (SobekCM_Database.Edit_User_Folder(thisFolder.Folder_ID, RequestSpecificValues.Current_User.UserID, -1, thisFolder.Folder_Name, true, String.Empty, RequestSpecificValues.Tracer) >= 0 )
                                thisFolder.IsPublic = true;
                        }
                    }

                    if ((item_action == "REMOVE") || ( item_action == "MOVE" ))
                    {
                        if (bookshelf_items.IndexOf("|") > 0)
                        {
                            string[] split_multi_items = bookshelf_items.Split("|".ToCharArray());
                            foreach (string[] split in split_multi_items.Select(ThisItem => ThisItem.Split("_".ToCharArray())).Where(Split => Split.Length == 2))
                            {
                                SobekCM_Database.Delete_Item_From_User_Folder(RequestSpecificValues.Current_User.UserID, properFolderName, split[0], split[1], RequestSpecificValues.Tracer);
                                if (item_action == "MOVE")
                                {
                                    SobekCM_Database.Add_Item_To_User_Folder(RequestSpecificValues.Current_User.UserID, add_bookshelf, split[0], split[1], 0, String.Empty, RequestSpecificValues.Tracer);
                                }
                            }

                            // Ensure this RequestSpecificValues.Current_User folder is not sitting in the cache
                            CachedDataManager.Remove_User_Folder_Browse(RequestSpecificValues.Current_User.UserID, properFolderName, RequestSpecificValues.Tracer);
                            CachedDataManager.Clear_Public_Folder_Info(current_folder_id, RequestSpecificValues.Tracer);
                            if (item_action == "MOVE")
                            {
                                CachedDataManager.Remove_User_Folder_Browse(RequestSpecificValues.Current_User.UserID, add_bookshelf, RequestSpecificValues.Tracer);
                                User_Folder moved_to_folder = RequestSpecificValues.Current_User.Get_Folder(add_bookshelf);
                                if (moved_to_folder != null)
                                {
                                    CachedDataManager.Clear_Public_Folder_Info(moved_to_folder.Folder_ID, RequestSpecificValues.Tracer);
                                }
                            }
                        }
                        else
                        {
                                string[] split = bookshelf_items.Split("_".ToCharArray());
                                if (split.Length == 2)
                                {
                                    SobekCM_Database.Delete_Item_From_User_Folder(RequestSpecificValues.Current_User.UserID, properFolderName, split[0], split[1], RequestSpecificValues.Tracer);
                                    if (item_action == "MOVE")
                                    {
                                        SobekCM_Database.Add_Item_To_User_Folder(RequestSpecificValues.Current_User.UserID, add_bookshelf, split[0], split[1], 1, String.Empty, RequestSpecificValues.Tracer);
                                    }
                                }

                            // Ensure this RequestSpecificValues.Current_User folder is not sitting in the cache
                            CachedDataManager.Remove_User_Folder_Browse(RequestSpecificValues.Current_User.UserID, properFolderName, RequestSpecificValues.Tracer);
                            CachedDataManager.Clear_Public_Folder_Info(current_folder_id, RequestSpecificValues.Tracer);
                            if (item_action == "MOVE")
                            {
                                CachedDataManager.Remove_User_Folder_Browse(RequestSpecificValues.Current_User.UserID, add_bookshelf, RequestSpecificValues.Tracer);
                                User_Folder moved_to_folder = RequestSpecificValues.Current_User.Get_Folder(add_bookshelf);
                                if (moved_to_folder != null)
                                {
                                    CachedDataManager.Clear_Public_Folder_Info(moved_to_folder.Folder_ID, RequestSpecificValues.Tracer);
                                }
                            }
                        }
                    }

                    if ( item_action == "EMAIL" )
                    {
                        string comments = form["email_comments"].Trim().Replace(">",")").Replace("<","(");
                        string email = form["email_address"].Trim();
                        string format = HttpContext.Current.Request.Form["email_format"].Trim().ToUpper();

                            string[] split = bookshelf_items.Split("_".ToCharArray());
                            if (split.Length == 2)
                            {
                                SobekCM_Assistant newAssistant = new SobekCM_Assistant();
                                SobekCM_Item newItem;
                                Page_TreeNode newPage;
                                SobekCM_Items_In_Title itemsInTitle;
                                newAssistant.Get_Item(RequestSpecificValues.Current_Mode, UI_ApplicationCache_Gateway.Items, UI_ApplicationCache_Gateway.Settings.Servers.Image_URL, null, RequestSpecificValues.Current_User, RequestSpecificValues.Tracer, out newItem, out newPage, out itemsInTitle );
                                SobekCM_Database.Add_Item_To_User_Folder(RequestSpecificValues.Current_User.UserID, add_bookshelf, split[0], split[1], 1, comments, RequestSpecificValues.Tracer);

                                // Determine the email format
                                bool is_html_format = (format != "TEXT");

                                // Send this email
                              //  Item_Email_Helper.Send_Email(email, String.Empty, comments, RequestSpecificValues.Current_User.Full_Name, RequestSpecificValues.Current_Mode.Instance_Abbreviation, newItem, is_html_format, RequestSpecificValues.Current_Mode.Base_URL + newItem.BibID + "/" + newItem.VID, RequestSpecificValues.Current_User.UserID);
                            }
                    }

                    if ( item_action == "EDIT_NOTES" )
                    {
                        string notes = form["add_notes"].Trim().Replace(">",")").Replace("<","(");

                            string[] split = bookshelf_items.Split("_".ToCharArray());
                            if (split.Length == 2)
                            {
                                SobekCM_Database.Add_Item_To_User_Folder(RequestSpecificValues.Current_User.UserID, add_bookshelf, split[0], split[1], 1, notes, RequestSpecificValues.Tracer);
                                CachedDataManager.Remove_User_Folder_Browse(RequestSpecificValues.Current_User.UserID, add_bookshelf, RequestSpecificValues.Tracer);
                            }

                    }
                }
                catch(Exception)
                {
                    // Catches any errors which may occur.  User will be sent back to the same URL,
                    // so any error that occurs should be obvious to the RequestSpecificValues.Current_User
                }

                string return_url = HttpContext.Current.Items["Original_URL"].ToString();
                HttpContext.Current.Response.Redirect(return_url, false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                RequestSpecificValues.Current_Mode.Request_Completed = true;
            }
        }
Esempio n. 5
0
        private DataSet Perform_Database_Search()
        {
            // Get the aggregation
            string code = Aggregation;

            if (Aggregation.Length == 0)
            {
                code = Institution;
            }

            // Build the search string and search fields string
            string        searchString      = First_Value + "|" + Second_Value + "|" + Third_Value + "|" + Fourth_Value;
            StringBuilder termStringBuilder = new StringBuilder();

            termStringBuilder.Append(term_to_code(First_Term) + "|");
            termStringBuilder.Append(join_to_symbol(First_Link) + term_to_code(Second_Term) + "|");
            termStringBuilder.Append(join_to_symbol(Second_Link) + term_to_code(Third_Term) + "|");
            termStringBuilder.Append(join_to_symbol(Third_Link) + term_to_code(Fourth_Term));
            string fieldString = termStringBuilder.ToString();


            List <string> terms      = new List <string>();
            List <string> web_fields = new List <string>();
            List <int>    db_fields  = new List <int>();
            List <int>    links      = new List <int>();

            // Split the terms correctly
            SobekCM_Assistant.Split_Clean_Search_Terms_Fields(searchString, fieldString, Search_Type_Enum.Advanced, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

            // Get the count that will be used
            int actualCount = Math.Min(terms.Count, web_fields.Count);

            // If there are no terms, return an empty item collection
            if (terms.Count == 0)
            {
                return(null);
            }

            // Special code for searching by bibid, oclc, or aleph
            if (actualCount == 1)
            {
                // Was this a OCLC search?
                if ((web_fields[0] == "OC") && (terms[0].Length > 0))
                {
                    bool is_number = terms[0].All(Char.IsNumber);

                    if (is_number)
                    {
                        long oclc = Convert.ToInt64(terms[0]);
                        return(SobekCM_Database.Tracking_Items_By_OCLC_Number(oclc, null));
                    }
                }

                // Was this a ALEPH search?
                if ((web_fields[0] == "AL") && (terms[0].Length > 0))
                {
                    bool is_number = terms[0].All(Char.IsNumber);

                    if (is_number)
                    {
                        int aleph = Convert.ToInt32(terms[0]);
                        return(SobekCM_Database.Tracking_Items_By_ALEPH_Number(aleph, null));
                    }
                }
            }

            // Step through all the web fields and convert to db fields
            for (int i = 0; i < actualCount; i++)
            {
                if (web_fields[i].Length > 1)
                {
                    // Find the joiner
                    if ((web_fields[i][0] == '+') || (web_fields[i][0] == '=') || (web_fields[i][0] == '-'))
                    {
                        if (i != 0)
                        {
                            if (web_fields[i][0] == '+')
                            {
                                links.Add(0);
                            }
                            if (web_fields[i][0] == '=')
                            {
                                links.Add(1);
                            }
                            if (web_fields[i][0] == '-')
                            {
                                links.Add(2);
                            }
                        }
                        web_fields[i] = web_fields[i].Substring(1);
                    }
                    else
                    {
                        if (i != 0)
                        {
                            links.Add(0);
                        }
                    }

                    // Find the db field number
                    //db_fields.Add( Settings.SMaRT_GlobalValues.Search_Fields.Metadata_Field_Number(web_fields[i]));
                }

                // Also add starting and ending quotes to all the valid searches
                if (terms[i].Length > 0)
                {
                    if ((terms[i].IndexOf("\"") < 0) && (terms[i].IndexOf(" ") < 0))
                    {
                        // Since this is a single word, see what type of special codes to include
                        switch (Search_Precision)
                        {
                        case Search_Precision_Type_Enum.Contains:
                            terms[i] = "\"" + terms[i] + "\"";
                            break;

                        case Search_Precision_Type_Enum.Inflectional_Form:
                            // If there are any non-characters, don't use inflectional for this term
                            bool inflectional = terms[i].All(Char.IsLetter);
                            if (inflectional)
                            {
                                terms[i] = "FORMSOF(inflectional," + terms[i] + ")";
                            }
                            else
                            {
                                terms[i] = "\"" + terms[i] + "\"";
                            }
                            break;

                        case Search_Precision_Type_Enum.Synonmic_Form:
                            terms[i] = "FORMSOF(thesaurus," + terms[i] + ")";
                            break;
                        }
                    }
                    else
                    {
                        if (Search_Precision != Search_Precision_Type_Enum.Exact_Match)
                        {
                            terms[i] = "\"" + terms[i] + "\"";
                        }
                    }
                }
            }

            // If this is an exact match, just do the search
            if (Search_Precision == Search_Precision_Type_Enum.Exact_Match)
            {
                return(SobekCM_Database.Tracking_Metadata_Exact_Search(terms[0], db_fields[0], code));
            }

            // Finish filling up the fields and links
            while (links.Count < 9)
            {
                links.Add(0);
            }
            while (db_fields.Count < 10)
            {
                db_fields.Add(-1);
            }
            while (terms.Count < 10)
            {
                terms.Add(String.Empty);
            }

            // See if this is a simple search, which can use a more optimized search routine
            bool simplified_search = db_fields.All(field => field <= 0);

            // Perform either the simpler metadata search, or the more complex
            if (simplified_search)
            {
                StringBuilder searchBuilder = new StringBuilder();
                for (int i = 0; i < terms.Count; i++)
                {
                    if (terms[i].Length > 0)
                    {
                        if (i > 0)
                        {
                            if (i > links.Count)
                            {
                                searchBuilder.Append(" AND ");
                            }
                            else
                            {
                                switch (links[i - 1])
                                {
                                case 0:
                                    searchBuilder.Append(" AND ");
                                    break;

                                case 1:
                                    searchBuilder.Append(" OR ");
                                    break;

                                case 2:
                                    searchBuilder.Append(" AND NOT ");
                                    break;
                                }
                            }
                        }

                        searchBuilder.Append(terms[i]);
                    }
                }

                return(SobekCM_Database.Tracking_Metadata_Search(searchBuilder.ToString(), code));
                // OLD CODE WHEN USING THE SIMPLE METADATA SEARCH WHICH INCLUDES THE SAME LINK TYPE
                //return Database.SobekCM_Database.Perform_Metadata_Search(terms[0], terms[1], terms[2], terms[3],
                //  terms[4], terms[5], terms[6], terms[7], terms[8], terms[9], main_link, include_private, Current_Mode.Aggregation, Tracer);
            }

            return(SobekCM_Database.Tracking_Metadata_Search(terms[0], db_fields[0], links[0], terms[1], db_fields[1], links[1], terms[2], db_fields[2], links[2], terms[3],
                                                             db_fields[3], links[3], terms[4], db_fields[4], links[4], terms[5], db_fields[5], links[5], terms[6], db_fields[6], links[6], terms[7], db_fields[7], links[7], terms[8], db_fields[8],
                                                             links[8], terms[9], db_fields[9], code));
        }
        /// <summary> Constructor creates a new instance of the Aggregation_HtmlSubwriter class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Aggregation_HtmlSubwriter(RequestCache RequestSpecificValues)
            : base(RequestSpecificValues)
        {
            // Get the item aggregation from the SobekCM engine endpoints
            // If the mode is NULL or the request was already completed, do nothing
            if ((RequestSpecificValues.Current_Mode == null) || (RequestSpecificValues.Current_Mode.Request_Completed))
                return;

            RequestSpecificValues.Tracer.Add_Trace("Aggregation_HtmlSubwriter.Constructor", "Retrieving collection");

            // Check that the current aggregation code is valid
            if (!UI_ApplicationCache_Gateway.Aggregations.isValidCode(RequestSpecificValues.Current_Mode.Aggregation))
            {
                // Is there a "forward value"
                if (UI_ApplicationCache_Gateway.Collection_Aliases.ContainsKey(RequestSpecificValues.Current_Mode.Aggregation))
                {
                    RequestSpecificValues.Current_Mode.Aggregation = UI_ApplicationCache_Gateway.Collection_Aliases[RequestSpecificValues.Current_Mode.Aggregation];
                }
            }

            // Use the method in the base class to actually pull the entire hierarchy
            if (!Get_Collection(RequestSpecificValues.Current_Mode, RequestSpecificValues.Tracer, out hierarchyObject))
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Error;
                return;
            }

            //// Check if a differente skin should be used if this is a collection display
            //string current_skin_code = RequestSpecificValues.Current_Mode.Skin.ToUpper();
            //if ((hierarchyObject != null) && (hierarchyObject.Web_Skins != null) && (hierarchyObject.Web_Skins.Count > 0))
            //{
            //    // Do NOT do this replacement if the web skin is in the URL and this is admin mode
            //    if ((!RequestSpecificValues.Current_Mode.Skin_In_URL) || (RequestSpecificValues.Current_Mode.Mode != Display_Mode_Enum.Administrative))
            //    {
            //        if (!hierarchyObject.Web_Skins.Contains(current_skin_code.ToLower()))
            //        {
            //            RequestSpecificValues.Current_Mode.Skin = hierarchyObject.Web_Skins[0];
            //        }
            //    }
            //}

            // Run the browse/info work if it is of those modes
            if (((RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Browse_Info) || (RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Child_Page_Edit)))
            {
                RequestSpecificValues.Tracer.Add_Trace("SobekCM_Page_Globals.Browse_Info_Block", "Retrieiving Browse/Info Object");

                // If this is a robot, then get the text from the static page
                if ((RequestSpecificValues.Current_Mode.Is_Robot) && (RequestSpecificValues.Current_Mode.Info_Browse_Mode == "all"))
                {
                    SobekCM_Assistant assistant = new SobekCM_Assistant();
                    browse_info_display_text = assistant.Get_All_Browse_Static_HTML(RequestSpecificValues.Current_Mode, RequestSpecificValues.Tracer);
                    RequestSpecificValues.Current_Mode.Writer_Type = Writer_Type_Enum.HTML_Echo;
                }
                else
                {
                    if (!Get_Browse_Info(RequestSpecificValues.Current_Mode, hierarchyObject, UI_ApplicationCache_Gateway.Settings.Servers.Base_Directory, RequestSpecificValues.Tracer, out thisBrowseObject, out datasetBrowseResultsStats, out pagedResults, out staticBrowse))
                    {
                        RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Home;
                        //RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Error;
                    }
                }
            }

            // Set some basic values
            leftButtons = String.Empty;
            rightButtons = String.Empty;
            children_icons_added = false;

            // Check to see if the user should be able to edit the home page
            if ((RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Aggregation) && (RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Home_Edit))
            {
                if ( RequestSpecificValues.Current_User == null )
                    RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Home;
                else
                {
                    if ((!RequestSpecificValues.Current_User.Is_System_Admin) && (!RequestSpecificValues.Current_User.Is_Portal_Admin) && (!RequestSpecificValues.Current_User.Is_Aggregation_Admin(hierarchyObject.Code)))
                    {
                        RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Home;
                    }
                }
            }
            else if ( RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Home_Edit )
                RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Home;

            #region Handle post backs from the mySobek sharing, emailin, etc.. buttons

            NameValueCollection form = HttpContext.Current.Request.Form;
            if ( form["item_action"] != null)
            {
                string action = form["item_action"].ToLower().Trim();

                if ((action == "add_aggregation") && ( RequestSpecificValues.Current_User != null ))
                {
                    SobekCM_Database.User_Set_Aggregation_Home_Page_Flag(RequestSpecificValues.Current_User.UserID, hierarchyObject.ID, true, RequestSpecificValues.Tracer);
                    RequestSpecificValues.Current_User.Set_Aggregation_Home_Page_Flag(hierarchyObject.Code, hierarchyObject.Name, true);
                    HttpContext.Current.Session.Add("ON_LOAD_MESSAGE", "Added aggregation to your home page");
                }

                if (( action == "remove_aggregation") && ( RequestSpecificValues.Current_User != null ))
                {
                    int removeAggregationID = hierarchyObject.ID;
                    string remove_code = hierarchyObject.Code;
                    string remove_name = hierarchyObject.Name;

                    if ((form["aggregation"] != null) && (form["aggregation"].Length > 0))
                    {
                        Item_Aggregation_Related_Aggregations aggrInfo = UI_ApplicationCache_Gateway.Aggregations[form["aggregation"]];
                        if (aggrInfo != null)
                        {
                            remove_code = aggrInfo.Code;
                            removeAggregationID = aggrInfo.ID;
                        }
                    }

                    SobekCM_Database.User_Set_Aggregation_Home_Page_Flag(RequestSpecificValues.Current_User.UserID, removeAggregationID, false, RequestSpecificValues.Tracer);
                    RequestSpecificValues.Current_User.Set_Aggregation_Home_Page_Flag(remove_code, remove_name, false);

                    if (RequestSpecificValues.Current_Mode.Home_Type != Home_Type_Enum.Personalized)
                    {
                        HttpContext.Current.Session.Add("ON_LOAD_MESSAGE", "Removed aggregation from your home page");
                    }
                }

                if ((action == "private_folder") && ( RequestSpecificValues.Current_User != null ))
                {
                    User_Folder thisFolder = RequestSpecificValues.Current_User.Get_Folder(form["aggregation"]);
                    if (SobekCM_Database.Edit_User_Folder(thisFolder.Folder_ID, RequestSpecificValues.Current_User.UserID, -1, thisFolder.Folder_Name, false, String.Empty, RequestSpecificValues.Tracer) >= 0)
                        thisFolder.IsPublic = false;
                }

                if ((action == "email") && ( RequestSpecificValues.Current_User != null ))
                {
                    string address = form["email_address"].Replace(";", ",").Trim();
                    string comments = form["email_comments"].Trim();
                    string format = form["email_format"].Trim().ToUpper();

                    if (address.Length > 0)
                    {
                        // Determine the email format
                        bool is_html_format = format != "TEXT";

                        // CC: the user, unless they are already on the list
                        string cc_list = RequestSpecificValues.Current_User.Email;
                        if (address.ToUpper().IndexOf(RequestSpecificValues.Current_User.Email.ToUpper()) >= 0)
                            cc_list = String.Empty;

                        // Send the email
                        string any_error = URL_Email_Helper.Send_Email(address, cc_list, comments, RequestSpecificValues.Current_User.Full_Name, RequestSpecificValues.Current_Mode.Instance_Abbreviation, is_html_format, HttpContext.Current.Items["Original_URL"].ToString(), hierarchyObject.Name, "Collection", RequestSpecificValues.Current_User.UserID);
                        HttpContext.Current.Session.Add("ON_LOAD_MESSAGE", any_error.Length > 0 ? any_error : "Your email has been sent");

                        RequestSpecificValues.Current_Mode.isPostBack = true;

                        // Do this to force a return trip (cirumnavigate cacheing)
                        string original_url = HttpContext.Current.Items["Original_URL"].ToString();
                        if (original_url.IndexOf("?") < 0)
                            HttpContext.Current.Response.Redirect(original_url + "?p=" + DateTime.Now.Millisecond, false);
                        else
                            HttpContext.Current.Response.Redirect(original_url + "&p=" + DateTime.Now.Millisecond, false);

                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        RequestSpecificValues.Current_Mode.Request_Completed = true;
                        return;
                    }
                }
            }
            #endregion

            #region Handle post backs from editing the home page text

            if (( RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Home_Edit ) && ( form["sbkAghsw_HomeTextEdit"] != null))
            {
                string aggregation_folder = UI_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "aggregations\\" + hierarchyObject.Code + "\\";
                if (!Directory.Exists(aggregation_folder))
                    Directory.CreateDirectory(aggregation_folder);

                string file = hierarchyObject.HomePageHtml.Source;

                // Make a backup from today, if none made yet
                if (File.Exists(file))
                {
                    DateTime lastWrite = (new FileInfo(file)).LastWriteTime;
                    string new_file = file.ToLower().Replace(".txt", "").Replace(".html", "").Replace(".htm", "") + lastWrite.Year + lastWrite.Month.ToString().PadLeft(2, '0') + lastWrite.Day.ToString() .PadLeft(2, '0')+ ".bak";
                    if (File.Exists(new_file))
                        File.Delete(new_file);
                    File.Move(file, new_file);
                }
                else
                {
                    // Ensure the folder exists
                    string directory = Path.GetDirectoryName(file);
                    if (!Directory.Exists(directory))
                        Directory.CreateDirectory(directory);
                }

                // Write to the file now
                StreamWriter homeWriter = new StreamWriter(file, false);
                homeWriter.WriteLine(form["sbkAghsw_HomeTextEdit"].Replace("%]", "%>").Replace("[%", "<%"));
                homeWriter.Flush();
                homeWriter.Close();

                // Also save this change
                SobekCM_Database.Save_Item_Aggregation_Milestone(hierarchyObject.Code, "Home page edited (" + Web_Language_Enum_Converter.Enum_To_Name(RequestSpecificValues.Current_Mode.Language) + ")", RequestSpecificValues.Current_User.Full_Name);

                // Clear this aggreation from the cache
                CachedDataManager.Aggregations.Remove_Item_Aggregation(hierarchyObject.Code, RequestSpecificValues.Tracer);

                // If this is all, save the new text as well
                if (String.Compare("all", hierarchyObject.Code, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    string home_app_key = "SobekCM_Home_" + RequestSpecificValues.Current_Mode.Language_Code;
                    HttpContext.Current.Application[home_app_key] = form["sbkAghsw_HomeTextEdit"].Replace("%]", "%>").Replace("[%", "<%");
                }

                // Forward along
                RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Home;
                string redirect_url = UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode);
                if (redirect_url.IndexOf("?") > 0)
                    redirect_url = redirect_url + "&refresh=always";
                else
                    redirect_url = redirect_url + "?refresh=always";
                RequestSpecificValues.Current_Mode.Request_Completed = true;
                HttpContext.Current.Response.Redirect(redirect_url, false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();

                return;
            }

            #endregion

            // If this is a search, verify it is a valid search type
            if (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Search)
            {
                // Not every collection has every search type...
                ReadOnlyCollection<Search_Type_Enum> possibleSearches = hierarchyObject.Search_Types;
                if (!possibleSearches.Contains(RequestSpecificValues.Current_Mode.Search_Type))
                {
                    bool found_valid = false;

                    if ((RequestSpecificValues.Current_Mode.Search_Type == Search_Type_Enum.Full_Text) && (possibleSearches.Contains(Search_Type_Enum.dLOC_Full_Text)))
                    {
                        found_valid = true;
                        RequestSpecificValues.Current_Mode.Search_Type = Search_Type_Enum.dLOC_Full_Text;
                    }

                    if ((!found_valid) && (RequestSpecificValues.Current_Mode.Search_Type == Search_Type_Enum.Basic) && (possibleSearches.Contains(Search_Type_Enum.Newspaper)))
                    {
                        found_valid = true;
                        RequestSpecificValues.Current_Mode.Search_Type = Search_Type_Enum.Newspaper;
                    }

                    if (( !found_valid ) && ( possibleSearches.Count > 0 ))
                    {
                        found_valid = true;
                        RequestSpecificValues.Current_Mode.Search_Type = possibleSearches[0];
                    }

                    if ( !found_valid )
                    {
                        RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Aggregation;
                        RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Home;
                    }
                }
            }

            #region Create the new subviewer to handle this request

            // First, create the aggregation view bag
            AggregationViewBag viewBag = new AggregationViewBag(hierarchyObject, datasetBrowseResultsStats, pagedResults, thisBrowseObject, staticBrowse);

            if (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Search)
            {
                collectionViewer = AggregationViewer_Factory.Get_Viewer(RequestSpecificValues.Current_Mode.Search_Type, RequestSpecificValues, viewBag);
            }

            if (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Aggregation)
            {
                switch (RequestSpecificValues.Current_Mode.Aggregation_Type)
                {
                    case Aggregation_Type_Enum.Home:
                    case Aggregation_Type_Enum.Home_Edit:
                        if (!hierarchyObject.Custom_Home_Page)
                        {
                            // Are there tiles here?
                            string aggregation_tile_directory = Path.Combine(UI_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, hierarchyObject.ObjDirectory, "images", "tiles");
                            if (Directory.Exists(aggregation_tile_directory))
                            {
                                string[] jpeg_tiles = Directory.GetFiles(aggregation_tile_directory, "*.jpg");
                                if (jpeg_tiles.Length > 0)
                                    collectionViewer = new Tiles_Home_AggregationViewer(RequestSpecificValues, viewBag);
                            }

                            // If the tiles home page as not built, build the standard viewer
                            if ( collectionViewer == null )
                                collectionViewer = AggregationViewer_Factory.Get_Viewer(hierarchyObject.Views_And_Searches[0], RequestSpecificValues, viewBag);
                        }
                        else
                        {
                            collectionViewer = new Custom_Home_Page_AggregationViewer(RequestSpecificValues, viewBag);
                        }
                        break;

                    case Aggregation_Type_Enum.Browse_Info:
                        if (datasetBrowseResultsStats == null)
                        {
                            collectionViewer = new Static_Browse_Info_AggregationViewer(RequestSpecificValues, viewBag);
                        }
                        else
                        {
                            collectionViewer = new DataSet_Browse_Info_AggregationViewer(RequestSpecificValues, viewBag);
                        }
                        break;

                    case Aggregation_Type_Enum.Child_Page_Edit:
                        collectionViewer = new Static_Browse_Info_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Browse_By:
                        collectionViewer = new Metadata_Browse_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Browse_Map:
                        collectionViewer = new Map_Browse_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Browse_Map_Beta:
                        collectionViewer = new Map_Browse_AggregationViewer_Beta(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Item_Count:
                        collectionViewer = new Item_Count_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Usage_Statistics:
                        collectionViewer = new Usage_Statistics_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Private_Items:
                        collectionViewer = new Private_Items_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Manage_Menu:
                        collectionViewer = new Manage_Menu_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.User_Permissions:
                        collectionViewer = new User_Permissions_AggregationViewer(RequestSpecificValues, viewBag);
                        break;

                    case Aggregation_Type_Enum.Work_History:
                        collectionViewer = new Work_History_AggregationViewer(RequestSpecificValues, viewBag);
                        break;
                }
            }

            // If execution should end, do it now
            if (RequestSpecificValues.Current_Mode.Request_Completed)
                return;

            if (collectionViewer != null)
            {
                // Pull the standard values
                switch (collectionViewer.Selection_Panel_Display)
                {
                    case Selection_Panel_Display_Enum.Selectable:
                        if (form["show_subaggrs"] != null)
                        {
                            string show_subaggrs = form["show_subaggrs"].ToUpper();
                            if (show_subaggrs == "TRUE")
                                RequestSpecificValues.Current_Mode.Show_Selection_Panel = true;
                        }
                        break;

                    case Selection_Panel_Display_Enum.Always:
                        RequestSpecificValues.Current_Mode.Show_Selection_Panel = true;
                        break;
                }

                behaviors = collectionViewer.AggregationViewer_Behaviors;
            }
            else
            {
                behaviors = emptybehaviors;
            }

            #endregion
        }
        /// <summary> Constructor for a new instance of the Folder_Mgmt_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Results_Statistics"> Information about the entire set of results for the current folder </param>
        /// <param name="Paged_Results"> Single page of results for the current folder, within the entire set </param>
        /// <param name="Code_Manager"> Code manager object maintains mapping between SobekCM codes and greenstone codes (used by result_dataset_html_subwriter)</param>
        /// <param name="Item_List"> Object for pulling additional information about each item during display </param>
        /// <param name="currentCollection"> Current item aggregation [UNUSED?] </param>
        /// <param name="htmlSkin"> HTML interface, which determines the header, footer, stylesheet, and other design elements for the rendered HTML</param>
        /// <param name="Translator"> Translation / language support object for writing the user interface is multiple languages</param>
        /// <param name="currentMode"> Mode / navigation information for the current request</param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Folder_Mgmt_MySobekViewer(User_Object User,
            Search_Results_Statistics Results_Statistics,
            List<iSearch_Title_Result> Paged_Results,
            Aggregation_Code_Manager Code_Manager,
            Item_Lookup_Object Item_List,
            Item_Aggregation currentCollection, 
            SobekCM_Skin_Object htmlSkin,
            Language_Support_Info Translator, 
            SobekCM_Navigation_Object currentMode,
            Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Folder_Mgmt_MySobekViewer.Constructor", String.Empty);

            user = User;
            pagedResults = Paged_Results;
            resultsStatistics = Results_Statistics;
            codeManager = Code_Manager;
            itemList = Item_List;
            this.htmlSkin = htmlSkin;
            base.Translator = Translator;
            this.currentCollection = currentCollection;

            properFolderName = String.Empty;
            int current_folder_id = -1;
            if (currentMode.My_Sobek_SubMode.Length > 0)
            {
                // Try to get this user folder from the user object
                User_Folder userFolder = user.Get_Folder( currentMode.My_Sobek_SubMode );

                // If the user folder is null, then this folder is not in the current user object
                // This may still be a valid folder though.  Check this by pulling folder list for this
                // user again
                if (userFolder == null)
                {
                    // Get the user from the database again
                    User_Object checkFolderUser = SobekCM_Database.Get_User(user.UserID, Tracer);

                    // Look for this folder in the new user object
                    userFolder = checkFolderUser.Get_Folder(currentMode.My_Sobek_SubMode);
                    if (userFolder == null)
                    {
                        // Invalid folder.. should not have gotten this far though
                        HttpContext.Current.Response.Redirect(currentMode.Base_URL);
                    }
                    else
                    {
                        // Save this to the user so this does not have to happen again
                        user.Add_Folder(userFolder);
                    }
                }

                // Get the proper name and folder id
                Debug.Assert(userFolder != null, "userFolder != null");
                properFolderName = userFolder.Folder_Name;
                current_folder_id = userFolder.Folder_ID;
            }

            if ((currentMode.isPostBack) || ((HttpContext.Current.Request.Form["item_action"] != null) && (HttpContext.Current.Request.Form["item_action"].Length > 0 )))
            {
                try
                {
                    // Pull the standard values
                    NameValueCollection form = HttpContext.Current.Request.Form;

                    string item_action = form["item_action"].Replace(",","").ToUpper().Trim();
                    string bookshelf_items = form["bookshelf_items"].Trim().Replace("%22", "\"").Replace("%27", "'").Replace("%3D", "=").Replace("%26", "&");
                    string bookshelf_params = form["bookshelf_params"].Trim();
                    string add_bookshelf = String.Empty;
                    if ( form["add_bookshelf"] != null )
                        add_bookshelf = form["add_bookshelf"].Trim();

                    if (item_action == "REFRESH_FOLDER")
                    {
                         refresh_user_folders(user, Tracer);
                         Cached_Data_Manager.Remove_All_User_Folder_Browses(user.UserID, Tracer);
                    }

                    if (item_action == "DELETE_FOLDER")
                    {
                        int folder_id = Convert.ToInt32(bookshelf_items);

                        SobekCM_Database.Delete_User_Folder(user.UserID, folder_id, Tracer);
                        Cached_Data_Manager.Clear_Public_Folder_Info(folder_id, Tracer);
                        refresh_user_folders(user, Tracer);
                    }

                    if (item_action == "NEW_BOOKSHELF")
                    {
                        string folder_name = form["new_bookshelf_name"].Trim().Replace("<", "(").Replace(">", ")");
                        int parent_id = Convert.ToInt32(form["new_bookshelf_parent"]);

                        if (SobekCM_Database.Edit_User_Folder(-1, user.UserID, parent_id, folder_name, false, String.Empty, Tracer) > 0)
                        {
                            refresh_user_folders(user, Tracer);
                        }
                    }

                    if ( item_action == "FOLDER_VISIBILITY" )
                    {
                        User_Folder thisFolder = user.Get_Folder(bookshelf_items);
                        if (bookshelf_params.ToUpper() == "PRIVATE")
                        {
                            if (SobekCM_Database.Edit_User_Folder(thisFolder.Folder_ID, user.UserID, -1, thisFolder.Folder_Name, false, String.Empty, Tracer) >= 0)
                                thisFolder.isPublic = false;

                            Cached_Data_Manager.Clear_Public_Folder_Info(thisFolder.Folder_ID, Tracer);
                        }

                        if (bookshelf_params.ToUpper() == "PUBLIC")
                        {
                            if (SobekCM_Database.Edit_User_Folder(thisFolder.Folder_ID, user.UserID, -1, thisFolder.Folder_Name, true, String.Empty, Tracer) >= 0 )
                                thisFolder.isPublic = true;
                        }
                    }

                    if ((item_action == "REMOVE") || ( item_action == "MOVE" ))
                    {
                        if (bookshelf_items.IndexOf("|") > 0)
                        {
                            string[] split_multi_items = bookshelf_items.Split("|".ToCharArray());
                            foreach (string[] split in split_multi_items.Select(thisItem => thisItem.Split("_".ToCharArray())).Where(split => split.Length == 2))
                            {
                                SobekCM_Database.Delete_Item_From_User_Folder(user.UserID, properFolderName, split[0], split[1], Tracer);
                                if (item_action == "MOVE")
                                {
                                    SobekCM_Database.Add_Item_To_User_Folder(user.UserID, add_bookshelf, split[0], split[1], 0, String.Empty, Tracer);
                                }
                            }

                            // Ensure this user folder is not sitting in the cache
                            Cached_Data_Manager.Remove_User_Folder_Browse(user.UserID, properFolderName, Tracer);
                            Cached_Data_Manager.Clear_Public_Folder_Info(current_folder_id, Tracer);
                            if (item_action == "MOVE")
                            {
                                Cached_Data_Manager.Remove_User_Folder_Browse(user.UserID, add_bookshelf, Tracer);
                                User_Folder moved_to_folder = user.Get_Folder(add_bookshelf);
                                if (moved_to_folder != null)
                                {
                                    Cached_Data_Manager.Clear_Public_Folder_Info(moved_to_folder.Folder_ID, Tracer);
                                }
                            }
                        }
                        else
                        {
                                string[] split = bookshelf_items.Split("_".ToCharArray());
                                if (split.Length == 2)
                                {
                                    SobekCM_Database.Delete_Item_From_User_Folder(user.UserID, properFolderName, split[0], split[1], Tracer);
                                    if (item_action == "MOVE")
                                    {
                                        SobekCM_Database.Add_Item_To_User_Folder(user.UserID, add_bookshelf, split[0], split[1], 1, String.Empty, Tracer);
                                    }
                                }

                            // Ensure this user folder is not sitting in the cache
                            Cached_Data_Manager.Remove_User_Folder_Browse(user.UserID, properFolderName, Tracer);
                            Cached_Data_Manager.Clear_Public_Folder_Info(current_folder_id, Tracer);
                            if (item_action == "MOVE")
                            {
                                Cached_Data_Manager.Remove_User_Folder_Browse(user.UserID, add_bookshelf, Tracer);
                                User_Folder moved_to_folder = user.Get_Folder(add_bookshelf);
                                if (moved_to_folder != null)
                                {
                                    Cached_Data_Manager.Clear_Public_Folder_Info(moved_to_folder.Folder_ID, Tracer);
                                }
                            }
                        }
                    }

                    if ( item_action == "EMAIL" )
                    {
                        string comments = form["email_comments"].Trim().Replace(">",")").Replace("<","(");
                        string email = form["email_address"].Trim();
                        string format = HttpContext.Current.Request.Form["email_format"].Trim().ToUpper();

                            string[] split = bookshelf_items.Split("_".ToCharArray());
                            if (split.Length == 2)
                            {
                                SobekCM_Assistant newAssistant = new SobekCM_Assistant();
                                SobekCM_Item newItem;
                                Page_TreeNode newPage;
                                SobekCM_Items_In_Title itemsInTitle;
                                newAssistant.Get_Item(currentMode, Item_List, SobekCM_Library_Settings.Image_URL, null, user, Tracer, out newItem, out newPage, out itemsInTitle );
                                SobekCM_Database.Add_Item_To_User_Folder(user.UserID, add_bookshelf, split[0], split[1], 1, comments, Tracer);

                                // Determine the email format
                                bool is_html_format = (format != "TEXT");

                                // Send this email
                                Item_Email_Helper.Send_Email(email, String.Empty, comments, user.Full_Name, currentMode.SobekCM_Instance_Abbreviation, newItem, is_html_format, currentMode.Base_URL + newItem.BibID + "/" + newItem.VID);
                            }
                    }

                    if ( item_action == "EDIT_NOTES" )
                    {
                        string notes = form["add_notes"].Trim().Replace(">",")").Replace("<","(");

                            string[] split = bookshelf_items.Split("_".ToCharArray());
                            if (split.Length == 2)
                            {
                                SobekCM_Database.Add_Item_To_User_Folder(user.UserID, add_bookshelf, split[0], split[1], 1, notes, Tracer);
                                Cached_Data_Manager.Remove_User_Folder_Browse(user.UserID, add_bookshelf, Tracer);
                            }

                    }
                }
                catch(Exception)
                {
                    // Catches any errors which may occur.  User will be sent back to the same URL,
                    // so any error that occurs should be obvious to the user
                }

                string return_url = HttpContext.Current.Items["Original_URL"].ToString();
                HttpContext.Current.Response.Redirect(return_url, false);

            }
        }
Esempio n. 8
0
        /// <summary> Constructor for a new instance of the Html_MainWriter class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Html_MainWriter(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            // Add a trace
            RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", "");

            // Check the IE hack CSS is loaded
            if (HttpContext.Current.Application["NonIE_Hack_CSS"] == null)
            {
                string css_file = HttpContext.Current.Server.MapPath("default/SobekCM_NonIE.css");
                if (File.Exists(css_file))
                {
                    try
                    {
                        StreamReader reader = new StreamReader(css_file);
                        HttpContext.Current.Application["NonIE_Hack_CSS"] = reader.ReadToEnd().Trim();
                        reader.Close();
                    }
                    catch (Exception)
                    {
                        HttpContext.Current.Application["NonIE_Hack_CSS"] = "/* ERROR READING FILE: default/SobekCM_NonIE.css */";
                        throw;
                    }
                }
                else
                {
                    HttpContext.Current.Application["NonIE_Hack_CSS"] = String.Empty;
                }
            }

            // Handle basic events which may be fired by the internal header
            if (HttpContext.Current.Request.Form["internal_header_action"] != null)
            {
                // Pull the action value
                string internalHeaderAction = HttpContext.Current.Request.Form["internal_header_action"].Trim();

                // Was this to hide or show the header?
                if ((internalHeaderAction == "hide") || (internalHeaderAction == "show"))
                {
                    // Pull the current visibility from the session
                    bool shown = !((HttpContext.Current.Session["internal_header"] != null) && (HttpContext.Current.Session["internal_header"].ToString() == "hidden"));
                    if ((internalHeaderAction == "hide") && (shown))
                    {
                        HttpContext.Current.Session["internal_header"] = "hidden";
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                        return;
                    }
                    if ((internalHeaderAction == "show") && (!shown))
                    {
                        HttpContext.Current.Session["internal_header"] = "shown";
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                        return;
                    }
                }
            }

            try
            {
                // Create the html sub writer now
                switch (RequestSpecificValues.Current_Mode.Mode)
                {
                case Display_Mode_Enum.Internal:
                    subwriter = new Internal_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Statistics:
                    subwriter = new Statistics_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Preferences:
                    subwriter = new Preferences_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Empty:
                    subwriter = new Empty_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Error:
                    subwriter = new Error_HtmlSubwriter(false, RequestSpecificValues);
                    // Send the email now
                    if (RequestSpecificValues.Current_Mode.Caught_Exception != null)
                    {
                        if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Error_Message))
                        {
                            RequestSpecificValues.Current_Mode.Error_Message = "Unknown exception caught";
                        }
                        Email_Information(RequestSpecificValues.Current_Mode.Error_Message, RequestSpecificValues.Current_Mode.Caught_Exception, RequestSpecificValues.Tracer, false);
                    }
                    break;

                case Display_Mode_Enum.Legacy_URL:
                    subwriter = new LegacyUrl_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Item_Print:
                    subwriter = new Print_Item_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Contact:
                    StringBuilder builder = new StringBuilder();
                    builder.Append("\n\nSUBMISSION INFORMATION\n");
                    builder.Append("\tDate:\t\t\t\t" + DateTime.Now.ToString() + "\n");
                    string lastMode = String.Empty;
                    try
                    {
                        if (HttpContext.Current.Session["Last_Mode"] != null)
                        {
                            lastMode = HttpContext.Current.Session["Last_Mode"].ToString();
                        }
                        builder.Append("\tIP Address:\t\t\t" + HttpContext.Current.Request.UserHostAddress + "\n");
                        builder.Append("\tHost Name:\t\t\t" + HttpContext.Current.Request.UserHostName + "\n");
                        builder.Append("\tBrowser:\t\t\t" + HttpContext.Current.Request.Browser.Browser + "\n");
                        builder.Append("\tBrowser Platform:\t\t" + HttpContext.Current.Request.Browser.Platform + "\n");
                        builder.Append("\tBrowser Version:\t\t" + HttpContext.Current.Request.Browser.Version + "\n");
                        builder.Append("\tBrowser Language:\t\t");
                        bool     first     = true;
                        string[] languages = HttpContext.Current.Request.UserLanguages;
                        if (languages != null)
                        {
                            foreach (string thisLanguage in languages)
                            {
                                if (first)
                                {
                                    builder.Append(thisLanguage);
                                    first = false;
                                }
                                else
                                {
                                    builder.Append(", " + thisLanguage);
                                }
                            }
                        }

                        builder.Append("\n\nHISTORY\n");
                        if (HttpContext.Current.Session["LastSearch"] != null)
                        {
                            builder.Append("\tLast Search:\t\t" + HttpContext.Current.Session["LastSearch"] + "\n");
                        }
                        if (HttpContext.Current.Session["LastResults"] != null)
                        {
                            builder.Append("\tLast Results:\t\t" + HttpContext.Current.Session["LastResults"] + "\n");
                        }
                        if (HttpContext.Current.Session["Last_Mode"] != null)
                        {
                            builder.Append("\tLast Mode:\t\t\t" + HttpContext.Current.Session["Last_Mode"] + "\n");
                        }
                        builder.Append("\tURL:\t\t\t\t" + HttpContext.Current.Items["Original_URL"]);
                    }
                    catch
                    {
                    }
                    subwriter = new Contact_HtmlSubwriter(lastMode, builder.ToString(), RequestSpecificValues);
                    break;


                case Display_Mode_Enum.Contact_Sent:
                    subwriter = new Contact_HtmlSubwriter(String.Empty, String.Empty, RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Simple_HTML_CMS:
                    subwriter = new Web_Content_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.My_Sobek:
                    subwriter = new MySobek_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Administrative:
                    subwriter = new Admin_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Results:
                    subwriter = new Search_Results_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Public_Folder:
                    subwriter = new Public_Folder_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Search:
                case Display_Mode_Enum.Aggregation:
                    subwriter = new Aggregation_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Item_Display:
                    if ((!RequestSpecificValues.Current_Mode.Invalid_Item.HasValue || !RequestSpecificValues.Current_Mode.Invalid_Item.Value))
                    {
                        // Create the item viewer writer
                        subwriter = new Item_HtmlSubwriter(RequestSpecificValues);
                    }
                    else
                    {
                        // Create the invalid item html subwrite and write the HTML
                        subwriter = new Error_HtmlSubwriter(true, RequestSpecificValues);
                    }
                    break;
                }

                // Might be redirected
                if (RequestSpecificValues.Current_Mode.Request_Completed)
                {
                    return;
                }

                // Now, look for error or the web content, which is also often
                // used for resource missing type errors
                switch (RequestSpecificValues.Current_Mode.Mode)
                {
                case Display_Mode_Enum.Error:
                    subwriter = new Error_HtmlSubwriter(false, RequestSpecificValues);
                    // Send the email now
                    if (RequestSpecificValues.Current_Mode.Caught_Exception != null)
                    {
                        if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Error_Message))
                        {
                            RequestSpecificValues.Current_Mode.Error_Message = "Unknown exception caught";
                        }
                        Email_Information(RequestSpecificValues.Current_Mode.Error_Message, RequestSpecificValues.Current_Mode.Caught_Exception, RequestSpecificValues.Tracer, false);
                    }
                    break;

                case Display_Mode_Enum.Simple_HTML_CMS:
                    subwriter = new Web_Content_HtmlSubwriter(RequestSpecificValues);
                    break;
                }

                // Now, pull the web skin
                SobekCM_Assistant assistant = new SobekCM_Assistant();

                // Try to get the web skin from the cache or skin collection, otherwise build it
                Web_Skin_Object htmlSkin = assistant.Get_HTML_Skin(RequestSpecificValues.Current_Mode.Skin, RequestSpecificValues.Current_Mode, UI_ApplicationCache_Gateway.Web_Skin_Collection, true, RequestSpecificValues.Tracer);

                // If the skin was somehow overriden, default back to the default skin
                string defaultSkin = RequestSpecificValues.Current_Mode.Base_Skin;
                if ((htmlSkin == null) && (!String.IsNullOrEmpty(defaultSkin)))
                {
                    if (String.Compare(RequestSpecificValues.Current_Mode.Skin, defaultSkin, StringComparison.InvariantCultureIgnoreCase) != 0)
                    {
                        RequestSpecificValues.Current_Mode.Skin = defaultSkin;
                        htmlSkin = assistant.Get_HTML_Skin(defaultSkin, RequestSpecificValues.Current_Mode, UI_ApplicationCache_Gateway.Web_Skin_Collection, true, RequestSpecificValues.Tracer);
                    }
                }

                // If there was no web skin returned, forward user to URL with no web skin.
                // This happens if the web skin code is invalid.  If a robot, just return a bad request
                // value though.
                if (htmlSkin == null)
                {
                    HttpContext.Current.Response.StatusCode = 404;
                    HttpContext.Current.Response.Output.WriteLine("404 - INVALID URL");
                    HttpContext.Current.Response.Output.WriteLine("Web skin indicated is invalid, default web skin invalid - line 1029");
                    HttpContext.Current.Response.Output.WriteLine(RequestSpecificValues.Tracer.Text_Trace);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    RequestSpecificValues.Current_Mode.Request_Completed = true;

                    return;
                }

                RequestSpecificValues.HTML_Skin = htmlSkin;
            }
            catch (Exception ee)
            {
                // Send to the dashboard
                if ((HttpContext.Current.Request.UserHostAddress == "127.0.0.1") || (HttpContext.Current.Request.UserHostAddress == HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]) || (HttpContext.Current.Request.Url.ToString().IndexOf("localhost") >= 0))
                {
                    RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", "Exception caught!", Custom_Trace_Type_Enum.Error);
                    RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", ee.Message, Custom_Trace_Type_Enum.Error);
                    RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", ee.StackTrace, Custom_Trace_Type_Enum.Error);

                    // Wrap this into the SobekCM Exception
                    SobekCM_Traced_Exception newException = new SobekCM_Traced_Exception("Exception caught while building the mode-specific HTML Subwriter", ee, RequestSpecificValues.Tracer);

                    // Save this to the session state, and then forward to the dashboard
                    HttpContext.Current.Session["Last_Exception"] = newException;
                    HttpContext.Current.Response.Redirect("dashboard.aspx", false);
                    RequestSpecificValues.Current_Mode.Request_Completed = true;
                }
                else
                {
                    subwriter = new Error_HtmlSubwriter(false, RequestSpecificValues);
                }
            }
        }