Ejemplo n.º 1
0
    /// <summary>
    /// Uniselector item selected event handler.
    /// </summary>
    protected void UniSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.newsletter", "ManageSubscribers"))
        {
            RedirectToAccessDenied("cms.newsletter", "ManageSubscribers");
        }

        // Get new items from selector
        string newValues = ValidationHelper.GetString(selectNewsletter.Value, null);

        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

        // Get all selected newsletters
        foreach (string item in newItems)
        {
            int newsletterId = ValidationHelper.GetInteger(item, 0);

            // Get subscription
            SubscriberNewsletterInfo subscription = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(mSubscriberId, newsletterId);

            // If not already subscribed
            if (subscription == null)
            {
                // Send confirmation only when subscriber is not Role or CG type and only when Double opt-in is enabled.
                SubscriberInfoProvider.Subscribe(mSubscriberId, newsletterId, DateTime.Now, chkSendConfirmation.Checked, !mIsMultipleSubscriber && chkRequireOptIn.Checked);
            }
        }

        selectNewsletter.Value = null;
        unigridNewsletters.ReloadData();
        pnlUpdate.Update();
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Handles multiple selector actions.
    /// </summary>
    protected void btnOk_Clicked(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (drpActions.SelectedValue != "SELECT")
        {
            // Go through all selected items
            ArrayList list = UniGridSubscribers.SelectedItems;
            if (list.Count > 0)
            {
                SubscriberNewsletterInfo sni = null;
                foreach (object subscriberId in list)
                {
                    sni = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(ValidationHelper.GetInteger(subscriberId, 0), newsletterId);
                    if (sni != null)
                    {
                        switch (drpActions.SelectedValue)
                        {
                        // Remove subscription
                        case "REMOVE":
                            SubscriberProvider.Unsubscribe(sni, chkSendConfirmation.Checked);
                            break;

                        // Approve subscription
                        case "APPROVE":
                            if (!sni.SubscriptionApproved)
                            {
                                sni.SubscriptionApproved     = true;
                                sni.SubscriptionApprovedWhen = DateTime.Now;
                                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(sni);
                            }
                            break;

                        // Reject subscription
                        case "REJECT":
                            if (sni.SubscriptionApproved)
                            {
                                sni.SubscriptionApproved     = false;
                                sni.SubscriptionApprovedWhen = DateTime.MinValue;
                                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(sni);
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                ltlScript.Text += ScriptHelper.GetAlertScript(GetString("general.noitems"));
            }
        }
        UniGridSubscribers.ResetSelection();
        UniGridSubscribers.ReloadData();
    }
    /// <summary>
    /// Unigrid newsletters action handler.
    /// </summary>
    protected void unigridNewsletters_OnAction(string actionName, object actionArgument)
    {
        // Check 'configure' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "ManageSubscribers"))
        {
            RedirectToCMSDeskAccessDenied("cms.newsletter", "ManageSubscribers");
        }

        int newsletterId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLowerCSafe())
        {
        // Renew subscription
        case "subscribe":
            SubscriberInfoProvider.RenewSubscription(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Unsubscribe selected subscriber
        case "unsubscribe":
            SubscriberInfoProvider.Unsubscribe(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Unsubscribe selected subscriber
        case "remove":
            SubscriberInfoProvider.DeleteSubscription(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Approve selected subscription
        case "approve":
        {
            SubscriberNewsletterInfo subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
            if ((subscriptionInfo != null) && (!subscriptionInfo.SubscriptionApproved))
            {
                subscriptionInfo.SubscriptionApproved     = true;
                subscriptionInfo.SubscriptionApprovedWhen = DateTime.Now;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
            }
        }
        break;

        // Reject selected subscription
        case "reject":
        {
            SubscriberNewsletterInfo subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
            if ((subscriptionInfo != null) && (subscriptionInfo.SubscriptionApproved))
            {
                subscriptionInfo.SubscriptionApproved     = false;
                subscriptionInfo.SubscriptionApprovedWhen = DateTime.MinValue;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
            }
        }
        break;
        }
    }
Ejemplo n.º 4
0
        private void AssignSubscriberToNewsletter(int newsletterId, SubscriberInfo subscriber)
        {
            var subscription = new SubscriberNewsletterInfo
            {
                SubscriberID         = subscriber.SubscriberID,
                NewsletterID         = newsletterId,
                SubscriptionApproved = true,
                SubscribedWhen       = DateTime.Now,
            };

            SubscriberNewsletterInfo.Provider.Set(subscription);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void UniGridSubscribers_OnAction(string actionName, object actionArgument)
    {
        // Check 'manage subscribers' permission
        CheckAuthorization();

        int subscriberId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLower())
        {
        // Unsubscribe selected subscriber
        case "remove":
            SubscriberProvider.Unsubscribe(subscriberId, newsletterId, chkSendConfirmation.Checked);
            break;

        // Approve selected subscription
        case "approve":
        {
            SubscriberNewsletterInfo subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
            if ((subscriptionInfo != null) && (!subscriptionInfo.SubscriptionApproved))
            {
                subscriptionInfo.SubscriptionApproved     = true;
                subscriptionInfo.SubscriptionApprovedWhen = DateTime.Now;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
            }
        }
        break;

        // Reject selected subscription
        case "reject":
        {
            SubscriberNewsletterInfo subscriptionInfo = SubscriberNewsletterInfoProvider.GetSubscriberNewsletterInfo(subscriberId, newsletterId);
            if ((subscriptionInfo != null) && (subscriptionInfo.SubscriptionApproved))
            {
                subscriptionInfo.SubscriptionApproved     = false;
                subscriptionInfo.SubscriptionApprovedWhen = DateTime.MinValue;
                SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscriptionInfo);
            }
        }
        break;

        // Block selected subscriber
        case "block":
            SubscriberProvider.BlockSubscriber(subscriberId);
            break;

        // Un-block selected subscriber
        case "unblock":
            SubscriberProvider.UnblockSubscriber(subscriberId);
            break;
        }
    }
Ejemplo n.º 6
0
    /// <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();
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Creates and sends unsubscription e-mail.
    /// </summary>
    /// <param name="subscriber">Subscriber object</param>
    /// <param name="news">Newsletter object</param>
    /// <param name="subscription">Subscription object</param>
    /// <param name="siteName">Site name</param>
    protected void SendUnsubscriptionRequest(Subscriber subscriber, Newsletter news, SubscriberNewsletterInfo subscription, string siteName)
    {
        // Get global e-mail template with unsubscription request
        EmailTemplateInfo et = CMS.EmailEngine.EmailTemplateProvider.GetEmailTemplate("newsletter.unsubscriptionrequest", siteName);

        if (et != null)
        {
            // Get subscriber member
            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;

                string body      = et.TemplateText;
                string plainBody = et.TemplatePlainText;

                // Resolve newsletter macros (first name, last name etc.)
                IssueHelper ih = new IssueHelper();
                if (ih.LoadDynamicFields(sb, news, subscription, null, false, siteName, null, null, null))
                {
                    body      = ih.ResolveDynamicFieldMacros(body);
                    plainBody = ih.ResolveDynamicFieldMacros(plainBody);
                }

                // Create e-mail
                EmailMessage msg = new EmailMessage();
                msg.EmailFormat   = EmailFormatEnum.Default;
                msg.From          = EmailHelper.GetSender(et, news.NewsletterSenderEmail);
                msg.Recipients    = sb.SubscriberEmail;
                msg.BccRecipients = et.TemplateBcc;
                msg.CcRecipients  = et.TemplateCc;
                msg.Subject       = ResHelper.LocalizeString(et.TemplateSubject);
                msg.Body          = URLHelper.MakeLinksAbsolute(body);
                msg.PlainTextBody = URLHelper.MakeLinksAbsolute(plainBody);

                // Add attachments and send e-mail
                MetaFileInfoProvider.ResolveMetaFileImages(msg, et.TemplateID, EmailObjectType.EMAILTEMPLATE, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE);

                EmailSender.SendEmail(siteName, msg);
            }
        }
        else
        {
            // Log missing template
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent(EventLogProvider.EVENT_TYPE_ERROR, DateTime.Now, "UnsubscriptionRequest", "Unsubscription request e-mail template is missing.");
        }
    }
    /// <summary>
    /// Unsubscribes customer from newsletter. Called when the "Unsubscribe customer from newsletter" button is pressed.
    /// Expects the SubscribeCustomerToNewsletter method to be run first.
    /// </summary>
    private bool UnsubscribeCustomerFromNewsletter()
    {
        SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo("*****@*****.**", CMSContext.CurrentSiteID);

        if (subscriber != null)
        {
            DataSet subscriptions = SubscriberNewsletterInfoProvider.GetSubscriberNewsletters(subscriber.SubscriberID, null, -1, null);
            if (!DataHelper.DataSourceIsEmpty(subscriptions))
            {
                // Creates object from DataRow
                SubscriberNewsletterInfo subscription = new SubscriberNewsletterInfo(subscriptions.Tables[0].Rows[0]);

                // Unsubscribe customer from newsletter
                SubscriberNewsletterInfoProvider.DeleteSubscriberNewsletterInfo(subscription);

                return true;
            }
        }

        return false;
    }
    /// <summary>
    /// Subscribes customer to newsletter. Called when the "Subscribe customer to newsletter" button is pressed.
    /// Expects the CreateRegisteredCustomer method to be run first.
    /// </summary>
    private bool SubscribeCustomerToNewsletter()
    {
        // Prepare the parameters
        string where = "CustomerLastName LIKE N'My New Registered%'";
        CustomerInfo customer = null;

        // Get the customer
        DataSet customers = CustomerInfoProvider.GetCustomers(where, null);
        if (!DataHelper.DataSourceIsEmpty(customers))
        {
            // Create object from DataRow
            customer = new CustomerInfo(customers.Tables[0].Rows[0]);
        }

        // Get the newsletter
        NewsletterInfo customerNewsletter = NewsletterInfoProvider.GetNewsletterInfo("CorporateNewsletter", CMSContext.CurrentSiteID);

        if ((customer != null) && (customerNewsletter != null))
        {
            // Create the new subscription object
            SubscriberNewsletterInfo subscription = new SubscriberNewsletterInfo();

            SubscriberInfo customerExistedSubscriber = SubscriberInfoProvider.GetSubscriberInfo("*****@*****.**", CMSContext.CurrentSiteID);

            // Check if customer is subscriber
            if (customerExistedSubscriber != null)
            {
                // Subscribe existed customer subscriber to newsletter
                subscription.SubscriberID = customerExistedSubscriber.SubscriberID;
            }
            else
            {
                // Create the new subscriber object
                SubscriberInfo customerSubscriber = new SubscriberInfo();

                // Set the properties
                customerSubscriber.SubscriberEmail = customer.CustomerEmail;
                customerSubscriber.SubscriberLastName = customer.CustomerLastName;
                customerSubscriber.SubscriberSiteID = CMSContext.CurrentSiteID;

                // Create the new subscriber
                SubscriberInfoProvider.SetSubscriberInfo(customerSubscriber);

                // Subscribe new customer subscriber to newsletter
                subscription.SubscriberID = customerSubscriber.SubscriberID;
            }

            subscription.NewsletterID = customerNewsletter.NewsletterID;
            subscription.SubscribedWhen = DateTime.Now;

            // Save the data
            SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscription);

            return true;
        }

        return false;
    }
    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 = SubscriberInfoProvider.GetSubscribersFromView(email, siteId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    SubscriberInfo sb = new SubscriberInfo(dr);
                    if ((sb != null) && (string.IsNullOrEmpty(sb.SubscriberType) || sb.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACT, true) || sb.SubscriberType.EqualsCSafe(SiteObjectType.USER, true)))
                    {
                        // Get newsletter information
                        NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(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) && (sni.SubscriptionEnabled))
                            {
                                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(ErrorText))
                {
                    result = GetString("unsubscribe.notsubscribed");
                }
                else
                {
                    result = 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(ResultText))
            {
                // Use default message if none was specified
                lblInfo.Text = GetString("unsubscribe.confirmtext");
            }
            else
            {
                lblInfo.Text = ResultText;
            }
            lblError.Visible  = false;
            txtEmail.Visible  = false;
            btnSubmit.Visible = false;
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            int siteId = 0;

            // Get current id
            if (SiteContext.CurrentSite != null)
            {
                siteId = SiteContext.CurrentSiteID;
            }

            // Get subscriber and newsletter guid from query string
            Guid   subscriberGuid   = QueryHelper.GetGuid("subscriberguid", Guid.Empty);
            Guid   newsletterGuid   = QueryHelper.GetGuid("newsletterguid", Guid.Empty);
            Guid   issueGuid        = QueryHelper.GetGuid("issueguid", Guid.Empty);
            string subscriptionHash = QueryHelper.GetString("subscriptionhash", string.Empty);
            int    issueId          = QueryHelper.GetInteger("issueid", 0);
            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))
            {
                SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(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.EqualsCSafe(RoleInfo.OBJECT_TYPE, true))
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscriber.CannotUnsubscribeRole");
                    return;
                }

                NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterGuid, siteId);
                if (newsletter == null)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Unsubscribe.NewsletterDoesNotExist");
                    return;
                }

                // Check whether subscription is valid
                if (SubscriberInfoProvider.IsSubscribed(subscriber.SubscriberID, newsletter.NewsletterID))
                {
                    bool isSubscribed = true;

                    if (string.IsNullOrEmpty(subscriber.SubscriberType) ||
                        (!subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true) &&
                         !subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.PERSONA, true)))
                    {
                        // Unsubscribe action
                        SubscriberInfoProvider.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, siteId, 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) && sni.SubscriptionEnabled)
                {
                    SubscriberInfoProvider.ApprovalResult result = SubscriberInfoProvider.Unsubscribe(subscriptionHash, SendConfirmationEmail, SiteContext.CurrentSiteName, datetime);

                    switch (result)
                    {
                    // Approving subscription was successful
                    case SubscriberInfoProvider.ApprovalResult.Success:
                        bool isSubscribed = true;

                        // Get subscriber
                        SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(sni.SubscriberID);
                        if ((subscriber != null) && !string.IsNullOrEmpty(subscriber.SubscriberType) && (subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true) || subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.PERSONA, true)))
                        {
                            // 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 SubscriberInfoProvider.ApprovalResult.Failed:
                        lblError.Visible = true;
                        lblError.Text    = GetString("newsletter.unsubscribefailed");
                        break;

                    case SubscriberInfoProvider.ApprovalResult.TimeExceeded:
                        lblError.Visible = true;
                        lblError.Text    = GetString("newsletter.approval_timeexceeded");
                        break;

                    // Subscription not found
                    default:
                    case SubscriberInfoProvider.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)
    {
        // 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>
    /// Subscribes customer to newsletter. Called when the "Subscribe customer to newsletter" button is pressed.
    /// Expects the CreateRegisteredCustomer method to be run first.
    /// </summary>
    private bool SubscribeCustomerToNewsletter()
    {
        // Get the customer
        CustomerInfo customer = CustomerInfoProvider.GetCustomers().WhereStartsWith("CustomerLastName", "My New Registered").FirstOrDefault();

        // Get the newsletter
        NewsletterInfo customerNewsletter = NewsletterInfoProvider.GetNewsletterInfo("CorporateNewsletter", SiteContext.CurrentSiteID);

        if ((customer != null) && (customerNewsletter != null))
        {
            // Create the new subscription object
            SubscriberNewsletterInfo subscription = new SubscriberNewsletterInfo();

            SubscriberInfo customerExistedSubscriber = SubscriberInfoProvider.GetSubscriberInfo("*****@*****.**", SiteContext.CurrentSiteID);

            // Check if customer is subscriber
            if (customerExistedSubscriber != null)
            {
                // Subscribe existed customer subscriber to newsletter
                subscription.SubscriberID = customerExistedSubscriber.SubscriberID;
            }
            else
            {
                // Create the new subscriber object
                SubscriberInfo customerSubscriber = new SubscriberInfo();

                // Set the properties
                customerSubscriber.SubscriberEmail = customer.CustomerEmail;
                customerSubscriber.SubscriberLastName = customer.CustomerLastName;
                customerSubscriber.SubscriberSiteID = SiteContext.CurrentSiteID;

                // Create the new subscriber
                SubscriberInfoProvider.SetSubscriberInfo(customerSubscriber);

                // Subscribe new customer subscriber to newsletter
                subscription.SubscriberID = customerSubscriber.SubscriberID;
            }

            subscription.NewsletterID = customerNewsletter.NewsletterID;
            subscription.SubscribedWhen = DateTime.Now;

            // Save the data
            SubscriberNewsletterInfoProvider.SetSubscriberNewsletterInfo(subscription);

            return true;
        }

        return false;
    }
Ejemplo n.º 14
0
    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;
        }
    }
Ejemplo n.º 15
0
    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);
            }
        }
    }
    /// <summary>
    /// Creates and sends unsubscription e-mail.
    /// </summary>
    /// <param name="subscriber">Subscriber object</param>
    /// <param name="news">Newsletter object</param>
    /// <param name="subscription">Subscription object</param>
    /// <param name="siteName">Site name</param>
    protected void SendUnsubscriptionRequest(SubscriberInfo subscriber, NewsletterInfo news, SubscriberNewsletterInfo subscription, string siteName)
    {
        // Get global e-mail template with unsubscription request
        EmailTemplateInfo et = EmailTemplateProvider.GetEmailTemplate("newsletter.unsubscriptionrequest", siteName);
        if (et != null)
        {
            // Get subscriber member
            SortedDictionary<int, SubscriberInfo> subscribers = SubscriberInfoProvider.GetSubscribers(subscriber, 1, 0);
            foreach (KeyValuePair<int, SubscriberInfo> item in subscribers)
            {
                // Get 1st subscriber's member
                SubscriberInfo sb = item.Value;

                string body = et.TemplateText;
                string plainBody = et.TemplatePlainText;

                // Resolve newsletter macros (first name, last name etc.)
                IssueHelper ih = new IssueHelper();
                if (ih.LoadDynamicFields(sb, news, subscription, null, false, siteName, null, null, null))
                {
                    body = ih.ResolveDynamicFieldMacros(body);
                    plainBody = ih.ResolveDynamicFieldMacros(plainBody);
                }

                // Create e-mail
                EmailMessage msg = new EmailMessage();
                msg.EmailFormat = EmailFormatEnum.Default;
                msg.From = EmailHelper.GetSender(et, news.NewsletterSenderEmail);
                msg.Recipients = sb.SubscriberEmail;
                msg.BccRecipients = et.TemplateBcc;
                msg.CcRecipients = et.TemplateCc;
                msg.Subject = ResHelper.LocalizeString(et.TemplateSubject);
                msg.Body = URLHelper.MakeLinksAbsolute(body);
                msg.PlainTextBody = URLHelper.MakeLinksAbsolute(plainBody);

                // Add attachments and send e-mail
                MetaFileInfoProvider.ResolveMetaFileImages(msg, et.TemplateID, EmailObjectType.EMAILTEMPLATE, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE);

                EmailSender.SendEmail(siteName, msg);
            }
        }
        else
        {
            // Log missing template
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent(EventLogProvider.EVENT_TYPE_ERROR, DateTime.Now, "UnsubscriptionRequest", "Unsubscription request e-mail template is missing.");
        }
    }