Odyssey
aMemberSettings.prg
1 <?php
2 /**
3  * @package MemberHub
4  * @author MGHandy
5  *
6  * @uses this script facilitates in viewing /editing member settings, sub-accounts
7  * and security values associated with the select member account.
8  *
9  * @uses view/edit rdc, billpay id and e-statement flag values
10  * @uses view sub-accounts associated with the select member accounts
11  * @uses view/edit restrictions value
12  *
13  * @param operation string: requested operation for this script
14  * @param payload string: encryption for the selected member
15  * @param mParameters string: json encoded string of all values to be updated
16  *
17  * @return json
18  */
19 require_once("$admLibrary/aMemberSupport.i");
20 
21 try {
22  $admVars = array();
23  $admOk = array(
24  "operation" => array("filter" => FILTER_SANITIZE_STRING),
25  "payload" => array("filter" => FILTER_SANITIZE_STRING),
26  "mParameters" => array("filter" => FILTER_SANITIZE_STRING)
27  );
28  HCU_ImportVars($admVars, "MEMBER_SETTINGS", $admOk);
29 
30  $aOperation = isset($admVars["MEMBER_SETTINGS"]["operation"]) ? $admVars["MEMBER_SETTINGS"]["operation"] : null;
31  $aPayload = isset($admVars["MEMBER_SETTINGS"]["payload"]) ? $admVars["MEMBER_SETTINGS"]["payload"] : null;
32  $aParameters = isset($admVars["MEMBER_SETTINGS"]["mParameters"]) ? $admVars["MEMBER_SETTINGS"]["mParameters"] : null;
33 
34  $aMember = $aPayload ?
35  MemberDecrypt($SYSENV, $Cu, $aPayload) :
36  null;
37 
38  $aContext = $aPayload ?
39  MemberContext($SYSENV, $Cu, $aMember['member']) :
40  MemberContext($SYSENV, $Cu);
41 
42  $aryResult = array();
43  $aryReply = array();
44 
45  switch ($aOperation) {
46  case "":
48  break;
49  case "memberReadSettings":
50 
51  header('Content-type: application/json');
52 
53  $aSettings = MemberReadSettings($SYSENV, $dbh, $aContext);
54  $aAccounts = MemberReadAccounts($SYSENV, $dbh, $aContext);
55 
56  $aryResult['data']['settings'] = $aSettings['settings'];
57  $aryResult['data']['accounts'] = $aAccounts['accounts'];
58  MemberReply($aryResult, $aryReply, $aOperation);
59  break;
60  case "memberUpdateSettings":
61  header('Content-type: application/json');
62 
63  $aValidate = MemberValidateSetings($SYSENV, $aParameters);
64  $aSettings = MemberUpdateSettings($SYSENV, $dbh, $aContext, $aValidate, $Cn);
65 
66  // re-select the group for all new data
67  $aMember = MemberSelect($SYSENV, $dbh, $aContext);
68  // get member payload
69  $aMemberEncrypt = MemberEncrypt($SYSENV, $Cu, $aMember);
70 
71  $aryResult['data']['member'] = $aMember;
72  $aryResult['data']['encrypt'] = $aMemberEncrypt;
73  $aryResult['info'] = $aSettings['message'];
74  MemberReply($aryResult, $aryReply, $aOperation);
75  break;
76  default:
77  throw new Exception("Unknown server request: " . $aOperation);
78  break;
79  }
80 
81 } catch (Exception $e) {
82  $aryReply['errors'][] = $e->getMessage();
83  $aryResult['data'] = array();
84  $aryResult['info'] = array();
85 
86  MemberReply($aryResult, $aryReply, $aOperation);
87  exit;
88 }
89 
90 /**
91  * @package MemberValidateSetings
92  * @uses validate incoming values to update member settings for input
93  * into the database.
94  *
95  * @param pEnv array: environment variable for debugging
96  * @param pSettings array: json string of updatable settings values
97  * to be updated.
98  *
99  * @return sqlReturn array: array of validated settings
100  */
101 function MemberValidateSetings($pEnv, $pSettings) {
102  $mValidate = array();
103 
104  $mSettings = html_entity_decode($pSettings, ENT_QUOTES);
105  $mSettings = HCU_JsonDecode($mSettings);
106 
107  //if (isset($mSettings['m_stmnt'])) {
108  if (array_key_exists("m_stmnt", $mSettings)) {
109  $mStmnt = $mSettings['m_stmnt'];
110  $mStmnt = $mStmnt ? "Y" : "N";
111 
112  $mValidate['m_stmnt'] = $mStmnt;
113  }
114 
115  if (array_key_exists("m_rdc", $mSettings)) {
116  $mRdc = $mSettings['m_rdc'] ?
117  intval($mSettings['m_rdc']) :
118  null;
119 
120  $mValidate['m_rdc'] = $mRdc;
121  }
122 
123  if (array_key_exists("m_payid", $mSettings)) {
124  $mPayId = prep_save($mSettings['m_payid'], 12);
125  $mPayId = preg_replace('/[^0-9a-zA-Z]/', "", $mPayId);
126  $mPayId = trim($mPayId);
127 
128  $mValidate['m_payid'] = strlen($mPayId) > 0 ?
129  $mPayId : null;
130  }
131 
132  if (array_key_exists("m_restr", $mSettings)) {
133  $mRestr = strtoupper($mSettings['m_restr']);
134  $mRestr = prep_save($mRestr, 1);
135  $mRestr = trim($mRestr, 1);
136 
137  $mValidate['m_restr'] = strlen($mRestr) > 0 ?
138  $mRestr : null;
139  }
140 
141  return $mValidate;
142 }
143 
144 /**
145  * @package MemberReadAccounts
146  * @uses read all sub-accounts associated with the selected member account
147  *
148  * @param pEnv array: environment variable for debugging
149  * @param pDbh object: database access object
150  * @param pContext array: array of common data needed accross the member hub
151  *
152  * @return sqlReturn array: array of sub-accounts
153  */
154 function MemberReadAccounts($pEnv, $pDbh, $pContext) {
155  $cuTable = $pContext['cu_table'];
156  $cuCode = $pContext['cu_code'];
157  $cuMember = $pContext['m_account'];
158 
159  $sqlReturn = array();
160 
161  // select all balance sub accounts for this member account.
162  $sqlColumns = "
163  ab.description AS a_desc,
164  ab.accounttype AS a_type,
165  ab.may_deposit AS m_deposit,
166  ab.may_withdraw AS m_withdraw,
167  ma.balance_stamp AS b_stamp,
168  ma.balance_attempt AS b_attempt,
169  ab.history_stamp AS h_stamp,
170  ab.history_attempt AS h_attempt";
171  $sqlSelect = "
172  SELECT $sqlColumns
173  FROM {$cuTable}accountbalance ab
174  LEFT JOIN {$cuTable}memberacct ma
175  ON ma.accountnumber = ab.accountnumber
176  WHERE ab.accountnumber = '$cuMember'
177  ORDER BY ab.accounttype ASC";
178  $sqlSelectRs = db_query($sqlSelect, $pDbh);
179  if (!$sqlSelectRs) {
180  $pEnv['logger']->error(db_last_error());
181  throw new Exception("Failed to read member deposit accounts.");
182  }
183 
184  // set deposit accounts
185  $sqlData = db_fetch_all($sqlSelectRs);
186  if (is_array($sqlData)) {
187  foreach ($sqlData as $key => $value) {
188  // convert timestamps
189  $cuTimeZone = GetCreditUnionTimezone($pDbh, $cuCode);
190 
191  $value['b_stamp'] = ($value['b_stamp'] && abs($value['b_stamp']) > 1) ?
192  GetDateFormatTimezone(abs($value['b_stamp']), "m/d/Y h:i A", $cuTimeZone) :
193  null;
194  $value['b_attempt'] = ($value['b_attempt'] && abs($value['b_attempt']) > 1) ?
195  GetDateFormatTimezone(abs($value['b_attempt']), "m/d/Y h:i A", $cuTimeZone) :
196  null;
197  $value['h_stamp'] = ($value['h_stamp'] && abs($value['h_stamp']) > 1) ?
198  GetDateFormatTimezone(abs($value['h_stamp']), "m/d/Y h:i A", $cuTimeZone) :
199  null;
200  $value['h_attempt'] = ($value['h_attempt'] && abs($value['h_attempt']) > 1) ?
201  GetDateFormatTimezone(abs($value['h_attempt']), "m/d/Y h:i A", $cuTimeZone) :
202  null;
203 
204  $sqlReturn['accounts']['deposit'][] = $value;
205  }
206  } else {
207  $sqlReturn['accounts']['deposit'] = array();
208  }
209 
210 
211  // select all loan sub accounts for this member account.
212  $sqlColumns = "
213  lb.description AS a_desc,
214  lb.loannumber AS a_type,
215  lb.may_addon AS m_addon,
216  lb.may_payment AS m_payment,
217  ma.balance_stamp AS b_stamp,
218  ma.balance_attempt AS b_attempt,
219  lb.history_stamp AS h_stamp,
220  lb.history_attempt AS h_attempt";
221  $sqlSelect = "
222  SELECT $sqlColumns
223  FROM {$cuTable}loanbalance lb
224  LEFT JOIN {$cuTable}memberacct ma
225  ON ma.accountnumber = lb.accountnumber
226  WHERE lb.accountnumber = '$cuMember'
227  ORDER BY lb.loannumber ASC";
228  $sqlSelectRs = db_query($sqlSelect, $pDbh);
229  if (!$sqlSelectRs) {
230  $pEnv['logger']->error(db_last_error());
231  throw new Exception("Failed to read member loan accounts.");
232  }
233 
234  // determine if loan typ 18 = credit
235  $dataType = ($GLOBALS['Fset2'] & $GLOBALS['CU2_SPEC18']) == $GLOBALS['CU2_SPEC18'];
236  $sqlData = db_fetch_all($sqlSelectRs);
237  if (is_array($sqlData)) {
238  foreach ($sqlData as $key => $value) {
239  $cuTimeZone = GetCreditUnionTimezone($pDbh, $cuCode);
240 
241  $value['b_stamp'] = ($value['b_stamp'] && abs($value['b_stamp']) > 1) ?
242  GetDateFormatTimezone(abs($value['b_stamp']), "m/d/Y h:i A", $cuTimeZone) :
243  null;
244  $value['b_attempt'] = ($value['b_attempt'] && abs($value['b_attempt']) > 1) ?
245  GetDateFormatTimezone(abs($value['b_attempt']), "m/d/Y h:i A", $cuTimeZone) :
246  null;
247  $value['h_stamp'] = ($value['h_stamp'] && abs($value['h_stamp']) > 1) ?
248  GetDateFormatTimezone(abs($value['h_stamp']), "m/d/Y h:i A", $cuTimeZone) :
249  null;
250  $value['h_attempt'] = ($value['h_attempt'] && abs($value['h_attempt']) > 1) ?
251  GetDateFormatTimezone(abs($value['h_attempt']), "m/d/Y h:i A", $cuTimeZone) :
252  null;
253 
254  // loan type is credit
255  if ($value['a_type'] == 18 && $dataType) {
256  // set credit account
257  $sqlReturn['accounts']['credit'][] = $value;
258  } else {
259  $sqlReturn['accounts']['loan'][] = $value;
260  }
261  }
262  } else {
263  $sqlReturn['accounts']['credit'] = array();
264  $sqlReturn['accounts']['loan'] = array();
265  }
266 
267  return $sqlReturn;
268 }
269 
270 /**
271  * @package MemberReadSettings
272  * @uses read rdc, billpay id and e-statement values for the
273  * selected member account.
274  *
275  * @param pEnv array: environment variable for debugging
276  * @param pDbh object: database access object
277  * @param pContext array: array of common data needed accross the member hub
278  *
279  * @return sqlReturn array: array of settings values
280  */
281 function MemberReadSettings($pEnv, $pDbh, $pContext) {
282  $cuTable = $pContext['cu_table'];
283  $cuCode = $pContext['cu_code'];
284  $cuMember = $pContext['m_account'];
285 
286  $sqlReturn = array();
287  $sqlColumns = "
288  TRIM(estmnt_flag) AS m_stmnt,
289  TRIM(billpayid) AS m_payid,
290  rdcsetting AS m_rdc";
291  $sqlSelect = "
292  SELECT $sqlColumns
293  FROM {$cuTable}memberacct ma
294  WHERE accountnumber = '$cuMember'";
295  $sqlSelectRs = db_query($sqlSelect, $pDbh);
296  if (!$sqlSelectRs) {
297  $pEnv['logger']->error(db_last_error());
298  throw new Exception("Failed to read member settings.");
299  }
300 
301  $sqlReturn['settings'] = db_fetch_all($sqlSelectRs)[0];
302  return $sqlReturn;
303 }
304 
305 /**
306  * @package MemberUpdateSettings
307  * @uses update rdc, bill pay id, e-statement and restrictions values
308  *
309  * @param pEnv array: environment variable for debugging
310  * @param pDbh object: database access object
311  * @param pContext array: array of common data needed accross the member hub
312  * @param pParameters array: array of values to update.
313  * @param $Cn The logged in user (for auditing)
314  *
315  * @return sqlReturn array: updated values
316  */
317 function MemberUpdateSettings($pEnv, $pDbh, $pContext, $pParameters, $Cn) {
318  $cuTable = $pContext['cu_table'];
319  $cuCode = $pContext['cu_code'];
320  $cuMember = $pContext['m_account'];
321 
322  $sqlReturn = array();
323  $sqlColumns = "";
324  $sqlValues = "";
325 
326  $updateArray = array("_action" => "update", "accountnumber" => $cuMember);
327 
328  // check which fields to update
329  if (HCU_array_key_exists("m_stmnt", $pParameters)) {
330  $column = $pParameters['m_stmnt'] ? trim($pParameters['m_stmnt']) : "";
331  $updateArray ["estmnt_flag"] = $column == "" ? null : $column;
332  $sqlReturn['message'][] = "eStatement Flag successfully updated.";
333  }
334 
335  if (HCU_array_key_exists("m_rdc", $pParameters)) {
336  $column = $pParameters['m_rdc'] ? trim($pParameters['m_rdc']) : "";
337  $updateArray ["rdcsetting"] = $column == "" ? null : $column;
338  $sqlReturn['message'][] = "RDC Setting successfully updated.";
339  }
340 
341  if (HCU_array_key_exists("m_restr", $pParameters)) {
342  $column = $pParameters['m_restr'] ? trim($pParameters['m_restr']) : "";
343  $updateArray ["restrictions"] = $column == "" ? null : $column;
344  $sqlReturn['message'][] = "Restrictions successfully updated.";
345  }
346 
347  // must update billpay on it's own because it must be unique in the database
348  if (HCU_array_key_exists("m_payid", $pParameters)) {
349  // 06-19: when there are records with empy values for billpayid, matching on empty
350  // input will throw the exception below, even if those records aren't associated
351  // with this member account. Added and clause to select to exclude empty values.
352  $sqlSelect = "
353  SELECT COUNT(billpayid)
354  FROM {$cuTable}memberacct
355  WHERE billpayid = '{$pParameters['m_payid']}'
356  AND billpayid <> '' AND billpayid is not null";
357  $sqlSelectRs = db_query($sqlSelect, $pDbh);
358  $sqlData = db_fetch_all($sqlSelectRs);
359  if ($sqlData[0]['count'] > 0) {
360  // notify of unable to update, must be unique billpayid
361  throw new Exception("Failed to update Bill Pay ID, the selected id already exists.");
362  }
363 
364  $column = $pParameters['m_payid'] ? trim($pParameters['m_payid']) : "";
365  $updateArray ["billpayid"] = $column == "" ? null : $column;
366  $sqlReturn['message'][] = "Bill Pay ID successfully updated.";
367  }
368 
369  $updateArray = array("memberacct" => array($updateArray));
370 
371  $context = "admin";
372  $script = "userSupport.prg";
373 
374  $sql = "select email from cuadminusers where user_name = '$Cn' and cu = '$cuCode'";
375  $sqls[] = $sql;
376  $sth = db_query($sql, $pDbh);
377  if (!$sth)
378  throw new exception("email query failed.", 7);
379  $email = db_fetch_row($sth)[0];
380 
381  if (!db_work ($pDbh, HOMECU_WORK_BEGIN))
382  throw new exception("begin query failed.", 32);
383 
384  $pEnv ["cu"] = $cuCode;
385 
386  if (DataUserTableUpdate($pDbh, $pEnv, null, $updateArray, 0, "A_UPD", $context, $script, "A", "Member Settings", $Cn, $email, trim($_SERVER["REMOTE_ADDR"]), false, $cuMember) === false) {
387  throw new exception ("Unable to update member settings.");
388  }
389 
390  if (!db_work ($pDbh, HOMECU_WORK_COMMIT))
391  throw new exception("commit query failed.", 32);
392 
393  $sql = "select accountnumber AS m_account, estmnt_flag AS m_stmnt, billpayid AS m_payid, rdcsetting AS m_rdc, restrictions AS m_restr
394  from ${cuTable}memberacct where accountnumber = '" . prep_save($cuMember, 12) . "'";
395 
396  $sth = db_query($sql, $pDbh);
397  if (!$sth) {
398  throw new exception ("Select query failed.");
399  }
400 
401  $sqlReturn['settings'] = db_fetch_assoc($sth, 0);
402  return $sqlReturn;
403 }
404 ?>
405 
406 <?php
407 /**
408  * @package PrintMemberSettings
409  * @uses print neccessary html/javascript to run the selected card
410  */
411 function PrintMemberSettings() { ?>
412 <style type="text/css">
413 .k-grid-content {
414  max-height: 165px;
415 }
416 </style>
417 <div id="settings">
418  <div id="status"></div>
419  <!--TABS: -->
420  <div class="container-fluid">
421  <div id="tabs"></div>
422  </div>
423 
424  <!--TAB VIEW: SECURITY-->
425  <div class="well well-sm col-sm-12" id="tabSecurity">
426  <div class="row">
427  <div class="col-xs-5 col-sm-4 col-md-3">
428  <label for="inpRestriction">
429  <span>Restrictions</span>
430  <span class="fa fa-asterisk" style="color: #f0ad4e;"
431  data-bind="visible: dirty"></span>
432  </label>
433  </div>
434 
435  <div class="col-xs-7 col-sm-4 col-md-3">
436  <input class="hcu-all-100" id="inpRestriction"
437  data-role="dropdownlist"
438  data-value-field="value"
439  data-text-field="text"
440  data-bind="
441  source: list,
442  value: source.e_restr,
443  events: { change: change }">
444  </div>
445  </div>
446  </div>
447 
448  <!--TAB VIEW: ACCOUNTS-->
449  <div class="well well-sm col-sm-12" id="tabAccounts">
450  <div data-bind="visible: showNoRecords">
451  <div class="hcu-secondary">
452  <div class="vsgSecondary">No Records Found</div>
453  </div>
454  </div>
455  <div data-bind="visible: showDeposit">
456  <h3>Deposit Accounts</h3><br>
457  <div id="depositGrid"
458  data-role="grid"
459  data-bind="source: deposit"
460  data-columns="[
461  { title: 'Accounts', columns: [
462  { field: 'a_type', title: 'Type', width: '150px' },
463  { field: 'a_desc', title: 'Name', width: '150px',
464  attributes: { 'class': 'showEllipsis' }
465  }
466  ]},
467  { title: 'May', columns: [
468  { field: 'm_withdraw', title: 'Withdraw', width: '90px',
469  template: '<span class=\'vsgSecondary\'># if (m_withdraw == \'t\') { # <div class=\'restriction allow readonly hcu-all-100\'><i class=\'fa fa-check\'></i></div> # } else { #<div class=\'restriction ban readonly hcu-all-100\'><i class=\'fa fa-ban\'></i></div> # } #</span>'
470  },
471  { field: 'm_deposit', title: 'Deposit', width: '90px',
472  template: '<span class=\'vsgSecondary\'># if (m_deposit == \'t\') { # <div class=\'restriction allow readonly hcu-all-100\'><i class=\'fa fa-check\'></i></div> # } else { #<div class=\'restriction ban readonly hcu-all-100\'><i class=\'fa fa-ban\'></i></div> # } #</span>'
473  },
474  ]},
475  <?php if ($GLOBALS['live'] == 'Y'): ?>
476  { title: 'Balance', columns: [
477  { field: 'b_stamp', title: 'Retrieved', width: '150px', },
478  { field: 'b_attempt', title: 'Attempted', width: '150px', }
479  ]},
480  { title: 'History', columns: [
481  { field: 'h_stamp', title: 'Retrieved', width: '150px', },
482  { field: 'h_attempt', title: 'Attempted', width: '150px', }
483  ]}
484  <?php endif; ?>
485  ]"></div>
486  </div>
487  &nbsp;
488  <div data-bind="visible: showLoan">
489  <h3>Loan Accounts</h3><br>
490  <div id="loanGrid"
491  data-role="grid"
492  data-bind="source: loan"
493  data-columns="[
494  { title: 'Accounts', columns: [
495  { field: 'a_type', title: 'Type', width: '150px', },
496  { field: 'a_desc', title: 'Name', width: '150px',
497  attributes: { 'class': 'showEllipsis' }
498  }
499  ]},
500  { title: 'May', columns: [
501  { field: 'm_addon', title: 'Add-on', width: '90px',
502  template: '<span class=\'vsgSecondary\'># if (m_addon == \'t\') { # <div class=\'restriction allow readonly hcu-all-100\'><i class=\'fa fa-check\'></i></div> # } else { #<div class=\'restriction ban readonly hcu-all-100\'><i class=\'fa fa-ban\'></i></div> # } #</span>'
503  },
504  { field: 'm_payment', title: 'Pay', width: '90px',
505  template: '<span class=\'vsgSecondary\'># if (m_payment == \'t\') { # <div class=\'restriction allow readonly hcu-all-100\'><i class=\'fa fa-check\'></i></div> # } else { #<div class=\'restriction ban readonly hcu-all-100\'><i class=\'fa fa-ban\'></i></div> # } #</span>'
506  }
507  ]},
508  <?php if ($GLOBALS['live'] == 'Y'): ?>
509  { title: 'Balance', columns: [
510  { field: 'b_stamp', title: 'Retrieved', width: '150px', },
511  { field: 'b_attempt', title: 'Attempted', width: '150px', }
512  ]},
513  { title: 'History', columns: [
514  { field: 'h_stamp', title: 'Retrieved', width: '150px', },
515  { field: 'h_attempt', title: 'Attempted', width: '150px', }
516  ]}
517  <?php endif; ?>
518  ]"></div>
519  </div>
520  &nbsp;
521  <div data-bind="visible: showCredit">
522  <h3>Credit Accounts</h3><br>
523  <div id="creditGrid"
524  data-role="grid"
525  data-bind="source: credit"
526  data-columns="[
527  { title: 'Accounts', columns: [
528  { field: 'a_type', title: 'Type', width: '150px' },
529  { field: 'a_desc', title: 'Name', width: '150px',
530  attributes: { 'class': 'showEllipsis' }
531  }
532  ]},
533  { title: 'May', columns: [
534  { field: 'm_addon', title: 'Add-on', width: '90px',
535  template: '<span class=\'vsgSecondary\'># if (m_addon == \'t\') { # <div class=\'restriction allow readonly hcu-all-100\'><i class=\'fa fa-check\'></i></div> # } else { #<div class=\'restriction ban readonly hcu-all-100\'><i class=\'fa fa-ban\'></i></div> # } #</span>'
536  },
537  { field: 'm_payment', title: 'Pay', width: '90px',
538  template: '<span class=\'vsgSecondary\'># if (m_payment == \'t\') { # <div class=\'restriction allow readonly hcu-all-100\'><i class=\'fa fa-check\'></i></div> # } else { #<div class=\'restriction ban readonly hcu-all-100\'><i class=\'fa fa-ban\'></i></div> # } #</span>'
539  }
540  ]},
541  <?php if ($GLOBALS['live'] == 'Y'): ?>
542  { title: 'Balance', columns: [
543  { field: 'b_stamp', title: 'Retrieved', width: '150px', },
544  { field: 'b_attempt', title: 'Attempted', width: '150px', }
545  ]},
546  { title: 'History', columns: [
547  { field: 'h_stamp', title: 'Retrieved', width: '150px', },
548  { field: 'h_attempt', title: 'Attempted', width: '150px', }
549  ]}
550  <?php endif; ?>
551  ]"></div>
552  </div>
553  </div>
554 
555  <!--TAB VIEW: SETTINGS-->
556  <div class="well well-sm col-sm-12" id="tabSettings">
557  <div class="row">
558  <div class="col-xs-5 col-sm-4 col-md-3">
559  <label for="inpEstmnt">
560  <span>eStatements</span>
561  <span class="fa fa-asterisk" style="color: #f0ad4e;"
562  data-bind="visible: source.e_dirty"></span>
563  </label>
564  </div>
565 
566  <div class="col-xs-7 col-sm-4 col-md-3">
567  <input id="inpEstmnt" type="checkbox" data-bind="checked: source.e_stmnt, events: { change: change }">
568  </div>
569  </div>
570  &nbsp;
571  <div class="row">
572  <div class="col-xs-5 col-sm-4 col-md-3">
573  <label for="inpRdc">
574  <span>RDC Setting</span>
575  <span class="fa fa-asterisk" style="color: #f0ad4e;"
576  data-bind="visible: source.e_dirty"></span>
577  </label>
578  </div>
579 
580  <div class="col-xs-5 col-sm-4 col-md-3">
581  <input id="inpRdc"
582  data-role="numerictextbox"
583  data-format="#"
584  data-decimals="0"
585  data-spinners="false"
586  data-max="2147483647"
587  data-min="0"
588  data-bind="
589  value: source.e_rdc,
590  events: { change: change }">
591  </div>
592  </div>
593  &nbsp;
594  <div class="row">
595  <div class="col-xs-5 col-sm-4 col-md-3">
596  <label for="inpBpay">
597  <span>Bill Pay ID</span>
598  <span class="fa fa-asterisk" style="color: #f0ad4e;"
599  data-bind="visible: source.e_dirty"></span>
600  </label>
601  </div>
602 
603  <div class="col-xs-7 col-sm-4 col-md-3">
604  <input id="inpBpay"
605  data-role="maskedtextbox"
606  data-mask="AAAAAAAAAAAA"
607  data-prompt-char=""
608  data-min="0"
609  data-bind="
610  value: source.e_payid,
611  events: { change: change }">
612  </div>
613  </div>
614  </div>
615 
616  <div class="bottomButtons">
617  <div class="hcu-edit-buttons k-state-default">
618  <span class="hcu-icon-delete">
619  </span>
620  <a href="##" id="lnkCancel">Cancel</a>
621  &ensp;
622  <a href="##" id="btnUpdate" class="k-button k-primary">
623  <i class="fa fa-check fa-lg"></i>
624  Update
625  </a>
626  </div>
627  </div>
628 </div>
629 
630 <div id="settingsCancel">
631  <p>This member's information has been changed.</p>
632  <p>Do you wish to discard the changes?</p>
633 </div>
634 
635 <?php
636 
637  // JQUERY PLUGIN FOR TABS: update from groupinfo
638  printTabPlugin();
639 /**
640  * @package MemberSettings
641  * @uses this object is used to display and interact with the member account settings feature.
642  *
643  * @var Init public: call to initialize data/view/action objects
644  * @var Open public: call to open the mamber search module/window
645  * @var Close public: call to close the member search module/window
646  * @var Data public: call to load payload and member display into
647  * MemberSettings object for later use.
648  *
649  * @var InitDataSources private: initialize all data sources/objects
650  * @var InitDataViews private: initialize all data views/objects
651  * @var InitDataActions private: initialize all user actions on html.
652  *
653  * @var EventOpenWindow private: open kendoDialog/kendoWindow objects
654  * @var EventCloseWindow private: close kendoDialog/kendoWindow objects
655  * @var EventPopWindow private: remove the correct window from the window stack.
656  *
657  * @var Event* private: other event functions explained by name.
658  * Some are entensions of kendo objects, others just help with events of html objects.
659  *
660  * @var DataBuild* private: these functions build up datasources for
661  * arrays, json objects and observables for use in manipulation and display.
662  *
663  * @var Validate* private: validation functions for forms, inputs, observables
664  * and any other data that could be altered.
665  */
666 ?>
667 <script type="text/javascript">
668 //# sourceURL=memberSettings.js
669 var MemberSettings = function() {
670  var maLive = <?php echo json_encode($GLOBALS['live']); ?>;
671  var maCardContainer = null;
672  var maCardWindows = null;
673 
674  var maPayload = null;
675  var maMember = null;
676  var maCall = null;
677  var maAction = null;
678 
679  var maSettings = null;
680  var maCancel = null;
681  var maUpdate = null;
682 
683  var maDataSource = null;
684 
685  var maTabs = null;
686  var maTabSettings = null;
687  var maDataSettings = null;
688  var maObserveSettings = null;
689 
690  var maTabAccounts = null;
691  var maDataAccounts = null;
692  var maObserveAccounts = null;
693  var maTooltipAccounts = null;
694 
695  var maTabSecurity = null;
696  var maDataSecurity = null;
697  var maListSecurity = null;
698  var maObserveSecurity = null;
699 
700  var maDiscard = null;
701 
702  var ValidateSettings = function() {
703  var label = null;
704  var warning = null;
705  var source = maObserveSettings.source;
706 
707  // validate e statement field
708  label = $("label[for=inpEstmnt]");
709  warning = $(label.find("span")[1]);
710  if (source.e_stmnt != source.o_stmnt) {
711  warning.show();
712  } else {
713  warning.hide();
714  }
715 
716  // validate rdc field
717  label = $("label[for=inpRdc]");
718  warning = $(label.find("span")[1]);
719  if (source.e_rdc != source.o_rdc) {
720  warning.show();
721  } else {
722  warning.hide();
723  }
724 
725  // validate billpay id field
726  label = $("label[for=inpBpay]");
727  warning = $(label.find("span")[1]);
728  if (source.e_payid != source.o_payid) {
729  warning.show();
730  } else {
731  warning.hide();
732  }
733 
734  source.e_dirty =
735  (source.e_stmnt != source.o_stmnt) ||
736  (source.e_rdc != source.o_rdc) ||
737  (source.e_payid != source.o_payid);
738 
739  return !source.e_dirty;
740  }
741 
742  var ValidateSecurity = function() {
743  var label = null;
744  var warning = null;
745  var source = maObserveSecurity.source;
746 
747  // validate restriction field
748  label = $("label[for=inpRestriction]");
749  warning = $(label.find("span")[1]);
750 
751  var value_e = null;
752  var value_o = source.o_restr;
753  if (source.e_restr) {
754  if (typeof source.e_restr == "string") {
755  value_e = source.e_restr;
756  } else {
757  value_e = source.e_restr.value;
758  }
759  } else {
760  value_e = "";
761  }
762 
763  source.e_dirty = value_e != value_o;
764  if (value_e != value_o) {
765  warning.show();
766  } else {
767  warning.hide();
768  }
769 
770  return !source.e_dirty;
771  }
772 
773  var DataBuildSettings = function(data) {
774  maDataSettings = {
775  o_payid: data.m_payid,
776  o_stmnt: data.m_stmnt == "Y" ? true : false,
777  o_rdc: data.m_rdc ? parseInt(data.m_rdc) : null,
778  e_payid: data.m_payid,
779  e_stmnt: data.m_stmnt == "Y" ? true : false,
780  e_rdc: data.m_rdc ? parseInt(data.m_rdc) : null,
781  e_dirty: false
782  };
783 
784  maObserveSettings.set("source", maDataSettings);
785  }
786 
787  var DataBuildAccounts = function(data) {
788  if (data.deposit) {
789  maObserveAccounts.set("deposit", data.deposit);
790  maObserveAccounts.set("showDeposit", data.deposit.length > 0);
791  }
792 
793  if (data.loan) {
794  maObserveAccounts.set("loan", data.loan);
795  maObserveAccounts.set("showLoan", data.loan.length > 0);
796  }
797 
798  if (data.credit) {
799  maObserveAccounts.set("credit", data.credit);
800  maObserveAccounts.set("showCredit", data.credit.length > 0);
801  }
802 
803  if (data.deposit.length == 0 && data.loan.length == 0 && data.credit.length == 0) {
804  maObserveAccounts.set("showNoRecords", true);
805  }
806  }
807 
808  var DataBuildSecurity = function() {
809  maListSecurity = [
810  { text: "Locked", value: "L" },
811  { text: "Read Only", value: "R" },
812  { text: "Unlocked", value: "" }
813  ];
814 
815  maDataSecurity = {
816  o_restr: maMember.m_restr,
817  e_restr: maMember.m_restr,
818  e_dirty: false
819  };
820 
821  maObserveSecurity.set("source", maDataSecurity);
822  maObserveSecurity.set("list", maListSecurity);
823  }
824 
825  var EventUpdateMember = function() {
826 
827  if (!maTabs.validate()) {
828  var sourceSettings = maObserveSettings.source;
829  var sourceSecurity = maObserveSecurity.source;
830  var memberData = {};
831 
832  // check for update to e statements
833  if (sourceSettings.e_stmnt != sourceSettings.o_stmnt) {
834  memberData.m_stmnt = sourceSettings.e_stmnt;
835  }
836 
837  // check for update to bill pay id
838  if (sourceSettings.e_payid != sourceSettings.o_payid) {
839  memberData.m_payid = sourceSettings.e_payid;
840  }
841 
842  // check for update to rdc setting
843  if (sourceSettings.e_rdc != sourceSettings.o_rdc) {
844  memberData.m_rdc = sourceSettings.e_rdc;
845  }
846 
847  // check for update to restrictions
848  var value_e = null;
849  if (sourceSecurity.e_restr) {
850  if (typeof sourceSecurity.e_restr == "string") {
851  value_e = sourceSecurity.e_restr;
852  } else {
853  value_e = sourceSecurity.e_restr.value;
854  }
855  } else {
856  value_e = "";
857  }
858 
859  if (sourceSecurity.e_dirty) {
860  memberData.m_restr = value_e;
861  }
862 
863  var stringData = JSON.stringify(memberData);
864  var memberRequest = {
865  operation: "memberUpdateSettings",
866  payload: maPayload,
867  mParameters: stringData
868  };
869 
870  maDataSource.transport.options.read.type = "POST";
871  maDataSource.read(memberRequest);
872  }
873  }
874 
875  var EventOpenWindow = function(e) {
876  var windowElement = this.element[0];
877  var windowId = windowElement.id;
878 
879  switch (windowId) {
880 
881  }
882 
883  maCardWindows.push(this);
884  }
885 
886  var EventCloseWindow = function(e) {
887  var windowElement = this.element[0];
888  var windowId = windowElement.id;
889 
890  switch (maAction) {
891  case "discardConfirm":
892  EventPopWindow(windowId);
893 
894  var sourceSettings = maObserveSettings.source;
895  var sourceSecurity = maObserveSecurity.source;
896  // reset settings
897  sourceSettings.e_stmnt = sourceSettings.o_stmnt;
898  sourceSettings.e_rdc = sourceSettings.o_rdc;
899  sourceSettings.e_payid = sourceSettings.o_payid;
900  sourceSettings.e_dirty = false;
901 
902  // reset security
903  sourceSecurity.e_restr = sourceSecurity.o_restr;
904  sourceSecurity.e_dirty = false;
905 
906  // must set action to null to avoid infinite loop
907  // if not null it will continue to drop into
908  // this case and call close until stack overflow
909  maAction = null;
910  maSettings.close();
911  break;
912  default:
913  if (windowId == "settings") {
914  if (!maTabs.validate()) {
915  e.preventDefault();
916  maDiscard.open();
917  } else {
918  EventPopWindow(windowId);
919  // setup validator, send back to hub
920  $.homecuValidator.setup({
921  formStatusField: "formStatus",
922  formValidate: "cardContainerDiv"
923  });
924  }
925  } else {
926  EventPopWindow(windowId);
927  }
928  break;
929  }
930 
931  maAction = null;
932  }
933 
934  var EventPopWindow = function(windowId) {
935  var popIndex = -1;
936  for (var i = 0; i < maCardWindows.length; i++) {
937  var openWindow = maCardWindows[i].element[0];
938  var openId = openWindow.id;
939 
940  if (openId == windowId) {
941  popIndex = i;
942  break;
943  }
944  }
945 
946  if (popIndex > -1) {
947  maCardWindows.splice(popIndex, 1);
948  }
949  }
950 
951  var InitDataSources = function() {
952  maDataSource = new kendo.data.DataSource({
953  transport: {
954  read: {
955  url: "main.prg",
956  dataType: "json",
957  contentType: "application/x-www-form-urlencoded",
958  type: "GET",
959  data: {
960  ft: "103104"
961  },
962  cache: false
963  }
964  },
965  requestStart: function(request) {
966  showWaitWindow();
967  //InfoClear();
968  },
969  requestEnd: function(response) {
970  setTimeout(hideWaitWindow, 500);
971 
972  if (response.hasOwnProperty("response")) {
973  if (response.response.hasOwnProperty("Results")) {
974  var results = response.response.Results;
975 
976  if (results.hasOwnProperty("errors")) {
977  $.homecuValidator.homecuResetMessage = true;
978  $.homecuValidator.displayMessage(results.errors, $.homecuValidator.settings.statusError);
979  } else if (results.hasOwnProperty("info")) {
980  $.homecuValidator.homecuResetMessage = true;
981  $.homecuValidator.displayMessage(results.info, $.homecuValidator.settings.statusSuccess);
982  }
983  } else {
984  $.homecuValidator.displayMessage("Error Parsing Server", $.homecuValidator.settings.statusError);
985  }
986  } else {
987  $.homecuValidator.displayMessage("Error Parsing Server", $.homecuValidator.settings.statusError);
988  }
989  },
990  schema: {
991  parse: function(response) {
992 
993  var results = null;
994  var resultData = null;
995  var resultOperation = null;
996 
997  if (response.hasOwnProperty("Results")) {
998  results = response.Results;
999  resultData = results.data;
1000  resultOperation = results.operation;
1001  }
1002 
1003  if (results.hasOwnProperty("errors")) {
1004  return [];
1005  }
1006 
1007  if (resultData == undefined || resultData == null) {
1008  return [];
1009  }
1010 
1011  setTimeout(function() {
1012  switch (resultOperation) {
1013  case "memberReadSettings":
1014  DataBuildSettings(resultData.settings);
1015  DataBuildAccounts(resultData.accounts);
1016  DataBuildSecurity();
1017  //InfoClear();
1018  maMember.cardTitle= "Account Settings";
1019  var template= kendo.template($("#titleTemplate").html());
1020  maSettings.title(template(maMember)).center().open();
1021  break;
1022  case "memberUpdateSettings":
1023  maMember = resultData.member.member;
1024  maMember.m_account = maMember.m_account == null ? null : maMember.m_account.trim();
1025  maMember.m_stmnt = maMember.m_stmnt == null ? null : maMember.m_stmnt.trim();
1026  maMember.m_payid = maMember.m_payid == null ? null : maMember.m_payid.trim();
1027  maMember.m_rdc = maMember.m_rdc == null ? null : maMember.m_rdc;
1028  maMember.m_restr = maMember.m_restr == null ? null : maMember.m_restr.trim();
1029 
1030  maCall("updateMemberInfo", resultData.member);
1031  maCall("updateMemberEncrypt", resultData.encrypt);
1032 
1033  DataBuildSettings(maMember);
1034  DataBuildSecurity();
1035 
1036  // revalidate to remove flags
1037  maTabs.validate();
1038  break;
1039  }
1040  }, 500);
1041 
1042  return [];
1043  }
1044  }
1045  });
1046  }
1047 
1048  var InitDataViews = function() {
1049  maSettings = maCardContainer.find("#settings").kendoWindow({
1050  title: "Member Settings",
1051  minWidth: "75%",
1052  maxWidth: "90%",
1053  width: 500,
1054  modal: true,
1055  visible: false,
1056  resizable: false,
1057  activate: EventOpenWindow,
1058  close: EventCloseWindow,
1059  open: function() {
1060  this.wrapper.css({ top: 100 });
1061  }
1062  }).data("kendoWindow");
1063 
1064  maCancel = $("#lnkCancel");
1065  maUpdate = $("#btnUpdate");
1066 
1067  maTabSettings = $("#tabSettings");
1068  maTabAccounts = $("#tabAccounts");
1069  maTabSecurity = $("#tabSecurity");
1070  maTabs = $("#tabs").hcuTabs({
1071  tabs: [
1072  { title: "Settings", text: "Settings", icon: "fa-check", selected: true, content: maTabSettings, validate: ValidateSettings },
1073  { title: "Accounts", text: "Sub-Accounts", icon: "fa-info-circle", content: maTabAccounts },
1074  { title: "Security", text: "Security", icon: "fa-lock", content: maTabSecurity, validate: ValidateSecurity }
1075  ],
1076  select: function(e) {
1077  maSettings.center();
1078  maSettings.wrapper.css({ top: 100 });
1079  },
1080  footer: $(".bottomButtons")
1081  });
1082 
1083  maObserveSettings = new kendo.observable({
1084  source: null,
1085  change: function() {
1086  maTabs.validate();
1087  }
1088  });
1089 
1090  maObserveAccounts = new kendo.observable({
1091  deposit: [],
1092  load: [],
1093  credit: [],
1094  showDeposit: false,
1095  showLoan: false,
1096  showCredit: false,
1097  showNoRecords: false,
1098  });
1099 
1100  maObserveSecurity = new kendo.observable({
1101  list: [],
1102  source: null,
1103  change: function() {
1104  maTabs.validate();
1105  }
1106  });
1107 
1108  kendo.bind(maTabSettings, maObserveSettings);
1109  kendo.bind(maTabAccounts, maObserveAccounts);
1110  kendo.bind(maTabSecurity, maObserveSecurity);
1111 
1112  // USE THIS TO SELECT OVERFLOW IN JQUERY SELECTORS FOR TOOLTIP BELOW
1113  jQuery.extend(jQuery.expr[':'], {
1114  overflown: function (el) {
1115  return el.offsetHeight < el.scrollHeight || el.offsetWidth < el.scrollWidth;
1116  }
1117  });
1118 
1119  maTooltipAccounts = homecuTooltip.defaults;
1120  maTooltipAccounts.filter = ".showEllipsis:overflown, .vsgDisabled";
1121  maTooltipAccounts.content = function(e) {
1122  return $(e.target).text().trim();
1123  }
1124  $("#depositGrid").kendoTooltip(maTooltipAccounts);
1125  $("#loanGrid").kendoTooltip(maTooltipAccounts);
1126  $("#creditGrid").kendoTooltip(maTooltipAccounts);
1127 
1128  maDiscard = $("#settingsCancel").kendoDialog({
1129  title: "Discard Changes",
1130  modal: true,
1131  visible: false,
1132  resizable: false,
1133  minWidth: 300,
1134  maxWidth: 500,
1135  show: EventOpenWindow,
1136  close: EventCloseWindow,
1137  actions: [
1138  { text: "No",
1139  action: function() { maAction = "discardDeny"; }
1140  },
1141  { text: "Yes", primary: true,
1142  action: function() { maAction = "discardConfirm"; }
1143  }
1144  ]
1145  }).data("kendoDialog");
1146  }
1147 
1148  var InitDataActions = function() {
1149  maUpdate.on("click", EventUpdateMember);
1150  maCancel.on("click", function() {
1151  maSettings.close();
1152  });
1153  }
1154 
1155  var InitWindowStack = function() {
1156 
1157  }
1158 
1159  this.Open = function(windowStack) {
1160 
1161  // setup validator
1162  $.homecuValidator.setup({
1163  formStatusField: "status",
1164  formValidate: "settings"
1165  });
1166 
1167  maCardWindows = windowStack;
1168  var memberRequest = {
1169  operation: "memberReadSettings",
1170  payload: maPayload
1171  };
1172 
1173  maDataSource.transport.options.read.type = "POST";
1174  maDataSource.read(memberRequest);
1175  }
1176 
1177  this.Close = function() {
1178  maSettings.destroy();
1179  }
1180 
1181  this.Data = function(payload, member) {
1182  maPayload = payload;
1183  maMember = member;
1184  }
1185 
1186  this.Init = function(hubCall, cardContainer) {
1187  maCall = hubCall;
1188  maCardContainer = cardContainer;
1189 
1190  InitDataSources();
1191  InitDataViews();
1192  InitDataActions();
1193 
1194  maCall("AccountSettings", this);
1195  }
1196 }
1197 </script>
1198 <?php }