/// <summary> Constructor for a new instance of the Edit_Item_Metadata_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="All_Items_Lookup"> Allows individual items to be retrieved by various methods as <see cref="Single_Item"/> objects.</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
        /// <param name="Icon_Table"> Dictionary of all the wordmark/icons which can be tagged to the items </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Edit_Item_Metadata_MySobekViewer(User_Object User,
                                                SobekCM_Navigation_Object Current_Mode,
                                                Item_Lookup_Object All_Items_Lookup,
                                                SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager,
                                                Dictionary <string, Wordmark_Icon> Icon_Table,
                                                SobekCM_Skin_Object HTML_Skin,
                                                Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", String.Empty);

            currentMode    = Current_Mode;
            item           = Current_Item;
            itemList       = All_Items_Lookup;
            codeManager    = Code_Manager;
            iconList       = Icon_Table;
            webSkin        = HTML_Skin;
            popUpFormsHtml = String.Empty;


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

            // Is this a project
            isProject = false;
            if (item.Bib_Info.SobekCM_Type == TypeOfResource_SobekCM_Enum.Project)
            {
                isProject = true;
            }

            string template_code = user.Edit_Template_Code;

            if ((isProject) || (item.Contains_Complex_Content) || (item.Using_Complex_Template))
            {
                template_code = user.Edit_Template_MARC_Code;
            }
            template = Cached_Data_Manager.Retrieve_Template(template_code, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\" + template_code + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(template_code, template, Tracer);
            }

            // Get the current page number, or default to 1
            page = 1;
            if (currentMode.My_Sobek_SubMode.Length > 0)
            {
                if ((currentMode.My_Sobek_SubMode == "preview") || (currentMode.My_Sobek_SubMode == "marc") || (currentMode.My_Sobek_SubMode == "mets"))
                {
                    page = 0;
                }
                else
                {
                    page = 1;
                    bool isNumber = currentMode.My_Sobek_SubMode.All(Char.IsNumber);
                    if (isNumber)
                    {
                        if (isProject)
                        {
                            Double.TryParse(currentMode.My_Sobek_SubMode[0].ToString(), out page);
                        }
                        else
                        {
                            Double.TryParse(currentMode.My_Sobek_SubMode, out page);
                        }
                    }
                    else if (isProject)
                    {
                        if (Char.IsNumber(currentMode.My_Sobek_SubMode[0]))
                        {
                            Double.TryParse(currentMode.My_Sobek_SubMode[0].ToString(), out page);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary> Constructor for a new instance of the Mass_Update_Items_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Mass_Update_Items_MySobekViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer) : base(User)
        {
            Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", String.Empty);
            currentMode = Current_Mode;

            // Since this is a mass update, just create a new empty item with the GroupID included
            // from the provided item
            SobekCM_Item emptyItem = new SobekCM_Item {
                BibID = Current_Item.BibID
            };

            emptyItem.Web.GroupID          = Current_Item.Web.GroupID;
            emptyItem.Bib_Info.Source.Code = String.Empty;
            emptyItem.Behaviors.CheckOut_Required_Is_Null         = true;
            emptyItem.Behaviors.IP_Restriction_Membership_Is_Null = true;
            emptyItem.Behaviors.Dark_Flag_Is_Null = true;
            item = emptyItem;

            // If the user cannot edit this item, go back
            if (!user.Can_Edit_This_Item(Current_Item))
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                currentMode.Redirect();
                return;
            }

            const string TEMPLATE_CODE = "massupdate";

            template = Cached_Data_Manager.Retrieve_Template(TEMPLATE_CODE, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\defaults\\" + TEMPLATE_CODE + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(TEMPLATE_CODE, template, Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["behaviors_request"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                currentMode.Redirect();
            }
            else if (hidden_request == "save")
            {
                // Save these changes to bib
                template.Save_To_Bib(item, user, 1);

                // Save the behaviors
                SobekCM_Database.Save_Behaviors(item, false, true);

                // Store on the caches (to replace the other)
                Cached_Data_Manager.Remove_Digital_Resource_Objects(item.BibID, Tracer);

                // Forward
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                currentMode.Redirect();
            }
        }
        /// <summary> Constructor for a new instance of the Edit_Item_Metadata_MySobekViewer class </summary>
        /// <param name="DefaultMetadata"> Default metadata object, if that is how this is being used </param>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Edit_Item_Metadata_MySobekViewer(SobekCM_Item DefaultMetadata, RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", String.Empty);

            popUpFormsHtml = String.Empty;
            delayed_popup  = String.Empty;

            // If no user then that is an error
            if ((RequestSpecificValues.Current_User == null) || (!RequestSpecificValues.Current_User.LoggedOn))
            {
                RequestSpecificValues.Current_Mode.Mode        = Display_Mode_Enum.Aggregation;
                RequestSpecificValues.Current_Mode.Aggregation = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // If the default metadata was provided, use that
            if (DefaultMetadata != null)
            {
                currentItem = DefaultMetadata;
            }
            else
            {
                // Ensure BibID and VID provided
                RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Validate provided bibid / vid");
                if ((String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID)) || (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.VID)))
                {
                    RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "BibID or VID was not provided!");
                    RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                    RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : BibID/VID missing in item metadata edit request";
                    return;
                }

                RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Try to pull this sobek complete item");
                currentItem = SobekEngineClient.Items.Get_Sobek_Item(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Current_Mode.VID, RequestSpecificValues.Current_User.UserID, RequestSpecificValues.Tracer);
                if (currentItem == null)
                {
                    RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Unable to build complete item");
                    RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                    RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : Unable to build complete item";
                    return;
                }
            }

            // If the RequestSpecificValues.Current_User cannot edit this item, go back
            if (!RequestSpecificValues.Current_User.Can_Edit_This_Item(currentItem.BibID, currentItem.Bib_Info.SobekCM_Type_String, currentItem.Bib_Info.Source.Code, currentItem.Bib_Info.HoldingCode, currentItem.Behaviors.Aggregation_Code_List))
            {
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                HttpContext.Current.Response.Redirect(UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode));
            }

            // Is this a project
            isProject = currentItem.Bib_Info.SobekCM_Type == TypeOfResource_SobekCM_Enum.Project;

            string template_code = RequestSpecificValues.Current_User.Edit_Template_Code_Simple;

            if ((currentItem.Contains_Complex_Content) || (currentItem.Using_Complex_Template))
            {
                template_code = RequestSpecificValues.Current_User.Edit_Template_Code_Complex;
            }
            if (isProject)
            {
                template_code    = "standard_project";
                completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(template_code, RequestSpecificValues.Tracer);
                if (completeTemplate != null)
                {
                    RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Found project-specific template in cache");
                }
                else
                {
                    RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Reading project-specific template file");

                    // Look in the user-defined portion
                    string user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\project.xml";
                    if (!File.Exists(user_template))
                    {
                        user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\project.xml";
                    }

                    // Read this CompleteTemplate
                    Template_XML_Reader reader = new Template_XML_Reader();
                    completeTemplate = new CompleteTemplate();
                    reader.Read_XML(user_template, completeTemplate, true);

                    // Save this into the cache
                    Template_MemoryMgmt_Utility.Store_Template(template_code, completeTemplate, RequestSpecificValues.Tracer);
                }
            }
            else
            {
                completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(template_code, RequestSpecificValues.Tracer);
                if (completeTemplate != null)
                {
                    RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Found template in cache");
                }
                else
                {
                    RequestSpecificValues.Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Reading template file");

                    // Look in the user-defined portion
                    string user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\edit\\" + template_code + ".xml";
                    if (!File.Exists(user_template))
                    {
                        user_template = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\edit\\" + template_code + ".xml";
                    }

                    // Read this CompleteTemplate
                    Template_XML_Reader reader = new Template_XML_Reader();
                    completeTemplate = new CompleteTemplate();
                    reader.Read_XML(user_template, completeTemplate, true);
                    if (completeTemplate != null)
                    {
                        completeTemplate.Build_Final_Adjustment_And_Checks();
                    }

                    // Save this into the cache
                    Template_MemoryMgmt_Utility.Store_Template(template_code, completeTemplate, RequestSpecificValues.Tracer);
                }
            }

            // Get the current page number, or default to 1
            page = 1;
            if (!String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.My_Sobek_SubMode))
            {
                if ((RequestSpecificValues.Current_Mode.My_Sobek_SubMode == "preview") || (RequestSpecificValues.Current_Mode.My_Sobek_SubMode == "marc") || (RequestSpecificValues.Current_Mode.My_Sobek_SubMode == "mets"))
                {
                    page = 0;
                }
                else
                {
                    page = 1;
                    bool isNumber = RequestSpecificValues.Current_Mode.My_Sobek_SubMode.All(Char.IsNumber);
                    if (isNumber)
                    {
                        if (isProject)
                        {
                            Double.TryParse(RequestSpecificValues.Current_Mode.My_Sobek_SubMode[0].ToString(), out page);
                        }
                        else
                        {
                            Double.TryParse(RequestSpecificValues.Current_Mode.My_Sobek_SubMode, out page);
                        }
                    }
                    else if (isProject)
                    {
                        if (Char.IsNumber(RequestSpecificValues.Current_Mode.My_Sobek_SubMode[0]))
                        {
                            Double.TryParse(RequestSpecificValues.Current_Mode.My_Sobek_SubMode[0].ToString(), out page);
                        }
                    }
                }
            }

            // Handle post backs
            if (RequestSpecificValues.Current_Mode.isPostBack)
            {
                // See if there was a hidden request
                string hidden_request = HttpContext.Current.Request.Form["new_element_requested"] ?? String.Empty;

                // If this was a cancel request do that
                if (hidden_request == "cancel")
                {
                    if (isProject)
                    {
                        CachedDataManager.Remove_Project(RequestSpecificValues.Current_User.UserID, currentItem.BibID, null);

                        RequestSpecificValues.Current_Mode.Mode             = Display_Mode_Enum.Administrative;
                        RequestSpecificValues.Current_Mode.Admin_Type       = Admin_Type_Enum.Default_Metadata;
                        RequestSpecificValues.Current_Mode.My_Sobek_SubMode = String.Empty;
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                    }
                    else
                    {
                        CachedDataManager.Items.Remove_Digital_Resource_Object(RequestSpecificValues.Current_User.UserID, currentItem.BibID, currentItem.VID, null);

                        // Also clear the engine
                        SobekEngineClient.Items.Clear_Item_Cache(currentItem.BibID, currentItem.VID, RequestSpecificValues.Tracer);

                        RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                    }
                    return;
                }


                // Save these changes to bib
                completeTemplate.Save_To_Bib(currentItem, RequestSpecificValues.Current_User, ((int)page));

                // See if the RequestSpecificValues.Current_User asked for a new element of a complex form type
                delayed_popup = String.Empty;
                switch (hidden_request.Trim())
                {
                case "name":
                    delayed_popup = "name";
                    currentItem.Bib_Info.Add_Named_Entity(String.Empty).Name_Type = Name_Info_Type_Enum.Personal;
                    break;

                case "title":
                    delayed_popup = "title";
                    currentItem.Bib_Info.Add_Other_Title(String.Empty, Title_Type_Enum.Alternative);
                    break;

                case "subject":
                    delayed_popup = "subject";
                    currentItem.Bib_Info.Add_Subject();
                    break;

                case "spatial":
                    delayed_popup = "spatial";
                    currentItem.Bib_Info.Add_Hierarchical_Geographic_Subject();
                    break;

                case "relateditem":
                    delayed_popup = "relateditem";
                    currentItem.Bib_Info.Add_Related_Item(new Related_Item_Info());
                    break;

                case "save":
                    Complete_Item_Save();
                    break;

                case "complicate":
                    currentItem.Using_Complex_Template = true;
                    HttpContext.Current.Response.Redirect("?" + HttpContext.Current.Request.QueryString, false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    RequestSpecificValues.Current_Mode.Request_Completed = true;
                    return;

                case "simplify":
                    currentItem.Using_Complex_Template = false;
                    HttpContext.Current.Response.Redirect("?" + HttpContext.Current.Request.QueryString, false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    RequestSpecificValues.Current_Mode.Request_Completed = true;
                    return;
                }

                // Was this for a new page?
                if (hidden_request.IndexOf("newpage") == 0)
                {
                    string page_requested = hidden_request.Replace("newpage", "");
                    if (page_requested != RequestSpecificValues.Current_Mode.My_Sobek_SubMode)
                    {
                        // forward to requested page
                        RequestSpecificValues.Current_Mode.My_Sobek_SubMode = page_requested;
                        if (RequestSpecificValues.Current_Mode.My_Sobek_SubMode == "0")
                        {
                            RequestSpecificValues.Current_Mode.My_Sobek_SubMode = "preview";
                        }
                        if (isProject)
                        {
                            RequestSpecificValues.Current_Mode.My_Sobek_SubMode = page_requested + currentItem.BibID;
                        }

                        HttpContext.Current.Response.Redirect(UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode) + "#CompleteTemplate", false);
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        RequestSpecificValues.Current_Mode.Request_Completed = true;
                    }
                }
            }
        }
        /// <summary> Constructor for a new instance of the Edit_Group_Behaviors_MySobekViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Edit_Group_Behaviors_MySobekViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", String.Empty);

            // If no user then that is an error
            if ((RequestSpecificValues.Current_User == null) || (!RequestSpecificValues.Current_User.LoggedOn))
            {
                RequestSpecificValues.Current_Mode.Mode        = Display_Mode_Enum.Aggregation;
                RequestSpecificValues.Current_Mode.Aggregation = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Ensure BibID provided
            RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Validate provided bibid");
            if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID))
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "BibID was not provided!");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : BibID missing in item group metadata edit request";
                return;
            }

            RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Try to pull this sobek complete item group");
            currentItem = SobekEngineClient.Items.Get_Sobek_Item_Group(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Tracer);
            if (currentItem == null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Unable to build complete item group");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : Unable to build complete item";
                return;
            }

            // If the RequestSpecificValues.Current_User cannot edit this currentItem, go back
            if (!RequestSpecificValues.Current_User.Can_Edit_This_Item(currentItem.BibID, currentItem.Bib_Info.SobekCM_Type_String, currentItem.Bib_Info.Source.Code, currentItem.Bib_Info.HoldingCode, currentItem.Behaviors.Aggregation_Code_List))
            {
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            const string TEMPLATE_CODE = "groupbehaviors";

            completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(TEMPLATE_CODE, RequestSpecificValues.Tracer);
            if (completeTemplate != null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Found CompleteTemplate in cache");
            }
            else
            {
                RequestSpecificValues.Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Reading CompleteTemplate file");

                // Read this CompleteTemplate
                Template_XML_Reader reader = new Template_XML_Reader();
                completeTemplate = new CompleteTemplate();
                if (File.Exists(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\" + TEMPLATE_CODE + ".xml"))
                {
                    reader.Read_XML(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\user\\standard\\" + TEMPLATE_CODE + ".xml", completeTemplate, true);
                }
                else
                {
                    reader.Read_XML(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\" + TEMPLATE_CODE + ".xml", completeTemplate, true);
                }

                // Save this into the cache
                Template_MemoryMgmt_Utility.Store_Template(TEMPLATE_CODE, completeTemplate, RequestSpecificValues.Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["behaviors_request"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
            else if (hidden_request == "save")
            {
                // Save these changes to bib
                completeTemplate.Save_To_Bib(currentItem, RequestSpecificValues.Current_User, 1);

                // Save the group title
                SobekCM_Item_Database.Update_Item_Group(currentItem.BibID, currentItem.Behaviors.GroupTitle, currentItem.Bib_Info.SortSafeTitle(currentItem.Behaviors.GroupTitle, true), String.Empty, currentItem.Behaviors.Primary_Identifier.Type, currentItem.Behaviors.Primary_Identifier.Identifier);

                // Save the interfaces to the group currentItem as well
                SobekCM_Item_Database.Save_Item_Group_Web_Skins(currentItem.Web.GroupID, currentItem);

                // Store on the caches (to replace the other)
                CachedDataManager.Items.Remove_Digital_Resource_Objects(currentItem.BibID, RequestSpecificValues.Tracer);

                // Also remove the list of volumes, since this may have changed
                CachedDataManager.Items.Remove_Items_In_Title(currentItem.BibID, RequestSpecificValues.Tracer);

                // Also clear the engine
                SobekEngineClient.Items.Clear_Item_Group_Cache(currentItem.BibID, RequestSpecificValues.Tracer);


                // Forward
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
        }
Ejemplo n.º 5
0
        /// <summary> Constructor for a new instance of the Edit_Item_Metadata_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="All_Items_Lookup"> Allows individual items to be retrieved by various methods as <see cref="Single_Item"/> objects.</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
        /// <param name="Icon_Table"> Dictionary of all the wordmark/icons which can be tagged to the items </param>
        /// <param name="HTML_Skin_Collection"> HTML Web skin collection which controls the overall appearance of this digital library </param>
        /// <param name="Translator"> Language support object which handles simple translational duties </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Edit_Item_Metadata_MySobekViewer(User_Object User,
                                                SobekCM_Navigation_Object Current_Mode,
                                                Item_Lookup_Object All_Items_Lookup,
                                                SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager,
                                                Dictionary <string, Wordmark_Icon> Icon_Table,
                                                SobekCM_Skin_Object HTML_Skin,
                                                Language_Support_Info Translator,
                                                SobekCM_Skin_Collection HTML_Skin_Collection,
                                                Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", String.Empty);

            currentMode     = Current_Mode;
            item            = Current_Item;
            itemList        = All_Items_Lookup;
            codeManager     = Code_Manager;
            iconList        = Icon_Table;
            webSkin         = HTML_Skin;
            popUpFormsHtml  = String.Empty;
            delayed_popup   = String.Empty;
            base.Translator = Translator;
            skins           = HTML_Skin_Collection;



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

            // Is this a project
            isProject = item.Bib_Info.SobekCM_Type == TypeOfResource_SobekCM_Enum.Project;

            string template_code = user.Edit_Template_Code;

            if ((isProject) || (item.Contains_Complex_Content) || (item.Using_Complex_Template))
            {
                template_code = user.Edit_Template_MARC_Code;
            }
            template = Cached_Data_Manager.Retrieve_Template(template_code, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\edit\\" + template_code + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(template_code, template, Tracer);
            }

            // Get the current page number, or default to 1
            page = 1;
            if (currentMode.My_Sobek_SubMode.Length > 0)
            {
                if ((currentMode.My_Sobek_SubMode == "preview") || (currentMode.My_Sobek_SubMode == "marc") || (currentMode.My_Sobek_SubMode == "mets"))
                {
                    page = 0;
                }
                else
                {
                    page = 1;
                    bool isNumber = currentMode.My_Sobek_SubMode.All(Char.IsNumber);
                    if (isNumber)
                    {
                        if (isProject)
                        {
                            Double.TryParse(currentMode.My_Sobek_SubMode[0].ToString(), out page);
                        }
                        else
                        {
                            Double.TryParse(currentMode.My_Sobek_SubMode, out page);
                        }
                    }
                    else if (isProject)
                    {
                        if (Char.IsNumber(currentMode.My_Sobek_SubMode[0]))
                        {
                            Double.TryParse(currentMode.My_Sobek_SubMode[0].ToString(), out page);
                        }
                    }
                }
            }

            // Handle post backs
            if (Current_Mode.isPostBack)
            {
                // See if there was a hidden request
                string hidden_request = HttpContext.Current.Request.Form["new_element_requested"] ?? String.Empty;

                // If this was a cancel request do that
                if (hidden_request == "cancel")
                {
                    if (isProject)
                    {
                        Cached_Data_Manager.Remove_Project(user.UserID, item.BibID, null);

                        currentMode.Mode             = Display_Mode_Enum.Administrative;
                        currentMode.Admin_Type       = Admin_Type_Enum.Default_Metadata;
                        currentMode.My_Sobek_SubMode = String.Empty;
                        currentMode.Redirect();
                    }
                    else
                    {
                        Cached_Data_Manager.Remove_Digital_Resource_Object(user.UserID, item.BibID, item.VID, null);

                        currentMode.Mode = Display_Mode_Enum.Item_Display;
                        currentMode.Redirect();
                    }
                    return;
                }


                // Save these changes to bib
                template.Save_To_Bib(item, user, ((int)page));

                // See if the user asked for a new element of a complex form type
                delayed_popup = String.Empty;
                switch (hidden_request.Trim())
                {
                case "name":
                    delayed_popup = "name";
                    item.Bib_Info.Add_Named_Entity(String.Empty).Name_Type = Name_Info_Type_Enum.personal;
                    break;

                case "title":
                    delayed_popup = "title";
                    item.Bib_Info.Add_Other_Title(String.Empty, Title_Type_Enum.alternative);
                    break;

                case "subject":
                    delayed_popup = "subject";
                    item.Bib_Info.Add_Subject();
                    break;

                case "spatial":
                    delayed_popup = "spatial";
                    item.Bib_Info.Add_Hierarchical_Geographic_Subject();
                    break;

                case "relateditem":
                    delayed_popup = "relateditem";
                    item.Bib_Info.Add_Related_Item(new Related_Item_Info());
                    break;

                case "save":
                    Complete_Item_Save();
                    break;

                case "complicate":
                    item.Using_Complex_Template = true;
                    HttpContext.Current.Response.Redirect("?" + HttpContext.Current.Request.QueryString, false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    currentMode.Request_Completed = true;
                    return;

                case "simplify":
                    item.Using_Complex_Template = false;
                    HttpContext.Current.Response.Redirect("?" + HttpContext.Current.Request.QueryString, false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    currentMode.Request_Completed = true;
                    return;
                }

                // Was this for a new page?
                if (hidden_request.IndexOf("newpage") == 0)
                {
                    string page_requested = hidden_request.Replace("newpage", "");
                    if (page_requested != currentMode.My_Sobek_SubMode)
                    {
                        // forward to requested page
                        currentMode.My_Sobek_SubMode = page_requested;
                        if (currentMode.My_Sobek_SubMode == "0")
                        {
                            currentMode.My_Sobek_SubMode = "preview";
                        }
                        if (isProject)
                        {
                            currentMode.My_Sobek_SubMode = page_requested + item.BibID;
                        }

                        HttpContext.Current.Response.Redirect(currentMode.Redirect_URL() + "#template", false);
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        currentMode.Request_Completed = true;
                    }
                }
            }
        }
        /// <summary> Constructor for a new instance of the Edit_Item_Behaviors_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Edit_Item_Behaviors_MySobekViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer) : base(User)
        {
            Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", String.Empty);

            currentMode = Current_Mode;
            item        = Current_Item;

            // If the user cannot edit this item, go back
            if (!user.Can_Edit_This_Item(item))
            {
                currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                currentMode.Redirect();
                return;
            }

            const string TEMPLATE_CODE = "itembehaviors";

            template = Cached_Data_Manager.Retrieve_Template(TEMPLATE_CODE, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Edit_Item_Behaviors_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\defaults\\" + TEMPLATE_CODE + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(TEMPLATE_CODE, template, Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["behaviors_request"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                currentMode.Redirect();
            }
            else if (hidden_request == "save")
            {
                // Changes to the tracking box require the metadata search citation be rebuilt for this item
                // so save the old tracking box information first
                string oldTrackingBox = item.Tracking.Tracking_Box;

                // Save these changes to bib
                template.Save_To_Bib(item, user, 1);

                // Save the behaviors
                SobekCM_Database.Save_Behaviors(item, item.Behaviors.Text_Searchable, false);

                // Save the serial hierarchy as well (sort of a behavior)
                SobekCM_Database.Save_Serial_Hierarchy_Information(item, item.Web.GroupID, item.Web.ItemID);

                // Did the tracking box change?
                if (item.Tracking.Tracking_Box != oldTrackingBox)
                {
                    SobekCM_Database.Create_Full_Citation_Value(item.Web.ItemID);
                }

                // Remoe from the caches (to replace the other)
                Cached_Data_Manager.Remove_Digital_Resource_Object(item.BibID, item.VID, Tracer);

                // Also remove the list of volumes, since this may have changed
                Cached_Data_Manager.Remove_Items_In_Title(item.BibID, Tracer);

                // Forward
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                currentMode.Redirect();
            }
        }
        /// <summary> Constructor for a new instance of the Mass_Update_Items_MySobekViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Mass_Update_Items_MySobekViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", String.Empty);

            // If no user then that is an error
            if ((RequestSpecificValues.Current_User == null) || (!RequestSpecificValues.Current_User.LoggedOn))
            {
                RequestSpecificValues.Current_Mode.Mode        = Display_Mode_Enum.Aggregation;
                RequestSpecificValues.Current_Mode.Aggregation = String.Empty;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Ensure BibID provided
            RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Validate provided bibid");
            if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.BibID))
            {
                RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "BibID was not provided!");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : BibID missing in item group metadata edit request";
                return;
            }

            RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Try to pull this sobek complete item group");
            SobekCM_Item currentItem = SobekEngineClient.Items.Get_Sobek_Item_Group(RequestSpecificValues.Current_Mode.BibID, RequestSpecificValues.Tracer);

            if (currentItem == null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Group_Add_Volume_MySobekViewer.Constructor", "Unable to build complete item group");
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.Error;
                RequestSpecificValues.Current_Mode.Error_Message = "Invalid Request : Unable to build complete item";
                return;
            }

            // Since this is a mass update, just create a new empty item with the GroupID included
            // from the provided item
            SobekCM_Item emptyItem = new SobekCM_Item {
                BibID = currentItem.BibID
            };

            emptyItem.Web.GroupID          = currentItem.Web.GroupID;
            emptyItem.Bib_Info.Source.Code = String.Empty;
            emptyItem.Behaviors.CheckOut_Required_Is_Null         = true;
            emptyItem.Behaviors.IP_Restriction_Membership_Is_Null = true;
            emptyItem.Behaviors.Dark_Flag_Is_Null = true;
            item = emptyItem;

            // If the user cannot edit this item, go back
            if (!RequestSpecificValues.Current_User.Can_Edit_This_Item(currentItem.BibID, currentItem.Bib_Info.SobekCM_Type_String, currentItem.Bib_Info.Source.Code, currentItem.Bib_Info.HoldingCode, currentItem.Behaviors.Aggregation_Code_List))
            {
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            const string TEMPLATE_CODE = "massupdate";

            completeTemplate = Template_MemoryMgmt_Utility.Retrieve_Template(TEMPLATE_CODE, RequestSpecificValues.Tracer);
            if (completeTemplate != null)
            {
                RequestSpecificValues.Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Found CompleteTemplate in cache");
            }
            else
            {
                RequestSpecificValues.Tracer.Add_Trace("Mass_Update_Items_MySobekViewer.Constructor", "Reading CompleteTemplate file");

                // Read this CompleteTemplate
                Template_XML_Reader reader = new Template_XML_Reader();
                completeTemplate = new CompleteTemplate();
                reader.Read_XML(UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "templates\\default\\standard\\" + TEMPLATE_CODE + ".xml", completeTemplate, true);

                // Save this into the cache
                Template_MemoryMgmt_Utility.Store_Template(TEMPLATE_CODE, completeTemplate, RequestSpecificValues.Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["behaviors_request"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
            else if (hidden_request == "save")
            {
                // Save these changes to bib
                completeTemplate.Save_To_Bib(item, RequestSpecificValues.Current_User, 1);

                // Save the behaviors
                SobekCM_Item_Database.Save_Behaviors(item, false, true, false);

                // Store on the caches (to replace the other)
                CachedDataManager.Items.Remove_Digital_Resource_Objects(item.BibID, RequestSpecificValues.Tracer);

                // Forward
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Item_Display;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
            }
        }
        /// <summary> Constructor for a new instance of the Edit_Group_Behaviors_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_Item"> Individual digital resource to be edited by the user </param>
        /// <param name="Code_Manager"> Code manager contains the list of all valid aggregation codes </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Edit_Group_Behaviors_MySobekViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, SobekCM_Item Current_Item, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer) : base(User)
        {
            Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", String.Empty);

            currentMode = Current_Mode;
            item        = Current_Item;


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

            const string templateCode = "groupbehaviors";

            template = Cached_Data_Manager.Retrieve_Template(templateCode, Tracer);
            if (template != null)
            {
                Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Found template in cache");
            }
            else
            {
                Tracer.Add_Trace("Edit_Group_Behaviors_MySobekViewer.Constructor", "Reading template file");

                // Read this template
                Template_XML_Reader reader = new Template_XML_Reader();
                template = new Template();
                reader.Read_XML(SobekCM_Library_Settings.Base_MySobek_Directory + "templates\\defaults\\" + templateCode + ".xml", template, true);

                // Add the current codes to this template
                template.Add_Codes(Code_Manager);

                // Save this into the cache
                Cached_Data_Manager.Store_Template(templateCode, template, Tracer);
            }

            // See if there was a hidden request
            string hidden_request = HttpContext.Current.Request.Form["behaviors_request"] ?? String.Empty;

            // If this was a cancel request do that
            if (hidden_request == "cancel")
            {
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }
            else if (hidden_request == "save")
            {
                // Save these changes to bib
                template.Save_To_Bib(item, user, 1);

                // Save the group title
                SobekCM_Database.Update_Item_Group(item.BibID, item.Behaviors.GroupTitle, item.Bib_Info.sortSafeTitle(item.Behaviors.GroupTitle, true), String.Empty, item.Behaviors.Primary_Identifier.Type, item.Behaviors.Primary_Identifier.Identifier);

                // Save the interfaces to the group item as well
                SobekCM_Database.Save_Item_Group_Web_Skins(item.Web.GroupID, item);

                // Store on the caches (to replace the other)
                Cached_Data_Manager.Remove_Digital_Resource_Objects(item.BibID, Tracer);

                // Forward
                currentMode.Mode = Display_Mode_Enum.Item_Display;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }
        }