Odyssey
showhavetrans.prg
1 <?php
2 $previousScript= "showhavetrans";
3 require_once("adm_reports.prg");
4 require_once("cu_flagconst.i");
5 
6 dms_import(array("report" => "string", "operation" => "string", "servers" => "string", "showServer" => "string"));
7 
8 $showSQL= false;
9 $title= "Allowed Transaction Settings";
10 $cookieName= "showhavetrans";
11 $url= $_SERVER["PHP_SELF"];
12 $defaultDateFormat= "MM/dd/yyyy";
13 
14 $showhavetransSQLTemplate= "select a.cu, a.orgname, # from (select cu, orgname from cuadmin where livebatch <> 'C') a";
15 $createReportList= true;
16 $cookie= "";
17 $reportList= array();
18 $errors= array();
19 $sqls= array();
20 
21 if (isset($_COOKIE[$cookieName]))
22 {
23  parse_str($_COOKIE[$cookieName]);
24 
25  if ($transListEncoded == "")
26  {
27  $transList= setTransList($link, $cookieName, $errors, $sqls, $usedTransEncoded);
28 
29  }
30  else
31  {
32  $transList= json_decode($transListEncoded, true);
33  }
34 
35  $usedTrans= $usedTransEncoded == "" ? array() : json_decode($usedTransEncoded, true);
36 
37  createReportListFromFlags($link, $showSQL, $reportList, $errors, $sqls, $transList, $usedTrans, $cookieName, $showhavetransSQLTemplate);
38 }
39 else
40 {
41  $transList= setTransList($link, $cookieName, $errors, $sqls, $cookieName);
42 }
43 
44 function setTransList($link, $cookieName, &$errors, &$sqls, $usedTransEncoded="")
45 {
46  $sql= "select trancode, trandesc from cutrans order by trancode";
47 
48  $results= runSelectStatementMap($sql, $link);
49  $errors= array_merge($errors, $results["error"]);
50  $sqls[]= $sql;
51  $transList= $results["record"];
52 
53  $expiresInDay= time()+86400;
54  $cookie= "usedTransEncoded=$usedTransEncoded&transListEncoded=" . urlencode(json_encode($transList));
55 
56  HCU_setcookie_env($SYSENV, $cookieName, $cookie, $expiresInDay);
57  return $transList;
58 }
59 
60 function createReportListFromFlags($link, $showSQL, &$reportList, &$errors, &$sqls, $transList, $usedTrans, $cookieName, $showhavetransSQLTemplate)
61 {
62  $errors= array();
63  $sqls= array();
64 
65  $joinList= array();
66  $colList= array("CU" => "string", "Org Name" => "string");
67  $values= array();
68  $colSelectList= array();
69 
70  $index= 0;
71 
72  if (is_array($usedTrans)) {
73  foreach($usedTrans as $trans)
74  {
75  $text= isset($transList[$trans]) ? $transList[$trans] : "t$index";
76  $colSelectList[]= "t$index.trancode";
77  $joinList[]= "left join (select * from cuhavetrans where trancode='$trans') as t$index on a.cu= t$index.cu";
78  $colList[$text]= "string";
79  $values[$text]= array(array("text" => "+", "value" => $trans), array("text" => " ", "value" => ""));
80  $index++;
81  }
82  }
83 
84  if (count($colSelectList) == 0) // nothing selected so select all
85  {
86  $index= 0;
87  foreach($transList as $value => $text)
88  {
89  $colSelectList[]= "t$index.trancode";
90  $joinList[]= "left join (select * from cuhavetrans where trancode='$value') as t$index on a.cu= t$index.cu";
91  $colList[$text]= "string";
92  $values[$text]= array(array("text" => "+", "value" => $value), array("text" => " ", "value" => ""));
93  $index++;
94  }
95  }
96 
97  $sql= str_replace("#", implode(", ", $colSelectList), $showhavetransSQLTemplate) . "\n" . implode("\n", $joinList);
98 
99  $reportList= array("loanAddon" => array("title" => "", "sql" => $sql, "cols" => $colList, "values" => $values));
100 }
101 
102 function outputFlagRows($transList)
103 {
104  print "<div class='grid_16 flagHeader'>Transcode</div>\n";
105 
106  $index= 0;
107  $row= "";
108  foreach($transList as $value => $text)
109  {
110  $modulus= $index % 4;
111  if ($modulus == 0)
112  $row= "<div class='grid_16'>
113  <div class='grid_4 alpha'>#0#</div>
114  <div class='grid_4'>#1#</div>
115  <div class='grid_4'>#2#</div>
116  <div class='grid_4 omega'>#3#</div>
117  </div>";
118  $row= str_replace("#$modulus#", "<input type='checkbox' class='transFlag' value=$value>$text</input>", $row);
119  if ($modulus == 3)
120  {
121  print "$row\n";
122  $row= "";
123  }
124  $index++;
125  }
126 
127  if ($row != "")
128  {
129  $row= preg_replace("/#[0-3]#/", "&nbsp;", $row);
130  print "$row\n";
131  }
132  print "<div class='grid_16'><hr></div><div class='grid_16'>&nbsp;</div>\n";
133 }
134 
135 function outputLegend($transList, $usedTrans)
136 {
137  $data= array();
138  $cols= 2;
139  $rowIndex= 0;
140  $row= "not started";
141  foreach($usedTrans as $index => $value)
142  {
143  $modulus= $index % $cols;
144  if ($modulus == 0)
145  $row= array("rowIndex" => ++$rowIndex);
146  $row["property$modulus"]= $transList[$value];
147  $row["value$modulus"]= $value;
148 
149  if ($modulus == $cols-1)
150  {
151  $data[]= $row;
152  $row= "not started";
153  }
154  }
155 
156  if ($row != "not started")
157  $data[]= $row;
158 
159  if (count($data) == 0) // nothing selected so everything.
160  {
161  $data= array();
162  $rowIndex= 0;
163  $index= 0;
164  $row= "not started";
165  foreach($transList as $value => $text)
166  {
167  $modulus= $index % $cols;
168  if ($modulus == 0)
169  $row= array("rowIndex" => ++$rowIndex);
170  $row["property$modulus"]= $text;
171  $row["value$modulus"]= $value;
172 
173  if ($modulus == $cols-1)
174  {
175  $data[]= $row;
176  $row= "not started";
177  }
178  $index++;
179  }
180 
181  if ($row != "not started")
182  $data[]= $row;
183  }
184 
185  print "gridDefinition.dataSource.data= " . json_encode($data) . ";\n";
186 }
187 
188 if (!isset($operation)) {$operation ="";}
189 if ($operation == "setReportCookie")
190 {
191  $parameters= array();
192  dms_import_v2($parameters, "BOTTOM_LEVEL", array("usedTrans" => "string"));
193 
194  $usedTrans= $parameters["BOTTOM_LEVEL"]["usedTrans"];
195 
196  $expiresInDay= time()+86400;
197  $cookie= "usedTransEncoded=$usedTrans&transListEncoded=" . urlencode(json_encode($transList));
198  HCU_setcookie_env($SYSENV, $cookieName, $cookie, $expiresInDay);
199 
200  header("Location: $url?report=loanAddon&servers=$servers&showServer=$showServer");
201  exit;
202 }
203 else if ($operation != "")
204 {
205 
206  $errors= array();
207  $sqls= array();
208 
209  switch ($operation)
210  {
211  case "readReport":
212  readReport($link, $showSQL, $errors, $sqls, $reportList, $defaultDateFormat, $cookieName);
213  break;
214  case "readReportSQL":
215  readReport($link, true, $errors, $sqls, $reportList, $defaultDateFormat, $cookieName);
216  break;
217  case "generateCSV":
218  generateCSV($link, $errors, $sqls, $reportList, $defaultDateFormat, $cookieName);
219  break;
220  default: // Won't get here
221  header('Content-type: application/json');
222  $errors[]= "Operation not specified: '$operation'";
223  $returnArray= array("error" => $errors, "record" => "", "operation" => "");
224  print json_encode($returnArray);
225  }
226 }
227 else
228 {
229 
230 
231 // Presentation layer
232 // ************************************
233 
234 if (!isset($report)) {$report ="";}
235 $report= trim($report);
236 
237 $reportMenuDDL= array("REDIRECT" => array("list" => array("Selection List" => array("url" => $presentationFile))),
238  "Download CSV" => array("id" => "downloadCSVBtn"), "Help &nbsp;<img src=\"/monitor/images/q1.gif\" border=\"0\" alt=\"View Help\" align=\"top\">" => array("id" => "helpBtn"));
239 
240 // Page for selecting the report.
241 // *****************************************************
242 if ($report == "")
243 {
244  printMonitorPageTop($title, $homecuKendoVersion, $cloudfrontDomainName);
245 ?>
246 
247 <style>
248  .flagHeader {
249  background-color: #B2B3C2 !important;
250  text-align: center !important;
251  font-size: 120%;
252  }
253 </style>
254 
255 <script type="text/javascript">
256 <?php
257 getErrorsAreShownFunction();
258 getEscapeHTMLFunction();
259 ?>
260 function initReportSelectPage()
261 {
262  var localServer = "<?php echo $_SERVER['SERVER_NAME']; ?>";
263  var serverMultiselect= $("#serverMultiselect").kendoMultiSelect({
264  dataSource: {
265  data: ["www3", "www5", "www6", localServer]
266  },
267  value: ["www3", "www5", "www6", localServer]
268  }).data("kendoMultiSelect");
269 
270  $("#serverMultiselect").prev().css({height: 25});
271 
272  $("#runReportBtn").click(function() {
273 
274  var data= {error: []};
275  if (!errorsAreShown(data, "formValidateMainDiv"))
276  {
277  var url= "<?php echo $url; ?>?operation=setReportCookie";
278  var showServer= $("#showServerCheckbox:checked").length > 0 ? "Y" : "N";
279  var servers= kendo.stringify(serverMultiselect.value());
280 
281  url+= "&showServer=" + showServer + "&servers=" + servers;
282 
283  var flags= [];
284  $(".transFlag").each(function() {
285  if ($(this).is(":checked"))
286  flags.push($(this).val());
287  });
288  url+= "&usedTrans=" + kendo.stringify(flags);
289 
290  window.location.href= url;
291  }
292 
293  return false;
294  });
295 }
296 
297 $(document).ready(function () {
298  initReportSelectPage();
299 });
300 </script>
301 <?php printMonitorPageMiddle($title); ?>
302 
303  <div id='hideSubmitWait' style='position:relative; left:-2000px;top:-2000px;'>
304  <div id='homecuSubmitWait' class='k-block' >
305  <div class='k-loading-image'></div>
306  </div>
307  </div>
308  <div class="container_16">
309  <?php outputFlagRows($transList, $usedTrans); ?>
310  <div class="grid_16">
311  Include Data From: <div id="serverMultiselect"></div>
312  </div>
313  <div class="grid_16">
314  Show Server: <input type="checkbox" id="showServerCheckbox">
315  </div>
316  <div class="grid_16">
317  <a href="#" class="k-button k-button-icontext" id="runReportBtn">Go</a>
318  </div>
319  </div>
320 <?php }
321 // Page for displaying the reports.
322 // **************************************************************
323 else
324 {
325  printMonitorPageTop($title, $homecuKendoVersion, $cloudfrontDomainName);
326 ?>
327 
328 <style>
329  #legendDiv .k-grid-toolbar {
330  background-color: #9BAFBE !important;
331  font-weight: bold !important;
332  text-align: center !important;
333  }
334  #legendDiv .firstGridToolbar {
335  background-color: #B2B3C2 !important;
336  }
337 
338  fieldset {
339  border: 1px solid black;
340  border-radius: 10px;
341  margin: 5px;
342  vertical-align: top;
343  display: inline;
344  width: 415px;
345  padding: 5px;
346  }
347 </style>
348 
349 <script type="text/javascript">
350 
351 <?php
352 // Include common functions
353 getErrorsAreShownFunction();
354 getEscapeHTMLFunction();
355 getShowSQLFunction($showSQL);
356 getShowWaitFunctions();
357 getIsFilterChanged();
358 initReportClientSide($presentationFile, $report, $title, array("servers" => $servers, "showServer" => $showServer), true, "addWidthsPre", "addWidthsPost"); // pass the variables down.
359 ?>
360 
361 function addWidthsPre(gridDefinition)
362 {
363  gridDefinition.columns[0].width= "100px"; // CU
364  gridDefinition.columns[1].width= "200px"; // orgName
365 }
366 
367 function addWidthsPost(grid)
368 {
369  for(var i=2, length=grid.columns.length; i!=length; i++)
370  {
371  grid.autoFitColumn(i);
372  }
373 
374  $("#reportGrid").css({width: $("#reportGrid table").css("width")});
375 }
376 
377 function initOptions()
378 {
379  var gridDefinition= {
380  dataSource: {
381  schema: {
382  model: {
383  id: "rowIndex",
384  fields: {
385  rowIndex: {type: "number"},
386  property0: {type: "string"},
387  value0: {type: "string"},
388  property1: {type: "string"},
389  value1: {type: "string"}
390  }
391  }
392  }
393  },
394  columns: [
395  {field: "property0", title: "Flag"},
396  {field: "value0", title: "Value"},
397  {title: " ", template: " ", width: "3px"},
398  {field: "property1", title: "Flag"},
399  {field: "value1", title: "Value"}
400  ]
401  };
402  <?php outputLegend($transList, $usedTrans); ?>
403  var legendGrid= $("#legendGrid").kendoGrid(gridDefinition).data("kendoGrid");
404 
405  $("#includeLegend").click(function () {
406  if ($(this).is(":checked"))
407  $("#legendDiv").show();
408  else
409  $("#legendDiv").hide();
410  });
411 
412  $("#legendDiv .k-grid-toolbar:eq(0)").addClass("firstGridToolbar");
413 
414  var cuOptionsDDL= $("#cuOptionsDDL").kendoDropDownList({
415  dataSource: {
416  data: [{text: "Show Selected Flags for All Credit Unions", value: 1}, {text: "Show Credit Unions w/ All Selected Flags Set", value: 2},
417  {text: "Show Credit Unions w/ Any Selected Flag Set", value: 3}]
418  },
419  dataTextField: "text",
420  dataValueField: "value",
421  change: function() {
422  var filter= [];
423  var dataRows = $("#reportGrid").data("kendoGrid").dataSource.data();
424  var dataColumns = $("#reportGrid").data("kendoGrid").columns;
425 
426  if (this.value() != 1) {
427  // Loop through all table rows
428  for (var i = 0; i < dataRows.length; i++) {
429  var hasAll = true;
430  var hasOne = false;
431 
432  var row = dataRows[i];
433  var rowCu = row.cu;
434 
435  // Loop through all columns in each row
436  for (var j = 0; j < dataColumns.length; j++) {
437  var column = dataColumns[j];
438  var columnName = column.field.trim();
439 
440  // Skip these columns we don't need them
441  if (columnName == "cu" || columnName == "orgName" || columnName == "server") {
442  continue;
443  }
444 
445  // Test when the field has a value
446  if (row[columnName] == "") {
447  hasAll = false;
448  } else {
449  hasOne = true;
450  }
451  }
452 
453  // The filtering dropdown has two main values:
454  // 1: Show any rows where the credit union has all flags set
455  // 2: Show any rows where the credit union has at least one flag set
456  if (this.value() == 2 && hasAll) {
457  filter.push({field: "cu", operator: "eq", value: rowCu});
458  } else if (this.value() == 3 && (hasOne || hasAll)) {
459  filter.push({field: "cu", operator: "eq", value: rowCu});
460  }
461  }
462 
463  // It is possible that no filters may be added, when this
464  // happens kendo will display the entire record set when
465  // we really want to display no results.
466 
467  // Create dummy filter to display no results.
468  if (filter.length == 0) {
469  filter.push({field: "cu", operator: "eq", value: ""});
470  }
471 
472  filter= {logic: "or", filters: filter};
473  }
474  $("#reportGrid").data("kendoGrid").dataSource.filter(filter);
475  }
476  }).data("kendoDropDownList");
477 
478  cuOptionsDDL.value(1);
479 }
480 
481 $(document).ready(function () {
482  initReport();
483  initOptions();
484 });
485 </script>
486 <?php
487 printMonitorPageMiddle($title, $reportMenuDDL); ?>
488  <div id='hideSubmitWait' style='position:relative; left:-2000px;top:-2000px;'>
489  <div id='homecuSubmitWait' class='k-block' >
490  <div class='k-loading-image'></div>
491  </div>
492  </div>
493 
494  <div id="notification"></div>
495  <div class="container_12">
496  <div class="grid_12">
497  <div id="sqlOutput"></div>
498  </div>
499  <fieldset id="optionsDiv">
500  <div class="grid_12">
501  <div class="grid_3">Include Legend:</div>
502  <div class="grid_9"><input id="includeLegend" type="checkbox"></div>
503  </div>
504  <div class="grid_12">
505  <div class="grid_3">Filter: </div>
506  <div class="grid_9"><div id="cuOptionsDDL" style="width:100%"></div></div>
507  </div>
508  </fieldset>
509  <div class="grid_12" id="legendDiv" style="display:none;">
510  <div id="legendGrid" ></div>
511  </div>
512  <div class="grid_12" style="margin-bottom:5px;">
513  <div id="formValidateMainDiv" class="k-block k-error-colored" style="display:none;"></div>
514  </div>
515  <div class="grid_12">
516  <div id="reportGrid"></div>
517  </div>
518  </div>
519 <?php printMonitorPageBottom();
520 } // Report selected
521 } // No operation