public function __construct($enquiryId = null) { if (is_null($enquiryId)) { throw new Zend_Exception("Enquiry identifier is null"); } else { $muntManager = new Manager_ReferencingLegacy_Munt(); $this->_reference = $muntManager->getReference($enquiryId); } }
/** * Opens a PDF from local storage, populates it with agent details (if * needed) and outputs it to either browser or by e-mail. * * @param string $formName The name of the PDF form, or 'all' for all by e-mail. * @param mixed $asn Agent scheme number of agent whose details are to be inserted. * @param int $agentUserId Optional user ID - needed for e-mailing forms. * @param string $destination Optional output mechanism, if set should be 'browser' or not 'browser'. * @param mixed $refno Optional reference number, for a special case PDF that requires applicant data injection. */ public function populateAndOuput($formName, $asn, $agentUserId = null, $destination = 'browser', $refno = null) { $attachmentList = array(); switch ($formName) { // Forms that require agent details to be injected case 'Agent-Company': case 'Agent-Guarantor': case 'Agent-Individual': case 'Agent-Student-guarantor': case 'Agent-Unemployed-guarantor': // Instantiate agent manager and fetch agent details $agentManager = new Manager_Core_Agent(); $agent = $agentManager->getAgent($asn); // Shove agent details through form $this->setForm($formName); $this->agentPopulate($agent); // For "Print Guarantor Form" from ref summary screen: if (!is_null($refno)) { // Fetch reference by refno using the Referencing MUNT Manager class $refMuntManager = new Manager_ReferencingLegacy_Munt(); $reference = $refMuntManager->getReference($refno); // For safety, ensure reference belongs to this ASN before injecting applicant details if ($reference->customer->customerId == $asn) { $this->applicantPopulate($reference); } } if ($destination == 'browser') { $this->output('browser'); } else { $attachmentList[$formName] = $this->output('file'); } break; // Forms that are a pass-through // Forms that are a pass-through case 'Tenant-Declaration': case 'Guarantor-Declaration': $this->setForm($formName); if ($destination == 'browser') { $this->output('browser'); } else { $attachmentList[$formName] = $this->output('file'); } break; // Send all forms - by e-mail only // Send all forms - by e-mail only case 'all': // Instantiate agent manager and fetch agent details $agentManager = new Manager_Core_Agent(); $agent = $agentManager->getAgent($asn); // Generate those needing agent data merged in foreach (array('Agent-Company', 'Agent-Guarantor', 'Agent-Individual', 'Agent-Student-guarantor', 'Agent-Unemployed-guarantor') as $thisFormName) { $this->setForm($thisFormName); $this->agentPopulate($agent); $attachmentList[$thisFormName] = $this->output('file'); } // Generate straight throughs foreach (array('Tenant-Declaration', 'Guarantor-Declaration') as $thisFormName) { $this->setForm($thisFormName); $attachmentList[$thisFormName] = $this->output('file'); } break; } // If there are attachments, this is/these are to be sent by e-mail if (count($attachmentList) > 0) { // Instantiate agent user manager to get name and e-mail address $agentUserManager = new Manager_Core_Agent_User(); $agentUser = $agentUserManager->getUser($agentUserId); // Generate e-mail $mailer = new Application_Core_Mail(); $mailer->setTo($agentUser->email->emailAddress, $agentUser->name); // TODO: Parameterise: $mailer->setFrom('*****@*****.**', 'HomeLet Referencing'); $mailer->setSubject('HomeLet Referencing Application Form'); $mailer->setBodyText('Please find your HomeLet referencing application forms attached.'); foreach ($attachmentList as $name => $location) { $mailer->addAttachment($location, "{$name}.pdf"); } $mailer->send(); // Garbage collection $this->garbageCollect($attachmentList); } }
/** * 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); }
public function resendEmailAction() { // Pop-up results need pop-up layout $this->_helper->layout->setLayout('popup'); // Get refno from GET var, look up applicant details $refno = isset($_GET['refno']) ? $_GET['refno'] : ''; $refMuntManager = new Manager_ReferencingLegacy_Munt(); $reference = $refMuntManager->getReference($refno); $applicantTypes = array_flip(Model_Referencing_ReferenceSubjectTypes::iterableKeys()); $applicantType = ucwords(strtolower($applicantTypes[$reference->referenceSubject->type])); $applicantType = $applicantType == 'Tenant' ? 'Applicant' : $applicantType; // Intantiate form definition $pageForm = new Connect_Form_ReferencingResendEmail(); // Validate form if POSTed $request = $this->getRequest(); if ($request->isPost() && !is_null($request->getParam('fromForm')) && $request->getParam('fromForm') == '1') { $postData = $request->getPost(); if ($pageForm->isValid($postData)) { // Instantiate security manager for generating MAC $securityManager = new Application_Core_Security($this->_params->connect->ref->security->securityString->user); $macToken = $securityManager->generate(array($this->_agentSchemeNumber, $this->_agentId)); // cURL original page in old ref system, bleurgh $baseReferencingUrl = $this->_params->connect->baseUrl->referencing; $to = $pageForm->getElement('email')->getValue(); $url = "{$baseReferencingUrl}frontEnd/emailtenantlink.php?refno={$refno}&tempemail={$to}&brand=default&agentToken={$macToken}"; // TODO: Use Zend_Http_Client and Zend_Http_Client_Adapter_Curl $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status != 200) { // Show user there was a problem $this->view->error = "({$status}): " . curl_error($ch); $this->_helper->viewRenderer('resend-email-failed'); } else { curl_close($ch); // TODO: Check for error being returned if (false) { // Show user there was a fatal problem $this->_helper->viewRenderer('resend-email-failed'); } else { //Update e-mail address. if ($pageForm->getElement('replace')->getValue() == '1') { //Get the legacy Tenant ID, then use that to identify the //Tenant record to update in the legacy Tenant table. $legacyEnquiryDatasource = new Datasource_ReferencingLegacy_Enquiry(); $legacyTenantId = $legacyEnquiryDatasource->getTenantId($reference->externalId); $rsds = new Datasource_ReferencingLegacy_ReferenceSubject(); $rsds->updateField($legacyTenantId, Datasource_ReferencingLegacy_ReferenceSubject::FIELD_EMAIL, $to); } // Show user all was successful $this->_helper->viewRenderer('resend-email-confirmation'); } } } else { // Show errors back to user $allErrors = $pageForm->getMessages(); foreach ($allErrors as $field => $errors) { foreach ($errors as $errorType => $errorMessage) { $this->_helper->flashmessages->addMessage($errorMessage); } } } } else { // Pre-fill in refno, e-mail address and replacement checkbox $pageForm->getElement('email')->setValue($reference->referenceSubject->contactDetails->email1); $pageForm->getElement('replace')->setValue(1); } $this->view->refno = $refno; $this->view->applicantName = "{$reference->referenceSubject->name->title} {$reference->referenceSubject->name->firstName} {$reference->referenceSubject->name->lastName}"; $this->view->applicantType = $applicantType; $this->view->form = $pageForm; $this->view->flashMessages = $this->_helper->flashmessages->getCurrentMessages(); }