Odyssey
hcuMobilePayEnroll.prg
1 <?php
2  /*
3  * File: hcuMobilePayEnrollment.prg
4  *
5  * Purpose: This script will show the enrollment and subscriber edit form for mobile banking.
6  *
7  * Created by ENR, 12/2018
8  *
9  */
10 
11  $serviceViewFromCUAdmin = (isset($serviceViewFromCUAdmin) ? $serviceViewFromCUAdmin : false);
12  if (!$serviceViewFromCUAdmin) {
13  // ** SET SCRIPT LEVEL VARIABLES
14  $serviceShowInfo = true;
15  $serviceLoadMenu = true;
16  $serviceShowMenu = true;
17  $serviceLiveCheck = true;
18  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
19  require_once(dirname(__FILE__) . '/../library/hcuService.i');
20  }
21 
22  require_once(dirname(__FILE__) . '/hcuMobilePay.plugin');
23  require_once(dirname(__FILE__) . '../../../shared/library/cutrusted.i');
24 
25  /*
26  * ** CHECK USER FEATURE PERMISSIONS **
27  * NOTE: DOES NOT RETURN ON FAILURE
28  */
29  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_BASIC);
30 
31  // ** INSERT BUSINESS LOGIC FOR THIS FORM
32  $inputVars = array();
33  $varOk = array("mp_token"=>"string", "mp_type"=>"string", "mpVendor"=>"string", "allowp2p"=>"string");
34 
35  HCU_ImportVars( $inputVars, "", $varOk );
36 
37  // extract the encrypted stuff
38  if ( strpos( $inputVars['mp_token'], "=" ) !== false ||
39  strpos( $inputVars['mp_token'], "+" ) !== false ) {
40  // already decoded
41  $decodedToken = $inputVars['mp_token'];
42  $encodedToken = urlencode( $inputVars['mp_token'] );
43  } else {
44  $encodedToken = $inputVars['mp_token'];
45  $decodedToken = urldecode( $inputVars['mp_token'] );
46  }
47 
48  $commonString = hcu_decrypturl( $decodedToken, $HB_ENV['2factorkey']);
49 
50  parse_str( $commonString, $commonParms );
51 
52  $mpDateModel = $commonParms["mpDateModel"];
53  $mobilePayName = $commonParms["mpName"];
54  $mpAccount = $commonParms["mpAccount"];
55 
56  $mpVendorKey = $commonParms["mpVendor"];
57  $mpType = $inputVars["mp_type"];
58  $mpToken = $commonParms["mpToken"];
59  //pulling permission from vendor/cu to allow P2P type Payees
60  $allowP2P = $commonParms["allowp2p"];
61  //get SubId - ENR
62  $userTokens = explode("|", $mpToken);
63  $subId = '';
64  if(isset($userTokens[1])){
65  $subId = $userTokens[1];
66  }
67  // extras need to be in an array
68  $extrasString = str_replace( "|", "&", $commonParms["mpExtras"] );
69  $extrasString = str_replace( ":", "=", $extrasString );
70 
71  parse_str( $extrasString, $mpExtras );
72 
73  // turn the extra options into a string like: key1:value1|key2:value2|key3:value3...
74  $extrasString = "";
75  foreach ($mpExtras as $key => $val) {
76  if ( strlen( $extrasString ) > 0 ) $extrasString .= "|";
77  $extrasString .= "$key:$val";
78  }
79 
80  if (strlen( $mpToken )) {
81  // set up common parameters
82  $commonURL = "mpToken=$mpToken&mpVendor=$mpVendorKey&mpDateModel=$mpDateModel&mpName=$mobilePayName&mpExtras=$extrasString&allowp2p=$allowP2P&mpAccount=$mpAccount";
83  $encryptedCommonURL = hcu_encrypturl( $commonURL, $HB_ENV['2factorkey'] );
84  $encodedCommonURL = urlencode( $encryptedCommonURL );
85  }
86  //getting requirements for subscribers
87  $mobilePayParams = array();
88  $mobilePayParams["MP_VENDOR"] = $mpVendorKey;
89  $mobilePayParams["MP_ACTION"] = "MP_SUBREQ";
90  $mobilePayParams["MP_ACCOUNT"]= $mpAccount;
91 
92  $mobilePayResultAry = MobilePayPlugin($dbh, $HB_ENV, $mobilePayParams);
93 
94  if ($mobilePayResultAry['status']['code'] == '000' ) {
95 
96  $minlen = $mobilePayResultAry['data']["minlen"];
97  $maxlen = $mobilePayResultAry['data']["maxlen"];
98  $minalpha = $mobilePayResultAry['data']["minalpha"];
99  $minnum = $mobilePayResultAry['data']["minnum"];
100  $minspecchar = $mobilePayResultAry['data']["minspecchar"];
101  $minlowcase = $mobilePayResultAry['data']["minlowcase"];
102  $minupcase = $mobilePayResultAry['data']["minupcase"];
103  $ssnreq = $mobilePayResultAry['data']["ssnreq"];
104 
105  $pinreq = $mobilePayResultAry['data']["pinreq"];
106  //pulling password pattern specific to vendor
107  $pswPattern = $mobilePayResultAry['data']["pswPattern"];
108  //password/pin tooltip
109  $pinTip = $mobilePayResultAry['data']["pinTip"];
110  // print_r($pswPattern);
111 
112  //building pattern for loginID requirements - Not Needed at this time
113  // if($minnum <= 0){
114  // //print_r($minnum);
115  // //$minnum = 1;
116  // }
117  // //setting minimum alpha and numeric chars
118  // $pattern .= '(?=.*[0-9]{'.$minnum.',})';
119  // $pattern .= '(?=.*[A-z]{'.$minalpha.',})';
120  // //setting minimum number of lower or upper case chars
121  // $pattern .= '(?=.*[a-z]{'.$minlowcase.',})';
122  // $pattern .= '(?=.*[A-Z]{'.$minupcase.',})';
123  // //setting minimum special characters - may need to specify characters allowed or not allowed if required
124  // if($minspecchar > 0){
125  // $pattern .= '(?=.*[$@]{'.$minspecchar.',})';
126  // }
127 
128  // //setting min and max lengths
129  // $pattern .= '\S{'.$minlen.','.$maxlen.'}';
130  // //end of pattern
131 
132  }
133 
134  //this is the header and side menu
135  // ** INCLUDE PRE CONTENT SCRIPT
136  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
137 ?>
138 
139 <!-- kendo mobile -->
140 <style>
141 .btn-group-wrap {
142  text-align: center;
143 }
144 
145 .btn-group {
146  text-align: center;
147 }
148 
149 </style>
150 
151 <div id="confirmationWindow"></div>
152 <div id="enrollWindow" name="enrollWindow" class="container-fluid">
153  <div class="row" style="margin: 10px 0px 10px 0px;">
154  <span class="hcu-breadcrumbs"><a href='hcuMobilePay.prg?mp_token=<?php echo $encodedToken ?>&<?php echo $HB_ENV['cuquery'] ?>' class="tabReturnBtn"><?php echo $mobilePayName . " " . $MC->msg("Menu", HCU_DISPLAY_AS_HTML) ?></a> / <span class="realname"><?php if ( $mpType == "NewSub") : ?><?php echo $MC->msg("Bill Pay Enrollment", HCU_DISPLAY_AS_HTML) ?><?php else : ?><?php echo $MC->msg("Account Maintenance", HCU_DISPLAY_AS_HTML) ?><?php endif; ?></span></span>
155  </div>
156  <div class="row">
157  <div class="k-content col-xs-12 " style="max-width: 600px;">
158  <div id="enrollFormStatus" class="homecu-formStatus k-block k-error-colored" style="display:none; margin-bottom:10px;max-width:800px;"></div>
159  <div id='enrollErrors'></div>
160  <div class="form-horizontal form-widgets well well-sm">
161  <!-- First Name -->
162  <div class="form-group">
163  <div class="">
164  <label class="col-sm-12" for="firstName"><?php echo $MC->msg("First Name", HCU_DISPLAY_AS_HTML) ?>
165  <span class="hcu-required-field"><sup>*</sup></span></label>
166  <div class="col-sm-12">
167  <input id='firstName' class='k-textbox distinctAcct hcu-all-100' name='firstName' type="text" pattern="[0-9a-zA-Z .,'-]{1,100}"
168  data-required-msg="<?php echo $MC->msg("First Name Missing", HCU_DISPLAY_AS_HTML) ?>"
169  data-bind="value: firstName"
170  validationMessage="<?php echo $MC->msg("First Name Invalid", HCU_DISPLAY_AS_HTML) ?>"
171  required/>
172  </div>
173  </div>
174  </div>
175  <!-- Last Name -->
176  <div class="form-group">
177  <label class="col-sm-12" for="lastName"><?php echo $MC->msg("Last Name", HCU_DISPLAY_AS_HTML) ?>
178  <span class="hcu-required-field"><sup>*</sup></span></label>
179  <div class="col-sm-12">
180  <input id='lastName' class='k-textbox distinctAcct hcu-all-100' name='lastName' type="text" pattern="[0-9a-zA-Z .,'-]{1,100}"
181  data-required-msg="<?php echo $MC->msg("Last Name Missing", HCU_DISPLAY_AS_HTML) ?>"
182  data-bind="value: lastName"
183  validationMessage="<?php echo $MC->msg("Last Name Invalid", HCU_DISPLAY_AS_HTML) ?>"
184  required/>
185  </div>
186  </div>
187  <!-- Address -->
188  <div class="form-group">
189  <label class="col-sm-12" for="addr1"><?php echo $MC->msg("ACH Address", HCU_DISPLAY_AS_HTML) . " 1"; ?>
190  <span class="hcu-required-field"><sup>*</sup></span></label>
191  <div class="col-sm-12">
192  <input id='addr1' class='k-textbox distinctAcct hcu-all-100' name='addr1' maxlength="100"
193  data-required-msg="<?php echo $MC->msg("Address Missing", HCU_DISPLAY_AS_HTML) ?>"
194  data-bind="value: addr1"
195  required />
196  </div>
197  </div>
198  <!-- Address 2-->
199  <div class="form-group">
200  <label class="col-sm-12" for="addr1"><?php echo $MC->msg("ACH Address", HCU_DISPLAY_AS_HTML) . " 2"; ?></label>
201  <div class="col-sm-12">
202  <input id='addr2' class='k-textbox distinctAcct hcu-all-100' name='addr2' maxlength="100"
203  data-bind="value: addr2"
204  />
205  </div>
206  </div>
207  <!-- City-->
208  <div class="form-group">
209  <label class="col-sm-12" for="city"><?php echo $MC->msg("City", HCU_DISPLAY_AS_HTML)?><span class="hcu-required-field"><sup>*</sup></span></label>
210  <div class="col-sm-12">
211  <input id='city' class='k-textbox distinctAcct hcu-all-100' name='city' type='text' type="text" pattern="[[0-9a-zA-Z .,'-]{1,100}"
212  data-required-msg="<?php echo $MC->msg("City Missing", HCU_DISPLAY_AS_HTML)?>"
213  data-bind="value: city"
214  validationMessage="<?php echo $MC->msg("City Invalid", HCU_DISPLAY_AS_HTML)?>"
215  required/>
216  </div>
217  </div>
218  <!-- State-->
219  <div class="form-group">
220  <label class="col-sm-12" for="state"><?php echo $MC->msg("State", HCU_DISPLAY_AS_HTML)?>
221  <span class="hcu-required-field"><sup>*</sup></span></label>
222  <div class="col-sm-12">
223  <input id='state' class='distinctAcct hcu-all-100' name='state' data-role='dropdownlist'
224  data-bind="value: state"
225  data-required-msg="<?php echo $MC->msg("State Missing", HCU_DISPLAY_AS_HTML)?>"
226  required
227  />
228  </div>
229  </div>
230  <!-- Zipcode-->
231  <div class="form-group">
232  <label class="col-sm-12" for="zip"><?php echo $MC->msg("Zip Code", HCU_DISPLAY_AS_HTML)?>
233  <span class="hcu-required-field"><sup>*</sup></span></label>
234  <div class="col-sm-12">
235  <input id='zip' class='k-textbox distinctAcct hcu-all-100' name='zip' type="text"
236  data-bind="value: zip"
237  data-required-msg='<?php echo $MC->msg("Zip Code Missing", HCU_DISPLAY_AS_HTML)?>'
238  required/>
239  </div>
240  </div>
241  <!-- Phone-->
242  <div class="form-group">
243  <label class="col-sm-12" for="phone"><?php echo $MC->msg("Phone", HCU_DISPLAY_AS_HTML)?>
244  <span class="hcu-required-field"><sup>*</sup></span></label>
245  <div class="col-sm-12">
246  <input id='phone' class='k-textbox distinctAcct hcu-all-100' name='phone' type='tel'
247  data-bind="value: phone"
248  data-required-msg='<?php echo $MC->msg("Phone Missing", HCU_DISPLAY_AS_HTML)?>'
249  required/>
250  </div>
251  </div>
252  <!-- Email-->
253  <div class="form-group">
254  <label class="col-sm-12" for="email"><?php echo $MC->msg("Email", HCU_DISPLAY_AS_HTML)?>
255  <span class="hcu-required-field"><sup>*</sup></span></label>
256  <div class="col-sm-12">
257  <input id='email' class='k-textbox distinctAcct hcu-all-100' name='email' type='email' pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
258  validationMessage="<?php echo $MC->msg("Bad Email Flag", HCU_DISPLAY_AS_HTML)?>"
259  placeholder="<?php echo $MC->msg("Email Placeholder", HCU_DISPLAY_AS_HTML)?>"
260  data-required-msg="<?php echo $MC->msg("Email Missing", HCU_DISPLAY_AS_HTML)?>"
261  data-bind="value: email"
262  required />
263  </div>
264  </div>
265  <!-- Only showing bank accounts list for adding new subscriber -->
266  <?php if ( $mpType == 'NewSub' ) : ?>
267  <!-- Pay From-->
268  <div class="form-group">
269  <label class="col-sm-12" for="payFrom"><?php echo $MC->msg("Account", HCU_DISPLAY_AS_HTML)?>
270  <span class="hcu-required-field"><sup>*</sup></span></label>
271  <div class="col-sm-12">
272  <input id='payFrom' class='distinctAcct hcu-all-100' name='payFrom' data-role='dropdownlist'
273  data-bind="value: accountId"
274  data-required-msg="<?php echo $MC->msg("Account is required", HCU_DISPLAY_AS_HTML)?>"
275  />
276  </div>
277  </div>
278  <?php endif; ?>
279  <!-- CU SPECIFIC REQUIREMENTS -->
280  <?php if ( $ssnreq == 'true' && $mpType == "NewSub") : ?>
281  <!-- SSN -->
282  <div class="form-group">
283  <label class="col-sm-12" for="ssn"><?php echo $MC->msg("Social Security Number", HCU_DISPLAY_AS_HTML)?>
284  <span class="hcu-required-field"><sup>*</sup></span>
285  <span class="fa fa-question-circle-o" id="ssnTip"></span>
286  </label>
287  <div class="col-sm-12">
288  <input id='ssn' class='k-textbox distinctAcct hcu-all-100' name='ssn' type="password" id="ssn"
289  data-bind="value: ssn" autocomplete="new-password" autocomplete="off" maxlength="9"
290  pattern="(?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4}"
291  validationMessage="<?php echo $MC->msg("SSN Invalid", HCU_DISPLAY_AS_HTML)?>"
292  data-required-msg="<?php echo $MC->msg("SSN Missing", HCU_DISPLAY_AS_HTML)?>"
293  />
294  </div>
295  </div>
296  <?php endif; ?>
297  <!--If pin is required and this is a new subscriber, show password field, do not show for editing sub-->
298  <?php if ( $pinreq == 'true' && $mpType == "NewSub") : ?>
299  <!-- Temp Password -->
300  <div class="form-group">
301  <label class="col-sm-12" for="temppass">
302  <span><?php echo $MC->msg("Temp Password", HCU_DISPLAY_AS_HTML)?></span>
303  <span class="hcu-required-field"><sup>*</sup></span>
304  <span class="fa fa-question-circle-o" id="pswdTip"></span>
305  </label>
306  <div class="col-sm-12">
307  <input id='temppass' class='k-textbox distinctAcct hcu-all-100 must_equal' name='temppass' type='password' pattern="<?php echo $pswPattern ?>"
308  autocomplete="off"
309  data-required-msg="<?php echo $MC->msg("Password Required", HCU_DISPLAY_AS_HTML)?>"
310  data-bind="value: temppass"
311  validationMessage="<?php echo $MC->msg("Password Invalid", HCU_DISPLAY_AS_HTML)?>"
312  required/>
313  </div>
314  </div>
315  <div class="form-group">
316  <label class="col-sm-12" for="confirmpass"><?php echo $MC->msg("Confirm Password", HCU_DISPLAY_AS_HTML)?>
317  <span class="hcu-required-field"><sup>*</sup></span>
318  <span class="fa fa-question-circle-o" id="pswdTip2"></span>
319  </label>
320  <div class="col-sm-12">
321  <input id='confirmpass' class='k-textbox distinctAcct hcu-all-100' name='confirmpass' type='password' pattern="<?php echo $pswPattern ?>"
322  autocomplete="off"
323  data-required-msg="<?php echo $MC->msg("Password Required", HCU_DISPLAY_AS_HTML)?>"
324  data-bind="value: confirmpass"
325  validationMessage="<?php echo $MC->msg("Password Invalid", HCU_DISPLAY_AS_HTML)?>"
326  placeholder="<?php echo $MC->msg("Confirm Password", HCU_DISPLAY_AS_HTML)?>"
327  homecu-equals="must_equal"
328  data-homecuCustomEquals-msg="<?php echo $MC->msg("Password Not Match", HCU_DISPLAY_AS_HTML)?>"
329  required />
330  </div>
331  </div>
332  <?php endif; ?>
333  <!-- ACTION BUTTONS -->
334  <div class="hcu-template">
335  <div class="hcu-edit-buttons k-state-default">
336  <a href="hcuMobilePay.prg?<?php echo $HB_ENV['cuquery'] ?>&mp_token=<?php echo $encodedToken ?>" id="lnkCancel" style=""><?php echo $MC->msg("Cancel", HCU_DISPLAY_AS_HTML)?></a>
337  &emsp;
338  <button class="k-button k-primary" id="btnEditSubscriber"><i class="fa fa-check fa-lg"></i><?php echo $MC->msg("Update", HCU_DISPLAY_AS_HTML)?></button>
339  <button class="k-button k-primary" id="btnAddSubscriber"><i class="fa fa-check fa-lg"></i><?php echo $MC->msg("Enroll", HCU_DISPLAY_AS_HTML)?></button>
340  </div>
341  </div>
342  </div>
343  </div>
344  </div>
345  </div>
346  <script id="confirmationTemplate" type="text/x-kendo-tmpl">
347  <div id="confirmationStatus"></div>
348  <div id="responseDiv">
349  <div class="local-transfer-msg">
350  <?php if($mpType == "NewSub") : ?>
351  <?php echo $MC->msg('Bill Pay Enroll Success', HCU_DISPLAY_AS_JS); ?>
352  <?php else : ?>
353  <?php echo $MC->msg('Bill Pay Update', HCU_DISPLAY_AS_JS); ?>
354  <?php endif; ?>
355  </div>
356  </div>
357  </script>
358 <script>
359 <?php if ( $ssnreq == 'true' && $mpType == 'NewSub' ) : ?>
360  $("#ssn").attr('required', true);
361 <?php endif; ?>
362 <?php if ( $pinreq == 'true' && $mpType == 'NewSub') : ?>
363  $("#temppass").attr('required', true);
364 <?php endif; ?>
365 <?php if ( $mpType == "NewSub") : ?>
366 $("#payFrom").attr('required', true);
367 <?php endif; ?>
368 
369 var windowStack = [];
370 var subId;
371 var editSubscriberModel;
372 var dsSubscriber;
373 var dsCUAccounts = [];
374 var dataPayFrom = [];
375 var confirmSaveDialog;
376 var stateList = <?php echo HCU_JsonEncode( GetBPStateList() ); ?>;
377 
378 //adding datasource to states field
379 $("#state").kendoDropDownList({
380  // valuePrimitive: true,
381  dataTextField: "name",
382  dataValueField: "value",
383  dataSource: stateList,
384  optionLabel: {value: "", name: "<?php echo $MC->msg("ACH Select State", HCU_DISPLAY_AS_JS) ?>"},
385 });
386 
387 homecuTooltip.bind({
388  pswdTip:
389  "<?php echo $pinTip ?> " ,
390  pswdTip2:
391  "<?php echo $MC->msg("Enter password again", HCU_DISPLAY_AS_HTML)?>" ,
392  ssnTip:
393  "<?php echo $MC->msg("SSN Format Tip", HCU_DISPLAY_AS_HTML)?>"
394  });
395 
396 
397 
398 // masked zip code (just US for now)
399 $("#zip").kendoMaskedTextBox({
400  mask: "00000-9999",
401  clearPromptChar: true
402 });
403 
404 // // masked ssn - not masking at this time per support
405 // $("#ssn").kendoMaskedTextBox({
406 // mask: "000-00-0000",
407 // clearPromptChar: true
408 // });
409 
410 // masked phone number
411 $("#phone").kendoMaskedTextBox({
412  mask: "(000) 000-0000",
413  clearPromptChar: true
414 });
415 
416 function InitDataSources(){
417  dsCUAccounts = new kendo.data.DataSource ({
418  data: dataPayFrom
419  });
420 
421  var accountURL = "hcuMobilePay.data?cu=<?php echo $HB_ENV['cu']; ?>&mp_token=<?php echo $encodedToken ?>&mp_type=cuAccounts&<?php echo $HB_ENV['cuquery'] ?>"
422  //prompt("Copy cuAccounts", accountURL); //ENR for debugging
423 
424  //pulling user account information
425  dsGetAccounts = new kendo.data.DataSource ({
426  transport: {
427  read: {
428  url: accountURL,
429  contentType: 'application/x-www-form-urlencoded',
430  type: 'POST',
431  data: {},
432  pageable: true,
433  cache: false
434  }
435  },
436  requestStart: function( e ) {
437  ShowWaitWindow();
438  },
439  requestEnd: function( e ) {
440  CloseWaitWindow();
441  var error = null;
442  // see if there is an error
443  if ( e.response && e.response.homecuErrors )
444  error = e.response.homecuErrors;
445  if ( error && error.length > 0 ) {
446  e.preventDefault();
447  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
448  } else {
449  // not sure
450  }
451  },
452  // code to run if the request fails; the raw request and
453  // status codes are passed to the function
454  error: function( e ) {
455  alert( "Transport error: " + e.errorThrown);
456  },
457  schema: {
458  model: {
459  id: "accountid",
460  fields: {
461  name: { type: "string" },
462  accountid: { type: "int" },
463  payFromId: { type: "int" },
464  accountDft: { type: "boolean" }
465  }
466  },
467  data: function (response) {
468  /* PARSE RESPONSE DATA */
469  var returnData = Array();
470  try {
471  if (response.homecuData) {
472  dataPayFrom = response.homecuData.accounts;
473  dsCUAccounts.data(dataPayFrom);
474  returnData = response.homecuData;
475  //adding datasource to From Account field
476  $("#payFrom").kendoDropDownList({
477  //valuePrimitive: true,
478  optionLabel: {accountid: "", name: "<?php echo $MC->msg("Select Pay From", HCU_DISPLAY_AS_JS) ?>"},
479  dataSource: dsCUAccounts,
480  dataTextField: 'name',
481  dataValueField: "accountid",
482  valueTemplate: '#= name #',
483  template: '#= name #',
484  change: function(e){
485  var dropdown = this;
486  var dropdownValue = dropdown.value();
487  var dropdownText = dropdown.text();
488  editSubscriberModel.set("accountId", dropdownValue);
489  editSubscriberModel.set("accountName", dropdownText);
490  },
491  });
492  } else if (response.homecuErrors) {
493  //error has been handled
494  } else {
495  throw "Error Parsing Result From Server";
496  }
497  } catch (err) {
498  // ** Need to report the message to the main screen
499  /* *** REPORT THE ERROR *** */
500  alert(err);
501  returnData = [];
502  }
503 
504  return [response];
505  },
506  }
507  });
508 
509  var crudServiceBaseUrl = "hcuMobilePay.data?cu=<?php echo $HB_ENV['cu']; ?>&mp_token=<?php echo $encodedToken ?>";
510  subId = "<?php echo $subId; ?>";
511 
512  //Datasource for enrolling new subscribers and for modifying existing
513  dsSubscriber = new kendo.data.DataSource({
514  autoSync: false,
515  batch: false,
516  transport: {
517  read: {
518  url: crudServiceBaseUrl,
519  dataType: "json",
520  contentType: "application/x-www-form-urlencoded",
521  type: "POST",
522  cache: false
523  },
524  },
525  schema: {
526  parse: function(response) {
527  // not showing data, so return empty array
528  var display = [];
529  return display;
530  }
531  },
532  requestStart: function( e ) {
533  ShowWaitWindow();
534  },
535  requestEnd: function(e) {
536  var error = null;
537  var results = null;
538  CloseWaitWindow();
539  if ( e.response && e.response.homecuErrors ){
540  error = e.response.homecuErrors;
541  if ( error && error.length > 0 ) {
542  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
543  }
544  } else if(e.response && e.response.homecuData){
545  var results = e.response.homecuData;
546  if(results.data){
547  var subscriberInfo = results.data;
548  editSubscriberModel.set( "firstName", subscriberInfo[0].firstName );
549  editSubscriberModel.set( "lastName", subscriberInfo[0].lastName );
550  editSubscriberModel.set( "addr1", subscriberInfo[0].addr1 );
551  editSubscriberModel.set( "addr2", subscriberInfo[0].addr2 );
552  editSubscriberModel.set( "city", subscriberInfo[0].city );
553  editSubscriberModel.set( "state", subscriberInfo[0].state );
554  editSubscriberModel.set( "zip", subscriberInfo[0].zip );
555  editSubscriberModel.set( "phone", subscriberInfo[0].phone );
556  editSubscriberModel.set( "email", subscriberInfo[0].email );
557  }
558  else{
559  ShowSuccess();
560  }
561  }
562  },
563  error: function( e ) {
564  alert( "Transport error: " + e.errorThrown);
565  },
566  });
567 }
568 
569 function InitDataView(){
570  //setting up for adding and modifying subscribers
571  editSubscriberModel = kendo.observable({
572  firstName: "",
573  lastName: "",
574  addr1: "",
575  addr2: "",
576  city: "",
577  state: "",
578  zip: "",
579  phone: "",
580  email: "",
581  ssn: "",
582  accountName: "",
583  accountId: "",
584  temppass: "",
585  subId: "",
586  Save: function() {
587  // if ( $.homecuValidator.validate() ) {
588  if ( ExtraValidation() ) {
589  var request = {
590  mp_type: "<?php echo $mpType ?>",
591  firstName: this.firstName,
592  lastName: this.lastName,
593  addr1: this.addr1,
594  addr2: this.addr2,
595  city: this.city,
596  state: this.state,
597  zip: this.zip,
598  phone: this.phone,
599  email: this.email,
600  subId: this.subId,
601  ssn: this.ssn,
602  accountName: this.accountName,
603  accountId: this.accountId,
604  temppass: this.temppass,
605  }
606  dsSubscriber.read(request);
607  }
608  },
609  ResetModel: function() {
610  this.set( "firstName", "" );
611  this.set( "lastName", "" );
612  this.set( "addr1", "" );
613  this.set( "addr2", "" );
614  this.set( "city", "" );
615  this.set( "state", "" );
616  this.set( "zip", "" );
617  this.set( "phone", "" );
618  this.set( "email", "" );
619  this.set( "payFrom", "" );
620  this.set( "ssn", "" );
621  this.set( "temppass", "" );
622  this.set( "confirmpass", "" );
623  // reset the selected account
624  var dropdownlist = $("#payFrom").data("kendoDropDownList");
625  dropdownlist.select(0);
626  },
627  });
628 
629  if(subId > 0){
630  var request = { mp_type: "GetSub", SubId: subId };
631  dsSubscriber.read(request);
632  editSubscriberModel.set("subId", subId);
633  }
634  kendo.bind($("#enrollWindow"), editSubscriberModel);
635 
636  // Confirmation dialog
637  $("#confirmationWindow").kendoDialog({
638  title: "<?php echo $MC->msg('Success', HCU_DISPLAY_AS_JS); ?>",
639  width: "85%",
640  maxWidth: "768px",
641  minWidth: "300px",
642  modal: true,
643  closable: false,
644  visible: false,
645  resizable: false,
646  actions: [
647  {
648  text: "<?php echo $MC->msg('Close', HCU_DISPLAY_AS_JS); ?>",
649  primary: true
650  }
651  ],
652  show: function(e) {
653  windowStack.push(this);
654  },
655  close: function(e) {
656  windowStack.pop();
657 
658  // Reset validator to use page status field.
659  $.homecuValidator.settings.formStatusField = "formStatus";
660  $.homecuValidator.settings.formInfoTitle = "";
661 
662  //redirect back to menu page
663  window.location = 'hcuMobilePay.prg?mp_token=<?php echo $encodedToken ?>&<?php echo $HB_ENV['cuquery'] ?>';
664  }
665  });
666 }
667 
668 function ShowSuccess(){
669  var confirmationTemplate = kendo.template($("#confirmationTemplate").html());
670  var confirmationDisplay = confirmationTemplate;
671  $("#confirmationWindow").data("kendoDialog").content(confirmationDisplay);
672  $("#confirmationWindow").data("kendoDialog").open();
673  editSubscriberModel.ResetModel();
674 }
675 
676 function ExtraValidation(){
677  var otherErrors = Array();
678 
679  //zipcode validator
680  if (editSubscriberModel.zip != "") {
681  // must validate zip code
682  var zipcode = editSubscriberModel.zip;
683  var zipReplace = zipcode.replace(/_/g, "");
684  var zipSplit = zipReplace.split("-");
685  var zipConstruct = "";
686 
687 
688  // validate section 1, must be 5 digits
689  if (zipSplit[0].length < 5) {
690  otherErrors.push("<?php echo $MC->msg("Zip Code Invalid", HCU_DISPLAY_AS_JS) ?>");
691  } else if (zipSplit[1]) {
692  if (zipSplit[1].length > 0 && zipSplit[1].length < 4) {
693  otherErrors.push("<?php echo $MC->msg("Zip Code Invalid", HCU_DISPLAY_AS_JS) ?>");
694  }
695  }
696 
697  // reconstruct zip code
698  if (zipSplit[1]) {
699  zipConstruct += zipSplit[0] + "-" + zipSplit[1];
700  } else {
701  zipConstruct += zipSplit[0];
702  }
703  editSubscriberModel.set("zip", zipConstruct);
704  }
705 
706  //phone validator
707  if (editSubscriberModel.phone != "") {
708  // must validate phone code
709  var phoneNumber = editSubscriberModel.phone;
710  var phoneReplace = phoneNumber.replace(/\(|\)|-|_/g, "");
711  if ( phoneReplace.length < 10 ) {
712  otherErrors.push("<?php echo $MC->msg("Phone Invalid", HCU_DISPLAY_AS_JS) ?>");
713  }
714  editSubscriberModel.set("phone", phoneReplace);
715  }
716 
717  //ssn validator
718  if (editSubscriberModel.ssn != "") {
719  // must validate zip code
720  var socialNum = editSubscriberModel.ssn;
721  var ssnReplace = socialNum.replace(/-|_/g, "");
722  editSubscriberModel.set("ssn", ssnReplace);
723  }
724 
725  $.homecuValidator.validate();
726  var totalErrors = $.homecuValidator.homecuKendoValidator.errors();
727 
728  // cannot concat errors together because there may be duplicate errors
729  for (var i = 0; i < otherErrors.length; i++) {
730  if ($.inArray(otherErrors[i], totalErrors) == -1) {
731  totalErrors.push(otherErrors[i]);
732  }
733  }
734 
735  if (totalErrors.length > 0) {
736  $.homecuValidator.displayMessage(totalErrors, $.homecuValidator.settings.statusError);
737  $.homecuValidator.homecuValidate = false;
738  } else {
739  $.homecuValidator.homecuValidate = true;
740  }
741 
742  return ( $.homecuValidator.homecuValidate );
743 }
744 
745 $(document).on("click", ".k-overlay", function (e) {
746  if(windowstack.length > 0) {
747  // get the close function from the stack, without popping it (the close will pop it)
748  var fn = windowstack[windowstack.length - 1];
749  var ret = fn(e);
750  }
751 });
752 
753 $(document).ready(function () {
754  $.homecuValidator.setup({enrollFormStatus: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>"});
755  $.homecuValidator.setup({formValidate: "enrollWindow",
756  formErrorTitle: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>",
757  formStatusField: "enrollFormStatus"});
758  InitDataSources();
759  InitDataView();
760 
761  <?php if($mpType == "NewSub") : ?>
762  dsGetAccounts.read();
763  $("#btnAddSubscriber").on('click', function (event) {
764  editSubscriberModel.Save();
765  });
766  $("#btnAddSubscriber").show();
767  $("#btnEditSubscriber").hide();
768  <?php else : ?>
769  dsGetAccounts.read();
770  $("#btnAddSubscriber").hide();
771  $("#btnEditSubscriber").on('click', function (event) {
772  editSubscriberModel.Save();
773  });
774  $("#btnEditSubscriber").show();
775  <?php endif; ?>
776 });
777 
778 </script>
779 <?php
780  /*
781  * ** END CONTENT
782  */
783 
784  // ** INCLUDE POST CONTENT SCRIPT
785  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
786 ?>