public function btnSave_Click() { $this->objPerson->MailingAddressId = $this->lstMailing->SelectedValue; $this->objPerson->StewardshipAddressId = $this->lstStewardship->SelectedValue; $this->objPerson->CanMailFlag = $this->lstCanMail->SelectedValue; $this->objPerson->CanEmailFlag = $this->lstCanEmail->SelectedValue; $this->objPerson->CanPhoneFlag = $this->lstCanPhone->SelectedValue; $this->objPerson->Save(); // Check to see if we need to remove person from email. if (!$this->objPerson->CanEmailFlag) { $objList = CommunicationList::LoadByToken('allchurch_nl'); // NOTE: this is the hard coded token of the congregational newsletter. if ($objList) { // Check communications list for an existing communications entry $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($this->objPerson->PrimaryEmail->Address); if ($objCommunicationListEntry) { if ($objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { $objList->UnassociateCommunicationListEntry($objCommunicationListEntry); } } //Check communications list for existing person entry if ($objList->IsPersonAssociated($this->objPerson)) { $objList->UnassociatePerson($this->objPerson); } } } $this->objPerson->RefreshPrimaryContactInfo(); QApplication::ExecuteJavaScript('document.location="#contact";'); }
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)); } }
/** * Associates an Email/Name/Etc. to this communication list * @param string $strEmail * @param string $strFirstName * @param string $strMiddleName * @param string $strLastName * @return CommunicationListEntry */ public function AddEntry($strEmail, $strFirstName, $strMiddleName, $strLastName) { $strEmail = strtolower($strEmail); if (!($objEntry = CommunicationListEntry::LoadByEmail($strEmail))) { $objEntry = new CommunicationListEntry(); $objEntry->Email = $strEmail; } $objEntry->FirstName = $strFirstName; $objEntry->MiddleName = $strMiddleName; $objEntry->LastName = $strLastName; $objEntry->Save(); if (!$this->IsCommunicationListEntryAssociated($objEntry)) { $this->AssociateCommunicationListEntry($objEntry); } return $objEntry; }
$objParameters->Run(); $txtSrcFile = $objParameters->GetDefaultValue('file'); $groupList = $objParameters->GetDefaultValue('token'); // read file if (is_file($txtSrcFile)) { $lineArray = file($txtSrcFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $isFirst = true; foreach ($lineArray as $line) { if ($isFirst) { $isFirst = false; } else { $strTokens = explode(',', trim($line)); $firstName = $strTokens[0]; $lastName = $strTokens[1]; $email = $strTokens[2]; $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($email); if (!$objCommunicationListEntry) { // If not found then create new entry and add to the communications list $objCommunicationListEntry = new CommunicationListEntry(); $objCommunicationListEntry->Email = $email; $objCommunicationListEntry->FirstName = $firstName; $objCommunicationListEntry->LastName = $lastName; $objCommunicationListEntry->Save(); } $objList = CommunicationList::LoadByToken($groupList); if ($objList) { if ($objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { print $email . " is already subscribed to the '" . $groupList . "' list\r\n"; } else { $objList->AssociateCommunicationListEntry($objCommunicationListEntry); print "Added email: " . $email . "\n\r";
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; } }
protected function AddToChurchEmailList() { if ($this->chkAddToNewsletter->Checked) { // First create a CommunicationListEntry for the person $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($this->txtPersonEmail->Text); // Then add person to the church newsletter list $objList = CommunicationList::LoadByToken('alcfweekly'); // NOTE: this is the hard coded token of the congregational newsletter. if ($objList) { if (!$objList->IsPersonAssociated($this->mctPerson->Person)) { if ($objCommunicationListEntry) { if (!$objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { // unassociate the communications entry if it exists because we'll associate the person directly instead. $objList->UnassociateCommunicationListEntry($objCommunicationListEntry); } } $objList->AssociatePerson($this->mctPerson->Person); } } } }
protected function btnSubmit_Click($strFormId, $strControlId, $strParameter) { $this->objSignupEntry->Save(); $this->CreateChildObject(); if (!QApplication::$PublicLogin) { // Create a communcations entry object or use an existing communcations_entry // if user is not logged in $txtEmail = $this->GetControl($this->strEmailCtrlId); $objCommunicationsEntry = CommunicationListEntry::LoadByEmail($txtEmail->Text); if (!$objCommunicationsEntry) { $objCommunicationsEntry = new CommunicationListEntry(); $objCommunicationsEntry->FirstName = $this->objFormQuestionControlArray[0]->Text; $objCommunicationsEntry->LastName = $this->objFormQuestionControlArray[1]->Text; if ($txtEmail) { $objCommunicationsEntry->Email = $txtEmail->Text; } $objCommunicationsEntry->Save(); } $this->objSignupEntry->CommunicationsEntryId = $objCommunicationsEntry->Id; } foreach ($this->objSignupForm->GetFormQuestionArray() as $objFormQuestion) { // Only update if this is NOT "InternalFlag" if ($objFormQuestion->InternalFlag) { continue; } $strControlId = 'fq' . $objFormQuestion->Id; $objFormAnswer = FormAnswer::LoadBySignupEntryIdFormQuestionId($this->objSignupEntry->Id, $objFormQuestion->Id); if (!$objFormAnswer) { $objFormAnswer = new FormAnswer(); $objFormAnswer->SignupEntry = $this->objSignupEntry; $objFormAnswer->FormQuestion = $objFormQuestion; } switch ($objFormQuestion->FormQuestionTypeId) { case FormQuestionType::SpouseName: $lstSpouse = $this->GetControl($strControlId . 'id'); $txtSpouse = $this->GetControl($strControlId . 'nm'); if ($lstSpouse && $lstSpouse->SelectedValue) { $objFormAnswer->TextValue = Person::Load($lstSpouse->SelectedValue)->Name; } else { $objFormAnswer->TextValue = trim($txtSpouse->Text); } break; case FormQuestionType::Address: $rblAddress = $this->GetControl($strControlId . 'switch'); $txtAddress1 = $this->GetControl($strControlId . 'address1'); $txtAddress2 = $this->GetControl($strControlId . 'address2'); $txtCity = $this->GetControl($strControlId . 'city'); $lstState = $this->GetControl($strControlId . 'state'); $txtZipCode = $this->GetControl($strControlId . 'zipcode'); if ($rblAddress && $rblAddress->SelectedValue) { $objFormAnswer->AddressId = $rblAddress->SelectedValue; $objFormAnswer->TextValue = $objFormAnswer->Address->AddressFullLine; } else { $objFormAnswer->AddressId = null; $objAddress = new Address(); $objAddress->Address1 = trim($txtAddress1->Text); $objAddress->Address2 = trim($txtAddress2->Text); $objAddress->City = trim($txtCity->Text); $objAddress->State = $lstState->SelectedValue; $objAddress->ZipCode = trim($txtZipCode->Text); $objFormAnswer->TextValue = $objAddress->AddressFullLine; } break; case FormQuestionType::Age: $txtAge = $this->GetControl($strControlId . 'age'); if (strlen(trim($txtAge->Text))) { $objFormAnswer->IntegerValue = $txtAge->Text; } else { $objFormAnswer->IntegerValue = null; } break; case FormQuestionType::DateofBirth: $dtxDateOfBirth = $this->GetControl($strControlId . 'dob'); if ($dtxDateOfBirth->DateTime) { $objFormAnswer->DateValue = $dtxDateOfBirth->DateTime; // Update the Person Information if (QApplication::$PublicLogin) { $this->objSignupEntry->Person->DateOfBirth = $objFormAnswer->DateValue; $this->objSignupEntry->Person->DobGuessedFlag = false; $this->objSignupEntry->Person->DobYearApproximateFlag = false; $this->objSignupEntry->Person->Save(); } } else { $objFormAnswer->DateValue = null; } break; case FormQuestionType::Gender: $lstGender = $this->GetControl($strControlId . 'gender'); if ($lstGender->SelectedValue === true) { $objFormAnswer->TextValue = 'Male'; $objFormAnswer->BooleanValue = true; if (QApplication::$PublicLogin) { $this->objSignupEntry->Person->Gender = 'M'; $this->objSignupEntry->Person->Save(); } } else { if ($lstGender->SelectedValue === false) { $objFormAnswer->TextValue = 'Female'; $objFormAnswer->BooleanValue = false; if (QApplication::$PublicLogin) { $this->objSignupEntry->Person->Gender = 'F'; $this->objSignupEntry->Person->Save(); } } else { $objFormAnswer->TextValue = null; $objFormAnswer->BooleanValue = null; } } break; case FormQuestionType::Phone: $lstPhone = $this->GetControl($strControlId . 'id'); $txtPhone = $this->GetControl($strControlId . 'phone'); if ($lstPhone && $lstPhone->SelectedValue) { $objFormAnswer->PhoneId = $lstPhone->SelectedValue; $objFormAnswer->TextValue = $objFormAnswer->Phone->Number; } else { if ($strNumber = trim($txtPhone->Text)) { $objFormAnswer->PhoneId = null; $objFormAnswer->TextValue = $strNumber; } else { $objFormAnswer->PhoneId = null; $objFormAnswer->TextValue = null; } } break; case FormQuestionType::Email: $lstEmail = $this->GetControl($strControlId . 'id'); $txtEmail = $this->GetControl($strControlId . 'email'); if ($lstEmail && $lstEmail->SelectedValue) { $objFormAnswer->EmailId = $lstEmail->SelectedValue; $objFormAnswer->TextValue = $objFormAnswer->Email->Address; } else { if ($strNumber = trim($txtEmail->Text)) { $objFormAnswer->EmailId = null; $objFormAnswer->TextValue = $strNumber; } else { $objFormAnswer->EmailId = null; $objFormAnswer->TextValue = null; } } break; case FormQuestionType::ShortText: case FormQuestionType::LongText: $txtAnswer = $this->GetControl($strControlId); if (strlen($strText = trim($txtAnswer->Text))) { $objFormAnswer->TextValue = $strText; } else { $objFormAnswer->TextValue = null; } break; case FormQuestionType::Number: $txtAnswer = $this->GetControl($strControlId); if (strlen($strText = trim($txtAnswer->Text))) { $objFormAnswer->IntegerValue = $strText; } else { $objFormAnswer->IntegerValue = null; } break; case FormQuestionType::YesNo: $chkAnswer = $this->GetControl($strControlId); $objFormAnswer->BooleanValue = $chkAnswer->Checked; break; case FormQuestionType::SingleSelect: $lstAnswer = $this->GetControl($strControlId); $txtAnswer = $this->GetControl($strControlId . 'other'); // No item selected ("-select one-" still selected) if (is_null($lstAnswer->SelectedValue)) { $objFormAnswer->TextValue = null; // "Other" option } else { if ($lstAnswer->SelectedValue === false) { if (strlen($strText = trim($txtAnswer->Text))) { $objFormAnswer->TextValue = $strText; } else { $objFormAnswer->TextValue = null; } // Regular List Selection } else { $objFormAnswer->TextValue = trim($lstAnswer->SelectedValue); } } break; case FormQuestionType::MultipleSelect: //GJS - changing to multiple check boxes $chkAnswer = $this->GetControl($strControlId); $objItemsArray = $chkAnswer->GetAllItems(); if (count($objItemsArray)) { $strSelectedArray = array(); foreach ($objItemsArray as $objItem) { if ($objItem->Selected) { $strSelectedArray[] = $objItem->Name; } } $objFormAnswer->TextValue = implode("\r\n", $strSelectedArray); } else { $objFormAnswer->TextValue = null; } break; case FormQuestionType::Instructions: // Don't need to do anything here! break; default: throw new Exception('Invalid FormQuestionTypeId: ' . $objFormQuestion->FormQuestionTypeId); } $objFormAnswer->Save(); } if ($this->objSignupForm->CountFormProducts()) { QApplication::Redirect($this->objSignupEntry->PaymentUrl); } else { $this->objSignupEntry->Complete(); QApplication::Redirect($this->objSignupEntry->ConfirmationUrl); } }
/** * Given a valid From EmailAddress, this will lookup and return a "Sender" array, a 3-item array containing: * Login * CommunicationListEntry * Person[] * that would correspond to this From EmailAddress. Note that any one of those indexes can also be null * if there is no object corresponding to this From Email Address. * @return mixed[] */ protected function CalculatePotentialSenderArray() { $objArrayToReturn = array(); $objArrayToReturn[] = Login::LoadByEmail($this->FromAddress); $objArrayToReturn[] = CommunicationListEntry::LoadByEmail($this->FromAddress); // Get all Person objects that have this as an email address $objArrayToReturn[] = Person::QueryArray(QQ::Equal(QQN::Person()->Email->Address, $this->FromAddress), QQ::Distinct()); return $objArrayToReturn; }
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(); }