Odyssey
aMemberEstmt.prg
1 <?php
2 /**
3  * @package MemberHub
4  * @author MGHandy
5  *
6  * @uses this script facilitates in viewing e-statements associated with the
7  * selected 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 require_once(dirname(__FILE__) . "/../../shared/library/hcuTranslate.i");
21 require_once(dirname(__FILE__) . "/../../shared/library/sAPIAppl.i");
22 
23 try {
24  $admVars = array();
25  $admOk = array(
26  "operation" => array("filter" => FILTER_SANITIZE_STRING),
27  "payload" => array("filter" => FILTER_SANITIZE_STRING),
28  "mPdf" => array("filter" => FILTER_SANITIZE_STRING)
29  );
30  HCU_ImportVars($admVars, "MEMBER_ESTMT", $admOk);
31 
32  $eOperation = isset($admVars["MEMBER_ESTMT"]["operation"]) ? $admVars["MEMBER_ESTMT"]["operation"] : null;
33  $ePayload = isset($admVars["MEMBER_ESTMT"]["payload"]) ? $admVars["MEMBER_ESTMT"]["payload"] : null;
34  $ePdf = isset($admVars["MEMBER_ESTMT"]["mPdf"]) ? $admVars["MEMBER_ESTMT"]["mPdf"] : null;
35 
36  $eMember = $ePayload ?
37  MemberDecrypt($SYSENV, $Cu, $ePayload) :
38  null;
39 
40  $eContext = $ePayload ?
41  MemberContext($SYSENV, $Cu, $eMember['member']) :
42  MemberContext($SYSENV, $Cu);
43 
44  $aryResult = array();
45  $aryReply = array();
46 
47  switch ($eOperation) {
48  case "":
49  PrintMemberEStatements();
50  break;
51  case "memberReadEStatements":
52  header('Content-type: application/json');
53 
54  ValidatePermissions($ePayload, $eMember["member"], $Cn, $Cu);
55  $eMemberStmt = MemberReadEStatements($SYSENV, $dbh, $eContext);
56  $aryResult['data']['news'] = $eMemberStmt['estmt']['news'];
57  $aryResult['data']['stmts'] = $eMemberStmt['estmt']['stmts'];
58  MemberReply($aryResult, $aryReply, $eOperation);
59  break;
60  case "memberReadPdf":
61  header('Content-type: application/pdf');
62  ValidatePermissions($ePayload, $eMember["member"], $Cn, $Cu);
63  $eValidate = MemberValidatePdf($SYSENV, $eContext, $ePdf);
64  $eMemberStmt = MemberReadPdf($SYSENV, $dbh, $eContext, $eValidate);
65  MemberReply($aryResult, $aryReply, $eOperation);
66  break;
67  default:
68  throw new Exception("Unknown server request: " . $eOperation);
69  break;
70  }
71 
72 } catch (Exception $e) {
73  $aryReply['errors'][] = $e->getMessage();
74  $aryResult['data'] = array();
75  $aryResult['info'] = array();
76 
77  MemberReply($aryResult, $aryReply, $eOperation);
78  exit;
79 }
80 
81 /**
82  * function ValidatePermissions($ePayload, $eMember, $Cn, $Cu)
83  * Validates the permissions for eStatement flag and employee flag.
84  *
85  * @param $ePayload -- the payload: checking if it exists.
86  * @param $eMember -- the data to extract the flags.
87  * @param $Cn -- the logged in user.
88  * @param $Cu -- the credit union.
89  *
90  * @throws an exception if the permissions are not met.
91  */
92 function ValidatePermissions($ePayload, $eMember, $Cn, $Cu) {
93  if (isset($ePayload)) {
94  // Now, apply permissions:
95  // Needs to have the eStatement flag set (account's estatements are ON.)
96  // Needs to either be the master user OR also has the employee flag set.
97  // This employee flag is true if one of the user's employee flag is true.
98  // It is set on the payload during account search or through the related account link.
99  $isMasterUser = $Cn == strtolower(trim($Cu));
100  $hasPermissions = true;
101  $hasPermissions = $hasPermissions && HCU_array_key_value("m_stmnt", $eMember) === "Y";
102  if (!$isMasterUser) {
103  $hasPermissions = $hasPermissions && HCU_array_key_value("m_employee", $eMember) !== "Y";
104  }
105  if (!$hasPermissions) {
106  throw new exception ("You do not have permissions to view eStatements.");
107  }
108  }
109 }
110 
111 function MemberValidatePdf($pEnv, $pContext, $pPdf) {
112  $sList = html_entity_decode($pPdf, ENT_QUOTES);
113  $dList = HCU_JsonDecode($sList);
114 
115  return $dList;
116 }
117 
118 function MemberReadPdf($pEnv, $pDbh, $pContext, $pPdf) {
119  $cuTable = $pContext['cu_table'];
120  $cuCode = $pContext['cu_code'];
121  $cuMember = $pContext['m_account'];
122 
123  $HB_ENV['Flang'] = "en_US";
124  $HB_ENV['Fset3'] = $GLOBALS['Fset3'];
125  $HB_ENV['Cu'] = $GLOBALS['Cu'];
126  $HB_ENV['Cn'] = $GLOBALS['Cn'];
127  $HB_ENV['chome'] = $GLOBALS['chome'];
128  $HB_ENV['CU3_ESTMNT_CORE'] = $GLOBALS['CU3_ESTMNT_CORE'];
129  $HB_ENV['dbh'] = $pDbh;
130  $HB_ENV['SYSENV'] = $pEnv;
131 
132  // get translate object
133  $MC = new hcu_talk_base($HB_ENV['Flang']);
134  $eStmt = Create_PDF_Statement($pPdf['pdfKey'], $HB_ENV, $MC, $cuMember);
135  if ($eStmt["status"]["code"] == "999" && count( $eStmt["errors"] ) > 0) {
136  throw new Exception($eStmt["errors"][0]);
137  }
138 }
139 
140 function MemberReadEStatements($pEnv, $pDbh, $pContext) {
141  $cuTable = $pContext['cu_table'];
142  $cuCode = $pContext['cu_code'];
143  $cuMember = $pContext['m_account'];
144 
145  $sqlReturn = array();
146  $sqlSelect = "
147  SELECT email
148  FROM {$cuTable}user u
149  INNER JOIN {$cuTable}memberacct m ON m.primary_user = u.user_id
150  WHERE m.accountnumber = '$cuMember'";
151  $sqlSelectRs = db_query($sqlSelect, $pDbh);
152  if (!$sqlSelectRs) {
153  $pEnv['logger']->error(db_last_error());
154  throw new Exception("Failed to read member email.");
155  }
156  $sqlData = db_fetch_all($sqlSelectRs)[0];
157 
158  // $http_scheme is defined in main.prg but we would have to include
159  // it as a global in this function. Instead, we already have
160  // the system environment, just define it locally the same way as main.prg.
161  $http_scheme = $pEnv['require_encryption'] ? 'https' : 'http';
162 
163  // build ENV VARIABLE
164  $HB_ENV['fi_path'] = "$http_scheme://{$GLOBALS['_SERVER']['HTTP_HOST']}/fi/{$cuTable}/";
165  $HB_ENV['Flang'] = "en_US";
166  $HB_ENV['Fset3'] = $GLOBALS['Fset3'];
167  $HB_ENV['Cu'] = $GLOBALS['Cu'];
168  $HB_ENV['Cn'] = $GLOBALS['Cn'];
169  $HB_ENV['chome'] = $GLOBALS['chome'];
170  $HB_ENV['live'] = $GLOBALS['live'];
171  $HB_ENV['Ml'] = $sqlData['email'];
172  $HB_ENV['CU3_ESTMNT_CORE'] = $GLOBALS['CU3_ESTMNT_CORE'];
173  $HB_ENV['dbh'] = $pDbh;
174  $HB_ENV['SYSENV'] = $pEnv;
175 
176  // get translate object
177  $MC = new hcu_talk_base($HB_ENV['Flang']);
178 
179  // get e-statements
180  $eStmt = Get_Estmt($pDbh, $HB_ENV, $MC, $cuMember);
181  if ($eStmt["status"]["code"] == "999" && count( $eStmt["status"]["errors"] ) > 0) {
182  throw new Exception($eStmt["status"]["errors"][0]);
183  }
184 
185  $sqlReturn['estmt']['news'] =
186  isset($eStmt["estmt"]["pdflinks"]) ? $eStmt["estmt"]["pdflinks"] : array();
187  $sqlReturn['estmt']['stmts'] =
188  isset($eStmt["estmt"]["toclinks"]) ? $eStmt["estmt"]["toclinks"] : array();
189  return $sqlReturn;
190 }
191 ?>
192 
193 <?php
194 /**
195  * @package MemberEStatements
196  * @uses print neccessary html/javascript to run the selected card
197  */
198 function PrintMemberEStatements() { ?>
199 <style type="text/css">
200 .hcu-pdf-link {
201  cursor: pointer;
202  display: block;
203 
204  margin-top: 15px;
205  margin-bottom: 15px;
206 }
207 
208 .hcu-pdf-link .hcu-pdf-icon,
209 .hcu-pdf-link .hcu-pdf-info {
210  display: table-cell;
211 }
212 
213 .hcu-pdf-link .hcu-pdf-info {
214  vertical-align: middle;
215  text-align: center;
216  width: 100%;
217 }
218 </style>
219 
220 <div id="meStmts">
221  <div id="status"></div>
222 
223  <div class="well well-sm col-sm-12">
224  <h3>Newsletters</h3>
225  </div>
226 
227  <div class="row" id="meNewsView"></div>
228 
229  <div class="well well-sm col-sm-12">
230  <h3>eStatements</h3>
231  </div>
232 
233  <div class="row" id="meStmtView"></div>
234 
235  <div class="hcu-template">
236  <div class="hcu-edit-buttons k-state-default">
237  <a href="##" id="btnUpdate" class="k-button k-primary">
238  <i class="fa fa-times fa-lg"></i>
239  Close
240  </a>
241  </div>
242  </div>
243 </div>
244 
245 <script type="text/x-kendo-template" id="meTemplate">
246  <a class="hcu-pdf-link col-sm-4 col-lg-3"
247  data-index="#= pdfIndex #"
248  data-source="#= pdfType #">
249  <div class="well well-sm">
250  <div class="hcu-pdf-icon">
251  <span class="fa fa-3x fa-file-pdf-o"></span>
252  </div>
253  <div class="hcu-pdf-info">
254  <span><strong>#= pdfTitle #</strong></span>
255  #if(pdfType == "stmt") {#
256  <br>
257  <span>#= pdfStmt #</span>
258  #}#
259  </div>
260  </div>
261  </a>
262 </script>
263 <?php
264 /**
265  * @package MemberEStatements
266  * @uses this object is used to display and interact with the member e-statements feature.
267  *
268  * @var Init public: call to initialize data/view/action objects
269  * @var Open public: call to open the mamber search module/window
270  * @var Close public: call to close the member search module/window
271  * @var Data public: call to load payload and member display into
272  * MemberEStatements object for later use.
273  *
274  * @var InitDataSources private: initialize all data sources/objects
275  * @var InitDataViews private: initialize all data views/objects
276  * @var InitDataActions private: initialize all user actions on html.
277  *
278  * @var EventOpenWindow private: open kendoDialog/kendoWindow objects
279  * @var EventCloseWindow private: close kendoDialog/kendoWindow objects
280  * @var EventPopWindow private: remove the correct window from the window stack.
281  *
282  * @var Event* private: other event functions explained by name.
283  * Some are entensions of kendo objects, others just help with events of html objects.
284  *
285  * @var DataBuild* private: these functions build up datasources for
286  * arrays, json objects and observables for use in manipulation and display.
287  *
288  * @var Validate* private: validation functions for forms, inputs, observables
289  * and any other data that could be altered.
290  */
291 ?>
292 <script type="text/javascript">
293 var MemberEStatements = function() {
294  var meCardContainer = null;
295  var meCardWindows = null;
296 
297  var mePayload = null;
298  var meMember = null;
299  var meCall = null;
300 
301  var meAction = null;
302  var meDataSource = null;
303  var meStmts = null;
304  var meStmtsOpened = false;
305 
306  var meStmtView = null;
307  var meStmtData = null;
308  var meNewsView = null;
309  var meNewsData = null;
310  var meTemplate = null;
311 
312  var meClose = null;
313 
314  var DataBuildNews = function(data) {
315  meNewsData = [];
316  for (var i = 0; i < data.length; i++) {
317  var letter = {
318  pdfIndex: i,
319  pdfTitle: data[i].pdftitle.trim(),
320  pdfPath: data[i].pdfpath.trim(),
321  pdfType: "news"
322  };
323 
324  meNewsData.push(letter);
325  meNewsView.append(meTemplate(letter));
326  }
327  }
328 
329  var DataBuildStmt = function(data) {
330  meStmtData = [];
331  for (var i = 0; i < data.length; i++) {
332  var stmt = {
333  pdfIndex: i,
334  pdfTitle: data[i].PerDesc.trim(),
335  pdfStmt: data[i].PerType.trim(),
336  pdfEnd: data[i].PerEnd.trim(),
337  pdfTokn: data[i].PerTokn.trim(),
338  pdfKey: data[i].PerKey.trim(),
339  pdfType: "stmt"
340  };
341 
342  meStmtData.push(stmt);
343  meStmtView.append(meTemplate(stmt));
344  }
345  }
346 
347  var DataBuildLinks = function() {
348  $(".hcu-pdf-link").each(function(i) {
349  $(this).on("click", EventReadPdf);
350  });
351  }
352 
353  var EventReadPdf = function(e) {
354  var pdfIndex = $(this).data("index");
355  var pdfType = $(this).data("source");
356  var pdfData = null;
357  var pdfPath = "";
358 
359  switch (pdfType) {
360  case "news":
361  pdfData = meNewsData[pdfIndex];
362  pdfPath = pdfData.pdfPath;
363  break;
364  case "stmt":
365  pdfData = meStmtData[pdfIndex];
366  pdfPath += "main.prg?ft=103108";
367  pdfPath += "&operation=memberReadPdf";
368  pdfPath += "&payload=" + encodeURIComponent(mePayload);
369  pdfPath += "&mPdf=" + encodeURIComponent(JSON.stringify(pdfData));
370  break;
371  }
372 
373  window.open(pdfPath);
374  }
375 
376  var EventOpenWindow = function(e) {
377  var windowElement = this.element[0];
378  var windowId = windowElement.id;
379 
380  switch (windowId) {
381  default:
382  meStmtsOpened = true;
383  break;
384  }
385 
386  meCardWindows.push(this);
387  }
388 
389  var EventCloseWindow = function(e) {
390  var windowElement = this.element[0];
391  var windowId = windowElement.id;
392 
393  switch (meAction) {
394  default:
395  meStmtsOpened = false;
396  break;
397  }
398 
399  meAction = null;
400  }
401 
402  var EventPopWindow = function(windowId) {
403  var popIndex = -1;
404  for (var i = 0; i < meCardWindows.length; i++) {
405  var openWindow = meCardWindows[i].element[0];
406  var openId = openWindow.id;
407 
408  if (openId == windowId) {
409  popIndex = i;
410  break;
411  }
412  }
413 
414  if (popIndex > -1) {
415  meCardWindows.splice(popIndex, 1);
416  }
417  }
418 
419  var InitDataSources = function() {
420  meDataSource = new kendo.data.DataSource({
421  transport: {
422  read: {
423  url: "main.prg",
424  dataType: "json",
425  contentType: "application/x-www-form-urlencoded",
426  type: "GET",
427  data: {
428  ft: "103108"
429  },
430  cache: false
431  }
432  },
433  requestStart: function(request) {
434  showWaitWindow();
435  },
436  requestEnd: function(response) {
437  setTimeout(hideWaitWindow, 500);
438 
439  if (response.hasOwnProperty("response")) {
440  if (response.response.hasOwnProperty("Results")) {
441  var results = response.response.Results;
442 
443  if (results.hasOwnProperty("errors")) {
444  if (meStmtsOpened == false) {
445  $.homecuValidator.setup({ formStatusField: "formStatus", formValidate: "cardContainerDiv" });
446  }
447  $.homecuValidator.homecuResetMessage = true;
448  $.homecuValidator.displayMessage(results.errors, $.homecuValidator.settings.statusError);
449  } else if (results.hasOwnProperty("info")) {
450  $.homecuValidator.homecuResetMessage = true;
451  $.homecuValidator.displayMessage(results.info, $.homecuValidator.settings.statusSuccess);
452  }
453  } else {
454  $.homecuValidator.displayMessage("Error Parsing Server", $.homecuValidator.settings.statusError);
455  }
456  } else {
457  $.homecuValidator.displayMessage("Error Parsing Server", $.homecuValidator.settings.statusError);
458  }
459  },
460  schema: {
461  parse: function(response) {
462 
463  var results = null;
464  var resultData = null;
465  var resultOperation = null;
466 
467  if (response.hasOwnProperty("Results")) {
468  results = response.Results;
469  resultData = results.data;
470  resultOperation = results.operation;
471  }
472 
473  if (results.hasOwnProperty("errors")) {
474  hideWaitWindow();
475  return [];
476  }
477 
478  if (resultData == undefined || resultData == null) {
479  hideWaitWindow();
480  return [];
481  }
482 
483  setTimeout(function() {
484  hideWaitWindow();
485 
486  switch (resultOperation) {
487  case "memberReadEStatements":
488  DataBuildStmt(resultData.stmts);
489  DataBuildNews(resultData.news);
490  DataBuildLinks();
491 
492  meMember.cardTitle= "Member eStatements";
493  var template= kendo.template($("#titleTemplate").html());
494  meStmts.title(template(meMember)).center().open();
495  }
496  }, 500);
497 
498  return [];
499  }
500  }
501  });
502  }
503 
504  var InitDataViews = function() {
505  meStmts = $("#meStmts").kendoWindow({
506  title: "Member eStatements",
507  minWidth: "75%",
508  maxWidth: "90%",
509  modal: true,
510  visible: false,
511  resizable: false,
512  activate: EventOpenWindow,
513  close: EventCloseWindow,
514  open: function() {
515  this.wrapper.css({ top: 100 });
516  }
517  }).data("kendoWindow");
518 
519  meNewsView = $("#meNewsView");
520  meStmtView = $("#meStmtView");
521  meTemplate = kendo.template($("#meTemplate").html());
522 
523  meStatus = $("#meStatus");
524  meStatus.hide();
525 
526  meClose = $("#btnUpdate");
527  }
528 
529  var InitDataActions = function() {
530  meClose.on("click", function(e) {
531  meStmts.close();
532  });
533  }
534 
535  this.Open = function(windowStack) {
536  // setup validator
537  $.homecuValidator.setup({
538  formStatusField: "status",
539  formValidate: "meStmts"
540  });
541 
542  meCardWindows = windowStack;
543  var memberRequest = {
544  operation: "memberReadEStatements",
545  payload: mePayload
546  };
547 
548  meDataSource.transport.options.read.type = "POST";
549  meDataSource.read(memberRequest);
550  }
551 
552  this.Close = function() {
553  meStmts.destroy();
554 
555  // reset validator for hub script
556  $.homecuValidator.setup({
557  formStatusField: "formStatus",
558  formValidate: "cardContainerDiv"
559  });
560  }
561 
562  this.Data = function(payload, member) {
563  mePayload = payload;
564  meMember = member;
565  }
566 
567  this.Init = function(hubCall, cardContainer) {
568  meCall = hubCall;
569  meCardContainer = cardContainer;
570 
571  InitDataSources();
572  InitDataViews();
573  InitDataActions();
574 
575  meCall("MemberEStatements", this);
576  }
577 }
578 </script>
579 <?php }