private static void LogNewsletterSubscriptionActivity(SubscriberInfo subscriber, NewsletterInfo newsletter)
    {
        // Under what contacts this subscriber belogs to?
        int contactId = ActivityTrackingHelper.GetContactID(subscriber);

        if (contactId <= 0)
        {
            return;
        }

        // Activity object is created for contact taken from ActivityContext.
        // Set ID of contact opening this email into this context otherwise new contact could be created.
        var activityContext = AnalyticsContext.ActivityEnvironmentVariables;

        activityContext.ContactID = contactId;

        var activity = new ActivityNewsletterSubscribing(subscriber, newsletter, activityContext);

        activity.Log();
    }
    /// <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>
    private void LogActivity(UserInfo ui, int newsletterId, bool subscribe)
    {
        if ((sb == null) || (ui == null))
        {
            return;
        }

        if (sb.SubscriberType.Equals(SiteObjectType.USER, StringComparison.InvariantCultureIgnoreCase))
        {
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);
            Activity       activity;
            if (subscribe)
            {
                activity = new ActivityNewsletterSubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
            }
            else
            {
                activity = new ActivityNewsletterUnsubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
            }
            activity.Log();
        }
    }
Example #3
0
    /// <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>
    private void LogActivity(UserInfo ui, int newsletterId, bool subscribe)
    {
        if ((subscriber == null) || (ui == null))
        {
            return;
        }

        // Log activity only if subscriber is User
        if ((subscriber.SubscriberType != null) && subscriber.SubscriberType.Equals(UserInfo.OBJECT_TYPE, StringComparison.InvariantCultureIgnoreCase))
        {
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);
            Activity       activity;
            if (subscribe)
            {
                activity = new ActivityNewsletterSubscribing(subscriber, news, AnalyticsContext.ActivityEnvironmentVariables);
            }
            else
            {
                activity = new ActivityNewsletterUnsubscribing(news, AnalyticsContext.ActivityEnvironmentVariables);
            }
            activity.Log();
        }
    }
Example #4
0
    /// <summary>
    /// Saves the data.
    /// </summary>
    private bool Save(string newsletterName, SubscriberInfo sb)
    {
        bool toReturn = false;
        int  siteId   = SiteContext.CurrentSiteID;

        // Check if sunscriber info object exists
        if ((sb == null) || string.IsNullOrEmpty(newsletterName))
        {
            return(false);
        }

        // Get nesletter info
        NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterName, siteId);

        if (news != null)
        {
            try
            {
                // Check if subscriber is not allready subscribed
                if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberGUID, news.NewsletterGUID, siteId))
                {
                    toReturn = true;

                    // Subscribe to the site
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, news.NewsletterID, DateTime.Now, SendConfirmationEmail);

                    // Info message
                    if (!chooseMode)
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text    = GetString("NewsletterSubscription.Subscribed");
                    }

                    // Track successful subscription conversion
                    if (TrackConversionName != string.Empty)
                    {
                        string siteName = SiteContext.CurrentSiteName;

                        if (AnalyticsHelper.AnalyticsEnabled(siteName) && AnalyticsHelper.TrackConversionsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, RequestContext.UserHostAddress))
                        {
                            // Log conversion
                            HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue);
                        }
                    }

                    // Log newsletter subscription activity if double opt-in is not required
                    if (!news.NewsletterEnableOptIn)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(sb, news, AnalyticsContext.ActivityEnvironmentVariables);
                        activity.Log();
                    }
                }
                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(ResHelper.LocalizeString(news.NewsletterDisplayName)) + ".<br />";
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = GetString("NewsletterSubscription.NewsletterDoesNotExist");
        }

        return(toReturn);
    }
    private static void LogNewsletterSubscriptionActivity(SubscriberInfo subscriber, NewsletterInfo newsletter)
    {
        // Under what contacts this subscriber belogs to?
        int contactId = ActivityTrackingHelper.GetContactID(subscriber);
        if (contactId <= 0)
        {
            return;
        }

        // Activity object is created for contact taken from ActivityContext.
        // Set ID of contact opening this email into this context otherwise new contact could be created.
        var activityContext = AnalyticsContext.ActivityEnvironmentVariables;
        activityContext.ContactID = contactId;

        var activity = new ActivityNewsletterSubscribing(subscriber, newsletter, activityContext);
        activity.Log();
    }
Example #6
0
    /// <summary>
    /// Saves the data.
    /// </summary>
    /// <param name="newsletterName">Newsletter name</param>
    /// <param name="sb">Subscriber</param>
    private bool Save(string newsletterName, SubscriberInfo sb)
    {
        bool toReturn = false;
        int  siteId   = SiteContext.CurrentSiteID;

        // Check if sunscriber info object exists
        if ((sb == null) || string.IsNullOrEmpty(newsletterName))
        {
            return(false);
        }

        // Get nesletter info
        NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterName, siteId);

        if (news != null)
        {
            // Init webpart resolver
            object[] data = new object[3];
            data[0] = news;
            data[1] = sb;

            MacroResolver resolver = ContextResolver;
            resolver.SetNamedSourceData("Newsletter", news);
            resolver.SetNamedSourceData("Subscriber", sb);
            if (AllowUserSubscribers && isAuthenticated)
            {
                data[2] = CurrentUser;
                resolver.SetNamedSourceData("User", CurrentUser);
            }
            resolver.SetAnonymousSourceData(data);

            try
            {
                // Check if subscriber is not allready subscribed
                if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberGUID, news.NewsletterGUID, siteId))
                {
                    toReturn = true;

                    // Subscribe to the site
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, news.NewsletterID, DateTime.Now, SendConfirmationEmail);

                    if (!chooseMode)
                    {
                        // Display message about successful subscription
                        lblInfo.Visible = true;
                        lblInfo.Text    = SubscriptionConfirmationMessage;
                    }

                    // Track successful subscription conversion
                    if (!string.IsNullOrEmpty(TrackConversionName))
                    {
                        string siteName = SiteContext.CurrentSiteName;

                        if (AnalyticsHelper.AnalyticsEnabled(siteName) && AnalyticsHelper.TrackConversionsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, RequestContext.UserHostAddress))
                        {
                            // Log conversion
                            HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue);
                        }
                    }

                    // Log newsletter subscription activity if double opt-in is not required
                    if (!news.NewsletterEnableOptIn)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(sb, news, AnalyticsContext.ActivityEnvironmentVariables);
                        activity.Log();
                    }
                }
                else
                {
                    lblInfo.Visible = true;
                    string message = null;

                    if (string.IsNullOrEmpty(MessageForAlreadySubscribed))
                    {
                        if (!chooseMode)
                        {
                            message = GetString("NewsletterSubscription.SubscriberIsAlreadySubscribed");
                        }
                        else
                        {
                            message = string.Format("{0} {1}.<br />", GetString("NewsletterSubscription.SubscriberIsAlreadySubscribedXY"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(news.NewsletterDisplayName)));
                        }
                    }
                    else
                    {
                        message = MessageForAlreadySubscribed;
                    }

                    // Info message - subscriber is allready in site
                    if (!chooseMode)
                    {
                        lblInfo.Text = message;
                    }
                    else
                    {
                        lblInfo.Text += message;
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = GetString("NewsletterSubscription.NewsletterDoesNotExist");
        }

        return(toReturn);
    }
    /// <summary>
    /// Saves the data.
    /// </summary>
    /// <param name="newsletterName">Newsletter name</param>
    /// <param name="sb">Subscriber</param>
    private bool Save(string newsletterName, SubscriberInfo sb)
    {
        bool toReturn = false;
        int siteId = SiteContext.CurrentSiteID;

        // Check if sunscriber info object exists
        if ((sb == null) || string.IsNullOrEmpty(newsletterName))
        {
            return false;
        }

        // Get nesletter info
        NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterName, siteId);
        if (news != null)
        {
            // Init webpart resolver
            object[] data = new object[3];
            data[0] = news;
            data[1] = sb;

            MacroResolver resolver = ContextResolver;
            resolver.SetNamedSourceData("Newsletter", news);
            resolver.SetNamedSourceData("Subscriber", sb);
            if (AllowUserSubscribers && isAuthenticated)
            {
                data[2] = CurrentUser;
                resolver.SetNamedSourceData("User", CurrentUser);
            }
            resolver.SetAnonymousSourceData(data);

            try
            {
                // Check if subscriber is not allready subscribed
                if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberGUID, news.NewsletterGUID, siteId))
                {
                    toReturn = true;

                    // Subscribe to the site
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, news.NewsletterID, DateTime.Now, SendConfirmationEmail);

                    if (!chooseMode)
                    {
                        // Display message about successful subscription
                        lblInfo.Visible = true;
                        lblInfo.Text = SubscriptionConfirmationMessage;
                    }

                    // Track successful subscription conversion
                    if (!string.IsNullOrEmpty(TrackConversionName))
                    {
                        string siteName = SiteContext.CurrentSiteName;

                        if (AnalyticsHelper.AnalyticsEnabled(siteName) && AnalyticsHelper.TrackConversionsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, RequestContext.UserHostAddress))
                        {
                            // Log conversion
                            HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue);
                        }
                    }

                    // Log newsletter subscription activity if double opt-in is not required
                    if (!news.NewsletterEnableOptIn)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(sb, news, AnalyticsContext.ActivityEnvironmentVariables);
                        activity.Log();
                    }
                }
                else
                {
                    lblInfo.Visible = true;
                    string message = null;

                    if (string.IsNullOrEmpty(MessageForAlreadySubscribed))
                    {
                        if (!chooseMode)
                        {
                            message = GetString("NewsletterSubscription.SubscriberIsAlreadySubscribed");
                        }
                        else
                        {
                            message = string.Format("{0} {1}.<br />", GetString("NewsletterSubscription.SubscriberIsAlreadySubscribedXY"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(news.NewsletterDisplayName)));
                        }
                    }
                    else
                    {
                        message = MessageForAlreadySubscribed;
                    }

                    // Info message - subscriber is allready in site
                    if (!chooseMode)
                    {
                        lblInfo.Text = message;
                    }
                    else
                    {
                        lblInfo.Text += message;
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = ex.Message;
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = GetString("NewsletterSubscription.NewsletterDoesNotExist");
        }

        return toReturn;
    }
    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))
        {
            Visible = false;
            return;
        }

        // Try to approve subscription
        SubscriberInfoProvider.ApprovalResult result = SubscriberInfoProvider.ApproveSubscription(subscriptionHash, false, CMSContext.CurrentSiteName, datetime);

        switch (result)
        {
        // Approving subscription was successful
        case SubscriberInfoProvider.ApprovalResult.Success:
            if (!String.IsNullOrEmpty(SuccessfulApprovalText))
            {
                lblInfo.Text = SuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.successful_approval");
            }

            // Log newsletter subscription activity
            SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash);
            if ((sni != null) && sni.SubscriptionEnabled)
            {
                NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(sni.NewsletterID);
                SubscriberInfo sb   = SubscriberInfoProvider.GetSubscriberInfo(sni.SubscriberID);
                if (sb != null)
                {
                    // Under what contacs this subscriber belogs to?
                    int contactId = ActivityTrackingHelper.GetContactID(sb);
                    if (contactId > 0)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
                        if (activity.Data != null)
                        {
                            activity.Data.ContactID = contactId;
                            activity.Log();
                        }
                    }
                }
            }
            break;

        // Subscription was already approved
        case SubscriberInfoProvider.ApprovalResult.Failed:
            if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
            {
                lblInfo.Text = UnsuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_failed");
            }
            break;

        case SubscriberInfoProvider.ApprovalResult.TimeExceeded:
            if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
            {
                lblInfo.Text = UnsuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_timeexceeded");
            }
            break;


        // Subscription not found
        default:
        case SubscriberInfoProvider.ApprovalResult.NotFound:
            if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
            {
                lblInfo.Text = UnsuccessfulApprovalText;
            }
            else
            {
                lblInfo.Text = ResHelper.GetString("newsletter.approval_invalid");
            }
            break;
        }
    }
    /// <summary>
    /// Saves the data.
    /// </summary>
    private bool Save(string newsletterName, SubscriberInfo 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
        NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterName, siteId);
        if (news != null)
        {
            try
            {
                // Check if subscriber is not allready subscribed
                if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberGUID, news.NewsletterGUID, siteId))
                {
                    toReturn = true;

                    // Subscribe to the site
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, news.NewsletterID, DateTime.Now, SendConfirmationEmail);

                    // Info message
                    if (!chooseMode)
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text = GetString("NewsletterSubscription.Subscribed");
                    }

                    // Track successful subscription conversion
                    if (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)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
                        activity.Log();
                    }
                }
                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;
    }
    /// <summary>
    /// Saves the data.
    /// </summary>
    private bool Save(string newsletterName, SubscriberInfo subscriber)
    {
        bool toReturn = false;
        int siteId = SiteContext.CurrentSiteID;

        // Check if subscriber info object exists
        if ((subscriber == null) || string.IsNullOrEmpty(newsletterName))
        {
            return false;
        }

        // Get newsletter info
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterName, siteId);
        if (newsletter != null)
        {
            try
            {
                // Check if subscriber is not already subscribed
                if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, newsletter.NewsletterID))
                {
                    toReturn = true;

                    mSubscriptionService.Subscribe(subscriber.SubscriberID, newsletter.NewsletterID, new SubscribeSettings()
                    {
                        SendConfirmationEmail = SendConfirmationEmail,
                        RequireOptIn = true,
                        RemoveAlsoUnsubscriptionFromAllNewsletters = true,
                    });

                    // Info message
                    if (!chooseMode)
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text = GetString("NewsletterSubscription.Subscribed");
                    }

                    // Track successful subscription conversion
                    if (TrackConversionName != string.Empty)
                    {
                        string siteName = SiteContext.CurrentSiteName;

                        if (AnalyticsHelper.AnalyticsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, RequestContext.UserHostAddress))
                        {
                            // Log conversion
                            HitLogProvider.LogConversions(siteName, LocalizationContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue);
                        }
                    }

                    // Log newsletter subscription activity if double opt-in is not required
                    if (!newsletter.NewsletterEnableOptIn)
                    {
                        Activity activity = new ActivityNewsletterSubscribing(subscriber, newsletter, AnalyticsContext.ActivityEnvironmentVariables);
                        activity.Log();
                    }
                }
                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(GetString(newsletter.NewsletterDisplayName)) + ".<br />";
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = ex.Message;
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = GetString("NewsletterSubscription.NewsletterDoesNotExist");
        }

        return toReturn;
    }
    /// <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>
    private void LogActivity(UserInfo ui, int newsletterId, bool subscribe)
    {
        if ((sb == null) || (ui == null))
        {
            return;
        }

        // Log activity only if subscriber is User
        if ((sb.SubscriberType != null) && sb.SubscriberType.Equals(UserInfo.OBJECT_TYPE, StringComparison.InvariantCultureIgnoreCase))
        {
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);
            Activity activity;
            if (subscribe)
            {
                activity = new ActivityNewsletterSubscribing(sb, news, AnalyticsContext.ActivityEnvironmentVariables);
            }
            else
            {
                activity = new ActivityNewsletterUnsubscribing(sb, news, AnalyticsContext.ActivityEnvironmentVariables);
            }
            activity.Log();
        }
    }
    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))
        {
            Visible = false;
            return;
        }

        // Try to approve subscription
        SubscriberInfoProvider.ApprovalResult result = SubscriberInfoProvider.ApproveSubscription(subscriptionHash, false, SiteContext.CurrentSiteName, datetime);

        switch (result)
        {
            // Approving subscription was successful
            case SubscriberInfoProvider.ApprovalResult.Success:
                if (!String.IsNullOrEmpty(SuccessfulApprovalText))
                {
                    lblInfo.Text = SuccessfulApprovalText;
                }
                else
                {
                    lblInfo.Text = ResHelper.GetString("newsletter.successful_approval");
                }

                // Log newsletter subscription activity
                SubscriberNewsletterInfo sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriptionHash);
                if ((sni != null) && sni.SubscriptionEnabled)
                {
                    NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(sni.NewsletterID);
                    SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(sni.SubscriberID);
                    if (sb != null)
                    {
                        // Under what contacs this subscriber belogs to?
                        int contactId = ActivityTrackingHelper.GetContactID(sb);
                        if (contactId > 0)
                        {
                            Activity activity = new ActivityNewsletterSubscribing(sb, news, AnalyticsContext.ActivityEnvironmentVariables);
                            if (activity.Data != null)
                            {
                                activity.Data.ContactID = contactId;
                                activity.Log();
                            }
                        }
                    }
                }
                break;

            case SubscriberInfoProvider.ApprovalResult.Failed:
                if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
                {
                    lblInfo.Text = UnsuccessfulApprovalText;
                }
                else
                {
                    lblInfo.Text = ResHelper.GetString("newsletter.approval_failed");
                }
                break;

            case SubscriberInfoProvider.ApprovalResult.TimeExceeded:
                if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
                {
                    lblInfo.Text = UnsuccessfulApprovalText;
                }
                else
                {
                    lblInfo.Text = ResHelper.GetString("newsletter.approval_timeexceeded");
                }
                break;

            case SubscriberInfoProvider.ApprovalResult.AlreadyApproved:
                if (!String.IsNullOrEmpty(SuccessfulApprovalText))
                {
                    lblInfo.Text = SuccessfulApprovalText;
                }
                else
                {
                    lblInfo.Text = ResHelper.GetString("newsletter.successful_approval");
                }
                break;

            // Subscription not found
            default:
            case SubscriberInfoProvider.ApprovalResult.NotFound:
                if (!String.IsNullOrEmpty(UnsuccessfulApprovalText))
                {
                    lblInfo.Text = UnsuccessfulApprovalText;
                }
                else
                {
                    lblInfo.Text = ResHelper.GetString("newsletter.approval_invalid");
                }
                break;
        }
    }
    /// <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>
    private void LogActivity(UserInfo ui, int newsletterId, bool subscribe)
    {
        if ((sb == null) || (ui == null))
        {
            return;
        }

        if (sb.SubscriberType.Equals(SiteObjectType.USER, StringComparison.InvariantCultureIgnoreCase))
        {
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);
            Activity activity;
            if (subscribe)
            {
                activity = new ActivityNewsletterSubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
            }
            else
            {
                activity = new ActivityNewsletterUnsubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
            }
            activity.Log();
        }
    }