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