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; }
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; } }