using System;
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;
using TreeNode = CMS.DocumentEngine.TreeNode;
public partial class CMSWebParts_General_EditDocumentLink : CMSAbstractWebPart
{
#region "Web part 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);
}
}
///
/// URL to the image
///
public string ImageURL
{
get
{
return ValidationHelper.GetString(GetValue("ImageURL"), String.Empty);
}
set
{
SetValue("ImageURL", value);
}
}
///
/// Text of the link.
///
public string LinkText
{
get
{
return ValidationHelper.GetString(GetValue("LinkText"), String.Empty);
}
set
{
SetValue("LinkText", value);
}
}
///
/// Indicates if the link should be available only for users who have the access to the CMS Desk and rights to edit the current document.
///
public bool ShowOnlyWhenAuthorized
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowOnlyWhenAuthorized"), false);
}
set
{
SetValue("ShowOnlyWhenAuthorized", value);
}
}
#endregion
#region "Web part methods"
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (!StopProcessing)
{
bool show = true;
TreeNode curDoc = CMSContext.CurrentDocument;
// Check if permissions should be checked
if (ShowOnlyWhenAuthorized)
{
// Check permissions
if (!((CMSContext.CurrentUser.IsEditor || CMSContext.CurrentUser.IsGlobalAdministrator) && CMSPage.IsUserAuthorizedPerContent() && (CMSContext.CurrentUser.IsAuthorizedPerDocument(curDoc, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))
{
show = false;
Visible = false;
}
}
if (show)
{
// Create edit link
StringBuilder sb = new StringBuilder("");
// Text link
if (String.IsNullOrEmpty(ImageURL))
{
sb.Append(LinkText);
}
// Image link
else
{
sb.Append("
");
}
sb.Append("");
ltlEditLink.Text = sb.ToString();
}
}
}
#endregion
}