Odyssey
hcuRDCStatus.prg
1 <?php
2 /**
3 * @package hcuRDCStatus (RDC Status Table Inquiry)
4 *
5 * Purpose: Shows content of CURDCSTATUS table records to assist in customer support for RDC from apps.
6 *
7 * NOTES:
8 * 1. No Updates allowed -- just read, filter, expand the json array
9 * 2. SPB 10/30/2015-- now uses monitorView.i
10 * 3. SPB 6/3/2016-- restyling to be consistent with loggingReport. Added saving filter.
11 */
12 
13  $monLibrary = dirname(__FILE__) . "/../library";
14  $sharedLibrary = dirname(__FILE__) . "/../../shared/library";
15  $bankingLibrary = dirname(__FILE__) . "/../../banking/library";
16  require_once("$monLibrary/cu_top.i");
17  require_once("$monLibrary/monitorView.i");
18  require_once("$sharedLibrary/reporting.i");
19  require_once("$sharedLibrary/commonJsFunctions.i");
20  require_once("$sharedLibrary/commonPhpFunctions.i");
21 
22 // if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR']))
23 // {
24 // // ** Permissions failed
25 // // ** redirect to new page
26 // header("Location: /hcuadm/hcu_noperm.prg");
27 // exit;
28 // }
29 
30 $parameters = array("a" => array("operation" => "", "cu" => ""));
31 $string = array("filter" => FILTER_SANITIZE_STRING);
32 HCU_ImportVars($parameters, "a", array("operation" => $string, "cu" => $string));
33 
34 $operation = HCU_array_key_exists("operation", $parameters["a"]) ? trim($parameters["a"]["operation"]) : "";
35 $cu = HCU_array_key_exists("cu", $parameters["a"]) ? strtoupper(trim($parameters["a"]["cu"])) : "";
36 
37 $report = "rdcstatus";
38 $pageSize = 20;
39 
40 /**
41  * This might seem stupid but it is defined to use reports.i which is designed to have a whole list of possible reports.
42  * @see the info block at the top of {@link hcuinc/reports.i}
43  */
44 $reportList = array("rdcstatus" => array(
45  "title" => "Mobile RDC Inquiry",
46  "sql" => "select depositid, status, cu, accountnumber, amount, acctid, rdcvendor, starttime, lastupdate, frontaccept,
47  backaccept, vendorinfo, frontpath, backpath from curdcstatus where (current_timestamp - lastupdate) < interval '20 days'",
48  "cols" => array("Deposit ID" => "number", "Status" => "list", "Cu" => "string", "Member" => "number", "Amount" => "currency",
49  "Account" => "string", "Vendor" => "string", "Start" => "date", "Update" => "date", "Front" => "string", "Back" => "string",
50  "info" => "ignore", "frontpath" => "ignore", "backpath" => "ignore"),
51  "ddl" => array("Status" => array("O" => "Open", "S" => "Session Started", "T" => "Terms Pending", "R" => "Rejected", "C" => "Completed",
52  "B" => "Blocked", "F" => "Failed")),
53  "defaultSort" => array(
54  array("field" => "update", "dir" => "desc"),
55  array("field" => "start", "dir" => "desc")
56  )
57  ));
58 
59 // Configuration for data operations & presentation layer.
60 $self = $_SERVER["PHP_SELF"];
61 $defaultDateFormat = "MM/dd/yyyy HH:mm:ss";
62 
63 // DATABASE
64 if ($operation != "") {
65  switch ($operation) {
66  case "readReport":
67  ReadReport($cu, $dbh, $reportList, $defaultDateFormat);
68  break;
69  case "getImage":
70  GetImage($dbh);
71  break;
72  default: // Won't get here
73  header('Content-type: application/json');
74  $returnArray = array("error" => array("Operation not specified: '$operation'"), "record" => "", "operation" => "");
75  print HCU_JsonEncode($returnArray);
76  }
77 } else {
78 // PRESENTATION
79 // Page for displaying the reports.
80 // **************************************************************
81  $reportRecord = $reportList[$report];
82  $title = !isset($reportRecord) ? "Unrecognized Report" : (isset($reportRecord["title"]) ? $reportRecord["title"] : $report);
83  printMonitorPageTop($title, $homecuKendoVersion, $cloudfrontDomainName, $bootstrapVersion, $fontawesomeVersion, true);
84 
85  $filter = $cu == "" ? "" : HCU_JsonEncode(array("field" => "cu", "operator" => "eq", "value" => $cu));
86 ?>
87 
88 <style>
89  .k-notification-wrap {
90  overflow-x: scroll;
91  overflow-y: visible;
92  }
93 
94  .loggingArea {
95  margin-left: 10px;
96  }
97  .loggingInfo {
98  white-space: pre-wrap;
99  width: 100%;
100  margin-left: 10px;
101  }
102 
103  .overflowDiv {
104  overflow-x: auto;
105  overflow-y: auto;
106  max-height: 600px;
107  }
108 </style>
109 
110 <script type="text/javascript">
111 
112 <?php
113 // Include common functions
114 getShowWaitFunctions();
115 GetIsFilterChanged();
116 InitReport($self, $report, $reportList, $defaultDateFormat, true, $pageSize, false, "", $filter);
117 ?>
118 
119 var inNotification = true;
120 var inShowClick = true;
121 var activeWindows = [];
122 
123 <?php
124 /**
125  * function OpenPopup(dataItem)
126  * Opens up the detail modal for a row.
127  *
128  * @param Object dataItem -- the data for the row.
129  */
130 ?>
131 function OpenPopup(dataItem) {
132  var template = kendo.template($("#popupTemplate").html());
133 
134  var popup = $("#detailPopup").data("kendoWindow");
135  if (popup == null) {
136  popup = $("<div id='detailPopup'></div>").appendTo("body").kendoWindow({
137  modal: true,
138  title: "Deposit Details",
139  visible: false,
140  draggable: false,
141  resizable: false,
142  maxWidth: 700,
143  minWidth: 350,
144  open: function() {
145  if (window.activeWindows != null) {
146  window.activeWindows.push(this);
147  }
148  },
149  close: function() {
150  if (window.activeWindows != null) {
151  window.activeWindows.pop();
152  }
153  }
154  }).data("kendoWindow");
155 
156  $("#detailPopup").on("click", ".imageLink", function() {
157  var depositId = "depositId=" + Number($("#detailPopup").data("depositid"));
158  var imageType = "imageType=" + ($(this).hasClass("front") ? "front" : "back");
159  var content = "<img src='<?php echo $self; ?>?operation=getImage&" + depositId + "&" + imageType + "' width='100%'>";
160  var imagePopup = $("#imagePopup").data("kendoWindow");
161  if (imagePopup == null) {
162  imagePopup = $("<div id='detailPopup'></div>").appendTo("body").kendoWindow({
163  modal: true,
164  title: "",
165  visible: false,
166  draggable: false,
167  resizable: false,
168  width: 400,
169  open: function() {
170  if (window.activeWindows != null) {
171  window.activeWindows.push(this);
172  }
173  },
174  close: function() {
175  if (window.activeWindows != null) {
176  window.activeWindows.pop();
177  }
178  }
179  }).data("kendoWindow");
180  }
181  imagePopup.content(content).open().center();
182  return false;
183  });
184  }
185  $("#detailPopup").data("depositid", dataItem.depositId);
186  popup.content(template(dataItem)).open().center();
187 }
188 
189 /**
190  * This makes sure that the count is included in the case that more records are being added to list, previously it would subbornly assert that there are no new records.
191  */
192 var inRefresh = false;
193 function ForceRefresh(data, parameters, filterChanged) {
194  if (inRefresh) {
195  parameters.includeCount = "Y";
196  inRefresh = false;
197  }
198  <?php if ($cu == "") { ?>
199  parameters.saveFilter = "Y";
200  <?php } ?>
201 }
202 
203 $(document).ready(function () {
204  InitReport({parameterMapFunc: ForceRefresh, preInitFunc: function(gridDefinition) {
205  gridDefinition.columns[0] = {command: [{name: "details", text: "Details"}], width: "30px"};
206  <?php if ($cu != "") { // Cannot unfilter CU if coming in through the CU ?>
207  gridDefinition.columns[2].filterable = false;
208  gridDefinition.columns[2].sortable = false;
209  <?php } ?>
210  }});
211 
212  $("#refreshBtn").click(function() {
213  var grid = $("#reportGrid").data("kendoGrid");
214  inRefresh = true;
215  grid.dataSource.read();
216  return false;
217  });
218 
219  $("#clearAllBtn").click(function() {
220  var grid = $("#reportGrid").data("kendoGrid");
221  <?php // If you clear the sort and then the filter, it is two calls versus one here. // The cookie will be changed in the call. ?>
222  inRefresh = true;
223  grid.dataSource.query({
224  sort: {field:"depositId", dir:"asc"},
225  <?php if ($cu == "") { ?>
226  filter: [],
227  <?php } else { ?>
228  filter: {field: "cu", operator: "eq", value: "<?php echo $cu; ?>"},
229  <?php } ?>
230  pageSize: <?php echo $pageSize; ?>,
231  page: 1
232  });
233  return false;
234  });
235 
236  $("#reportGrid").on("click", ".k-grid-details", function() {
237  var grid = $("#reportGrid").data("kendoGrid");
238  OpenPopup(grid.dataItem($(this).closest("tr")));
239  });
240 
241  <?php printClickOverlayEvent(); ?>
242 
243 });
244 </script>
245 <script type="text/x-kendo-template" id="popupTemplate">
246  # var frontHTML = frontpath == "" ? "No Image" : "(<a href='\\#' class='imageLink front'>Image</a>)"; #
247  # var backHTML = backpath == "" ? "No Image" : "(<a href='\\#' class='imageLink back'>Image</a>)"; #
248  <div class="overflowDiv">
249  <div class="container-fluid">
250  <div class="row hcuSpacer">
251  <div class="col-xs-6"><label>Deposit ID</label></div>
252  <div class="col-xs-6">#: depositId #</div>
253  </div>
254  <div class="row hcuSpacer">
255  <div class="col-xs-6"><label>Vendor</label></div>
256  <div class="col-xs-6">#: vendor #</div>
257  </div>
258  <div class="row hcuSpacer">
259  <div class="col-xs-6"><label>Front Accepted</label></div>
260  <div class="col-xs-6"># if (front == "") { # # } else if (front == "Y") { # Yes # } else { # No # } # #= frontHTML #</div>
261  </div>
262  <div class="row hcuSpacer">
263  <div class="col-xs-6"><label>Back Accepted</label></div>
264  <div class="col-xs-6"># if (back == "") { # # } else if (back == "Y") { # Yes # } else { # No # } # #= backHTML #</div>
265  </div>
266  # if (info && info.trim() != "") { #
267  <div class="row hcuSpacer">
268  <div class="col-xs-12">#= info #</div>
269  </div>
270  # } #
271  </div>
272  </div>
273 </script>
274 <?php printMonitorPageMiddle($title, array("Refresh" => array("id" => "refreshBtn"), "Clear All" => array("id" => "clearAllBtn"))); ?>
275 
276  <div class="loggingReportDiv container hcu-all-100 vsgPrimary" id="loggingReportDiv">
277 
278  <div id="notification"></div>
279 
280  <div class="row hcuSpacer">
281  <div class="col-xs-12">
282  <div id="formValidateMainDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
283  </div>
284  </div>
285 
286  <div class="row hcuSpacer">
287  <div class="col-xs-12">
288  <div class="reportGridOverflow">
289  <div id="reportGrid"></div>
290  </div>
291  </div>
292  </div>
293  </div>
294 <?php printMonitorPageBottom();
295 } // No operation
296 
297 // FUNCTIONS
298 
299 /**
300  * function ReadReport($dbh, $reportList, $defaultDateFormat)
301  * Returns the data needed from the parameters for the report:
302  *
303  * "report" -- the report to read. Refers to the $reportKey in the function getReportList(). The frontend sends the variable down as a javascript literal.
304  * "initial" -- {true/false} If initial, then also figure out the boolean DDLs and send those to the frontend to recreate the grid with those parameters. (There is no re-read.)
305  * "limit" -- How many records to return.
306  * "offset" -- Where to start in the resultset.
307  * "newFilter" -- {true/false} If newFilter, then also find out the count of the resultset. Also, ignore the offset. It will get the first page.
308  * "sort" -- This is a json encoded string of the current sort in the grid.
309  * "filter" -- This is a json encoded string of the current filter in the grid.
310  * "printerFriendly" -- printer friendly doesn't have paging.
311  *
312  * @param $Cu -- the credit union
313  * @param $dbh -- the database connection
314  * @param $reportList -- the reportList from the getReportList() above.
315  * @param $defaultDateFormat -- This is what the date will be formatted as.
316  */
317 function ReadReport($Cu, $dbh, $reportList, $defaultDateFormat) {
318  $parameters = array("a" => array("report" => "", "initial" => "", "limit" => "", "offset" => "", "newFilter" => "", "sort" => "", "filter" => "", "printerFriendly" => ""));
319  $string = array("filter" => HCUFILTER_INPUT_STRING);
320  HCU_ImportVars($parameters, "a", array("report" => $string, "initial" => $string, "limit" => $string, "offset" => $string, "newFilter" => $string, "sort" => $string,
321  "filter" => $string, "printerFriendly" => $string));
322 
323  $report = HCU_array_key_exists("report", $parameters["a"]) ? trim($parameters["a"]["report"]) : "";
324  $initial = HCU_array_key_exists("initial", $parameters["a"]) ? trim($parameters["a"]["initial"]) == "true" : false;
325  $limit = HCU_array_key_exists("limit", $parameters["a"]) ? intval($parameters["a"]["limit"]) : -1;
326  $offset = HCU_array_key_exists("offset", $parameters["a"]) ? intval($parameters["a"]["offset"]) : 0;
327  $newFilter = HCU_array_key_exists("newFilter", $parameters["a"]) ? trim($parameters["a"]["newFilter"]) == "true" : false;
328  $sort = HCU_array_key_exists("sort", $parameters["a"]) ? trim($parameters["a"]["sort"]) : "";
329  $filter = HCU_array_key_exists("filter", $parameters["a"]) ? trim($parameters["a"]["filter"]) : "";
330  $printerFriendly = HCU_array_key_exists("printerFriendly", $parameters["a"]) ? trim($parameters["a"]["printerFriendly"]) == "true" : false;
331 
332  $includeCount = !$printerFriendly && $newFilter;
333  $limit = $printerFriendly ? -1 : $limit;
334  $offset = $printerFriendly || $newFilter ? 0 : $offset;
335 
336  $returnArray = ReadReportData($Cu, $reportList[$report], $dbh, $limit, $offset, $includeCount, false, $initial, false, $sort, $filter, $report, "loggingReport");
337 
338  header('Content-type: application/json');
339  print HCU_JsonEncode($returnArray);
340 }
341 
342 /**
343  * function GetImage($dbh)
344  * @param $dbh -- the database connection
345  * Get the image from the filepath. If it doesn't exist, shows "Image doesn't exist."
346  */
347 function GetImage($dbh) {
348  $parameters = array("a" => array("depositId" => "", "imageType" => ""));
349  $string = array("filter" => HCUFILTER_INPUT_STRING);
350  HCU_ImportVars($parameters, "a", array("depositId" => $string, "imageType" => $string));
351 
352  $depositId = HCU_array_key_exists("depositId", $parameters["a"]) ? intval($parameters["a"]["depositId"]) : 0;
353  $imageType = HCU_array_key_exists("imageType", $parameters["a"]) ? trim($parameters["a"]["imageType"]) : "";
354 
355  try {
356  if (!in_array($imageType, array("front", "back"))) {
357  throw new exception ("Image type is invalid", 3);
358  }
359  $sql = "select " . ($imageType == "front" ? "frontpath" : "backpath") . " from curdcstatus where depositid = $depositId";
360  $sth = db_query($sql, $dbh);
361  if (!$sth) {
362  throw new exception("Query invalid", 4);
363  }
364  $filepath = trim(db_fetch_row($sth,0)[0]);
365  if (!file_exists($filepath)) {
366  throw new exception ("Image is not found", 1);
367  }
368  if (!is_readable($filepath)) {
369  throw new exception ("Image is readable", 2);
370  }
371  header('Content-Type: image/jpeg');
372  readfile($filepath);
373  } catch(exception $e) {
374  // Create a blank image and add some text
375  $image = imagecreatetruecolor(120, 20);
376 
377  $textColor = imagecolorallocate($image, 46, 46, 46);
378  $backgroundColor = imagecolorallocate($image, 255, 255, 255);
379 
380  imagefill($image, 0, 0, $backgroundColor);
381  imagestring($image, 1, 5, 5, $e->getMessage(), $textColor);
382 
383  header('Content-Type: image/png');
384  imagepng($image);
385  imagedestroy($image);
386  }
387 }