/**
  * check customer registration and carry on the registration process if it is not completed 
  *
  * Returns True if valid, false otherwise.
  *
  * @param string $email_address
  *
  * @return int
  */
 public function checkRegister($refno, $email, $isChangeEmail)
 {
     (string) ($refno = preg_replace('/X/', '', $refno));
     $customermgr = new Manager_Core_Customer();
     $customer = $customermgr->getCustomerByEmailAddress($email);
     $params = Zend_Registry::get('params');
     $mac = new Application_Core_Security($params->myhomelet->activation_mac_secret, false);
     $digest = $mac->generate(array('email' => $email));
     $activationLink = 'refno=' . $refno . '&' . 'email=' . $email . '&' . 'mac=' . $digest;
     $customerMap = new Datasource_Core_CustomerMaps();
     if ($customer) {
         if (!$customerMap->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $refno)) {
             $customermgr->linkLegacyToNew($refno, $customer->getIdentifier(Model_Core_Customer::IDENTIFIER));
         }
         if (!$customer->getEmailValidated()) {
             $mail = new Application_Core_Mail();
             $mail->setTo($email, null);
             $mail->setFrom('*****@*****.**', 'HomeLet');
             $mail->setSubject('My HomeLet account validation');
             $mail->applyTemplate('core/account-validation', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $customer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account', 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml');
             $mail->applyTextTemplate('core/account-validationtxt', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $customer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml');
             // Send email
             $mail->send();
             return 1;
         } else {
             return 0;
         }
     } else {
         if ($isChangeEmail) {
             $cMap = $customerMap->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $refno);
             if ($cMap) {
                 $customer = $customermgr->getCustomer(Model_Core_Customer::IDENTIFIER, $cMap->getIdentifier());
                 $customer->setEmailAddress($email);
                 $customermgr->updateCustomer($customer);
                 $legacyids = $customerMap->getLegacyIDs($customer->getIdentifier());
                 foreach ($legacyids as $legacyid) {
                     if ($legacyid != $refno) {
                         $customer = $customermgr->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $legacyid);
                         $customer->setEmailAddress($email);
                         $customermgr->updateCustomer($customer);
                     }
                 }
                 return 0;
             }
         }
         $oldCustomer = $customermgr->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $refno);
         $mail = new Application_Core_Mail();
         $mail->setTo($email, null);
         $mail->setFrom('*****@*****.**', 'HomeLet');
         $mail->setSubject("Don't forget to register your My HomeLet account");
         $mail->applyTemplate('core/partial-registration', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $oldCustomer->getFirstName(), 'templateId' => 'HL2469 12-12', 'heading' => 'Get even more with your My HomeLet account', 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml');
         $mail->applyTextTemplate('core/partial-registrationtxt', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $oldCustomer->getFirstName(), 'templateId' => 'HL2469 12-12', 'heading' => 'Get even more with your My HomeLet account'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml');
         // Send email
         $mail->send();
         return 2;
     }
 }
 public function updatePersonalDetails($email, $title, $firstName, $lastName)
 {
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->getCustomerByEmailAddress($email);
     if ($customer) {
         // Customer found in web database, update their personal details
         $customer->setTitle($title);
         $customer->setFirstName($firstName);
         $customer->setLastName($lastName);
         $customerManager->updateCustomer($customer);
         return 1;
     } else {
         // No customer found, update nothing
         return 0;
     }
 }
 public function saveAction()
 {
     if ($this->getRequest()->isPost()) {
         $password1 = $this->getRequest()->getPost('password1');
         $password2 = $this->getRequest()->getPost('password2');
         if ($password1 != $password2) {
             $return['status'] = 'error';
             $return['errorMessage'] = 'Passwords do not match. Please re-enter';
         } else {
             $customerManager = new Manager_Core_Customer();
             $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
             $legacyCustomerReference = $pageSession->CustomerRefNo;
             // This will create a customer record as we don't currently have one (only a legacy one)
             $customerID = $customerManager->linkLegacyToNew($legacyCustomerReference, null, Model_Core_Customer::TENANT);
             // Now we need to retreive the newly created customer and update the password
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             $customer->setPassword($password1);
             $customerManager->updateCustomer($customer);
             // Email the new customer to give them their details
             $metaData = array('name' => $customer->getFirstName(), 'quoteNumber' => $pageSession->PolicyNumber);
             // Log the customer in
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             $adapter = $customerManager->getAuthAdapter(array('password' => $this->getRequest()->getPost('password1'), 'email' => $customer->getEmailAddress()));
             $result = $auth->authenticate($adapter);
             if (!$result->isValid()) {
                 // This really shouldn't ever happen as we've just created the customer!!
             } else {
                 $storage = $auth->getStorage();
                 $storage->write($adapter->getResultRowObject(array('title', 'first_name', 'last_name', 'email_address', 'id')));
             }
             $emailer = new Application_Core_Mail();
             $emailer->setTo($customer->getEmailAddress(), $customer->getFirstName() . ' ' . $customer->getLastName())->setSubject('Homelet - Saved Tenants Contents Insurance Quote')->applyTemplateWithoutFooter('tenantsinsurancequote_saved', $metaData);
             $emailer->send();
             $return['status'] = 'saved';
         }
         echo Zend_Json::encode($return);
     }
 }
 /**
  * Saves the form data to the datastore.
  * 
  * @return void
  */
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     // Create the new customer in the legacy datasource only.
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->createNewCustomer($data['email'], Model_Core_Customer::CUSTOMER);
     // Update the newly created customer with values submitted on the registration form.
     //$customer->setTitle($data['personal_title']);
     $customer->setTitle($data['title']);
     $customer->setFirstName($data['first_name']);
     $customer->setLastName($data['last_name']);
     $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $data['phone_number']);
     $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $data['mobile_number']);
     $customer->setFax($data['fax_number']);
     $customer->setEmailAddress($data['email']);
     $customer->setPassword($data['password']);
     $customer->setSecurityQuestion($data['security_question']);
     $customer->setSecurityAnswer($data['security_answer']);
     //Address update
     $postcode = new Manager_Core_Postcode();
     $propertyAddress = $postcode->getPropertyByID($data['property_address'], false);
     $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
     $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $addressLine1);
     $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $propertyAddress['address4']);
     $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $propertyAddress['address5']);
     $customer->setPostCode($data['property_postcode']);
     $customer->typeID = Model_Core_Customer::CUSTOMER;
     // Update the customer record
     $customerManager->updateCustomer($customer);
     //		// Log the customer in automatically
     //        $auth = Zend_Auth::getInstance();
     //        $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
     //        $customerManager = new Manager_Core_Customer();
     //        $adapter = $customerManager->getAuthAdapter(array('email' => $data['email'], 'password' => $data['password']));
     //        $auth->authenticate($adapter);
     //        // Writer customer data to session
     //        $storage = $auth->getStorage();
     //        $storage->write($adapter->getResultRowObject(array(
     //            'title',
     //            'first_name',
     //            'last_name',
     //            'email_address',
     //            'id')));
     //Finally, set the necessary session variables.
     $session->awaitingvalidation = 1;
     $session->customerId = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER);
     // Save dpa preferences for direct landlord to insurance dpa system - direct landlords save their customer records to insurance
     $dpaManager = new Manager_Core_DataProtection();
     $item = new Model_Core_DataProtection_Item();
     $item->itemGroupId = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
     $item->entityTypeId = Model_Core_DataProtection_ItemEntityTypes::INSURANCE;
     // Phone and post
     $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST;
     $item->isAllowed = $data['subform_dataprotection']['dpa_phone_post'] == 1 ? true : false;
     $dpaManager->upsertItem($item);
     // Sms and email
     $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL;
     $item->isAllowed = $data['subform_dataprotection']['dpa_sms_email'] == 1 ? true : false;
     $dpaManager->upsertItem($item);
     // Third party sale
     $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY;
     $item->isAllowed = $data['subform_dataprotection']['dpa_resale'] == 1 ? true : false;
     $dpaManager->upsertItem($item);
     // Save insurance renewal mi data, if provided
     if ($this->getElement('insurance_renewal_date')->getValue() != '') {
         $renewalDate = new Zend_Date($this->getElement('insurance_renewal_date')->getValue(), Zend_Date::DAY . '/' . Zend_Date::MONTH . '/' . Zend_Date::YEAR);
         $miInsuranceRenewalDataSource = new Datasource_Referencing_MiInsuranceRenewal();
         $miInsuranceRenewalDataSource->insertMiData($customer->getIdentifier(Model_Core_Customer::IDENTIFIER), $renewalDate);
     }
     // Create sign-up completion email
     $customer->sendAccountValidationEmail();
 }
 /**
  * RRP Inception Form
  */
 public function rentRecoveryPlusAction()
 {
     // Ensure address lookup JS is available
     $this->view->headScript()->appendFile('/assets/connect/js/rentguaranteeclaims/addressLookup.js');
     // Ensure date picker CSS and JS are available
     $this->view->headLink()->appendStylesheet('/assets/vendor/jquery-datepicker/css/datePicker.css');
     $this->view->headScript()->appendFile('/assets/vendor/jquery-date/js/date.js');
     $this->view->headScript()->appendFile('/assets/vendor/jquery-datepicker/js/jquery.datePicker.js');
     $request = $this->getSymfonyRequest();
     $data = null;
     $policyNumberManager = new Manager_Core_PolicyNumber();
     if ($request->isMethod('GET')) {
         $quoteNumber = $request->get('policyNumber');
         if ($policyNumberManager->isRentRecoveryPlusQuote($quoteNumber)) {
             $applicationDecoratorClass = $this->getContainer()->get('rrp.application.decorator.class');
             /** @var RRP\Application\Decorators\RentRecoveryPlusQuote $quote */
             $quote = $applicationDecoratorClass::getDecorator('RentRecoveryPlusQuote');
             $data = $quote->getApplicationData($quoteNumber);
         }
     }
     $form = $this->_getRentRecoveryPlusApplicationForm($data, array('currentAsn' => $this->_agentSchemeNumber));
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             if ($request->isXmlHttpRequest()) {
                 $update = true;
             } else {
                 $update = $form->get('update')->isClicked();
             }
             if (!$update) {
                 /** @var RRP\Model\RentRecoveryPlusApplication $application */
                 $application = $form->getData();
                 $applicationDecoratorClass = $this->getContainer()->get('rrp.application.decorator.class');
                 /** @var RRP\Application\Decorators\RentRecoveryPlusQuote $quote */
                 $quote = $applicationDecoratorClass::getDecorator('RentRecoveryPlusQuote');
                 $quote->setFromApplication($application);
                 if ($quote->getAppData()->getRefNo() === null) {
                     $customerManager = new Manager_Core_Customer();
                     $sudoEmailAddress = $customerManager->generateAgentSudoEmailAddress($this->_agentSchemeNumber);
                     $customer = $customerManager->getCustomerByEmailAddress($sudoEmailAddress);
                     $isNewCustomer = false;
                     if (!$customer) {
                         $isNewCustomer = true;
                         $customer = $customerManager->createNewCustomer($sudoEmailAddress, Model_Core_Customer::AGENT, true);
                         $customer->setLastName($this->_agentObj->name);
                         if ($this->_agentObj->contact[0]->address->flatNumber) {
                             $line1 = $this->_agentObj->contact[0]->address->flatNumber . ' ';
                         } else {
                             if ($this->_agentObj->contact[0]->address->houseName) {
                                 $line1 = $this->_agentObj->contact[0]->address->houseName . ' ';
                             } else {
                                 if ($this->_agentObj->contact[0]->address->houseNumber) {
                                     $line1 = $this->_agentObj->contact[0]->address->houseNumber . ' ';
                                 } else {
                                     $line1 = '';
                                 }
                             }
                         }
                         if ($this->_agentObj->contact[0]->address->addressLine1 && $this->_agentObj->contact[0]->address->addressLine2) {
                             $line1 .= $this->_agentObj->contact[0]->address->addressLine1 . ', ' . $this->_agentObj->contact[0]->address->addressLine2;
                         } else {
                             if ($this->_agentObj->contact[0]->address->addressLine1) {
                                 $line1 .= $this->_agentObj->contact[0]->address->addressLine1;
                             } else {
                                 if ($this->_agentObj->contact[0]->address->addressLine2) {
                                     $line1 .= $this->_agentObj->contact[0]->address->addressLine2;
                                 }
                             }
                         }
                         $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $line1);
                         $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $this->_agentObj->contact[0]->address->town);
                         $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $this->_agentObj->contact[0]->address->county);
                         $customer->setPostCode($this->_agentObj->contact[0]->address->postCode);
                         $customer->setCountry($this->_agentObj->contact[0]->address->country);
                         $customerManager->updateCustomer($customer);
                     }
                     // Now get the reference number from the newly created customer
                     $refNo = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                     $quote->getAppData()->setRefNo($refNo);
                     if ($isNewCustomer) {
                         $customerManager->updateCustomerAgentSchemeNumber($this->_agentSchemeNumber, $refNo);
                     }
                     if ($application->getPolicyNumber()) {
                         $policyNumber = $application->getPolicyNumber();
                     } else {
                         $policyNumber = $policyNumberManager->generateApplicationNumber(Manager_Core_PolicyNumber::QUOTE_IDENTIFIER);
                     }
                     $quote->setDefaults($policyNumber, $application->getReferenceType(), $application->getIsContinuationOfExistingPolicy(), $application->getPropertyLetType(), $application->getPropertyDeposit(), Model_Insurance_RentRecoveryPlus_LegacyPolicy::STATUS_QUOTE)->getAppData()->setAgentSchemeNumber($this->_agentSchemeNumber)->setUnderwritingQuestionSetID($this->_params->connect->settings->rentRecoveryPlus->underwritingQuestionSetID)->setRiskArea($this->_params->connect->settings->rentRecoveryPlus->riskArea);
                 } else {
                     $policyNumber = $quote->getAppData()->getPolicyNumber();
                 }
                 $this->referralModel->setPolicyNumber($policyNumber);
                 $this->rateManager = $this->initialiseRateManager($application);
                 $quote->setPolicyOptions($application->getPropertyRental(), $this->rateManager->getPremium(), $this->rateManager->getNilExcessOption())->getAppData()->setPremium($this->rateManager->getPremium())->setIpt($this->rateManager->getIpt())->setQuote($this->rateManager->getQuote())->setRateSetID($this->rateManager->getRateSetID());
                 // Does the given reference satisfy the policy criteria for this particular reference?
                 $referralRequired = false;
                 $reference = $this->getReferenceFromSession($application->getReferenceNumber());
                 $referenceSatisfiesCriteria = $this->referenceSatisfiesCriteria($reference);
                 // Does the application satisfy the application criteria?
                 $this->referralModel->setFromApplication($application, $this->rateManager->getPremium());
                 $applicationSatisfiesCriteria = $this->applicationSatisfiesCriteria();
                 if (!$referenceSatisfiesCriteria || !$applicationSatisfiesCriteria) {
                     // Fire a POLICY_REFERRED event to handle all referral related actions.
                     $referredEvent = new ReferredEvent($this->referralModel);
                     $this->eventDispatcher->dispatch(RRPEvents::POLICY_REFERRED, $referredEvent);
                     // Mark this application as referred.
                     $quote->getAppData()->setPayStatus(Model_Insurance_RentRecoveryPlus_LegacyPolicy::PAY_STATUS_REFERRED);
                     $referralRequired = true;
                 }
                 if ($application->getIsContinuationOfExistingPolicy()) {
                     $mailManager = new Application_Core_Mail();
                     if ($application->getIsExistingPolicyToBeCancelled()) {
                         $subject = str_replace('{$existingPolicyRef}', $application->getExistingPolicyRef(), $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailSubject);
                         $message = $this->getContainer()->get('twig')->render('rent-recovery-plus-cancel-existing-mail.plain.twig', array('agentName' => $this->_agentObj->name, 'agentSchemeNumber' => $this->_agentSchemeNumber, 'policyNumber' => $policyNumber));
                         $mailManager->setTo($this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailToAddress, $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailToName)->setFrom($this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailFromAddress, $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailFromName)->setSubject($subject)->setBodyText($message);
                     } else {
                         $subject = str_replace('{$existingPolicyRef}', $application->getExistingPolicyRef(), $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailSubject);
                         $message = $this->getContainer()->get('twig')->render('rent-recovery-plus-keep-existing-mail.plain.twig', array('agentName' => $this->_agentObj->name, 'agentSchemeNumber' => $this->_agentSchemeNumber, 'existingPolicyRef' => $application->getExistingPolicyRef()));
                         $mailManager->setTo($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailToAddress, $this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailToName)->setFrom($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailFromAddress, $this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailFromName)->setSubject($subject)->setBodyText($message);
                         if (isset($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailCcAddress)) {
                             $mailManager->setCC($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailCcAddress);
                         }
                     }
                     $mailManager->send();
                 }
                 if (!$quote->save()) {
                     return $this->renderTwigView('/rentguarantee/rent-recovery-plus-error.html.twig');
                 }
                 if ($referralRequired) {
                     // Render the referral text to the user.
                     return $this->renderTwigView('/rentguarantee/rent-recovery-plus-referral.html.twig', array('policyNumber' => $policyNumber));
                 }
                 if ($application->getIsPayMonthly()) {
                     $paymentDetails = sprintf('This will appear on your invoices as %d monthly payments of' . ' £%.02f plus £%.02f (IPT at %d%%). Total monthly payment £%.02f. ', $application->getPolicyLength(), $this->rateManager->getPremium(), $this->rateManager->getIpt(), $this->rateManager->getIptPercent(), $this->rateManager->getQuote());
                 } else {
                     $paymentDetails = sprintf('This will appear on your next invoices as £%.02f plus £%.02f (IPT at %d%%). Total £%.02f. ', $this->rateManager->getPremium(), $this->rateManager->getIpt(), $this->rateManager->getIptPercent(), $this->rateManager->getQuote());
                 }
                 return $this->renderTwigView('/rentguarantee/rent-recovery-plus-quote.html.twig', array('policyNumber' => $policyNumber, 'paymentDetails' => $paymentDetails));
             }
         }
     }
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->_helper->viewRenderer->setNoRender(true);
         $this->_helper->layout->disableLayout();
     }
     $agent = new Datasource_Core_AgentUser();
     if ($agent->canDisplayRRPI($this->_agentSchemeNumber, $this->_agentUserName)) {
         $this->renderTwigView('/rentguarantee/rent-recovery-plus-application.html.twig', array('form' => $form->createView()));
     } else {
         $this->renderTwigView('/rentguarantee/rent-recovery-plus-information.html.twig');
     }
 }
 /**
  * Edit account action
  * 
  * @return void 
  */
 public function editAccountAction()
 {
     $this->_setMetaTitle('My HomeLet | Edit Account');
     $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/edit-account' => 'My Account Details'));
     $form = new Account_Form_EditAccount();
     // Populate the form with the security question options
     $securityQuestionModel = new Datasource_Core_SecurityQuestion();
     $securityQuestionOptions = $securityQuestionModel->getOptions();
     foreach ($securityQuestionOptions as $option) {
         $form->security_question->addMultiOption($option['id'], $option['question']);
     }
     // Get the customer session
     $customerSession = $this->auth->getStorage()->read();
     // Retrieve the customer record
     $customermgr = new Manager_Core_Customer();
     $customer = $customermgr->getCustomer(Model_Core_Customer::IDENTIFIER, $customerSession->id);
     if ($this->getRequest()->isPost()) {
         // Set the current password for validation
         $form->setCurrentPassword($customer->getPassword());
         // Validate the form
         if ($form->isValid($this->getRequest()->getPost())) {
             // Update the customer
             if ($form->password->getValue() != '') {
                 // Set new password
                 $customer->setPassword($form->password->getValue());
             }
             $customer->setSecurityQuestion($form->security_question->getValue());
             $customer->setSecurityAnswer($form->security_answer->getValue());
             $this->view->accountUpdated = true;
             $customermgr->updateCustomer($customer);
         }
     } else {
         // Populate the form with customers data
         $form->security_question->setValue($customer->getSecurityQuestion());
         $form->security_answer->setValue($customer->getSecurityAnswer());
     }
     $form->email->setValue($customer->getEmailAddress());
     $form->title->setValue($customer->getTitle());
     $form->first_name->setValue($customer->getFirstName());
     $form->last_name->setValue($customer->getLastName());
     $this->view->form = $form;
 }
 /**
  * Register action
  *
  * @return void
  */
 public function partialRegistrationAction()
 {
     $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/partial-registration' => 'Continue Registration'));
     $params = Zend_Registry::get('params');
     $form = new Account_Form_Register();
     // Populate the form with the security question options
     $securityQuestionModel = new Datasource_Core_SecurityQuestion();
     $securityQuestionOptions = $securityQuestionModel->getOptions();
     foreach ($securityQuestionOptions as $option) {
         $form->security_question->addMultiOption($option['id'], $option['question']);
     }
     $customerManager = new Manager_Core_Customer();
     if (!$this->getRequest()->isPost()) {
         $refno = $_GET['refno'];
         $email = $_GET['email'];
         $mac = new Application_Core_Security($params->myhomelet->activation_mac_secret, false);
         $digest = $mac->generate(array('email' => $email));
         if ($refno) {
             // Try by legacy customer refno
             $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $refno);
         } else {
             // Try by email
             $customer = $customerManager->getCustomerByEmailAddress($email);
         }
         $formData = array();
         $formData['title'] = $customer->getTitle();
         $formData['first_name'] = $customer->getFirstName();
         $formData['last_name'] = $customer->getLastName();
         $formData['email'] = $email;
         $formData['refno'] = $refno;
         #$form->title->setAttrib('readonly','readonly');
         #$form->first_name->setAttrib('readonly','readonly');
         #$form->last_name->setAttrib('readonly','readonly');
         $form->email->setAttrib('readonly', 'readonly');
         $form->populate($formData);
         if ($digest != $_GET['mac']) {
             // Render error page if invalid mac
             $this->render('activate-account-invalidmac');
             return;
         }
     } else {
         if ($form->isValid($this->getRequest()->getPost())) {
             // Detect if the customer has already registered with this email address
             $customer = $customerManager->getCustomerByEmailAddress($form->email->getValue());
             if ($customer) {
                 // Customer already exists, flag form in error
                 // Ideally this should go in the form as an overridden validation method, but this would
                 // tightly couple the form to the customer manager anyway, which itself is bad.
                 // Alternatively I could inject the found customer object into the form, but then this doesn't change
                 // much to using the code here anyway.
                 $form->email->addError('This email is already in use. Have you signed up before?')->markAsError();
             } else {
                 // Create customer. Because this is the generic registration page, we use a generic customer type
                 $customer = $customerManager->createCustomerFromLegacy($form->email->getValue(), $form->refno->getValue());
                 $custID = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER);
                 $leg = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $form->refno->getValue());
                 // Update customer with password and security data
                 $customerManager->updateCustomerByLegacy($leg, $custID);
                 $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $custID);
                 $customer->setSecurityQuestion($form->security_question->getValue());
                 $customer->setSecurityAnswer($form->security_answer->getValue());
                 $customer->setPassword($form->password->getValue());
                 $customer->setEmailValidated(true);
                 $customerManager->updateCustomer($customer);
                 // Create welcome email
                 $mail = new Application_Core_Mail();
                 $mail->setTo($_GET['email'], null);
                 $mail->setFrom('*****@*****.**', 'HomeLet');
                 $mail->setSubject('Registration for My HomeLet');
                 // Apply template
                 $mail->applyTemplate('core/account-welcome', array('homeletWebsite' => $params->homelet->domain, 'templateId' => 'HL2443 12-12', 'firstname' => $customer->getFirstName(), 'heading' => 'Your registration for My HomeLet is complete!', 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml');
                 $mail->applyTextTemplate('core/account-welcometxt', array('homeletWebsite' => $params->homelet->domain, 'templateId' => 'HL2443 12-12', 'firstname' => $customer->getFirstName(), 'heading' => 'Your registration for My HomeLet is complete!'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml');
                 // Send email
                 $mail->send();
                 // Find all customers in mysql4 insurance that have the same email address
                 $legacyCustomers = $customerManager->getAllLegacyCustomersByEmailAddress($_GET['email']);
                 $customerIdentifier = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER);
                 foreach ($legacyCustomers as $legacyCustomer) {
                     // For each customer found, insert a record into the mysql5 customer_legacy_customer_map table
                     $legacyIdentifier = $legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                     $customerMap = new Datasource_Core_CustomerMaps();
                     if (!$customerMap->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $legacyIdentifier)) {
                         $customerManager->linkLegacyToNew($legacyIdentifier, $customerIdentifier);
                     }
                 }
                 $this->_helper->redirector->gotoUrl('/my-homelet/login?message=registration-complete');
             }
         }
     }
     $this->view->form = $form;
 }
 /**
  * Initialise the step 3 form [Important Information Form]
  *
  * @return void
  */
 public function step3Action()
 {
     $pageForm = new TenantsInsuranceQuoteB_Form_Step3();
     // Tell page to use AJAX validation as we go
     $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 3;');
     // Get customer details
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber);
     // Hydrate registration form
     if (isset($pageForm->subform_register) || isset($pageForm->subform_login)) {
         // Grab a new customer to populate the form
         $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
         $newCust = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $pageSession->CustomerID);
         if (isset($pageForm->subform_register)) {
             if ($newCust) {
                 $pageForm->subform_register->email->setValue($newCust->getEmailAddress());
                 $pageForm->subform_register->security_question->setValue($newCust->getSecurityQuestion());
                 $pageForm->subform_register->security_answer->setValue($newCust->getSecurityAnswer());
                 $emailAddress = $newCust->getEmailAddress();
             } else {
                 $pageForm->subform_register->email->setValue($customer->getEmailAddress());
                 $emailAddress = $customer->getEmailAddress();
             }
             if (!$emailAddress) {
                 $emailAddress = $newCust->getEmailAddress();
             }
         } else {
             if ($newCust) {
                 $pageForm->subform_login->email->setValue($newCust->getEmailAddress());
             }
         }
     }
     if ($this->getRequest()->isPost()) {
         $valid = $this->_formStepCommonValidate($pageForm, 3);
         if (isset($pageForm->subform_register)) {
             $pageForm->subform_register->getElement('email')->setValue($emailAddress);
         }
         if ($valid) {
             $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
             $pageSession->IsNewCustomer = false;
             $data = $pageForm->getValues();
             //Update the WebLead summary and create a STEP3 blob.
             $webLeadManager = new Manager_Core_WebLead();
             $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId);
             $webLeadSummary->lastUpdatedTime = $this->_offsetDate();
             $webLeadSummary->promotionCode = $data["subform_howhear"]['campaign_code'];
             $webLeadManager->updateSummary($webLeadSummary);
             //Determine if a new STEP3 blob needs to be created, or an existing one retrieved.
             if ($webLeadManager->getBlobExists($this->_webLeadSummaryId, Model_Core_WebLeadStep::STEP3)) {
                 $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP3);
             } else {
                 $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP3);
             }
             //Update the blob and store
             $webLeadBlob->blob = Zend_Json::encode($_POST);
             $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob);
             $webLeadManager->updateBlob($webLeadBlob);
             // Instantiate the quote manager
             $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
             // Save new ASN if there is one
             // Create a postcode model
             $postcode = new Manager_Core_Postcode();
             // Get the address as array for Insured and correspondance address
             $insuredAddress = $postcode->getPropertyByID($data['subform_insuredaddress']['ins_address'], false);
             $correspondenceAddress = $postcode->getPropertyByID($data['subform_correspondencedetails']['cor_address'], false);
             // Update the property address in the quote
             $quoteManager->setPropertyAddress(($insuredAddress['organisation'] != '' ? "{$insuredAddress['organisation']}, " : '') . ($insuredAddress['buildingName'] != '' ? "{$insuredAddress['buildingName']}, " : '') . ($insuredAddress['houseNumber'] != '' ? "{$insuredAddress['houseNumber']} " : '') . $insuredAddress['address2'], $insuredAddress['address4'], $insuredAddress['address5'], $insuredAddress['postcode']);
             // Update start and end dates
             $startDate = $data['subform_policydetails']['policy_start'];
             $startDate = substr($startDate, 6, 4) . '-' . substr($startDate, 3, 2) . '-' . substr($startDate, 0, 2);
             $endDate = date('Y-m-d', strtotime(date('Y-m-d', strtotime($startDate)) . ' +1 year -1 day'));
             $quoteManager->setStartAndEndDates($startDate, $endDate);
             //Update the customer in the DataStore and the LegacyDataStore. Use the CustomerManager
             //to do this.
             //$customerManager = new Manager_Core_Customer();
             //First get the existing customer details.
             //$customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber);
             //Now modify the details.
             $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, ($correspondenceAddress['organisation'] != '' ? "{$correspondenceAddress['organisation']}, " : '') . ($correspondenceAddress['houseNumber'] != '' ? "{$correspondenceAddress['houseNumber']} " : '') . ($correspondenceAddress['buildingName'] != '' ? "{$correspondenceAddress['buildingName']}, " : '') . $correspondenceAddress['address2']);
             $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $correspondenceAddress['address4']);
             $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $correspondenceAddress['address5']);
             $customer->setPostCode($correspondenceAddress['postcode']);
             $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob));
             //Finally, save the details back to both DataStores.
             $customerManager->updateCustomer($customer);
             $premiums = $quoteManager->calculatePremiums();
             // Save MI information - how did you hear about us
             $marketQuestion = new Manager_Core_ManagementInformation();
             $marketQuestion->saveMarketingAnswers($this->_policyNumber, $this->_customerReferenceNumber, $data["subform_howhear"]["how_hear"]);
             // Perform login/register procedure
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             if (isset($data['subform_register'])) {
                 // Process registration
                 $params = Zend_Registry::get('params');
                 $newCustomer = $customerManager->getCustomerByEmailAddress($data['subform_register']['email']);
                 if (!$newCustomer) {
                     $newCustomer = $customerManager->createCustomerFromLegacy($data['subform_register']['email'], $this->_customerReferenceNumber);
                 }
                 // Update customer with password and security data
                 $newCustomer->setTitle($customer->getTitle());
                 $newCustomer->setFirstName($customer->getFirstName());
                 $newCustomer->setLastName($customer->getLastName());
                 $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, ($correspondenceAddress['organisation'] != '' ? "{$correspondenceAddress['organisation']}, " : '') . ($correspondenceAddress['houseNumber'] != '' ? "{$correspondenceAddress['houseNumber']} " : '') . ($correspondenceAddress['buildingName'] != '' ? "{$correspondenceAddress['buildingName']}, " : '') . $correspondenceAddress['address2']);
                 $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $correspondenceAddress['address4']);
                 $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $correspondenceAddress['address5']);
                 $newCustomer->setPostCode($correspondenceAddress['postcode']);
                 $newCustomer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob));
                 //                    assuming that the email is already set and so won't require setting again.
                 //                    $newCustomer->setEmailAddress($data['subform_register']['email']);
                 $newCustomer->setSecurityQuestion($data['subform_register']['security_question']);
                 $newCustomer->setSecurityAnswer($data['subform_register']['security_answer']);
                 $newCustomer->setPassword($data['subform_register']['password']);
                 $newCustomer->setAccountLoadComplete(true);
                 $newCustomer->typeID = Model_Core_Customer::CUSTOMER;
                 $customerManager->updateCustomer($newCustomer);
                 // Create sign-up completion email
                 $mail = new Application_Core_Mail();
                 $mail->setTo($data['subform_register']['email'], null);
                 $mail->setFrom('*****@*****.**', 'HomeLet');
                 $mail->setSubject('My HomeLet account validation');
                 //  Generate activation link
                 $mac = new Application_Core_Security($params->myhomelet->activation_mac_secret, false);
                 $digest = $mac->generate(array('email' => $data['subform_register']['email']));
                 $activationLink = 'email=' . $data['subform_register']['email'] . '&' . 'mac=' . $digest;
                 // Apply template
                 $mail->applyTemplate('core/account-validation', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $newCustomer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account'), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml');
                 $mail->applyTextTemplate('core/account-validationtxt', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $newCustomer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml');
                 // Send email
                 $mail->send();
                 // Everything has been saved ok so navigate to next step
                 $this->_formStepCommonNavigate(3);
             } elseif ($auth->hasIdentity()) {
                 $this->_formStepCommonNavigate(3);
             }
             //return;
         } elseif (isset($_POST['back'])) {
             $this->_formStepCommonNavigate(3);
             return;
         }
     }
     // Load the element data from the database if we can
     if ($this->_formStepCommonPopulate($pageForm, 3)) {
         // Render the page unless we have been redirected
         $this->view->form = $pageForm;
         $this->render('step');
     }
 }
 /**
  * Writes the Reference object to the legacy datasources.
  *
  * @param Model_Referencing_Reference $reference
  * The reference to write to the Munt.
  *
  * @return void
  */
 protected function _pushToMunt(Model_Referencing_Reference $reference)
 {
     // Check the legacy customer id is set
     if ($reference->customer->legacyCustomerId == null && $reference->customer->customerType == Model_Referencing_CustomerTypes::LANDLORD) {
         // Create a new legacy customer for the private landlord
         $customerManager = new Manager_Core_Customer();
         $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $reference->customer->customerId);
         $legacyCustomer = $customerManager->createNewCustomer($customer->getEmailAddress(), Model_Core_Customer::CUSTOMER, true);
         $legacyCustomer->setFirstName($customer->getFirstName());
         $legacyCustomer->setLastName($customer->getLastName());
         $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1));
         $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2));
         $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3));
         $legacyCustomer->setTelephone(Model_Core_Customer::TELEPHONE1, $customer->getTelephone(Model_Core_Customer::TELEPHONE1));
         $legacyCustomer->setTelephone(Model_Core_Customer::TELEPHONE2, $customer->getTelephone(Model_Core_Customer::TELEPHONE2));
         $legacyCustomer->setPassword($customer->getPassword());
         $customerManager->updateCustomer($legacyCustomer);
         // Drop the legacy customer refno into the reference customer map object
         $reference->customer->legacyCustomerId = $legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
     }
     $muntManager = new Manager_ReferencingLegacy_Munt();
     $muntManager->updateReference($reference);
 }
 /**
  * Handle registering for or sign in to My HomeLet.
  *
  * @param int $policyNumber
  * @return LandlordsInsuranceQuote_Form_MyHomeLetRegistration
  */
 private function registrationFormProcess($policyNumber)
 {
     $pageForm = new LandlordsInsuranceQuote_Form_MyHomeLetRegistration();
     // Tell page NOT to use AJAX validation as we go
     $this->view->headScript()->appendScript('var ajaxValidate = false;');
     // Get the session
     $session = new Zend_Session_Namespace('landlords_insurance_quote');
     // Get customer details
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber);
     // Hydrate registration form
     if (isset($pageForm->subform_register)) {
         // Grab a new customer to populate the form
         $newCust = $customerManager->getCustomerByEmailAddress($customer->getEmailAddress());
         if ($newCust) {
             $pageForm->subform_register->email->setValue($newCust->getEmailAddress());
             $pageForm->subform_register->security_question->setValue($newCust->getSecurityQuestion());
             $pageForm->subform_register->security_answer->setValue($newCust->getSecurityAnswer());
             $emailAddress = $newCust->getEmailAddress();
         } else {
             $pageForm->subform_register->email->setValue($customer->getEmailAddress());
             $emailAddress = $customer->getEmailAddress();
         }
         if (!$emailAddress) {
             $emailAddress = $newCust->getEmailAddress();
         }
     } elseif (isset($pageForm->subform_login)) {
         // Get the email address from the legacy customer and pre-populate the login form
         $pageForm->subform_login->email->setValue($customer->getEmailAddress());
     }
     if ($this->getRequest()->isPost() && isset($_POST['register'])) {
         // We need to validate and save the data
         $valid = $this->_formStepCommonValidate($pageForm, 'registration');
         if (isset($pageForm->subform_register)) {
             $pageForm->subform_register->getElement('email')->setValue($emailAddress);
         }
         if ($valid) {
             $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
             $data = $pageForm->getValues();
             // Re-add the DoB remembered from Step 1 because otherwise logging-in landlords' DoBs go missing.
             $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob));
             $customerManager->updateCustomer($customer);
             // Perform login/register procedure
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             if (isset($data['subform_register'])) {
                 // Process registration
                 $newCustomer = $customerManager->getCustomerByEmailAddress($data['subform_register']['email']);
                 if (!$newCustomer) {
                     $newCustomer = $customerManager->createCustomerFromLegacy($data['subform_register']['email'], $this->_customerReferenceNumber);
                     $customerID = $newCustomer->getIdentifier(Model_Core_Customer::IDENTIFIER);
                     $customerManager->updateCustomerByLegacy($customer, $customerID);
                     $newCustomer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
                 }
                 // Update customer with password and security data
                 $newCustomer->setEmailAddress($data['subform_register']['email']);
                 // Set the new customer's DoB with that remembered from Step 1 otherwise newly registering
                 //   landlords' DoBs become empty.
                 $newCustomer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob));
                 $newCustomer->setSecurityQuestion($data['subform_register']['security_question']);
                 $newCustomer->setSecurityAnswer($data['subform_register']['security_answer']);
                 $newCustomer->setPassword($data['subform_register']['password']);
                 $newCustomer->setAccountLoadComplete(true);
                 $newCustomer->typeID = Model_Core_Customer::CUSTOMER;
                 $customerManager->updateCustomer($newCustomer);
                 // Create sign-up completion email
                 $newCustomer->sendAccountValidationEmail();
                 // Everything has been saved OK so navigate to registration confirmation step
                 $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/registration-confirmation?pn=' . $policyNumber);
             } elseif ($auth->hasIdentity()) {
                 $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/registration-confirmation?pn=' . $policyNumber);
             }
         }
     }
     return $pageForm;
 }
 /**
  * Handle registering for or sign in to My HomeLet.
  *
  * @param int $policyNumber
  * @return TenantsInsuranceQuote_Form_MyHomeLetRegistration
  */
 private function registrationFormProcess($policyNumber)
 {
     $pageForm = new TenantsInsuranceQuote_Form_MyHomeLetRegistration();
     // Tell page NOT to use AJAX validation as we go
     $this->view->headScript()->appendScript('var ajaxValidate = false;');
     // Get customer details
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber);
     // Hydrate registration form
     if (isset($pageForm->subform_register) || isset($pageForm->subform_login)) {
         // Grab a new customer to populate the form
         $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
         $newCust = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $pageSession->CustomerID);
         if (isset($pageForm->subform_register)) {
             if ($newCust) {
                 $pageForm->subform_register->email->setValue($newCust->getEmailAddress());
                 $pageForm->subform_register->security_question->setValue($newCust->getSecurityQuestion());
                 $pageForm->subform_register->security_answer->setValue($newCust->getSecurityAnswer());
                 $emailAddress = $newCust->getEmailAddress();
             } else {
                 $pageForm->subform_register->email->setValue($customer->getEmailAddress());
                 $emailAddress = $customer->getEmailAddress();
             }
             if (!$emailAddress) {
                 $emailAddress = $newCust->getEmailAddress();
             }
         } else {
             if ($newCust) {
                 $pageForm->subform_login->email->setValue($newCust->getEmailAddress());
             }
         }
     }
     if ($this->getRequest()->isPost() && isset($_POST['register'])) {
         $valid = $this->_formStepCommonValidate($pageForm, 'registration');
         if (isset($pageForm->subform_register)) {
             $pageForm->subform_register->getElement('email')->setValue($emailAddress);
         }
         if ($valid) {
             $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
             $pageSession->IsNewCustomer = false;
             $data = $pageForm->getValues();
             // Perform login/register procedure
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             if (isset($data['subform_register'])) {
                 // Process registration
                 $newCustomer = $customerManager->getCustomerByEmailAddress($data['subform_register']['email']);
                 if (!$newCustomer) {
                     $newCustomer = $customerManager->createCustomerFromLegacy($data['subform_register']['email'], $this->_customerReferenceNumber);
                 }
                 // Update customer with password and security data
                 $newCustomer->setTitle($customer->getTitle());
                 $newCustomer->setFirstName($customer->getFirstName());
                 $newCustomer->setLastName($customer->getLastName());
                 $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1));
                 $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2));
                 $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3));
                 $newCustomer->setPostcode($customer->getPostcode());
                 $newCustomer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob));
                 $newCustomer->setSecurityQuestion($data['subform_register']['security_question']);
                 $newCustomer->setSecurityAnswer($data['subform_register']['security_answer']);
                 $newCustomer->setPassword($data['subform_register']['password']);
                 $newCustomer->setAccountLoadComplete(true);
                 $newCustomer->typeID = Model_Core_Customer::CUSTOMER;
                 $customerManager->updateCustomer($newCustomer);
                 // Create sign-up completion email
                 $newCustomer->sendAccountValidationEmail();
                 // Everything has been saved OK so navigate to registration confirmation step
                 $this->_helper->redirector->gotoUrl('/tenants/insurance-quote/registration-confirmation?pn=' . $policyNumber);
             } elseif ($auth->hasIdentity()) {
                 $this->_helper->redirector->gotoUrl('/tenants/insurance-quote/registration-confirmation?pn=' . $policyNumber);
             }
         }
     }
     return $pageForm;
 }