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; }
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"; } } else { print $groupList . " List could not be found. No entries added.\n\r"; } } } } else {
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); } }