Odyssey
hcuStatement.prg
1 <?php
2  /*
3  * File: hcuStatement.prg
4  *
5  * Purpose: To allow the member to set up, discontinue, or see electronic statements.
6  *
7  */
8 
9 
10  // ** SET SCRIPT LEVEL VARIABLES
11  $serviceShowInfo = true;
12  $serviceLoadMenu = true;
13  $serviceShowMenu = true;
14  $serviceAllowReadonly = true;
15 
16  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
17  require_once(dirname(__FILE__) . '/../library/hcuService.i');
18 
19  /*
20  * ** CHECK USER FEATURE PERMISSIONS **
21  * NOTE: DOES NOT RETURN ON FAILURE
22  */
23  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_ESTATEMENTS);
24  $SPEEDBUMP_FEATURE = "ES";
25  require_once(dirname(__FILE__) . '/../includes/hcuAccountSelector.i');
26  $Ca = $HB_ENV["selected_account"];
27 
28  $string= array("filter" => FILTER_DEFAULT);
29  $parameters = array("a" => array("action" => "", "st_id" => "", "account" => ""));
30  HCU_ImportVars($parameters, "a", array("action" => $string, "st_id" => $string, "account" => $string));
31  extract($parameters["a"]);
32 
33  $account = isset($account) ? trim($account) : "";
34  $account = $account == "" ? "" : "&account=$account";
35 
36  $startStopMessage = ""; // Prevent console complaint.
37 
38  $errorMessage = "";
39  if ($action == "statement" ) {
40  // get the pdf
41  $stId = $st_id;
42 
43  $pdfInfo = Create_PDF_Statement( $stId, $HB_ENV, $MC, $Ca );
44 
45  # else spew the content
46  if ( $pdfInfo["status"]["code"] == "0" ) {
47  // the file sent successfully
48  exit;
49  } else {
50  // show the errors
51  print "<div class='container-fluid'>";
52 
53  // NOTE: We are in a new window, so just print the errors and exit
54  for ( $i = 0; $i < count( $pdfInfo["errors"] ); $i++ ) {
55  if ( strlen( $errorMessage ) ) $errorMessage .= "<br>";
56 
57  $errorMessage .= $pdfInfo["errors"][$i];
58  }
59 
60  print "<div class='row'>";
61  print "<div class='col-xs-12 col-sm-8' style='color:red; font-size:larger;'>$errorMessage</div>";
62  print "</div>";
63 
64  // also give a message about trying later
65  if ( count( $pdfInfo["errors"] ) ) {
66  print "<div class='row'>";
67  print "<div class='col-xs-12 col-sm-8' style='margin:50px 25px;'>{$MC->msg('Please try again later', HCU_DISPLAY_AS_HTML) }</div>";
68  print "</div>";
69  }
70 
71  print "</div>";
72 
73  exit;
74  }
75  } else if ($action === "esTermsStart" || $action === "esTermsStop" ) {
76  $HB_ENV['esProcessMode'] = $action == "esTermsStart" ? "start" : ( $action == "esTermsStop" ? "stop" : "");
77  $esResults = Post_CUEStmt($dbh, $HB_ENV, $MC, $Ca);
78 
79  // check for errors
80  if ( $esResults["status"]["code"] == "000" ) {
81  // show the message as an error message because the lower code is set up that way
82  $startStopMessage = $esResults["homecuInfo"];
83  } else {
84  $startStopMessage = "";
85  for ( $i = 0; $i < count( $esResults["status"]["errors"] ); $i++ ) {
86  if ( strlen( $startStopMessage ) ) {
87  $startStopMessage .= "<br>";
88  }
89 
90  $startStopMessage .= "<div style='margin:50px 25px; color:red; font-size:larger;'>{$esResults["status"]["errors"][$i]}</div>";
91  }
92  }
93  }
94 
95  // ** INSERT BUSINESS LOGIC FOR THIS FORM
96  $Cu = $HB_ENV["Cu"];
97  $Cn = $HB_ENV["Cn"];
98  $chome = $HB_ENV["chome"];
99  $Flang = $HB_ENV["Flang"];
100 
101  // ** SET VARIABLES FOR WEBSITE FLAGS
102 
103 
104  // ** INCLUDE PRE CONTENT SCRIPT
105  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
106 
107  /********* functions ************/
108  /********* end functions ********/
109 
110  try {
111  $Flang = (trim($Flang) == "" ? "en_US" : trim($Flang));
112 
113  if ( $HB_ENV['offline'] != "N" ) {
114  $thisPageErrors = $HB_ENV["offlinemsg"];
115  throw new Exception( HCU_JsonEncode( $thisPageErrors ), 1);
116  }
117 
118  // get any newsletters or eStatements
119  $eStmtInfo = Get_Estmt($dbh, $HB_ENV, $MC, $Ca);
120 
121  if ( $eStmtInfo["status"]["code"] == "999" && count( $eStmtInfo["status"]["errors"] ) > 0 ) {
122  // error(s) occurred - show them and leave
123  $thisPageErrors = $eStmtInfo["status"]["errors"];
124  throw new Exception( HCU_JsonEncode( $thisPageErrors ), 2);
125  }
126 
127 ?>
128  <div class="k-content" style='font-size:12px;'>
129  <div id="messageWindow" name="messageWindow"></div>
130 <?php
131 
132  // display any message from starting or stopping the e-statements
133  if ( strlen( $startStopMessage ) ) { ?>
134  <div class="col-xs-12 hcuSpacer"><div class="k-block k-info-colored"><?php echo $startStopMessage; ?></div></div>
135  <?php }
136 
137  // display any errors returned from trying to build the PDF
138  if ( strlen( $errorMessage ) ) {
139  print "<p>$errorMessage</p>";
140  }
141  /*
142  * RETRIEVE the eStatement Notice
143  *
144  */
145  $noticesAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, "D", "esNotice", true);
146 
147  $hasNotice = false;
148  $hasNoticePopup = false;
149  if ( $noticesAry["status"]["code"] == "000" && count($noticesAry["notice"]) > 0 && $noticesAry["notice"][0]["notice_id"] ) {
150  $hasNotice = true;
151  $noticeOption = $noticesAry['notice'][0];
152 
153  $noticeOptions = Array (
154  'docsid' => $noticeOption['notice_id'],
155  'docstype' => $noticeOption['notice_type'],
156  'device' => 'D',
157  'noticeOnly' => '0',
158  'expireTime' => mktime() + 86400
159  );
160 
161  $encryptedDocDetails = HCU_PayloadEncode($HB_ENV['Cu'], $noticeOptions);
162 
163  $noticeOptions['noticeOnly'] = 1;
164 
165  $encryptedDocDetailsNoticeOnly = HCU_PayloadEncode($HB_ENV['Cu'], $noticeOptions);
166 
167  // build the url encoded string
168  // * For the Popup
169  if ($noticeOption['notice_popup'] > 0) {
170  $hasNoticePopup = true;
171  $noticeURL = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetails);
172  }
173 
174  // * For the regular Button
175  $noticeURLNoticeOnly = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetailsNoticeOnly);
176  }
177 
178  $newsletterList = HCU_array_key_exists("pdflinks", $eStmtInfo["estmt"]) ? $eStmtInfo["estmt"]["pdflinks"] : array();
179  $eStmtList = HCU_array_key_exists("toclinks", $eStmtInfo["estmt"]) ? $eStmtInfo["estmt"]["toclinks"] : array();
180  // start the content ?>
181 
182  <?php if ($account != "") { ?>
183 
184  <div class="col-xs-12">
185  <h4><?php echo $MC->msg("Account #", HCU_DISPLAY_AS_HTML) . $Ca; ?></h4>
186  </div>
187 
188 <?php }
189 
190  $newsletters = array();
191 
192  // panel header and listview for newsletters
193  if ( count( $newsletterList ) ) { ?>
194  <div class="col-xs-12 col-sm-6 col-lg-8"><div class="panel panel-default">
195  <div class="panel-heading"><?php echo $MC->msg('Newsletters', HCU_DISPLAY_AS_HTML); ?></div>
196  <div class="panel-body" id="listViewNewsletters"></div>
197  </div></div>
198  <?php }
199 
200  // Note: Some phrases end with period ('.') and some don't, for a reason.
201  if ( $eStmtInfo["estmt"]["enrolled"] == "W" ) {
202  // give message about waiting for first statement and allow to stop
203  $statementMessage = $MC->msg('Statement Not Found', HCU_DISPLAY_AS_HTML) . " " . $MC->msg('Statement Missing', HCU_DISPLAY_AS_HTML) . " " . $MC->msg("Statements Stop", HCU_DISPLAY_AS_HTML);
204  $start = "stop";
205  $termsName = "esTermsStop";
206  $termsTitle = $MC->msg( "Stop e-Statements", HCU_DISPLAY_AS_JS );
207  } else if ( $eStmtInfo["estmt"]["enrolled"] == "Y" ) {
208  $statementMessage = $MC->msg("Statements Stop", HCU_DISPLAY_AS_HTML);
209  $start = "stop";
210  $termsName = "esTermsStop";
211  $termsTitle = $MC->msg( "Stop e-Statements", HCU_DISPLAY_AS_JS );
212  } else {
213  $statementMessage = $MC->msg('Account not set for EStatements', HCU_DISPLAY_AS_HTML) . ". " . $MC->msg('Sign up fast', HCU_DISPLAY_AS_HTML);
214  $start = "start";
215  $termsName = "esTermsStart";
216  $termsTitle = $MC->msg( "Start e-Statements", HCU_DISPLAY_AS_JS);
217  }
218 
219  $hasTerms = false;
220  $hasTermsPopup = false;
221  if ( $start == "start" ) {
222  $termsAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, "D", $termsName);
223 
224  /*
225  * RETRIEVE the eStatement Start/Stop Terms (the one other than the current state
226  *
227  */
228 
229  if ( $termsAry["status"]["code"] == "000" && $termsAry["notice"][0]["notice_id"] ) {
230  $hasTerms = true;
231  $termsOption = $termsAry['notice'][0];
232 
233  $termsOptions = Array (
234  'docsid' => $termsOption['notice_id'],
235  'docstype' => $termsOption['notice_type'],
236  'device' => 'D',
237  'noticeOnly' => '0',
238  'expireTime' => mktime() + 86400,
239  "accountnumber" => $Ca
240  );
241 
242  $encryptedDocDetails = HCU_PayloadEncode($HB_ENV['Cu'], $termsOptions);
243 
244  // build the url encoded string for the Popup (if not started) and Button (to start or stop)
245  $hasTermsPopup = true;
246 
247  $termsURL = $HB_ENV['homebankingpath'] . '/hcuViewNotice.prg?cu=' . $HB_ENV['cu'] . '&x=' . urlencode($encryptedDocDetails);
248  }
249  } ?>
250 
251  <div class="col-xs-12 col-sm-6 col-lg-4"><div class="panel panel-default">
252  <div class="panel-heading"><?php echo $MC->msg('EStatement Service', HCU_DISPLAY_AS_HTML); ?></div>
253  <div class="panel-body">
254  <?php echo $statementMessage; ?>
255  <?php if ( $start == "start" ) { ?>
256  <a id='termsButton'><?php echo $MC->msg("Click Here", HCU_DISPLAY_AS_HTML); ?></a>
257  <?php } else { ?>
258  <a onClick='location.href="<?php echo $HB_ENV['homebankingpath'] . '/hcuStatementStop.prg?' . $HB_ENV['cuquery'] . $account; ?>"'>
259  <?php echo $MC->msg("Click Here", HCU_DISPLAY_AS_HTML); ?></a>
260  <?php } ?>
261  </div>
262  </div></div>
263 
264  <?php
265 
266  if ( $start == "start" ) {
267  // set up a form to post a response to starting e-Statements
268  $actionPath = $HB_ENV['loginpath'] . "/" . $HB_ENV['currentscript'] . "?" . $HB_ENV['cuquery'] . "$account";
269  print <<< EOF
270  <form class='' id='formAcceptTerms' name='formAcceptTerms' method="post" action='$actionPath'>
271  <input type="hidden" name="action" value="$termsName" />
272  <input type="hidden" name="notice_id" value="{$termsAry["notice"][0]["notice_id"]}" />
273  </form>
274 EOF;
275  }
276 
277  // create an array for the datasource
278  for ( $i = 0; $i < count( $newsletterList ); $i++ ) {
279  $newsletters[] = array( "eStmtTitle" => trim($newsletterList[$i]["pdftitle"]), "eStmtType" => "", "eStmtLink" => $newsletterList[$i]["pdfpath"]);
280  }
281 
282  $eStmtData = array();
283  if ( count( $eStmtList ) ) { ?>
284 
285  <div class="col-xs-12"><div class="panel panel-default">
286  <div class="panel-heading"><?php echo $MC->msg('E-Statements', HCU_DISPLAY_AS_HTML); ?>
287  <?php // show a menu to let the user choose to filter the statements ?>
288  <ul id='filterStatements'>
289  <li><?php echo $MC->msg('Filter', HCU_DISPLAY_AS_HTML); ?>
290  <ul>
291  <li><?php echo $MC->msg('All Available', HCU_DISPLAY_AS_HTML); ?></li>
292  <li><?php echo $MC->msg('Monthly', HCU_DISPLAY_AS_HTML); ?></li>
293  <li><?php echo $MC->msg('Quarterly', HCU_DISPLAY_AS_HTML); ?></li>
294  <li><?php echo $MC->msg('Annual', HCU_DISPLAY_AS_HTML); ?></li>
295  </ul>
296  </li>
297  </ul>
298  </div>
299  <div class="panel-body" id="listViewStatements"></div>
300  </div></div>
301 
302  <?php // go through and make an object for the datasource
303  for ( $i = 0; $i < count( $eStmtList ); $i++ ) {
304  $eStmtLink = "{$HB_ENV['homebankingpath']}/hcuStatement.prg?action=statement{$account}&cu={$Cu}&Flang={$Flang}";
305  $eStmtLink .= "&st_id=" . $eStmtList[$i]['PerKey'];
306  // this decorates the url to make a unique-to-the-user url
307  $eStmtLink .= "&c=" . $eStmtList[$i]['PerTokn'];
308 
309  $eStmtData[] = array( "eStmtTitle" => trim($eStmtList[$i]["PerDesc"]),
310  "eStmtType" => $eStmtList[$i]["PerType"], "eStmtTypeText" => $eStmtList[$i]["PerTypeText"],
311  "eStmtLink" => $eStmtLink
312  );
313  }
314 
315  }
316 
317 ?>
318 <?php
319 
320  if ( $hasNotice ) {
321 ?>
322  <div class="row">
323  <div class="col-xs-12">
324  <a id="msgButton"><?php echo $noticeOption["notice_linkdisplay"] ?></a>
325  </div>
326  </div>
327 <?php
328  }
329 
330 ?>
331  </div>
332  <style>
333  #listViewStatements {
334  margin-bottom: -1px;
335  }
336  .k-listview:after {
337  content: ".";
338  display: block;
339  height: 0;
340  clear: both;
341  visibility: hidden;
342  }
343  #filterStatements {
344  float: right;
345  min-height: 90px; <?php // This is to prevent a weird scrollbar when the filter returns nothing and then you try to filter again. This is the height of one row. ?>
346  }
347  .statement {
348  display: inline-block;
349  position: relative;
350  width: 170px;
351  height: 50px;
352  margin: 5px;
353  padding: 5px 0px 5px 5px;
354  cursor: pointer;
355  }
356  .statement span {
357  display: block;
358  float: left;
359  position: relative;
360  padding-left: 5px;
361  }
362  .statement img {
363  width: 35px;
364  height: 35px;
365  }
366  .statement h3 {
367  padding-left: 5px;
368  line-height: 1.1em;
369  font-size: .9em;
370  font-weight: bold;
371  text-transform: uppercase;
372  }
373  .statement h4 {
374  padding-left: 5px;
375  line-height: 1.1em;
376  font-size: .8em;
377  font-weight: normal;
378  }
379  .statement a {
380  text-decoration:none;
381  background-color: #fff;
382  }
383  .k-state-hover {
384  background-color: #f0713a;
385  color: #fff;
386  }
387 
388  .row {
389  margin-top: 20px;
390  }
391  .row .k-widget {
392  border: 0;
393  }
394 .k-widget.k-menu,
395 .k-menu .k-group.k-popup{
396  border: none;
397 }
398 .k-widget.k-menu-horizontal > .k-item{
399  border-right: none;
400 }
401 #filterStatements .k-link {
402  padding: 5px;
403 }
404  /* Small devices @screen-sm-min (tablets, 768px and up) */
405  @media (max-width: 600px) {
406  .statement {
407  width: 130px;
408  }
409  .newsletter-text {
410  max-width:75px;
411  }
412  }
413 
414  </style>
415 
416  <script>
417  $(document).ready(function() {
418  var newsletters = <?php echo HCU_JsonEncode($newsletters); ?>;
419  var estatements = <?php echo HCU_JsonEncode($eStmtData); ?>;
420 
421  <?php // Put all the URLs here so that they aren't printed multiple times on the page and also for clarity. ?>
422  var noticeURLNoticeOnly = "<?php echo isset($noticeURLNoticeOnly) ? trim($noticeURLNoticeOnly) : ''; ?>";
423  var termsURL = "<?php echo isset($termsURL) ? trim($termsURL) : ''; ?>";
424  var termsTitle = "<?php echo isset($termsTitle) ? trim($termsTitle) : ''; ?>";
425  var noticeURL = "<?php echo isset($noticeURL) ? trim($noticeURL) : ''; ?>";
426 
427  $("#listViewNewsletters").kendoListView({
428  dataSource: newsletters,
429  template: kendo.template($("#newsletterTemplate").html())
430  });
431 
432  $("#listViewStatements").kendoListView({
433  dataSource: estatements,
434  template: kendo.template($("#statementTemplate").html())
435  });
436 
437  $("#filterStatements").kendoMenu({
438  select: onFilterSelect
439  });
440 
441  $( ".statement" ).hover(
442  function() {
443  $( this ).addClass( "k-info-colored" );
444  }, function() {
445  $( this ).removeClass( "k-info-colored" );
446  }
447  );
448 
449  function onFilterSelect(e) {
450  var selectedText = $(e.item).text();
451 
452  var showMonthly = "inline-block";
453  var showQuarterly = "inline-block";
454  var showAnnual = "inline-block";
455  if ( selectedText === "<?php echo $MC->msg("Monthly", HCU_DISPLAY_AS_JS); ?>" ) {
456  showQuarterly = "none";
457  showAnnual = "none";
458  } else if ( selectedText === "<?php echo $MC->msg("Quarterly", HCU_DISPLAY_AS_JS); ?>" ) {
459  showMonthly = "none";
460  showAnnual = "none";
461  } else if ( selectedText === "<?php echo $MC->msg("Annual", HCU_DISPLAY_AS_JS); ?>" ) {
462  showMonthly = "none";
463  showQuarterly = "none";
464  }
465 
466  $(".monthly").css("display",showMonthly);
467  $(".quarterly").css("display",showQuarterly);
468  $(".annual").css("display",showAnnual);
469  }
470 
471  function PostResponse() {
472  // Post the form to send a reponse to this page to do the starting or stopping
473  document.formAcceptTerms.submit();
474  }
475 
476  $("#msgButton").click( function() {
477  openWindow = ShowNotice(noticeURLNoticeOnly);
478  });
479  $("#termsButton").click( function() {
480  openWindow = ShowNotice(termsURL, termsTitle, PostResponse );
481  });
482 <?php
483  // see if need to open automagically
484  if ( $hasTerms && $hasTermsPopup ) {
485  // pop open new window for terms
486 ?>
487  openWindow = ShowNotice(termsURL, termsTitle, PostResponse );
488 <?php
489  } else if ( $hasNotice && $hasNoticePopup ) {
490  # pop open new window for ~cu/EStatement.html (lower priority)
491 ?>
492  openWindow = ShowNotice(noticeURL);
493 <?php
494  }
495 ?>
496  $(document).on("click", ".k-overlay", function () {
497  // close the currently open window
498  if ( openWindow ) {
499  openWindow.close();
500  }
501  });
502 
503  });
504  var openWindow;
505  var printButton;
506 
507  function createWindow(type, contentString, title) {
508  <?php
509  if ( $HB_ENV["platform"] == "ADA" || $HB_ENV["platform"] == "APP" ) {
510  // open the link directly so the apps can catch it and handle it their way
511  ?>
512  window.location.href = contentString;
513  <?php
514  } else {
515  // open in a new window
516  ?>
517  window.open(contentString, "print_view", "width=825, height=650, resizable=yes");
518  <?php
519  }
520  ?>
521  }
522 
523  function GetNotice() {
524  $(document.body).append('<div id="noticeWindow"></div>');
525  $('#noticeWindow').kendoWindow({
526  visible: false,
527  actions: [ "Close" ],
528  iframe: true,
529  modal: true,
530  title: "<?php echo $MC->msg("Important", HCU_DISPLAY_AS_JS) ?>",
531  resizable: true,
532  maxWidth: 700,
533  refresh: function() {this.center();},
534  close: function(e) {
535  var dialog = $("#noticeWindow").data("kendoWindow");
536  dialog.destroy();
537  },
538  activate: function(e) {
539  $(".k-window").height("");
540  $(".k-content-frame").height("");
541  },
542  content: noticeURL
543  });
544  // doing it this way for IE8
545  var dialog = $("#noticeWindow").data('kendoWindow');
546  dialog.center().open();
547 
548  }
549  </script>
550  <script type="text/x-kendo-template" id="newsletterTemplate">
551  <div class="statement k-block k-shadow k-link" onClick='createWindow("newsletter", "#= eStmtLink#", "#= eStmtTitle #")'>
552  <span class="newsletter-text fa fa-file fa-2x col-xs-3 col-sm-2" title="#= eStmtTitle#"></span>
553  <div class="col-xs-9 col-sm-10 hcu-nopadding">
554  <h3 class="col-xs-12">#= eStmtTitle#</h3>
555  <h4 class="col-xs-12">#= eStmtType#</h4>
556  </div>
557  </div>
558  </script>
559  <script type="text/x-kendo-template" id="statementTemplate">
560  <div class="statement
561  #if ( eStmtType === "Monthly" ) { #
562  monthly
563  #} else if ( eStmtType === "Quarterly" ) { #
564  quarterly
565  #} else if ( eStmtType === "Annual" ) { #
566  annual
567  #} #
568  k-block k-shadow k-link" onClick='createWindow("statement", "#= eStmtLink#", "#= eStmtTitle#")'>
569  <span class="fa fa-file-text fa-2x col-xs-3 col-sm-2" title="#= eStmtTitle #"></span>
570  <div class="col-xs-9 col-sm-10 hcu-nopadding">
571  <h3 class="col-xs-12">#= eStmtTitle#</h3>
572  <h4 class="col-xs-12">#= eStmtTypeText#</h4>
573  </div>
574  </div>
575  </script>
576 
577 <?php
578  /*
579  * ** END CONTENT
580  */
581  } catch (Exception $ex) {
582 
583  //Return error message
584  $thisPageErrors = HCU_JsonDecode($ex->getMessage());
585 
586  // ** Handle Errors on this screen
587  $serviceErrorCode = '917';
588  $serviceErrorTitle = "";
589  $serviceErrorMsgs = $thisPageErrors;
590 
591  require_once(dirname(__FILE__) . '/../includes/hcuErrorPage.i');
592  // drop through to close the page
593  }
594 
595  // ** INCLUDE POST CONTENT SCRIPT
596  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
597 
598 
599  // Functions