Esempio n. 1
0
        public static string SupportLinkAnonymousReplacement(CMSDataContext db, string oid, string gsid)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var qs = $"{oid},0,0,{"supportlink"}:{gsid}";

            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            return(db.ServerLink($"/OnlineReg/SendLink/{ot.Id.ToCode()}"));
        }
Esempio n. 2
0
        public static void RegisterHelpers(CMSDataContext db)
        {
            Handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(CssStyle.BottomBorder); });
            Handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(CssStyle.AlignTop); });
            Handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(CssStyle.AlignRight); });
            Handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(CssStyle.DataLabelStyle); });
            Handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(CssStyle.LabelStyle); });
            Handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(CssStyle.DataStyle); });

            Handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
            Handlebars.RegisterHelper("FmtZip", (writer, context, args) => { writer.Write(args[0].ToString().FmtZip()); });
            Handlebars.RegisterHelper("IfEqual", (writer, options, context, args) =>
            {
                if (IsEqual(args))
                    options.Template(writer, (object)context);
                else
                    options.Inverse(writer, (object)context);
            });
            Handlebars.RegisterHelper("IfNotEqual", (writer, options, context, args) =>
            {
                if (!IsEqual(args))
                    options.Template(writer, (object)context);
                else
                    options.Inverse(writer, (object)context);
            });
            Handlebars.RegisterHelper("GetToken", (writer, context, args) =>
            {
                var s = args[0].ToString();
                var n = args[1].ToInt();
                var ntoks = args.Length > 2 ? args[2].ToInt() : 2;
                var sep = args.Length > 3 ? args[3].ToString() : " ";
                var a = s.SplitStr(sep, ntoks);
                writer.Write(a[n].trim());
            });

            // Format helper in form of:  {{Fmt value "fmt"}}
            // ex. {{Fmt Total "C"}}
            // fmt is required. Uses standard/custom dotnet format strings
            Handlebars.RegisterHelper("Fmt", (writer, context, args) =>
            {
                var fmt = $"{{0:{args[1]}}}";
                writer.Write(fmt, args[0]);
            });

            // FmtPhone helper in form of:  {{FmtPhone phone# "prefix"}}
            Handlebars.RegisterHelper("FmtPhone", (writer, context, args) => { writer.Write(args[0].ToString().FmtFone($"{args[1]}")); });

            Handlebars.RegisterHelper("ReplaceCode", (writer, context, args) =>
            {
                EmailReplacements r = context.Replacements as EmailReplacements
                    ?? (context.Replacements = new EmailReplacements(db));
                var code = args[0].ToString();
                var p = db.LoadPersonById(args[1].ToInt());
                int? oid = null;
                if(args.Length == 3)
                    oid = args[2].ToInt2();
                writer.Write(r.RenderCode(code, p, oid));
            });
        }
Esempio n. 3
0
 public static void RegisterHelpers(CMSDataContext db)
 {
     Handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(BottomBorder); });
     Handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(AlignTop); });
     Handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(AlignRight); });
     Handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(DataLabelStyle); });
     Handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(LabelStyle); });
     Handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(DataStyle); });
     Handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
 }
Esempio n. 4
0
        public string PayLink2(CMSDataContext db)
        {
            if (!TranId.HasValue)
            {
                return(null);
            }
            var estr = HttpUtility.UrlEncode(Util.Encrypt(TranId.ToString()));

            return(db.ServerLink("/OnlineReg/PayAmtDue?q=" + estr));
        }
Esempio n. 5
0
        public static string DropFromOrgLinkUrl(CMSDataContext db, int orgid, int pid, int queueid)
        {
            var qs = $"{orgid},{pid},{queueid}";
            var ot = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs,
            };

            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            var url = db.ServerLink($"/OnlineReg/DropFromOrgLink/{ot.Id.ToCode()}");

            return(url);
        }
Esempio n. 6
0
        public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype)
        {
            var    showfamily = linktype == "registerlink2";
            string qs         = "{0},{1},{2},{3}".Fmt(orgid, pid, queueid, linktype);
            var    ot         = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs
            };

            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            string url = db.ServerLink("/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            return(url);
        }
Esempio n. 7
0
        public static void RegisterHelpers(CMSDataContext db)
        {
            Handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(CssStyle.BottomBorder); });
            Handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(CssStyle.AlignTop); });
            Handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(CssStyle.AlignRight); });
            Handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(CssStyle.DataLabelStyle); });
            Handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(CssStyle.LabelStyle); });
            Handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(CssStyle.DataStyle); });
            Handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
            Handlebars.RegisterHelper("FmtZip", (writer, context, args) => { writer.Write(args[0].ToString().FmtZip()); });
            Handlebars.RegisterHelper("IfEqual", (writer, options, context, args) =>
            {
                var eq = args[0] == args[1];
                if (!eq && args[0] is int)
                    eq = args[0].ToString() == args[1].ToString();
                if (eq)
                    options.Template(writer, (object) context);
                else
                    options.Inverse(writer, (object) context);
            });
            Handlebars.RegisterHelper("GetToken", (writer, context, args) =>
            {
                var s = args[0].ToString();
                var n = args[1].ToInt();
                var a = s.SplitStr(" ", 2);
                writer.Write(a[n]);
            });

            // Format helper in form of:  {{Fmt value "fmt"}}
            // ex. {{Fmt Total "C"}}
            // fmt is required. Uses standard/custom dotnet format strings
            Handlebars.RegisterHelper("Fmt", (writer, context, args) =>
            {
                var fmt = $"{{0:{args[1]}}}";
                writer.Write(fmt, args[0]);
            });

            // FmtPhone helper in form of:  {{FmtPhone phone# "prefix"}}
            Handlebars.RegisterHelper("FmtPhone", (writer, context, args) => { writer.Write(args[0].ToString().FmtFone($"{args[1]}")); });
        }
        public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype, DateTime?expires = null)
        {
            var showfamily = linktype == "registerlink2";
            var qs         = $"{orgid},{pid},{queueid},{linktype}";
            var ot         = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs,
            };

            if (expires.HasValue)
            {
                ot.Expires = expires.Value;
            }
            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            var url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            return(url);
        }
Esempio n. 9
0
 public string PayLink2(CMSDataContext db)
 {
     if (!TranId.HasValue)
         return null;
     var estr = HttpUtility.UrlEncode(Util.Encrypt(TranId.ToString()));
     return db.ServerLink("/OnlineReg/PayAmtDue?q=" + estr);
 }
Esempio n. 10
0
        public static Person Add(CMSDataContext Db, bool SendNotices, Family fam, int position, Tag tag, string firstname, string nickname, string lastname, string dob, int MarriedCode, int gender, int originId, int? EntryPointId, bool testing = false)
        {
            var p = new Person();
            p.CreatedDate = Util.Now;
            p.CreatedBy = Util.UserId;
            Db.People.InsertOnSubmit(p);
            p.PositionInFamilyId = position;
            p.AddressTypeId = 10;

            if (Util.HasValue(firstname))
                p.FirstName = firstname.Trim().ToProper().Truncate(25);
            else
                p.FirstName = "";

            if (Util.HasValue(nickname))
                p.NickName = nickname.Trim().ToProper().Truncate(15);

            if (Util.HasValue(lastname))
                p.LastName = lastname.Trim().ToProper().Truncate(30);
            else
                p.LastName = "?";

            p.GenderId = gender;
            if (p.GenderId == 99)
                p.GenderId = 0;
            p.MaritalStatusId = MarriedCode;

            DateTime dt;
            if (Util.BirthDateValid(dob, out dt))
            {
                if (dt.Year == Util.SignalNoYear)
                {
                    p.BirthDay = dt.Day;
                    p.BirthMonth = dt.Month;
                    p.BirthYear = null;
                }
                else
                {
                    while (dt.Year < 1900)
                        dt = dt.AddYears(100);
                    if (dt > Util.Now)
                        dt = dt.AddYears(-100);
                    p.BirthDay = dt.Day;
                    p.BirthMonth = dt.Month;
                    p.BirthYear = dt.Year;
                }
                if (p.GetAge() < 18 && MarriedCode == 0)
                    p.MaritalStatusId = MaritalStatusCode.Single;
            }
                // I think this else statement is no longer necessary
            else if (DateTime.TryParse(dob, out dt))
            {
                p.BirthDay = dt.Day;
                p.BirthMonth = dt.Month;
                if (Regex.IsMatch(dob, @"\d+[-/]\d+[-/]\d+"))
                {
                    p.BirthYear = dt.Year;
                    while (p.BirthYear < 1900)
                        p.BirthYear += 100;
                    if (p.GetAge() < 18 && MarriedCode == 0)
                        p.MaritalStatusId = MaritalStatusCode.Single;
                }
            }

            p.MemberStatusId = MemberStatusCode.JustAdded;
            if (fam == null)
            {
                fam = new Family();
                Db.Families.InsertOnSubmit(fam);
                p.Family = fam;
            }
            else
                fam.People.Add(p);

            if (tag != null)
                tag.PersonTags.Add(new TagPerson { Person = p });

            p.OriginId = originId;
            p.EntryPointId = EntryPointId;
            p.FixTitle();
            if(Db.Setting("ElectronicStatementDefault", "false").Equal("true"))
                p.ElectronicStatement = true;
            if (!testing)
                Db.SubmitChanges();
            if (SendNotices)
            {
                if (Util.UserPeopleId.HasValue
                    && Util.UserPeopleId.Value != Db.NewPeopleManagerId
                    && HttpContext.Current.User.IsInRole("Access")
                    && !HttpContext.Current.User.IsInRole("OrgMembersOnly")
                    && !HttpContext.Current.User.IsInRole("OrgLeadersOnly"))
                    Task.AddNewPerson(Db, p.PeopleId);
                else
                {
                    var np = Db.GetNewPeopleManagers();
                    if (np != null)
                        Db.Email(Util.SysFromEmail, np,
                            $"Just Added Person on {Db.Host}",
                            $"<a href='{Db.ServerLink("/Person2/" + p.PeopleId)}'>{p.Name}</a>");
                }
            }
            return p;
        }
Esempio n. 11
0
        public static IHandlebars RegisterHelpers(CMSDataContext db, PythonModel pm = null, IHandlebars handlebars = null)
        {
            handlebars = handlebars ?? Handlebars.Create();
            handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(CssStyle.BottomBorder); });
            handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(CssStyle.AlignTop); });
            handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(CssStyle.AlignRight); });
            handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(CssStyle.DataLabelStyle); });
            handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(CssStyle.LabelStyle); });
            handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(CssStyle.DataStyle); });

            handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
            handlebars.RegisterHelper("FmtZip", (writer, context, args) => { writer.Write(args[0].ToString().FmtZip()); });
            handlebars.RegisterHelper("HtmlComment", (writer, context, args) =>
            {
#if DEBUG
                writer.Write($"<h6>{args[0].ToString()} {args[1].ToString()}</h6>");
#else
                writer.Write($"<!--{args[0].ToString()} {args[1].ToString()}-->");
#endif
            });
            handlebars.RegisterHelper("IfEqual", (writer, options, context, args) =>
            {
                if (IsEqual(args))
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("IfNotEqual", (writer, options, context, args) =>
            {
                if (!IsEqual(args))
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("IfCond", (writer, options, context, args) =>
            {
                var op = HttpUtility.HtmlDecode(args[1].ToString());
                bool b = false;
                switch (op)
                {
                case "==":
                    b = Compare(args) == 0;
                    break;

                case "!=":
                    b = Compare(args) != 0;
                    break;

                case "<":
                    b = Compare(args) < 0;
                    break;

                case ">":
                    b = Compare(args) > 0;
                    break;

                case ">=":
                    b = Compare(args) >= 0;
                    break;

                case "<=":
                    b = Compare(args) <= 0;
                    break;

                case "&&":
                    b = NumTrue(args) == 2;
                    break;

                case "||":
                    b = NumTrue(args) >= 1;
                    break;
                }
                if (b)
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("IfGT", (writer, options, context, args) =>
            {
                if (Compare2(args) > 0)
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("IfLT", (writer, options, context, args) =>
            {
                if (Compare2(args) < 0)
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("IfGE", (writer, options, context, args) =>
            {
                if (Compare2(args) <= 0)
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("IfLE", (writer, options, context, args) =>
            {
                if (Compare2(args) <= 0)
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            handlebars.RegisterHelper("GetToken", (writer, context, args) =>
            {
                var s     = args[0].ToString();
                var n     = args[1].ToInt();
                var ntoks = args.Length > 2 ? args[2].ToInt() : 2;
                var sep   = args.Length > 3 ? args[3].ToString() : " ";
                var a     = s.SplitStr(sep, ntoks);
                writer.Write(a[n]?.Trim() ?? "");
            });

            handlebars.RegisterHelper("FmtMDY", (writer, context, args) =>
            {
                DateTime dt;
                var s = args[0].ToString();
                if (DateTime.TryParse(s, out dt))
                {
                    writer.Write(dt.ToShortDateString());
                }
            });
            handlebars.RegisterHelper("FmtDate", (writer, context, args) =>
            {
                DateTime dt;
                var s = args[0].ToString();
                if (DateTime.TryParse(s, out dt))
                {
                    writer.Write(dt.ToShortDateString());
                }
            });
            handlebars.RegisterHelper("FmtMoney", (writer, context, args) =>
            {
                decimal d;
                var s = args[0].ToString();
                if (decimal.TryParse(s, out d))
                {
                    writer.Write(d.ToString("C"));
                }
            });

            // Format helper in form of:  {{Fmt value "fmt"}}
            // ex. {{Fmt Total "C"}}
            // fmt is required. Uses standard/custom dotnet format strings
            handlebars.RegisterHelper("Fmt", (writer, context, args) =>
            {
                var fmt = $"{{0:{args[1]}}}";
                writer.Write(fmt, args[0]);
            });

            // FmtPhone helper in form of:  {{FmtPhone phone# "prefix"}}
            handlebars.RegisterHelper("FmtPhone", (writer, context, args) => { writer.Write(args[0].ToString().FmtFone($"{args[1]}")); });

            handlebars.RegisterHelper("ReplaceCode", (writer, context, args) =>
            {
                EmailReplacements r = context.Replacements as EmailReplacements
                                      ?? (context.Replacements = new EmailReplacements(db));
                var code = args[0].ToString();
                var p    = db.LoadPersonById(args[1].ToInt());
                int?oid  = null;
                if (args.Length == 3)
                {
                    oid = args[2].ToInt2();
                }
                writer.Write(r.RenderCode(code, p, oid));
            });
            handlebars.RegisterHelper("Json", (writer, options, context, args) =>
            {
                dynamic a = JsonDeserialize2(args[0].ToString());
                foreach (var item in a)
                {
                    options.Template(writer, item);
                }
            });

            handlebars.RegisterHelper("Calc", (writer, context, args) =>
            {
                var calcAmt    = args[0].ToDouble() - args[1].ToDouble();
                var calcAmtfmt = $"{{0:{'c'}}}";
                writer.Write(calcAmtfmt, calcAmt);
            });

            handlebars.RegisterHelper("ThrowError", (writer, context, args) =>
            {
                throw new Exception("ThrowError called in Handlebars Helper");
            });

            return(handlebars);
        }
Esempio n. 12
0
 public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype, DateTime? expires = null)
 {
     var showfamily = linktype == "registerlink2";
     var qs = $"{orgid},{pid},{queueid},{linktype}";
     var ot = new OneTimeLink
     {
         Id = Guid.NewGuid(),
         Querystring = qs,
     };
     if (expires.HasValue)
         ot.Expires = expires.Value;
     db.OneTimeLinks.InsertOnSubmit(ot);
     db.SubmitChanges();
     var url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");
     if (showfamily)
         url += "?showfamily=true";
     return url;
 }
Esempio n. 13
0
 public static string TaskLink(CMSDataContext Db, string text, int id)
 {
     return("<a href='{0}'>{1}</a>".Fmt(Db.ServerLink(TaskLink0(id)), text));
 }
Esempio n. 14
0
 public static string TaskLink(CMSDataContext Db, string text, int id)
 {
     return($"<a href='{Db.ServerLink(TaskLink0(id))}'>{text}</a>");
 }
Esempio n. 15
0
 public static string TaskLink(CMSDataContext Db, string text, int id)
 {
     return $"<a href='{Db.ServerLink(TaskLink0(id))}'>{text}</a>";
 }
Esempio n. 16
0
        private string DoReplaceCode(string code, Person p, PayInfo pi = null, EmailQueueTo emailqueueto = null)
        {
            if (code.StartsWith("<style"))
            {
                return(code);
            }
            switch (code.ToLower())
            {
            case "{address}":
                return(p.PrimaryAddress);

            case "{address2}":
                if (p.PrimaryAddress2.HasValue())
                {
                    return("<br>" + p.PrimaryAddress2);
                }
                return("");

            case "{amtdue}":
                if (pi != null)
                {
                    return(pi.AmountDue.ToString2("c"));
                }
                break;

            case "{amtpaid}":
                if (pi != null)
                {
                    return(pi.AmountPaid.ToString2("c"));
                }
                break;

            case "{amount}":
                if (pi != null)
                {
                    return(pi.Amount.ToString2("c"));
                }
                break;

            case "{barcode}":
                return($"<img src='{db.ServerLink("/Track/Barcode/" + p.PeopleId)}' />");

            case "{campus}":
                return(p.CampusId != null ? p.Campu.Description : $"No {Util2.CampusLabel} Specified");

            case "{cellphone}":
                return(p.CellPhone.HasValue() ? p.CellPhone.FmtFone() : "no cellphone on record");

            case "{city}":
                return(p.PrimaryCity);

            case "{csz}":
                return(Util.FormatCSZ(p.PrimaryCity, p.PrimaryState, p.PrimaryZip));

            case "{country}":
                return(p.PrimaryCountry);

            case "{createaccount}":
                if (emailqueueto != null)
                {
                    return(CreateUserTag(emailqueueto));
                }
                break;

            case "{church}":
                return(db.Setting("NameOfChurch", "Set this in NameOfChurch setting"));

            case "{cmshost}":
                return(db.ServerLink());

            case "{dob}":
                return(p.DOB);

            case "{estatement}":
                if (p.ElectronicStatement == true)
                {
                    return("Online Electronic Statement Only");
                }
                else
                {
                    return("Printed Statement in Addition to Online Option");
                }

            case "{emailhref}":
                if (emailqueueto != null)
                {
                    return(db.ServerLink("/EmailView/" + emailqueueto.Id));
                }
                break;

            case "{first}":
                return(p.PreferredName.Contains("?") || p.PreferredName.Contains("unknown", true) ? "" : p.PreferredName);

            case "{fromemail}":
                return(from.Address);

            case "{homephone}":
                return(p.HomePhone.HasValue() ? p.HomePhone.FmtFone() : "no homephone on record");

            case "{last}":
                return(p.LastName);

            case "{name}":
                return(p.Name.Contains("?") || p.Name.Contains("unknown", true) ? "" : p.Name);

            case "{nextmeetingtime}":
                if (emailqueueto != null)
                {
                    return(NextMeetingDate(code, emailqueueto));
                }
                break;

            case "{nextmeetingtime0}":
                if (emailqueueto != null)
                {
                    return(NextMeetingDate0(code, emailqueueto));
                }
                break;

            case "{occupation}":
                return(p.OccupationOther);

            case "{orgname}":
            case "{org}":
                return(GetOrgInfo(emailqueueto).Name);

            case "{orgmembercount}":
                return(GetOrgInfo(emailqueueto).Count);

            case "{paylink}":
                if (pi != null && pi.PayLink.HasValue())
                {
                    return($"<a href=\"{pi.PayLink}\">Click this link to make a payment and view your balance.</a>");
                }
                break;

            case "{peopleid}":
                return(p.PeopleId.ToString());

            case "{receivesms}":
                if (p.ReceiveSMS == true)
                {
                    return("Yes");
                }
                else
                {
                    return("No");
                }

            case "{salutation}":
                if (emailqueueto != null)
                {
                    return(db.GoerSupporters.Where(ee => ee.Id == emailqueueto.GoerSupportId).Select(ee => ee.Salutation).SingleOrDefault());
                }
                break;

            case "{state}":
                return(p.PrimaryState);

            case "{statementtype}":
                var stmtcode = p.ContributionOptionsId;
                switch (stmtcode)
                {
                case CmsData.Codes.StatementOptionCode.Individual:
                    return("Individual");

                case CmsData.Codes.StatementOptionCode.Joint:
                    return("Joint");

                case CmsData.Codes.StatementOptionCode.None:
                default:
                    return("None");
                }


            case "{email}":
            case "{toemail}":
                if (ListAddresses.Count > 0)
                {
                    return(ListAddresses[0].Address);
                }
                break;

            case "{today}":
                return(DateTime.Today.ToShortDateString());

            case "{title}":
                if (p.TitleCode.HasValue())
                {
                    return(p.TitleCode);
                }
                return(p.ComputeTitle());

            case "{track}":
                if (emailqueueto != null)
                {
                    return(emailqueueto.Guid.HasValue ?
                           $"<img src=\"{db.ServerLink("/Track/Key/" + emailqueueto.Guid.Value.GuidToQuerystring())}\" />"
                            : "");
                }
                break;

            case "{unsubscribe}":
                if (emailqueueto != null)
                {
                    return(UnSubscribeLink(emailqueueto));
                }
                break;

            default:
                if (emailqueueto == null)
                {
                    emailqueueto = new EmailQueueTo()
                    {
                        PeopleId = p.PeopleId,
                        OrgId    = db.CurrentOrgId0
                    }
                }
                ;

                if (code.StartsWith("{addsmallgroup:", StringComparison.OrdinalIgnoreCase))
                {
                    return(AddSmallGroup(code, emailqueueto));
                }

                if (code.StartsWith("{extra", StringComparison.OrdinalIgnoreCase))
                {
                    return(ExtraValue(code, emailqueueto));
                }

                if (registerLinkRe.IsMatch(code))
                {
                    return(RegisterLink(code, emailqueueto));
                }

                if (registerHrefRe.IsMatch(code))
                {
                    return(RegisterLinkHref(code, emailqueueto));
                }

                if (registerTagRe.IsMatch(code))
                {
                    return(RegisterTag(code, emailqueueto));
                }

                if (rsvpLinkRe.IsMatch(code))
                {
                    return(RsvpLink(code, emailqueueto));
                }

                if (sendLinkRe.IsMatch(code))
                {
                    return(SendLink(code, emailqueueto));
                }

                if (code.StartsWith("{orgextra:", StringComparison.OrdinalIgnoreCase))
                {
                    return(OrgExtra(code, emailqueueto));
                }

                if (code.StartsWith("{orgmember:", StringComparison.OrdinalIgnoreCase))
                {
                    return(OrgMember(code, emailqueueto));
                }

                if (code.StartsWith("{orgbarcode"))
                {
                    return(OrgBarcode(code, emailqueueto));
                }

                if (code.StartsWith("{smallgroup:", StringComparison.OrdinalIgnoreCase))
                {
                    return(SmallGroup(code, emailqueueto));
                }
                if (code.StartsWith("{subgroup:", StringComparison.OrdinalIgnoreCase))
                {
                    return(SmallGroup(code, emailqueueto));
                }

                if (regTextRe.IsMatch(code))
                {
                    return(RegText(code, emailqueueto));
                }

                if (code.StartsWith("{smallgroups", StringComparison.OrdinalIgnoreCase))
                {
                    return(SmallGroups(code, emailqueueto));
                }
                if (code.StartsWith("{subgroups", StringComparison.OrdinalIgnoreCase))
                {
                    return(SmallGroups(code, emailqueueto));
                }

                if (supportLinkRe.IsMatch(code))
                {
                    return(SupportLink(code, emailqueueto));
                }

                if (masterLinkRe.IsMatch(code))
                {
                    return(MasterLink(code, emailqueueto));
                }

                if (volReqLinkRe.IsMatch(code))
                {
                    return(VolReqLink(code, emailqueueto));
                }

                if (volSubLinkRe.IsMatch(code))
                {
                    return(VolSubLink(code, emailqueueto));
                }

                if (voteLinkRe.IsMatch(code))
                {
                    return(VoteLink(code, emailqueueto));
                }

                break;
            }

            return(code);
        }
Esempio n. 17
0
 public void LogPictureUpload(CMSDataContext db, int UserPeopleId)
 {
     var c = new ChangeLog
     {
         UserPeopleId = UserPeopleId,
         PeopleId = PeopleId,
         Field = "Basic Info",
         Created = Util.Now
     };
     db.ChangeLogs.InsertOnSubmit(c);
     c.ChangeDetails.Add(new ChangeDetail("Picture", null, "(new upload)"));
     var np = db.GetNewPeopleManagers();
     if (np != null)
         db.EmailRedacted(db.Setting("AdminMail", "*****@*****.**"), np,
             "Picture Uploaded on " + Util.Host,
             $"{Util.UserName} Uploaded a picture for <a href=\"{db.ServerLink($"/Person2/{PeopleId}")}\">{Name}</a><br />\n");
 }
Esempio n. 18
0
        public static void RegisterHelpers(CMSDataContext db)
        {
            Handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(CssStyle.BottomBorder); });
            Handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(CssStyle.AlignTop); });
            Handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(CssStyle.AlignRight); });
            Handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(CssStyle.DataLabelStyle); });
            Handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(CssStyle.LabelStyle); });
            Handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(CssStyle.DataStyle); });
            Handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
            Handlebars.RegisterHelper("FmtZip", (writer, context, args) => { writer.Write(args[0].ToString().FmtZip()); });
            Handlebars.RegisterHelper("IfEqual", (writer, options, context, args) =>
            {
                var eq = args[0] == args[1];
                if (!eq && args[0] is int)
                {
                    eq = args[0].ToString() == args[1].ToString();
                }
                if (eq)
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            Handlebars.RegisterHelper("GetToken", (writer, context, args) =>
            {
                var s = args[0].ToString();
                var n = args[1].ToInt();
                var a = s.SplitStr(" ", 2);
                writer.Write(a[n]);
            });

            // Format helper in form of:  {{Fmt value "fmt"}}
            // ex. {{Fmt Total "C"}}
            // fmt is required. Uses standard/custom dotnet format strings
            Handlebars.RegisterHelper("Fmt", (writer, context, args) =>
            {
                var fmt = $"{{0:{args[1]}}}";
                writer.Write(fmt, args[0]);
            });

            // FmtPhone helper in form of:  {{FmtPhone phone# "prefix"}}
            Handlebars.RegisterHelper("FmtPhone", (writer, context, args) =>
            {
                writer.Write(args[0].ToString().FmtFone($"{args[1]}"));
            });
        }
Esempio n. 19
0
        public static void RegisterHelpers(CMSDataContext db)
        {
            Handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(CssStyle.BottomBorder); });
            Handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(CssStyle.AlignTop); });
            Handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(CssStyle.AlignRight); });
            Handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(CssStyle.DataLabelStyle); });
            Handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(CssStyle.LabelStyle); });
            Handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(CssStyle.DataStyle); });

            Handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
            Handlebars.RegisterHelper("FmtZip", (writer, context, args) => { writer.Write(args[0].ToString().FmtZip()); });
            Handlebars.RegisterHelper("IfEqual", (writer, options, context, args) =>
            {
                if (IsEqual(args))
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            Handlebars.RegisterHelper("IfNotEqual", (writer, options, context, args) =>
            {
                if (!IsEqual(args))
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            Handlebars.RegisterHelper("GetToken", (writer, context, args) =>
            {
                var s     = args[0].ToString();
                var n     = args[1].ToInt();
                var ntoks = args.Length > 2 ? args[2].ToInt() : 2;
                var sep   = args.Length > 3 ? args[3].ToString() : " ";
                var a     = s.SplitStr(sep, ntoks);
                writer.Write(a[n].trim());
            });

            // Format helper in form of:  {{Fmt value "fmt"}}
            // ex. {{Fmt Total "C"}}
            // fmt is required. Uses standard/custom dotnet format strings
            Handlebars.RegisterHelper("Fmt", (writer, context, args) =>
            {
                var fmt = $"{{0:{args[1]}}}";
                writer.Write(fmt, args[0]);
            });

            // FmtPhone helper in form of:  {{FmtPhone phone# "prefix"}}
            Handlebars.RegisterHelper("FmtPhone", (writer, context, args) => { writer.Write(args[0].ToString().FmtFone($"{args[1]}")); });

            Handlebars.RegisterHelper("ReplaceCode", (writer, context, args) =>
            {
                EmailReplacements r = context.Replacements as EmailReplacements
                                      ?? (context.Replacements = new EmailReplacements(db));
                var code = args[0].ToString();
                var p    = db.LoadPersonById(args[1].ToInt());
                int?oid  = null;
                if (args.Length == 3)
                {
                    oid = args[2].ToInt2();
                }
                writer.Write(r.RenderCode(code, p, oid));
            });
        }
Esempio n. 20
0
        private string DoReplaceCode(string code, Person p, PayInfo pi = null, EmailQueueTo emailqueueto = null)
        {
            switch (code.ToLower())
            {
            case "{address}":
                return(p.PrimaryAddress);

            case "{address2}":
                if (p.PrimaryAddress2.HasValue())
                {
                    return("<br>" + p.PrimaryAddress2);
                }
                return("");

            case "{amtdue}":
                if (pi != null)
                {
                    return(pi.AmountDue.ToString2("c"));
                }
                break;

            case "{amtpaid}":
                if (pi != null)
                {
                    return(pi.AmountPaid.ToString2("c"));
                }
                break;

            case "{amount}":
                if (pi != null)
                {
                    return(pi.Amount.ToString2("c"));
                }
                break;

            case "{barcode}":
                return(string.Format("<img src='{0}' />", db.ServerLink("/Track/Barcode/" + p.PeopleId)));

            case "{campus}":
                return(p.CampusId != null ? p.Campu.Description : "No Campus Specified");

            case "{cellphone}":
                return(p.CellPhone.HasValue() ? p.CellPhone.FmtFone() : "no cellphone on record");

            case "{city}":
                return(p.PrimaryCity);

            case "{csz}":
                return(Util.FormatCSZ(p.PrimaryCity, p.PrimaryState, p.PrimaryZip));

            case "{country}":
                return(p.PrimaryCountry);

            case "{createaccount}":
                if (emailqueueto != null)
                {
                    return(CreateUserTag(emailqueueto));
                }
                break;

            case "{cmshost}":
                return(db.ServerLink());

            case "{emailhref}":
                if (emailqueueto != null)
                {
                    return(db.ServerLink("/EmailView/" + emailqueueto.Id));
                }
                break;

            case "{first}":
                return(p.PreferredName.Contains("?") || p.PreferredName.Contains("unknown", true) ? "" : p.PreferredName);

            case "{fromemail}":
                return(from.Address);

            case "{homephone}":
                return(p.HomePhone.HasValue() ? p.HomePhone.FmtFone() : "no homephone on record");

            case "{last}":
                return(p.LastName);

            case "{name}":
                return(p.Name.Contains("?") || p.Name.Contains("unknown", true) ? "" : p.Name);

            case "{nextmeetingtime}":
                if (emailqueueto != null)
                {
                    return(NextMeetingDate(code, emailqueueto));
                }
                break;

            case "{nextmeetingtime0}":
                if (emailqueueto != null)
                {
                    return(NextMeetingDate0(code, emailqueueto));
                }
                break;

            case "{occupation}":
                return(p.OccupationOther);

            case "{orgname}":
            case "{org}":
                return(GetOrgInfo(emailqueueto).Name);

            case "{orgmembercount}":
                return(GetOrgInfo(emailqueueto).Count);

            case "{paylink}":
                if (pi != null && pi.PayLink.HasValue())
                {
                    return("<a href=\"{0}\">Click this link to make a payment and view your balance.</a>".Fmt(pi.PayLink));
                }
                break;

            case "{peopleid}":
                return(p.PeopleId.ToString());

            case "{salutation}":
                if (emailqueueto != null)
                {
                    return(db.GoerSupporters.Where(ee => ee.Id == emailqueueto.GoerSupportId).Select(ee => ee.Salutation).SingleOrDefault());
                }
                break;

            case "{state}":
                return(p.PrimaryState);

            case "{toemail}":
                if (ListAddresses.Count > 0)
                {
                    return(ListAddresses[0].Address);
                }
                break;

            case "{today}":
                return(DateTime.Today.ToShortDateString());

            case "{title}":
                if (p.TitleCode.HasValue())
                {
                    return(p.TitleCode);
                }
                return(p.ComputeTitle());

            case "{track}":
                if (emailqueueto != null)
                {
                    return(emailqueueto.Guid.HasValue ? "<img src=\"{0}\" />".Fmt(db.ServerLink("/Track/Key/" + emailqueueto.Guid.Value.GuidToQuerystring())) : "");
                }
                break;

            case "{unsubscribe}":
                if (emailqueueto != null)
                {
                    return(UnSubscribeLink(emailqueueto));
                }
                break;

            default:
                if (emailqueueto == null)
                {
                    return(code);
                }

                if (code.StartsWith("{addsmallgroup:", StringComparison.OrdinalIgnoreCase))
                {
                    return(AddSmallGroup(code, emailqueueto));
                }

                if (code.StartsWith("{extra", StringComparison.OrdinalIgnoreCase))
                {
                    return(ExtraValue(code, emailqueueto));
                }

                if (registerLinkRe.IsMatch(code))
                {
                    return(RegisterLink(code, emailqueueto));
                }

                if (registerHrefRe.IsMatch(code))
                {
                    return(RegisterLinkHref(code, emailqueueto));
                }

                if (registerTagRe.IsMatch(code))
                {
                    return(RegisterTag(code, emailqueueto));
                }

                if (rsvpLinkRe.IsMatch(code))
                {
                    return(RsvpLink(code, emailqueueto));
                }

                if (sendLinkRe.IsMatch(code))
                {
                    return(SendLink(code, emailqueueto));
                }

                if (code.StartsWith("{orgextra:", StringComparison.OrdinalIgnoreCase))
                {
                    return(OrgExtra(code, emailqueueto));
                }

                if (code.StartsWith("{orgmember:", StringComparison.OrdinalIgnoreCase))
                {
                    return(OrgMember(code, emailqueueto));
                }

                if (code.StartsWith("{smallgroup:", StringComparison.OrdinalIgnoreCase))
                {
                    return(SmallGroup(code, emailqueueto));
                }

                if (code.StartsWith("{smallgroups", StringComparison.OrdinalIgnoreCase))
                {
                    return(SmallGroups(code, emailqueueto));
                }

                if (supportLinkRe.IsMatch(code))
                {
                    return(SupportLink(code, emailqueueto));
                }

                if (volReqLinkRe.IsMatch(code))
                {
                    return(VolReqLink(code, emailqueueto));
                }

                if (volSubLinkRe.IsMatch(code))
                {
                    return(VolSubLink(code, emailqueueto));
                }

                if (voteLinkRe.IsMatch(code))
                {
                    return(VoteLink(code, emailqueueto));
                }

                break;
            }

            return(code);
        }