using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.Notifications;
using CMS.SettingsProvider;
using CMS.UIControls;
public partial class CMSModules_Notifications_Controls_UserNotifications : CMSAdminControl
{
#region "Variables"
private int mUserId = 0;
private int mSiteId = 0;
private int mDisplayNameLength = 50;
private string mZeroRowsText = "";
#endregion
#region "Properties"
///
/// Maximum length of the displayname (whole display name is displayed in tooltip).
///
public int DisplayNameLength
{
get
{
return mDisplayNameLength;
}
set
{
mDisplayNameLength = value;
}
}
///
/// User id.
///
public int UserId
{
get
{
return mUserId;
}
set
{
mUserId = value;
}
}
///
/// Text displayed when no notifications exist.
///
public string ZeroRowsText
{
get
{
if (mZeroRowsText == "")
{
mZeroRowsText = GetString("notifications.userhasnonotifications");
}
return mZeroRowsText;
}
set
{
mZeroRowsText = value;
}
}
///
/// Gets or sets directory path for images.
///
public string UnigridImageDirectory
{
get
{
return ValidationHelper.GetString(ViewState["UnigridImageDirectory"], null);
}
set
{
ViewState["UnigridImageDirectory"] = value;
}
}
///
/// Site ID (If this value is set, then only subscriptions for specified site and global subscriptions are
/// displayed, If this value equals to zero then all subscriptions are displayed).
///
public int SiteID
{
get
{
return mSiteId;
}
set
{
mSiteId = value;
}
}
#endregion
#region "Page Events"
protected void Page_Load(object sender, EventArgs e)
{
gridElem.IsLiveSite = IsLiveSite;
// In design mode is pocessing of control stoped
if (StopProcessing)
{
// Do nothing
gridElem.StopProcessing = true;
gridElem.Visible = false;
}
else
{
if (UnigridImageDirectory != null)
{
gridElem.ImageDirectoryPath = UnigridImageDirectory;
}
gridElem.ZeroRowsText = ZeroRowsText;
gridElem.OnExternalDataBound += new OnExternalDataBoundEventHandler(gridElem_OnExternalDataBound);
gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction);
gridElem.WhereCondition = "(SubscriptionUserID = " + UserId + (SiteID > 0 ? " AND (SubscriptionSiteID IS NULL OR SubscriptionSiteID = " + SiteID + "))" : ")");
// Set pager links text on live site
if (IsLiveSite)
{
gridElem.Pager.FirstPageText = "<<";
gridElem.Pager.LastPageText = ">>";
gridElem.Pager.PreviousPageText = "<";
gridElem.Pager.NextPageText = ">";
gridElem.Pager.PreviousGroupText = "...";
gridElem.Pager.NextGroupText = "...";
}
}
}
#endregion
#region "UniGrid Events"
///
/// Handles Unigrid's OnExternalDataBound event.
///
protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
{
switch (sourceName.ToLowerCSafe())
{
case "subscriptioneventdisplayname":
string displayName = Convert.ToString(parameter);
if (displayName.Length <= DisplayNameLength)
{
return HTMLHelper.HTMLEncode(displayName);
}
else
{
return HTMLHelper.HTMLEncode(displayName.Substring(0, DisplayNameLength)) + " ...";
}
}
return parameter;
}
///
/// Handles the UniGrid's OnAction event.
///
/// Name of item (button) that threw event
/// ID (value of Primary key) of corresponding data row
protected void gridElem_OnAction(string actionName, object actionArgument)
{
if (actionName == "delete")
{
try
{
if (!RaiseOnCheckPermissions(PERMISSION_MODIFY, this))
{
CurrentUserInfo cui = CMSContext.CurrentUser;
if ((cui == null) || ((UserId != cui.UserID) && !cui.IsAuthorizedPerResource("CMS.Users", PERMISSION_MODIFY)))
{
RedirectToAccessDenied("CMS.Users", PERMISSION_MODIFY);
}
}
NotificationSubscriptionInfoProvider.DeleteNotificationSubscriptionInfo(Convert.ToInt32(actionArgument));
}
catch (Exception ex)
{
// Show error message
ShowError(ex.Message);
}
}
}
#endregion
///
/// Overridden SetValue - because of MyAccount webpart.
///
/// Name of the property to set
/// Value to set
public override void SetValue(string propertyName, object value)
{
base.SetValue(propertyName, value);
switch (propertyName.ToLowerCSafe())
{
case "userid":
UserId = ValidationHelper.GetInteger(value, 0);
break;
case "unigridimagedirectory":
UnigridImageDirectory = ValidationHelper.GetString(value, "");
break;
}
}
}