/**
  * Helper function for generating sent email history HTML fragment
  *
  * @return string
  */
 public function showEmailHistory()
 {
     // Fetch e-mails
     $pageSession = new Zend_Session_Namespace('tenants_referencing_tracker');
     if (isset($pageSession->enquiryId)) {
         $tatManager = new Manager_Referencing_Tat($pageSession->enquiryId);
         $tat = $tatManager->getTat();
         $tatNotificationArray = $tat->tatNotifications;
         $outputData = array();
         if (!empty($tatNotificationArray)) {
             foreach ($tatNotificationArray as $currentNotification) {
                 $outputData[] = array('date' => $currentNotification->sendDate->toString(), 'content' => $currentNotification->content);
             }
         }
         if (count($outputData) > 0) {
             // Return partial view HTML for when e-mails have been sent
             return $this->view->partial('tenants-referencing-tracker/partials/show-email-history.phtml', array('emails' => $outputData));
         } else {
             // Return partial view HTML for when no e-mails have been sent
             return $this->view->partial('tenants-referencing-tracker/partials/show-email-history-empty.phtml');
         }
     }
 }
 /**
  * Send e-mail to HomeLet screen
  *
  * @return void
  */
 public function emailAction()
 {
     if ($this->_enquiryId == null) {
         return;
     }
     $pageForm = new Form_TenantsReferencingTracker_Email();
     $request = $this->getRequest();
     $formData = $request->getPost();
     $pageForm->populate($formData);
     $tatManager = new Manager_Referencing_Tat($this->_enquiryId);
     $tat = $tatManager->getTat();
     $tatMailManager = new Manager_Referencing_TatMail($tatManager->_reference);
     if ($request->isPost()) {
         // Check if user's going back to the TAT index, or is submitting the form
         if (isset($formData['back'])) {
             // Redirect to index page
             $this->_helper->redirector->gotoUrl('/tenants/reference-tracker');
             return;
         } else {
             // Check if this is to add/remove attachments, or is a full submit
             // TODO: It'd be nice to handle this by separating it out into a smooth non-page-refreshing AJAX method
             if (isset($formData['attachButton']) || isset($formData['deleteButton'])) {
                 // Handle attachments
                 if (isset($formData['attachButton'])) {
                     $tatMailManager->addAttachments();
                 } else {
                     $tatMailManager->deleteAttachments();
                 }
             } else {
                 if ($pageForm->isValid($formData)) {
                     // Successful set of data, send e-mail and show message to user
                     $data = $pageForm->getValues();
                     $content = '';
                     $content .= "Enquiry ID: {$this->_enquiryId}\r\n\r\n";
                     $content .= "Name: {$data['name']}\r\n\r\n";
                     $content .= "Contact number or e-mail address: {$data['contact_info']}\r\n\r\n";
                     $content .= "Message to assessor:\r\n{$data['message']}\r\n\r\n";
                     $attachmentInfo = $tatMailManager->detailAttachments();
                     if (count($attachmentInfo) > 0) {
                         $tatMailManager->notifyAssessorWithAttachments($content);
                         $tatMailManager->deleteAttachments();
                     } else {
                         $tatMailManager->notifyAssessor($content);
                     }
                     // Log MI event
                     Application_Core_ActivityLogger::log('TAT Email HomeLet', 'complete', 'TAT', null, "IRN: {$this->_enquiryId}");
                     // Redirect to confirmation page, the redirect prevents
                     //   multiple submissions if user refreshes browser
                     $this->_helper->redirector->gotoUrl('/tenants/reference-tracker/emailsent');
                     return;
                 }
             }
         }
     }
     $this->view->reference = $tatManager->_reference;
     $this->view->form = $pageForm;
 }
Example #3
0
 /**
  * Overridden isValid() method for pre-validation code
  *
  * @param array $formData data typically from a POST or GET request
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     // Check if all 3 pieces of info are supplied
     $asn = isset($formData['letting_agent_asn']) ? preg_replace('/[^\\d]/', '', $formData['letting_agent_asn']) : '';
     $irn = isset($formData['tenant_reference_number']) ? preg_replace('/[^\\d]/', '', $formData['tenant_reference_number']) : '';
     $dob = isset($formData['tenant_dob']) ? preg_replace('/[^\\d\\/]/', '', $formData['tenant_dob']) : '';
     // If the IRN is not actually an IRN, but an IRIS reference number (i.e. prefixed with HLT)
     if (preg_match('/^HLT\\d+$/', $formData['tenant_reference_number'])) {
         return self::IRIS_LOGIN;
     }
     if ($dob != '') {
         try {
             //Check for a valid date of birth. If this causes an exception, end
             //the process here rather than passing up to the overriden method,
             //otherwise the same exception will be thrown again.
             $isDobError = false;
             $dob = new Zend_Date($dob);
         } catch (Zend_Exception $e) {
             $isDobError = true;
         }
         if ($isDobError) {
             $this->getElement('tenant_dob')->addError('Please provide a valid date of birth.');
             // Validate other fields, to keep the error messages consistent
             unset($formData['tenant_dob']);
             $dummy = parent::isValidPartial($formData);
             return false;
         }
     }
     //Continue the validation.
     $displayErrorMessage1 = false;
     $displayErrorMessage2 = false;
     $displayErrorMessage3 = false;
     $displayErrorMessage4 = false;
     if ($asn != '' && $irn != '' && $dob != '') {
         // Check if a record can be found
         $tatManager = new Manager_Referencing_Tat($irn);
         if ($tatManager->isLoginValid($asn, $dob)) {
             // Check if user allowed to login
             if (!$tatManager->isTatApplicable()) {
                 // Can't log in. Check if this is because the TAT has expired.
                 if ($tatManager->isTatExpired()) {
                     $displayErrorMessage1 = true;
                 } else {
                     //If the reference is of type INSIGHT or XPRESS, then provide a specific error message.
                     $referenceManager = new Manager_ReferencingLegacy_Munt();
                     $reference = $referenceManager->getReference($irn);
                     $product = $reference->productSelection->product;
                     if (isset($product->variables[Model_Referencing_ProductVariables::CREDIT_REFERENCE])) {
                         $displayErrorMessage2 = true;
                     } else {
                         //Set the generic form-level error.
                         $displayErrorMessage3 = true;
                     }
                 }
             }
         } else {
             // Can't find a record, set a form-level error
             $displayErrorMessage3 = true;
         }
     } else {
         // One or more fields are empty (when filtered), set a form-level error
         $displayErrorMessage4 = true;
     }
     //Display the error message if appropriate.
     if ($displayErrorMessage1) {
         $this->addError('Unfortunately we only hold information on the Tenant Application Tracker for 30 days and we believe
                          that your application was completed over a month ago. If you have any questions about your tenancy
                          application please speak directly with your letting agent.');
     } else {
         if ($displayErrorMessage2) {
             $this->addError('Oops, we\'re unable to match the information you\'ve entered, please check your details and try again.');
         } else {
             if ($displayErrorMessage3) {
                 $this->addError('I\'m sorry we\'ve been unable to find your application with the details that you\'ve provided. Please check the details that you entered and try again.');
             } else {
                 if ($displayErrorMessage4) {
                     $this->addError('Please ensure you complete all 3 fields before selecting submit.');
                 }
             }
         }
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * Records a TAT notification email in the datasource.
  *
  * Will not record a TAT notification if a TAT is not applicable for
  * the reference.
  *
  * @param string $enquiryId
  * Identifies the reference. Can be either the IRN or the ERN.
  *
  * @param string $content
  * The email content that was sent to the reference subject.
  *
  * @return void
  */
 public function logTatNotification($enquiryId, $content)
 {
     //Ensure no logging of non-applicable references.
     $tatManager = new Manager_Referencing_Tat($enquiryId);
     if ($tatManager->isTatApplicable()) {
         $tatNotification = new Model_Referencing_TatNotification();
         $tatNotification->enquiryId = $tatManager->_reference->externalId;
         $tatNotification->sendDate = Zend_Date::now();
         $tatNotification->content = $content;
         $tatNotifications = new Datasource_Referencing_TatNotification();
         $tatNotifications->insertNotification($tatNotification);
     }
 }