/**
  * 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;
 }