Esempio n. 1
0
        public static string GetRecipientCount(int recipientTypeId, int geographyId)
        {
            int personCount = 0;

            AuthenticationData authData  = GetAuthenticationDataAndCulture();
            Geography          geography = Geography.FromIdentity(geographyId);
            Geographies        geoTree   = geography.GetTree();
            Organizations      orgTree   = authData.CurrentOrganization.GetTree();

            switch (recipientTypeId)
            {
            case 0:     // "Select one"
                personCount = 0;
                break;

            case 1:     // Regulars
                personCount = orgTree.GetMemberCountForGeographies(geoTree);
                break;

            case 2:     // Agents
                personCount = Activists.GetCountForGeography(geography);
                break;

            // TODO: Dynamic membership types

            case 101:     // Officers
                personCount = orgTree.GetRoleHolderCountForGeographies(geoTree);
                break;

            case 102:            // Volunteers
                personCount = 0; // TODO
                break;

            default:
                throw new NotImplementedException();
            }

            string result;

            string[] resources = Resources.Pages.Comms.SendMassMessage_RecipientCount.Split('|');

            switch (personCount)
            {
            case 0:
                result = resources[0];
                break;

            case 1:
                result = resources[1];
                break;

            default:
                result = String.Format(resources[2], personCount);
                break;
            }

            return(result);
        }
Esempio n. 2
0
    protected void ButtonSend_Click(object sender, EventArgs e)
    {
        int actingOrgId = (int)ViewState["actingOrg"];

        if (actingOrgId == 0)
        {
            ErrorMsg.Text = "No organisation!";
            return;
        }



        Button theBtn = (sender as Button);

        ErrorMsg.Text = TimedDisableButton(theBtn, "AlertActivistLastSend", 60); // Should it even be possible to push the button again without reloading page?
        if (ErrorMsg.Text != "")
        {
            return;
        }

        Activists activists = Activists.FromGeography(this.GeographyTree.SelectedGeography);

        if (this.CheckSms.Checked && actingOrgId == Organization.PPSEid)
        {
            string smsText = this.TextSms.Text;
            if (!string.IsNullOrEmpty(smsText) && smsText.Trim().Length > 3) // 3 characters is too small message, should always be more
            {
                // Defer sending SMS messages to bot

                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.PhoneMessagesCreated,
                                                            _currentUser.Identity,
                                                            actingOrgId, this.GeographyTree.SelectedGeography.Identity, 0,
                                                            SelectBudget(this.GeographyTree.SelectedGeography).Identity, "PP: " + smsText.Trim());
            }
        }

        if (this.CheckMail.Checked)
        {
            string mailSubject = this.TextMailSubject.Text;
            string mailBody    = this.TextMailBody.Text;

            if (!string.IsNullOrEmpty(mailSubject) && !string.IsNullOrEmpty(mailBody))
            {
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ActivistMailsCreated,
                                                            _currentUser.Identity,
                                                            actingOrgId,
                                                            this.GeographyTree.SelectedGeography.Identity, 0,
                                                            0,
                                                            mailSubject.Replace("|", "") + "|" + mailBody);
            }
        }

        this.PanelFinal.Visible = true;
        PanelTestSent.Visible   = false;
    }
Esempio n. 3
0
    private void UpdateSmsCosts()
    {
        this.PanelSmsText.Visible = this.CheckSms.Checked;

        if (this.CheckSms.Checked)
        {
            Geography selectedGeo   = this.GeographyTree.SelectedGeography;
            int       activistCount = Activists.GetCountForGeography(selectedGeo);

            ResetSmsCosts(selectedGeo, activistCount);
        }
        else
        {
            this.LabelSmsCost.Text = "0.00";
            this.LabelBudget.Text  = "None";
        }
    }
Esempio n. 4
0
    private void UpdateActivistCount()
    {
        Geography selectedGeo   = this.GeographyTree.SelectedGeography;
        int       activistCount = Activists.GetCountForGeography(selectedGeo);

        string result = " No activist in " + selectedGeo.Name + ". Not even one! Nobody will receive your alert.";

        if (activistCount == 1)
        {
            result = " One activist in " + selectedGeo.Name + ". Just one. Hardly a mobilization, eh?";
        }
        else if (activistCount > 1)
        {
            result = " " + activistCount.ToString() + " activists in " + selectedGeo.Name + ".";
        }

        this.LabelGeographies.Text = result;
        UpdateSmsCosts();
        this.ButtonSend.Text = "Send (to " + activistCount.ToString() + ")";
    }
Esempio n. 5
0
 private void _Next()
 {
     if (_Activists.Count > 0)
     {
         _Current.Shutdown();
         _Current = _Activists.Dequeue();
         _Current.DoneEvent += _Next;
         _Current.Launch();
     }
     else
     {
         _Judge();
     }
 }
Esempio n. 6
0
 void Regulus.Game.IStage.Enter()
 {
     _Current = _Activists.Dequeue();
     _Current.DoneEvent += _Next;
     _Current.Launch();
 }
Esempio n. 7
0
    protected void ButtonSearch_Click(object sender, EventArgs e)
    {
        // If a member number is present, use only that as search criteria.

        People searchResults = null;

        string searchMemberNumber = this.TextMemberNumber.Text.Trim();

        if (searchMemberNumber.Length > 0)
        {
            // Lots of things here that will throw on invalid arguments
            Regex    re      = new Regex(@"[\s,;]+");
            string[] numbers = re.Replace(searchMemberNumber, ";").Split(';');
            searchResults = new People();
            foreach (string pers in numbers)
            {
                try
                {
                    string persID = pers;
                    if (searchMemberNumber.Trim().ToUpper().StartsWith("PP"))
                    {
                        //Hexcoded number
                        char[] mnr = persID.Substring(2).ToCharArray();
                        Array.Reverse(mnr);
                        persID = new string(mnr);
                        int num = (System.Int32.Parse(searchMemberNumber, System.Globalization.NumberStyles.AllowHexSpecifier));
                        persID = num.ToString();
                    }
                    int    personId = Convert.ToInt32(persID);
                    Person person   = Person.FromIdentity(personId);
                    searchResults.Add(person);
                }
                catch (Exception)
                { }
            }

            if (numbers.Length > 1)
            {
                PersonList.GridView.PageSize = numbers.Length;
                PersonList.ShowStreet        = true;
            }
        }
        else
        {
            searchResults = null;
            try
            {
                if (DropOrganizations.SelectedValue == "-1")
                {
                    if (DropGeographies.SelectedValue != "-1")
                    {
                        searchResults = People.FromGeography(Convert.ToInt32(DropGeographies.SelectedValue));
                    }
                    else
                    {
                        searchResults = null;
                    }
                }
                else
                {
                    searchResults = People.FromOrganizationAndGeography(Convert.ToInt32(DropOrganizations.SelectedValue),
                                                                        Convert.ToInt32(DropGeographies.SelectedValue));
                }
            }
            catch { }

            People nameResult  = People.FromNamePattern(TextNamePattern.Text);
            People emailResult = People.FromEmailPattern(TextEmailPattern.Text);
            People cityResult  = People.FromCityPattern(TextCityPattern.Text);
            People pcResult    = People.FromPostalCodePattern(TextPostalCodePattern.Text);

            if (nameResult != null)
            {
                searchResults = People.LogicalAnd(searchResults, nameResult);
            }
            if (searchResults != null || emailResult != null)
            {
                searchResults = People.LogicalAnd(searchResults, emailResult);
            }
            if (searchResults != null || cityResult != null)
            {
                searchResults = People.LogicalAnd(searchResults, cityResult);
            }
            if (searchResults != null || pcResult != null)
            {
                searchResults = People.LogicalAnd(searchResults, pcResult);
            }

            string inputDateText = textPersonalNumber.Text.Trim();
            if (inputDateText != "")
            {
                int inpLen = inputDateText.Length;
                int yLen   = 2;

                string[] formats2 = new string[] { "yy", "yyMM", "yyMMdd", "yyyy", "yyyyMM", "yyyyMMdd", "yyyy", "yyyy-MM", "yyyy-MM-dd", "yy", "yy-MM", "yy-MM-dd" };
                string[] formats4 = new string[] { "yyyy", "yyyyMM", "yyyyMMdd", "yy", "yyMM", "yyMMdd", "yyyy", "yyyy-MM", "yyyy-MM-dd", "yy", "yy-MM", "yy-MM-dd" };
                string[] formats;

                DateTime parsedDate = DateTime.MinValue;
                DateTime endDate    = DateTime.MaxValue;

                if (inputDateText.StartsWith("19") ||
                    inputDateText.StartsWith("20"))
                {
                    formats = formats4;
                    yLen    = 4;
                }
                else
                {
                    formats = formats2;
                }
                string[] datesSplit = (textPersonalNumber.Text + "--").Split(new string[] { "--" }, StringSplitOptions.None);

                DateTime.TryParseExact(datesSplit[0].Trim(), formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate);
                if (parsedDate != DateTime.MinValue)
                {
                    if (datesSplit[1] != "")
                    {
                        DateTime.TryParseExact(datesSplit[1].Trim(), formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDate);
                        inpLen = datesSplit[1].Trim().Length;
                        bool dash = textPersonalNumber.Text.Contains("-");
                        if (inpLen == yLen)
                        {
                            endDate = endDate.AddYears(1);
                        }
                        else if (inpLen == yLen + 2 || (dash && inpLen == yLen + 3))
                        {
                            endDate = endDate.AddMonths(1);
                        }
                        else
                        {
                            endDate = endDate.AddDays(1);
                        }
                    }
                    else
                    {
                        inpLen = datesSplit[0].Trim().Length;
                        bool dash = textPersonalNumber.Text.Contains("-");
                        if (inpLen == yLen)
                        {
                            endDate = parsedDate.AddYears(1);
                        }
                        else if (inpLen == yLen + 2 || (dash && inpLen == yLen + 3))
                        {
                            endDate = parsedDate.AddMonths(1);
                        }
                        else
                        {
                            endDate = parsedDate.AddDays(1);
                        }
                    }

                    People dateResults = People.FromBirtDatePattern(parsedDate, endDate);
                    if (searchResults != null || dateResults != null)
                    {
                        searchResults = People.LogicalAnd(searchResults, dateResults);
                    }
                }
            }
        }

        if (searchResults != null && CheckBoxActivist.Checked)
        {
            Geography geoTree = Geography.FromIdentity(Convert.ToInt32(DropGeographies.SelectedValue));

            //Activism can't be searched for in itself. Too heavy on the DB.
            Activists activists   = Activists.FromGeography(Geography.FromIdentity(Convert.ToInt32(DropGeographies.SelectedValue)));
            int[]     activistIds = activists.Identities;
            Dictionary <int, bool> activistsHashed = new Dictionary <int, bool>();
            foreach (int id in activistIds)
            {
                activistsHashed[id] = true;
            }

            searchResults = searchResults.Filter(
                delegate(Person p)
            {
                if (activistsHashed.ContainsKey(p.Identity))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
        }


        if (searchResults != null)
        {
            PersonList.ShowStatus = false;

            Authority auth = _authority;

            //TODO: All this supposes that these permissions can be applied to mon swedish people as well, ie Organization.PPSEid is supposed
            if (!auth.HasPermission(Permission.CanSeeNonMembers, Organization.PPSEid, -1, Authorization.Flag.AnyGeographyExactOrganization))
            {
                PersonList.ShowStatus = true;
            }

            if (!auth.HasPermission(Permission.CanValidateActivistEmail, Organization.PPSEid, -1, Authorization.Flag.AnyGeographyExactOrganization) ||
                searchResults.Count > 5)
            {
                // SERIOUS SECURITY BREACH here: All chairmen for all organizations could see ALL members.
                // "CanValidateActivistEmail" was set for "OrganizationChairman".

                searchResults = searchResults.GetVisiblePeopleByAuthority(auth);
            }
            else
            {
                PersonList.ShowStatus = true;
            }


            if (!auth.HasPermission(Permission.CanValidateActivistEmail, Organization.PPSEid, -1, Authorization.Flag.AnyGeographyExactOrganization) ||
                searchResults.Count > 1)
            {
                // SERIOUS SECURITY BREACH here: All chairmen for all organizations could see ALL members.
                // "CanValidateActivistEmail" was set for "OrganizationChairman".

                searchResults = searchResults.RemoveUnlisted();
            }
            PersonList.PersonList = searchResults;
        }
    }