using System; using System.Data; using System.Collections; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.DocumentEngine; using CMS.UIControls; using CMS.URLRewritingEngine; public partial class CMSWebParts_General_AdminActions : CMSAbstractWebPart { #region "Properties" /// /// Indicates whether on-site editing is preferred for document editing if is available /// public bool PreferOnSiteEdit { get { return ValidationHelper.GetBoolean(GetValue("PreferOnSiteEdit"), true); } set { SetValue("PreferOnSiteEdit", value); } } /// /// Display only to global administrator. /// public bool DisplayOnlyToGlobalAdministrator { get { return ValidationHelper.GetBoolean(GetValue("DisplayOnlyToGlobalAdministrator"), false); } set { SetValue("DisplayOnlyToGlobalAdministrator", value); } } /// /// Check permissions. /// public bool CheckPermissions { get { return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), false); } set { SetValue("CheckPermissions", value); } } /// /// Separator. /// public string Separator { get { return ValidationHelper.GetString(GetValue("Separator"), null); } set { SetValue("Separator", value); } } /// /// Show cms desk link. /// public bool ShowCMSDeskLink { get { return ValidationHelper.GetBoolean(GetValue("ShowCMSDeskLink"), true); } set { SetValue("ShowCMSDeskLink", value); } } /// /// CMS Desk link text. /// public string CMSDeskLinkText { get { return ValidationHelper.GetString(GetValue("CMSDeskLinkText"), "CMS Desk"); } set { SetValue("CMSDeskLinkText", value); } } /// /// CMS Desk text. /// public string CMSDeskText { get { return ValidationHelper.GetString(GetValue("CMSDeskText"), "{0}"); } set { SetValue("CMSDeskText", value); } } /// /// Show site manager link. /// public bool ShowCMSSiteManagerLink { get { return ValidationHelper.GetBoolean(GetValue("ShowCMSSiteManagerLink"), true); } set { SetValue("ShowCMSSiteManagerLink", value); } } /// /// Site manager link text. /// public string CMSSiteManagerLinkText { get { return ValidationHelper.GetString(GetValue("CMSSiteManagerLinkText"), "Site manager"); } set { SetValue("CMSSiteManagerLinkText", value); } } /// /// Site manager text. /// public string CMSSiteManagerText { get { return ValidationHelper.GetString(GetValue("CMSSiteManagerText"), "{0}"); } set { SetValue("CMSSiteManagerText", value); } } /// /// Show edit document link. /// public bool ShowEditDocumentLink { get { return ValidationHelper.GetBoolean(GetValue("ShowEditDocumentLink"), false); } set { SetValue("ShowEditDocumentLink", value); } } /// /// Edit document link text. /// public string EditDocumentLinkText { get { return ValidationHelper.GetString(GetValue("EditDocumentLinkText"), "Edit document"); } set { SetValue("EditDocumentLinkText", value); } } /// /// Edit document text. /// public string EditDocumentText { get { return ValidationHelper.GetString(GetValue("EditDocumentText"), "{0}"); } set { SetValue("EditDocumentText", value); } } /// /// Default user name for logon page. /// public string DefaultUserName { get { return ValidationHelper.GetString(GetValue("DefaultUserName"), null); } set { SetValue("DefaultUserName", value); } } #endregion #region "Methods" /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do not process } else { CurrentUserInfo uinfo = CMSContext.CurrentUser; if (uinfo.IsGlobalAdministrator || !DisplayOnlyToGlobalAdministrator) { // Create new string builder for links StringBuilder sb = new StringBuilder(); // Store current site name string curSiteName = CMSContext.CurrentSiteName; // Get default user name string queryStringKey = (string.IsNullOrEmpty(DefaultUserName)) ? null : "?username=" + DefaultUserName; bool separatorNeeded = false; // If cms desk link is shown if (ShowCMSDeskLink && (!CheckPermissions || uinfo.CheckEditor(curSiteName))) { string url = ResolveUrl("~/cmsdesk/default.aspx"); if (!string.IsNullOrEmpty(DefaultUserName)) { url = URLHelper.AddParameterToUrl(url, "username", DefaultUserName); } if (CMSContext.CurrentPageInfo != null) { url = URLHelper.AddParameterToUrl(url, "nodeid", CMSContext.CurrentPageInfo.NodeID.ToString()); } sb.AppendFormat(CMSDeskText, string.Concat("", CMSDeskLinkText, "")); separatorNeeded = true; } // If site manager link is shown if (ShowCMSSiteManagerLink && (!CheckPermissions || uinfo.UserSiteManagerAdmin)) { // Check if separator needed if (separatorNeeded) { sb.Append(Separator); } string url = ResolveUrl("~/cmssitemanager/default.aspx"); if (!string.IsNullOrEmpty(DefaultUserName)) { url = URLHelper.AddParameterToUrl(url, "username", DefaultUserName); } sb.AppendFormat(CMSSiteManagerText, string.Concat("", CMSSiteManagerLinkText, "")); separatorNeeded = true; } // If edit document link is shown if (ShowEditDocumentLink && (!CheckPermissions || (uinfo.CheckEditor(curSiteName) && CMSPage.IsUserAuthorizedPerContent() && (uinfo.IsAuthorizedPerDocument(CMSContext.CurrentDocument, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))) { // Check if separator needed if (separatorNeeded) { sb.Append(" " + Separator + " "); } string url = URLHelper.EncodeQueryString(UIHelper.GetDocumentEditUrl(CMSContext.CurrentDocument.NodeID, CMSContext.CurrentDocumentCulture.CultureCode)); if (PreferOnSiteEdit && PortalHelper.IsOnSiteEditingEnabled(CurrentSiteName)) { url = URLHelper.ResolveUrl(PortalHelper.OnSiteEditRelativeURL); string retUrl = URLHelper.CurrentURL; // handle default alias path if ((ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite) && (URLRewriter.CurrentPageInfoSource == PageInfoSource.DefaultAliasPath)) { string aliasPath = PageInfoProvider.GetDefaultAliasPath(URLHelper.GetCurrentDomain(), CMSContext.CurrentSiteName); if (!String.IsNullOrEmpty(aliasPath)) { string query = URLHelper.GetQuery(retUrl); retUrl = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(aliasPath)); retUrl = URLHelper.AppendQuery(retUrl, query); } } url = URLHelper.UpdateParameterInUrl(url, "returnurl", HTMLHelper.HTMLEncode(HttpUtility.UrlEncode(retUrl))); } sb.AppendFormat(EditDocumentText, string.Concat("", EditDocumentLinkText, "")); } ltlAdminActions.Text = sb.ToString(); } } } /// /// Reloads the control data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } #endregion }