Ejemplo n.º 1
0
        private string ReplaceSubscriberTags(string content, NewsletterSubscriber subscriber, NewsletterMode showMode, NewsletterMailing mailing = null)
        {
            content = content.Replace("[NAME]", (subscriber.Name != "") ? subscriber.Name : subscriber.Email)
                      .Replace("[FORENAME]", subscriber.ForeName)
                      .Replace("[NAMEPREFIX]", subscriber.NamePrefix)
                      .Replace("[COMPANYNAME]", subscriber.CompanyName)
                      .Replace("[DATE]", DateTime.Now.ToString("yyyy-MM-dd / hh:mm:ss"))
                      .Replace("[SEXE]", subscriber.GenderString)
                      .Replace("[BEGINNING]", subscriber.GenderString)
                      .Replace("[LIVEURL]", this.Site.DomainName + "/" + this.RelativeUrl)
                      .Replace("[UNSUBSCRIBEURL]", (mailing != null && this.Site.NewsletterOptOutEmailPage != null) ? this.Site.DomainName + this.Site.NewsletterOptOutEmailPage.RelativeUrl + "?subscriber=" + mailing.Subscriber.ID.ToString() : "")
                      .Replace("[USERCODE]", subscriber.ID.ToString());

            if (showMode == NewsletterMode.Online || showMode == NewsletterMode.GuestOnline)
            {
                content = content.Replace("{OnlineModeTemplate}", "").Replace("{/OnlineModeTemplate}", "");
                content = Regex.Replace(content, "{NewsletterModeTemplate}(.*?){/NewsletterModeTemplate}", "");
            }
            else
            {
                content = content.Replace("{NewsletterModeTemplate}", "").Replace("{/NewsletterModeTemplate}", "");
                content = Regex.Replace(content, "{OnlineModeTemplate}(.*?){/OnlineModeTemplate}", "");
            }

            //Is er een mailing mee gegeven?
            if (mailing != null)
            {
                content = ReplaceAttribute("href", content, mailing);
                content = ReplaceAttribute("src", content, mailing);
            }
            return(content);
        }
Ejemplo n.º 2
0
        public JsonResult SaveAbbonementEmail(string NewsLetterGroupId, string Email)
        {
            NewsletterSubscriber Subscriber;
            Guid            NewsletterGroupID      = Guid.Parse(NewsLetterGroupId);
            NewsletterGroup CurrentNewsletterGroup = NewsletterGroup.GetById <NewsletterGroup>(NewsletterGroupID);
            //BaseCollection<NewsletterSubscriber> SubScribers = BaseCollection<NewsletterSubscriber>.Get("EmailAdres = '" + Email + "'");
            BaseCollection <NewsletterSubscriber> SubScribers = BaseCollection <NewsletterSubscriber> .Get("Name = '" + Email + "'");

            if (SubScribers.Count >= 1)
            {
                Subscriber = SubScribers[0];

                if (Subscriber.SubscribedGroups.Where(c => c.ID == NewsletterGroupID).Count() >= 1)
                {
                    return(JsonResult.CreateResult(false, "Dit emailadres is al toegekend aan deze nieuwsbrief groep."));
                }
                else
                {
                    Subscriber.SubscribedGroups.Add(CurrentNewsletterGroup);
                    Subscriber.Save();
                }
            }
            else
            {
                Subscriber       = new BitPlate.Domain.Newsletters.NewsletterSubscriber();
                Subscriber.Email = Email;
                Subscriber.SubscribedGroups.Add(CurrentNewsletterGroup);
                Subscriber.Save();
            }
            return(JsonResult.CreateResult(true, CurrentNewsletterGroup.Subscribers));
        }
Ejemplo n.º 3
0
        private string importCsvRow(string row)
        {
            string log = string.Empty;

            string[] fields = row.Split(new char[] { Delimiter[0] });

            string email         = fields[EmailColumnNo].Trim();
            string achternaam    = fields[NameColumnNo].Trim();
            string voornaam      = fields[ForeNameColumnNo].Trim();
            string tussenvoegsel = fields[NamePrefixColumnNo].Trim();

            if (!EmailManager.isValidEmailAddress(email))
            {
                log = "Geen geldig email adres.";
            }
            else
            {
                NewsletterSubscriber subscriber = new NewsletterSubscriber();

                subscriber.Email            = email;
                subscriber.Name             = achternaam;
                subscriber.NamePrefix       = tussenvoegsel;
                subscriber.ForeName         = voornaam;
                subscriber.SubscribedGroups = this.Groups;

                subscriber.Save();
            }
            return(log);
        }
Ejemplo n.º 4
0
        public NewsletterSubscriber GetSubscriber(Guid id)
        {
            NewsletterSubscriber subscriber = BaseObject.GetById <NewsletterSubscriber>(id);

            if (subscriber == null)
            {
                subscriber           = new BitPlate.Domain.Newsletters.NewsletterSubscriber();
                subscriber.Confirmed = true;
                foreach (NewsletterGroup group in LoadNewsletterGroupList("Name ASC"))
                {
                    if (group.IsMandatoryGroup && !subscriber.SubscribedGroups.Contains(group))
                    {
                        subscriber.SubscribedGroups.Add(group);
                    }
                }
            }

            return(subscriber);
        }
Ejemplo n.º 5
0
        public void Send(NewsletterSubscriber Subscriber)
        {
            string            content  = Publish2(NewsletterMode.Newsletter, null);
            var               Mailings = Subscriber.Mailings.Where(c => c.Newsletter.ID == this.ID);
            NewsletterMailing Mailing;

            Mailing            = new NewsletterMailing();
            Mailing.Site       = Subscriber.Site;
            Mailing.Subscriber = Subscriber;
            Mailing.Newsletter = this;
            this.Mailings.Add(Mailing);

            Mailing.Name         = this.Name + "_" + DateTime.Now;
            Mailing.EmailAddress = Subscriber.Email;
            Mailing.Save();
            string subscriberContent = this.ReplaceSubscriberTags(content, Subscriber, NewsletterMode.Newsletter, Mailing);

            Mailing.NewsletterSent = EmailManager.SendMail(this.SentFromAddress, Subscriber.Email, this.Subject, subscriberContent, true);
            Mailing.Save();
        }
Ejemplo n.º 6
0
        public string Publish2(NewsletterMode newsletterMode, NewsletterMailing mailing)
        {
            string html = Template.Content;

            string head = "";

            if (newsletterMode != NewsletterMode.Newsletter)
            {
                string jQueryVersion = ConfigurationManager.AppSettings["jQueryVersion"];
                if (jQueryVersion == null || jQueryVersion == "")
                {
                    jQueryVersion = "jquery-1.8.2.js";
                }
                string jqueryScriptInclude = String.Format(@"
<script type=""text/javascript"" src=""/_js/{0}""></script>
", jQueryVersion);
                head = jqueryScriptInclude;
                string jQueryUIVersion       = "/_bitPlate/_js/jquery-ui-1.9.1.custom.js";
                string jqueryUIScriptInclude = String.Format(@"<script type=""text/javascript"" src=""{0}""></script>
", jQueryUIVersion);
                head += jqueryUIScriptInclude;
                head += getHeader();
            }
            foreach (CmsScript script in this.Template.Scripts)
            {
                if (script.ScriptType == ScriptTypeEnum.Css)
                {
                    head += @"<style>
" + script.Content + @"
</style>";
                }
            }
            foreach (CmsScript script in this.Scripts)
            {
                if (script.ScriptType == ScriptTypeEnum.Css)
                {
                    head += @"<style>
" + script.Content + @"
</style>";
                }
            }


            html = html.Replace("[HEAD]", head);

            Dictionary <string, string> modulesHtmlByContainerName = new Dictionary <string, string>();

            string where = "";
            // modules zichtbaar in de template
            if (this.Template != null)
            {
                where = String.Format("FK_Site='{0}' AND (CrossPagesMode=1 AND FK_Template = '{1}')", this.Site.ID, this.Template.ID);
                BaseCollection <BaseModule> templateModules = BaseCollection <BaseModule> .Get(where, "OrderingNumber");

                this.Modules.AddRange(templateModules);
                //foreach (BaseModule module in templateModules)
                //{
                //    if (!modulesHtmlByContainerName.ContainsKey(module.ContainerName))
                //    {
                //        modulesHtmlByContainerName.Add(module.ContainerName, "");
                //    }
                //    modulesHtmlByContainerName[module.ContainerName] += module.ConvertToType().Publish2(this);
                //}
            }
            //en alle newsletter modules
            BaseCollection <BaseModule> newsletterModules = BaseCollection <BaseModule> .Get("FK_Newsletter='" + this.ID + "'", "OrderingNumber");

            List <BaseModule> modules = this.Modules.GroupBy(c => c.ID).Select(c => c.FirstOrDefault()).OrderBy(c => c.OrderingNumber).ToList();

            foreach (BaseModule module in modules)
            {
                if (!modulesHtmlByContainerName.ContainsKey(module.ContainerName))
                {
                    modulesHtmlByContainerName.Add(module.ContainerName, "");
                }
                modulesHtmlByContainerName[module.ContainerName] += module.ConvertToType().Publish2(this);
            }

            foreach (CmsTemplateContainer container in this.Template.Containers)
            {
                string containerContent = "";
                modulesHtmlByContainerName.TryGetValue(container.Name, out containerContent);

                containerContent = "<div id='bitContainer" + container.Name + "' class='bitContainer'>" + containerContent + "</div>";
                html             = html.Replace("[" + container.Name.ToUpper() + "]", containerContent);
            }
            //head += Template.GetHeadContent();

            switch (newsletterMode)
            {
            case NewsletterMode.GuestOnline:
                NewsletterSubscriber subscriber = new NewsletterSubscriber();
                subscriber.ForeName = "Gast";
                subscriber.Gender   = Autorisation.BaseUser.SexeEnum.Undefined;
                html = ReplaceSubscriberTags(html, subscriber, newsletterMode);
                break;

            case NewsletterMode.Online:
                html = ReplaceSubscriberTags(html, mailing.Subscriber, newsletterMode);
                break;

            case NewsletterMode.Newsletter:
                //Het plaatsen van de waardes in een nieuwsbrief gebeurd tijdens het verzenden, omdat elke nieuwsbrief voorzien moet worden van andere gegevens.
                break;
            }

            return(html);
        }
Ejemplo n.º 7
0
        private string importSubscriber(string[] data, int[] importProgress)//BaseCollection<NewsletterGroup> newsGroups
        {
            string[] log = new string[6];
            try
            {
                BaseCollection <NewsletterSubscriber> subscribers = BaseCollection <NewsletterSubscriber> .Get("FK_Site = '" + WebSessionHelper.CurrentSite.ID.ToString() + "' AND Email = '" + data[this.EmailColumnNo].Trim() + "'");

                NewsletterSubscriber subscriber;

                var existingSubscriber = subscribers.Where(b => b.Email == data[this.EmailColumnNo]).FirstOrDefault();//Where(b => b.Name == data[this.NameColumnNo]).FirstOrDefault();

                if (existingSubscriber == null)
                {
                    if (EmailManager.isValidEmailAddress(data[this.EmailColumnNo].Trim()))
                    {
                        if (isValidDataLength(data) == true)
                        {
                            subscriber = new NewsletterSubscriber();
                            subscriber.RegistrationType = RegistrationTypeEnum.Import;
                            subscriber.Site             = WebSessionHelper.CurrentSite;
                            subscriber.Email            = data[this.EmailColumnNo].Trim();
                            subscriber.Confirmed        = (this.AutoConfirm);
                            if (this.ForeNameColumn != "" && this.ForeNameColumnNo != 9999)
                            {
                                subscriber.ForeName = data[this.ForeNameColumnNo];
                            }
                            if (this.NameColumn != "" && this.NameColumnNo != 9999)
                            {
                                subscriber.Name = data[this.NameColumnNo];
                            }
                            if (this.NamePrefixColumn != "" && this.NamePrefixColumnNo != 9999)
                            {
                                subscriber.NamePrefix = data[this.NamePrefixColumnNo];
                            }
                            //subscriber.Gender = data[this.GenderCoumnNo] // ERROR: cannot convert string/int > sexeEnum
                            subscriber.SubscribedGroups.AddRange(this.Groups);
                            subscriber.Save();

                            log[0] = importProgress[0].ToString();

                            if (this.NameColumnNo != 9999)
                            {
                                log[1] = data[this.NameColumnNo];
                            }
                            log[2] = data[this.EmailColumnNo];
                            log[3] = "Geimporteerd";
                            log[4] = importProgress[1].ToString();
                            log[5] = true.ToString();
                        }
                        else
                        {
                            string tooLong = "Het ";

                            if (this.EmailColumnNo != 9999)
                            {
                                if (data[this.EmailColumnNo].ToString().Length > 50)
                                {
                                    tooLong += "email adres, ";
                                }
                            }
                            if (this.NameColumnNo != 9999)
                            {
                                if (data[this.NameColumnNo].ToString().Length > 150)
                                {
                                    tooLong += "achternaam, ";
                                }
                            }
                            if (this.ForeNameColumnNo != 9999)
                            {
                                if (data[this.ForeNameColumnNo].ToString().Length > 250)
                                {
                                    tooLong += "voornaam, ";
                                }
                            }
                            if (this.NamePrefixColumnNo != 9999)
                            {
                                if (data[this.NamePrefixColumnNo].ToString().Length > 25)
                                {
                                    tooLong += "tussenvoegsel, ";
                                }
                            }
                            log[0] = importProgress[0].ToString();
                            if (this.NameColumnNo != 9999)
                            {
                                log[1] = data[this.NameColumnNo];
                            }
                            log[2] = data[this.EmailColumnNo];
                            log[3] = tooLong += "is te lang";
                            log[4] = importProgress[1].ToString();
                            log[5] = false.ToString();
                        }
                    }
                    else
                    {
                        log[0] = importProgress[0].ToString();
                        if (this.NameColumnNo != 9999)
                        {
                            log[1] = data[this.NameColumnNo];
                        }
                        log[2] = data[this.EmailColumnNo];
                        log[3] = "Geen geldig email adres";
                        log[4] = importProgress[1].ToString();
                        log[5] = false.ToString();
                    }
                }
                else if (existingSubscriber != null && this.SkipDoubleRecords == false)
                {
                    if (EmailManager.isValidEmailAddress(data[this.EmailColumnNo].Trim()) && isValidDataLength(data) == true)
                    {
                        if (this.AppendGroups == true)
                        {
                            for (int i = 0; i < existingSubscriber.SubscribedGroups.Count(); i++)
                            {
                                for (int j = 0; j < this.Groups.Count(); j++)
                                {
                                    if (this.Groups[j].ID == existingSubscriber.SubscribedGroups[i].ID)
                                    {
                                        this.Groups.RemoveAt(j);
                                        break;
                                    }
                                }
                            }
                        }

                        /* subscriber = new NewsletterSubscriber();
                         * subscriber.Site = SessionObject.CurrentSite;
                         * subscriber.Email = data[this.EmailColumnNo].Trim();
                         * subscriber.Confirmed = (this.AutoConfirm);
                         * subscriber.ForeName = data[this.ForeNameColumnNo];
                         * subscriber.Name = data[this.NameColumnNo];
                         * subscriber.NamePrefix = data[this.NamePrefixColumnNo];
                         * //subscriber.Gender = data[this.GenderColumnNo]; // ERROR: cannot convert string/int > sexeEnum
                         * subscriber.SubscribedGroups.AddRange(this.Groups);
                         * subscriber.Save();*/

                        existingSubscriber.Site      = WebSessionHelper.CurrentSite;
                        existingSubscriber.Confirmed = (this.AutoConfirm);

                        if (this.ForeNameColumn != "" && this.ForeNameColumnNo != 9999)
                        {
                            existingSubscriber.ForeName = data[this.ForeNameColumnNo];
                        }
                        else
                        {
                            existingSubscriber.ForeName = "";
                        }

                        if (this.NameColumn != "" && this.NameColumnNo != 9999)
                        {
                            existingSubscriber.Name = data[this.NameColumnNo];
                        }
                        else
                        {
                            existingSubscriber.Name = "";
                        }

                        if (this.NamePrefixColumn != "" && this.NamePrefixColumnNo != 9999)
                        {
                            existingSubscriber.NamePrefix = data[this.NamePrefixColumnNo];
                        }
                        else
                        {
                            existingSubscriber.NamePrefix = "";
                        }

                        if (this.AppendGroups == false)
                        {
                            existingSubscriber.SubscribedGroups.Clear();
                        }

                        if (existingSubscriber.SubscribedGroups != this.Groups)
                        {
                            existingSubscriber.SubscribedGroups.AddRange(this.Groups);
                        }

                        existingSubscriber.Save();

                        log[0] = importProgress[0].ToString();
                        if (this.NameColumnNo != 9999)
                        {
                            log[1] = data[this.NameColumnNo];
                        }
                        log[2] = data[this.EmailColumnNo];
                        log[3] = "Abonnee bestaat al. overschreven";
                        log[4] = importProgress[1].ToString();
                        log[5] = true.ToString();
                    }
                    else if (isValidDataLength(data) == false)
                    {
                        string tooLong = "Het ";

                        if (this.EmailColumnNo != 9999)
                        {
                            if (data[this.EmailColumnNo].ToString().Length > 50)
                            {
                                tooLong += "email adres, ";
                            }
                        }
                        if (this.NameColumnNo != 9999)
                        {
                            if (data[this.NameColumnNo].ToString().Length > 150)
                            {
                                tooLong += "achternaam, ";
                            }
                        }
                        if (this.ForeNameColumnNo != 9999)
                        {
                            if (data[this.ForeNameColumnNo].ToString().Length > 250)
                            {
                                tooLong += "voornaam, ";
                            }
                        }
                        if (this.NamePrefixColumnNo != 9999)
                        {
                            if (data[this.NamePrefixColumnNo].ToString().Length > 25)
                            {
                                tooLong += "tussenvoegsel, ";
                            }
                        }
                        log[0] = importProgress[0].ToString();
                        if (this.NameColumnNo != 9999)
                        {
                            log[1] = data[this.NameColumnNo];
                        }
                        log[2] = data[this.EmailColumnNo];
                        log[3] = tooLong += "is te lang";
                        log[4] = importProgress[1].ToString();
                        log[5] = false.ToString();
                    }
                    else
                    {
                        log[0] = importProgress[0].ToString();
                        if (this.NameColumnNo != 9999)
                        {
                            log[1] = data[this.NameColumnNo];
                        }
                        log[2] = data[this.EmailColumnNo];
                        log[3] = "Geen geldig email adres";
                        log[4] = importProgress[1].ToString();
                        log[5] = false.ToString();
                    }
                }
                else
                {
                    log[0] = importProgress[0].ToString();
                    if (this.NameColumnNo != 9999)
                    {
                        log[1] = data[this.NameColumnNo];
                    }
                    log[2] = data[this.EmailColumnNo];
                    log[3] = "Dubbele abonnee is overgeslagen";
                    log[4] = importProgress[1].ToString();
                    log[5] = true.ToString();
                }
            }
            catch (Exception ex)
            {
                log[0] = importProgress[0].ToString();
                log[2] = "";
                log[3] = "SYSTEEM FOUT: " + ex.Message;
                log[4] = importProgress[1].ToString();
                log[5] = false.ToString();
            }
            if (log[5] == false.ToString())
            {
                return("FOUT in regel " + log[0] + "/" + log[4] + " : " + log[2] + " = " + log[3] + ".");
            }
            else
            {
                return("GESLAAGD regel " + log[0] + "/" + log[4] + " : " + log[2] + " = " + log[3] + ".");
            }
        }