/// <summary> Constructor for a new instance of the Admin_HtmlSubwriter class </summary>
        /// <param name="Results_Statistics"> Information about the entire set of results for a browse of a user's bookshelf folder </param>
        /// <param name="Paged_Results"> Single page of results for a browse of a user's bookshelf folder, within the entire set </param>
        /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
        /// <param name="All_Items_Lookup"> Lookup object used to pull basic information about any item loaded into this library </param>
        /// <param name="Hierarchy_Object"> Current item aggregation object to display </param>
        /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
        /// <param name="Translator"> Language support object which handles simple translational duties </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_Item">Current item to edit, if the user is requesting to edit an item</param>
        /// <param name="Aggregation_Aliases"> List of all existing aliases for existing aggregations </param>
        /// <param name="Web_Skin_Collection"> Collection of all the web skins </param>
        /// <param name="Current_User"> Currently logged on user </param>
        /// <param name="Icon_Table"> Dictionary of all the wordmark/icons which can be tagged to the items </param>
        /// <param name="IP_Restrictions"> List of all IP Restriction ranges in use by this digital library </param>
        /// <param name="URL_Portals"> List of all web portals into this system </param>
        /// <param name="Stats_Date_Range"> Object contains the start and end dates for the statistical data in the database </param>
        /// <param name="Thematic_Headings"> Headings under which all the highlighted collections on the home page are organized </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Admin_HtmlSubwriter(Search_Results_Statistics Results_Statistics,
                                   List <iSearch_Title_Result> Paged_Results,
                                   Aggregation_Code_Manager Code_Manager,
                                   Item_Lookup_Object All_Items_Lookup,
                                   Item_Aggregation Hierarchy_Object,
                                   SobekCM_Skin_Object HTML_Skin,
                                   Language_Support_Info Translator,
                                   SobekCM_Navigation_Object Current_Mode,
                                   SobekCM_Item Current_Item,
                                   Dictionary <string, string> Aggregation_Aliases,
                                   SobekCM_Skin_Collection Web_Skin_Collection,
                                   User_Object Current_User,
                                   IP_Restriction_Ranges IP_Restrictions,
                                   Dictionary <string, Wordmark_Icon> Icon_Table,
                                   Portal_List URL_Portals,
                                   Statistics_Dates Stats_Date_Range,
                                   List <Thematic_Heading> Thematic_Headings,
                                   Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Admin_HtmlSubwriter.Constructor", "Saving values and geting user object back from the session");

            resultsStatistics = Results_Statistics;
            pagedResults      = Paged_Results;
            codeManager       = Code_Manager;
            itemList          = All_Items_Lookup;
            htmlSkin          = HTML_Skin;
            translator        = Translator;
            currentCollection = Hierarchy_Object;
            currentItem       = Current_Item;
            user           = Current_User;
            ipRestrictions = IP_Restrictions;
            iconTable      = Icon_Table;
            statsDates     = Stats_Date_Range;


            if (Current_Mode.My_Sobek_Type == My_Sobek_Type_Enum.Log_Out)
            {
                Tracer.Add_Trace("Admin_HtmlSubwriter.Constructor", "Performing logout");

                HttpContext.Current.Session["user"] = null;
                HttpContext.Current.Response.Redirect("?");
            }

            if ((Current_Mode.My_Sobek_Type != My_Sobek_Type_Enum.Logon) && (user != null) && (user.Is_Temporary_Password))
            {
                Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.New_Password;
            }

            if (Current_Mode.Logon_Required)
            {
                Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Logon;
            }

            // If the user is not an admin, and admin was selected, reroute this
            if ((!Current_User.Is_System_Admin) && (!Current_User.Is_Portal_Admin))
            {
                Current_Mode.Mode             = Display_Mode_Enum.My_Sobek;
                Current_Mode.My_Sobek_Type    = My_Sobek_Type_Enum.Home;
                Current_Mode.My_Sobek_SubMode = String.Empty;
                HttpContext.Current.Response.Redirect(Current_Mode.Redirect_URL());
            }

            Tracer.Add_Trace("Admin_HtmlSubwriter.Constructor", "Building the my sobek viewer object");
            switch (Current_Mode.Admin_Type)
            {
            case Admin_Type_Enum.Aggregation_Single:
                adminViewer = new Aggregation_Single_AdminViewer(user, Current_Mode, codeManager, Thematic_Headings, Web_Skin_Collection, Tracer);
                break;

            case Admin_Type_Enum.Home:
                adminViewer = new Home_AdminViewer(user, Current_Mode, Tracer);
                break;

            case Admin_Type_Enum.Builder_Status:
                adminViewer = new Builder_AdminViewer(user, Current_Mode);
                break;

            case Admin_Type_Enum.Interfaces:
                adminViewer = new Skins_AdminViewer(user, Current_Mode, Web_Skin_Collection, Tracer);
                break;

            case Admin_Type_Enum.Forwarding:
                adminViewer = new Aliases_AdminViewer(user, Current_Mode, Aggregation_Aliases, Tracer);
                break;

            case Admin_Type_Enum.Wordmarks:
                adminViewer = new Wordmarks_AdminViewer(user, Current_Mode, Tracer);
                break;

            case Admin_Type_Enum.URL_Portals:
                adminViewer = new Portals_AdminViewer(user, Current_Mode, URL_Portals, Tracer);
                break;

            case Admin_Type_Enum.Users:
                adminViewer = new Users_AdminViewer(user, Current_Mode, codeManager, Tracer);
                break;

            case Admin_Type_Enum.User_Groups:
                adminViewer = new User_Group_AdminViewer(user, Current_Mode, codeManager, Tracer);
                break;

            case Admin_Type_Enum.Aggregations_Mgmt:
                adminViewer = new Aggregations_Mgmt_AdminViewer(user, Current_Mode, codeManager, Tracer);
                break;

            case Admin_Type_Enum.IP_Restrictions:
                adminViewer = new IP_Restrictions_AdminViewer(user, Current_Mode, ipRestrictions, Tracer);
                break;

            case Admin_Type_Enum.Thematic_Headings:
                adminViewer = new Thematic_Headings_AdminViewer(user, Current_Mode, Thematic_Headings, Tracer);
                break;

            case Admin_Type_Enum.Settings:
                adminViewer = new Settings_AdminViewer(user, Current_Mode, Tracer);
                break;

            case Admin_Type_Enum.Projects:
                if (Current_Mode.My_Sobek_SubMode.Length > 1)
                {
                    string project_code = Current_Mode.My_Sobek_SubMode.Substring(1);
                    Tracer.Add_Trace("MySobek_HtmlSubwriter.Constructor", "Checking cache for valid project file");
                    if (user != null)
                    {
                        SobekCM_Item projectObject = Cached_Data_Manager.Retrieve_Project(user.UserID, project_code, Tracer);
                        if (projectObject != null)
                        {
                            Tracer.Add_Trace("MySobek_HtmlSubwriter.Constructor", "Valid project file found in cache");
                            adminViewer = new Edit_Item_Metadata_MySobekViewer(user, Current_Mode, itemList, projectObject, codeManager, iconTable, htmlSkin, Tracer);
                        }
                        else
                        {
                            if (SobekCM_Database.Get_All_Projects_Templates(Tracer).Tables[0].Select("ProjectCode='" + project_code + "'").Length > 0)
                            {
                                Tracer.Add_Trace("MySobek_HtmlSubwriter.Constructor", "Building project file from (possible) PMETS");
                                string       pmets_file = SobekCM_Library_Settings.Base_MySobek_Directory + "projects\\" + Current_Mode.My_Sobek_SubMode.Substring(1) + ".pmets";
                                SobekCM_Item pmets_item = File.Exists(pmets_file) ? SobekCM_Item.Read_METS(pmets_file) : new SobekCM_Item();
                                pmets_item.Bib_Info.Main_Title.Title = "Project level metadata for '" + project_code + "'";
                                pmets_item.Bib_Info.SobekCM_Type     = TypeOfResource_SobekCM_Enum.Project;
                                pmets_item.BibID            = project_code.ToUpper();
                                pmets_item.VID              = "00001";
                                pmets_item.Source_Directory = SobekCM_Library_Settings.Base_MySobek_Directory + "projects\\";

                                Tracer.Add_Trace("MySobek_HtmlSubwriter.Constructor", "Adding project file to cache");

                                Cached_Data_Manager.Store_Project(user.UserID, project_code, pmets_item, Tracer);

                                adminViewer = new Edit_Item_Metadata_MySobekViewer(user, Current_Mode, itemList, pmets_item, codeManager, iconTable, htmlSkin, Tracer);
                            }
                        }
                    }
                }

                if (adminViewer == null)
                {
                    adminViewer = new Projects_AdminViewer(user, Current_Mode, Tracer);
                }
                break;
            }

            // Pass in the navigation and translator information
            adminViewer.CurrentMode = Current_Mode;
            adminViewer.Translator  = translator;
        }
        private void Write_Edit_User_Group_Form(TextWriter Output, Custom_Tracer Tracer)
        {
            Output.WriteLine("  <div class=\"SobekHomeText\">");
            Output.WriteLine("  <br />");
            Output.WriteLine("  <b>Edit this user group's permissions and abilities</b>");
            Output.WriteLine("    <ul>");
            Output.WriteLine("      <li>Enter the permissions for this user group below and press the SAVE button when all your edits are complete.</li>");
            Output.WriteLine("      <li>For clarification of any terms on this form, <a href=\"" + SobekCM_Library_Settings.Help_URL(currentMode.Base_URL) + "admin/users\" target=\"ADMIN_USER_HELP\" >click here to view the help page</a>.</li>");
            Output.WriteLine("     </ul>");
            Output.WriteLine("  </div>");

            Output.WriteLine("  <div class=\"ViewsBrowsesRow\">");
            Output.WriteLine("    " + Selected_Tab_Start + " GROUP INFORMATION " + Selected_Tab_End);
            Output.WriteLine("  </div>");

            Output.WriteLine("  <div class=\"SobekEditPanel\">");

            // Add the buttons
            string last_mode = currentMode.My_Sobek_SubMode;

            currentMode.My_Sobek_SubMode = String.Empty;
            currentMode.Admin_Type       = Admin_Type_Enum.Users;
            Output.WriteLine("  <table width=\"100%px\"><tr><td width=\"480px\">&nbsp;</td><td align=\"right\"><a href=\"" + currentMode.Redirect_URL() + "\"><img border=\"0\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/cancel_button_g.gif\" alt=\"CLOSE\" /></a> &nbsp; <input type=\"image\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/save_button_g.gif\" value=\"Submit\" alt=\"Submit\"></td><td width=\"20px\">&nbsp;</td></tr></table>");
            currentMode.My_Sobek_SubMode = last_mode;
            currentMode.Admin_Type       = Admin_Type_Enum.User_Groups;


            Output.WriteLine("  <span class=\"SobekEditItemSectionTitle_first\"> &nbsp; Basic Information</span>");
            Output.WriteLine("  <blockquote>");
            Output.WriteLine("    <table>");
            Output.WriteLine("      <tr><td><b><label for=\"groupName\">Name:</label></b></td><td><input id=\"groupName\" name=\"groupName\" class=\"admin_small_input\" value=\"" + editGroup.Name + "\" type=\"text\" onfocus=\"javascript:textbox_enter('groupName', 'admin_small_input_focused')\" onblur=\"javascript:textbox_leave('groupName', 'admin_small_input')\" /></td></tr>");
            Output.WriteLine("      <tr><td><b><label for=\"groupDescription\">Description:</label></b></td><td><input id=\"groupDescription\" name=\"groupDescription\" class=\"admin_large_input\" value=\"" + editGroup.Description + "\" type=\"text\" onfocus=\"javascript:textbox_enter('groupDescription', 'admin_large_input_focused')\" onblur=\"javascript:textbox_leave('groupDescription', 'admin_large_input')\" /></td></tr>");
            Output.WriteLine("    </table>");
            Output.WriteLine("  </blockquote>");
            Output.WriteLine("  <br />");

            Output.WriteLine("  <span class=\"SobekEditItemSectionTitle\"> &nbsp; Global Permissions</span><br />");
            Output.WriteLine(editGroup.Can_Submit
                                 ? "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_submit\" id=\"admin_user_submit\" checked=\"checked\" /> <label for=\"admin_user_submit\">Can submit items</label> <br />"
                                 : "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_submit\" id=\"admin_user_submit\" /> <label for=\"admin_user_submit\">Can submit items</label> <br />");

            Output.WriteLine(editGroup.Is_Internal_User
                                 ? "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_internal\" id=\"admin_user_internal\" checked=\"checked\" /> <label for=\"admin_user_internal\">Is internal user</label> <br />"
                                 : "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_internal\" id=\"admin_user_internal\" /> <label for=\"admin_user_internal\">Is internal user</label> <br />");

            bool canEditAll = editGroup.Editable_Regular_Expressions.Any(thisRegularExpression => thisRegularExpression == "[A-Z]{2}[A-Z|0-9]{4}[0-9]{4}");

            Output.WriteLine(canEditAll
                                 ? "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_editall\" id=\"admin_user_editall\" checked=\"checked\" /> <label for=\"admin_user_editall\">Can edit <u>all</u> items</label> <br />"
                                 : "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_editall\" id=\"admin_user_editall\" /> <label for=\"admin_user_editall\">Can edit <u>all</u> items</label> <br />");

            Output.WriteLine(editGroup.Is_System_Admin
                                 ? "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_admin\" id=\"admin_user_admin\" checked=\"checked\" /> <label for=\"admin_user_admin\">Is system administrator</label> <br />"
                                 : "    <input class=\"admin_user_checkbox\" type=\"checkbox\" name=\"admin_user_admin\" id=\"admin_user_admin\" /> <label for=\"admin_user_admin\">Is system administrator</label> <br />");

            Output.WriteLine("  <br />");
            Output.WriteLine("  <br />");


            Output.WriteLine("  <span class=\"SobekEditItemSectionTitle\"> &nbsp; Templates and Projects</span>");
            Output.WriteLine("  <blockquote>");
            Output.WriteLine("    <table width=\"600px\">");

            DataSet projectTemplateSet = SobekCM_Database.Get_All_Projects_Templates(Tracer);

            Output.WriteLine("      <tr valign=\"top\" >");
            Output.WriteLine("        <td wdith=\"300px\">");
            Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsWhiteTable\">");
            Output.WriteLine("  <tr align=\"left\" bgcolor=\"#0022a7\" >");
            Output.WriteLine("    <th width=\"180px\" align=\"left\"><span style=\"color: White\">TEMPLATES</span></th>");
            Output.WriteLine("   </tr>");
            Output.WriteLine("  <tr ><td bgcolor=\"#e7e7e7\"></td></tr>");

            ReadOnlyCollection <string> user_templates = editGroup.Templates;

            foreach (DataRow thisTemplate in projectTemplateSet.Tables[1].Rows)
            {
                string template_name = thisTemplate["TemplateName"].ToString();
                string template_code = thisTemplate["TemplateCode"].ToString();

                Output.Write("  <tr align=\"left\"><td><input type=\"checkbox\" name=\"admin_user_template_" + template_code + "\" id=\"admin_user_template_" + template_code + "\"");
                if (user_templates.Contains(template_code))
                {
                    Output.Write(" checked=\"checked\"");
                }
                if (template_name.Length > 0)
                {
                    Output.WriteLine(" /> &nbsp; <acronym title=\"" + template_name.Replace("\"", "'") + "\"><label for=\"admin_user_template_" + template_code + "\">" + template_code + "</label></acronym></td></tr>");
                }
                else
                {
                    Output.WriteLine(" /> &nbsp; <label for=\"admin_user_template_" + template_code + "\">" + template_code + "</label></td></tr>");
                }
                Output.WriteLine("  <tr><td bgcolor=\"#e7e7e7\"></td></tr>");
            }
            Output.WriteLine("</table>");
            Output.WriteLine("        </td>");

            Output.WriteLine("        <td>");
            Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsWhiteTable\">");
            Output.WriteLine("  <tr align=\"left\" bgcolor=\"#0022a7\" >");
            Output.WriteLine("    <th width=\"180px\" align=\"left\"><span style=\"color: White\">PROJECTS</span></th>");
            Output.WriteLine("   </tr>");
            Output.WriteLine("  <tr><td bgcolor=\"#e7e7e7\"></td></tr>");

            ReadOnlyCollection <string> user_projects = editGroup.Projects;

            foreach (DataRow thisProject in projectTemplateSet.Tables[0].Rows)
            {
                string project_name = thisProject["ProjectName"].ToString();
                string project_code = thisProject["ProjectCode"].ToString();

                Output.Write("  <tr align=\"left\"><td><input type=\"checkbox\" name=\"admin_user_project_" + project_code + "\" id=\"admin_user_project_" + project_code + "\"");
                if (user_projects.Contains(project_code))
                {
                    Output.Write(" checked=\"checked\"");
                }
                if (project_name.Length > 0)
                {
                    Output.WriteLine(" /> &nbsp; <acronym title=\"" + project_name.Replace("\"", "'") + "\"><label for=\"admin_user_project_" + project_code + "\">" + project_code + "</label></acronym></td></tr>");
                }
                else
                {
                    Output.WriteLine(" /> &nbsp; <label for=\"admin_user_project_" + project_code + "\">" + project_code + "</label></td></tr>");
                }

                Output.WriteLine("  <tr><td bgcolor=\"#e7e7e7\"></td></tr>");
            }
            Output.WriteLine("</table>");
            Output.WriteLine("        </td>");

            Output.WriteLine("      </tr>");
            Output.WriteLine("   </table>");
            Output.WriteLine("  </blockquote>");

            Output.WriteLine("  <br />");
            Output.WriteLine("  <br />");
            Output.WriteLine("  <span class=\"SobekEditItemSectionTitle\"> &nbsp; Aggregations</span>");
            Output.WriteLine("  <br />");
            Output.WriteLine("  <br />");
            Output.WriteLine("<table><tr><td width=\"30px\">&nbsp;</td><td>");
            Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsWhiteTable\">");

            // Get the list of collections lists in the user object
            ReadOnlyCollection <User_Editable_Aggregation> aggregations_in_editable_user = editGroup.Aggregations;
            Dictionary <string, User_Editable_Aggregation> lookup_aggs = aggregations_in_editable_user.ToDictionary(thisAggr => thisAggr.Code.ToLower());

            // Step through each aggregation type
            foreach (string aggregationType in codeManager.All_Types)
            {
                Output.WriteLine("  <tr align=\"left\" bgcolor=\"#0022a7\" >");
                if ((aggregationType.Length > 0) && (aggregationType[aggregationType.Length - 1] != 'S'))
                {
                    Output.WriteLine("    <td colspan=\"6\"><span style=\"color: White\"><b>" + aggregationType.ToUpper() + "S</b></span></td>");
                }
                else
                {
                    Output.WriteLine("    <td colspan=\"6\"><span style=\"color: White\"><b>" + aggregationType.ToUpper() + "</b></span></td>");
                }
                Output.WriteLine("  </tr>");

                Output.WriteLine("  <tr align=\"left\" bgcolor=\"#7d90d5\" >");
                Output.WriteLine("    <td width=\"57px\" align=\"left\"><span style=\"color: White\"><acronym title=\"Can select this aggregation when editing or submitting an item\">CAN<br />SELECT</acronym></span></td>");
                Output.WriteLine("    <td width=\"50px\" align=\"left\"><span style=\"color: White\"><acronym title=\"Can edit any item in this aggregation\">CAN<br />EDIT</acronym></span></td>");
                Output.WriteLine("    <td width=\"50px\" align=\"left\"><span style=\"color: White\"><acronym title=\"Can perform curatorial or collection manager tasks on this aggregation\">IS<br />CURATOR</acronym></span></td>");
                Output.WriteLine("    <td align=\"left\" colspan=\"2\"><span style=\"color: White\">ITEM AGGREGATION</span></td>");
                Output.WriteLine("   </tr>");

                // Show all matching rows
                foreach (Item_Aggregation_Related_Aggregations thisAggr in codeManager.Aggregations_By_Type(aggregationType))
                {
                    Output.WriteLine("  <tr align=\"left\" >");
                    if (!lookup_aggs.ContainsKey(thisAggr.Code))
                    {
                        Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_select_" + thisAggr.Code + "\" id=\"admin_project_select_" + thisAggr.Code + "\" /></td>");
                        Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_edit_" + thisAggr.Code + "\" id=\"admin_project_edit_" + thisAggr.Code + "\" /></td>");
                        Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_admin_" + thisAggr.Code + "\" id=\"admin_project_admin_" + thisAggr.Code + "\" /></td>");
                    }
                    else
                    {
                        if (lookup_aggs[thisAggr.Code].CanSelect)
                        {
                            Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_select_" + thisAggr.Code + "\" id=\"admin_project_select_" + thisAggr.Code + "\" checked=\"checked\" /></td>");
                        }
                        else
                        {
                            Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_select_" + thisAggr.Code + "\" id=\"admin_project_select_" + thisAggr.Code + "\" /></td>");
                        }

                        if (lookup_aggs[thisAggr.Code].CanEditItems)
                        {
                            Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_edit_" + thisAggr.Code + "\" id=\"admin_project_edit_" + thisAggr.Code + "\" checked=\"checked\" /></td>");
                        }
                        else
                        {
                            Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_edit_" + thisAggr.Code + "\" id=\"admin_project_edit_" + thisAggr.Code + "\" /></td>");
                        }

                        if (lookup_aggs[thisAggr.Code].IsCurator)
                        {
                            Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_admin_" + thisAggr.Code + "\" id=\"admin_project_admin_" + thisAggr.Code + "\" checked=\"checked\" /></td>");
                        }
                        else
                        {
                            Output.WriteLine("    <td><input type=\"checkbox\" name=\"admin_project_admin_" + thisAggr.Code + "\" id=\"admin_project_admin_" + thisAggr.Code + "\" /></td>");
                        }
                    }

                    Output.WriteLine("    <td>" + thisAggr.Code + "</td>");
                    Output.WriteLine("    <td>" + thisAggr.Name + "</td>");
                    Output.WriteLine("   </tr>");
                    Output.WriteLine("  <tr><td bgcolor=\"#e7e7e7\" colspan=\"6\"></td></tr>");
                }
            }

            Output.WriteLine("</table>");
            Output.WriteLine("</td></tr></table>");
            Output.WriteLine("<br />");

            // Add the buttons
            currentMode.My_Sobek_SubMode = String.Empty;
            Output.WriteLine("  <table width=\"100%px\"><tr><td width=\"480px\">&nbsp;</td><td align=\"right\"><a href=\"" + currentMode.Redirect_URL() + "\"><img border=\"0\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/cancel_button_g.gif\" alt=\"CLOSE\" /></a> &nbsp; <input type=\"image\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/save_button_g.gif\" value=\"Submit\" alt=\"Submit\"></td><td width=\"20px\">&nbsp;</td></tr></table>");
            currentMode.My_Sobek_SubMode = last_mode;

            Output.WriteLine("</div>");
        }
        /// <summary> This is an opportunity to write HTML directly into the main form, without
        /// using the pop-up html form architecture </summary>
        /// <param name="Output"> Textwriter to write the pop-up form HTML for this viewer </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <remarks> This text will appear within the ItemNavForm form tags </remarks>
        public override void Add_HTML_In_Main_Form(TextWriter Output, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Projects_AdminViewer.Add_HTML_In_Main_Form", "Add any popup divisions for form elements");

            // Add the scripts needed
            Output.WriteLine("<script type=\"text/javascript\" src=\"" + currentMode.Base_URL + "default/scripts/jquery/jquery-1.6.2.min.js\"></script>");
            Output.WriteLine("<script type=\"text/javascript\" src=\"" + currentMode.Base_URL + "default/scripts/jquery/jquery-ui-1.8.16.custom.min.js\"></script>");
            Output.WriteLine("<script type=\"text/javascript\" src=\"" + currentMode.Base_URL + "default/scripts/sobekcm_form.js\" ></script>");

            // Add the hidden field
            Output.WriteLine("<!-- Hidden field is used for postbacks to indicate what to save -->");
            Output.WriteLine("<input type=\"hidden\" id=\"admin_project_tosave\" name=\"admin_project_tosave\" value=\"\" />");
            Output.WriteLine();

            Output.WriteLine("<!-- Projects Rename Form -->");
            Output.WriteLine("<div class=\"admin_project_popup_div\" id=\"form_project\" style=\"display:none;\">");
            Output.WriteLine("  <div class=\"popup_title\"><table width=\"100%\"><tr><td align=\"left\">RENAME PROJECT</td><td align=\"right\"> <a href=\"#template\" alt=\"CLOSE\" onclick=\"project_form_close()\">X</a> &nbsp; </td></tr></table></div>");
            Output.WriteLine("  <br />");
            Output.WriteLine("  <table class=\"popup_table\">");

            // Add line for code
            Output.Write("    <tr align=\"left\"><td width=\"120px\"><label for=\"form_project_code\">Project Code:</label></td>");
            Output.Write("<td><span class=\"form_linkline admin_existing_code_line\" id=\"form_project_code\"></span></td>");

            // Add line for name
            Output.WriteLine("    <tr><td><label for=\"form_project_name\">Project Name:</label></td><td><input class=\"admin_project_large_input\" name=\"form_project_name\" id=\"form_project_name\" type=\"text\" value=\"\" onfocus=\"javascript:textbox_enter('form_project_name', 'admin_project_large_input_focused')\" onblur=\"javascript:textbox_leave('form_project_name', 'admin_project_large_input')\" /></td></tr>");

            Output.WriteLine("  </table>");
            Output.WriteLine("  <br />");
            Output.WriteLine("  <center><a href=\"\" onclick=\"return project_form_close();\"><img border=\"0\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/cancel_button_g.gif\" alt=\"CLOSE\" /></a> &nbsp; &nbsp; <input type=\"image\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/save_button_g.gif\" value=\"Submit\" alt=\"Submit\"></center>");
            Output.WriteLine("</div>");

            Tracer.Add_Trace("Projects_AdminViewer.Add_HTML_In_Main_Form", "Write the rest of the form html");

            // Get the list of all projects
            DataSet projectsSet = SobekCM_Database.Get_All_Projects_Templates(Tracer);

            Output.WriteLine("<!-- Projects_AdminViewer.Add_HTML_In_Main_Form -->");
            Output.WriteLine("<script src=\"" + currentMode.Base_URL + "default/scripts/sobekcm_admin.js\" type=\"text/javascript\"></script>");
            Output.WriteLine("<div class=\"SobekHomeText\">");

            if (actionMessage.Length > 0)
            {
                Output.WriteLine("  <br />");
                Output.WriteLine("  <center><b>" + actionMessage + "</b></center>");
            }

            Output.WriteLine("  <blockquote>For clarification of any terms on this form, <a href=\"" + SobekCM_Library_Settings.Help_URL(currentMode.Base_URL) + "admin/projects\" target=\"PROJECTS_INTERFACE_HELP\" >click here to view the help page</a>.</blockquote>");

            Output.WriteLine("  <span class=\"SobekAdminTitle\">New Project</span>");
            Output.WriteLine("    <blockquote>");
            Output.WriteLine("      <div class=\"admin_project_new_div\">");
            Output.WriteLine("        <table class=\"popup_table\">");

            // Add line for code and base code
            Output.Write("          <tr><td width=\"120px\"><label for=\"admin_project_code\">Project Code:</label></td>");
            Output.Write("<td><input class=\"admin_project_small_input\" name=\"admin_project_code\" id=\"admin_project_code\" type=\"text\" value=\"\"  onfocus=\"javascript:textbox_enter('admin_project_code', 'admin_project_small_input_focused')\" onblur=\"javascript:textbox_leave('admin_project_code', 'admin_project_small_input')\" /></td>");
            Output.Write("<td width=\"285px\" ><label for=\"admin_project_base\">Base Project Code:</label> &nbsp;  <select class=\"admin_project_select\" name=\"admin_project_base\" id=\"admin_project_base\">");
            Output.Write("<option value=\"(none)\" selected=\"selected\">(none)</option>");
            foreach (DataRow thisRow in projectsSet.Tables[0].Rows)
            {
                Output.Write("<option value=\"" + thisRow["ProjectCode"] + "\" >" + thisRow["ProjectCode"] + "</option>");
            }
            Output.WriteLine("</select></td></tr>");

            // Add line for name
            Output.WriteLine("          <tr><td><label for=\"admin_project_name\">Project Name:</label></td><td colspan=\"2\"><input class=\"admin_project_large_input\" name=\"admin_project_name\" id=\"admin_project_name\" type=\"text\" value=\"\" onfocus=\"javascript:textbox_enter('admin_project_name', 'admin_project_large_input_focused')\" onblur=\"javascript:textbox_leave('admin_project_name', 'admin_project_large_input')\" /></td></tr>");
            Output.WriteLine("        </table>");
            Output.WriteLine("        <br />");
            Output.WriteLine("        <center><input type=\"image\" src=\"" + currentMode.Base_URL + "design/skins/" + currentMode.Base_Skin + "/buttons/save_button.gif\" value=\"Submit\" alt=\"Submit\" onclick=\"return save_new_project();\"/></center>");
            Output.WriteLine("      </div>");
            Output.WriteLine("    </blockquote>");
            Output.WriteLine("  <span class=\"SobekAdminTitle\">Existing Projects</span>");
            Output.WriteLine("    <blockquote>");
            Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">");
            Output.WriteLine("  <tr align=\"left\" bgcolor=\"#0022a7\" >");
            Output.WriteLine("    <th width=\"110px\" align=\"left\"><span style=\"color: White\"> &nbsp; ACTIONS</span></th>");
            Output.WriteLine("    <th width=\"140px\" align=\"left\"><span style=\"color: White\">CODE</span></th>");
            Output.WriteLine("    <th width=\"450px\" align=\"left\"><span style=\"color: White\">NAME</span></th>");
            Output.WriteLine("   </tr>");
            Output.WriteLine("  <tr><td bgcolor=\"#e7e7e7\" colspan=\"3\"></td></tr>");

            currentMode.My_Sobek_SubMode = "XXXXXXX";
            string redirect = currentMode.Redirect_URL();

            // Write the data for each interface
            foreach (DataRow thisRow in projectsSet.Tables[0].Rows)
            {
                // Pull all these values
                string code = thisRow["ProjectCode"].ToString();
                string name = thisRow["ProjectName"].ToString();

                // Build the action links
                Output.WriteLine("  <tr align=\"left\" >");
                Output.Write("    <td class=\"SobekAdminActionLink\" >( ");
                Output.Write("<a title=\"Click to edit this project\" id=\"EDIT_" + code + "\" href=\"" + redirect.Replace("XXXXXXX", "1" + code) + "\" >edit</a> | ");
                Output.Write("<a title=\"Click to change the name of this project\" id=\"RENAME_" + code + "\" href=\"" + currentMode.Base_URL + "l/technical/javascriptrequired\" onclick=\"return project_form_popup('RENAME_" + code + "', '" + code + "','" + name + "');\">rename</a> )</td>");

                // Add the rest of the row with data
                Output.WriteLine("    <td>" + code + "</span></td>");
                Output.WriteLine("    <td>" + name + "</span></td>");
                Output.WriteLine("   </tr>");
                Output.WriteLine("  <tr><td bgcolor=\"#e7e7e7\" colspan=\"3\"></td></tr>");
            }

            Output.WriteLine("</table>");
            Output.WriteLine("    </blockquote>");
            Output.WriteLine("    <br />");
            Output.WriteLine("</div>");
            Output.WriteLine();
        }