Exemple #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();
    }
    /// <summary>
    /// Subscribes subscriber to a newsletter. Called when the "Subscribe to newsletter" button is pressed.
    /// Expects the CreateSubscriber method to be run first.
    /// </summary>
    private bool SubscribeToNewsletter()
    {
        // Get the subscriber and newsletter
        SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo("*****@*****.**", SiteContext.CurrentSiteID);
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewStaticNewsletter", SiteContext.CurrentSiteID);

        if ((subscriber != null) && (newsletter != null))
        {
            // Subscribe to 'My new static newsletter'
            SubscriberInfoProvider.Subscribe(subscriber.SubscriberID, newsletter.NewsletterID, DateTime.Now);

            return(true);
        }

        return(false);
    }
    /// <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;
        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)
                {
                    // Subscribe role
                    if (isRoleORContactGroup)
                    {
                        SubscriberInfoProvider.Subscribe(subscriberId, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false);
                    }
                    // Subscribe users and subscribers
                    else
                    {
                        SubscriberInfoProvider.Subscribe(subscriberId, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                    }
                }
            }
        }

        selectNewsletter.Value = null;
        unigridNewsletters.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// Subscriber control items changed event.
    /// </summary>
    protected void SubscriberSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int subscriberID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;

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

        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            // Add all new items to site
            foreach (string item in newItems)
            {
                subscriberID = ValidationHelper.GetInteger(item, 0);

                // Get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(subscriberID);

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                    }
                    catch
                    {
                    }
                }
            }
        }

        selectSubscriber.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
Exemple #5
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);
    }
Exemple #6
0
    private void usNewsletters_OnSelectionChanged(object sender, EventArgs e)
    {
        // Check 'EcommerceModify' permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Ecommerce", "EcommerceModify"))
        {
            // Check 'ModifyCustomers' permission if don't have general ecommerce modify permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Ecommerce", "ModifyCustomers"))
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
            }
        }

        // Check if a customer has a valid email
        if ((email != null) && (email.Trim() != string.Empty) && (ValidationHelper.IsEmail(email)))
        {
            // Check whether subscriber already exist
            var sb = GetSubscriber();
            if (sb == null)
            {
                // Create new subscriber
                sb = new SubscriberInfo
                {
                    SubscriberEmail     = email,
                    SubscriberFirstName = firstName,
                    SubscriberLastName  = lastName,
                    SubscriberFullName  = (firstName + " " + lastName).Trim(),
                    SubscriberSiteID    = siteId,
                    SubscriberGUID      = Guid.NewGuid()
                };
                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }

            var changed = false;

            // Remove old items
            string newValues = ValidationHelper.GetString(usNewsletters.Value, null);
            string items     = DataHelper.GetNewItemsInList(newValues, currentValues);
            if (!String.IsNullOrEmpty(items))
            {
                string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in newItems)
                {
                    int newsletterId = ValidationHelper.GetInteger(item, 0);

                    // If subscriber is subscribed, unsubscribe him
                    if (SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))
                    {
                        SubscriberInfoProvider.Unsubscribe(sb.SubscriberID, newsletterId);

                        changed = true;
                    }
                }
            }

            // Add new items
            items = DataHelper.GetNewItemsInList(currentValues, newValues);
            if (!String.IsNullOrEmpty(items))
            {
                string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in newItems)
                {
                    int newsletterId = ValidationHelper.GetInteger(item, 0);

                    // If subscriber is not subscribed, subscribe him
                    if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now);

                        changed = true;
                    }
                }
            }

            // Display information about successful (un)subscription if occurred
            if (changed)
            {
                ShowChangesSaved();
            }
        }
    }
    private void usNewsletters_OnSelectionChanged(object sender, EventArgs e)
    {
        if (RaiseOnCheckPermissions("ManageSubscribers", this))
        {
            if (StopProcessing)
            {
                return;
            }
        }

        // Get specified user if used instead of current user
        UserInfo ui = null;

        if (UserID > 0)
        {
            ui = UserInfoProvider.GetUserInfo(UserID);
        }
        else
        {
            ui = CMSContext.CurrentUser;
        }

        // Get specified site ID instead of current site ID
        int siteId = 0;

        if (SiteID > 0)
        {
            siteId = SiteID;
        }
        else
        {
            siteId = CMSContext.CurrentSiteID;
        }

        if ((sb == null) && (ui != null))
        {
            // Create new subsciber (bind to existing user account)
            if ((!ui.IsPublic()) && (ValidationHelper.IsEmail(ui.Email) || ValidationHelper.IsEmail(ui.UserName)))
            {
                sb = new SubscriberInfo();
                if (ui != null)
                {
                    if (!string.IsNullOrEmpty(ui.FirstName) && !string.IsNullOrEmpty(ui.LastName))
                    {
                        sb.SubscriberFirstName = ui.FirstName;
                        sb.SubscriberLastName  = ui.LastName;
                    }
                    else
                    {
                        sb.SubscriberFirstName = ui.FullName;
                    }
                    // Full name consists of "user " and user full name
                    sb.SubscriberFullName = "User '" + ui.FullName + "'";
                }

                sb.SubscriberSiteID    = siteId;
                sb.SubscriberType      = SiteObjectType.USER;
                sb.SubscriberRelatedID = ui.UserID;
                // Save subscriber to DB
                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }
        }

        if (sb == null)
        {
            return;
        }

        // Create membership between current contact and subscriber
        ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID());

        // Remove old items
        int    newsletterId = 0;
        string newValues    = ValidationHelper.GetString(usNewsletters.Value, null);
        string items        = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                foreach (string item in newItems)
                {
                    newsletterId = ValidationHelper.GetInteger(item, 0);

                    // If subscriber is subscribed, unsubscribe him
                    if (SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))
                    {
                        SubscriberInfoProvider.Unsubscribe(sb.SubscriberID, newsletterId, SendConfirmationEmail);
                        // Log activity
                        LogActivity(ui, newsletterId, false);
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                foreach (string item in newItems)
                {
                    newsletterId = ValidationHelper.GetInteger(item, 0);

                    // If subscriber is not subscribed, subscribe him
                    if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))
                    {
                        try
                        {
                            SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, SendConfirmationEmail);
                            // Log activity
                            LogActivity(ui, newsletterId, true);
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }

        // Display information about successful (un)subscription
        ShowChangesSaved();
    }
Exemple #8
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>
    /// Persona items selected event handler.
    /// </summary>
    protected void PersonaSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (personaSelector == null)
        {
            return;
        }

        int siteId = SiteContext.CurrentSiteID;

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

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Personas, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            // Get persona ID
            int personaID = ValidationHelper.GetInteger(item, 0);

            // Try to get subscriber
            SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.PERSONA, personaID, siteId);
            if (subscriber == null)
            {
                // Get persona display name
                var    persona     = BaseAbstractInfoProvider.GetInfoById(PredefinedObjectType.PERSONA, personaID);
                string personaName = ValidationHelper.GetString(persona.GetValue("PersonaDisplayName"), string.Empty);
                if (string.IsNullOrEmpty(personaName))
                {
                    continue;
                }

                // Create new subscriber of persona type
                subscriber = new SubscriberInfo();

                subscriber.SubscriberFirstName = personaName;

                // Full name consists of "persona" and display name
                subscriber.SubscriberFullName = new SubscriberFullNameFormater().GetPersonaSubscriberName(personaName);

                subscriber.SubscriberSiteID    = siteId;
                subscriber.SubscriberType      = PredefinedObjectType.PERSONA;
                subscriber.SubscriberRelatedID = personaID;

                CheckPermissionsForSubscriber(subscriber);

                SubscriberInfoProvider.SetSubscriberInfo(subscriber);
            }

            // If subscriber exists and is not subscribed, subscribe him
            if (!SubscriberInfoProvider.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID))
            {
                try
                {
                    SubscriberInfoProvider.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, DateTime.Now, chkSendConfirmation.Checked, false);
                }
                catch (InvalidOperationException ex)
                {
                    ShowError(ex.Message);
                }
            }
        }

        personaSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// Contact items selected event handler.
    /// </summary>
    protected void ContactSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cSelector == null)
        {
            return;
        }
        int siteId = SiteContext.CurrentSiteID;

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

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            // Get contact ID
            int contactID = ValidationHelper.GetInteger(item, 0);

            // Try to get subscriber
            SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.CONTACT, contactID, siteId);
            if (sb == null)
            {
                // Get contact's info
                DataSet contactData = ModuleCommands.OnlineMarketingGetContactForNewsletters(contactID, "ContactFirstName,ContactMiddleName,ContactLastName,ContactEmail");
                if (DataHelper.DataSourceIsEmpty(contactData))
                {
                    continue;
                }

                string firstName  = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactFirstName"], string.Empty);
                string lastName   = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactLastName"], string.Empty);
                string middleName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactMiddleName"], string.Empty);
                string email      = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactEmail"], string.Empty);

                // Create new subscriber of contact type
                sb = new SubscriberInfo();
                sb.SubscriberFirstName = firstName;
                sb.SubscriberLastName  = lastName;
                sb.SubscriberEmail     = email;
                sb.SubscriberFullName  = new SubscriberFullNameFormater().GetContactSubscriberName(firstName, middleName, lastName);
                sb.SubscriberSiteID    = siteId;
                sb.SubscriberType      = PredefinedObjectType.CONTACT;
                sb.SubscriberRelatedID = contactID;

                CheckPermissionsForSubscriber(sb);

                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }

            // Subscribe the existing or created subscriber
            if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, mNewsletter.NewsletterID))
            {
                try
                {
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, mNewsletter.NewsletterID, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                }
                catch (InvalidOperationException ex)
                {
                    ShowError(ex.Message);
                }
            }
        }

        cSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// Contact group items selected event handler.
    /// </summary>
    protected void CGSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cgSelector == null)
        {
            return;
        }
        int siteId = SiteContext.CurrentSiteID;

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

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            // Get group ID
            int groupID = ValidationHelper.GetInteger(item, 0);

            // Try to get subscriber
            SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.CONTACTGROUP, groupID, siteId);
            if (sb == null)
            {
                // Get contact group display name
                string cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID);
                if (string.IsNullOrEmpty(cgName))
                {
                    continue;
                }

                // Create new subscriber of contact group type
                sb = new SubscriberInfo();
                sb.SubscriberFirstName = cgName;
                // Full name consists of "contact group " and display name
                sb.SubscriberFullName  = new SubscriberFullNameFormater().GetContactGroupSubscriberName(cgName);
                sb.SubscriberSiteID    = siteId;
                sb.SubscriberType      = PredefinedObjectType.CONTACTGROUP;
                sb.SubscriberRelatedID = groupID;

                CheckPermissionsForSubscriber(sb);

                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }

            // If subscriber exists and is not subscribed, subscribe him
            if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, mNewsletter.NewsletterID))
            {
                try
                {
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, mNewsletter.NewsletterID, DateTime.Now, chkSendConfirmation.Checked, false);
                }
                catch (InvalidOperationException ex)
                {
                    ShowError(ex.Message);
                }
            }
        }

        cgSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// User control items changed event.
    /// </summary>
    protected void UserSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int siteId = SiteContext.CurrentSiteID;

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

        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            // Check limited number of subscribers
            if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert))
            {
                ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                break;
            }

            int userID = ValidationHelper.GetInteger(item, 0);

            // Get subscriber
            SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, userID, siteId);
            if (sb == null)
            {
                // Get user info
                UserInfo ui = UserInfoProvider.GetUserInfo(userID);
                if (ui == null)
                {
                    continue;
                }

                // Create new subscriber of user type
                sb = new SubscriberInfo();
                sb.SubscriberFirstName = ui.FullName;
                sb.SubscriberFullName  = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName);
                sb.SubscriberSiteID    = siteId;
                sb.SubscriberType      = UserInfo.OBJECT_TYPE;
                sb.SubscriberRelatedID = userID;

                CheckPermissionsForSubscriber(sb);

                SubscriberInfoProvider.SetSubscriberInfo(sb);
            }

            // If subscriber exists and is not subscribed, subscribe him
            if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, mNewsletter.NewsletterID))
            {
                try
                {
                    SubscriberInfoProvider.Subscribe(sb.SubscriberID, mNewsletter.NewsletterID, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                }
                catch (InvalidOperationException ex)
                {
                    ShowError(ex.Message);
                }
            }
        }

        selectUser.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// Contact items selected event handler.
    /// </summary>
    protected void ContactSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cSelector == null)
        {
            return;
        }
        int contactID = 0;

        string[]       newItems    = null;
        SubscriberInfo sb          = null;
        int            siteId      = CMSContext.CurrentSiteID;
        string         cType       = PredefinedObjectType.CONTACT;
        DataSet        contactData = null;

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

        // Get added items
        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                // Get contact ID
                contactID = ValidationHelper.GetInteger(item, 0);

                // Try to get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(cType, contactID, siteId);
                if (sb == null)
                {
                    // Get contact's info
                    contactData = ModuleCommands.OnlineMarketingGetContactForNewsletters(contactID, "ContactFirstName,ContactMiddleName,ContactLastName");
                    if (DataHelper.DataSourceIsEmpty(contactData))
                    {
                        continue;
                    }

                    string firstName  = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactFirstName"], string.Empty);
                    string lastName   = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactLastName"], string.Empty);
                    string middleName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactMiddleName"], string.Empty);

                    // Create new subscriber of contact type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = firstName;
                    sb.SubscriberLastName  = lastName;
                    sb.SubscriberFullName  = string.Format("Contact '{0}{1}{2}'", string.IsNullOrEmpty(firstName) ? string.Empty : firstName + " ", string.IsNullOrEmpty(middleName) ? string.Empty : middleName + " ", lastName);
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = cType;
                    sb.SubscriberRelatedID = contactID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                    }
                    catch
                    {
                    }
                }
            }
        }

        cSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// Contact group items selected event handler.
    /// </summary>
    protected void CGSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        if (cgSelector == null)
        {
            return;
        }
        int groupID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;
        int            siteId   = CMSContext.CurrentSiteID;
        string         cgType   = "om.contactgroup";
        string         cgName   = null;

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

        // Get added items
        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                // Get group ID
                groupID = ValidationHelper.GetInteger(item, 0);

                // Try to get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(cgType, groupID, siteId);
                if (sb == null)
                {
                    // Get contact group display name
                    cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID);
                    if (string.IsNullOrEmpty(cgName))
                    {
                        continue;
                    }

                    // Create new subscriber of contact group type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = cgName;
                    // Full name consists of "contact group " and display name
                    sb.SubscriberFullName  = string.Concat("Contact group '", cgName, "'");
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = cgType;
                    sb.SubscriberRelatedID = groupID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false);
                    }
                    catch
                    {
                    }
                }
            }
        }

        cgSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// User control items changed event.
    /// </summary>
    protected void UserSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int userID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;
        UserInfo       ui       = null;
        int            siteId   = CMSContext.CurrentSiteID;

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

        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                userID = ValidationHelper.GetInteger(item, 0);

                // Get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.USER, userID, siteId);
                if (sb == null)
                {
                    // Get user info
                    ui = UserInfoProvider.GetUserInfo(userID);
                    if (ui == null)
                    {
                        continue;
                    }

                    // Create new subscriber of user type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = ui.FullName;
                    sb.SubscriberFullName  = "User '" + ui.FullName + "'";
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = SiteObjectType.USER;
                    sb.SubscriberRelatedID = userID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked);
                    }
                    catch
                    {
                    }
                }
            }
        }

        selectUser.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
    /// <summary>
    /// Roles control items changed event.
    /// </summary>
    protected void RolesSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        int roleID = 0;

        string[]       newItems = null;
        SubscriberInfo sb       = null;
        RoleInfo       ri       = null;
        int            siteId   = CMSContext.CurrentSiteID;

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

        // Get added items
        newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        if (newItems != null)
        {
            foreach (string item in newItems)
            {
                // Check limited number of subscribers
                if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert))
                {
                    ShowError(GetString("licenselimitations.subscribers.errormultiple"));
                    break;
                }

                roleID = ValidationHelper.GetInteger(item, 0);

                // Get subscriber
                sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.ROLE, roleID, siteId);
                if (sb == null)
                {
                    // Get role info and copy display name to new subscriber
                    ri = RoleInfoProvider.GetRoleInfo(roleID);
                    if ((ri == null) || (ri.SiteID != siteId))
                    {
                        continue;
                    }

                    // Create new subscriber of role type
                    sb = new SubscriberInfo();
                    sb.SubscriberFirstName = ri.DisplayName;
                    // Full name consists of "role " and role display name
                    sb.SubscriberFullName  = string.Concat("Role '", ri.DisplayName, "'");
                    sb.SubscriberSiteID    = siteId;
                    sb.SubscriberType      = SiteObjectType.ROLE;
                    sb.SubscriberRelatedID = roleID;
                    SubscriberInfoProvider.SetSubscriberInfo(sb);
                }

                // If subscriber exists and is not subscribed, subscribe him
                if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
                {
                    try
                    {
                        SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false);
                    }
                    catch
                    {
                    }
                }
            }
        }

        selectRole.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }