Odyssey
hcuStatementStop.prg
1 <?php
2  /*
3  * File: hcuStatementStop.prg
4  *
5  * Purpose: To allow the member to stop electronic statements and provide a reason, all in one step.
6  *
7  * NOTE: The starting of E-Statements is done through the hcuStatement page.
8  *
9  */
10 
11  // ** Chicken and egg. The HomeCU Functions won't exist until after the inclusion of hcuService but the includes should be used.
12  // * Because require_once is used in hcuService we should be fine using it here
13  require_once(dirname(__FILE__) . '/../../shared/library/dms_imp_val.i');
14  require_once(dirname(__FILE__) . '/../../shared/library/hcuCommon.i');
15 
16  $string= array("filter" => FILTER_DEFAULT);
17  $actualString= array("filter" => FILTER_SANITIZE_STRING);
18 
19  $parameters= array("a" => array("action" => ""));
20  HCU_ImportVars($parameters, "a", array("action" => $actualString));
21  extract($parameters["a"]);
22 
23  if ($action === "esTermsStop" ) {
24 
25  // Note: this expects a message in $HB_ENV["HCUPOST"]["stop_reason"];
26  try {
27 
28  $serviceShowInfo = false;
29  $serviceLoadMenu = false;
30  $serviceShowMenu = false;
31 
32  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
33  require_once(dirname(__FILE__) . '/../library/hcuService.i');
34 
35  /*
36  * ** CHECK USER FEATURE PERMISSIONS **
37  * NOTE: DO NOT AUTO-REDIR. Handle perm error here
38  */
39  if (!PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_ESTATEMENTS, '', false)) {
40  throw new Exception (HCU_JsonEncode($MC->msg('Rights not set', HCU_DISPLAY_AS_HTML)));
41  }
42 
43  $SPEEDBUMP_FEATURE = "ES";
44  require_once(dirname(__FILE__) . '/../includes/hcuAccountSelector.i');
45  $Ca = $HB_ENV["selected_account"];
46 
47  HCU_ImportVars($HB_ENV, "HCUPOST", array("stop_reason" => $string, "account" => $string, "formTerms" => $string, "termsAgree" => $string, "cu" => $string));
48 
49  $account= HCU_array_key_exists("account", $HB_ENV["HCUPOST"]) ? trim($HB_ENV["HCUPOST"]["account"]) : "";
50  $account= $account == "" ? "" : "&account=$account";
51 
52  $retStatus_ary = Array(
53  'homecuInfo' => '',
54  'homecuErrors' => Array(),
55  'homecuData' => ''
56  );
57 
58  if ( strlen( $HB_ENV['HCUPOST']['formTerms'] ) > 0 &&
59  $HB_ENV['HCUPOST']['termsAgree'] == "Y" ) {
60  // ** Decode the formTerms value
61  $formTermsAry= HCU_PayloadDecode($HB_ENV["Cu"], $HB_ENV['HCUPOST']['formTerms']);
62 
63  // Add Error Code
64  if ( $formTermsAry['formTimeExpire'] > mktime() &&
65  $formTermsAry['formView'] == "stop" ) {
66  // ** We are good, post it all
67  $HB_ENV['esProcessMode'] = $formTermsAry['formView'];
68  //$HB_ENV["HCUPOST"]["stop_reason"] has the stop reason
69  $esResults = Post_CUEStmt($dbh, $HB_ENV, $MC, $Ca);
70  // check for errors
71  if ( $esResults["status"]["code"] == "000" ) {
72  /*
73  * Prepare for returning the data
74  */
75  $retStatus_ary['homecuInfo'] = $esResults["homecuInfo"];
76 
77  // ** Look up the Current Terms for the Credit Union
78  $esTermsArray = Get_NoticeInfo($dbh, $HB_ENV, $MC, 'D', "esTermsStop");
79 
80  // build up a response to the notice so the member doesn't see again
81  $HB_ENV["HCUPOST"]["notice_type"] = "C";
82  $HB_ENV["HCUPOST"]["notice_id"] = intval($esTermsArray['notice'][0]['notice_id']); // 8
83  $HB_ENV["HCUPOST"]["notice_device"] = "M"; // mobile
84  $HB_ENV["HCUPOST"]["notice_response"] = array( "answer" => 1 ); // something non-zero but numeric
85  $HB_ENV["HCUPOST"]["notice_cancel"] = "0";
86  $HB_ENV["HCUPOST"]["notice_accountnumber"] = $Ca;
87 
88  $results = Update_NoticeInfo($dbh, $HB_ENV, $MC);
89 
90  if ($results["status"]["code"] !== "000") {
91  throw new exception ($results["status"]["errors"]);
92  }
93 
94  } else {
95  if (is_array($esResults['status']['errors'])) {
96  // ** Just show the first
97  $postError = $esResults['status']['errors'][0];
98  } else {
99  $postError = $esResults['status']['errors'];
100  }
101  throw new Exception($postError, 999); // Maybe not go back to account screen?
102  }
103  } else {
104  // ** Time expired
105  throw new Exception($MC->msg('Feature Unavailable', HCU_DISPLAY_AS_RAW));
106  }
107  } else {
108  throw new Exception($MC->msg('Feature Unavailable', HCU_DISPLAY_AS_RAW));
109  }
110  } catch (Exception $ex) {
111 
112  // ** Add the Error to the list of errors to return
113  if ($ex->getMessage() != '') {
114  $retStatus_ary['homecuErrors'][] = $ex->getMessage();
115  }
116 
117  }
118 
119  header('Content-type: application/json');
120  $retStatusJson = HCU_JsonEncode($retStatus_ary);
121  print $retStatusJson;
122  exit;
123  }
124 
125  // ** SET SCRIPT LEVEL VARIABLES
126  $serviceShowInfo = true;
127  $serviceLoadMenu = true;
128  $serviceShowMenu = true;
129  $serviceShowBanner = true;
130  $serviceAllowReadonly = true;
131 
132  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
133  require_once(dirname(__FILE__) . '/../library/hcuService.i');
134 
135 
136  /*
137  * ** CHECK USER FEATURE PERMISSIONS **
138  * NOTE: DOES NOT RETURN ON FAILURE
139  */
140  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_ESTATEMENTS);
141 
142  $SPEEDBUMP_FEATURE = "ES";
143  require_once(dirname(__FILE__) . '/../includes/hcuAccountSelector.i');
144  $Ca = $HB_ENV["selected_account"];
145 
146  HCU_ImportVars($HB_ENV, "HCUPOST", array("cu" => $string, "formView" => $string, "formTerms" => $string, "formAction" => $string, "account" => $string));
147 
148  $account = HCU_array_key_exists("account", $HB_ENV["HCUPOST"]) ? trim($HB_ENV["HCUPOST"]["account"]) : "";
149  $account = $account == "" ? "" : "&account=$account";
150 
151  // ** INSERT BUSINESS LOGIC FOR THIS FORM
152  $Cu = $HB_ENV["Cu"];
153  $Cn = $HB_ENV["Cn"];
154  $chome = $HB_ENV["chome"];
155  $Flang = $HB_ENV["Flang"];
156 
157  $serviceMenuScript = 'hcuStatement';
158  // ** INCLUDE PRE CONTENT SCRIPT
159  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
160 
161  try {
162  /*
163  * ** VERIFY CU IS SETUP**
164  */
165  $retCUStatus = Get_EstmtEnrollStatus($dbh, $HB_ENV, $MC, $Ca);
166  if (!$retCUStatus['status']['code'] == '999') {
167  if ($retCUStatus['status']['errors'][0] != '') {
168  $errMsg = $retCUStatus['status']['errors'][0];
169  } else {
170  $errMsg = $pMC->msg('Contact CU', HCU_DISPLAY_AS_RAW);
171  }
172  throw new Exception($errMsg, 1);
173  }
174 
175  // ** Create an array with the formview and a time expires of ONE day
176  $setOptionsArray = Array("formView" => "stop", "formTimeExpire" => mktime() + 86400);
177  $setFormTerms = HCU_PayloadEncode($Cu, $setOptionsArray);
178 
179  // ** Look up the Current Terms for the Credit Union
180  $esTermsArray = Get_NoticeInfo($dbh, $HB_ENV, $MC, 'D', "esTermsStop");
181 
182  // ** Check to make sure the Terms are returned.
183  // * some sort of terms MUST be returned
184  if ($esTermsArray['status']['code'] != '000' || count($esTermsArray["notice"]) == 0 || $esTermsArray['notice'][0]['notice_text'] == '') {
185  // ** ERROR
186  throw new Exception($MC->msg('Feature Not Set', HCU_DISPLAY_AS_HTML) . '. ' . $MC->msg('Contact CU', HCU_DISPLAY_AS_HTML), 2);
187  }
188 
189  $cbAnswer = $esTermsArray["notice"][0]["notice_answers"][0]["answer_text"];
190  ?>
191  <script type="text/javascript">
192  $(document).ready(function() {
193  var kendoWindow = $("<div />").kendoWindow({
194  visible:false,
195  title: "<?php echo $MC->msg("Complete", HCU_DISPLAY_AS_JS) ?>",
196  resizable: false,
197  modal: true,
198  draggable: false,
199  actions: [],
200  close: function() {
201  return false;
202  }
203  });
204 
205  homecuTooltip.reset();
206  homecuTooltip.bind({ systemEmail: "<?php echo $MC->msg("Use MemberSettings", HCU_DISPLAY_AS_JS); ?>" });
207 
208  $.homecuValidator.setup({formValidate: "esForm", formErrorTitle: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>", validateOnClick:"btnPositive"});
209 
210  $('#btnPositive').click(function() {
211  if ($.homecuValidator.homecuValidate) {
212  ShowWaitWindow();
213 
214  $.post("hcuStatementStop.prg?cu=<?php echo $HB_ENV['cu']; ?><?php echo $account; ?>", $('#esForm').serialize(),
215  function(data) {
216  try {
217 
218  var NoticeResp,
219  RequestSuccessful = false;
220  // ** eval json data
221  NoticeResp = data;
222 
223  CloseWaitWindow();
224 
225  // ** Check the length of errors -- first check existence
226  if (NoticeResp['homecuErrors']) {
227 
228  if (NoticeResp['homecuErrors'].length > 0) {
229  // Post FAILED
230  $.homecuValidator.displayMessage(NoticeResp['homecuErrors'], $.homecuValidator.settings.statusError);
231  RequestSuccessful = false;
232  }
233  }
234 
235  // ** Check the length of Info
236  if (NoticeResp['homecuInfo'] && !RequestSuccessful) {
237  // ** Info must have value to continue
238  if (NoticeResp['homecuInfo'].length > 0) {
239  // ** SUCCESS
240 
241  $('#formTerms').val('');
242  $('#postResponse').html(NoticeResp['homecuInfo']);
243  kendoWindow.data("kendoWindow").content($('#submitResponse').html()).center().open();
244  RequestSuccessful = true;
245  }
246  }
247  if (!RequestSuccessful) {
248  // * Nothing was processed
249  throw '<?php echo $MC->msg('Bill Pay Error', HCU_DISPLAY_AS_JS); ?>';
250  }
251  } catch (err) {
252  // * There seems to be a syntax error of sorts.
253  $.homecuValidator.displayMessage(err, $.homecuValidator.settings.statusError);
254  kendoWindow.data("kendoWindow").close();
255  }
256  }, 'json')
257  .done (function (data) {
258  // * NOTHING TO DO ?
259  })
260  .fail(function(jqXHR, textStatus) {
261  // ** This is a more FATAL type error
262  $.homecuValidator.displayMessage('<?php echo $MC->msg('problem encountered', HCU_DISPLAY_AS_JS); ?>', $.homecuValidator.settings.statusError);
263  $('#formTerms').val('');
264  CloseWaitWindow();
265  });
266  }
267  });
268 
269  // start with button disabled
270  var btnPositive = $("#btnPositive").kendoButton({
271  enable: false,
272  click: function(e) {
273  if ( $("#stop_reason").val().length === 0 ) {
274  btnPositive.enable(false);
275  return false;
276  }
277  }
278  }).data("kendoButton");
279 
280  $("#termsAgree").click( function() {
281  EnablePositiveBtn();
282  });
283 
284  $("#stop_reason").keyup( function() {
285  EnablePositiveBtn();
286  });
287 
288  function EnablePositiveBtn() {
289  if ( $("#stop_reason").val().length === 0 || !$("#termsAgree").prop("checked") ) {
290  btnPositive.enable(false);
291  } else {
292  btnPositive.enable(true);
293  }
294  }
295  });
296  </script>
297  <div class='k-content container-fluid' id="profile" style="max-width:500px;" >
298  <form id='esForm' NAME='esForm' class='formInputx' ACTION='<?php echo $HB_ENV['loginpath'] . "/" . $HB_ENV['currentscript'] . "?" . $HB_ENV['cuquery']; ?><?php echo $account; ?>'
299  METHOD='POST'>
300  <input type='hidden' id='formTerms' name='formTerms' value='<?php echo $setFormTerms ?>'>
301  <INPUT TYPE='hidden' NAME='action' VALUE='esTermsStop'>
302 
303  <div class="row">
304  <div class="col-xs-12">
305  <fieldset>
306  <div class="well">
307  <div style="max-height: 400px;overflow: auto">
308  <?php if ($account != "") { ?>
309  <h4><?php echo $MC->msg("Account #", HCU_DISPLAY_AS_HTML) . $Ca; ?></h4>
310  <?php } ?>
311  <h3><?php echo $MC->msg("E-STATEMENT STOP REQUEST", HCU_DISPLAY_AS_HTML) ?></h3>
312  <?php echo $esTermsArray['notice'][0]['notice_text']; ?>
313  </div>
314  </div>
315  </fieldset>
316 
317  </div>
318  <div class="col-xs-12">
319  <fieldset>
320  <div style="margin:10px 0;">
321  <input required type="checkbox"
322  name="termsAgree"
323  id="termsAgree"
324  value="Y"
325  validationMessage="<?php echo $MC->msg('REQUIRED FIELDS', HCU_DISPLAY_AS_HTML) ?>">
326  <?php echo $cbAnswer ?><span class="k-invalid-msg" data-for="termsAgree"></span>
327  </div>
328  </fieldset>
329 
330  </div>
331  <div class="col-xs-12">
332  <fieldset>
333  <div class='field-label-wrapper'>
334  <label for="stop_reason"><?php echo $MC->msg('Why Stop', HCU_DISPLAY_AS_HTML) ?>: </label>
335  </div>
336  <textarea required id='stop_reason' name='stop_reason' rows='4' cols='40' wrap="virtual" class='k-textbox' style='width:100%; max-width:450px;' validationMessage="<?php echo $MC->msg('REQUIRED FIELDS', HCU_DISPLAY_AS_HTML) ?>"></textarea>
337  </fieldset>
338 
339  </div>
340  <div class="col-xs-12">
341  <hr/>
342  </div>
343  <div class="col-xs-12 col-sm-6 hcu-xs-btn-margin-top">
344  <button id='btnNegative' onclick="document.location='<?php echo $HB_ENV['loginpath'] . "/hcuStatement.prg?" . $HB_ENV['cuquery']; ?><?php echo $account; ?>'" name='btnNegative' type="button" class="k-button" style="width:100%;"><span class="fa fa-times"></span>&nbsp;<?php print $esTermsArray['notice'][0]['notice_negative_caption']; ?></button>
345  </div>
346  <div class="col-xs-12 col-sm-6 hcu-xs-btn-margin-top" style='text-align:right'>
347  <?php if ($esTermsArray['notice'][0]['notice_positive_caption'] != ''): ?>
348  <button id='btnPositive' name='btnPositive' type="button" class="k-button" style="width:100%;"><span class="fa fa-check"></span>&nbsp;<?php print $esTermsArray['notice'][0]['notice_positive_caption']; ?></button>
349  <?php endif; ?>
350  </div>
351  </div>
352  </form>
353  </div>
354  <div id='submitResponse' style='display:none;'>
355  <div class='k-block'>
356  <div class='k-header k-shadow' style="text-align:center"><?php echo $MC->msg('Credit Union responded', HCU_DISPLAY_AS_HTML); ?> <span id="displayStatus"></span></div>
357  <br/>
358  <span id='postResponse'><?php echo $MC->msg('Thank you your request will be sent', HCU_DISPLAY_AS_HTML); ?></span>
359  <br/>
360  </div>
361  <br/>
362  <button type="button" id="btnContinue" name="btnContinue" onclick="window.location='<?php echo $HB_ENV['loginpath'] . "/hcuAccounts.prg?" . $HB_ENV['cuquery']; ?>'" class="k-button"><span class="fa fa-arrow-right"></span>&nbsp;<?php echo $MC->msg('Continue', HCU_DISPLAY_AS_HTML); ?></button>
363  </div>
364  <br/>
365 
366  <?php
367  } catch (Exception $err) {
368  // ** Handle Errors on this screen
369 
370 ?>
371  <div class='formContent'>
372  <div class="row">
373  <div class="col-xs-12">
374  <div class="" style="max-height: 600px;overflow: auto">
375  <?php echo $err->getMessage(); ?>
376  </div>
377  </div>
378  <div class="col-xs-12">
379  <hr/>
380  </div>
381  <div class="col-xs-12">
382  <button id='btnNegative' onclick="document.location='<?php echo $HB_ENV['loginpath'] . "/hcuAccounts.prg?" . $HB_ENV['cuquery']; ?>'" name='btnNegative' type="button" class="k-button"><span class="fa fa-arrow-right"></span>&nbsp;<?php echo $MC->msg('Continue', HCU_DISPLAY_AS_HTML); ?></button>
383  </div>
384  </div>
385  </div>
386 <?php
387 
388  }
389 
390 ?>
391 <?php
392  /*
393  * ** END CONTENT
394  */
395 
396 
397  // ** INCLUDE POST CONTENT SCRIPT
398  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');