Exemple #1
0
 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);
     }
 }