PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter6.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 270 lines | 182 code | 45 blank | 43 comment | 51 complexity | 447fa9652fe8886870ec05bf86dfff9b MD5 | raw file
  1. <?php
  2. class PayflowProGateway_Form_TwoColumnLetter6 extends PayflowProGateway_Form_OneStepTwoColumn {
  3. public function __construct( &$form_data, &$form_errors ) {
  4. global $wgScriptPath;
  5. // set the path to css, before the parent constructor is called, checking to make sure some child class hasn't already set this
  6. if ( !strlen( $this->getStylePath() ) ) {
  7. $this->setStylePath( $wgScriptPath . '/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoColumnLetter6.css' );
  8. }
  9. parent::__construct( $form_data, $form_errors );
  10. }
  11. public function generateFormStart() {
  12. global $wgOut, $wgRequest;
  13. $form = parent::generateBannerHeader();
  14. $form .= Xml::openElement( 'table', array( 'width' => '100%', 'cellspacing' => 0, 'cellpadding' => 0, 'border' => 0 ) );
  15. $form .= Xml::openElement( 'tr' );
  16. $form .= Xml::openElement( 'td', array( 'id' => 'appeal', 'valign' => 'top' ) );
  17. $text_template = $wgRequest->getText( 'text_template', '2010/JimmyAppealLong' );
  18. // if the user has uselang set, honor that, otherwise default to the language set for the form defined by 'language' in the query string
  19. if ( $wgRequest->getText( 'language' ) ) $text_template .= '/' . $this->form_data[ 'language' ];
  20. $template = ( strlen( $text_template ) ) ? $wgOut->parse( '{{' . $text_template . '}}' ) : '';
  21. // if the template doesn't exist, prevent the display of the red link
  22. if ( preg_match( '/redlink\=1/', $template ) ) $template = NULL;
  23. $form .= $template;
  24. $form .= Xml::closeElement( 'td' );
  25. $form .= Xml::openElement( 'td', array( 'id' => 'donate', 'valign' => 'top' ) );
  26. // add noscript tags for javascript disabled browsers
  27. $form .= $this->getNoScript();
  28. $form .= Xml::tags( 'h2', array( 'id' => 'donate-head' ), wfMsg( 'payflowpro_gateway-make-your-donation' ));
  29. // provide a place at the top of the form for displaying general messages
  30. if ( $this->form_errors['general'] ) {
  31. $form .= Xml::openElement( 'div', array( 'id' => 'mw-payflow-general-error' ) );
  32. if ( is_array( $this->form_errors['general'] ) ) {
  33. foreach ( $this->form_errors['general'] as $this->form_errors_msg ) {
  34. $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
  35. }
  36. } else {
  37. $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
  38. }
  39. $form .= Xml::closeElement( 'div' ); // close div#mw-payflow-general-error
  40. }
  41. // Xml::element seems to convert html to htmlentities
  42. $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>";
  43. $form .= Xml::openElement( 'form', array( 'name' => 'payment', 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => 'return formCheck(this)', 'autocomplete' => 'off' ) );
  44. $form .= $this->generateBillingContainer();
  45. return $form;
  46. }
  47. public function generateFormEnd() {
  48. $form = '';
  49. $form .= $this->generateFormClose();
  50. return $form;
  51. }
  52. protected function generateBillingContainer() {
  53. $form = '';
  54. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-personal-info' ) );
  55. $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-donor' ) );
  56. $form .= $this->generateBillingFields();
  57. $form .= Xml::closeElement( 'table' ); // close table#payflow-table-donor
  58. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-personal-info
  59. return $form;
  60. }
  61. protected function generateBillingFields() {
  62. global $wgScriptPath, $wgPayflowGatewayPaypalURL, $wgRequest;
  63. $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
  64. $form = '';
  65. /*
  66. $form .= '<tr>';
  67. $form .= '<td style="text-align:center;" colspan="2"><big><b>' . wfMsg( 'payflowpro_gateway-paypal-button' ) . '</b></big><br/><a href="#" onclick="document.payment.PaypalRedirect.value=1;document.payment.submit();"><img src="' . $scriptPath . '/paypal.png"/></a></td>';
  68. $form .= '</tr>';
  69. */
  70. // amount
  71. $otherChecked = false;
  72. $amount = -1;
  73. if ( $this->form_data['amount'] != 100 && $this->form_data['amount'] != 50 && $this->form_data['amount'] != 35 && $this->form_data['amount'] != 20 && $this->form_data['amountOther'] > 0 ) {
  74. $otherChecked = true;
  75. $amount = $this->form_data['amountOther'];
  76. }
  77. $form .= '<tr>';
  78. $form .= '<td colspan="2"><span class="creditcard-error-msg">' . $this->form_errors['invalidamount'] . '</span></td>';
  79. $form .= '</tr>';
  80. $form .= '<tr>';
  81. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-amount' ), 'amount' ) . '</td>';
  82. $form .= '<td>' . Xml::radio( 'amount', 100, $this->form_data['amount'] == 100, array( 'onfocus' => 'clearField2( document.getElementById(\'amountOther\'), "Other" )' ) ) . '100 ' .
  83. Xml::radio( 'amount', 50, $this->form_data['amount'] == 50, array( 'onfocus' => 'clearField2( document.getElementById(\'amountOther\'), "Other" )' ) ) . '50 ' .
  84. Xml::radio( 'amount', 35, $this->form_data['amount'] == 35, array( 'onfocus' => 'clearField2( document.getElementById(\'amountOther\'), "Other" )' ) ) . '35 ' .
  85. Xml::radio( 'amount', 20, $this->form_data['amount'] == 20, array( 'onfocus' => 'clearField2( document.getElementById(\'amountOther\'), "Other" )' ) ) . '20 ' .
  86. '</td>';
  87. $form .= '</tr>';
  88. $form .= '<tr>';
  89. $form .= '<td class="label"></td>';
  90. $form .= '<td>' . Xml::radio( 'amount', $amount, $otherChecked, array( 'id' => 'otherRadio' ) ) . Xml::input( 'amountOther', '7', $this->form_data['amountOther'], array( 'type' => 'text', 'onfocus' => 'clearField(this, "Other");document.getElementById("otherRadio").checked=true;', 'maxlength' => '10', 'onblur' => 'document.getElementById("otherRadio").value = this.value;', 'id' => 'amountOther' ) ) .
  91. ' ' . $this->generateCurrencyDropdown() . '</td>';
  92. $form .= '</tr>';
  93. // email opt-in
  94. $email_opt_value = ( $wgRequest->wasPosted() ) ? $this->form_data[ 'email-opt' ] : true;
  95. $form .= '<tr>';
  96. $form .= '<td class="label"> </td>';
  97. $form .= '<td class="check-option">' . Xml::check( 'email-opt', $email_opt_value );
  98. $form .= ' ';
  99. // put the label inside Xml::openElement so any HTML in the msg might get rendered (right, Germany?)
  100. $form .= Xml::openElement( 'label', array( 'for' => 'email-opt' ) );
  101. $form .= wfMsg( 'donate_interface-email-agreement' );
  102. $form .= Xml::closeElement( 'label' );
  103. $form .= '</td>';
  104. $form .= '</tr>';
  105. $form .= '<tr>';
  106. $form .= '<td class="label">' . wfMsg( 'payflowpro_gateway-payment-type' ) . '</td>';
  107. $form .= '<td>' .
  108. Xml::radio( 'card', 'cc1', $this->form_data['card'] == 'cc1', array( 'id' => 'cc1radio', 'onclick' => 'switchToCreditCard()' ) ) . '<label for="cc1radio">' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/card-visa.png" ) ). '</label>' .
  109. Xml::radio( 'card', 'cc2', $this->form_data['card'] == 'cc2', array( 'id' => 'cc2radio', 'onclick' => 'switchToCreditCard()' ) ) . '<label for="cc2radio">' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/card-mastercard.png" ) ). '</label>' .
  110. Xml::radio( 'card', 'cc3', $this->form_data['card'] == 'cc3', array( 'id' => 'cc3radio', 'onclick' => 'switchToCreditCard()' ) ) . '<label for="cc3radio">' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/card-amex.png" ) ). '</label>' .
  111. Xml::radio( 'card', 'cc4', $this->form_data['card'] == 'cc4', array( 'id' => 'cc4radio', 'onclick' => 'switchToCreditCard()' ) ) . '<label for="cc4radio">' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/card-discover.png" ) ). '</label>' .
  112. Xml::radio( 'card', 'pp', $this->form_data['card'] == 'pp', array( 'id' => 'ppradio', 'onclick' => 'switchToPayPal()' ) ) . '<label for="ppradio">' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/card-paypal.png" ) ) . '</label>' .
  113. '</td>';
  114. $form .= '</tr>';
  115. $form .= '</table>';
  116. if ( $this->form_data['card'] == 'cc1' || $this->form_data['card'] == 'cc2' || $this->form_data['card'] == 'cc3' || $this->form_data['card'] == 'cc4' ) {
  117. $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-cc' ) );
  118. } else {
  119. $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-cc', 'style' => 'display: none;' ) );
  120. }
  121. // name
  122. $form .= $this->getNameField();
  123. // email
  124. $form .= $this->getEmailField();
  125. $form .= '<tr>';
  126. $form .= '<td colspan=2><span class="creditcard-error-msg"> </span></td>';
  127. $form .= '</tr>';
  128. // card number
  129. $form .= $this->getCardNumberField();
  130. // cvv
  131. $form .= $this->getCvvField();
  132. // expiry
  133. $form .= $this->getExpiryField();
  134. // street
  135. $form .= $this->getStreetField();
  136. // city
  137. $form .= $this->getCityField();
  138. // state
  139. $form .= $this->getStateField();
  140. // zip
  141. $form .= '<tr>';
  142. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['zip'] . '</span></td>';
  143. $form .= '</tr>';
  144. $form .= '<tr>';
  145. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-postal' ), 'zip' ) . '</td>';
  146. $form .= '<td>' . Xml::input( 'zip', '15', $this->form_data['zip'], array( 'type' => 'text', 'maxlength' => '15', 'id' => 'zip' ) ) .
  147. '</td>';
  148. $form .= '</tr>';
  149. // country
  150. $form .= $this->getCountryField();
  151. /*
  152. $comment_opt_value = ( $wgRequest->wasPosted() ) ? $this->form_data[ 'comment-option' ] : true;
  153. $form .= '<tr>';
  154. $form .= '<td class="check-option" colspan="2">' . Xml::check( 'comment-option', $comment_opt_value );
  155. $form .= ' ' . Xml::label( wfMsg( 'payflowpro_gateway-anon-message' ), 'comment-option' ) . '</td>';
  156. $form .= '</tr>';
  157. $form .= $this->getEmailOptField();
  158. */
  159. return $form;
  160. }
  161. public function generateFormSubmit() {
  162. // cc submit button
  163. if ( $this->form_data['card'] == 'cc1' || $this->form_data['card'] == 'cc2' || $this->form_data['card'] == 'cc3' || $this->form_data['card'] == 'cc4' ) {
  164. $form = Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit' ) );
  165. } else {
  166. $form = Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit', 'style' => 'display: none;' ) );
  167. }
  168. $form .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' ) );
  169. $form .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'payflowpro_gateway-donor-submit' ), 'onclick' => 'document.payment.PaypalRedirect.value=0;return true;', 'type' => 'submit' ) );
  170. $form .= Xml::closeElement( 'div' ); // close div#mw-donate-submit-button
  171. $form .= Xml::openElement( 'div', array( 'class' => 'mw-donate-submessage', 'id' => 'payflowpro_gateway-donate-submessage' ) ) .
  172. wfMsg( 'payflowpro_gateway-donate-click' );
  173. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-submessage
  174. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-form-submit
  175. // paypal submit button
  176. if ( $this->form_data['card'] == 'cc1' || $this->form_data['card'] == 'cc2' || $this->form_data['card'] == 'cc3' || $this->form_data['card'] == 'cc4' ) {
  177. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit-paypal', 'style' => 'display: none;' ) );
  178. } else {
  179. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit-paypal' ) );
  180. }
  181. $form .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' ) );
  182. $form .= Html::hidden( 'PaypalRedirect', 0 );
  183. $form .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'payflowpro_gateway-donor-submit' ), 'onclick' => 'document.payment.PaypalRedirect.value=1;return true;', 'type' => 'submit' ) );
  184. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-submessage
  185. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-form-submit
  186. return $form;
  187. }
  188. /**
  189. * Generate form closing elements
  190. */
  191. public function generateFormClose() {
  192. $form = '';
  193. // add hidden fields
  194. $hidden_fields = $this->getHiddenFields();
  195. foreach ( $hidden_fields as $field => $value ) {
  196. $form .= Html::hidden( $field, $value );
  197. }
  198. $form .= Xml::closeElement( 'form' ); // close form 'payment'
  199. $form .= $this->generateDonationFooter();
  200. $form .= Xml::closeElement( 'td' );
  201. $form .= Xml::closeElement( 'tr' );
  202. $form .= Xml::closeElement( 'table' );
  203. return $form;
  204. }
  205. /**
  206. * Generates the donation footer ("There are other ways to give...")
  207. * @returns string of HTML
  208. */
  209. public function generateDonationFooter() {
  210. global $wgScriptPath;
  211. $form = '';
  212. $form .= Xml::openElement( 'div', array( 'class' => 'payflow-cc-form-section', 'id' => 'payflowpro_gateway-donate-addl-info' ) );
  213. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-donate-addl-info-secure-logos' ) );
  214. $form .= Xml::tags( 'p', array( 'class' => '' ), Xml::openElement( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/rapidssl_ssl_certificate-nonanimated.png" ) ) );
  215. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-addl-info-secure-logos
  216. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-donate-addl-info-text' ) );
  217. $form .= Xml::tags( 'p', array( 'class' => '' ), wfMsg( 'payflowpro_gateway-otherways-short' ) );
  218. $form .= Xml::tags( 'p', array( 'class' => '' ), wfMsg( 'payflowpro_gateway-credit-storage-processing' ) );
  219. $form .= Xml::tags( 'p', array( 'class' => '' ), wfMsg( 'payflowpro_gateway-question-comment' ) );
  220. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-addl-info-text
  221. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-addl-info
  222. return $form;
  223. }
  224. }