private static TemplateInfo GetTemplateByName(string templateName, int moduleId, int portalId) { var tc = new TemplateController(); TemplateInfo ti; try { ti = tc.Template_Get(templateName, portalId, moduleId); } catch (Exception ex) { ti = new TemplateInfo {TemplateHTML = "Error loading " + templateName + " template."}; ti.TemplateText = ti.TemplateHTML; } return ti; }
private void cbAction_Callback(object sender, Controls.CallBackEventArgs e) { string sMsg = ""; switch (e.Parameters[0].ToLower()) { case "save": { try { //save template TemplateInfo ti = null; TemplateController tc = new TemplateController(); int templateId = 0; if (e.Parameters[1].ToString() != "") { templateId = Convert.ToInt32(e.Parameters[1]); ti = tc.Template_Get(templateId, PortalId, ModuleId); } else { ti = new TemplateInfo(); ti.IsSystem = false; ti.TemplateType = (Templates.TemplateTypes)(Convert.ToInt32(e.Parameters[6])); ti.PortalId = PortalId; ti.ModuleId = ModuleId; } ti.Title = e.Parameters[2].ToString(); ti.Subject = e.Parameters[3].ToString(); if (ti.TemplateType == Templates.TemplateTypes.Email || ti.TemplateType == Templates.TemplateTypes.ModEmail) { ti.Template = "<template><html>" + Server.HtmlEncode(e.Parameters[4]) + "</html><plaintext>" + Utilities.StripHTMLTag(e.Parameters[5].ToString()) + "</plaintext></template>"; } else { ti.Template = "<template><html>" + Server.HtmlEncode(e.Parameters[4]) + "</html><plaintext>" + string.Empty + "</plaintext></template>"; } ti.Template = ti.Template.Replace("[TRESX:", "[RESX:"); templateId = tc.Template_Save(ti); string ckey = ModuleId + templateId + Convert.ToString(Enum.Parse(typeof(Templates.TemplateTypes), ti.TemplateType.ToString())); DataCache.CacheClear(ckey); sMsg = "Template saved successfully!"; } catch (Exception ex) { sMsg = "Error saving template."; } break; } case "delete": { try { //delete template TemplateInfo ti = null; TemplateController tc = new TemplateController(); int templateid = 0; if (e.Parameters[1].ToString() != "") { templateid = Convert.ToInt32(e.Parameters[1]); ti = tc.Template_Get(templateid, PortalId, ModuleId); if (!(ti.IsSystem == true)) { tc.Template_Delete(templateid, PortalId, ModuleId); sMsg = "Template deleted successfully!"; } else { sMsg = "Enable to delete system templates"; } } } catch (Exception ex) { sMsg = "Error deleting template."; } break; } } cbActionMessage.InnerText = sMsg; cbActionMessage.RenderControl(e.Output); }
private void LoadTemplates(int PortalId, int ModuleId) { try { var xDoc = new System.Xml.XmlDocument(); xDoc.Load(sPath); if (xDoc != null) { System.Xml.XmlNode xRoot = xDoc.DocumentElement; System.Xml.XmlNodeList xNodeList = xRoot.SelectNodes("//templates/template"); if (xNodeList.Count > 0) { var tc = new TemplateController(); int i; for (i = 0; i < xNodeList.Count; i++) { var ti = new TemplateInfo { TemplateId = -1, TemplateType = (Templates.TemplateTypes) Enum.Parse(typeof (Templates.TemplateTypes), xNodeList[i].Attributes["templatetype"].Value), IsSystem = true, PortalId = PortalId, ModuleId = ModuleId, Title = xNodeList[i].Attributes["templatetitle"].Value, Subject = xNodeList[i].Attributes["templatesubject"].Value }; string sHTML; sHTML = GetFileContent(xNodeList[i].Attributes["importfilehtml"].Value); string sText; sText = GetFileContent(xNodeList[i].Attributes["importfiletext"].Value); string sTemplate = sText; if (sHTML != string.Empty) { sTemplate = "<template><html>" + HttpContext.Current.Server.HtmlEncode(sHTML) + "</html><plaintext>" + sText + "</plaintext></template>"; } ti.Template = sTemplate; tc.Template_Save(ti); } } } } catch (Exception ex) { } }
private void cbAction_Callback(object sender, Controls.CallBackEventArgs e) { string sMsg = ""; switch (e.Parameters[0].ToLower()) { case "save": { try { //save template TemplateInfo ti = null; TemplateController tc = new TemplateController(); int templateId = 0; if (e.Parameters[1].ToString() != "") { templateId = Convert.ToInt32(e.Parameters[1]); ti = tc.Template_Get(templateId, PortalId, ModuleId); } else { ti = new TemplateInfo(); ti.IsSystem = false; ti.TemplateType = (Templates.TemplateTypes)(Convert.ToInt32(e.Parameters[6])); ti.PortalId = PortalId; ti.ModuleId = ModuleId; } ti.Title = e.Parameters[2].ToString(); ti.Subject = e.Parameters[3].ToString(); if (ti.TemplateType == Templates.TemplateTypes.Email || ti.TemplateType == Templates.TemplateTypes.ModEmail) { ti.Template = "<template><html>" + Server.HtmlEncode(e.Parameters[4]) + "</html><plaintext>" + Utilities.StripHTMLTag(e.Parameters[5].ToString()) + "</plaintext></template>"; } else { ti.Template = "<template><html>" + Server.HtmlEncode(e.Parameters[4]) + "</html><plaintext>" + string.Empty + "</plaintext></template>"; } ti.Template = ti.Template.Replace("[TRESX:", "[RESX:"); templateId = tc.Template_Save(ti); string ckey = ModuleId + templateId + Convert.ToString(Enum.Parse(typeof(Templates.TemplateTypes), ti.TemplateType.ToString())); DataCache.CacheClear(ckey); sMsg = "Template saved successfully!"; } catch (Exception ex) { sMsg = "Error saving template."; } break; } case "delete": { try { //delete template TemplateInfo ti = null; TemplateController tc = new TemplateController(); int templateid = 0; if (e.Parameters[1].ToString() != "") { templateid = Convert.ToInt32(e.Parameters[1]); ti = tc.Template_Get(templateid, PortalId, ModuleId); if (! (ti.IsSystem == true)) { tc.Template_Delete(templateid, PortalId, ModuleId); sMsg = "Template deleted successfully!"; } else { sMsg = "Enable to delete system templates"; } } } catch (Exception ex) { sMsg = "Error deleting template."; } break; } } cbActionMessage.InnerText = sMsg; cbActionMessage.RenderControl(e.Output); }
private void btnSend_Click(object sender, System.EventArgs e) { if (Request.IsAuthenticated) { Email objEmail = new Email(); string Comments = null; Comments = drpReasons.SelectedItem.Value + "<br>"; Comments += Utilities.CleanString(PortalId, txtComments.Text, false, EditorTypes.TEXTBOX, false, false, ModuleId, string.Empty, false); int templateId = 0; TemplateController tc = new TemplateController(); TemplateInfo ti = tc.Template_Get("ModAlert", PortalId, ModuleId); string sUrl = NavigateUrl(Convert.ToInt32(Request.QueryString["TabId"]), "", new string[] { ParamKeys.ForumId + "=" + ForumId, ParamKeys.TopicId + "=" + TopicId, ParamKeys.ViewType + "=confirmaction", ParamKeys.ConfirmActionId + "=" + ConfirmActions.AlertSent }); NotificationType notificationType = NotificationsController.Instance.GetNotificationType("AF-ContentAlert"); TopicsController topicController = new TopicsController(); TopicInfo topic = topicController.Topics_Get(PortalId, ModuleId, TopicId, ForumId, -1, false); string sBody = string.Empty; string authorName = string.Empty; string sSubject = string.Empty; string sTopicURL = string.Empty; sTopicURL = topic.TopicUrl; if (ReplyId > 0 & TopicId != ReplyId) { ReplyController rc = new ReplyController(); ReplyInfo reply = rc.Reply_Get(PortalId, ModuleId, TopicId, ReplyId); sBody = reply.Content.Body; sSubject = reply.Content.Subject; authorName = reply.Author.DisplayName; } else { sBody = topic.Content.Body; sSubject = topic.Content.Subject; authorName = topic.Author.DisplayName; } ControlUtils ctlUtils = new ControlUtils(); string fullURL = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, ForumInfo.ForumGroup.PrefixURL, ForumInfo.PrefixURL, ForumInfo.ForumGroupId, ForumInfo.ForumID, TopicId, sTopicURL, -1, -1, string.Empty, 1, ReplyId, SocialGroupId); string subject = Utilities.GetSharedResource("AlertSubject"); subject = subject.Replace("[DisplayName]", authorName); subject = subject.Replace("[Subject]", sSubject); string body = Utilities.GetSharedResource("AlertBody"); body = body.Replace("[Post]", sBody); body = body.Replace("[Comment]", Comments); body = body.Replace("[URL]", fullURL); body = body.Replace("[Reason]", drpReasons.SelectedItem.Value); List <Entities.Users.UserInfo> mods = Utilities.GetListOfModerators(PortalId, ForumId); string notificationKey = string.Format("{0}:{1}:{2}:{3}:{4}", TabId, ForumModuleId, ForumId, TopicId, ReplyId); Notification notification = new Notification(); notification.NotificationTypeID = notificationType.NotificationTypeId; notification.Subject = subject; notification.Body = body; notification.IncludeDismissAction = false; notification.SenderUserID = UserInfo.UserID; notification.Context = notificationKey; NotificationsController.Instance.SendNotification(notification, PortalId, null, mods); Response.Redirect(sUrl); } }
//'<summary> //'Function to save template.</summary> //'<param name="info">TemplateInfo object</param> public int Template_Save(TemplateInfo info) { return(Convert.ToInt32(DataProvider.Instance().Templates_Save(info.TemplateId, info.PortalId, info.ModuleId, (int)info.TemplateType, info.IsSystem, info.Title, info.Subject, info.Template))); }
public void SendEmailToModerators(int TemplateId, int PortalId, int ForumId, int TopicId, int ReplyId, int ModuleID, int TabID, string Comments, DotNetNuke.Entities.Users.UserInfo User) { var _portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]); SettingsInfo MainSettings = DataCache.MainSettings(ModuleID); var fc = new ForumController(); Forum fi = fc.Forums_Get(ForumId, -1, false, true); if (fi == null) { return; } var subs = new List <SubscriptionInfo>(); var rc = new Security.Roles.RoleController(); var uc = new Entities.Users.UserController(); SubscriptionInfo si; string modApprove = fi.Security.ModApprove; string[] modRoles = modApprove.Split('|')[0].Split(';'); if (modRoles != null) { foreach (string r in modRoles) { if (!(string.IsNullOrEmpty(r))) { int rid = Convert.ToInt32(r); string rName = rc.GetRole(rid, PortalId).RoleName; foreach (Entities.Users.UserRoleInfo usr in rc.GetUserRolesByRoleName(PortalId, rName)) { var ui = uc.GetUser(PortalId, usr.UserID); si = new SubscriptionInfo { UserId = ui.UserID, DisplayName = ui.DisplayName, Email = ui.Email, FirstName = ui.FirstName, LastName = ui.LastName }; if (!(subs.Contains(si))) { subs.Add(si); } } } } } if (subs.Count <= 0) { return; } string Subject; string BodyText; string BodyHTML; string sTemplate = string.Empty; var tc = new TemplateController(); TemplateInfo ti = tc.Template_Get(TemplateId, PortalId, ModuleID); Subject = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, _portalSettings.TimeZoneOffset); BodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset); BodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset); string sFrom; sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : _portalSettings.Email; var oEmail = new Email { Recipients = subs, Subject = Subject, From = sFrom, BodyText = BodyText, BodyHTML = BodyHTML, SmtpServer = Host.SMTPServer, // Convert.ToString(_portalSettings.HostSettings["SMTPServer"]), SmtpUserName = Host.SMTPUsername, // Convert.ToString(_portalSettings.HostSettings["SMTPUsername"]), SmtpPassword = Host.SMTPPassword, // Convert.ToString(_portalSettings.HostSettings["SMTPPassword"]), SmtpAuthentication = Host.SMTPAuthentication // Convert.ToString(_portalSettings.HostSettings["SMTPAuthentication"]) }; //#if SKU_ENTERPRISE oEmail.UseQueue = MainSettings.MailQueue; //#endif var objThread = new System.Threading.Thread(oEmail.Send); objThread.Start(); }
//'<summary> //'Function to save template.</summary> //'<param name="info">TemplateInfo object</param> public int Template_Save(TemplateInfo info) { return Convert.ToInt32(DataProvider.Instance().Templates_Save(info.TemplateId, info.PortalId, info.ModuleId, (int)info.TemplateType, info.IsSystem, info.Title, info.Subject, info.Template)); }
private List<TemplateInfo> GetTemplateList(int PortalId, int ModuleId, Templates.TemplateTypes TemplateType) { try { var tl = new List<TemplateInfo>(); IDataReader dr = TemplateType == Templates.TemplateTypes.All ? DataProvider.Instance().Templates_List(PortalId, ModuleId, -1) : DataProvider.Instance().Templates_List(PortalId, ModuleId, (int)TemplateType); dr.Read(); dr.NextResult(); while (dr.Read()) { var ti = new TemplateInfo { DateCreated = dr.IsDBNull(8) ? Utilities.NullDate() : Convert.ToDateTime(dr["DateCreated"]), DateUpdated = dr.IsDBNull(9) ? Utilities.NullDate() : Convert.ToDateTime(dr["DateUpdated"]), IsSystem = Convert.ToBoolean(dr["IsSystem"]), ModuleId = Convert.ToInt32(dr["ModuleID"]), PortalId = Convert.ToInt32(dr["PortalId"]), Subject = Convert.ToString(dr["Subject"]), Template = Convert.ToString(dr["Template"]) }; ti.TemplateHTML = GetHTML(ti.Template); ti.TemplateId = Convert.ToInt32(dr["TemplateId"]); ti.TemplateText = GetText(ti.Template); ti.TemplateType = (Templates.TemplateTypes)(dr["TemplateType"]); ti.Title = Convert.ToString(dr["Title"]); tl.Add(ti); } dr.Close(); return tl; } catch (Exception ex) { return null; } }
public TemplateInfo Template_Get(int TemplateId, int PortalId, int ModuleId) { var info = new TemplateInfo(); IDataReader dr = DataProvider.Instance().Templates_Get(TemplateId, PortalId, ModuleId); while (dr.Read()) { try { info.TemplateId = Convert.ToInt32(dr["TemplateId"]); info.PortalId = Convert.ToInt32(dr["PortalId"]); info.ModuleId = Convert.ToInt32(dr["ModuleId"]); info.TemplateType = (Templates.TemplateTypes)(Convert.ToInt32(dr["TemplateType"])); info.IsSystem = Convert.ToBoolean(dr["IsSystem"]); info.Title = Convert.ToString(dr["Title"]); info.Subject = Convert.ToString(dr["Subject"]); info.Template = Convert.ToString(dr["Template"]); info.TemplateHTML = GetHTML(Convert.ToString(dr["Template"])); info.TemplateText = GetText(Convert.ToString(dr["Template"])); info.DateCreated = dr.IsDBNull(8) ? Utilities.NullDate() : Convert.ToDateTime(dr["DateCreated"]); info.DateUpdated = dr.IsDBNull(9) ? Utilities.NullDate() : Convert.ToDateTime(dr["DateUpdated"]); } catch (Exception ex) { return null; } } return info; }