using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.ExtendedControls; using CMS.GlobalHelper; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.SiteProvider; using CMS.UIControls; using CMS.WebAnalytics; public partial class CMSModules_AbuseReport_Controls_AbuseReportEdit : CMSAdminControl { #region "Variables" private string mConfirmationText = string.Empty; private string mReportTitle = string.Empty; private int mReportObjectID = 0; private string mReportObjectType = string.Empty; private string mReportURL = string.Empty; private LocalizedButton mReportButton = null; private LocalizedButton mCancelButton = null; #endregion #region "Properties" /// public override MessagesPlaceHolder MessagesPlaceHolder { get { return plcMess; } } /// /// Indicates if control is used on live site. /// public override bool IsLiveSite { get { return base.IsLiveSite; } set { plcMess.IsLiveSite = value; base.IsLiveSite = value; } } /// /// Gets and sets Confirmation text. /// public string ConfirmationText { get { if (string.IsNullOrEmpty(mConfirmationText)) { return "abuse.saved"; } else { return mConfirmationText; } } set { mConfirmationText = value; } } /// /// Gets or sets Report title. /// public string ReportTitle { get { return mReportTitle; } set { mReportTitle = value; } } /// /// Gets or sets Report Object ID. /// public int ReportObjectID { get { return mReportObjectID; } set { mReportObjectID = value; } } /// /// Gets or sets the URL of the abuse to be reported. /// public string ReportURL { get { if (string.IsNullOrEmpty(mReportURL)) { mReportURL = URLHelper.GetAbsoluteUrl(URLHelper.CurrentURL); } return mReportURL; } set { mReportURL = value; } } /// /// Gets or sets Report Object type. /// public string ReportObjectType { get { return mReportObjectType; } set { mReportObjectType = value; } } /// /// Returns textbox control. /// public TextBox TextField { get { return txtText; } } /// /// Returns report button control. /// public LocalizedButton ReportButton { get { if (mReportButton == null) { mReportButton = btnReport; } return mReportButton; } set { mReportButton = value; } } /// /// Returns cancel button control. /// public LocalizedButton CancelButton { get { if (mCancelButton == null) { mCancelButton = btnCancel; } return mCancelButton; } set { mCancelButton = value; } } /// /// Gets or sets cancel button visible property. /// public bool ShowCancelButton { get { return btnCancel.Visible; } set { btnCancel.Visible = value; } } /// /// Indicates if buttons should be displayed. /// public bool DisplayButtons { get { return plcButtons.Visible; } set { plcButtons.Visible = value; } } /// /// Returns panel control. /// public Panel BodyPanel { get { return pnlBody; } } #endregion #region "Methods" protected void Page_Load(object sender, EventArgs e) { rfvText.ErrorMessage = GetString("abuse.textreqired"); rfvText.ValidationGroup = "Abuse" + ClientID; ReportButton.ValidationGroup = "Abuse" + ClientID; // WAI validation lblText.Attributes.Add("style", "display:none;"); if (!RequestHelper.IsPostBack()) { Reload(); } } /// /// Resets all properties. /// public void Reload() { txtText.Visible = true; ReportButton.Visible = true; txtText.Text = String.Empty; } /// /// Log activity /// /// Report info private void LogActivity(AbuseReportInfo ari) { Activity activity = new ActivityAbuseReport(ari, CMSContext.ActivityEnvironmentVariables); activity.Log(); } #endregion #region "Button handling" /// /// Cancel button event handler. /// protected void btnCancel_Click(object sender, EventArgs e) { Reload(); } /// /// Report abuse event handler. /// protected void btnReport_Click(object sender, EventArgs e) { PerformAction(); } /// /// Performs reporting of abuse. /// public void PerformAction() { // Check banned ip if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { ShowError(GetString("General.BannedIP")); return; } string report = txtText.Text; // Check that text area is not empty or too long report = report.Trim(); report = TextHelper.LimitLength(report, 1000); if (report.Length > 0) { // Create new AbuseReport AbuseReportInfo abuseReport = new AbuseReportInfo(); if (ReportTitle != "") { // Set AbuseReport properties // Decode first, from forums it can be encoded ReportTitle = Server.HtmlDecode(ReportTitle); // Remove BBCode tags ReportTitle = DiscussionMacroHelper.RemoveTags(ReportTitle); abuseReport.ReportTitle = TextHelper.LimitLength(ReportTitle, 100); abuseReport.ReportURL = URLHelper.GetAbsoluteUrl(ReportURL); abuseReport.ReportCulture = CMSContext.PreferredCultureCode; if (ReportObjectID > 0) { abuseReport.ReportObjectID = ReportObjectID; } if (ReportObjectType != "") { abuseReport.ReportObjectType = ReportObjectType; } abuseReport.ReportComment = report; if (CMSContext.CurrentUser.UserID > 0) { abuseReport.ReportUserID = CMSContext.CurrentUser.UserID; } abuseReport.ReportWhen = DateTime.Now; abuseReport.ReportStatus = AbuseReportStatusEnum.New; abuseReport.ReportSiteID = CMSContext.CurrentSite.SiteID; // Save AbuseReport AbuseReportInfoProvider.SetAbuseReportInfo(abuseReport); LogActivity(abuseReport); ShowConfirmation(GetString(ConfirmationText), true); txtText.Visible = false; ReportButton.Visible = false; } else { ShowError(GetString("abuse.errors.reporttitle")); } } else { ShowError(GetString("abuse.errors.reportcomment")); } // Additional form modification ReportButton.Visible = false; CancelButton.ResourceString = "general.close"; } #endregion }