public static function IsAvailableForPublicRegistration($strAddress) { $strAddress = trim(strtolower($strAddress)); // Go through all potential active registrations foreach (Email::LoadArrayByAddress($strAddress) as $objEmail) { if ($objEmail->Person->PublicLogin) { return false; } } // If we are here, then there are no emails associated with publiclogin-linked people return true; }
protected function btnCheck_Click($strFormId, $strControlId, $strParameter) { $this->lblResult->Text = ''; $objEmailArray = Email::LoadArrayByAddress($this->txtEmail->Text); if (count($objEmailArray) > 0) { $this->lblResult->Text .= "Found email objects<br><br>"; $intPersonIdArray = array(); foreach ($objEmailArray as $objEmail) { $objPerson = Person::LoadByPrimaryEmailId($objEmail->Id); if ($objPerson) { $intPersonIdArray[] = $objPerson->Id; } } $this->lblResult->Text .= "<h3>GROUPS</h3>"; $objGroupCursor = Group::QueryCursor(QQ::All()); while ($objGroup = Group::InstantiateCursor($objGroupCursor)) { $objGroupParticipationArr = $objGroup->GetGroupParticipationArray(); foreach ($objGroupParticipationArr as $objGroupParticipant) { if (in_array($objGroupParticipant->PersonId, $intPersonIdArray)) { $this->lblResult->Text .= sprintf("%s is in %s: %s<br>", $this->txtEmail->Text, $objGroup->Ministry->Name, $objGroup->Name); break; } } } $this->lblResult->Text .= "<br><h3>COMMUNICATION LISTS</h3>"; $objCommuncationsCursor = CommunicationList::QueryCursor(QQ::All()); while ($objCommunicationList = CommunicationList::InstantiateCursor($objCommuncationsCursor)) { $objCommListArray = $objCommunicationList->GetMemberAsArray(); foreach ($objCommListArray as $objComListEntry) { if ($objComListEntry[3] == $this->txtEmail->Text) { $this->lblResult->Text .= sprintf("%s is in %s: %s<br>", $this->txtEmail->Text, $objCommunicationList->Ministry->Name, $objCommunicationList->Name); break; } } } } else { $this->lblResult->Text .= "No email object found<br>"; } }
<?php // Get arguments $objParameters = new QCliParameterProcessor('bounceback', 'Checking for Bounceback emails'); $objParameters->AddDefaultParameter('file', QCliParameterType::String, 'The csv file that contains the email addresses that bounced'); $objParameters->Run(); $txtSrcFile = $objParameters->GetDefaultValue('file'); // read file if (is_file($txtSrcFile)) { $lineArray = file($txtSrcFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $isFirst = true; foreach ($lineArray as $line) { $objEmailArray = Email::LoadArrayByAddress(trim($line)); if ($objEmailArray) { printf("Found email: %s\n", trim($line)); foreach ($objEmailArray as $objEmail) { $objPerson = Person::LoadByPrimaryEmailId($objEmail->Id); if ($objPerson) { printf("Deleting email: %s from %s %s\n", trim($line), $objPerson->FirstName, $objPerson->LastName); $objPerson->PrimaryEmail->Delete(); // If there's a secondary email associated with the user set it as primary $objSecondaryEmailArray = Email::LoadArrayByPersonId($objPerson->Id); if (count($objSecondaryEmailArray) >= 1) { foreach ($objSecondaryEmailArray as $objSecondEmail) { printf(" Found secondary email object...%s\n", $objSecondEmail->Address); if ($objSecondEmail->Address != trim($line)) { $objPerson->PrimaryEmail = $objSecondEmail; $objPerson->PrimaryEmail->SetAsPrimary(); printf(" Set email: %s as the new primary email.\n", $objSecondEmail->Address); break; }
protected function btnUnsubscribe_Click() { $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($this->txtEmail->Text); $objEmailArray = Email::LoadArrayByAddress($this->txtEmail->Text); foreach ($objEmailArray as $objEmail) { $objPerson = Person::LoadByPrimaryEmailId($objEmail->Id); if ($objPerson != null) { $strUnsubscribedList = ''; $success = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { $bFound = false; if ($this->objList->IsPersonAssociated($objPerson)) { $this->objList->UnassociatePerson($objPerson); // If church newletter is the one being unsubscribed, document reason. if ($this->lstTerminationReason->SelectedValue == -1) { $objAttributeOption = new AttributeOption(); $objAttributeOption->AttributeId = $this->objAttributeValue->AttributeId; $objAttributeOption->Name = trim($this->txtOther->Text); $objAttributeOption->Save(); $objAttributeValue = AttributeValue::LoadByAttributeIdPersonId($this->objAttribute->Id, $objPerson->Id); if ($objAttributeValue) { $objAttributeValue->SingleAttributeOption = $objAttributeOption; $objAttributeValue->Save(); } else { $objAttributeValue = new AttributeValue(); $objAttributeValue->AttributeId = $this->objAttribute->Id; $objAttributeValue->PersonId = $objPerson->Id; $objAttributeValue->SingleAttributeOption = $objAttributeOption; $objAttributeValue->Save(); $objPerson->AssociateAttributeValue($objAttributeValue); } } else { $objAttributeValue = AttributeValue::LoadByAttributeIdPersonId($this->objAttribute->Id, $objPerson->Id); if ($objAttributeValue) { $objAttributeValue->SingleAttributeOptionId = $this->lstTerminationReason->SelectedValue; $objAttributeValue->Save(); } else { $objAttributeValue = new AttributeValue(); $objAttributeValue->AttributeId = $this->objAttribute->Id; $objAttributeValue->PersonId = $objPerson->Id; $objAttributeValue->SingleAttributeOptionId = $this->lstTerminationReason->SelectedValue; $objAttributeValue->Save(); $objPerson->AssociateAttributeValue($objAttributeValue); } } $strUnsubscribedList .= $objItem->Text . ','; $success = true; $bFound = true; } if (!$bFound) { $this->lblMessage->Text = '(Person Entry) You cannot Unsubscribe because you are not subscribed to the ' . $objItem->Text . ' Mailing List.'; $this->lblMessage->Visible = true; } } } } if ($success) { $strUnsubscribedList = substr($strUnsubscribedList, 0, strlen($strUnsubscribedList) - 1); QApplication::Redirect('/unsubscribe/success.php/' . urlencode($strUnsubscribedList) . '/' . $objPerson->Id); } } } if ($objCommunicationListEntry) { $strUnsubscribedList = ''; $success = false; $bChecked = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { $bFound = false; if ($objCommunicationListEntry != null) { if ($this->objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { $this->objList->UnassociateCommunicationListEntry($objCommunicationListEntry); $strUnsubscribedList .= $objItem->Text . ','; $success = true; $bFound = true; } } if (!$bFound) { $this->lblMessage->Text = '(CommunicationsEntry) You cannot Unsubscribe because you are not subscribed to the ' . $objItem->Text . ' Mailing List.'; $this->lblMessage->Visible = true; } } } } if ($success) { $strUnsubscribedList = substr($strUnsubscribedList, 0, strlen($strUnsubscribedList) - 1); QApplication::Redirect('/unsubscribe/success.php/' . urlencode($strUnsubscribedList)); } } $bChecked = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $bChecked = true; break; } } if (!$bChecked) { $this->lblMessage->Text = 'You must select a list to subscribe to.'; $this->lblMessage->Visible = true; } else { $this->lblMessage->Text = 'Failed to unsubscribe from the list. The email may not exist.'; $this->lblMessage->Visible = true; } }
<?php // Get arguments $objParameters = new QCliParameterProcessor('email', 'Email to check against'); $objParameters->AddDefaultParameter('email', QCliParameterType::String, 'The email address to check for in group and email lists'); $objParameters->Run(); $txtEmail = $objParameters->GetDefaultValue('email'); $objEmailArray = Email::LoadArrayByAddress($txtEmail); if (count($objEmailArray) > 0) { print "Found email objects\n"; print "\n"; $intPersonIdArray = array(); foreach ($objEmailArray as $objEmail) { $objPerson = Person::LoadByPrimaryEmailId($objEmail->Id); if ($objPerson) { $intPersonIdArray[] = $objPerson->Id; } } print "GROUPS\n"; $objGroupCursor = Group::QueryCursor(QQ::All()); QDataGen::DisplayForEachTaskStart('Checking for email in Group Lists', Group::CountAll()); while ($objGroup = Group::InstantiateCursor($objGroupCursor)) { QDataGen::DisplayForEachTaskNext('Checking for email in Group Lists'); $objGroupParticipationArr = $objGroup->GetGroupParticipationArray(); foreach ($objGroupParticipationArr as $objGroupParticipant) { if (in_array($objGroupParticipant->PersonId, $intPersonIdArray)) { printf("\n%s is in %s: %s\n", $txtEmail, $objGroup->Ministry->Name, $objGroup->Name); break; } } }
protected function btnSubscribe_Click() { $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($this->txtEmail->Text); if (!$objCommunicationListEntry) { // create new entry and add to the communications list $objCommunicationListEntry = new CommunicationListEntry(); $objCommunicationListEntry->Email = $this->txtEmail->Text; $objCommunicationListEntry->FirstName = $this->txtFirstName->Text; $objCommunicationListEntry->LastName = $this->txtLastName->Text; $objCommunicationListEntry->Save(); } $strSubscribedList = ''; $success = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { if ($this->objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { $this->lblMessage->Text .= 'You are already subscribed to the "' . $objItem->Name . '" list'; $this->lblMessage->ForeColor = 'red'; $this->lblMessage->Visible = true; } else { // See if Person exists in Noah, and if so, then associate. Else associate the Communications Entry $bFoundPerson = false; $emailArray = Email::LoadArrayByAddress($this->txtEmail->Text); foreach ($emailArray as $email) { $objPerson = Person::LoadByPrimaryEmailId($email->Id); if ($objPerson) { if (!$this->objList->IsPersonAssociated($objPerson)) { $bFoundPerson = true; $this->objList->AssociatePerson($objPerson); } else { $this->lblMessage->Text .= 'You are already subscribed to the "' . $objItem->Name . '" list'; $this->lblMessage->ForeColor = 'red'; $this->lblMessage->Visible = true; } } } if (!$bFoundPerson) { $this->objList->AssociateCommunicationListEntry($objCommunicationListEntry); } $strSubscribedList .= $objItem->Name . ','; $success = true; } } } else { $this->lblMessage->Text .= 'You must select a list to subscribe to.'; $this->lblMessage->ForeColor = 'red'; $this->lblMessage->Visible = true; } } if ($success) { $strSubscribedList = substr($strSubscribedList, 0, strlen($strSubscribedList) - 1); // Send confirmation email here. $this->SendMessage($strSubscribedList); QApplication::Redirect('/subscribe/success.php/subscribed/' . urlencode($strSubscribedList)); } }
public function btnAdd_Click() { $strEmail = trim(strtolower($this->txtEmail->Text)); // Is this already a person? if (count($objEmailArray = Email::LoadArrayByAddress($strEmail, QQ::OrderBy(QQN::Email()->Id)))) { $objPersonToAdd = null; // If anyone in the resulting array has this email as "Primary" -- that person gets assigne foreach ($objEmailArray as $objEmail) { if (!$objPersonToAdd && $objEmail->Person->PrimaryEmailId == $objEmail->Id) { $objPersonToAdd = $objEmail->Person; } } // Otherwise, assign the first person in the resultset if ($objPersonToAdd) { $this->objArrayToAdd[] = $objPersonToAdd; } else { $this->objArrayToAdd[] = $objEmailArray[0]->Person; } // No -- Is already an Entry? } else { if ($objEntry = CommunicationListEntry::LoadByEmail($strEmail)) { if ($strName = trim($this->txtFirstName->Text)) { $objEntry->FirstName = $strName; } if ($strName = trim($this->txtMiddleName->Text)) { $objEntry->MiddleName = $strName; } if ($strName = trim($this->txtLastName->Text)) { $objEntry->LastName = $strName; } $this->objArrayToAdd[] = $objEntry; // No -- Add a New Entry } else { $objEntry = new CommunicationListEntry(); $objEntry->FirstName = trim($this->txtFirstName->Text); $objEntry->MiddleName = trim($this->txtMiddleName->Text); $objEntry->LastName = trim($this->txtLastName->Text); $objEntry->Email = $strEmail; $this->objArrayToAdd[] = $objEntry; } } $this->dtgMembers->Refresh(); $this->txtFirstName->Text = null; $this->txtMiddleName->Text = null; $this->txtLastName->Text = null; $this->txtEmail->Text = null; $this->txtEmail->Focus(); }
/** * Given data points supplied this will attempt to reconcile this PublicLogin record to an actual person... or if not possible, * it will create a new person record. * * There are several stesp to this process. * First, do a Search of All People for the given Email * - if 1 and only 1 person was found: * + Check the personal details of that persons record * - If matched against First/Last or Nickname/Last, setup the match * - If matched against DOB and/or Gender and/or Mobile, setup the match and update the name * - If not matched, create as new * - if no people were found * + in all the DB, do a search to find matches against First/Last or Nickname/Last AND any address * - if exactly one is found, setup the match * - if non were found, create as new * - if multiple were found, find the first one that also match DOB and/or Gender and/or Mobile (or if none just find the first one) and setup the match * - if multiple people were found * + WITHIN the set of found people, do a search to find matches against First/Last or Nickname/Last AND any address * - if exactly one is found, setup the match * - if non were found, create as new * - if multiple were found, find the first one that also match DOB and/or Gender and/or Mobile (or if none just find the first one) and setup the match * * It will then check and see if the Person found (if any) already has a login object... if so, it will return that found Person record and do nothing further. * * Otherwise, it will then update all data accordingly (including creating a new Person record, if needed) and return the Person that was created. * * @param string $strPassword * @param string $strQuestion * @param string $strAnswer * @param string $strHomePhone * @param string $strMobilePhone * @param Address $objHomeAddress * @param Address $objMailingAddress optional * @param QDateTime $dttDateOfBirth optional * @param string $strGenderFlag optional * @return Person the person that was matched */ public function Reconcile($strPassword, $strQuestion, $strAnswer, $strHomePhone, $strMobilePhone, Address $objHomeAddress, Address $objMailingAddress = null, QDateTime $dttDateOfBirth = null, $strGenderFlag = null) { // Try and Find a Person based on Email $objPersonArray = array(); foreach (Email::LoadArrayByAddress($this->strEmailAddress) as $objEmail) { $objPersonArray[] = $objEmail->Person; } // Let's try and find a single Person object to reconcile for // 1 and only 1 person was found with the email if (count($objPersonArray) == 1) { if ($objPersonArray[0]->IsNameMatch($this->FirstName, $this->LastName)) { $objPerson = $objPersonArray[0]; } else { if ($objPersonArray[0]->ScoreDobGenderMobileMatch($dttDateOfBirth, $strGenderFlag, $strMobilePhone) > 0) { $objPerson = $objPersonArray[0]; } else { $objPerson = null; } } // MORE than one person was found with the email } else { if (count($objPersonArray)) { // Go through each of them and find a name-match and address-match $objMatchedPersonArray = array(); foreach ($objPersonArray as $objPerson) { if ($objPerson->IsNameAndAddressMatch($this->FirstName, $this->LastName, $objHomeAddress, $objMailingAddress)) { $objMatchedPersonArray[] = $objPerson; } } if (count($objMatchedPersonArray) == 1) { $objPerson = $objMatchedPersonArray[0]; } else { if (!count($objMatchedPersonArray)) { $objPerson = null; } else { $objPerson = $objMatchedPersonArray[0]; $intCurrentScore = 0; foreach ($objMatchedPersonArray as $objMatchedPerson) { $intScore = $objMatchedPerson->ScoreDobGenderMobileMatch($dttDateOfBirth, $strGenderFlag, $strMobilePhone); if ($intScore > $intCurrentScore) { $intCurrentScore = $intScore; $objPerson = $objMatchedPerson; } } } } // NO ONE was found with the email } else { // First pull the ones with Name Matched $objPersonArray = Person::LoadArrayByNameMatch($this->FirstName, $this->LastName); // Go through each of those and find address-match records $objMatchedPersonArray = array(); foreach ($objPersonArray as $objPerson) { if ($objPerson->IsNameAndAddressMatch($this->FirstName, $this->LastName, $objHomeAddress, $objMailingAddress)) { $objMatchedPersonArray[] = $objPerson; } } if (count($objMatchedPersonArray) == 1) { $objPerson = $objMatchedPersonArray[0]; } else { if (!count($objMatchedPersonArray)) { $objPerson = null; } else { $objPerson = $objMatchedPersonArray[0]; $intCurrentScore = 0; foreach ($objMatchedPersonArray as $objMatchedPerson) { $intScore = $objMatchedPerson->ScoreDobGenderMobileMatch($dttDateOfBirth, $strGenderFlag, $strMobilePhone); if ($intScore > $intCurrentScore) { $intCurrentScore = $intScore; $objPerson = $objMatchedPerson; } } } } } } // If we have a person, make sure it's not already linked if ($objPerson) { if ($objPerson->PublicLogin) { return $objPerson; } } // We now have either a unlinked Person record or no person record // Let's make all the DB updates we need to Person::GetDatabase()->TransactionBegin(); // Do we have a single Person object? // If not, let's create it if (!$objPerson) { $blnMaleFlag = null; if ($strGenderFlag = trim(strtoupper($strGenderFlag))) { $blnMaleFlag = $strGenderFlag == 'M'; } $intPhoneTypeId = $strMobilePhone ? PhoneType::Mobile : null; $objPerson = Person::CreatePerson($this->FirstName, null, $this->LastName, $blnMaleFlag, $this->EmailAddress, $strMobilePhone, $intPhoneTypeId); $objPerson->DateOfBirth = $dttDateOfBirth; if ($objPerson->DateOfBirth) { $objPerson->DobGuessedFlag = false; $objPerson->DobYearApproximateFlag = false; } $objPerson->PublicCreationFlag = true; $objPerson->Save(); } ////////////////////////////////// // Let's update the information ////////////////////////////////// // Email Address $objPerson->ChangePrimaryEmailTo($this->EmailAddress, false); // Gender and DOB if ($strGenderFlag = trim(strtoupper($strGenderFlag))) { $objPerson->Gender = $strGenderFlag; } if ($dttDateOfBirth) { $objPerson->DateOfBirth = $dttDateOfBirth; $objPerson->DobGuessedFlag = false; $objPerson->DobYearApproximateFlag = false; } // Mobile Phone if ($strMobilePhone) { $blnFound = false; foreach ($objPerson->GetAllAssociatedPhoneArray() as $objPhone) { if ($objPhone->Number == $strMobilePhone) { $objPhone->PhoneTypeId = PhoneType::Mobile; $objPhone->Save(); $blnFound = true; } } if (!$blnFound) { $objPhone = new Phone(); $objPhone->Number = $strMobilePhone; $objPhone->PhoneTypeId = PhoneType::Mobile; $objPhone->Save(); $objPerson->PrimaryPhone = $objPhone; } } // Mailing Address if ($objMailingAddress) { $blnFound = false; foreach ($objPerson->GetAllAssociatedAddressArray() as $objAddress) { if ($objAddress->IsEqualTo($objMailingAddress)) { $blnFound = true; $objAddress->CurrentFlag = true; $objAddress->AddressTypeId = AddressType::Other; $objAddress->Save(); $objPerson->MailingAddress = $objAddress; $objPerson->StewardshipAddress = $objAddress; } } if (!$blnFound) { $objMailingAddress->Person = $objPerson; $objMailingAddress->CurrentFlag = true; $objMailingAddress->AddressTypeId = AddressType::Other; $objMailingAddress->Save(); $objPerson->MailingAddress = $objMailingAddress; $objPerson->StewardshipAddress = $objMailingAddress; } } // Home Address and Phone $objHouseholdParticipationArray = $objPerson->GetHouseholdParticipationArray(); if (count($objHouseholdParticipationArray) == 1) { $objHousehold = $objHouseholdParticipationArray[0]->Household; $objAddress = $objHousehold->GetCurrentAddress(); if ($objAddress && $objAddress->IsEqualTo($objHomeAddress)) { $objHomeAddress = $objAddress; } else { $objHomeAddress->AddressTypeId = AddressType::Home; $objHomeAddress->Household = $objHousehold; $objHomeAddress->CurrentFlag = true; $objHomeAddress->Save(); if ($objAddress) { $objAddress->CurrentFlag = false; $objAddress->Save(); } } if ($strHomePhone) { $blnFound = false; foreach ($objHomeAddress->GetPhoneArray() as $objPhone) { if ($objPhone->Number == $strHomePhone) { $blnFound = true; $objPhone->SetAsPrimary(null, $objHomeAddress); } } if (!$blnFound) { $objPhone = new Phone(); $objPhone->PhoneTypeId = PhoneType::Home; $objPhone->Number = $strHomePhone; $objPhone->Address = $objHomeAddress; $objPhone->Save(); $objPhone->SetAsPrimary(null, $objHomeAddress); } } } else { if (count($objHouseholdParticipationArray) == 0) { $objHousehold = Household::CreateHousehold($objPerson); $objHomeAddress->AddressTypeId = AddressType::Home; $objHomeAddress->Household = $objHousehold; $objHomeAddress->CurrentFlag = true; $objHomeAddress->Save(); $objHousehold->SetAsCurrentAddress($objHomeAddress); if ($strHomePhone) { $objPhone = new Phone(); $objPhone->PhoneTypeId = PhoneType::Home; $objPhone->Number = $strHomePhone; $objPhone->Address = $objHomeAddress; $objPhone->Save(); $objPhone->SetAsPrimary(null, $objHomeAddress); } } } // Wire to PublicLogin $this->PublicLogin->Person = $objPerson; $this->PublicLogin->SetPassword($strPassword); $this->PublicLogin->LostPasswordQuestion = trim($strQuestion); $this->PublicLogin->LostPasswordAnswer = trim(strtolower($strAnswer)); $this->PublicLogin->DateLastLogin = QDateTime::Now(); $this->PublicLogin->Save(); // Save the person and delete the provision $objPerson->RefreshPrimaryContactInfo(); $objPerson->RefreshAge(false); $objPerson->RefreshNameItemAssociations(true); $this->Delete(); // Commit to DB Person::GetDatabase()->TransactionCommit(); // Return the now-linked person! return $objPerson; }