Ejemplo n.º 1
0
 /**
  * Credit card payment form
  * Different form for administrators
  */
 public function paymentForm(\Jazzee\Entity\Applicant $applicant, $amount)
 {
     $form = new \Foundation\Form();
     if (\is_a($this->_controller, 'ApplyPageController')) {
         $form->newHiddenElement('ucla_ref_no', uniqid(rand()));
         $form->newHiddenElement('amount1', $amount);
         $form->newHiddenElement('itemcode1', $this->_paymentType->getVar('itemCode'));
         $form->newHiddenElement('desc1', $this->_paymentType->getVar('itemDescription'));
         $form->newHiddenElement('ref1type1', $this->_paymentType->getVar('reftypeApplicantId'));
         $form->newHiddenElement('ref1val1', $applicant->getId());
         $form->newHiddenElement('ref2type1', $this->_paymentType->getVar('reftypeForwardUrl'));
         $form->newHiddenElement('ref2val1', $this->_controller->getServerPath() . $this->_controller->getActionPath());
         $form->newHiddenElement('signouturl', $this->_controller->absolutePath('transaction/' . \urlencode(get_class($this))));
         if ($this->_controller->getConfig()->getStatus() == 'PRODUCTION') {
             $form->setAction(self::CASHNET_URL . $this->_paymentType->getVar('liveSiteName'));
         } else {
             $form->setAction(self::CASHNET_URL . $this->_paymentType->getVar('devSiteName'));
         }
         $field = $form->newField();
         $field->setLegend($this->_paymentType->getName());
         $field->setInstructions("<p>Clicking the 'Pay with Credit Card' button will redirect you to a secure payment page.  Once you have completed your transaction you will be returned to the application.<strong>Application Fee:</strong> &#36;{$amount}</p>");
         $form->newButton('submit', 'Pay with Credit Card');
     } else {
         $field = $form->newField();
         $field->setLegend($this->_paymentType->getName());
         $field->setInstructions("<p>Credit card details should be enterd directly at the cashnet website and then the transaction ID entered here.</p>");
         $element = $field->newElement('TextInput', 'transactionId');
         $element->setLabel('Transaction ID');
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         //we pass the amount back as a hidden element so PaymentPage will have it again
         $form->newHiddenElement('amount', $amount);
         $form->newButton('submit', 'Lookup Transaction');
     }
     return $form;
 }
Ejemplo n.º 2
0
 /**
  * The payment type and the amount are selected first
  * then we display the form for the payment type
  * @see StandardPage::makeForm()
  */
 protected function makeForm()
 {
     $allowedTypes = explode(',', $this->_applicationPage->getPage()->getVar('allowedPaymentTypes'));
     $allowedTypesCount = count($allowedTypes);
     $amounts = $this->_applicationPage->getPage()->getVar('amounts');
     if ($allowedTypesCount == 1 and $amounts == 1) {
         $paymentType = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findOneBy(array('id' => $allowedTypes[0], 'isExpired' => false));
         $form = $paymentType->getJazzeePaymentType($this->_controller)->paymentForm($this->_applicant, $this->_applicationPage->getPage()->getVar('amount1'));
         $form->setCSRFToken($this->_controller->getCSRFToken());
         $form->newHiddenElement('level', 2);
         $form->newHiddenElement('paymentType', $paymentType->getId());
         return $form;
     }
     $form = new \Foundation\Form();
     $form->setAction($this->_controller->getActionPath());
     $form->setCSRFToken($this->_controller->getCSRFToken());
     $field = $form->newField();
     $field->setLegend($this->_applicationPage->getTitle());
     $field->setInstructions($this->_applicationPage->getInstructions());
     if ($allowedTypesCount == 1 and !$this->_controller instanceof \Jazzee\AdminController) {
         $paymentType = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findOneBy(array('id' => $allowedTypes[0], 'isExpired' => false));
         $element = $field->newElement('Plaintext', 'paymentTypeName');
         $element->setLabel('Payment Method');
         $element->setValue($paymentType->getName());
         $form->newHiddenElement('paymentType', $paymentType->getId());
     } else {
         $element = $field->newElement('SelectList', 'paymentType');
         $element->setLabel('Payment Method');
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         $paymentTypes = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->findBy(array('isExpired' => false), array('name' => 'ASC'));
         foreach ($paymentTypes as $type) {
             if ($this->_controller instanceof \Jazzee\AdminController or in_array($type->getId(), $allowedTypes)) {
                 $element->newItem($type->getId(), $type->getName());
             }
         }
     }
     if ($amounts == 1) {
         $element = $field->newElement('Plaintext', 'amountText');
         $element->setLabel('Type of payment');
         $element->setValue($this->_applicationPage->getPage()->getVar('description1'));
         $form->newHiddenElement('amount', $this->_applicationPage->getPage()->getVar('amount1'));
     } else {
         $element = $field->newElement('RadioList', 'amount');
         $element->setLabel('Type of payment');
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         for ($i = 1; $i <= $amounts; $i++) {
             $element->newItem($this->_applicationPage->getPage()->getVar('amount' . $i), $this->_applicationPage->getPage()->getVar('description' . $i));
         }
         $element->setValue($this->_applicationPage->getPage()->getVar('amount1'));
     }
     $form->newHiddenElement('level', 1);
     $form->newButton('submit', 'Select');
     return $form;
 }
Ejemplo n.º 3
0
 public function testHiddenInput()
 {
     $form = new \Foundation\Form();
     $element = $form->newHiddenElement('hidden', 'hidden');
     $this->assertTrue($element instanceof \Foundation\Form\Element\HiddenInput);
     $this->assertContains($element, $form->getElements());
 }
Ejemplo n.º 4
0
 public function paymentForm(\Jazzee\Entity\Applicant $applicant, $amount)
 {
     $form = new \Foundation\Form();
     $form->setAction($this->_controller->getActionPath());
     $form->newHiddenElement('amount', $amount);
     $field = $form->newField();
     $field->setLegend($this->_paymentType->getName());
     $field = $form->newField();
     $instructions = "<p><strong>Application Fee:</strong> &#36;{$amount}</p>";
     $instructions .= '<p><strong>Make Checks Payable to:</strong> ' . $this->_paymentType->getVar('payable') . '</p>';
     if ($this->_paymentType->getVar('address')) {
         $instructions .= '<p><h4>Mail Check to:</h4>' . nl2br($this->_paymentType->getVar('address')) . '</p>';
     }
     if ($this->_paymentType->getVar('coupon')) {
         $instructions .= '<p><h4>Include the following information with your payment:</h4> ' . nl2br($this->_paymentType->getVar('coupon')) . '</p>';
     }
     $search = array('_Applicant_Name_', '_Applicant_ID_', '_Program_Name_', '_Program_ID_');
     $replace = array();
     $replace[] = $applicant->getFirstName() . ' ' . $applicant->getLastName();
     $replace[] = $applicant->getId();
     $replace[] = $applicant->getApplication()->getProgram()->getName();
     $replace[] = $applicant->getApplication()->getProgram()->getId();
     $instructions = str_ireplace($search, $replace, $instructions);
     $instructions .= '<p>Click the Pay By Check button to pay your fee by check.  Your account will be temporarily credited and you can complete your application.  Your application will not be reviewed until your check is recieved.</p>';
     $field->setInstructions($instructions);
     $form->newButton('submit', 'Pay By Check');
     return $form;
 }
Ejemplo n.º 5
0
 /**
  * Branching Page Form
  * Replaces the form with the correct branch
  * @param \Jazzee\Entity\Page $page
  */
 protected function branchingForm(\Jazzee\Entity\Page $page)
 {
     $form = new \Foundation\Form();
     $form->setAction($this->_controller->getActionPath());
     $field = $form->newField();
     $field->setLegend($this->_applicationPage->getTitle());
     $field->setInstructions($page->getInstructions());
     foreach ($page->getElements() as $element) {
         $element->getJazzeeElement()->setController($this->_controller);
         $element->getJazzeeElement()->addToField($field);
     }
     $form->newHiddenElement('level', 2);
     $form->newHiddenElement('branching', $page->getId());
     $form->newButton('submit', 'Save');
     $this->_form = $form;
 }
Ejemplo n.º 6
0
 public function paymentForm(\Jazzee\Entity\Applicant $applicant, $amount)
 {
     $form = new \Foundation\Form();
     $form->setAction($this->_controller->getActionPath());
     $form->newHiddenElement('amount', $amount);
     $field = $form->newField();
     $field->setLegend($this->_paymentType->getName());
     $element = $field->newElement('Textarea', 'justification');
     $element->setLabel('What is your reason for applying for a fee waiver?');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $element->addValidator(new \Foundation\Form\Validator\MaximumLength($element, 5000));
     $form->newButton('submit', 'Apply for Fee Waiver');
     return $form;
 }
Ejemplo n.º 7
0
 /**
  * Display a form which posts to authorize.net's server
  */
 public function paymentForm(\Jazzee\Entity\Applicant $applicant, $amount)
 {
     if (\is_a($this->_controller, 'ApplyPageController')) {
         $time = time();
         $fpSequence = $applicant->getId() . $time;
         $form = new \Foundation\Form();
         $form->newHiddenElement('x_amount', $amount);
         $form->newHiddenElement('x_test_request', $this->_controller->getConfig()->getStatus() == 'PRODUCTION' ? 0 : 1);
         $form->newHiddenElement('x_fp_sequence', $fpSequence);
         $form->newHiddenElement('x_fp_hash', \AuthorizeNetDPM::getFingerprint($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayKey'), $amount, $fpSequence, $time));
         $form->newHiddenElement('x_fp_timestamp', $time);
         $form->newHiddenElement('x_relay_response', "TRUE");
         $form->newHiddenElement('x_relay_url', $this->_controller->getServerPath() . $this->_controller->getActionPath() . '/../../../../../transaction/' . \urlencode(get_class($this)));
         $form->newHiddenElement('redirect_url', $this->_controller->getServerPath() . $this->_controller->getActionPath());
         $form->newHiddenElement('x_login', $this->_paymentType->getVar('gatewayId'));
         $form->newHiddenElement('x_cust_id', $applicant->getId());
         $form->newHiddenElement('x_customer_ip', $_SERVER['REMOTE_ADDR']);
         $form->newHiddenElement('x_email', $applicant->getEmail());
         $form->newHiddenElement('x_email_customer', 0);
         $form->newHiddenElement('x_description', $this->_paymentType->getVar('description'));
         $form->setAction($this->_paymentType->getVar('testAccount') ? \AuthorizeNetDPM::SANDBOX_URL : \AuthorizeNetDPM::LIVE_URL);
         $field = $form->newField();
         $field->setLegend($this->_paymentType->getName());
         $field->setInstructions("<p><strong>Application Fee:</strong> &#36;{$amount}</p>");
         $element = $field->newElement('TextInput', 'x_card_num');
         $element->setLabel('Credit Card Number');
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         $element = $field->newElement('TextInput', 'x_exp_date');
         $element->setLabel('Expiration Date');
         $element->setFormat('mm/yy eg ' . date('m/y'));
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         $element = $field->newElement('TextInput', 'x_card_code');
         $element->setLabel('CCV');
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         $element = $field->newElement('TextInput', 'x_zip');
         $element->setLabel('Billing Postal Code');
         $element->setInstructions('US Credit Cards which do not provide a postal code will be rejected.');
         $form->newButton('submit', 'Pay with Credit Card');
     } else {
         $form = parent::paymentForm($applicant, $amount);
     }
     return $form;
 }
Ejemplo n.º 8
0
 /**
  * Create a form to choose a school
  * @param array $choices
  */
 protected function pickSchoolForm($choices)
 {
     $form = new \Foundation\Form();
     $field = $form->newField();
     $field->setLegend($this->_applicationPage->getTitle());
     $field->setInstructions($this->_applicationPage->getInstructions());
     $element = $field->newElement('RadioList', 'pickSchoolId');
     $element->setLabel('Choose School');
     $element->newItem(null, 'Enter a new School');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     asort($choices);
     foreach ($choices as $id => $value) {
         $element->newItem($id, $value);
     }
     $form->newHiddenElement('level', 'pick');
     $form->newButton('submit', 'Next');
     $this->_form = $form;
 }
Ejemplo n.º 9
0
 /**
  * Display a form which posts to authorize.net's server
  */
 public function paymentForm(\Jazzee\Entity\Applicant $applicant, $amount)
 {
     if (\is_a($this->_controller, 'ApplyPageController')) {
         $time = time();
         $fpSequence = $applicant->getId() . $time;
         $form = new \Foundation\Form();
         $form->newHiddenElement('x_show_form', 'PAYMENT_FORM');
         $form->newHiddenElement('x_amount', $amount);
         $form->newHiddenElement('x_test_request', $this->_controller->getConfig()->getStatus() == 'PRODUCTION' ? 0 : 1);
         $form->newHiddenElement('x_fp_sequence', $fpSequence);
         $form->newHiddenElement('x_fp_hash', \AuthorizeNetSIM_Form::getFingerprint($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayKey'), $amount, $fpSequence, $time));
         $form->newHiddenElement('x_fp_timestamp', $time);
         $form->newHiddenElement('x_relay_response', "TRUE");
         $form->newHiddenElement('x_relay_url', $this->_controller->getServerPath() . $this->_controller->getActionPath() . '/../../../../../transaction/' . \urlencode(get_class($this)));
         $form->newHiddenElement('x_cancel_url', $this->_controller->getServerPath() . $this->_controller->getActionPath());
         $form->newHiddenElement('redirect_url', $this->_controller->getServerPath() . $this->_controller->getActionPath());
         $form->newHiddenElement('x_login', $this->_paymentType->getVar('gatewayId'));
         $form->newHiddenElement('x_cust_id', $applicant->getId());
         $form->newHiddenElement('x_customer_ip', $_SERVER['REMOTE_ADDR']);
         $form->newHiddenElement('x_email', $applicant->getEmail());
         $form->newHiddenElement('x_email_customer', 0);
         $form->newHiddenElement('x_description', $this->_paymentType->getVar('description'));
         $form->setAction($this->_paymentType->getVar('testAccount') ? \AuthorizeNetDPM::SANDBOX_URL : \AuthorizeNetDPM::LIVE_URL);
         $field = $form->newField();
         $field->setLegend($this->_paymentType->getName());
         $field->setInstructions("<p>Clicking the 'Pay with Credit Card' button will redirect you to a secure payment page.  Once you have completed your transaction you will be returned to the application.<strong>Application Fee:</strong> &#36;{$amount}</p>");
         $form->newButton('submit', 'Pay with Credit Card');
     } else {
         $form = parent::paymentForm($applicant, $amount);
     }
     return $form;
 }
Ejemplo n.º 10
0
 /**
  * Record the reason the payment was refunded
  * @see ApplyPaymentInterface::rejectPaymentForm()
  */
 public function getRefundPaymentForm(\Jazzee\Entity\Payment $payment)
 {
     $transactionDetails = new \AuthorizeNetTD($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayKey'));
     $transactionDetails->setSandBox($this->_paymentType->getVar('testAccount'));
     //test accounts get sent to the sandbox
     // Get Transaction Details
     $transactionId = $payment->getVar('transactionId');
     $response = $transactionDetails->getTransactionDetails($transactionId);
     if ($response->isError()) {
         throw new \Jazzee\Exception('Unable to get transaction details for payment #' . $payment->getId() . " transcation id {$transactionId}.  Authorize.net said " . $response->getMessageText(), E_ERROR, 'There was a problem getting payment information.');
     }
     $submitted = new \DateTime($response->xml->transaction->submitTimeLocal);
     if ($submitted->diff(new \DateTime())->days > 120) {
         throw new \Jazzee\Exception('Cannot refund payment, it is too old. Payment ID #' . $payment->getId() . " transcation id {$transactionId}.", E_ERROR, 'Payment is too old to refund.');
     }
     $form = new \Foundation\Form();
     $field = $form->newField();
     $field->setLegend('Refund Payment');
     $element = $field->newElement('Plaintext', 'details');
     $element->setLabel('Details');
     $element->setValue('Refund $' . $payment->getAmount() . ' to card ' . $response->xml->transaction->payment->creditCard->cardNumber);
     $element = $field->newElement('Textarea', 'refundedReason');
     $element->setLabel('Reason displayed to Applicant');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $form->newHiddenElement('cardNumber', substr($response->xml->transaction->payment->creditCard->cardNumber, strlen($response->xml->transaction->payment->creditCard->cardNumber) - 4, 4));
     $form->newHiddenElement('zip', (string) $response->xml->transaction->billTo->zip);
     $form->newButton('submit', 'Save');
     return $form;
 }
Ejemplo n.º 11
0
 /**
  * Find Possible gre score matches
  * @param integer $answerID
  * @param array $postData
  */
 public function do_searchScores($postData)
 {
     $this->checkIsAdmin();
     $searchForm = new \Foundation\Form();
     $field = $searchForm->newField();
     $field->setLegend('Search Scores');
     $element = $field->newElement('TextInput', 'firstName');
     $element->setLabel('First Name');
     $element->setValue($this->_applicant->getFirstName());
     $element = $field->newElement('TextInput', 'lastName');
     $element->setLabel('Last Name');
     $element->setValue($this->_applicant->getLastName());
     $searchForm->newHiddenElement('level', 'search');
     $searchForm->newButton('submit', 'Search Scores');
     $matchForm = new \Foundation\Form();
     $field = $matchForm->newField();
     $field->setLegend('Select scores to match');
     $greElement = $field->newElement('CheckboxList', 'greMatches');
     $greElement->setLabel('Possible GRE');
     $toeflElement = $field->newElement('CheckboxList', 'toeflMatches');
     $toeflElement->setLabel('Possible TOEFL');
     $matchForm->newHiddenElement('level', 'match');
     $matchForm->newButton('submit', 'Match Scores');
     $form = $searchForm;
     if (!empty($postData)) {
         if ($postData['level'] == 'search') {
             if ($input = $searchForm->processInput($postData)) {
                 $matchForm->newHiddenElement('firstName', $input->get('firstName'));
                 $matchForm->newHiddenElement('lastName', $input->get('lastName'));
                 $existingScores = array();
                 foreach ($this->getAnswers() as $answer) {
                     $date = strtotime($this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_DATE)->getJazzeeElement()->displayValue($answer));
                     $uniqueId = $this->_applicationPage->getPage()->getElementByFixedId(self::FID_REGISTRATION_NUMBER)->getJazzeeElement()->displayValue($answer) . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_TYPE)->getJazzeeElement()->displayValue($answer) . date('m', $date) . date('Y', $date);
                     $existingScores[$uniqueId] = $answer;
                 }
                 foreach ($this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\GREScore')->findByName($input->get('firstName') . '%', $input->get('lastName') . '%') as $score) {
                     $uniqueId = $score->getRegistrationNumber() . 'GRE/GRE Subject' . $score->getTestDate()->format('m') . $score->getTestDate()->format('Y');
                     if (!array_key_exists($uniqueId, $existingScores)) {
                         $greElement->newItem($score->getId(), $score->getLastName() . ',  ' . $score->getFirstName() . ' ' . $score->getMiddleInitial() . ' ' . $score->getTestDate()->format('m/d/Y'));
                     } else {
                         if (!$existingScores[$uniqueId]->getGREScore()) {
                             $greElement->addMessage('The system found at least one match for a GRE score the applicant had previously entered.  You may need to refresh this page to view that match.');
                             $this->matchScore($existingScores[$uniqueId]);
                         }
                     }
                 }
                 foreach ($this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\TOEFLScore')->findByName($input->get('firstName') . '%', $input->get('lastName') . '%') as $score) {
                     $uniqueId = $score->getRegistrationNumber() . 'TOEFL' . $score->getTestDate()->format('m') . $score->getTestDate()->format('Y');
                     if (!array_key_exists($uniqueId, $existingScores)) {
                         $toeflElement->newItem($score->getId(), $score->getLastName() . ',  ' . $score->getFirstName() . ' ' . $score->getMiddleName() . ' ' . $score->getTestDate()->format('m/d/Y'));
                     } else {
                         if (!$existingScores[$uniqueId]->getTOEFLScore()) {
                             $toeflElement->addMessage('The system found at least one match for a TOEFL score the applicant had previously entered.  You may need to refresh this page to view that match.');
                             $this->matchScore($existingScores[$uniqueId]);
                         }
                     }
                 }
                 $form = $matchForm;
             }
         } else {
             if ($postData['level'] == 'match') {
                 $form = $matchForm;
                 //Re add all the matches to the elements so they will validate
                 foreach ($this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\GREScore')->findByName($postData['firstName'] . '%', $postData['lastName'] . '%') as $score) {
                     $greElement->newItem($score->getId(), $score->getLastName() . ',  ' . $score->getFirstName() . ' ' . $score->getMiddleInitial() . ' ' . $score->getTestDate()->format('m/d/Y'));
                 }
                 foreach ($this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\TOEFLScore')->findByName($postData['firstName'] . '%', $postData['lastName'] . '%') as $score) {
                     $toeflElement->newItem($score->getId(), $score->getLastName() . ',  ' . $score->getFirstName() . ' ' . $score->getMiddleName() . ' ' . $score->getTestDate()->format('m/d/Y'));
                 }
                 if ($input = $matchForm->processInput($postData)) {
                     //create a blank for so it can get values from parent::newAnswer
                     $this->_form = new \Foundation\Form();
                     if ($input->get('greMatches')) {
                         foreach ($input->get('greMatches') as $scoreId) {
                             $score = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\GREScore')->find($scoreId);
                             $arr = array('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_REGISTRATION_NUMBER)->getId() => $score->getRegistrationNumber(), 'el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_DATE)->getId() => $score->getTestDate()->format('c'), 'el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_TYPE)->getId() => $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_TYPE)->getItemByValue('GRE/GRE Subject')->getId());
                             $newInput = new \Foundation\Form\Input($arr);
                             $this->newAnswer($newInput);
                         }
                     }
                     if ($input->get('toeflMatches')) {
                         foreach ($input->get('toeflMatches') as $scoreId) {
                             $score = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\TOEFLScore')->find($scoreId);
                             $arr = array('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_REGISTRATION_NUMBER)->getId() => $score->getRegistrationNumber(), 'el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_DATE)->getId() => $score->getTestDate()->format('c'), 'el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_TYPE)->getId() => $this->_applicationPage->getPage()->getElementByFixedId(self::FID_TEST_TYPE)->getItemByValue('TOEFL')->getId());
                             $newInput = new \Foundation\Form\Input($arr);
                             $this->newAnswer($newInput);
                         }
                     }
                     $this->_controller->setLayoutVar('status', 'success');
                 }
             }
         }
     }
     return $form;
 }
Ejemplo n.º 12
0
 /**
  * SIR Form
  */
 public function actionSir()
 {
     if ($this->_applicant->getDecision()->status() != 'finalAdmit') {
         throw new \Jazzee\Exception("Applicant #{$this->_applicant->getId()} tried to access SIR but is not in the status finalAdmit", E_USER_NOTICE, 'You do not have access to this page.');
     }
     $sirAcceptPage = false;
     if ($pages = $this->_application->getApplicationPages(\Jazzee\Entity\ApplicationPage::SIR_ACCEPT)) {
         $sirAcceptPage = $pages[0];
         $sirAcceptPage->getJazzeePage()->setApplicant($this->_applicant);
         $sirAcceptPage->getJazzeePage()->setController($this);
     }
     $sirDeclinePage = false;
     if ($pages = $this->_application->getApplicationPages(\Jazzee\Entity\ApplicationPage::SIR_DECLINE)) {
         $sirDeclinePage = $pages[0];
         $sirDeclinePage->getJazzeePage()->setApplicant($this->_applicant);
         $sirDeclinePage->getJazzeePage()->setController($this);
     }
     $this->setVar('sirAcceptPage', $sirAcceptPage);
     $this->setVar('sirDeclinePage', $sirDeclinePage);
     $this->setVar('actionPath', $this->applyPath('status/sir'));
     $form = new \Foundation\Form();
     $form->setAction($this->applyPath('status/sir'));
     $field = $form->newField();
     $field->setLegend('Confirm Enrolment');
     $field->setInstructions('You must confirm your enrollment by <strong><em>' . $this->_applicant->getDecision()->getOfferResponseDeadline()->format('l F jS Y g:ia') . '</em></strong>. If you do not confirm your enrollment your space may be released to another applicant.');
     $element = $field->newElement('RadioList', 'confirm');
     $element->setLabel('Do you intend to register for the term in which you applied?');
     $element->newItem(0, 'No');
     $element->newItem(1, 'Yes');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $buttonText = ($sirAcceptPage or $sirDeclinePage) ? 'Next' : 'Save';
     $form->newButton('submit', $buttonText);
     $form->newHiddenElement('sirLevel', '1');
     $this->setVar('form', $form);
     if ($this->post) {
         if (isset($this->post['sirLevel']) and $this->post['sirLevel'] == 1 and $input = $form->processInput($this->post)) {
             $this->setVar('confirm', $input->get('confirm'));
             if ($input->get('confirm') == 1 and !$sirAcceptPage) {
                 $this->acceptApplicant();
             } else {
                 if ($input->get('confirm') == 0 and !$sirDeclinePage) {
                     $this->declineApplicant();
                 }
             }
         } else {
             if (isset($this->post['confirm'])) {
                 if ($this->post['confirm'] == 0) {
                     $this->setVar('confirm', 0);
                     if ($input = $sirDeclinePage->getJazzeePage()->validateInput($this->post)) {
                         $sirDeclinePage->getJazzeePage()->newAnswer($input);
                         $this->declineApplicant();
                     }
                 }
                 if ($this->post['confirm'] == 1) {
                     $this->setVar('confirm', 1);
                     if ($input = $sirAcceptPage->getJazzeePage()->validateInput($this->post)) {
                         $sirAcceptPage->getJazzeePage()->newAnswer($input);
                         $this->acceptApplicant();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Validate an address with QAS
  * @param array $postData
  * @param \Foundation\Form $countryForm
  * @return \Foundation\Form\Input | false
  */
 protected function validateAddress(array $postData, \Foundation\Form $countryForm)
 {
     $countryName = $countryForm->getElementByName('countryName')->getValue();
     $country = $countryForm->getElementByName('country')->getValue();
     $countriesToValidate = explode(',', $this->_applicationPage->getPage()->getVar('validatedCountries'));
     //Create the QuickAddress Object and set the engine and picklist type
     $qas = new \QuickAddress($this->_applicationPage->getPage()->getVar('wsdlAddress'));
     $qas->setEngineType(QAS_VERIFICATION_ENGINE);
     $qas->setFlatten(true);
     $qasCountryCode = $this->getQASCodeForCountry($countryName);
     $qasLayout = "Database layout";
     switch ($postData['type']) {
         case 'confirmAddress':
             if ($postData['addressChoice'] == 'validated') {
                 return unserialize(base64_decode($postData['validatedInput']));
             } else {
                 if ($postData['addressChoice'] == 'original') {
                     return unserialize(base64_decode($postData['originalInput']));
                 } else {
                     $input = unserialize(base64_decode($postData['originalInput']));
                     foreach ($countryForm->getElements() as $formElement) {
                         if ($input->checkIsSet($formElement->getName())) {
                             $formElement->setValue($input->get($formElement->getName()));
                         }
                     }
                     $this->_form = $countryForm;
                     return false;
                 }
             }
             break;
         case 'validate':
             if (!($input = $countryForm->processInput($postData))) {
                 $this->_form = $countryForm;
                 return false;
             }
             //Check to see if this is the second time the user has input this address,
             //if it is then just use that as the address unverified
             $sameUserInput = false;
             if ($str = $input->get('originalInput')) {
                 $str = base64_decode($str);
                 $originalInput = unserialize($str);
                 $sameUserInput = true;
                 foreach (array('address1', 'address2', 'address3', 'city', 'state', 'postalCode', 'country') as $name) {
                     if ($originalInput->get($name) != $input->get($name)) {
                         $sameUserInput = false;
                         break;
                     }
                 }
             }
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS1)->getId(), $input->get('address1'));
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS2)->getId(), $input->get('address2'));
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS3)->getId(), $input->get('address3'));
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_CITY)->getId(), $input->get('city'));
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_STATE)->getId(), $input->get('state'));
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_POSTALCODE)->getId(), $input->get('postalCode'));
             $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_COUNTRY)->getId(), $countryName);
             if ($sameUserInput or !in_array($this->getQASCodeForCountry($countryName), $countriesToValidate) or !$qas->canSearch($qasCountryCode, $qasLayout)->IsOk) {
                 return $input;
             }
             $search = array();
             $search[0] = $input->get('address1');
             $search[1] = $input->get('address2');
             $search[2] = $input->get('city');
             $search[3] = $input->get('state');
             $search[4] = $input->get('postalCode');
             //Perform the search itself
             $result = $qas->search($qasCountryCode, $search, QAS_DEFAULT_PROMPT, $qasLayout);
             switch ($result->sVerifyLevel) {
                 case 'Verified':
                 case 'InteractionRequired':
                     $originalInput = clone $input;
                     $arr = $result->address->atAddressLines;
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS1)->getId(), $arr[0]->Line);
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS2)->getId(), $arr[1]->Line);
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS3)->getId(), $input->get('address3'));
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_CITY)->getId(), $arr[3]->Line);
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_STATE)->getId(), $arr[4]->Line);
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_POSTALCODE)->getId(), $arr[5]->Line);
                     $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_COUNTRY)->getId(), $countryName);
                     $validatedInput = clone $input;
                     $confirmationForm = new \Foundation\Form();
                     $confirmationForm->setAction($countryForm->getAction());
                     $confirmationForm->setCSRFToken($this->_controller->getCSRFToken());
                     $field = $confirmationForm->newField();
                     $field->setLegend('Confirm Address');
                     $element = $field->newElement('RadioList', 'addressChoice');
                     $element->setLabel('Confirm Address');
                     $element->newItem('validated', 'Use Our Sugested Address <br />' . $this->formatAddressFromInput($validatedInput));
                     $element->newItem('original', 'Use Address as Entered<br />' . $this->formatAddressFromInput($originalInput));
                     $element->newItem('edit', 'Edit the Address you Entered');
                     $element->setValue('validated');
                     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
                     $confirmationForm->newHiddenElement('type', 'confirmAddress');
                     $confirmationForm->newHiddenElement('countryName', $countryName);
                     $confirmationForm->newHiddenElement('country', $country);
                     $confirmationForm->newHiddenElement('originalInput', base64_encode(serialize($originalInput)));
                     $confirmationForm->newHiddenElement('validatedInput', base64_encode(serialize($validatedInput)));
                     $confirmationForm->newButton('submit', 'Save');
                     $this->_form = $confirmationForm;
                     return false;
                     break;
                 case 'Multiple':
                     $this->_controller->addMessage('error', 'We were unable to validate your address.');
                     $this->_controller->setVar('confirm', true);
                     $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered');
                     $this->_controller->setVar('originalInput', base64_encode(serialize($input)));
                     $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input)));
                     $this->_controller->setVar('picklist', $result->picklist);
                     $this->_form = $countryForm;
                     break;
                 case 'StreetPartial':
                 case 'PremisesPartial':
                     $this->_controller->addMessage('error', 'We were unable to validate your address.  If you are sure this address is correct then click the "Confirm Address as Entered" button.');
                     $countryForm->getElementByName('address1')->addMessage('Your address is incomplete');
                     $countryForm->getElementByName('address2')->addMessage('Your address is incomplete');
                     $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered');
                     $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input)));
                     $this->_form = $countryForm;
                     break;
                 case 'None':
                     $this->_controller->addMessage('error', 'We were unable to validate your address.');
                     $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered');
                     $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input)));
                     $this->_form = $countryForm;
                     break;
                 default:
                     throw new \Jazzee\Exception("{$result->sVerifyLevel} is not a known QAS address verification type.", E_USER_ERROR, 'There was a problem verifying your address.  Please try entering it again.');
             }
             break;
     }
     return false;
 }