/// <summary> /// Logs activity for subscribing/unsubscribing /// </summary> /// <param name="ui">User</param> /// <param name="newsletterId">Newsletter ID</param> /// <param name="subscribe">Subscribing/unsubscribing flag</param> /// <param name="siteId">Site ID</param> private void LogActivity(UserInfo ui, int newsletterId, bool subscribe, int siteId) { if ((sb == null) || (ui == null) || (CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteId) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(ui)) { return; } if (sb.SubscriberType == SiteObjectType.USER) { if (subscribe && ActivitySettingsHelper.NewsletterSubscribeEnabled(siteId) || !subscribe && ActivitySettingsHelper.NewsletterUnsubscribeEnabled(siteId)) { Newsletter news = NewsletterProvider.GetNewsletter(newsletterId); if ((news != null) && news.NewsletterLogActivity) { var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = sb.SubscriberSiteID, Type = PredefinedActivityType.NEWSLETTER_UNSUBSCRIBING, TitleData = news.NewsletterName, ItemID = newsletterId, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } } } }
protected void Page_Load(object sender, EventArgs e) { // Get issue ID from querystring issueId = QueryHelper.GetInteger("issueid", 0); // Get newsletter issue and check its existence Issue issue = IssueProvider.GetIssue(issueId); EditedObject = issue; btnSend.Enabled = true; // Display information wheather the issue was sent bool isSent = (issue.IssueMailoutTime != DateTimeHelper.ZERO_TIME) && (issue.IssueMailoutTime < DateTime.Now); lblSent.Text = isSent ? GetString("Newsletter_Issue_Header.AlreadySent") : GetString("Newsletter_Issue_Header.NotSentYet"); if (!RequestHelper.IsPostBack()) { // Fill draft emails box Newsletter newsletter = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); EditedObject = newsletter; txtSendDraft.Text = newsletter.NewsletterDraftEmails; } calendarControl.DateTimeTextBox.CssClass = "EditingFormCalendarTextBox"; string scriptBlock = "var wopener = parent.wopener; function RefreshPage() { wopener.RefreshPage(); }"; ScriptHelper.RegisterClientScriptBlock(this, this.GetType(), "RefreshPage", scriptBlock, true); }
/// <summary> /// Initializes header menu. /// </summary> /// <param name="issue">Issue object</param> protected void InitalizeMenu(Issue issue) { // Get newsletter Newsletter news = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); if (news == null) { return; } InitTabs(3, "newsletterIssueContent"); // Show only 'Send' tab for dynamic newsletter if (news.NewsletterType == NewsletterType.Dynamic) { SetTab(0, GetString("Newsletter_Issue_Header.Send"), "Newsletter_Issue_Send.aspx?issueid=" + issue.IssueID, "SetHelpTopic('helpTopic', 'send_tab');"); // Set proper context help page SetHelp("send_tab", "helpTopic"); } else { // Show 'Edit' and 'Send' tabs only to authorized users if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "authorissues")) { SetTab(0, GetString("General.Edit"), "Newsletter_Issue_Edit.aspx?issueid=" + issue.IssueID, "SetHelpTopic('helpTopic', 'edit_tab');"); SetTab(1, GetString("Newsletter_Issue_Header.Send"), "Newsletter_Issue_Send.aspx?issueid=" + issue.IssueID, "SetHelpTopic('helpTopic', 'send_tab');"); } // Add 'Preview' tab SetTab(2, GetString("Newsletter_Issue_Header.Preview"), "Newsletter_Issue_Preview.aspx?issueid=" + issue.IssueID, "SetHelpTopic('helpTopic', 'preview_tab');"); } }
protected void Page_Load(object sender, EventArgs e) { // Get issue ID from querystring issueId = QueryHelper.GetInteger("issueid", 0); Issue issue = IssueProvider.GetIssue(issueId); if (issue == null) { return; } btnFinish.Enabled = true; // Initializes page title control this.CurrentMaster.Title.TitleText = GetString("newsletter_issue_list.title"); this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Newsletter_Issue/new.png"); // Initialize controls' labels ucHeader.Title = GetString("Newsletter_Issue_New_Send.Step3"); ucHeader.Header = GetString("Newsletter_Issue_New_Send.header"); ucHeader.DescriptionVisible = false; if (!RequestHelper.IsPostBack()) { // Fill draft emails box Newsletter newsletter = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); txtSendDraft.Text = newsletter.NewsletterDraftEmails; } calendarControl.DateTimeTextBox.CssClass = "EditingFormCalendarTextBox"; RegisterModalPageScripts(); ScriptHelper.RegisterClientScriptBlock(this, this.GetType(), "RefreshPage", "function RefreshPage() { wopener.RefreshPage(); }", true); }
protected void Page_Load(object sender, EventArgs e) { // Get newsletter id from querystring newsletterId = QueryHelper.GetInteger("newsletterid", 0); // Try to get nesletter display name string newsName = ""; Newsletter news = NewsletterProvider.GetNewsletter(newsletterId); if (news != null) { newsName = news.NewsletterDisplayName; } // Initializes page title string[,] breadcrumbs = new string[2, 3]; breadcrumbs[0, 0] = GetString("Newsletter_Edit.Newsletters"); breadcrumbs[0, 1] = "~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_List.aspx"; breadcrumbs[0, 2] = "newslettersContent"; breadcrumbs[1, 0] = newsName; breadcrumbs[1, 1] = ""; breadcrumbs[1, 2] = ""; this.CurrentMaster.Title.Breadcrumbs = breadcrumbs; this.CurrentMaster.Title.HelpTopicName = "issues_tab"; this.CurrentMaster.Title.HelpName = "helpTopic"; // Initialize tabs InitalizeMenu(news); }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { repNewsArchive.StopProcessing = true; } else { SetContext(); Newsletter news = null; // Try to get data from cache using (CachedSection <Newsletter> cs = new CachedSection <Newsletter>(ref news, this.CacheMinutes, true, this.CacheItemName, "newsletterarchive", CMSContext.CurrentSiteName, NewsletterName)) { if (cs.LoadData) { // Get the data news = NewsletterProvider.GetNewsletter(NewsletterName, CMSContext.CurrentSite.SiteID); // Add data to the cache if (CacheMinutes > 0) { cs.CacheDependency = GetCacheDependency(); cs.Data = news; } } } ReleaseContext(); if (news != null) { repNewsArchive.ControlContext = ControlContext; repNewsArchive.QueryName = "newsletter.issue.selectall"; repNewsArchive.OrderBy = "IssueMailoutTime"; string where = "(IssueNewsletterID = " + news.NewsletterID + ")"; if (!IgnoreShowInNewsletterArchive) { where += " AND (IssueShowInNewsletterArchive = 1)"; } if (SelectOnlySendedIssues) { where += " AND (IssueMailoutTime IS NOT NULL) AND (IssueMailoutTime < getDate())"; } repNewsArchive.WhereCondition = where; repNewsArchive.TransformationName = TransformationName; } } }
/// <summary> /// Uniselector item selected event handler. /// </summary> protected void UniSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "ManageSubscribers")) { RedirectToCMSDeskAccessDenied("cms.newsletter", "ManageSubscribers"); } // Get new items from selector string newValues = ValidationHelper.GetString(selectNewsletter.Value, null); string[] newItems = null; SubscriberNewsletterInfo subscription = null; Newsletter newsletter = null; int newsletterId = 0; newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Get all selected newsletters foreach (string item in newItems) { newsletterId = ValidationHelper.GetInteger(item, 0); // Get subscription subscription = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId); // If not already subscribed if (subscription == null) { newsletter = NewsletterProvider.GetNewsletter(newsletterId); // Subscribe role if (isRoleORContactGroup) { SubscriberProvider.Subscribe(subscriberId, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false); } // Subscribe users and subscribers else { SubscriberProvider.Subscribe(subscriberId, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked); } } } } selectNewsletter.Value = null; unigridNewsletters.ReloadData(); pnlUpdate.Update(); }
protected void Page_Load(object sender, EventArgs e) { newsletterId = QueryHelper.GetInteger("newsletterid", 0); if (newsletterId == 0) { return; } btnSend.Enabled = true; if (!RequestHelper.IsPostBack()) { // Fill draft emails box Newsletter newsletter = NewsletterProvider.GetNewsletter(newsletterId); txtSendDraft.Text = newsletter.NewsletterDraftEmails; } }
protected void Page_Load(object sender, EventArgs e) { // Get issue object int issueId = QueryHelper.GetInteger("issueid", 0); Issue issue = IssueProvider.GetIssue(issueId); // Get information about author issue permission bool authorized = CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "authorissues"); if (issue != null) { // Get newsletter object Newsletter news = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); if (news != null) { if (news.NewsletterType == NewsletterType.Dynamic) { // Only send page is allowed for dynamic newsletters issueContentUrl = "Newsletter_Issue_Send.aspx?issueid=" + issueId.ToString(); } else { if (authorized) { issueContentUrl = "Newsletter_Issue_Edit.aspx?issueid=" + issueId.ToString(); } else { issueContentUrl = "Newsletter_Issue_Preview.aspx?issueid=" + issueId.ToString(); } } } } if (string.IsNullOrEmpty(issueContentUrl)) { issueContentUrl = "Newsletter_Issue_Edit.aspx"; } RegisterModalPageScripts(); }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterDialogScript(this); CurrentMaster.DisplayActionsPanel = true; chkRequireOptIn.CheckedChanged += chkRequireOptIn_CheckedChanged; string siteName = CMSContext.CurrentSiteName; mBounceLimit = SettingsKeyProvider.GetIntValue(siteName + ".CMSBouncedEmailsLimit"); mBounceInfoAvailable = SettingsKeyProvider.GetBoolValue(siteName + ".CMSMonitorBouncedEmails") && NewsletterProvider.OnlineMarketingEnabled(siteName); newsletterId = QueryHelper.GetInteger("newsletterid", 0); Newsletter newsletter = NewsletterProvider.GetNewsletter(newsletterId); EditedObject = newsletter; // Check if newsletter enables double opt-in if ((newsletter != null) && !newsletter.NewsletterEnableOptIn) { chkRequireOptIn.Visible = false; } if (!RequestHelper.IsPostBack()) { chkSendConfirmation.Checked = false; } // Initialize unigrid UniGridSubscribers.WhereCondition = "NewsletterID = " + newsletterId; UniGridSubscribers.OnAction += UniGridSubscribers_OnAction; UniGridSubscribers.OnExternalDataBound += UniGridSubscribers_OnExternalDataBound; CurrentMaster.DisplayControlsPanel = true; // Initialize selectors and mass actions SetupSelectors(); }
protected void Page_Load(object sender, EventArgs e) { newsletterId = QueryHelper.GetInteger("newsletterid", 0); if (newsletterId == 0) { RequestHelper.EndResponse(); } string siteName = CMSContext.CurrentSiteName; mBounceMonitoringEnabled = SettingsKeyProvider.GetBoolValue(siteName + ".CMSMonitorBouncedEmails"); mOnlineMarketingEnabled = NewsletterProvider.OnlineMarketingEnabled(siteName); ScriptHelper.RegisterDialogScript(this); string scriptBlock = string.Format(@" function RefreshPage() {{ document.location.replace(document.location); }} function EditItem(id) {{ modalDialog('{0}?issueid=' + id, 'NewsletterIssueEdit', screen.availWidth - 10, screen.availHeight - 80); }} function NewItem(id) {{ modalDialog('{1}?newsletterid=' + id, 'NewsletterNewIssue', screen.availWidth - 10, screen.availHeight - 80); }} function ShowOpenedBy(id) {{ modalDialog('{2}?issueid=' + id, 'NewsletterIssueOpenedBy', '900px', '700px'); return false; }} function ViewClickedLinks(id) {{ modalDialog('{3}?issueid=' + id, 'NewsletterTrackedLinks', '900px', '700px'); return false; }}", ResolveUrl(@"~\CMSModules\Newsletters\Tools\Newsletters\Newsletter_Issue_Frameset.aspx"), ResolveUrl(@"~\CMSModules\Newsletters\Tools\Newsletters\Newsletter_Issue_New_Edit.aspx"), ResolveUrl(@"~\CMSModules\Newsletters\Tools\Newsletters\Newsletter_Issue_OpenedBy.aspx"), ResolveUrl(@"~\CMSModules\Newsletters\Tools\Newsletters\Newsletter_Issue_TrackedLinks.aspx")); ScriptHelper.RegisterClientScriptBlock(this, GetType(), "Actions", scriptBlock, true); UniGrid.OnAction += uniGrid_OnAction; UniGrid.WhereCondition = "IssueNewsletterID = " + newsletterId; UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; UniGrid.ZeroRowsText = GetString("Newsletter_Issue_List.NoIssuesFound"); UniGrid.OnBeforeDataReload += UniGrid_OnBeforeDataReload; // Get newsletter object and check its existence EditedObject = newsletter = NewsletterProvider.GetNewsletter(newsletterId); InitHeaderActions(); }
protected void Page_Load(object sender, EventArgs e) { // Check read permission for newsletters if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Newsletter", "Read")) { int issueId = QueryHelper.GetInteger("IssueId", 0); if (issueId > 0) { // Get newsletter issue Issue iss = IssueProvider.GetIssue(issueId); if ((iss != null) && (iss.IssueSiteID == CMSContext.CurrentSiteID)) { // Get newsletter Newsletter news = NewsletterProvider.GetNewsletter(iss.IssueNewsletterID); Response.Clear(); Response.Write(IssueProvider.GetEmailBody(iss, news, null, null, false, CMSContext.CurrentSiteName, null, null, null)); Response.Flush(); RequestHelper.EndResponse(); } } } }
protected void Page_Load(object sender, EventArgs e) { // Get data from query string Guid subscriberGuid = QueryHelper.GetGuid("subscriberguid", Guid.Empty); Guid newsletterGuid = QueryHelper.GetGuid("newsletterguid", Guid.Empty); string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty); Guid issueGuid = QueryHelper.GetGuid("issueGuid", Guid.Empty); int issueID = QueryHelper.GetInteger("issueid", 0); int contactId = QueryHelper.GetInteger("contactid", 0); bool unsubscribed = false; string requestTime = QueryHelper.GetString("datetime", string.Empty); DateTime datetime = DateTimeHelper.ZERO_TIME; // Get date and time if (!string.IsNullOrEmpty(requestTime)) { try { datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null); } catch { ShowError(GetString("newsletter.unsubscribefailed")); return; } } // Get site ID int siteId = 0; if (CMSContext.CurrentSite != null) { siteId = CMSContext.CurrentSiteID; } if ((subscriberGuid != Guid.Empty) && (newsletterGuid != Guid.Empty) && (siteId != 0)) { Subscriber subscriber = SubscriberProvider.GetSubscriber(subscriberGuid, siteId); if (subscriber == null) { ShowError(GetString("Unsubscribe.SubscriberDoesNotExist")); return; } // Show error message if subscriber type is 'Role' if (!string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.Equals(SiteObjectType.ROLE, StringComparison.InvariantCultureIgnoreCase)) { ShowError(GetString("Unsubscribe.CannotUnsubscribeRole")); return; } Newsletter newsletter = NewsletterProvider.GetNewsletter(newsletterGuid, siteId); if (newsletter == null) { ShowError(GetString("Unsubscribe.NewsletterDoesNotExist")); return; } // Check if subscriber with given GUID is subscribed to specified newsletter if (SubscriberProvider.IsSubscribed(subscriber.SubscriberID, newsletter.NewsletterID)) { bool isSubscribed = true; if (string.IsNullOrEmpty(subscriber.SubscriberType) || !subscriber.SubscriberType.Equals(PredefinedObjectType.CONTACTGROUP, StringComparison.InvariantCultureIgnoreCase)) { // Unsubscribe action SubscriberProvider.Unsubscribe(subscriber.SubscriberID, newsletter.NewsletterID); } else { // Check if the contact group member has unsubscription activity for the specified newsletter isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, newsletter.NewsletterID, siteId); } if (isSubscribed) { // Log newsletter unsubscription activity LogActivity(subscriber, 0, newsletter.NewsletterID, issueID, issueGuid, siteId, contactId); // Display confirmation ShowInformation(GetString("Unsubscribe.Unsubscribed")); unsubscribed = true; } else { // Contact group member is already unsubscribed ShowError(GetString("Unsubscribe.NotSubscribed")); } } else { ShowError(GetString("Unsubscribe.NotSubscribed")); } } // Check if subscription approval hash is supplied else if (!string.IsNullOrEmpty(subscriptionHash)) { SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash); // Check if hash is valid if (sni != null) { SubscriberProvider.ApprovalResult result = SubscriberProvider.Unsubscribe(subscriptionHash, true, CMSContext.CurrentSiteName, datetime); switch (result) { // Approving subscription was successful case SubscriberProvider.ApprovalResult.Success: bool isSubscribed = true; // Get subscriber Subscriber subscriber = SubscriberProvider.GetSubscriber(sni.SubscriberID); if ((subscriber != null) && !string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.Equals(PredefinedObjectType.CONTACTGROUP, StringComparison.InvariantCultureIgnoreCase)) { // Check if the contact group member has unsubscription activity for the specified newsletter isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, sni.NewsletterID, siteId); } if (isSubscribed) { // Log newsletter unsubscription activity LogActivity(null, sni.SubscriberID, sni.NewsletterID, issueID, issueGuid, siteId, contactId); // Display confirmation ShowInformation(GetString("Unsubscribe.Unsubscribed")); unsubscribed = true; } else { // Contact group member is already unsubscribed ShowError(GetString("Unsubscribe.NotSubscribed")); } break; // Subscription was already approved case SubscriberProvider.ApprovalResult.Failed: ShowError(GetString("newsletter.unsubscribefailed")); break; case SubscriberProvider.ApprovalResult.TimeExceeded: ShowError(GetString("newsletter.approval_timeexceeded")); break; // Subscription not found default: case SubscriberProvider.ApprovalResult.NotFound: ShowError(GetString("Unsubscribe.NotSubscribed")); break; } } else { ShowError(GetString("Unsubscribe.NotSubscribed")); } } else { if (subscriberGuid == Guid.Empty) { ShowError(GetString("Unsubscribe.SubscriberDoesNotExist")); } if (newsletterGuid == Guid.Empty) { ShowError(GetString("Unsubscribe.NewsletterDoesNotExist")); } } // Increase unsubscribed count if (unsubscribed) { // If Issue ID was provided if (issueID > 0) { IssueProvider.Unsubscribe(issueID); return; } // Otherwise try using the Issue GUID if (issueGuid != Guid.Empty) { Issue issue = IssueProvider.GetIssue(issueGuid, siteId); if (issue == null) { return; } IssueProvider.Unsubscribe(issue.IssueID); } } }
protected void Page_Load(object sender, EventArgs e) { Guid subscriberGuid = QueryHelper.GetGuid("subscriberguid", Guid.Empty); int newsletterIssueId = QueryHelper.GetInteger("issueid", 0); // Get newsletter issue Issue issue = IssueProvider.GetIssue(newsletterIssueId); if (issue == null) { return; } // Get subscriber Subscriber subscriber = SubscriberProvider.GetSubscriber(subscriberGuid, CMSContext.CurrentSiteID); // Get the newsletter Newsletter news = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); if (news == null) { return; } // Get site default culture string culture = CultureHelper.GetDefaultCulture(CMSContext.CurrentSiteName); // Ensure preview in default site culture // Keep old culture System.Globalization.CultureInfo oldUICulture = Thread.CurrentThread.CurrentUICulture; // Set current culture Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture); string htmlPage = String.Empty; try { if (subscriber != null) { // Get subscriber's member (different for user or role subscribers) SortedDictionary <int, Subscriber> subscribers = SubscriberProvider.GetSubscribers(subscriber, 1, 0); foreach (KeyValuePair <int, Subscriber> item in subscribers) { // Get 1st subscriber's member Subscriber sb = item.Value; htmlPage = IssueProvider.GetEmailBody(issue, news, null, sb, true, CMSContext.CurrentSiteName, null, null, null); } } if (string.IsNullOrEmpty(htmlPage)) { htmlPage = IssueProvider.GetEmailBody(issue, news, null, null, true, CMSContext.CurrentSiteName, null, null, null); } } catch (Exception ex) { throw ex; } finally { // Set back to old culture Thread.CurrentThread.CurrentUICulture = oldUICulture; } Response.Clear(); Response.Write(htmlPage); RequestHelper.EndResponse(); }
protected void Page_Load(object sender, EventArgs e) { // If StopProcessing flag is set, do nothing if (StopProcessing) { Visible = false; return; } string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty); string requestTime = QueryHelper.GetString("datetime", string.Empty); DateTime datetime = DateTimeHelper.ZERO_TIME; // Get date and time if (!string.IsNullOrEmpty(requestTime)) { try { datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null); } catch { lblInfo.Text = ResHelper.GetString("newsletter.approval_failed"); return; } } if (string.IsNullOrEmpty(subscriptionHash)) { this.Visible = false; return; } // Try to approve subscription SubscriberProvider.ApprovalResult result = SubscriberProvider.ApproveSubscription(subscriptionHash, false, CMSContext.CurrentSiteName, datetime); switch (result) { // Approving subscription was successful case SubscriberProvider.ApprovalResult.Success: if (!String.IsNullOrEmpty(this.SuccessfulApprovalText)) { lblInfo.Text = this.SuccessfulApprovalText; } else { lblInfo.Text = ResHelper.GetString("newsletter.successful_approval"); } // Log newsletter subscription activity if ((CMSContext.ViewMode == ViewModeEnum.LiveSite)) { SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash); if (sni != null) { // Load subscriber info and make sure activity modul is enabled Subscriber sb = SubscriberProvider.GetSubscriber(sni.SubscriberID); if ((sb != null) && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(sb.SubscriberSiteID)) { int siteId = sb.SubscriberSiteID; Newsletter news = NewsletterProvider.GetNewsletter(sni.NewsletterID); if (news.NewsletterLogActivity && ActivitySettingsHelper.NewsletterSubscribeEnabled(siteId)) { // Under what contacs this subscriber belogs to? int contactId = ActivityTrackingHelper.GetContactID(sb); if (contactId > 0) { ModuleCommands.OnlineMarketingUpdateContactFromExternalData(sb, contactId); ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, contactId); var data = new ActivityData() { ContactID = contactId, SiteID = sb.SubscriberSiteID, Type = PredefinedActivityType.NEWSLETTER_SUBSCRIBING, TitleData = news.NewsletterName, ItemID = news.NewsletterID, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } } } } } break; // Subscription was already approved case SubscriberProvider.ApprovalResult.Failed: if (!String.IsNullOrEmpty(this.UnsuccessfulApprovalText)) { lblInfo.Text = this.UnsuccessfulApprovalText; } else { lblInfo.Text = ResHelper.GetString("newsletter.approval_failed"); } break; case SubscriberProvider.ApprovalResult.TimeExceeded: if (!String.IsNullOrEmpty(this.UnsuccessfulApprovalText)) { lblInfo.Text = this.UnsuccessfulApprovalText; } else { lblInfo.Text = ResHelper.GetString("newsletter.approval_timeexceeded"); } break; // Subscription not found default: case SubscriberProvider.ApprovalResult.NotFound: if (!String.IsNullOrEmpty(this.UnsuccessfulApprovalText)) { lblInfo.Text = this.UnsuccessfulApprovalText; } else { lblInfo.Text = ResHelper.GetString("newsletter.approval_invalid"); } break; } }
protected void LoadData() { // Get newsletter object and check if exists Newsletter newsletterObj = NewsletterProvider.GetNewsletter(newsletterId); EditedObject = newsletterObj; // Initialize issue selectors int siteId = newsletterObj.NewsletterSiteID; subscriptionTemplate.WhereCondition = "TemplateType='S' AND TemplateSiteID=" + siteId; unsubscriptionTemplate.WhereCondition = "TemplateType='U' AND TemplateSiteID=" + siteId; issueTemplate.WhereCondition = "TemplateType='I' AND TemplateSiteID=" + siteId; optInSelector.WhereCondition = "TemplateType='D' AND TemplateSiteID=" + siteId; // Check if the newsletter is dynamic and adjust config dialog isDynamic = newsletterObj.NewsletterType == NewsletterType.Dynamic; lblDynamic.Visible = pnlDynamic.Visible = lblNewsletterDynamicURL.Visible = txtNewsletterDynamicURL.Visible = plcUrl.Visible = chkSchedule.Visible = lblSchedule.Visible = plcInterval.Visible = isDynamic; lblTemplateBased.Visible = lblIssueTemplate.Visible = issueTemplate.Visible = !isDynamic; if (RequestHelper.IsPostBack()) { if (isDynamic) { schedulerInterval.Visible = chkSchedule.Checked; } else { plcInterval.Visible = false; } return; } // Fill config dialog with newsletter data GetNewsletterValues(newsletterObj); if (!isDynamic) { issueTemplate.Value = newsletterObj.NewsletterTemplateID.ToString(); return; } // Check if dynamic newsletter subject is empty bool subjectEmpty = string.IsNullOrEmpty(newsletterObj.NewsletterDynamicSubject); radPageTitle.Checked = subjectEmpty; radFollowing.Checked = !subjectEmpty; radPageTitle_CheckedChanged(null, null); if (!subjectEmpty) { txtSubject.Text = newsletterObj.NewsletterDynamicSubject; } txtNewsletterDynamicURL.Text = newsletterObj.NewsletterDynamicURL; TaskInfo task = TaskInfoProvider.GetTaskInfo(newsletterObj.NewsletterDynamicScheduledTaskID); if (task != null) { chkSchedule.Checked = plcInterval.Visible = true; schedulerInterval.ScheduleInterval = task.TaskInterval; } else { chkSchedule.Checked = false; schedulerInterval.Visible = false; } }
protected void btnOK_Click(object sender, EventArgs e) { // Check "configure" permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure")) { RedirectToCMSDeskAccessDenied("cms.newsletter", "configure"); } string errorMessage = ValidateNewsletterValues(); if (!string.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); return; } Newsletter newsletterObj = NewsletterProvider.GetNewsletter(txtNewsletterName.Text.Trim(), CMSContext.CurrentSiteID); // Newsletter's code name must be unique if (newsletterObj != null && newsletterObj.NewsletterID != newsletterId) { ShowError(GetString("Newsletter_Edit.NewsletterNameExists")); return; } if (newsletterObj == null) { newsletterObj = NewsletterProvider.GetNewsletter(newsletterId); } SetNewsletterValues(newsletterObj); // Check if subscription template was selected int subscriptionTemplateValue = ValidationHelper.GetInteger(subscriptionTemplate.Value, 0); if (subscriptionTemplateValue == 0) { ShowError(GetString("Newsletter_Edit.NoSubscriptionTemplateSelected")); return; } newsletterObj.NewsletterSubscriptionTemplateID = subscriptionTemplateValue; // Check if double opt-in template was selected int optInTemplateValue = ValidationHelper.GetInteger(optInSelector.Value, 0); if (newsletterObj.NewsletterEnableOptIn && optInTemplateValue == 0) { ShowError(GetString("Newsletter_Edit.NoOptInTemplateSelected")); return; } newsletterObj.NewsletterOptInTemplateID = optInTemplateValue; // Check if unsubscription template was selected int unsubscriptionTemplateValue = ValidationHelper.GetInteger(unsubscriptionTemplate.Value, 0); if (unsubscriptionTemplateValue == 0) { ShowError(GetString("Newsletter_Edit.NoUnsubscriptionTemplateSelected")); return; } newsletterObj.NewsletterUnsubscriptionTemplateID = unsubscriptionTemplateValue; // ID of scheduled task which should be deleted int deleteScheduledTaskId = 0; if (isDynamic) { newsletterObj.NewsletterType = NewsletterType.Dynamic; newsletterObj.NewsletterDynamicURL = txtNewsletterDynamicURL.Text.Trim(); newsletterObj.NewsletterDynamicSubject = radFollowing.Checked ? txtSubject.Text : string.Empty; if (chkSchedule.Checked) { // Set info for scheduled task TaskInfo task = GetDynamicNewsletterTask(newsletterObj); if (!schedulerInterval.CheckOneDayMinimum()) { // If problem occurred while setting schedule interval ShowError(GetString("Newsletter_Edit.NoDaySelected")); return; } if (!IsValidDate(SchedulingHelper.DecodeInterval(schedulerInterval.ScheduleInterval).StartTime)) { ShowError(GetString("Newsletter.IncorrectDate")); return; } task.TaskInterval = schedulerInterval.ScheduleInterval; task.TaskNextRunTime = SchedulingHelper.GetNextTime(task.TaskInterval, new DateTime(), new DateTime()); task.TaskDisplayName = GetString("DynamicNewsletter.TaskName") + newsletterObj.NewsletterDisplayName; task.TaskName = "DynamicNewsletter_" + newsletterObj.NewsletterName; // Set task for processing in external service task.TaskAllowExternalService = true; task.TaskUseExternalService = (SchedulingHelper.UseExternalService && NewsletterProvider.UseExternalServiceForDynamicNewsletters(CMSContext.CurrentSiteName)); TaskInfoProvider.SetTaskInfo(task); newsletterObj.NewsletterDynamicScheduledTaskID = task.TaskID; } else { if (newsletterObj.NewsletterDynamicScheduledTaskID > 0) { // Store task ID for deletion deleteScheduledTaskId = newsletterObj.NewsletterDynamicScheduledTaskID; } newsletterObj.NewsletterDynamicScheduledTaskID = 0; schedulerInterval.Visible = false; } } else { newsletterObj.NewsletterType = NewsletterType.TemplateBased; // Check if issue template was selected int issueTemplateValue = ValidationHelper.GetInteger(issueTemplate.Value, 0); if (issueTemplateValue == 0) { ShowError(GetString("Newsletter_Edit.NoEmailTemplateSelected")); return; } newsletterObj.NewsletterTemplateID = issueTemplateValue; } // Save changes to DB NewsletterProvider.SetNewsletter(newsletterObj); if (deleteScheduledTaskId > 0) { // Delete scheduled task if schedule mail-outs were unchecked TaskInfoProvider.DeleteTaskInfo(deleteScheduledTaskId); } ShowInformation(GetString("General.ChangesSaved")); // Refresh header with display name ScriptHelper.RefreshTabHeader(Page, GetString("Newsletter_Header.Configuration")); }
protected void Page_Load(object sender, EventArgs e) { InitGUI(); // Get issue ID from query string int newsletterIssueId = QueryHelper.GetInteger("issueid", 0); // Get Issue object Issue issue = IssueProvider.GetIssue(newsletterIssueId); if (issue == null) { lblError.Visible = true; lblError.Text = GetString("Newsletter_Issue_New_Preview.NoIssue"); return; } // Get specific number of subscribers subscribed to the newsletter string where = "SubscriberID IN (SELECT SubscriberID FROM Newsletter_SubscriberNewsletter WHERE NewsletterID=" + issue.IssueNewsletterID + " AND (SubscriptionApproved = 1 OR SubscriptionApproved IS NULL))"; DataSet subscribers = SubscriberProvider.GetSubscribers(where, null, MAX_PREVIEW_SUBSCRIBERS, null); string script; if (!DataHelper.DataSourceIsEmpty(subscribers)) { // Limit max subscribers count to number of rows int maxCount = subscribers.Tables[0].Rows.Count; // Generate javascript based on subscribers script = string.Format(@"newsletterIssueId ={0}; var guid = new Array({1}); var email = new Array({1}); var subject = new Array({1}); var subscribers = new Array(guid, email);", newsletterIssueId, maxCount); // Ensure correct subject culture string siteName = CMSContext.CurrentSiteName; string culture = CultureHelper.GetDefaultCulture(siteName); // Get newsletter object Newsletter news = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); // Get subject base string subjectBase = GetString("general.subject") + ResHelper.Colon; Subscriber subscriber = null; Subscriber sb = null; SortedDictionary <int, Subscriber> subMembers = null; string infoLine = null; string subject = null; IssueHelper ih = new IssueHelper(); for (int i = 0; i < maxCount; i++) { // Get subscriber subscriber = new Subscriber(subscribers.Tables[0].Rows[i]); if (subscriber != null) { // Insert subscriber GUID script = string.Format("{0} guid[{1}] = '{2}'; \n ", script, i, subscriber.SubscriberGUID); // Get subscriber's member (different for user, role or contact group subscribers) subMembers = SubscriberProvider.GetSubscribers(subscriber, 1, 0); foreach (KeyValuePair <int, Subscriber> item in subMembers) { // Get 1st subscriber's member sb = item.Value; if (sb != null) { // Create information line infoLine = ScriptHelper.GetString(sb.SubscriberEmail, false); // Add info about subscriber type if (sb.SubscriberType == SiteObjectType.USER) { infoLine = string.Format("{0} ({1})", infoLine, GetString("objecttype.cms_user").ToLower()); } else if (sb.SubscriberType == SiteObjectType.ROLE) { infoLine = string.Format("{0} ({1})", infoLine, GetString("objecttype.cms_role").ToLower()); } else if (sb.SubscriberType == PredefinedObjectType.CONTACTGROUP) { infoLine = string.Format("{0} ({1})", infoLine, GetString("objecttype.om_contactgroup").ToLower()); } script = string.Format("{0} email[{1}] = '{2}'; \n ", script, i, infoLine); // Resolve dynamic field macros ({%FirstName%}, {%LastName%}, {%Email%}) if (ih.LoadDynamicFields(sb, news, null, issue, true, siteName, null, null, null)) { subject = ih.ResolveDynamicFieldMacros(issue.IssueSubject); } // Create resolved subject subject = HTMLHelper.HTMLEncode(string.Format("{0} {1}", subjectBase, subject)); script = string.Format("{0}subject[{1}] = {2}; \n ", script, i, ScriptHelper.GetString(subject)); } } } } } else { // No subscribers? => hide 'prev' and 'next' link buttons pnlLinkButtons.Visible = false; // Generate void javascript script = string.Format(@"newsletterIssueId ={0}; var guid = new Array(1); var email = new Array(1); var subscribers = new Array(guid, email); guid[1] = 0; email[1] = 0;", newsletterIssueId); } ltlScript.Text = ScriptHelper.GetScript(script); if (!RequestHelper.IsPostBack()) { ScriptHelper.RegisterStartupScript(this, typeof(string), "LoadPreview" + ClientID, ScriptHelper.GetScript("pageLoad();")); } }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void uniGrid_OnAction(string actionName, object actionArgument) { switch (actionName.ToLower()) { case "edit": URLHelper.Redirect("Newsletter_Frameset.aspx?newsletterid=" + Convert.ToString(actionArgument)); break; case "delete": if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure")) { RedirectToCMSDeskAccessDenied("cms.newsletter", "configure"); } // delete Newsletter object from database NewsletterProvider.DeleteNewsletter(ValidationHelper.GetInteger(actionArgument, 0)); break; case "clone": if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure")) { RedirectToCMSDeskAccessDenied("cms.newsletter", "configure"); } Newsletter oldnl = NewsletterProvider.GetNewsletter(ValidationHelper.GetInteger(actionArgument, 0)); if (oldnl != null) { // Create new newsletter Newsletter nl = oldnl.Clone(true); // Find unique newsletter code name string newsletterDisplayName = nl.NewsletterDisplayName; string newsletterName = nl.NewsletterName; while (NewsletterProvider.GetNewsletter(newsletterName, nl.NewsletterSiteID) != null) { newsletterName = Increment(newsletterName, "_", ""); newsletterDisplayName = Increment(newsletterDisplayName, "(", ")"); } nl.NewsletterName = newsletterName; nl.NewsletterDisplayName = newsletterDisplayName; if (NewsletterProvider.LicenseVersionCheck(CMSContext.CurrentSite.DomainName, FeatureEnum.Newsletters, VersionActionEnum.Insert)) { // Clone scheduled task if (oldnl.NewsletterDynamicScheduledTaskID > 0) { TaskInfo oldti = TaskInfoProvider.GetTaskInfo(oldnl.NewsletterDynamicScheduledTaskID); if (oldti != null) { // Create new task TaskInfo ti = oldti.Clone(true); ti.TaskDisplayName = GetString("DynamicNewsletter.TaskName") + nl.NewsletterDisplayName; // Save the task TaskInfoProvider.SetTaskInfo(ti); nl.NewsletterDynamicScheduledTaskID = ti.TaskID; } } NewsletterProvider.SetNewsletter(nl); } else { lblError.Visible = true; lblError.Text = GetString("licenseversioncheck.newsletterclone"); } } break; } }
protected void btnSubmit_Click(object sender, EventArgs e) { // Check email format string email = txtEmail.Text.Trim(); string result = new Validator().IsEmail(email, GetString("unsubscribe.invalidemailformat")).Result; if (String.IsNullOrEmpty(result)) { bool requestSent = false; int siteId = 0; if (CMSContext.CurrentSite != null) { siteId = CMSContext.CurrentSiteID; } // Try to get all subscriber infos with given e-mail DataSet ds = SubscriberProvider.GetSubscribersFromView(email, siteId); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { Subscriber sb = new Subscriber(dr); if ((sb != null) && ((sb.SubscriberType == null) || (sb.SubscriberRelatedID > 0) && (sb.SubscriberType == SiteObjectType.USER))) { // Get newsletter information Newsletter news = NewsletterProvider.GetNewsletter(this.NewsletterName, siteId); if (news != null) { // Get subscription info SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(sb.SubscriberID, news.NewsletterID); // Send e-mail to subscribed user only if (sni != null) { SendUnsubscriptionRequest(sb, news, sni, CMSContext.CurrentSiteName); requestSent = true; // At least one request was sent } } } } } // Unsubscription failed if none confirmation e-mail was sent if (!requestSent) { // Use default error message if none is specified if (String.IsNullOrEmpty(this.ErrorText)) { result = GetString("unsubscribe.notsubscribed"); } else { result = this.ErrorText; } } } // Display error message if set if (!string.IsNullOrEmpty(result)) { lblError.Text = result; lblError.Visible = true; } else { // Display unsubscription confirmation lblInfo.Visible = true; if (String.IsNullOrEmpty(this.ResultText)) { // Use default message if none was specified lblInfo.Text = GetString("unsubscribe.confirmtext"); } else { lblInfo.Text = this.ResultText; } lblError.Visible = false; txtEmail.Visible = false; btnSubmit.Visible = false; } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check 'configure' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "configure")) { RedirectToCMSDeskAccessDenied("cms.newsletter", "configure"); } // Validate base inputs (newsletter display name, code name, sender name, sender e-mail) string errorMessage = new Validator().NotEmpty(txtNewsletterDisplayName.Text.Trim(), GetString("general.requiresdisplayname")).NotEmpty(txtNewsletterName.Text.Trim(), GetString("Newsletter_Edit.ErrorEmptyName")).NotEmpty(txtNewsletterSenderName.Text.Trim(), GetString("Newsletter_Edit.ErrorEmptySenderName")).NotEmpty(txtNewsletterSenderEmail.Text.Trim(), GetString("Newsletter_Edit.ErrorEmptySenderEmail")).IsEmail(txtNewsletterSenderEmail.Text.Trim(), GetString("Newsletter_Edit.ErrorEmailFormat")).IsCodeName(txtNewsletterName.Text.Trim(), GetString("general.invalidcodename")).Result; if (String.IsNullOrEmpty(errorMessage)) { if (String.IsNullOrEmpty((string)subscriptionTemplate.Value)) { // No subscription template selected lblSubscriptionError.Visible = true; return; } if (String.IsNullOrEmpty((string)unsubscriptionTemplate.Value)) { // No unsubscription template selected lblUnsubscriptionError.Visible = true; return; } if ((radTemplateBased.Checked) && (String.IsNullOrEmpty((string)issueTemplate.Value))) { // No issue template selected for template based newsletter lblIssueError.Visible = true; return; } if ((radDynamic.Checked) && (!ScheduleInterval.CheckOneDayMinimum())) { // Problem occurred while setting schedule interval for dynamic newsletter lblError.Visible = true; lblError.Text = GetString("Newsletter_Edit.NoDaySelected"); return; } // Newsletter code name must to be unique per site... Newsletter newsletterObj = NewsletterProvider.GetNewsletter(txtNewsletterName.Text.Trim(), CMSContext.CurrentSiteID); // If newsletter code name is unique... if (newsletterObj == null) { // Create new item -> insert newsletterObj = new Newsletter(); newsletterObj.NewsletterDisplayName = txtNewsletterDisplayName.Text.Trim(); newsletterObj.NewsletterName = txtNewsletterName.Text.Trim(); int selectedValue = ValidationHelper.GetInteger(subscriptionTemplate.Value, 0); if (selectedValue != 0) { newsletterObj.NewsletterSubscriptionTemplateID = selectedValue; } else { lblError.Visible = true; lblError.Text = GetString("Newsletter_Edit.NoSubscriptionTemplateSelected"); return; } selectedValue = ValidationHelper.GetInteger(unsubscriptionTemplate.Value, 0); if (selectedValue != 0) { newsletterObj.NewsletterUnsubscriptionTemplateID = selectedValue; } else { lblError.Visible = true; lblError.Text = GetString("Newsletter_Edit.NoUnsubscriptionTemplateSelected"); return; } newsletterObj.NewsletterSenderName = txtNewsletterSenderName.Text.Trim(); newsletterObj.NewsletterSenderEmail = txtNewsletterSenderEmail.Text.Trim(); if (radDynamic.Checked) { newsletterObj.NewsletterDynamicURL = txtNewsletterDynamicURL.Text.Trim(); newsletterObj.NewsletterType = NewsletterType.Dynamic; } else { selectedValue = ValidationHelper.GetInteger(issueTemplate.Value, 0); if (selectedValue != 0) { newsletterObj.NewsletterTemplateID = selectedValue; } else { lblError.Visible = true; lblError.Text = GetString("Newsletter_Edit.NoEmailTemplateSelected"); return; } newsletterObj.NewsletterType = NewsletterType.TemplateBased; } newsletterObj.NewsletterSiteID = CMSContext.CurrentSiteID; newsletterObj.NewsletterGUID = Guid.NewGuid(); newsletterObj.NewsletterLogActivity = true; if (NewsletterProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Newsletters, VersionActionEnum.Insert)) { // Create new newsletter NewsletterProvider.SetNewsletter(newsletterObj); if (radDynamic.Checked) { if (chkSchedule.Checked) { // Create new task to schedule the dynamic newsletter TaskInfo task = new TaskInfo(); task.TaskAssemblyName = "CMS.Newsletter"; task.TaskClass = "CMS.Newsletter.DynamicNewsletterSender"; task.TaskDisplayName = GetString("DynamicNewsletter.TaskName") + newsletterObj.NewsletterDisplayName; task.TaskEnabled = true; task.TaskInterval = ScheduleInterval.ScheduleInterval; task.TaskLastResult = string.Empty; task.TaskName = "DynamicNewsletter." + ValidationHelper.GetCodeName(newsletterObj.NewsletterName, "_"); task.TaskSiteID = CMSContext.CurrentSiteID; task.TaskNextRunTime = SchedulingHelper.GetNextTime(task.TaskInterval, new DateTime(), new DateTime()); task.TaskData = newsletterObj.NewsletterGUID.ToString(); // Set task for processing in external service task.TaskAllowExternalService = true; task.TaskUseExternalService = (SchedulingHelper.UseExternalService && NewsletterProvider.UseExternalServiceForDynamicNewsletters(CMSContext.CurrentSiteName)); TaskInfoProvider.SetTaskInfo(task); newsletterObj.NewsletterDynamicScheduledTaskID = task.TaskID; NewsletterProvider.SetNewsletter(newsletterObj); } } URLHelper.Redirect("Newsletter_Frameset.aspx?newsletterid=" + ValidationHelper.GetString(newsletterObj.NewsletterID, null) + "&saved=1"); } else { lblError.Visible = true; lblError.Text = GetString("LicenseVersionCheck.Newsletter"); } } else { lblError.Visible = true; lblError.Text = GetString("Newsletter_Edit.NewsletterNameExists"); } } else { lblError.Visible = true; lblError.Text = errorMessage; } }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterScriptFile(Page, "cmsedit.js"); ScriptHelper.RegisterStartupScript(Page, typeof(string), "Initialize", ScriptHelper.GetScript("InitializePage();")); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Reload", ScriptHelper.GetScript("" + "function SaveContent(callNext, newsSubject, newsShowInArchive) { \n" + " document.getElementById('" + hdnNewsletterSubject.ClientID + "').value = newsSubject; \n" + " document.getElementById('" + hdnNewsletterShowInArchive.ClientID + "').value = newsShowInArchive; \n" + " if (callNext) { document.getElementById('" + this.hdnNext.ClientID + "').value = 1; } \n" + this.Page.ClientScript.GetPostBackEventReference(btnHidden, null) + "} \n" + "function SaveDocument() { window.parent.ClearToolbar(); window.parent.SaveDocument(); } \n")); if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "authorissues")) { ScriptHelper.RegisterShortcuts(this); } // Get issue ID mIssueID = QueryHelper.GetInteger("issueid", 0); if (mIssueID == 0) { mIssueID = QueryHelper.GetInteger(hdnIssueId.Value, 0); } // Get newsletter ID mNewsletterID = QueryHelper.GetInteger("newsletterid", 0); // Get info if new issue is created mIsNewIssue = QueryHelper.GetBoolean("new", false); if (mIssueID > 0) { issue = IssueProvider.GetIssue(mIssueID); if (issue != null) { templateId = issue.IssueTemplateID; } } else if (mNewsletterID > 0) { Newsletter newsletter = NewsletterProvider.GetNewsletter(mNewsletterID); if (newsletter != null) { templateId = newsletter.NewsletterTemplateID; } } if (templateId > 0) { // Load content from the template LoadContent(); } if (!RequestHelper.IsPostBack()) { if ((issue != null)) { bool saved = QueryHelper.GetBoolean("saved", false); if (saved) { ltlScript2.Text = ScriptHelper.GetScript("if (parent.MsgInfo) { parent.MsgInfo(0); } "); } } } LoadRegionList(); }
/// <summary> /// Logs activity for unsubscribing. /// </summary> /// <param name="sb">Subscriber (optional - can be null if subscriber ID is used)</param> /// <param name="subscriberId">Subscriber ID (optional - can be zero if subscriber object is used)</param> /// <param name="newsletterId">Newsletter ID</param> /// <param name="siteId">Site ID</param> /// <param name="issueId">Issue ID</param> /// <param name="issueGuid">Issue GUID</param> /// <param name="contactId">Contact ID is present if the mail is sent to a contact group</param> private void LogActivity(Subscriber sb, int subscriberId, int newsletterId, int siteId, int issueId, Guid issueGuid, int contactId) { // Check if activities logging is enabled if ((newsletterId <= 0) || (CMSContext.ViewMode != ViewModeEnum.LiveSite) || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteId) || !ActivitySettingsHelper.NewsletterSubscribeEnabled(siteId)) { return; } // Load subscriber info object according to its ID if not given if (sb == null) { if (subscriberId <= 0) { return; } sb = SubscriberProvider.GetSubscriber(subscriberId); } if (sb == null) { return; } Newsletter news = NewsletterProvider.GetNewsletter(newsletterId); if ((news != null) && news.NewsletterLogActivity) { bool isFromContactGroup = (contactId > 0); // Try to retrieve contact IDs for particular subscriber from membership relations if (!isFromContactGroup) { contactId = ActivityTrackingHelper.GetContactID(sb); } if (contactId > 0) { // Load additional info (issue id) if ((issueId <= 0) && (issueGuid != Guid.Empty)) { Issue issue = IssueProvider.GetIssue(issueGuid, siteId); if (issue != null) { issueId = issue.IssueID; } } var data = new ActivityData() { ContactID = contactId, SiteID = sb.SubscriberSiteID, Type = PredefinedActivityType.NEWSLETTER_UNSUBSCRIBING, TitleData = news.NewsletterName, ItemID = newsletterId, URL = URLHelper.CurrentRelativePath, ItemDetailID = issueId, Value = (isFromContactGroup ? "contactgroup(" + sb.SubscriberRelatedID + ")" : null) }; ActivityLogProvider.LogActivity(data); } } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { int siteId = 0; // Get current id if (CMSContext.CurrentSite != null) { siteId = CMSContext.CurrentSiteID; } // Get subscriber and newsletter guid from query string Guid subscriberGuid = QueryHelper.GetGuid("subscriberguid", Guid.Empty); Guid newsletterGuid = QueryHelper.GetGuid("newsletterguid", Guid.Empty); string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty); int issueId = QueryHelper.GetInteger("issueid", 0); Guid issueGuid = QueryHelper.GetGuid("issueguid", Guid.Empty); int contactId = QueryHelper.GetInteger("contactid", 0); string requestTime = QueryHelper.GetString("datetime", string.Empty); DateTime datetime = DateTimeHelper.ZERO_TIME; // Get date and time if (!string.IsNullOrEmpty(requestTime)) { try { datetime = DateTime.ParseExact(requestTime, SecurityHelper.EMAIL_CONFIRMATION_DATETIME_FORMAT, null); } catch { lblError.Visible = true; lblError.Text = GetString("newsletter.unsubscribefailed"); return; } } // Check whether both guid exists if ((subscriberGuid != Guid.Empty) && (newsletterGuid != Guid.Empty)) { Subscriber subscriber = SubscriberProvider.GetSubscriber(subscriberGuid, siteId); if (subscriber == null) { lblError.Visible = true; lblError.Text = GetString("Unsubscribe.SubscriberDoesNotExist"); return; } // Show error message if subscriber type is 'Role' if (!string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.Equals(SiteObjectType.ROLE, StringComparison.InvariantCultureIgnoreCase)) { lblError.Visible = true; lblError.Text = GetString("Unsubscriber.CannotUnsubscribeRole"); return; } Newsletter newsletter = NewsletterProvider.GetNewsletter(newsletterGuid, siteId); if (newsletter == null) { lblError.Visible = true; lblError.Text = GetString("Unsubscribe.NewsletterDoesNotExist"); return; } // Check whether subscription is valid if (SubscriberProvider.IsSubscribed(subscriber.SubscriberID, newsletter.NewsletterID)) { bool isSubscribed = true; if (string.IsNullOrEmpty(subscriber.SubscriberType) || !subscriber.SubscriberType.Equals(PredefinedObjectType.CONTACTGROUP, StringComparison.InvariantCultureIgnoreCase)) { // Unsubscribe action SubscriberProvider.Unsubscribe(subscriber.SubscriberID, newsletter.NewsletterID, SendConfirmationEmail); } else { // Check if the contact group member has unsubscription activity for the specified newsletter isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, newsletter.NewsletterID, siteId); } if (isSubscribed) { // Log newsletter unsubscription activity LogActivity(subscriber, subscriber.SubscriberID, newsletter.NewsletterID, subscriber.SubscriberSiteID, issueId, issueGuid, contactId); // Display confirmation DisplayConfirmation(); } else { // Contact group member is already unsubscribed lblError.Visible = true; lblError.Text = GetString("Unsubscribe.NotSubscribed"); } } else { lblError.Visible = true; lblError.Text = GetString("Unsubscribe.NotSubscribed"); } } // Check if subscriptionGUID is supplied else if (!string.IsNullOrEmpty(subscriptionHash)) { // Check if given subscription exists SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash); if (sni != null) { SubscriberProvider.ApprovalResult result = SubscriberProvider.Unsubscribe(subscriptionHash, true, CMSContext.CurrentSiteName, datetime); switch (result) { // Approving subscription was successful case SubscriberProvider.ApprovalResult.Success: bool isSubscribed = true; // Get subscriber Subscriber subscriber = SubscriberProvider.GetSubscriber(sni.SubscriberID); if ((subscriber != null) && !string.IsNullOrEmpty(subscriber.SubscriberType) && subscriber.SubscriberType.Equals(PredefinedObjectType.CONTACTGROUP, StringComparison.InvariantCultureIgnoreCase)) { // Check if the contact group member has unsubscription activity for the specified newsletter isSubscribed = (contactId > 0) && !ModuleCommands.OnlineMarketingIsContactUnsubscribed(contactId, sni.NewsletterID, siteId); } if (isSubscribed) { // Log newsletter unsubscription activity LogActivity(subscriber, subscriber.SubscriberID, sni.NewsletterID, siteId, issueId, issueGuid, contactId); // Display confirmation DisplayConfirmation(); } else { // Contact group member is already unsubscribed lblError.Visible = true; lblError.Text = GetString("Unsubscribe.NotSubscribed"); } break; // Subscription was already approved case SubscriberProvider.ApprovalResult.Failed: lblError.Visible = true; lblError.Text = GetString("newsletter.unsubscribefailed"); break; case SubscriberProvider.ApprovalResult.TimeExceeded: lblError.Visible = true; lblError.Text = GetString("newsletter.approval_timeexceeded"); break; // Subscription not found default: case SubscriberProvider.ApprovalResult.NotFound: lblError.Visible = true; lblError.Text = GetString("Unsubscribe.NotSubscribed"); break; } } else { lblError.Visible = true; lblError.Text = GetString("Unsubscribe.NotSubscribed"); } } else { Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { chkShowInArchive.Text = GetString("NewsletterTemplate_Edit.ShowInArchive"); mSave = GetString("general.save"); if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Newsletter", "AuthorIssues")) { // Disable Save button if user is not authorized lnkSave.Enabled = false; imgSave.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/savedisabled.png"); } else { imgSave.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png"); lnkSave.Attributes.Add("onclick", "SaveDocument(); return false;"); lblInfo.Text = GetString("general.changessaved"); lblInfo.Style.Add("display", "none"); lblError.Text = GetString("NewsletterContentEditor.SubjectRequired"); lblError.Style.Add("display", "none"); // Registr scripts ScriptHelper.RegisterShortcuts(this); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "MsgInfo", ScriptHelper.GetScript( "function MsgInfo(err) { \n" + " if (err == 0) { \n" + " document.getElementById('" + lblError.ClientID + "').style.display = \"none\"; \n" + " document.getElementById('" + lblInfo.ClientID + "').style.display = \"block\"; \n" + " } \n" + " if (err == 1) { \n" + " document.getElementById('" + lblInfo.ClientID + "').style.display = \"none\"; \n" + " document.getElementById('" + lblError.ClientID + "').style.display = \"block\"; \n" + " } \n" + "} \n")); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "GetSubject", ScriptHelper.GetScript( "function SaveDocument() \n" + "{ \n" + " ClearToolbar(); \n" + " window.frames['iframeContent'].SaveContent(false, document.getElementById('" + txtSubject.ClientID + "').value, " + " document.getElementById('" + chkShowInArchive.ClientID + "').checked ); \n" + " document.getElementById('" + lblInfo.ClientID + "').style.display = \"block\"; \n" + " setTimeout('RefreshPage()',200); \n" + "} \n")); } // Get issue ID from query string int issueId = QueryHelper.GetInteger("issueid", 0); // Get edited issue object and check its existence Issue issue = IssueProvider.GetIssue(issueId); EditedObject = issue; // Check whether issue has been sent bool isSent = (issue.IssueMailoutTime == DateTimeHelper.ZERO_TIME ? false : (issue.IssueMailoutTime < DateTime.Now)); if (isSent) { lblSent.Text = GetString("Newsletter_Issue_Header.AlreadySent"); } else { lblSent.Text = GetString("Newsletter_Issue_Header.NotSentYet"); } // Get newsletter and check its existence Newsletter news = NewsletterProvider.GetNewsletter(issue.IssueNewsletterID); EditedObject = news; if (news.NewsletterType == NewsletterType.Dynamic) { lblInfo.Visible = true; lblInfo.Text = GetString("Newsletter_Issue_Edit.CannotBeEdited"); contentBody.Visible = false; contentFooter.Visible = false; pnlMenu.Visible = false; return; } else { contentBody.IssueID = issueId; txtSubject.Text = issue.IssueSubject; chkShowInArchive.Checked = issue.IssueShowInNewsletterArchive; } // Initialize attachment list AttachmentTitle.TitleText = GetString("general.attachments"); AttachmentTitle.SetWindowTitle = false; AttachmentList.ObjectID = issueId; AttachmentList.SiteID = CMSContext.CurrentSiteID; AttachmentList.AllowPasteAttachments = true; AttachmentList.ObjectType = NewsletterObjectType.NEWSLETTERISSUE; AttachmentList.Category = MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE; AttachmentList.AllowEdit = lnkSave.Enabled; // Add after upload event AttachmentList.OnAfterUpload += new EventHandler(AttachmentList_OnAfterUpload); AttachmentList.OnAfterDelete += new EventHandler(AttachmentList_OnAfterUpload); }
/// <summary> /// Saves the data. /// </summary> private bool Save(string newsletterName, Subscriber sb) { bool toReturn = false; int siteId = CMSContext.CurrentSiteID; // Check if sunscriber info object exists if ((sb == null) || string.IsNullOrEmpty(newsletterName)) { return(false); } // Get nesletter info Newsletter news = NewsletterProvider.GetNewsletter(newsletterName, siteId); if (news != null) { try { // Check if subscriber is not allready subscribed if (!SubscriberProvider.IsSubscribed(sb.SubscriberGUID, news.NewsletterGUID, siteId)) { toReturn = true; // Subscribe to the site SubscriberProvider.Subscribe(sb.SubscriberID, news.NewsletterID, DateTime.Now, this.SendConfirmationEmail); // Info message if (!chooseMode) { lblInfo.Visible = true; lblInfo.Text = GetString("NewsletterSubscription.Subscribed"); } // Track successful subscription conversion if (this.TrackConversionName != string.Empty) { string siteName = CMSContext.CurrentSiteName; if (AnalyticsHelper.AnalyticsEnabled(siteName) && AnalyticsHelper.TrackConversionsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, HTTPHelper.UserHostAddress)) { // Log conversion HitLogProvider.LogConversions(siteName, CMSContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue); } } // Log newsletter subscription activity if double opt-in is not required if (!news.NewsletterEnableOptIn) { if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && news.NewsletterLogActivity && ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteId) && ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) && ActivitySettingsHelper.NewsletterSubscribeEnabled(siteId)) { int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingUpdateContactFromExternalData(sb, contactId); ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, contactId); if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)) { var data = new ActivityData() { ContactID = contactId, SiteID = sb.SubscriberSiteID, Type = PredefinedActivityType.NEWSLETTER_SUBSCRIBING, TitleData = news.NewsletterName, ItemID = news.NewsletterID, URL = URLHelper.CurrentRelativePath, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); } } } } else { // Info message - subscriber is allready in site if (!chooseMode) { lblInfo.Visible = true; lblInfo.Text = GetString("NewsletterSubscription.SubscriberIsAlreadySubscribed"); } else { lblInfo.Visible = true; lblInfo.Text += GetString("NewsletterSubscription.SubscriberIsAlreadySubscribedXY") + " " + HTMLHelper.HTMLEncode(news.NewsletterDisplayName) + ".<br />"; } } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; } } else { lblError.Visible = true; lblError.Text = GetString("NewsletterSubscription.NewsletterDoesNotExist"); } return(toReturn); }