diff --git a/App_LocalResources/Settings.ascx.resx b/App_LocalResources/Settings.ascx.resx index 73efde5..a240253 100644 --- a/App_LocalResources/Settings.ascx.resx +++ b/App_LocalResources/Settings.ascx.resx @@ -374,6 +374,12 @@ Send Email when Comment Posted + + If you want to receive an email when user downloads a file, check this box and enter the email address where you would like the notification sent + + + Send Email when user downloads file + If you want to receive an email when a new item is uploaded, check this box and enter the email address where you would like the notification sent diff --git a/Repository.ascx.cs b/Repository.ascx.cs index 28f091f..446eb61 100644 --- a/Repository.ascx.cs +++ b/Repository.ascx.cs @@ -42,15 +42,16 @@ using DotNetNuke.UI.WebControls; using DotNetNuke.Services.Mail; using DotNetNuke.Security.Permissions; +using DotNetNuke.Services.Exceptions; namespace DotNetNuke.Modules.Repository { public abstract class Repository : Entities.Modules.PortalModuleBase, Entities.Modules.Communications.IModuleListener { - - #region "Controls" - protected Label lblDescription; + static Instrumentation.DnnLogger log = Instrumentation.DnnLogger.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()); + #region "Controls" + protected Label lblDescription; private DataGrid withEventsField_lstObjects; protected DataGrid lstObjects { get { return withEventsField_lstObjects; } @@ -406,8 +407,46 @@ public void lstObjects_PageIndexChanged(object source, DataGridPageChangedEventA BindObjectList(); } - - private void SendCommentNotification(RepositoryInfo objRepository, TextBox txtName, TextBox txtComment) + private void SendDownloadNotification(RepositoryInfo objRepository) + { + try + { + bool emailOnDownload = false; + // check to see if we need to send an email notification + if (bool.TryParse(Settings["EmailOnDownload"].ToString(), out emailOnDownload) == true && + emailOnDownload == true) + { + string _email = Convert.ToString(Settings["EmailOnDownloadAddress"]); + if (string.IsNullOrEmpty(_email) == false) + { + // send an email + string _subject = string.Format("[{0}] New Download from Your Repository", PortalSettings.PortalName); + System.Text.StringBuilder _body = new System.Text.StringBuilder(); + _body.Append(string.Format("A new download at {0}
", System.DateTime.Now)); + _body.Append(string.Format("by {0} ({1})

", UserInfo.DisplayName, UserInfo.Email)); + _body.Append(string.Format("File {0}

", objRepository.FileName)); + _body.Append("------------------------------------------------------------
"); + _body.Append(string.Format("{0}
", this.Request.UserHostAddress)); + Mail.SendMail( + PortalSettings.Email, + _email, + "", "", + Services.Mail.MailPriority.Normal, + _subject, + Services.Mail.MailFormat.Html, + System.Text.Encoding.Default, + _body.ToString(), + "", "", "", "", ""); + } + } + } + catch (Exception ex) + { + Exceptions.ProcessModuleLoadException(this, ex); + } + } + + private void SendCommentNotification(RepositoryInfo objRepository, TextBox txtName, TextBox txtComment) { // check to see if we need to send an email notification if (!string.IsNullOrEmpty(Convert.ToString(Settings["EmailOnComment"]))) { @@ -504,7 +543,8 @@ public void lstObjects_ItemCommand(object source, DataGridCommandEventArgs e) string target = oRepositoryBusinessController.GetSkinAttribute(xmlDoc, "DOWNLOAD", "Target", "NEW"); oRepositoryBusinessController.DownloadFile(e.CommandArgument.ToString(), target); - break; + SendDownloadNotification(objRepository); + break; case "PostComment": objCommentsPanel = null; TextBox txtName = null; @@ -736,7 +776,8 @@ private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.Data string target = oRepositoryBusinessController.GetSkinAttribute(xmlDoc, "DOWNLOAD", "Target", "NEW"); oRepositoryBusinessController.DownloadFile(e.CommandArgument.ToString(), target); - break; + SendDownloadNotification(objRepository); + break; case "PostComment": objCommentsPanel = null; TextBox txtName = null; @@ -797,8 +838,7 @@ private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.Data } - - private void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) + private void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem) { PlaceHolder holder = (PlaceHolder)e.Item.FindControl("PlaceHolder1"); diff --git a/Settings.ascx b/Settings.ascx index 5958e1a..e46bc21 100644 --- a/Settings.ascx +++ b/Settings.ascx @@ -151,6 +151,13 @@

+ + + + +

+ + diff --git a/Settings.ascx.cs b/Settings.ascx.cs index e6ca359..d57016e 100644 --- a/Settings.ascx.cs +++ b/Settings.ascx.cs @@ -302,9 +302,11 @@ protected ImageButton cmdDeleteValue { protected System.Web.UI.WebControls.CheckBox cbAllFiles; protected System.Web.UI.WebControls.CheckBox cbxIsPersonal; protected System.Web.UI.WebControls.CheckBox cbxEmailOnComment; - protected System.Web.UI.WebControls.CheckBox cbxEmailOnUpload; + protected System.Web.UI.WebControls.CheckBox cbxEmailOnDownload; + protected System.Web.UI.WebControls.CheckBox cbxEmailOnUpload; protected System.Web.UI.WebControls.TextBox txtEmailOnComment; - protected System.Web.UI.WebControls.TextBox txtEmailOnUpload; + protected System.Web.UI.WebControls.TextBox txtEmailOnDownload; + protected System.Web.UI.WebControls.TextBox txtEmailOnUpload; protected System.Web.UI.WebControls.RadioButtonList rblDataControl; protected System.Web.UI.WebControls.TextBox txtWatermark; @@ -379,7 +381,17 @@ private void Page_Load(System.Object sender, System.EventArgs e) cbxEmailOnComment.Checked = false; } - if (!string.IsNullOrEmpty(Convert.ToString(settings["AnonEditDelete"]))) { + bool emailOnDownload = false; + if (bool.TryParse(settings["EmailOnDownload"]?.ToString(), out emailOnDownload) == true) + { + cbxEmailOnDownload.Checked = emailOnDownload; + } + else + { + cbxEmailOnDownload.Checked = false; + } + + if (!string.IsNullOrEmpty(Convert.ToString(settings["AnonEditDelete"]))) { cbxAnonEditDelete.Checked = bool.Parse(settings["AnonEditDelete"].ToString()); } else { cbxAnonEditDelete.Checked = false; @@ -392,7 +404,17 @@ private void Page_Load(System.Object sender, System.EventArgs e) // default value } - if (!string.IsNullOrEmpty(Convert.ToString(settings["EmailOnUpload"]))) { + if (!string.IsNullOrEmpty(Convert.ToString(settings["EmailOnDownloadAddress"]))) + { + txtEmailOnDownload.Text = Convert.ToString(settings["EmailOnDownloadAddress"]); + } + else + { + txtEmailOnDownload.Text = ""; + // default value + } + + if (!string.IsNullOrEmpty(Convert.ToString(settings["EmailOnUpload"]))) { cbxEmailOnUpload.Checked = bool.Parse(settings["EmailOnUpload"].ToString()); } else { cbxEmailOnUpload.Checked = false; @@ -735,7 +757,8 @@ private void Page_Load(System.Object sender, System.EventArgs e) cbAllFiles.Text = Localization.GetString("AllowAllFiles", LocalResourceFile); cbxIsPersonal.Text = Localization.GetString("IsPersonal", LocalResourceFile); - cbxEmailOnComment.Text = Localization.GetString("EmailOnComment", LocalResourceFile); + cbxEmailOnComment.Text = Localization.GetString("EmailOnComment", LocalResourceFile); + cbxEmailOnDownload.Text = Localization.GetString("EmailOnDownload", LocalResourceFile); cbxEmailOnUpload.Text = Localization.GetString("EmailOnUpload", LocalResourceFile); cbxAnonEditDelete.Text = Localization.GetString("AnonEditDelete", LocalResourceFile); @@ -811,7 +834,10 @@ public override void UpdateSettings() objModules.UpdateModuleSetting(ModuleId, "EmailOnComment", cbxEmailOnComment.Checked.ToString()); objModules.UpdateModuleSetting(ModuleId, "EmailOnCommentAddress", txtEmailOnComment.Text); - objModules.UpdateModuleSetting(ModuleId, "EmailOnUpload", cbxEmailOnUpload.Checked.ToString()); + objModules.UpdateModuleSetting(ModuleId, "EmailOnDownload", cbxEmailOnDownload.Checked.ToString()); + objModules.UpdateModuleSetting(ModuleId, "EmailOnDownloadAddress", txtEmailOnDownload.Text); + + objModules.UpdateModuleSetting(ModuleId, "EmailOnUpload", cbxEmailOnUpload.Checked.ToString()); objModules.UpdateModuleSetting(ModuleId, "EmailOnUploadAddress", txtEmailOnUpload.Text); objModules.UpdateModuleSetting(ModuleId, "AnonEditDelete", cbxAnonEditDelete.Checked.ToString());