/// <summary> Constructor for a new instance of the Builder_Folder_Mgmt_AdminViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Builder_Folder_Mgmt_AdminViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            // Verify this user can edit this
            bool allowEdit = (((!UI_ApplicationCache_Gateway.Settings.Servers.isHosted) && (RequestSpecificValues.Current_User.Is_System_Admin)) || (RequestSpecificValues.Current_User.Is_Host_Admin));

            if (!allowEdit)
            {
                RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Aggregation;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Is there a folder specified?
            folderId = -1;
            if ((RequestSpecificValues.Current_Mode.Remaining_Url_Segments != null) && (RequestSpecificValues.Current_Mode.Remaining_Url_Segments.Length > 0))
            {
                if (String.Compare(RequestSpecificValues.Current_Mode.Remaining_Url_Segments[0], "new", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    if (!Int32.TryParse(RequestSpecificValues.Current_Mode.Remaining_Url_Segments[0], out folderId))
                    {
                        folderId = -1;
                    }
                }
            }

            // Handle any post backs
            saved = false;
            if (RequestSpecificValues.Current_Mode.isPostBack)
            {
                try
                {
                    // Pull the standard values from the form
                    NameValueCollection form = HttpContext.Current.Request.Form;
                    string action_value      = form["admin_builder_folder_action"];

                    // Get the entered values
                    folderName             = form["admin_folder_name"];
                    failuresFolder         = form["admin_folder_error"];
                    inboundFolder          = form["admin_folder_network"];
                    processingFolder       = form["admin_folder_processing"];
                    performChecksum        = (form["admin_folder_checksum"] != null);
                    archiveTiffs           = (form["admin_folder_archive_tiff"] != null);
                    archiveAllFiles        = (form["admin_folder_archive_all"] != null);
                    allowDeletes           = (form["admin_folder_allow_delete"] != null);
                    allowFoldersNoMetadata = (form["admin_folder_no_metadata"] != null);
                    allowMetadataUpdates   = (form["admin_folder_allow_updates"] != null);

                    // Get the hidden values
                    bibIdRestrictions = form["admin_builder_folder_restrictions"];
                    moduleSetId       = Int32.Parse(form["admin_builder_folder_modulesetid"]);

                    // The folders should always end with a slash
                    if ((!String.IsNullOrWhiteSpace(failuresFolder)) && (failuresFolder.Length > 2) && (failuresFolder[failuresFolder.Length - 1] != '\\'))
                    {
                        failuresFolder = failuresFolder + "\\";
                    }
                    if ((!String.IsNullOrWhiteSpace(inboundFolder)) && (inboundFolder.Length > 2) && (inboundFolder[inboundFolder.Length - 1] != '\\'))
                    {
                        inboundFolder = inboundFolder + "\\";
                    }
                    if ((!String.IsNullOrWhiteSpace(processingFolder)) && (processingFolder.Length > 2) && (processingFolder[processingFolder.Length - 1] != '\\'))
                    {
                        processingFolder = processingFolder + "\\";
                    }

                    // Switch, depending on the request
                    if (!String.IsNullOrEmpty(action_value))
                    {
                        // Was this a CANCEL?
                        if (action_value == "cancel")
                        {
                            // Determine URL
                            string returnUrl = RequestSpecificValues.Current_Mode.Base_URL + "l/admin/settings/builder/folders";
                            RequestSpecificValues.Current_Mode.Request_Completed = true;
                            HttpContext.Current.Response.Redirect(returnUrl, false);
                            HttpContext.Current.ApplicationInstance.CompleteRequest();
                            return;
                        }

                        // Was this a DELETE/
                        if (action_value == "delete")
                        {
                            // Try to delete this folder
                            bool result = SobekCM_Database.Builder_Folder_Delete(folderId, RequestSpecificValues.Tracer);
                            if (!result)
                            {
                                actionMessage = "Unknown error encountered while trying to delete this folder";
                            }
                            else
                            {
                                // Clear settings to be pulled again
                                HttpContext.Current.Session["Admin_Settigs"] = null;

                                // Assign this to be used by the system
                                UI_ApplicationCache_Gateway.ResetSettings();

                                // Return to the folder list
                                string returnUrl = RequestSpecificValues.Current_Mode.Base_URL + "l/admin/settings/builder/folders";
                                RequestSpecificValues.Current_Mode.Request_Completed = true;
                                HttpContext.Current.Response.Redirect(returnUrl, false);
                                HttpContext.Current.ApplicationInstance.CompleteRequest();
                                return;
                            }
                        }

                        // Was this a SAVE?
                        if (action_value == "save")
                        {
                            // Perform some validations
                            List <string> errors = new List <string>();
                            if (String.IsNullOrWhiteSpace(folderName))
                            {
                                errors.Add("DESCRIPTIVE NAME is required and missing");
                            }
                            if (String.IsNullOrWhiteSpace(failuresFolder))
                            {
                                errors.Add("FAILURES FOLDER is required and missing");
                            }
                            if (String.IsNullOrWhiteSpace(inboundFolder))
                            {
                                errors.Add("INBOUND FOLDER is required and missing");
                            }
                            if (String.IsNullOrWhiteSpace(processingFolder))
                            {
                                errors.Add("PROCESSING FOLDER is required and missing");
                            }

                            // If there were error, prepare the error message and don't save
                            if (errors.Count > 0)
                            {
                                actionMessage = "ERROR: Some required fields are missing:<br /><br />";
                                foreach (string thisError in errors)
                                {
                                    actionMessage = actionMessage + "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " + thisError + "<br />";
                                }
                            }
                            else
                            {
                                // Try to save this folder
                                bool result = SobekCM_Database.Builder_Folder_Edit(folderId, folderName, inboundFolder, failuresFolder, processingFolder, performChecksum, archiveTiffs, archiveAllFiles, allowDeletes, allowFoldersNoMetadata, bibIdRestrictions, moduleSetId, RequestSpecificValues.Tracer);
                                if (!result)
                                {
                                    actionMessage = "Unknown error encountered while saving folder to the database";
                                }
                                else
                                {
                                    // Successfully saved
                                    saved         = true;
                                    actionMessage = "Successfully saved builder folder changes.";

                                    // Clear settings to be pulled again
                                    HttpContext.Current.Session["Admin_Settigs"] = null;

                                    // Assign this to be used by the system
                                    UI_ApplicationCache_Gateway.ResetSettings();

                                    // Also, look to see if a warning might be suitable
                                    List <string> warnings = new List <string>();
                                    try
                                    {
                                        if (!Directory.Exists(failuresFolder))
                                        {
                                            warnings.Add("Can't verify existence of the FAILURES FOLDER");
                                        }
                                        if (!Directory.Exists(inboundFolder))
                                        {
                                            warnings.Add("Can't verify existence of the INBOUND FOLDER");
                                        }
                                        if (!Directory.Exists(processingFolder))
                                        {
                                            warnings.Add("Can't verify existence of the PROCESSING FOLDER");
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        warnings.Clear();
                                        warnings.Add("Exception caught while trying to verify folders.");
                                    }

                                    // Add warnings
                                    if (warnings.Count == 3)
                                    {
                                        // i.e., none of the folders could be verified
                                        actionMessage = actionMessage + "<br /><br />WARNING: Unable to verify existence of any of the folders.  This may be normal since the account under which the web runs does not necessarily need access to the builder folders.";
                                    }
                                    else if (warnings.Count > 0)
                                    {
                                        actionMessage = actionMessage + "<br /><br />WARNING: Unable to verify existence of some of the folders:<br /><br />";
                                        foreach (string thisWarning in warnings)
                                        {
                                            actionMessage = actionMessage + "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " + thisWarning + "<br />";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            else // NOT A POST BACK
            {
                // Configure the values
                folderName             = String.Empty;
                failuresFolder         = String.Empty;
                inboundFolder          = String.Empty;
                processingFolder       = String.Empty;
                performChecksum        = false;
                archiveTiffs           = false;
                archiveAllFiles        = false;
                allowDeletes           = true;
                allowFoldersNoMetadata = true;
                bibIdRestrictions      = String.Empty;
                moduleSetId            = 10;

                // Is there a folder specified?
                if (folderId > 0)
                {
                    // Try to get this source folder
                    Builder_Source_Folder sourceFolder = SobekEngineClient.Builder.Get_Builder_Folder(folderId, RequestSpecificValues.Tracer);

                    if (sourceFolder != null)
                    {
                        // Set the values from the existing source folder
                        folderName             = sourceFolder.Folder_Name;
                        failuresFolder         = sourceFolder.Failures_Folder;
                        inboundFolder          = sourceFolder.Inbound_Folder;
                        processingFolder       = sourceFolder.Processing_Folder;
                        performChecksum        = sourceFolder.Perform_Checksum;
                        archiveTiffs           = sourceFolder.Archive_TIFFs;
                        archiveAllFiles        = sourceFolder.Archive_All_Files;
                        allowDeletes           = sourceFolder.Allow_Deletes;
                        allowFoldersNoMetadata = sourceFolder.Allow_Folders_No_Metadata;
                        allowMetadataUpdates   = sourceFolder.Allow_Metadata_Updates;
                        bibIdRestrictions      = sourceFolder.BibID_Roots_Restrictions;
                        moduleSetId            = sourceFolder.Builder_Module_Set.SetID;
                    }
                    else
                    {
                        folderId = -1;
                    }
                }
            }
        }