/// <summary> Constructor for a new instance of the Skins_AdminViewer class </summary> /// <param name="User"> Authenticated user information </param> /// <param name="currentMode"> Mode / navigation information for the current request</param> /// <param name="Web_Skin_Collection"> Contains the collection of all the default skins and the data to create any additional skins on request</param> /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param> /// <remarks> Postback from handling an edit or new html skin is handled here in the constructor </remarks> public Skins_AdminViewer(User_Object User, SobekCM_Navigation_Object currentMode, SobekCM_Skin_Collection Web_Skin_Collection, Custom_Tracer Tracer) : base(User) { Tracer.Add_Trace("Skins_AdminViewer.Constructor", String.Empty); // Save the mode and settings here base.currentMode = currentMode; skinCollection = Web_Skin_Collection; // Set action message to nothing to start actionMessage = String.Empty; // If the user cannot edit this, go back if ((!user.Is_System_Admin) && (!user.Is_Portal_Admin)) { currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home; HttpContext.Current.Response.Redirect(currentMode.Redirect_URL()); } // If this is a postback, handle any events first if (currentMode.isPostBack) { try { // Pull the standard values NameValueCollection form = HttpContext.Current.Request.Form; string reset_value = form["admin_interface_reset"].ToLower(); string save_value = form["admin_interface_tosave"].ToUpper().Trim(); string new_interface_code = form["admin_interface_code"].ToUpper().Trim(); // Was this a reset request? if (reset_value.Length > 0) { Tracer.Add_Trace("Skins_AdminViewer.Constructor", "Reset html skin '" + reset_value + "'"); if (Web_Skin_Collection.Remove(reset_value)) { actionMessage = "Removed skin <i>" + reset_value.ToUpper() + "</i> from the semi-permanent skin collection"; } else { int values_cleared = Cached_Data_Manager.Remove_Skin(reset_value, Tracer); if (values_cleared == 0) { actionMessage = "Html skin <i>" + reset_value.ToUpper() + "</i> was not in the application cache"; } else { actionMessage = "Removed " + values_cleared + " values from the cache for <i>" + reset_value.ToUpper() + "</i>"; } } } else { // Or.. was this a save request if (save_value.Length > 0) { Tracer.Add_Trace("Skins_AdminViewer.Constructor", "Save html skin '" + save_value + "'"); bool override_banner = false; bool override_header = false; bool build_on_launch = false; bool suppress_top_nav = false; bool copycurrent = false; object temp_object; // Was this to save a new interface (from the main page) or edit an existing (from the popup form)? if (save_value == new_interface_code) { string new_base_code = form["admin_interface_basecode"].ToUpper().Trim(); string new_banner_link = form["admin_interface_link"].Trim(); string new_notes = form["admin_interface_notes"].Trim(); temp_object = form["admin_interface_banner_override"]; if (temp_object != null) { override_banner = true; } temp_object = form["admin_interface_header_override"]; if (temp_object != null) { override_header = true; } temp_object = form["admin_interface_buildlaunch"]; if (temp_object != null) { build_on_launch = true; } temp_object = form["admin_interface_top_nav"]; if (temp_object != null) { suppress_top_nav = true; } temp_object = form["admin_interface_copycurrent"]; if (temp_object != null) { copycurrent = true; } // Save this new interface if (SobekCM_Database.Save_Web_Skin(save_value, new_base_code, override_banner, override_header, new_banner_link, new_notes, build_on_launch, suppress_top_nav, Tracer)) { // Ensure a folder exists for this, otherwise create one try { string folder = SobekCM_Library_Settings.Base_Design_Location + "skins/" + save_value.ToLower(); if (!Directory.Exists(folder)) { // Create this directory and the necessary subdirectories Directory.CreateDirectory(folder); // Create a default stylesheet StreamWriter writer = new StreamWriter(folder + "\\" + save_value.ToLower() + ".css"); writer.WriteLine("/* Skin-specific stylesheet used to override values from the base stylesheets */"); writer.WriteLine(); writer.WriteLine(); writer.Flush(); writer.Close(); // Create the html subdirectory Directory.CreateDirectory(folder + "/html"); // Do the rest differently depending on whether we should copy the current files if (!copycurrent) { // Write the default header file writer = new StreamWriter(folder + "\\html\\header.html"); writer.WriteLine("<div id=\"container-inner\">"); writer.WriteLine(); writer.WriteLine("<!-- Add the standard header buttons -->"); writer.WriteLine("<div style=\"width: 100%; background-color: #eeeeee; color: Black; height:30px;\">"); writer.WriteLine("<%BREADCRUMBS%>"); writer.WriteLine("<div style=\"float: right\"><%MYSOBEK%></div>"); writer.WriteLine("</div>"); writer.WriteLine(); writer.WriteLine("<%BANNER%>"); writer.WriteLine(); writer.WriteLine("<div id=\"pagecontainer\">"); writer.WriteLine(); writer.WriteLine("<!-- Blankets out the rest of the web form when a pop-up form is envoked -->"); writer.WriteLine("<div id=\"blanket_outer\" style=\"display:none;\"></div>"); writer.Flush(); writer.Close(); // Write the default header_item file writer = new StreamWriter(folder + "/html/header_item.html"); writer.WriteLine("<!-- Blankets out the rest of the web form when a pop-up form is envoked -->"); writer.WriteLine("<div id=\"blanket_outer\" style=\"display:none;\"></div>"); writer.WriteLine(); writer.WriteLine("<!-- Add the standard header buttons -->"); writer.WriteLine("<div style=\"width: 100%; background-color: #eeeeee; color: Black; height:30px;\">"); writer.WriteLine("<%BREADCRUMBS%>"); writer.WriteLine("<div style=\"float: right\"><%MYSOBEK%></div>"); writer.WriteLine("</div>"); writer.WriteLine(); writer.WriteLine("<%BANNER%>"); writer.Flush(); writer.Close(); // Write the default footer file writer = new StreamWriter(folder + "/html/footer.html"); writer.WriteLine("</div> <!-- END PAGE CONTAINER DIV -->"); writer.WriteLine(); writer.WriteLine("<!-- Add most the standard footer buttons -->"); writer.WriteLine("<center>"); writer.WriteLine("<a href=\"<%BASEURL%>contact<%?URLOPTS%>\">Contact Us</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>preferences<%?URLOPTS%>\">Preferences</a> | "); writer.WriteLine("<a href=\"http://ufdc.ufl.edu/sobekcm\">Technical Aspects</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>stats<%?URLOPTS%>\">Statistics</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>internal<%?URLOPTS%>\">Internal</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>admin<%?URLOPTS%>\">Admin</a>"); writer.WriteLine("</center>"); writer.WriteLine("<br />"); writer.WriteLine("<br />"); writer.WriteLine("<span style=\"color: Gray; font-size: 0.8em;\">"); writer.WriteLine("To edit this footer or header, edit header.html or footer.html at: " + folder + "\\html\\ <br />"); writer.WriteLine("</span>"); writer.WriteLine(); writer.WriteLine("</div> <!-- END CONTAINER INNER -->"); writer.Flush(); writer.Close(); // Write the default footer item file writer = new StreamWriter(folder + "/html/footer_item.html"); writer.WriteLine("<!-- Add most the standard footer buttons -->"); writer.WriteLine("<center>"); writer.WriteLine("<a href=\"<%BASEURL%>contact<%?URLOPTS%>\">Contact Us</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>preferences<%?URLOPTS%>\">Preferences</a> | "); writer.WriteLine("<a href=\"http://ufdc.ufl.edu/sobekcm\">Technical Aspects</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>stats<%?URLOPTS%>\">Statistics</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>internal<%?URLOPTS%>\">Internal</a> | "); writer.WriteLine("<a href=\"<%BASEURL%>admin<%?URLOPTS%>\">Admin</a>"); writer.WriteLine("</center>"); writer.WriteLine("<br />"); writer.WriteLine("<br />"); writer.WriteLine("<span style=\"color: Gray; font-size: 0.8em;\">"); writer.WriteLine("To edit this footer or header, edit header.html or footer.html at: " + folder + "\\html\\ <br />"); writer.WriteLine("</span>"); writer.Flush(); writer.Close(); } else { // Copy the web skin information over? string current_web_skin = currentMode.Skin; string current_web_folder = SobekCM_Library_Settings.Base_Design_Location + "skins/" + current_web_skin; copy_entire_folder(current_web_folder, folder); //if (File.Exists(current_web_folder + "\\" + current_web_skin + ".css")) //{ // File.Copy(current_web_folder + "\\" + current_web_skin + ".css", folder + "\\" + new_interface_code + ".css", true ); //} //if (File.Exists(current_web_folder + "\\html\\header.html")) //{ // File.Copy(current_web_folder + "\\html\\header.html", folder + "\\html\\header.html"); //} //if (File.Exists(current_web_folder + "\\html\\header_item.html")) //{ // File.Copy(current_web_folder + "\\html\\header_item.html", folder + "\\html\\header_item.html"); //} //if (File.Exists(current_web_folder + "\\html\\footer.html")) //{ // File.Copy(current_web_folder + "\\html\\footer.html", folder + "\\html\\footer.html"); //} //if (File.Exists(current_web_folder + "\\html\\footer_item.html")) //{ // File.Copy(current_web_folder + "\\html\\footer_item.html", folder + "\\html\\footer_item.html"); //} if (File.Exists(folder + "\\" + current_web_skin + ".css")) { if (File.Exists(folder + "\\" + new_interface_code + ".css")) { File.Delete(folder + "\\" + new_interface_code + ".css"); } File.Move(folder + "\\" + current_web_skin + ".css", folder + "\\" + new_interface_code + ".css"); } } // Irregardless of the user's choice on whether to copy the current skin, if there is NO base skin // provided and the folder does not exist, then we'll copy over the base skin type of stuff, such // as buttons, tabs, etc... if (new_base_code.Length == 0) { // What is the current base skin folder then? string base_skin_folder = SobekCM_Library_Settings.Base_Design_Location + "skins/" + currentMode.Base_Skin; copy_entire_folder(base_skin_folder + "/buttons", folder + "/buttons"); copy_entire_folder(base_skin_folder + "/tabs", folder + "/tabs"); copy_entire_folder(base_skin_folder + "/zoom_controls", folder + "/zoom_controls"); } } } catch (Exception ee) { bool error = false; } // Reload the list of all skins from the database, to include this new skin lock (skinCollection) { SobekCM_Skin_Collection_Builder.Populate_Default_Skins(skinCollection, Tracer); } actionMessage = "Saved new html skin <i>" + save_value + "</i>"; } else { actionMessage = "Unable to save new html skin <i>" + save_value + "</i>"; } // Try to create the directory try { if (!Directory.Exists(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value)) { Directory.CreateDirectory(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value); } if (!Directory.Exists(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\html")) { Directory.CreateDirectory(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\html"); } if (new_base_code.Length == 0) { if (!Directory.Exists(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\buttons")) { Directory.CreateDirectory(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\buttons"); } if (!Directory.Exists(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\tabs")) { Directory.CreateDirectory(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\tabs"); } if (!Directory.Exists(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\zoom_controls")) { Directory.CreateDirectory(SobekCM_Library_Settings.Base_Design_Location + "skins\\" + save_value + "\\zoom_controls"); } } } catch (Exception) { actionMessage = "Error creating all the necessary folders"; } } else { string edit_base_code = form["form_interface_basecode"].ToUpper().Trim(); string edit_banner_link = form["form_interface_link"].Trim(); string edit_notes = form["form_interface_notes"].Trim(); temp_object = form["form_interface_banner_override"]; if (temp_object != null) { override_banner = true; } temp_object = form["form_interface_header_override"]; if (temp_object != null) { override_header = true; } temp_object = form["form_interface_buildlaunch"]; if (temp_object != null) { build_on_launch = true; } temp_object = form["form_interface_top_nav"]; if (temp_object != null) { suppress_top_nav = true; } // Save this existing interface if (SobekCM_Database.Save_Web_Skin(save_value, edit_base_code, override_banner, override_header, edit_banner_link, edit_notes, build_on_launch, suppress_top_nav, Tracer)) { lock (skinCollection) { SobekCM_Skin_Collection_Builder.Populate_Default_Skins(skinCollection, Tracer); } Cached_Data_Manager.Remove_Skin(save_value, Tracer); actionMessage = "Edited existing html skin <i>" + save_value + "</i>"; } else { actionMessage = "Unable to edit existing html skin <i>" + save_value + "</i>"; } } } } } catch (Exception) { actionMessage = "Unknown error caught while handing your request."; } } }
/// <summary> Verifies that each global object is built and builds them upon request </summary> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <param name="Reload_All"> Flag indicates if everything should be reloaded/repopulated</param> /// <param name="Skins"> [REF] Collection of all the web skins </param> /// <param name="Translator"> [REF] Language support object which handles simple translational duties </param> /// <param name="Code_Manager"> [REF] List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param> /// <param name="All_Items_Lookup"> [REF] Lookup object used to pull basic information about any item loaded into this library </param> /// <param name="Icon_Dictionary"> [REF] Dictionary of information about every wordmark/icon in this digital library </param> /// <param name="Stats_Date_Range"> [REF] Object contains the start and end dates for the statistical data in the database </param> /// <param name="Thematic_Headings"> [REF] Headings under which all the highlighted collections on the main home page are organized </param> /// <param name="Aggregation_Aliases"> [REF] List of all existing aliases for existing aggregations </param> /// <param name="IP_Restrictions"> [REF] List of all IP Restriction ranges in use by this digital library </param> /// <param name="URL_Portals"> [REF] List of all web portals into this system </param> /// <param name="Mime_Types">[REF] Dictionary of MIME types by extension</param> public static void Build_Application_State(Custom_Tracer Tracer, bool Reload_All, ref SobekCM_Skin_Collection Skins, ref Language_Support_Info Translator, ref Aggregation_Code_Manager Code_Manager, ref Item_Lookup_Object All_Items_Lookup, ref Dictionary <string, Wordmark_Icon> Icon_Dictionary, ref Statistics_Dates Stats_Date_Range, ref List <Thematic_Heading> Thematic_Headings, ref Dictionary <string, string> Aggregation_Aliases, ref IP_Restriction_Ranges IP_Restrictions, ref Portal_List URL_Portals, ref Dictionary <string, Mime_Type_Info> Mime_Types) { // Should we reload the data from the exteral configuraiton file? if (Reload_All) { SobekCM_Library_Settings.Read_Configuration_File(); SobekCM_Database.Connection_String = SobekCM_Library_Settings.Database_Connection_String; SobekCM_Library_Settings.Refresh(SobekCM_Database.Get_Settings_Complete(null)); } // If there is no database connection string, there is a problem if (String.IsNullOrEmpty(SobekCM_Library_Settings.Database_Connection_String)) { throw new ApplicationException("Missing database connection string!"); } // Set the database connection strings Resource_Object.Database.SobekCM_Database.Connection_String = SobekCM_Library_Settings.Database_Connection_String; SobekCM_Database.Connection_String = SobekCM_Library_Settings.Database_Connection_String; // Set the workflow and disposition types if ((SobekCM_Library_Settings.Need_Workflow_And_Disposition_Types) || (Reload_All)) { SobekCM_Library_Settings.Set_Workflow_And_Disposition_Types(SobekCM_Database.All_WorkFlow_Types, SobekCM_Database.All_Possible_Disposition_Types); } // Set the metadata types if ((SobekCM_Library_Settings.Need_Metadata_Types) || (Reload_All)) { SobekCM_Library_Settings.Set_Metadata_Types(SobekCM_Database.Get_Metadata_Fields(null)); } // Set the search stop words if ((SobekCM_Library_Settings.Need_Search_Stop_Words) || (Reload_All)) { SobekCM_Library_Settings.Search_Stop_Words = SobekCM_Database.Search_Stop_Words(Tracer); } // Check the list of thematic headings if ((Thematic_Headings == null) || (Reload_All)) { if (Thematic_Headings != null) { lock (Thematic_Headings) { if (!SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer)) { Thematic_Headings = null; throw SobekCM_Database.Last_Exception; } } } else { Thematic_Headings = new List <Thematic_Heading>(); if (!SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer)) { Thematic_Headings = null; throw SobekCM_Database.Last_Exception; } } } // Check the list of forwardings if ((Aggregation_Aliases == null) || (Reload_All)) { if (Aggregation_Aliases != null) { lock (Aggregation_Aliases) { SobekCM_Database.Populate_Aggregation_Aliases(Aggregation_Aliases, Tracer); } } else { Aggregation_Aliases = new Dictionary <string, string>(); SobekCM_Database.Populate_Aggregation_Aliases(Aggregation_Aliases, Tracer); } } // Check the list of constant skins if ((Skins == null) || (Skins.Count == 0) || (Reload_All)) { if (Skins != null) { lock (Skins) { SobekCM_Skin_Collection_Builder.Populate_Default_Skins(Skins, Tracer); } } else { Skins = new SobekCM_Skin_Collection(); SobekCM_Skin_Collection_Builder.Populate_Default_Skins(Skins, Tracer); } } // Check the list of all web portals if ((URL_Portals == null) || (URL_Portals.Count == 0) || (Reload_All)) { if (URL_Portals != null) { lock (URL_Portals) { SobekCM_Database.Populate_URL_Portals(URL_Portals, Tracer); } } else { URL_Portals = new Portal_List(); SobekCM_Database.Populate_URL_Portals(URL_Portals, Tracer); } } // Check the translation table has been loaded if ((Translator == null) || (Reload_All)) { // Get the translation hashes into memory if (Translator != null) { lock (Translator) { SobekCM_Database.Populate_Translations(Translator, Tracer); } } else { Translator = new Language_Support_Info(); SobekCM_Database.Populate_Translations(Translator, Tracer); } } // Check that the conversion from SobekCM Codes to Greenstone Codes has been loaded if ((Code_Manager == null) || (Reload_All)) { if (Code_Manager != null) { lock (Code_Manager) { SobekCM_Database.Populate_Code_Manager(Code_Manager, Tracer); } } else { Code_Manager = new Aggregation_Code_Manager(); SobekCM_Database.Populate_Code_Manager(Code_Manager, Tracer); } } // Check the statistics date range information if ((Stats_Date_Range == null) || (Reload_All)) { if (Stats_Date_Range != null) { // Get the translation hashes into memory lock (Stats_Date_Range) { SobekCM_Database.Populate_Statistics_Dates(Stats_Date_Range, Tracer); } } else { Stats_Date_Range = new Statistics_Dates(); SobekCM_Database.Populate_Statistics_Dates(Stats_Date_Range, Tracer); } } // Get the Icon list if ((Icon_Dictionary == null) || (Reload_All)) { if (Icon_Dictionary != null) { // Get the translation hashes into memory lock (Icon_Dictionary) { SobekCM_Database.Populate_Icon_List(Icon_Dictionary, Tracer); } } else { Icon_Dictionary = new Dictionary <string, Wordmark_Icon>(); SobekCM_Database.Populate_Icon_List(Icon_Dictionary, Tracer); } } // Check the list of ip range restrictions if ((IP_Restrictions == null) || (Reload_All)) { if (IP_Restrictions != null) { lock (IP_Restrictions) { DataTable ipRestrictionTbl = SobekCM_Database.Get_IP_Restriction_Ranges(Tracer); if (ipRestrictionTbl != null) { IP_Restrictions.Populate_IP_Ranges(ipRestrictionTbl); } } } else { DataTable ipRestrictionTbl = SobekCM_Database.Get_IP_Restriction_Ranges(Tracer); if (ipRestrictionTbl != null) { IP_Restrictions = new IP_Restriction_Ranges(); IP_Restrictions.Populate_IP_Ranges(ipRestrictionTbl); } } } // Get the MIME type list if ((Mime_Types == null) || (Reload_All)) { if (Mime_Types != null) { // Get the translation hashes into memory lock (Mime_Types) { SobekCM_Database.Populate_MIME_List(Mime_Types, Tracer); } } else { Mime_Types = new Dictionary <string, Mime_Type_Info>(); SobekCM_Database.Populate_MIME_List(Mime_Types, Tracer); } } }