/// <summary> Constructor for a new instance of the Aliases_AdminViewer class </summary> /// <param name="User"> Authenticated user information </param> /// <param name="CurrentMode"> Mode / navigation information for the current request</param> /// <param name="Aggregation_Aliases"> Dictionary of all current item aggregation aliases </param> /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param> /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param> /// <remarks> Postback from handling an edit or new item aggregation alias is handled here in the constructor </remarks> public Aliases_AdminViewer(User_Object User, SobekCM_Navigation_Object CurrentMode, Dictionary <string, string> Aggregation_Aliases, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer) : base(User) { Tracer.Add_Trace("Aliases_AdminViewer.Constructor", String.Empty); // Save the mode and settings here currentMode = CurrentMode; aggregationAliases = Aggregation_Aliases; // Set action message to nothing to start actionMessage = String.Empty; // If the user cannot edit this, go back if ((user == null) || ((!user.Is_System_Admin) && (!user.Is_Portal_Admin))) { CurrentMode.Mode = Display_Mode_Enum.My_Sobek; CurrentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home; CurrentMode.Redirect(); return; } // If this is a postback, handle any events first if (CurrentMode.isPostBack) { try { // Pull the standard values NameValueCollection form = HttpContext.Current.Request.Form; string save_value = form["admin_forwarding_tosave"].ToLower().Trim(); string new_alias = form["admin_forwarding_alias"].ToLower().Trim(); // Was this a save request if (save_value.Length > 0) { // If this starts with a '-' this is a delete if (save_value[0] == '-') { if ((user.Is_System_Admin) && (save_value.Length > 1)) { save_value = save_value.Substring(1); Tracer.Add_Trace("Aliases_AdminViewer.Constructor", "Delete alias '" + save_value + "'"); if (SobekCM_Database.Delete_Aggregation_Alias(save_value, Tracer)) { if (aggregationAliases.ContainsKey(save_value)) { aggregationAliases.Remove(save_value); } actionMessage = "Deleted existing aggregation alias <i>" + save_value + "</i>"; } } } else { Tracer.Add_Trace("Aliases_AdminViewer.Constructor", "Save alias '" + save_value + "'"); // Was this to save a new alias (from the main page) or edit an existing (from the popup form)? if (save_value == new_alias) { string new_code = form["admin_forwarding_code"].ToLower().Trim(); // Validate the code if (new_code.Length > 20) { actionMessage = "New alias code must be twenty characters long or less"; } else if (new_code.Length == 0) { actionMessage = "You must enter a CODE for this aggregation alias"; } else if (Code_Manager[new_code.ToUpper()] != null) { actionMessage = "Aggregation with this code already exists"; } else if (SobekCM_Library_Settings.Reserved_Keywords.Contains(new_code.ToLower())) { actionMessage = "That code is a system-reserved keyword. Try a different code."; } // Save this new forwarding if (SobekCM_Database.Save_Aggregation_Alias(save_value, new_code, Tracer)) { if (aggregationAliases.ContainsKey(save_value)) { aggregationAliases[save_value] = new_code; } else { aggregationAliases.Add(save_value, new_code); } actionMessage = "Saved new aggregation alias <i>" + save_value + "</i>"; } else { actionMessage = "Unable to save new aggregation alias <i>" + save_value + "</i>"; } } else { string edit_code = form["form_forwarding_code"].ToLower().Trim(); // Save this existing forwarding if (SobekCM_Database.Save_Aggregation_Alias(save_value, edit_code, Tracer)) { if (aggregationAliases.ContainsKey(save_value)) { aggregationAliases[save_value] = edit_code; } else { aggregationAliases.Add(save_value, edit_code); } actionMessage = "Edited existing aggregation alias <i>" + save_value + "</i>"; } else { actionMessage = "Unable to save existing aggregation alias <i>" + save_value + "</i>"; } } } } } catch (Exception) { actionMessage = "Unknown error caught while processing request"; } } }
/// <summary> Constructor for a new instance of the Aliases_AdminViewer class </summary> /// <param name="User"> Authenticated user information </param> /// <param name="currentMode"> Mode / navigation information for the current request</param> /// <param name="Aggregation_Aliases"> Dictionary of all current item aggregation aliases </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 item aggregation alias is handled here in the constructor </remarks> public Aliases_AdminViewer(User_Object User, SobekCM_Navigation_Object currentMode, Dictionary <string, string> Aggregation_Aliases, Custom_Tracer Tracer) : base(User) { Tracer.Add_Trace("Aliases_AdminViewer.Constructor", String.Empty); // Save the mode and settings here base.currentMode = currentMode; aggregationAliases = Aggregation_Aliases; // 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 save_value = form["admin_forwarding_tosave"].ToLower().Trim(); string new_alias = form["admin_forwarding_alias"].ToLower().Trim(); // Was this a save request if (save_value.Length > 0) { // If this starts with a '-' this is a delete if (save_value[0] == '-') { if (save_value.Length > 1) { save_value = save_value.Substring(1); Tracer.Add_Trace("Aliases_AdminViewer.Constructor", "Delete alias '" + save_value + "'"); if (SobekCM_Database.Delete_Aggregation_Alias(save_value, Tracer)) { if (aggregationAliases.ContainsKey(save_value)) { aggregationAliases.Remove(save_value); } actionMessage = "Deleted existing aggregation alias <i>" + save_value + "</i>"; } } } else { Tracer.Add_Trace("Aliases_AdminViewer.Constructor", "Save alias '" + save_value + "'"); // Was this to save a new alias (from the main page) or edit an existing (from the popup form)? if (save_value == new_alias) { string new_code = form["admin_forwarding_code"].ToLower().Trim(); // Save this new forwarding if (SobekCM_Database.Save_Aggregation_Alias(save_value, new_code, Tracer)) { if (aggregationAliases.ContainsKey(save_value)) { aggregationAliases[save_value] = new_code; } else { aggregationAliases.Add(save_value, new_code); } actionMessage = "Saved new aggregation alias <i>" + save_value + "</i>"; } else { actionMessage = "Unable to save new aggregation alias <i>" + save_value + "</i>"; } } else { string edit_code = form["form_forwarding_code"].ToLower().Trim(); // Save this existing forwarding if (SobekCM_Database.Save_Aggregation_Alias(save_value, edit_code, Tracer)) { if (aggregationAliases.ContainsKey(save_value)) { aggregationAliases[save_value] = edit_code; } else { aggregationAliases.Add(save_value, edit_code); } actionMessage = "Edited existing aggregation alias <i>" + save_value + "</i>"; } else { actionMessage = "Unable to save existing aggregation alias <i>" + save_value + "</i>"; } } } } } catch (Exception) { actionMessage = "Unknown error caught while processing request"; } } }