protected void Page_Load(object sender, EventArgs e)
        {
            WBLogging.Generic.Verbose("In Page_Load for the self approval dialog");

            manager = new WBRecordsManager(SPContext.Current.Web.CurrentUser.LoginName);

            // If this is the initial call to the page then we need to load the basic details of the document we're publishing out:
            if (!IsPostBack)
            {
                process         = WBUtils.DeserializeFromCompressedJSONInURI <WBPublishingProcess>(Request.QueryString["PublishingProcessJSON"]);
                process.WorkBox = WorkBox;

//                WBLogging.Debug("Created the WBProcessObject");

                PublishingProcessJSON.Value = WBUtils.SerializeToCompressedJSONForURI(process);

                //             WBLogging.Debug("Serialized the WBProcessObject to hidden field");
            }
            else
            {
                process         = WBUtils.DeserializeFromCompressedJSONInURI <WBPublishingProcess>(PublishingProcessJSON.Value);
                process.WorkBox = WorkBox;
            }



            // Let's clear out all of the error messages text fields:
            ErrorMessageLabel.Text = "";


            //OK so we have the basic identity information for the document being published out so let's get the document item:

            Guid sourceListGuid            = new Guid(process.ListGUID);
            SPDocumentLibrary sourceDocLib = (SPDocumentLibrary)WorkBox.Web.Lists[sourceListGuid];

            sourceDocAsItem = sourceDocLib.GetItemById(int.Parse(process.CurrentItemID));
            sourceFile      = sourceDocAsItem.File;

            WBDocument sourceDocument = new WBDocument(WorkBox, sourceDocAsItem);

            fileTypeInfo = manager.GetFileTypeInfo(sourceDocument.FileType);

            if (fileTypeInfo != null)
            {
                Dictionary <String, String> checkBoxDetails = manager.GetCheckBoxDetailsForDocumentType(fileTypeInfo.WBxGetAsString(WBColumn.DocumentType));
                foreach (String checkBoxCode in checkBoxDetails.Keys)
                {
                    CheckBoxes.Controls.Add(CreateCheckBoxDiv(checkBoxCode, checkBoxDetails[checkBoxCode]));
                }

                CheckBoxesCodes.Value = String.Join(";", checkBoxDetails.Keys.ToArray <string>());
            }

            if (!IsPostBack)
            {
                DocumentsBeingPublished.Text = process.GetStandardHTMLTableRows();

                String typeText = null;

                if (fileTypeInfo != null)
                {
                    typeText = fileTypeInfo.WBxGetAsString(WBColumn.DocumentType) + " (" + fileTypeInfo.WBxGetAsString(WBColumn.FileTypePrettyName) + ")";
                }
                if (String.IsNullOrEmpty(typeText))
                {
                    typeText = sourceDocument.FileType + " " + sourceDocument.Name;
                }
                DocumentType.Text = typeText;
                WBLogging.Debug("The file type of the record is: " + typeText);

                IAO.Text = "<none found>";
                if (!String.IsNullOrEmpty(process.OwningTeamsIAOAtTimeOfPublishing))
                {
                    SPUser owningTeamIAO = SPContext.Current.Web.WBxEnsureUserOrNull(process.OwningTeamsIAOAtTimeOfPublishing);
                    if (owningTeamIAO != null)
                    {
                        IAO.Text = owningTeamIAO.Name;
                    }
                }
            }
        }
        private void RenderPage()
        {
            if (process == null)
            {
                WBLogging.Debug("process == null");
                return;
            }

            DocumentsBeingPublished.Text = process.GetStandardHTMLTableRows();

            SPListItem currentItem = process.CurrentItem;

            EditShortTitle.Text = process.CurrentShortTitle;
            ShortTitle.Text     = process.CurrentShortTitle;

            WBLogging.Debug("Passed title / name");

            SelectLocationButton.OnClientClick = "WorkBoxFramework_pickANewLocation(WorkBoxFramework_PublishDoc_pickedANewLocation, '" + process.FunctionalAreaUIControlValue + "', '" + process.RecordsTypeUIControlValue + "'); return false;";


            if (!String.IsNullOrEmpty(process.ToReplaceRecordID) && process.ReplaceAction != WBPublishingProcess.REPLACE_ACTION__CREATE_NEW_SERIES)
            {
                recordBeingReplaced = manager.Libraries.GetRecordByID(process.ToReplaceRecordID);
                if (recordBeingReplaced == null)
                {
                    ErrorMessageLabel.Text = "Could not find the record that is meant to be replaced. Supposedly it has RecordID = " + process.ToReplaceRecordID;
                    return;
                }
            }

            if (recordBeingReplaced == null)
            {
                if (documentFunctionalArea != null && documentRecordsType != null)
                {
                    LocationPath.Text = documentFunctionalArea.Name + " / " + documentRecordsType.FullPath.Replace("/", " / ");
                }
                else
                {
                    LocationPath.Text = "<none>";
                }
            }
            else
            {
                LocationPath.Text = process.ToReplaceRecordPath;
            }

            if (recordBeingReplaced == null || process.ReplaceAction == WBPublishingProcess.REPLACE_ACTION__CREATE_NEW_SERIES)
            {
                WBLogging.Debug("Setting buttons etc for NEW");

                NewRadioButton.Checked      = true;
                ReplaceRadioButton.Checked  = false;
                LeaveOnIzziCheckBox.Enabled = true; // Otherwise the surrounding span tag is disabled too! - we'll disable with jQuery!
                SelectLocationButton.Text   = "Choose Location";
                PublishAll.Enabled          = true;

                NewOrReplace.Text = "New";
            }
            else
            {
                WBLogging.Debug("Setting buttons etc for REPLACE");

                NewRadioButton.Checked      = false;
                ReplaceRadioButton.Checked  = true;
                LeaveOnIzziCheckBox.Enabled = true;
                if (process.ReplaceAction == WBPublishingProcess.REPLACE_ACTION__LEAVE_ON_IZZI)
                {
                    LeaveOnIzziCheckBox.Checked = true;
                }
                else
                {
                    LeaveOnIzziCheckBox.Checked = false;
                }
                SelectLocationButton.Text = "Choose Document";
                PublishAll.Enabled        = false;

                NewOrReplace.Text = "Replace";
            }

            WBLogging.Debug("Just before protective zone stage");

            TheProtectiveZone.Text = process.ProtectiveZone;

            if (showSubjectTags)
            {
                if (documentRecordsType == null || documentRecordsType.IsDocumentSubjectTagsRequired)
                {
                    SubjectTagsTitle.Text = "Subject Tags" + WBConstant.REQUIRED_ASTERISK;
                }
                else
                {
                    SubjectTagsTitle.Text = "Subject Tags (optional)";
                }

                if (documentRecordsType != null)
                {
                    SubjectTagsDescription.Text = documentRecordsType.DocumentSubjectTagsDescription;
                }

                process.SubjectTagsTaxonomy.InitialiseTaxonomyControl(SubjectTagsField, WorkBox.COLUMN_NAME__SUBJECT_TAGS, true);
                SubjectTagsField.Text = process.SubjectTagsUIControlValue;
            }

            /*
             * if (showReferenceID)
             * {
             *  if (documentRecordsType.IsDocumentReferenceIDRequired)
             *  {
             *      ReferenceIDTitle.Text = "Reference ID" + WBConstant.REQUIRED_ASTERISK;
             *  }
             *  else
             *  {
             *      ReferenceIDTitle.Text = "Reference ID (optional)";
             *  }
             *  ReferenceIDDescription.Text = documentRecordsType.DocumentReferenceIDDescription;
             *  ReferenceID.Text = sourceDocAsItem.WBxGetColumnAsString(WorkBox.COLUMN_NAME__REFERENCE_ID);
             * }
             *
             * if (showReferenceDate)
             * {
             *  if (documentRecordsType.IsDocumentReferenceDateRequired)
             *  {
             *      ReferenceDateTitle.Text = "Reference Date" + WBConstant.REQUIRED_ASTERISK;
             *  }
             *  else
             *  {
             *      ReferenceDateTitle.Text = "Reference Date (optional)";
             *  }
             *  ReferenceDateDescription.Text = documentRecordsType.DocumentReferenceDateDescription;
             *  if (sourceDocAsItem.WBxColumnHasValue(WorkBox.COLUMN_NAME__REFERENCE_DATE))
             *  {
             *      ReferenceDate.SelectedDate = (DateTime)sourceDocAsItem[WorkBox.COLUMN_NAME__REFERENCE_DATE];
             *  }
             *  else
             *  {
             *      ReferenceDate.SelectedDate = DateTime.Now;
             *  }
             * }
             *
             * if (showSeriesTag)
             * {
             *  if (documentRecordsType.IsDocumentSeriesTagRequired)
             *  {
             *      SeriesTagTitle.Text = "Series Tag" + WBConstant.REQUIRED_ASTERISK;
             *  }
             *  else
             *  {
             *      SeriesTagTitle.Text = "Series Tag (optional)";
             *  }
             *  SeriesTagDescription.Text = documentRecordsType.DocumentSeriesTagDescription;
             *
             *  SeriesTagDropDownList.DataSource = GetSeriesTagDataSource(documentRecordsType.DocumentSeriesTagParentTerm(process.SeriesTagsTaxonomy));
             *  SeriesTagDropDownList.DataTextField = "SeriesTagTermName";
             *  SeriesTagDropDownList.DataValueField = "SeriesTagTermUIControlValue";
             *  SeriesTagDropDownList.DataBind();
             *
             *  if (sourceDocAsItem.WBxColumnHasValue(WorkBox.COLUMN_NAME__SERIES_TAG))
             *  {
             *      SeriesTagDropDownList.SelectedValue = sourceDocAsItem.WBxGetSingleTermColumn<WBTerm>(process.SeriesTagsTaxonomy, WorkBox.COLUMN_NAME__SERIES_TAG).UIControlValue;
             *  }
             * }
             *
             * if (showScanDate)
             * {
             *  if (documentRecordsType.IsDocumentScanDateRequired)
             *  {
             *      ScanDateTitle.Text = "Scan Date" + WBConstant.REQUIRED_ASTERISK;
             *  }
             *  else
             *  {
             *      ScanDateTitle.Text = "Scan Date (optional)";
             *  }
             *  ScanDateDescription.Text = documentRecordsType.DocumentScanDateDescription;
             *  if (sourceDocAsItem.WBxColumnHasValue(WorkBox.COLUMN_NAME__SCAN_DATE))
             *  {
             *      ScanDate.SelectedDate = (DateTime)sourceDocAsItem[WorkBox.COLUMN_NAME__SCAN_DATE];
             *  }
             * }
             */

            WBLogging.Debug("Just owning team");

            process.TeamsTaxonomy.InitialiseTaxonomyControl(OwningTeamField, WorkBox.COLUMN_NAME__OWNING_TEAM, false);
            OwningTeamField.Text = process.OwningTeamUIControlValue;

            WBLogging.Debug("Just involved team");

            process.TeamsTaxonomy.InitialiseTaxonomyControl(InvolvedTeamsField, WorkBox.COLUMN_NAME__INVOLVED_TEAMS, true);
            InvolvedTeamsField.Text = process.InvolvedTeamsWithoutOwningTeamAsUIControlValue;

            if (process.ProtectiveZone == WBRecordsType.PROTECTIVE_ZONE__PUBLIC)
            {
                WebPageURL.Text = process.WebPageURL;
                showWebPageURL  = true;
            }
            else
            {
                WebPageURL.Text    = "";
                process.WebPageURL = "";
                showWebPageURL     = false;
            }


            if (process.CountStillToPublish > 1)
            {
                if (process.ProtectiveZone == WBRecordsType.PROTECTIVE_ZONE__PROTECTED)
                {
                    showPublishAllButton = manager.AllowBulkPublishOfFileTypes(process.DifferentFileTypesStillToPublish);
                }
                else
                {
                    showPublishAllButton = manager.AllowBulkPublishToPublicOfFileTypes(process.DifferentFileTypesStillToPublish);
                }
            }
            else
            {
                showPublishAllButton = false;
            }


            WBLogging.Debug("Just before serialization");

            // Lastly we're going to capture the state of the publishing process:
            PublishingProcessJSON.Value = WBUtils.SerializeToCompressedJSONForURI(process);
        }