Skip to content

Commit

Permalink
Merge pull request #32 from juvander/AddEmailNotifySettingForDownloads
Browse files Browse the repository at this point in the history
Add email notify setting for downloads
  • Loading branch information
valadas authored Jan 16, 2020
2 parents 98117e6 + d7cd9c8 commit 45fe86b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 15 deletions.
6 changes: 6 additions & 0 deletions App_LocalResources/Settings.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@
<data name="plEmailOnComment.Text" xml:space="preserve">
<value>Send Email when Comment Posted</value>
</data>
<data name="plEmailOnDownload.Help" xml:space="preserve">
<value>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</value>
</data>
<data name="plEmailOnDownload.Text" xml:space="preserve">
<value>Send Email when user downloads file</value>
</data>
<data name="plEmailOnUpload.Help" xml:space="preserve">
<value>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</value>
</data>
Expand Down
58 changes: 49 additions & 9 deletions Repository.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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}<br />", System.DateTime.Now));
_body.Append(string.Format("by {0} ({1})<br /><br />", UserInfo.DisplayName, UserInfo.Email));
_body.Append(string.Format("File {0}<br /><br />", objRepository.FileName));
_body.Append("------------------------------------------------------------<br />");
_body.Append(string.Format("{0}<br />", 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"]))) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions Settings.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@
<asp:TextBox ID="txtEmailOnComment" runat="server" CssClass="normal" Text="" Width="350" /><br /><br />
</td>
</tr>
<tr>
<td><dnn:label id="plEmailOnDownload" runat="server" controlname="cbxEmailOnDownload" suffix=":"></dnn:label></td>
<td class="repSetting">
<asp:CheckBox ID="cbxEmailOnDownload" runat="server" Checked="false" CssClass="normal" Text="" />
<asp:TextBox ID="txtEmailOnDownload" runat="server" CssClass="normal" Text="" Width="350" /><br /><br />
</td>
</tr>

<tr>
<td><dnn:label id="plSecurityRoles" runat="server" suffix=":"></dnn:label></td>
Expand Down
38 changes: 32 additions & 6 deletions Settings.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 45fe86b

Please sign in to comment.