PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/extensions/DonationInterface/payflowpro_gateway/forms/TwoStepTwoColumnPremiumUS.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 363 lines | 293 code | 49 blank | 21 comment | 42 complexity | ecfcc7e4816a4bd31cf399f3316a9f6d MD5 | raw file
  1. <?php
  2. class PayflowProGateway_Form_TwoStepTwoColumnPremiumUS extends PayflowProGateway_Form_TwoStepTwoColumn {
  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/TwoStepTwoColumnPremiumUS.css' );
  8. }
  9. parent::__construct( $form_data, $form_errors );
  10. }
  11. public function loadPlaceholders() {
  12. global $wgOut;
  13. // form placeholder values
  14. $first = wfMsg( 'payflowpro_gateway-donor-fname' );
  15. $last = wfMsg( 'payflowpro_gateway-donor-lname' );
  16. $street = wfMsg( 'payflowpro_gateway-donor-street' );
  17. $city = wfMsg( 'payflowpro_gateway-donor-city' );
  18. $zip = wfMsg( 'payflowpro_gateway-zip-code' );
  19. $email = wfMsg( 'payflowpro_gateway-donor-email' );
  20. $js = <<<EOT
  21. <script type="text/javascript">
  22. function loadPlaceholders() {
  23. var fname = document.getElementById('fname');
  24. var lname = document.getElementById('lname');
  25. var street = document.getElementById('street');
  26. var city = document.getElementById('city');
  27. var zip = document.getElementById('zip');
  28. var email = document.getElementById('emailAdd');
  29. if (fname.value == '') {
  30. fname.style.color = '#999999';
  31. fname.value = '$first';
  32. }
  33. if (lname.value == '') {
  34. lname.style.color = '#999999';
  35. lname.value = '$last';
  36. }
  37. if (street.value == '') {
  38. street.style.color = '#999999';
  39. street.value = '$street';
  40. }
  41. if (city.value == '') {
  42. city.style.color = '#999999';
  43. city.value = '$city';
  44. }
  45. if (zip.value == '') {
  46. zip.style.color = '#999999';
  47. zip.value = '$zip';
  48. }
  49. if (email.value == '') {
  50. email.style.color = '#999999';
  51. email.value = '$email';
  52. }
  53. }
  54. addEvent( window, 'load', loadPlaceholders );
  55. function formCheck( ccform ) {
  56. var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip', 'CardNum', 'Cvv' ];
  57. var fields = ["emailAdd","fname","lname","street","city","zip","card_num","cvv" ],
  58. numFields = fields.length,
  59. i,
  60. output = '',
  61. currField = '';
  62. for( i = 0; i < numFields; i++ ) {
  63. if( document.getElementById( fields[i] ).value == '' ) {
  64. currField = window['payflowproGatewayErrorMsg'+ msg[i]];
  65. output += payflowproGatewayErrorMsgJs + ' ' + currField + '.\\r\\n';
  66. }
  67. }
  68. if (document.getElementById('fname').value == '$first') {
  69. output += payflowproGatewayErrorMsgJs + ' first name.\\r\\n';
  70. }
  71. if (document.getElementById('lname').value == '$last') {
  72. output += payflowproGatewayErrorMsgJs + ' last name.\\r\\n';
  73. }
  74. if (document.getElementById('street').value == '$street') {
  75. output += payflowproGatewayErrorMsgJs + ' street address.\\r\\n';
  76. }
  77. if (document.getElementById('city').value == '$city') {
  78. output += payflowproGatewayErrorMsgJs + ' city.\\r\\n';
  79. }
  80. if (document.getElementById('zip').value == '$zip') {
  81. output += payflowproGatewayErrorMsgJs + ' zip code.\\r\\n';
  82. }
  83. var stateField = document.getElementById( 'state' );
  84. if( stateField.options[stateField.selectedIndex].value == '' ) {
  85. output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgState'] + '.\\r\\n';
  86. }
  87. // validate email address
  88. var apos = document.payment.emailAdd.value.indexOf("@");
  89. var dotpos = document.payment.emailAdd.value.lastIndexOf(".");
  90. if( apos < 1 || dotpos-apos < 2 ) {
  91. output += payflowproGatewayErrorMsgEmail;
  92. }
  93. if( output ) {
  94. alert( output );
  95. return false;
  96. }
  97. }
  98. </script>
  99. EOT;
  100. $wgOut->addHeadItem( 'placeholders', $js );
  101. }
  102. public function generateFormStart() {
  103. global $wgOut, $wgRequest, $wgScriptPath;
  104. $form = parent::generateBannerHeader();
  105. $form .= Xml::openElement( 'table', array( 'width' => '100%', 'cellspacing' => 0, 'cellpadding' => 0, 'border' => 0 ) );
  106. $form .= Xml::openElement( 'tr' );
  107. $form .= Xml::openElement( 'td', array( 'id' => 'appeal', 'valign' => 'top' ) );
  108. $form .= Xml::openElement( 'div', array( 'id' => 'premium-confirmation' ) );
  109. $form .= Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/Wikipedia-ten-tshirt-back.jpg", 'width' => '300', 'height' => '300' ) );
  110. $form .= wfMsg( 'payflowpro_gateway-shirt-size-2', $wgRequest->getText( 'size' ) );
  111. $form .= Xml::closeElement( 'div' ); // close div#premium-confirmation
  112. $form .= Xml::closeElement( 'td' );
  113. $form .= Xml::openElement( 'td', array( 'id' => 'donate', 'valign' => 'top' ) );
  114. // add noscript tags for javascript disabled browsers
  115. $form .= $this->getNoScript();
  116. $form .= Xml::tags( 'h2', array( 'id' => 'donate-head' ), wfMsg( 'payflowpro_gateway-please-complete' ) );
  117. // provide a place at the top of the form for displaying general messages
  118. if ( $this->form_errors['general'] ) {
  119. $form .= Xml::openElement( 'div', array( 'id' => 'mw-payflow-general-error' ) );
  120. if ( is_array( $this->form_errors['general'] ) ) {
  121. foreach ( $this->form_errors['general'] as $this->form_errors_msg ) {
  122. $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
  123. }
  124. } else {
  125. $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
  126. }
  127. $form .= Xml::closeElement( 'div' ); // close div#mw-payflow-general-error
  128. }
  129. // Xml::element seems to convert html to htmlentities
  130. $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>";
  131. $form .= Xml::openElement( 'form', array( 'name' => 'payment', 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => 'return formCheck(this)', 'autocomplete' => 'off' ) );
  132. $form .= $this->generateBillingContainer();
  133. return $form;
  134. }
  135. public function generateFormEnd() {
  136. $form = '';
  137. $form .= $this->generateFormClose();
  138. return $form;
  139. }
  140. protected function generateBillingContainer() {
  141. $form = '';
  142. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-personal-info' ) );
  143. $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-donor' ) );
  144. $form .= $this->generateBillingFields();
  145. $form .= Xml::closeElement( 'table' ); // close table#payflow-table-donor
  146. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-personal-info
  147. return $form;
  148. }
  149. protected function generateBillingFields() {
  150. global $wgScriptPath, $wgPayflowGatewayTest;
  151. $form = '';
  152. // amount
  153. $form .= '<tr>';
  154. $form .= '<td colspan="2">';
  155. $form .= '<table cellspacing="0" cellpadding="4" border="1" id="donation_amount">';
  156. $form .= '<tr>';
  157. $form .= '<td class="amount_header">'.wfMsg( 'payflowpro_gateway-description' ).'</td>';
  158. $form .= '<td class="amount_header" style="text-align:right;width:75px;">'.wfMsg( 'payflowpro_gateway-donor-amount' ).'</td>';
  159. $form .= '<td class="amount_header" style="text-align:right;width:75px;">'.wfMsg( 'payflowpro_gateway-donor-currency-label' ).'</td>';
  160. $form .= '</tr>';
  161. $form .= '<tr>';
  162. $form .= '<td class="amount_data">'.wfMsg( 'payflowpro_gateway-donation' ).'</td>';
  163. $form .= '<td class="amount_data" style="text-align:right;width:75px;">'.$this->form_data['amount'] .
  164. Html::hidden( 'amount', $this->form_data['amount'] ) .
  165. '</td>';
  166. $form .= '<td class="amount_data" style="text-align:right;width:75px;">'.$this->form_data[ 'currency' ] .
  167. Html::hidden( 'currency_code', $this->form_data['currency'] ) .
  168. '</td>';
  169. $form .= '</tr>';
  170. $form .= '</table>';
  171. $form .= '</td>';
  172. $form .= '</tr>';
  173. $form .= '<tr>';
  174. $form .= '<td colspan="2"><h3 class="cc_header">' . wfMsg( 'payflowpro_gateway-cc-form-header-personal' ) .
  175. Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/padlock.gif", 'style' => 'vertical-align:baseline;margin-left:8px;' ) ) . '</h3></td>';
  176. $form .= '</tr>';
  177. // card logos
  178. $form .= '<tr>';
  179. $form .= '<td class="label"> </td>';
  180. if ( $this->form_data[ 'currency' ] == 'USD' ) {
  181. $form .= '<td>' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/credit_card_logos.gif" ) ) . '</td>';
  182. } else {
  183. $form .= '<td>' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/credit_card_logos3.gif" ) ) . '</td>';
  184. }
  185. $form .= '</tr>';
  186. // card number
  187. $card_num = ( $wgPayflowGatewayTest ) ? $this->form_data[ 'card_num' ] : '';
  188. $form .= '';
  189. if ( $this->form_errors['card_num'] ) {
  190. $form .= '<tr>';
  191. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['card_num'] . '</span></td>';
  192. $form .= '</tr>';
  193. }
  194. if ( $this->form_errors['card'] ) {
  195. $form .= '<tr>';
  196. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['card'] . '</span></td>';
  197. $form .= '</tr>';
  198. }
  199. $form .= '<tr>';
  200. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-card-num' ), 'card_num' ) . '</td>';
  201. $form .= '<td>' . Xml::input( 'card_num', '30', $card_num, array( 'type' => 'text', 'maxlength' => '100', 'id' => 'card_num', 'class' => 'fullwidth', 'autocomplete' => 'off' ) ) .
  202. '</td>';
  203. $form .= '</tr>';
  204. // expiry
  205. $form .= '<tr>';
  206. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-expiration' ), 'expiration' ) . '</td>';
  207. $form .= '<td>' . $this->generateExpiryMonthDropdown() . ' / ' . $this->generateExpiryYearDropdown() . '</td>';
  208. $form .= '</tr>';
  209. // cvv
  210. $form .= $this->getCvvField();
  211. // name
  212. $form .= '<tr>';
  213. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['fname'] . '</span></td>';
  214. $form .= '</tr>';
  215. $form .= '<tr>';
  216. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['lname'] . '</span></td>';
  217. $form .= '</tr>';
  218. $form .= '<tr>';
  219. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-name-on-card' ), 'fname' ) . '</td>';
  220. $form .= '<td>' . Xml::input( 'fname', '30', $this->form_data['fname'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-fname' ).'\' )', 'maxlength' => '25', 'class' => 'required', 'id' => 'fname' ) ) .
  221. Xml::input( 'lname', '30', $this->form_data['lname'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-lname' ).'\' )', 'maxlength' => '25', 'id' => 'lname' ) ) . '</td>';
  222. $form .= "</tr>";
  223. // street
  224. $form .= '<tr>';
  225. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['street'] . '</span></td>';
  226. $form .= '</tr>';
  227. $form .= '<tr>';
  228. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-billing-address' ), 'street' ) . '</td>';
  229. $form .= '<td>' . Xml::input( 'street', '30', $this->form_data['street'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-street' ).'\' )', 'maxlength' => '100', 'id' => 'street', 'class' => 'fullwidth' ) ) .
  230. '</td>';
  231. $form .= '</tr>';
  232. // city
  233. $form .= '<tr>';
  234. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['city'] . '</span></td>';
  235. $form .= '</tr>';
  236. $form .= '<tr>';
  237. $form .= '<td class="label"> </td>';
  238. $form .= '<td>' . Xml::input( 'city', '18', $this->form_data['city'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-city' ).'\' )', 'maxlength' => '40', 'id' => 'city' ) ) . ' ' .
  239. $this->generateStateDropdown() . ' ' .
  240. Xml::input( 'zip', '5', $this->form_data['zip'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-zip-code' ).'\' )', 'maxlength' => '10', 'id' => 'zip' ) ) .
  241. Html::hidden( 'country', 'US' ) .
  242. '</td>';
  243. $form .= '</tr>';
  244. // country
  245. $form .= '<tr>';
  246. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['country'] . '</span></td>';
  247. $form .= '</tr>';
  248. $form .= '<tr>';
  249. $form .= '<td class="label"> </td>';
  250. $form .= '<td>' . $this->generateCountryDropdown( $this->form_data['country2'] ) . '</td>';
  251. $form .= '</tr>';
  252. // email
  253. $form .= '<tr>';
  254. $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['emailAdd'] . '</span></td>';
  255. $form .= '</tr>';
  256. $form .= '<tr>';
  257. $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-email-receipt' ), 'emailAdd' ) . '</td>';
  258. $form .= '<td>' . Xml::input( 'emailAdd', '30', $this->form_data['email'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-email' ).'\' )', 'maxlength' => '64', 'id' => 'emailAdd', 'class' => 'fullwidth' ) ) .
  259. '</td>';
  260. $form .= '</tr>';
  261. return $form;
  262. }
  263. /**
  264. * Generate form closing elements
  265. */
  266. public function generateFormClose() {
  267. $form = '';
  268. // add hidden fields
  269. $hidden_fields = $this->getHiddenFields();
  270. foreach ( $hidden_fields as $field => $value ) {
  271. $form .= Html::hidden( $field, $value );
  272. }
  273. $form .= Xml::closeElement( 'form' ); // close form 'payment'
  274. $form .= $this->generateDonationFooter();
  275. $form .= Xml::closeElement( 'td' );
  276. $form .= Xml::closeElement( 'tr' );
  277. $form .= Xml::closeElement( 'table' );
  278. return $form;
  279. }
  280. public function generateDonationFooter() {
  281. global $wgScriptPath;
  282. $form = '';
  283. $form .= Xml::openElement( 'div', array( 'class' => 'payflow-cc-form-section', 'id' => 'payflowpro_gateway-donate-addl-info' ) );
  284. $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-donate-addl-info-text' ) );
  285. $form .= Xml::tags( 'div', array( 'style' => 'text-align:center;' ), '* * *' );
  286. $form .= Xml::tags( 'div', array( 'class' => '' ), wfMsg( 'payflowpro_gateway-credit-storage-processing' ) );
  287. $form .= Xml::tags( 'div', array( 'class' => '' ), wfMsg( 'payflowpro_gateway-otherways-alt' ) );
  288. $form .= Xml::tags( 'div', array( 'class' => '' ), wfMsg( 'payflowpro_gateway-question-comment' ) );
  289. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-addl-info-text
  290. $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-addl-info
  291. return $form;
  292. }
  293. public function generateStateDropdown() {
  294. require_once( dirname( __FILE__ ) . '/../includes/stateAbbreviations.inc' );
  295. $states = statesMenuXML();
  296. $state_opts = Xml::option( '', '' );
  297. // generate dropdown of state opts
  298. foreach ( $states as $value => $state_name ) {
  299. if ( $value !== 'YY' && $value !== 'XX' ) {
  300. $selected = ( $this->form_data[ 'state' ] == $value ) ? true : false;
  301. $state_opts .= Xml::option( $value, $value, $selected );
  302. }
  303. }
  304. $state_menu = Xml::openElement(
  305. 'select',
  306. array(
  307. 'name' => 'state',
  308. 'id' => 'state'
  309. ) );
  310. $state_menu .= $state_opts;
  311. $state_menu .= Xml::closeElement( 'select' );
  312. return $state_menu;
  313. }
  314. }