Odyssey
loggingReport.prg
1 <?php
2 /**
3  * @author Samuel Bennett <samuel@homecu.net>
4  * @package loggingReport
5  * Shows the most recent logging records from trusted vendors. Using in-house for debugging purposes.
6  */
7 
8  $monLibrary = dirname(__FILE__) . "/../library";
9  $sharedLibrary = dirname(__FILE__) . "/../../shared/library";
10  $bankingLibrary = dirname(__FILE__) . "/../../banking/library";
11  require_once("$monLibrary/cu_top.i");
12  require_once("$monLibrary/monitorView.i");
13  require_once("$sharedLibrary/reporting.i");
14  require_once("$sharedLibrary/commonJsFunctions.i");
15  require_once("$sharedLibrary/commonPhpFunctions.i");
16 
17 // if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR']))
18 // {
19 // // ** Permissions failed
20 // // ** redirect to new page
21 // header("Location: /hcuadm/hcu_noperm.prg");
22 // exit;
23 // }
24 
25 $parameters = array("a" => array("operation" => "", "cu" => ""));
26 $string = array("filter" => FILTER_SANITIZE_STRING);
27 HCU_ImportVars($parameters, "a", array("operation" => $string, "cu" => $string));
28 
29 $operation = HCU_array_key_exists("operation", $parameters["a"]) ? trim($parameters["a"]["operation"]) : "";
30 $cu = HCU_array_key_exists("cu", $parameters["a"]) ? strtoupper(trim($parameters["a"]["cu"])) : "";
31 
32 $report = "logging";
33 $pageSize = 20;
34 
35 /**
36  * This might seem stupid but it is defined to use reports.i which is designed to have a whole list of possible reports.
37  * @see the info block at the top of {@link hcuinc/reports.i}
38  */
39 $sql = "select null, entry, cu, user_id, service, sub_service, session_id, txn_id, user_ip, request, response from cu_vendorlog";
40 $reportList = array("logging" => array("title" => "Trusted Vendor Logging Report", "sql" => $sql, "defaultSort" => array("field" => "entry", "dir" => "desc"),
41  "cols" => array("Details" => "string", "Entry" => "date", "CU" => "string","User" => "string", "Service" => "string","Sub Service" => "string", "Session" => "string",
42  "TXN" => "string",
43  "IP" => "string","Request" => "ignore", "Response" => "ignore")));
44 
45 // Configuration for data operations & presentation layer.
46 $dataFile = $_SERVER["PHP_SELF"];
47 $presentationFile = $dataFile;
48 $defaultDateFormat = "MM/dd/yyyy HH:mm:ss";
49 
50 // DATABASE
51 if ($operation != "") {
52  switch ($operation) {
53  case "readReport":
54  ReadReport($cu, $dbh, $reportList, $defaultDateFormat);
55  break;
56  default: // Won't get here
57  header('Content-type: application/json');
58  $returnArray = array("error" => array("Operation not specified: '$operation'"), "record" => "", "operation" => "");
59  print HCU_JsonEncode($returnArray);
60  }
61 } else {
62 // PRESENTATION
63 // Page for displaying the reports.
64 // **************************************************************
65  $reportRecord = $reportList[$report];
66  $title = !isset($reportRecord) ? "Unrecognized Report" : (isset($reportRecord["title"]) ? $reportRecord["title"] : $report);
67  printMonitorPageTop($title, $homecuKendoVersion, $cloudfrontDomainName, $bootstrapVersion, $fontawesomeVersion, true);
68 
69  $filter = $cu == "" ? "" : HCU_JsonEncode(array("field" => "cu", "operator" => "eq", "value" => $cu));
70 ?>
71 
72 <style>
73  .k-notification-wrap {
74  overflow-x: scroll;
75  overflow-y: visible;
76  }
77 
78  .loggingArea {
79  margin-left: 10px;
80  }
81  .loggingInfo {
82  white-space: pre-wrap;
83  width: 100%;
84  margin-left: 10px;
85  }
86 </style>
87 
88 <script type="text/javascript">
89 
90 <?php
91 // Include common functions
92 getShowWaitFunctions();
93 GetIsFilterChanged();
94 InitReport($presentationFile, $report, $reportList, $defaultDateFormat, true, $pageSize, false, "", $filter);
95 ?>
96 
97 var inNotification = true;
98 var inShowClick = true;
99 
100 <?php
101 /**
102  * Creates a notification popup for the logging details.
103  * @param HTMLElement tr-- the table row that the notification is opened on
104  * @param string info-- the display message
105  * @return void
106  */
107 ?>
108 function InitNotification(tr, info) {
109  var notification = $("<div></div>").kendoNotification({
110  position: {
111  pinned: false,
112  top: $(tr).offset().top - $("body").scrollTop(),
113  left: $(tr).offset().left - $("body").scrollLeft()
114  },
115  autoHideAfter: 0,
116  width: 600,
117  hideOnClick: false,
118  show: function () {
119  $(tr).data("hasNotification", true);
120  $(".k-i.notification:not(:last)").remove();
121  $(".k-i.notification .k-icon").remove();
122 
123  inNotification = $(".k-notification:hover").length != 0;
124  inShowClick = true; // This is needed or it will close right away because it starts with a click.
125 
126  // Want mouseover, mouseout here not mouseenter, mouseleave. mouseover and mouseout include entering, leaving descendants. USUALLY want mouseenter, mouseleave.
127  $(".k-notification").mouseover(function () {
128  inNotification = true;
129  });
130  $(".k-notification").mouseout(function () {
131  inNotification = false;
132  });
133 
134  $("body").on("click.tr-" + $(tr).data("uid"), function() {
135  if (inShowClick) {
136  inShowClick = false;
137  } else if (!inNotification) {
138  notification.hide();
139  }
140  return false;
141  });
142 
143  $(".closeBtn").click(function() {
144  notification.hide();
145  return false;
146  })
147 
148  },
149  hide: function () {
150  $(tr).data("hasNotification", false);
151  $("body").off("click.tr-" + $(tr).data("uid"));
152  }
153  }).data("kendoNotification");
154 
155  notification.info(info);
156 }
157 
158 <?php
159 /**
160  * @param KendoGrid grid-- the logging report grid.
161  * @param HTMLElement tr-- the row clicked. This is necessary to get the details from the dataItem.
162  * @return void
163  */
164 ?>
165 function ShowDefaultNotification(grid, tr) {
166  var dataItem = grid.dataItem($(tr));
167  var template = "<div class='loggingArea'><a href='\\#' class='closeBtn'>Close</a><br><br>";
168  template += "<b>Request:</b><br><div class='loggingInfo'>#: request #</div>";
169  template += "<br><b>Response:</b><br><div class='loggingInfo'>#: response #</div>";
170  template += "<br><br><a href='\\#' class='closeBtn'>Close</a></div>";
171  var template = kendo.template(template);
172  InitNotification($(tr), template(dataItem));
173 }
174 
175 /**
176  * 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.
177  */
178 var inRefresh = false;
179 function ForceRefresh(data, parameters, filterChanged) {
180  if (inRefresh) {
181  parameters.includeCount = "Y";
182  inRefresh = false;
183  }
184  <?php if ($cu == "") { ?>
185  parameters.saveFilter = "Y";
186  <?php } ?>
187 }
188 
189 $(document).ready(function () {
190  InitReport({parameterMapFunc: ForceRefresh, preInitFunc: function(gridDefinition) {
191  gridDefinition.columns[0] = {command: [{name: "details", text: "Details"}], width: "30px"};
192  <?php if ($cu != "") { // Cannot unfilter CU if coming in through the CU ?>
193  gridDefinition.columns[2].filterable = false;
194  gridDefinition.columns[2].sortable = false;
195  <?php } ?>
196  }});
197 
198  $("#refreshBtn").click(function() {
199  var grid = $("#reportGrid").data("kendoGrid");
200  inRefresh = true;
201  grid.dataSource.read();
202  return false;
203  });
204 
205  $("#clearAllBtn").click(function() {
206  var grid = $("#reportGrid").data("kendoGrid");
207  // If you clear the sort and then the filter, it is two calls versus one here.
208  // The cookie will be changed in the call.
209  inRefresh = true;
210  grid.dataSource.query({
211  sort: {field:"entry", dir:"desc"},
212  <?php if ($cu == "") { ?>
213  filter: [],
214  <?php } else { ?>
215  filter: {field: "cu", operator: "eq", value: "<?php echo $cu; ?>"},
216  <?php } ?>
217  pageSize: <?php echo $pageSize; ?>,
218  page: 1
219  });
220  return false;
221  });
222 
223  $("#reportGrid").on("click", ".k-grid-details", function() {
224  var grid = $("#reportGrid").data("kendoGrid");
225  ShowDefaultNotification(grid, $(this).closest("tr"));
226  });
227 });
228 </script>
229 <?php printMonitorPageMiddle($title, array("Refresh" => array("id" => "refreshBtn"), "Clear All" => array("id" => "clearAllBtn"))); ?>
230 
231  <div class="loggingReportDiv container hcu-all-100 vsgPrimary" id="loggingReportDiv">
232 
233  <div id="notification"></div>
234 
235  <div class="row hcuSpacer">
236  <div class="col-xs-12">
237  <div id="formValidateMainDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
238  </div>
239  </div>
240 
241  <div class="row hcuSpacer">
242  <div class="col-xs-12">
243  <div class="reportGridOverflow">
244  <div id="reportGrid"></div>
245  </div>
246  </div>
247  </div>
248  </div>
249 <?php printMonitorPageBottom();
250 } // No operation
251 
252 // FUNCTIONS
253 
254 /**
255  * function ReadReport($dbh, $reportList, $defaultDateFormat)
256  * Returns the data needed from the parameters for the report:
257  *
258  * "report" -- the report to read. Refers to the $reportKey in the function getReportList(). The frontend sends the variable down as a javascript literal.
259  * "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.)
260  * "limit" -- How many records to return.
261  * "offset" -- Where to start in the resultset.
262  * "newFilter" -- {true/false} If newFilter, then also find out the count of the resultset. Also, ignore the offset. It will get the first page.
263  * "sort" -- This is a json encoded string of the current sort in the grid.
264  * "filter" -- This is a json encoded string of the current filter in the grid.
265  * "printerFriendly" -- printer friendly doesn't have paging.
266  *
267  * @param $Cu -- the credit union
268  * @param $dbh -- the database connection
269  * @param $reportList -- the reportList from the getReportList() above.
270  * @param $defaultDateFormat -- This is what the date will be formatted as.
271  */
272 function ReadReport($Cu, $dbh, $reportList, $defaultDateFormat) {
273  $parameters = array("a" => array("report" => "", "initial" => "", "limit" => "", "offset" => "", "newFilter" => "", "sort" => "", "filter" => "", "printerFriendly" => ""));
274  $string = array("filter" => HCUFILTER_INPUT_STRING);
275  HCU_ImportVars($parameters, "a", array("report" => $string, "initial" => $string, "limit" => $string, "offset" => $string, "newFilter" => $string, "sort" => $string,
276  "filter" => $string, "printerFriendly" => $string));
277 
278  $report = HCU_array_key_exists("report", $parameters["a"]) ? trim($parameters["a"]["report"]) : "";
279  $initial = HCU_array_key_exists("initial", $parameters["a"]) ? trim($parameters["a"]["initial"]) == "true" : false;
280  $limit = HCU_array_key_exists("limit", $parameters["a"]) ? intval($parameters["a"]["limit"]) : -1;
281  $offset = HCU_array_key_exists("offset", $parameters["a"]) ? intval($parameters["a"]["offset"]) : 0;
282  $newFilter = HCU_array_key_exists("newFilter", $parameters["a"]) ? trim($parameters["a"]["newFilter"]) == "true" : false;
283  $sort = HCU_array_key_exists("sort", $parameters["a"]) ? trim($parameters["a"]["sort"]) : "";
284  $filter = HCU_array_key_exists("filter", $parameters["a"]) ? trim($parameters["a"]["filter"]) : "";
285  $printerFriendly = HCU_array_key_exists("printerFriendly", $parameters["a"]) ? trim($parameters["a"]["printerFriendly"]) == "true" : false;
286 
287  $includeCount = !$printerFriendly && $newFilter;
288  $limit = $printerFriendly ? -1 : $limit;
289  $offset = $printerFriendly || $newFilter ? 0 : $offset;
290 
291  $returnArray = ReadReportData($Cu, $reportList[$report], $dbh, $limit, $offset, $includeCount, false, $initial, false, $sort, $filter, $report, "loggingReport");
292 
293  header('Content-type: application/json');
294  print HCU_JsonEncode($returnArray);
295 }