//public ViewMode Mode { get; set; }

        protected void AddItem_Click(object sender, EventArgs e)
        {
            var field = GetField();

            var media = MediasMapper.GetByID(field.MediaDetail.MediaID);

            var fieldAssociation = new FieldAssociation();

            fieldAssociation.MediaDetail = (MediaDetail)PagesMapper.CreateObject(MediaTypeID, MediasMapper.CreateObject(), media);
            fieldAssociation.MediaDetail.SectionTitle              = fieldAssociation.MediaDetail.ShortDescription = fieldAssociation.MediaDetail.MainContent = fieldAssociation.MediaDetail.LinkTitle;
            fieldAssociation.MediaDetail.PathToFile                = "/media/images/icons/File.jpg";
            fieldAssociation.MediaDetail.PublishDate               = DateTime.Now;
            fieldAssociation.MediaDetail.CreatedByUserID           = fieldAssociation.MediaDetail.LastUpdatedByUserID = FrameworkSettings.CurrentUser.ID;
            fieldAssociation.MediaDetail.CachedVirtualPath         = fieldAssociation.MediaDetail.CalculatedVirtualPath();
            fieldAssociation.MediaDetail.LanguageID                = AdminBasePage.CurrentLanguage.ID;
            fieldAssociation.MediaDetail.UseDefaultLanguageLayouts = false;

            var mediaType = MediaTypesMapper.GetByID(fieldAssociation.MediaDetail.MediaTypeID);

            if (mediaType != null)
            {
                fieldAssociation.MediaDetail.UseMediaTypeLayouts = mediaType.UseMediaTypeLayouts;
            }

            field.FieldAssociations.Add(fieldAssociation);
            var returnObj = BaseMapper.SaveDataModel();

            BindValues();
        }
        public void UpdateFieldsFromObject()
        {
            MediaDetailID.Text = selectedItem.ID.ToString();
            MediaID.Text       = selectedItem.MediaID.ToString();

            Handler.SetValue(selectedItem.Handler);
            MediaTypeID.Text      = selectedItem.MediaTypeID.ToString();
            MediaType.Text        = MediaTypesMapper.GetByID(selectedItem.MediaTypeID).Name.ToString();
            EnableCaching.Checked = selectedItem.EnableCaching;

            if (selectedItem.LastUpdatedByUserID != 0)
            {
                LastModifiedByUser.Text = UsersMapper.GetByID(selectedItem.LastUpdatedByUserID).UserName;
            }

            if (selectedItem.CreatedByUserID != 0)
            {
                CreatedByUser.Text = UsersMapper.GetByID(selectedItem.CreatedByUserID).UserName;
            }

            if (selectedItem.ID != 0)
            {
                OrderIndex.Text = MediasMapper.GetByMediaDetail(selectedItem).OrderIndex.ToString();
            }

            MasterPageSelector.SelectedValue = selectedItem.MasterPageID.ToString();
        }
Esempio n. 3
0
        /*protected override void OnPreRender(EventArgs e)
         * {
         *  base.OnPreRender(e);
         *
         *  if (!IsPostBack)
         *      UpdateFieldsFromObject();
         * }*/

        private void UpdateSectionTitles()
        {
            string title        = "";
            string sectionTitle = "";

            if (selectedItem.ID == 0)
            {
                string       under      = "Root";
                IMediaDetail atleastOne = null;

                if (parentMediaItem != null)
                {
                    atleastOne = MediaDetailsMapper.GetAtleastOneByMedia(parentMediaItem, CurrentLanguage);
                }

                if ((parentMediaItem != null) && (atleastOne != null))
                {
                    under = atleastOne.LinkTitle;
                }

                sectionTitle = "Creating: <span>New Media of Type '" + MediaTypesMapper.GetByID(mediaTypeId).Name + "' Under '" + under + "' with Language '" + CurrentLanguage.Name + "'</span>";
                title        = StringHelper.StripHtmlTags(sectionTitle);
            }
            else
            {
                title        = "Editing: " + selectedItem.LinkTitle;
                sectionTitle = "Editing: <span>" + selectedItem.LinkTitle + "</span>";
            }

            this.Page.Title        = title;
            this.SectionTitle.Text = sectionTitle;
        }
Esempio n. 4
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!BaseMapper.GetDataModel().MediaDetails.Any())
            {
                var rootMediaType = MediaTypesMapper.GetByEnum(MediaTypeEnum.RootPage);

                if (rootMediaType != null)
                {
                    MediaTypeSelector.SetMediaTypes(new List <MediaType>()
                    {
                        rootMediaType
                    });
                }
            }
            else
            {
                if (SelectedMedia != null)
                {
                    MediaType mediaType = MediaTypesMapper.GetByID(MediaDetailsMapper.GetAtleastOneByMedia(SelectedMedia, CurrentLanguage).MediaTypeID);
                    MediaTypeSelector.SetMediaTypes(mediaType.MediaTypes);
                }
            }
        }
Esempio n. 5
0
        public void UpdateFieldsFromObject()
        {
            IMediaDetail item = (IMediaDetail)SelectedItem;

            if ((item.ID == 0) && (item.LinkTitle == null || item.LinkTitle == ""))
            {
                var mediaType    = MediaTypesMapper.GetByID(item.MediaTypeID);
                var createdItems = mediaType.MediaDetails.Where(i => !i.IsHistory && i.Media.ParentMediaID == item.Media.ParentMediaID && i.LanguageID == AdminBasePage.CurrentLanguage.ID).Select(i => i);

                var newIndex = createdItems.Count() + 1;

                item.LinkTitle = AdminBasePage.CurrentLanguage.DisplayName + " - " + mediaType.Name + " " + newIndex;
            }

            LinkTitle.Text = item.LinkTitle;

            var virtualPath = item.AutoCalculatedVirtualPath;

            /*if (LanguagesMapper.GetAllActive().Count() > 1)
             *  virtualPath = URIHelper.ConvertAbsUrlToTilda(URIHelper.ConvertToAbsUrl(virtualPath).Replace(URIHelper.BaseUrl, URIHelper.BaseUrlWithLanguage));*/

            VirtualPath.Text        = virtualPath;
            VirtualPath.NavigateUrl = URIHelper.ConvertToAbsUrl(virtualPath) + "?version=" + item.HistoryVersionNumber;

            UpdateTags();

            UpdateTabsFieldsFromObject();

            UpdateMediaFieldsFromObject();

            //SEOSettingsTab.UpdateFieldsFromObject();
            //PublishSettingsTab.UpdateFieldsFromObject();
        }
Esempio n. 6
0
        public void SetItem(IMediaDetail item)
        {
            this.selectedItem = item;
            var mediaTypeRoles = MediaTypesMapper.GetByID(item.MediaTypeID).GetRoles();

            if (mediaTypeRoles.Count() > 0)
            {
                RolePermissionsSelector.SetRoles(mediaTypeRoles);
            }
        }
Esempio n. 7
0
        protected void PublishNow_OnClick(object sender, EventArgs e)
        {
            if (!CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error publishing item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to publish items")));
                return;
            }

            selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

            if (selectedItem == null)
            {
                return;
            }

            var mediaType = MediaTypesMapper.GetByID(selectedItem.MediaTypeID);

            selectedItem.PublishDate = DateTime.Now;

            if (selectedItem.ExpiryDate != null)
            {
                selectedItem.ExpiryDate = null;
            }

            selectedItem.ShowInMenu          = mediaType.ShowInMenu;
            selectedItem.ShowInSearchResults = mediaType.ShowInSearchResults;
            selectedItem.EnableCaching       = mediaType.EnableCaching;

            Return returnObj = MediaDetailsMapper.Update(selectedItem);

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Publishing Item", returnObj.Error);
            }
            else
            {
                DisplaySuccessMessage("Successfully Published Item");

                var mediaId = (selectedItem.Media.ParentMediaID != null) ? selectedItem.Media.ParentMediaID : selectedItem.MediaID;

                ExecuteRawJS("RefreshSiteTreeNodeById(" + mediaId + "); ReloadPreviewPanel();");

                UpdateFieldsFromObject();

                PublishNow.Visible = false;
                ContextHelper.Clear(ContextType.Cache);
                FileCacheHelper.ClearAllCache();
            }

            UpdateFieldsFromObject();

            OnPublishExecuteCode();
        }
Esempio n. 8
0
        protected void Page_init(object sender, EventArgs e)
        {
            long id;

            if (long.TryParse(Request["id"], out id))
            {
                selectedItem = MediaTypesMapper.GetByID(id);

                if (!IsPostBack)
                {
                    UpdateFieldsFromObject();
                }
            }

            MediaTypeFieldsEditor.SetItems(selectedItem);

            this.Page.Title = this.SectionTitle.Text = GetSectionTitle();
        }
Esempio n. 9
0
        public string DeleteItemPermanently(long id)
        {
            MediaType item = BaseMapper.GetObjectFromContext(MediaTypesMapper.GetByID(id));

            if (item != null)
            {
                Return returnObj = MediaTypesMapper.DeletePermanently(item);

                if (returnObj.IsError)
                {
                    return(jGrowlHelper.GenerateCode(new jGrowlMessage("Error", "Error deleting item permanently", jGrowlMessage.jGrowlMessageType.Error, returnObj.Error), true));
                }
                else
                {
                    return(jGrowlHelper.GenerateCode(new jGrowlMessage("Success", "Item was successfully deleted permanently", jGrowlMessage.jGrowlMessageType.Success), false));
                }
            }

            return("");
        }
Esempio n. 10
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            RedisCacheHelper.SetRedisCacheConnectionString(AppSettings.RedisCacheConnectionString);
            FileCacheHelper.SetFileSystemCacheDirPath(AppSettings.FileSystemCacheDirPath);

            virtualPath = URIHelper.GetCurrentVirtualPath().ToLower();

            var queryString = HttpContext.Current.Request.QueryString.ToString();

            queryString = System.Web.HttpUtility.UrlDecode(queryString);


            if (!Request.Path.EndsWith("/") || ((virtualPath != "~/") && (!virtualPath.EndsWith("/"))))
            {
                var path = Request.Path + "/";

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                HttpContext.Current.Response.RedirectPermanent(path);
            }

            Settings cmsSettings            = null;
            bool     isAttemptingAdminLogin = false;

            if ((virtualPath != "~/login/") && (virtualPath != "~/admin/") && string.IsNullOrEmpty(Request.QueryString["format"]))
            {
                cmsSettings = SettingsMapper.GetSettings();

                if (cmsSettings != null)
                {
                    var isSiteOnline = cmsSettings.IsSiteOnline();

                    if (isSiteOnline)
                    {
                        if (virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect("~/");
                        }

                        AttemptToLoadFromCache();
                    }
                    else
                    {
                        if (!virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect(cmsSettings.SiteOfflineUrl);
                        }
                    }
                }
                else
                {
                    AttemptToLoadFromCache();
                }
            }
            else
            {
                isAttemptingAdminLogin = true;
            }

            var languageSegment = FrameworkSettings.GetCurrentLanguage().UriSegment;

            if (LanguagesMapper.GetAllActive().Count() > 1 && !Request.Url.PathAndQuery.Contains($"/{languageSegment}/"))
            {
                var url = URIHelper.ConvertToAbsUrl("/" + languageSegment + Request.Url.PathAndQuery);
                Response.RedirectPermanent(url, true);
            }

            var segments = URIHelper.GetUriSegments(virtualPath).ToList();

            string firstSegment = "";

            if (segments.Count > 0)
            {
                firstSegment = segments[0];

                var language = LanguagesMapper.GetAllActive().SingleOrDefault(i => i.UriSegment == firstSegment);

                if (language != null)
                {
                    FrameworkSettings.SetCurrentLanguage(language);
                }
            }

            if (!isAttemptingAdminLogin && AppSettings.EnableUrlRedirectRules)
            {
                var path = virtualPath;

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                var redirectRule = UrlRedirectRulesMapper.GetRuleForUrl(path);

                if (redirectRule != null)
                {
                    var newUrl = redirectRule.RedirectToUrl;

                    if (newUrl.Contains("{"))
                    {
                        newUrl = MediaDetailsMapper.ParseSpecialTags(redirectRule, newUrl);
                    }

                    newUrl = URIHelper.ConvertToAbsUrl(newUrl);

                    var possibleLoopRules      = UrlRedirectRulesMapper.GetRulesFromUrl(URIHelper.ConvertAbsUrlToTilda(newUrl));
                    var foundActiveVirtualPath = MediaDetailsMapper.GetByVirtualPath(path);

                    if (possibleLoopRules.Any())
                    {
                        foreach (var rule in possibleLoopRules)
                        {
                            var returnObj = MediaDetailsMapper.DeletePermanently(rule);
                        }
                    }

                    if (foundActiveVirtualPath != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(redirectRule);
                    }

                    if (Request.QueryString.Count > 0)
                    {
                        newUrl += "?" + Request.QueryString;
                    }

                    if (redirectRule.Is301Redirect)
                    {
                        Response.RedirectPermanent(newUrl);
                    }
                    else
                    {
                        Response.Redirect(newUrl);
                    }
                }
            }

            if (!File.Exists(HttpContext.Current.Server.MapPath(virtualPath)) && !virtualPath.Contains(ParserHelper.OpenToken) && !virtualPath.Contains(ParserHelper.CloseToken))
            {
                string viewPath = "";

                long mediaDetailId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaDetailID"], out mediaDetailId);

                long mediaId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaID"], out mediaId);

                MediaDetail detail = null;

                if (mediaDetailId == 0 && mediaId == 0)
                {
                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByVirtualPath(virtualPath, true);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaDetailId != 0)
                {
                    var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(mediaDetail);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaId != 0)
                {
                    var media = MediasMapper.GetByID(mediaId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMedia(media);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }

                /*if (detail != null && !detail.CanUserAccessSection(FrameworkSettings.CurrentUser))
                 * {
                 *  FormsAuthentication.RedirectToLoginPage();
                 * }*/

                /*if (detail != null)
                 * {
                 *  var absUrlBase = URIHelper.ConvertAbsUrlToTilda(detail.AbsoluteUrl).Replace("~", "");
                 *  var absPathBase = URIHelper.ConvertAbsUrlToTilda(Request.Url.AbsolutePath).Replace("~", "");
                 *
                 *  if (absUrlBase != absPathBase)
                 *  {
                 *      Response.Redirect(detail.AbsoluteUrl + Request.Url.Query);
                 *  }
                 * }*/

                if (detail != null)
                {
                    if (detail.ForceSSL || AppSettings.ForceSSL)
                    {
                        URIHelper.ForceSSL();
                    }
                }
                else
                {
                    var currentLanguageId = FrameworkSettings.GetCurrentLanguage().ID;

                    var historyVersion = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.LanguageID == currentLanguageId && i.CachedVirtualPath == virtualPath && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber != 0 && i.HistoryForMediaDetail != null);

                    if (historyVersion != null && historyVersion.VirtualPath != historyVersion.HistoryForMediaDetail.VirtualPath)
                    {
                        var foundRedirectUrl = UrlRedirectRulesMapper.GetRuleForUrl(virtualPath);

                        if (foundRedirectUrl == null)
                        {
                            var urlRedirectRule = UrlRedirectRulesMapper.CreateUrlRedirect(virtualPath, historyVersion.HistoryForMediaDetail.Media);

                            if (urlRedirectRule != null)
                            {
                                var returnObj = UrlRedirectRulesMapper.Insert(urlRedirectRule);
                                HttpContext.Current.Response.RedirectPermanent(historyVersion.HistoryForMediaDetail.CachedVirtualPath);
                            }
                            else
                            {
                                HttpContext.Current.Response.RedirectPermanent("/");
                            }
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.RedirectPermanent("/");
                    }
                }

                if ((detail == null) || (!IsValidRequest(detail)))
                {
                    detail = null;
                    if (cmsSettings != null)
                    {
                        if (!string.IsNullOrEmpty(cmsSettings.PageNotFoundUrl))
                        {
                            ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));

                            Response.Redirect(cmsSettings.PageNotFoundUrl);

                            /*FrameworkSettings.CurrentFrameworkBaseMedia = null;
                             *
                             * FrameworkSettings.CurrentFrameworkBaseMedia = FrameworkBaseMedia.GetInstanceByVirtualPath(cmsSettings.PageNotFoundUrl, true);
                             * detail = (MediaDetail)FrameworkSettings.CurrentFrameworkBaseMedia.CurrentMediaDetail;
                             *
                             * ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));*/

                            //Response.StatusCode = 301;
                        }
                    }
                }

                if (detail != null)
                {
                    var draft = detail.GetLatestDraft();

                    if (draft != null && (draft.PublishDate - detail.PublishDate) > TimeSpan.FromSeconds(10) && draft.CanRender)
                    {
                        var returnObj = draft.PublishLive();

                        if (!returnObj.IsError)
                        {
                            detail.RemoveFromCache();
                            draft.RemoveFromCache();

                            FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(draft);
                            detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                        }
                    }

                    if (detail.RedirectToFirstChild)
                    {
                        var child = detail.ChildMediaDetails.FirstOrDefault();

                        if (child != null)
                        {
                            var redirectPath = child.AutoCalculatedVirtualPath;

                            if (!string.IsNullOrEmpty(queryString))
                            {
                                redirectPath = redirectPath + "?" + queryString;
                            }

                            HttpContext.Current.Response.Redirect(redirectPath);
                        }
                    }

                    viewPath = FrameworkSettings.Current.CurrentMediaDetail.Handler;

                    if ((viewPath == null) || (viewPath.Trim() == ""))
                    {
                        viewPath = MediaTypesMapper.GetByID(FrameworkSettings.Current.CurrentMediaDetail.MediaTypeID).MediaTypeHandler;
                    }

                    viewPath = URIHelper.ConvertAbsUrlToTilda(viewPath);

                    if (!string.IsNullOrEmpty(Request.QueryString["format"]))
                    {
                        FrontEndBasePage.HandleFormatQueryString(detail, Request.QueryString["format"], Request.QueryString["depth"]);
                    }

                    return(CreateInstanceFromVirtualPath(viewPath, typeof(BasePage)));
                }
            }

            return(new DefaultHttpHandler());
        }
Esempio n. 11
0
 public MediaType GetSelectedMediaType()
 {
     return(MediaTypesMapper.GetByID(long.Parse(MediaTypes.SelectedValue)));
 }
Esempio n. 12
0
        protected void Page_Init(object sender, EventArgs e)
        {
            long id;
            long parentId;

            long.TryParse(Request["historyVersion"], out historyVersion);
            long.TryParse(Request["mediaTypeId"], out mediaTypeId);

            if (long.TryParse(Request["selectedMediaId"], out id))
            {
                selectedMediaItem = MediasMapper.GetByID(id);
                SelectedMedia     = selectedMediaItem;

                if (selectedMediaItem != null)
                {
                    selectedItem = MediaDetailsMapper.GetByMedia(selectedMediaItem, CurrentLanguage);

                    if (historyVersion > 0)
                    {
                        selectedItem       = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);
                        historyVersionItem = BaseMapper.GetObjectFromContext((MediaDetail)MediaDetailsMapper.GetByMedia(selectedMediaItem, CurrentLanguage, historyVersion));
                    }

                    if ((selectedItem != null) && (historyVersionItem != null))
                    {
                        tmpSelectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);
                        selectedItem    = historyVersionItem;
                    }
                }
            }

            if (long.TryParse(Request["parentMediaId"], out parentId))
            {
                parentMediaItem = MediasMapper.GetByID(parentId);
            }

            if (selectedItem == null)
            {
                if (parentMediaItem != null)
                {
                    SelectedMedia = parentMediaItem;
                }

                /*if (parentMediaItem == null)
                 *  return;*/

                selectedItem = MediaDetailsMapper.CreateObject(mediaTypeId, selectedMediaItem, parentMediaItem);
            }

            Return canAccessReturnObj = BaseMapper.GenerateReturn();

            if (selectedItem.ID != 0)
            {
                canAccessReturnObj = MediaDetailsMapper.CanAccessMediaDetail(selectedItem, CurrentUser);
                if (canAccessReturnObj.IsError)
                {
                    DisplayErrorMessage("Cannot edit item", canAccessReturnObj.Error);

                    CanAccessItem = canAccessReturnObj;

                    return;
                }
                else
                {
                    KeyValuePair <IMediaDetail, User> checkedOutItem = IsCheckedOut(selectedItem);

                    if (checkedOutItem.Key == null)
                    {
                        CheckOut(selectedItem);
                    }
                    else
                    {
                        if (checkedOutItem.Value.ID != CurrentUser.ID)
                        {
                            Return returnObj = BaseMapper.GenerateReturn("Cannot edit item", "The item has been checked out by user: ( " + checkedOutItem.Value.UserName + " )");

                            CanAccessItem = returnObj;

                            DisplayErrorMessage("Error", returnObj.Error);

                            return;
                        }
                    }
                }
            }

            SelectedMediaDetail = selectedItem;
            SelectedMedia       = selectedMediaItem;

            if (selectedMediaItem == null)
            {
                SelectedMedia = parentMediaItem;
            }

            if (selectedItem.ID == 0)
            {
                Save.Text           = "Create";
                SaveAndPublish.Text = "Create And Publish";

                LoadLatestDraft.Visible = false;
                CreateDraft.Visible     = false;

                var mediaType = MediaTypesMapper.GetByID(selectedItem.MediaTypeID);

                if (mediaType == null)
                {
                    return;
                }

                selectedItem.MainLayout     = mediaType.MainLayout;
                selectedItem.SummaryLayout  = mediaType.SummaryLayout;
                selectedItem.FeaturedLayout = mediaType.FeaturedLayout;

                selectedItem.UseMediaTypeLayouts = mediaType.UseMediaTypeLayouts;

                var liveMediaDetail = selectedItem.Media?.GetLiveMediaDetail();

                if (liveMediaDetail != null)
                {
                    selectedItem.CopyFrom(liveMediaDetail);

                    var fieldsNotInMediaType = liveMediaDetail.Fields.Where(i => i.MediaTypeFieldID == null);

                    if (fieldsNotInMediaType != null)
                    {
                        foreach (var field in fieldsNotInMediaType)
                        {
                            var newField = new MediaDetailField();
                            newField.CopyFrom(field);

                            if (field.FieldAssociations.Count > 0)
                            {
                                newField.FieldValue = "";
                            }
                            else
                            {
                                newField.FieldValue = field.FieldValue;
                            }

                            newField.DateCreated      = DateTime.Now;
                            newField.DateLastModified = DateTime.Now;

                            selectedItem.Fields.Add(newField);
                        }
                    }

                    var fieldsThatCanBeCopied = liveMediaDetail.Fields.Where(i => !i.FieldAssociations.Any());

                    foreach (var field in fieldsThatCanBeCopied)
                    {
                        var foundField = selectedItem.Fields.FirstOrDefault(i => i.FieldCode == field.FieldCode);

                        if (foundField != null)
                        {
                            foundField.CopyFrom(field);
                        }
                    }
                }
            }
            else
            {
                Save.Text           = "Save Page";
                SaveAndPublish.Text = "Save And Publish";
            }

            if ((historyVersion > 0) && (historyVersionItem != null) && (!historyVersionItem.IsDraft))
            {
                //SavePanel.Visible = false;
            }
            else
            {
                var draftItems = selectedItem.History.Where(i => i.IsDraft);

                if (draftItems.Count() > 0)
                {
                    LoadLatestDraft.Visible = true;
                    CreateDraft.Visible     = false;
                }

                SaveAndPublish.Visible = true;
                SavePanel.Visible      = true;

                HistoryPanel.Visible = false;
            }

            if (historyVersion > 0)
            {
                SavePanel.Visible = true;

                if (!selectedItem.IsDraft)
                {
                    Save.Visible = false;
                }

                CreateDraft.Visible = false;
                PublishNow.Visible  = false;
                PublishLive.Visible = true;

                HistoryPanel.Visible      = true;
                HistoryVersionNumber.Text = historyVersion.ToString();
            }

            if (CurrentUser.IsInRole(RoleEnum.Developer))
            {
                EditMediaType.NavigateUrl = "~/Admin/Views/PageHandlers/MediaTypes/Detail.aspx?id=" + SelectedMediaDetail.MediaTypeID;
                EditMediaType.Visible     = true;
            }

            Panel.SetObject(SelectedMediaDetail);

            if (Request.QueryString["masterFilePath"] != null)
            {
                PreviewPanel.Visible             = false;
                RemovePreviewPanelScript.Visible = true;
            }
            else
            {
                PreviewPanel.Visible             = true;
                RemovePreviewPanelScript.Visible = false;
            }

            UpdateSectionTitles();
        }