Odyssey
hcuDispFunctions.i
1 <?php
2 /*
3  * Function: setIncludeFiles
4  * Purpose: Include the appropriate files for the environment. It can be used
5  * for home banking, monitor, or simple, non-decorated utility windows.
6  *
7  * NOTE: This file should be included in the "<head>" portion of a script.
8  *
9  * Parameters:
10  * @param boolean pIncludeBrand - if TRUE include the brand-related files
11  * @param boolean pIncludeGridLayout - if TRUE include the 960grid layout
12  * @param string pKendoTheme - if non-blank include the specified KendoUI theme
13  * @param boolean pIncludeHomeBanking - if TRUE include the files for Home Banking
14  * @param array pHbEnv - An array of values for the current Home Banking session.
15  *
16  * NOTES: If pIncludeBrand, then $HB_ENV and $settingsDir must already be set up.
17  * They are set up in hcuService.
18  *
19  * Returns: no return
20  */
21 function setIncludeFiles( $pIncludeBrand, $pIncludeGridLayout, $pKendoTheme, $pIncludeHomeBanking, $pHbEnv = array(), $pMC = array() ) {
22 
23 
24  $cloudfrontDomainName = (HCU_array_key_exists("cloudfrontDomainName", $pHbEnv) ? $pHbEnv['cloudfrontDomainName'] : GetCloudFrontDomainName());
25  $homecuKendoVersion = (HCU_array_key_exists("homecuKendoVersion", $pHbEnv) ? $pHbEnv['homecuKendoVersion'] : GetHomecuKendoVersion());
26  $bootstrapVersion = (HCU_array_key_exists("bootstrapVersion", $pHbEnv) ? $pHbEnv['bootstrapVersion'] : GetHomecuBootstrapVersion());
27  $fontawesomeVersion = (HCU_array_key_exists("fontawesomeVersion", $pHbEnv) ? $pHbEnv['fontawesomeVersion'] : GetFontawesomeVersion());
28  $pKendoTheme = isset($pKendoTheme) || $pKendoTheme === false ? trim($pKendoTheme) : "";
29  $pKendoTheme = $pKendoTheme == "" ? "silver" : $pKendoTheme;
30  $cuCustomBrand = '';
31  if (HCU_array_key_exists("chome", $pHbEnv) && HCU_array_key_exists("settingsDir", $pHbEnv)) {
32  // ** OLD $cuCustomBrand = " <link rel='stylesheet' media='all' type='text/css' href='/banking/static/css/brand.{$pHbEnv['chome']}.css' />";
33  $cuCustomBrand = " <link rel='stylesheet' media='all' type='text/css' href='/fi/{$pHbEnv['chome']}/bankingIncludes/{$pHbEnv['settingsDir']}/css/brand.{$pHbEnv['chome']}.css' />";
34  }
35 
36  /*
37  * Test the ACCEPT_ENCODING header value, to see if the browser is able to process gzip
38  */
39  $useGZExt = (stristr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE);
40 
41  /**
42  * STYLE SHEET INCLUDES
43  */
44  // have dev mode use non-minified files; handle browsers that cannot understand gzip encoding
45  if ( HCU_array_key_exists("SYSENV", $pHbEnv) && $pHbEnv["SYSENV"]["devmode"] == 1 ) {
46  // developer version (non-minified files)
47  $useGZExt = ""; // force non-zipped file
48  $jqueryFile = "jquery-1.10.2.js";
49  $kendoWebFile = "kendo.web.js";
50  $cssResetFile = "reset.css";
51  $cssBootstrap = "bootstrap.css";
52  $cssFontAwesome = "font-awesome.css";
53  $bootstrapFile = "bootstrap.js";
54  $jqueryCookieFile = "jquery.cookie.js";
55  } else {
56  // determine if GZip encoding can be handled
57  if ( $useGZExt ) {
58  $jqueryFile = "jquery-1.10.2.min.js.jgz";
59  $kendoWebFile = "kendo.web.min.js.jgz";
60  $cssBootstrap = "bootstrap.min.css.gz";
61  $bootstrapFile = "bootstrap.min.js.gz";
62  } else {
63  $jqueryFile = "jquery-1.10.2.min.js";
64  $kendoWebFile = "kendo.web.min.js";
65  $cssBootstrap = "bootstrap.min.css";
66  $bootstrapFile = "bootstrap.min.js";
67  }
68 
69  // these are not gzipped
70  $cssResetFile = "reset.4085.min.css";
71  $cssFontAwesome = "font-awesome.min.css";
72  $jqueryCookieFile = "jquery.cookie.4788.min.js";
73  }
74  /* RESET FORM STYLING TO CREATE CONSISTENT DISPLAY */
75  print <<< HTML_DEPS
76 
77  <link rel='stylesheet' media='all' type='text/css' href='https://{$cloudfrontDomainName}/homecu/css/$cssResetFile' />
78 
79  <!-- BASE BOOTSTRAP -->
80  <link href='https://{$cloudfrontDomainName}/homecu/css/bootstrap/{$bootstrapVersion}/css/$cssBootstrap' rel='stylesheet'/>
81 
82  <!-- KENDO BOOTSTRAP COMMON STYLES - REPLACES kendo.common.css -->
83  <link href='https://{$cloudfrontDomainName}/homecu/css/KendoUI/{$homecuKendoVersion}/kendo.common-bootstrap.min.css' rel='stylesheet'/>
84 
85  <!-- KENDO BOOTSTRAP THEME -->
86  <link href='https://{$cloudfrontDomainName}/homecu/css/KendoUI/{$homecuKendoVersion}/kendo.$pKendoTheme.min.css' rel='stylesheet'/>
87 
88  <!-- METIS MENU -->
89  <link href='/banking/static/css/metisMenu.css' rel='stylesheet'/>
90 
91  <!-- /* CUSTOM KENDO BOOTSTRAP STYLING */ -->
92  <link rel='stylesheet' media='all' type='text/css' href='/shared/static/css/homecu-custom-kendo-boot.css' />
93 
94  <!-- /* HOMECU BASE LAYOUT */ -->
95  <link rel='stylesheet' media='all' type='text/css' href='/shared/static/css/hcuLayout.css?v=201912161500' />
96  <link rel='stylesheet' media='all' type='text/css' href='/banking/static/css/layout.css??v=201912161500' />
97 
98  <!-- /* FONT AWESOME */ -->
99  <link href='https://{$cloudfrontDomainName}/homecu/css/font-awesome/{$fontawesomeVersion}/css/$cssFontAwesome' rel='stylesheet'/>
100 
101  <!-- /* brand.css and brand.cucode.css will need to be combined with the ability to properly "BRAND/THEME" for the credit union */ -->
102  {$cuCustomBrand}
103  <!-- /**
104  * JAVASCRIPT INCLUDES
105  */
106  /* JQUERY BASE */ -->
107  <script type='text/javascript' src='https://{$cloudfrontDomainName}/jquery/js/{$jqueryFile}'></script>
108 
109  <!-- /* KENDO FULL WIDGET INCLUDE - CREATE CUSTOM FOR PRODUCTION */ -->
110  <script src='https://{$cloudfrontDomainName}/homecu/js/KendoUI/{$homecuKendoVersion}/{$kendoWebFile}'></script>
111  <!-- /* BOOTSTRAP JAVASCRIPT */ -->
112  <script src='https://{$cloudfrontDomainName}/homecu/js/bootstrap/{$bootstrapVersion}/js/$bootstrapFile'></script>
113 
114  <!-- /* CUSTOM JQUERY TIMEOUT DIALOG SCRIPT */ -->
115  <!-- <script type='text/javascript' src='https://{$cloudfrontDomainName}/homecu/js/jquery-timeout-dialog.4425.min.js'></script> -->
116  <script type='text/javascript' src='/static/js/jquery-timeout-dialog.js'></script>
117 
118  <!-- /* JQUERY COOKIE */ -->
119  <script type='text/javascript' src='https://{$cloudfrontDomainName}/homecu/js/$jqueryCookieFile'></script>
120 
121  <!-- /* HOMECU CUSTOM ERRORS FOR FORMS */ -->
122  <script type='text/javascript' src='/shared/static/js/hcuFormError.js?v=201912170810'></script>
123 
124  <!-- /* HOMECU CUSTOM NOTICES FOR FORMS - PROVIDES CHAINING*/ -->
125  <script type='text/javascript' src='/banking/static/js/hcuFormNotice.js'></script>
126 
127  <!-- /* HOMECU CUSTOM KENDO SETTINGS */ -->
128  <script type='text/javascript' src='/shared/static/js/kendo.homecu.custom.js'></script>
129 
130  <!-- Toast-style notifier -->
131  <script type='text/javascript' src='/banking/static/js/CinnaToast.min.js'></script>
132 
133  <!-- /* metisMenu */ -->
134  <script type='text/javascript' src='/banking/static/js/metisMenu.js'></script>
135 HTML_DEPS;
136 
137 }
138 
139 /**
140  *
141  * This function will return the string for display in html, it was designed to be a replacement
142  * for both dms_disphtml and disp_i18n
143  *
144  * @param string $text - This is the string to be processed for display
145  * @param integer $mode - This is the htmlspecialchars entity flag
146  * @param boolean $pReplaceEntCodes - if {true} the amp; will be reqplce with a single ampersand
147  * @param string $charset - The charset to use
148  *
149  * @return string
150 */
151  function hcu_displayHtml ($text, $mode=ENT_COMPAT, $pReplaceEntCodes=false, $charset='UTF-8', $preventDblEncode=false) {
152  $retString = htmlspecialchars(trim($text), $mode, $charset, !$preventDblEncode);
153 
154  if ($pReplaceEntCodes) {
155  $retString = str_replace('&amp;#', '&#', $retString);
156  }
157  return $retString;
158  }
159 
160  function hcuFormatNumber($p_nbr, $p_show_separator = true) {
161 
162  $inc_comma = ($p_show_separator ? ",": "");
163  if (is_numeric($p_nbr)) {
164  return number_format($p_nbr, 2, ".", $inc_comma);
165  } else {
166  return $p_nbr;
167  }
168  }
169  function hcuFormatDate($p_date) {
170  // ** ONLY FORMAT A VALID DATE
171  $retVal = "";
172  $timestamp = "";
173 
174  // ** Make accommdations for a N/A coming through on the date
175  // Make sure NOT to format this date
176  if (trim($p_date) != "N/A") {
177  if (($timestamp = strtotime($p_date)) !== false) {
178  $retVal = date("m/d/y", $timestamp);
179  }
180  } else {
181  $retVal = $p_date;
182  }
183  return $retVal;
184  }
185 
186  function field_setfocus($fld) {
187 // This function will print javascript to setfocus to a particular field upon loading the form
188  print <<< EOF
189  <script language="javascript">
190  <!--
191  function field_focus() {
192  self.focus();
193  document.$fld.focus();
194  }
195  window.onload = field_focus;
196  // -->
197  </script>
198 EOF;
199 }
200 
201 
202 /**
203  *
204  * Print the Feature Menu from the cu_featuremenu table taking into account the users access list
205  *
206  * @param integer $pDbh - Current Database Connection
207  * @param array $pHbEnv - Current HB_ENV Array
208  * Cu - is needed
209  * FeatureAccessList - Compiled array of Profile Features with the user access rights
210  * @param string $pMenuOoutput - {HTML } string identifying how to output the menu
211  * @param array $pParamList - Parameter List
212  * Uid - The user id for the current user viewing the menu
213  * output - {HTML} currently HTML is only option
214  * menuId - (optional) this is the id name to use when the output is HTML
215  * @return string - This will return an empty string for any error
216  * -- Otherwise it will return the menu in the output specified
217  */
218 function PrintFeatureMenu ($pDbh, $pHbEnv, $pMenuOutput, $pParamList, $adminOnly=false, $pRetString=false) {
219  $retOutput = '';
220  try {
221 
222  /* **** VALIDATION **** */
223  /* Uid is set */
224  $userId = HCU_array_key_value('Uid', $pParamList);
225  if (intval($userId) <= 0) {
226  throw new Exception('Print Feature Menu - Invalid User Id');
227  }
228 
229  /* output is set */
230  $outType = HCU_array_key_value('output', $pParamList);
231  if ($outType == '') {
232  throw new Exception('Print Feature Menu - Output not specified');
233  }
234  /* output is set */
235  $menuCu = HCU_array_key_value('Cu', $pHbEnv);
236 
237  if ($menuCu == '') {
238  throw new Exception('Print Feature Menu - Cu not specified');
239  }
240  /* **** RETRIEVE USER ACCESS LIST **** */
241  $paramList = Array("Uid" => $userId);
242  $accessListResult = Perm_FeatureAccessList($pDbh, $pHbEnv, $paramList);
243  if ($accessListResult['status']['code'] != '000') {
244  throw new Exception('Print Feature Menu - Error Accessing Permissions');
245  }
246  $accessList = $accessListResult['data'][$userId];
247  /* **** RETRIEVE MENU FROM DATA STORE **** */
248 
249  $featureMenuResults = FetchFeatureMenu($pDbh, $menuCu, $adminOnly);
250 
251  if ($featureMenuResults['code'] == '000') {
252  if (count($featureMenuResults['data']) == 0) {
253  // Default Data Should be loaded - otherwise throw error
254  throw new ErrorException ("Print Feature Menu - Empty Menu");
255  }
256  // ** We now should have a feature menu to build from
257 
258  $featureMenuData = $featureMenuResults['data'];
259 
260  // Restrict menus with username filtering to only show for those usernames.
261  $filteredFeatureMenuData = array();
262 
263  foreach ($featureMenuData as $menuItemData) {
264  if (_PassedUserAccountFilter( trim($pHbEnv["Cn"]), HCU_array_key_value('details_memacct_filter', $menuItemData) )) {
265  $filteredFeatureMenuData[] = $menuItemData;
266  }
267  }
268  $featureMenuData = $filteredFeatureMenuData;
269 
270  if ($pMenuOutput == 'HTML') {
271  // buildMenuToHtml($HB_ENV, 1, 'list-menu', HCU_array_key_value("menu", $cuSettings));
272 
273  $retOutput = PrintMenuHtml($pHbEnv, $featureMenuData, $accessList);
274 
275  }
276 
277  } else {
278  // Default Data Should be loaded - otherwise throw error
279  throw new ErrorException ("Print Feature Menu - Unable to retrieve menu list");
280  }
281 
282 
283  } catch (Exception $ex) {
284  // ** reset output on error
285  $retOutput = '';
286  // ** Print error to apache error
287  $pHbEnv['SYSENV']['logger']->error($ex->getMessage());
288 
289  // ** DEFAULT MENU OPTION??
290 
291  }
292 
293  // ** Print or return string
294  if ($pRetString) {
295  return $retOutput;
296  } else {
297  print $retOutput;
298  }
299 }
300 
301 
302 /**
303  * HTML specific printing of the menu
304  *
305  * @param array $pHbEnv - Current class for HB_ENV
306  * @param array $pFeatureMenu - Array containing the Feature Menu
307  * @param array $pAccessList - Array containing the Access List for the user
308  *
309  * @return string - This returns the menu in html format
310  *
311  */
312 function PrintMenuHtml($pHbEnv, $pFeatureMenu, $pAccessList) {
313 
314  $retMenu = '
315  <li id="sidebar-skip-nav" class="hcu-selected-menu-item skip-nav-link">
316  <a href="#main-container">Skip Navigation</a>
317  </li>';
318 
319  /* *** HEADER *** */
320  for ($menuIdx = 0; $menuIdx < count($pFeatureMenu); $menuIdx++) {
321  $menuItemData = $pFeatureMenu[$menuIdx];
322  $menuItemType = HCU_array_key_value('MenuItemType', $menuItemData);
323  if ($menuItemType == 'H') {
324  /* *** MENU GROUP *** */
325  $parentId = HCU_array_key_value('MenuItemId', $menuItemData);
326  $parentIcon = HCU_array_key_value('details_fa_icon', $menuItemData);
327 
328  $collapseGroup = HCU_array_key_value('details_collapse_group', $menuItemData);
329 
330  // ** Reset the hasSelectedChild variable
331  $hasSelectedChild = false;
332 
333  $groupLinks = PrintMenuHtmlChildren($pHbEnv, $pFeatureMenu, $pAccessList, false, $menuIdx, $parentId, $hasSelectedChild);
334 
335  $collapseGroup = ($hasSelectedChild ? 0 : $collapseGroup);
336  $parentSelect = ($hasSelectedChild ? 'hcu-selected-menu-group' : '');
337 
338  /* *** DETAIL LINK *** */
339  if (strlen($groupLinks) > 0) {
340  $parentClass = ($collapseGroup == 1 ? "" : "active");
341  $childClass = ($collapseGroup == 1 ? "" : "in");
342 
343  // ** Child Items Are accessible -- Include this group
344  $retMenu .= "\n<li class='$parentClass $parentSelect' data-rowid='$menuIdx'>";
345  $retMenu .= "\n" . buildMenuLink($pHbEnv, $menuItemData, 'parent', $parentIcon);
346  $retMenu .= "\n<ul class='nav nav-second-level collapse $childClass'>";
347  $retMenu .= "\n" . $groupLinks;
348  $retMenu .= "\n</ul>";
349  $retMenu .="\n</li>";
350  }
351 
352  } elseif ($menuItemType == 'S') {
353  /* *** STAND ALONE *** */
354  $hasSelectedChild = false;
355  $retMenu .= PrintMenuHtmlChildren($pHbEnv, $pFeatureMenu, $pAccessList, true, $menuIdx, null, $hasSelectedChild);
356  } // ** type {D} should not be handled by this function directly, they will be ignored, misconfigured menu
357 
358 
359  }
360 
361  // ** set the master Menu <ul
362  $retMenu = "\n<ul id='list-menu' class='nav root-nav-categories'>\n$retMenu\n</ul>";
363 
364  return $retMenu;
365 }
366 
367 /**
368  * Print the children related to the ParentId that is passed into the function.
369  * The function will push the array index forward to the last child associated with the group
370  *
371  *
372  * @param boolean $pCurrentItemOnly - Print the current item ONLY
373  * true - print the item the passed in index refers {stand alone}
374  * false - print the subsequent children based on parent id
375  * @param boolean $pSelectedChild - By reference -- Does this menu group have a selected child?? --
376  * if so the group will need to make some changes as well
377  *
378  *
379  */
380 function PrintMenuHtmlChildren($pHbEnv, $pFeatureMenu, $pAccessList, $pCurrentItemOnly, &$pMenuIdx, $pParentId, &$pSelectedChild) {
381 
382  $retChildren = ''; // The html of the children to return
383 
384  if ($pCurrentItemOnly) {
385  $startIdx = $pMenuIdx;
386  $endIdx = $pMenuIdx + 1;
387  } else {
388  $startIdx = $pMenuIdx + 1;
389  $endIdx = count($pFeatureMenu);
390  }
391 
392  /**
393  * Retrieve
394  * Current Script
395  * Location Item (li)
396  */
397  $currentScript = HCU_array_key_value("currentscript", $pHbEnv);
398  $locationItem = 0;
399 
400  // ** locationItem is an integer and is the MenuItemId from the cu_featuremenu table
401  if (HCU_array_key_exists("menu-location", $pHbEnv)) {
402  $locationItem = intval(HCU_array_key_value("li", $pHbEnv['menu-location']));
403  }
404 
405  // ** Start looping through the data , start at the next indices, should be the child
406  for ($localIdx = $startIdx; $localIdx < $endIdx; $localIdx++) {
407  $childAllowed = false; // Assume false
408  $childData = $pFeatureMenu[$localIdx];
409 
410  // ** Get the parent ID of the child
411  $childParentId = HCU_array_key_value('ParentId', $childData);
412 
413  $isSelected = false; // IS THIS THE SELECTED CURRENT SCRIPT
414 
415  if ($childParentId != $pParentId && !$pCurrentItemOnly) {
416  // ** We have reached the end... break from the 'for' loop
417  break;
418  }
419 
420  // ** Verify this item can be seen
421  $childFeatureCode = HCU_array_key_value('FeatureCode', $childData);
422  $childFaIcon = HCU_array_key_value('details_fa_icon', $childData);
423  if (trim($childFeatureCode) == '') {
424  $childAllowed = true;
425  } else {
426  // ** Verify the user can see from their access list,
427  // ** The feature code MUST be found and {create || access} is true
428  $featurePerms = HCU_array_key_value($childFeatureCode, $pAccessList);
429  // ** MWS - access is used to determine if the menu includes the feature
430  if (HCU_array_key_value('access', $featurePerms)) {
431  $childAllowed = true;
432  }
433  }
434 
435  if ($childAllowed) {
436  if (strpos($childData['details_href'], $currentScript) !== false) {
437  // ** This is a match -- now see if we need to identify to a more granular level by checking the locationItem against the menuItemId, but ONLY if the locationItem > 0
438  if ($locationItem > 0) {
439  $isSelected = ($locationItem == $childData['MenuItemId']);
440 
441  } else {
442  // * * LocationItem not defined -- Good enough
443  $isSelected = true;
444  }
445  if ($isSelected) {
446  $pSelectedChild = true;
447  }
448  }
449 
450 
451 
452  /* ** CHILD ALLOWED ** -- ADD Item here */
453  $retChildren .= "\n<li class='" . ($isSelected ? 'hcu-selected-menu-item' : '') . "'>" . buildMenuLink ($pHbEnv, $childData, 'child', $childFaIcon) . "</li>";
454  }
455 
456 
457  }
458 
459 
460  // ** ALWASY substract one from the localIdx, this will properly identify the LAST child that was gathered
461  $pMenuIdx = --$localIdx;
462 
463  return $retChildren;
464 }
465 
466 /**
467  *
468  * @param array $pHbEnv - The Home Banking HB_ENV array structure
469  * @param integer $pMenuLevel - The level we are currently on {1, 2}. Currenly only support two levels
470  * @param string $pMenuId - The id of the div tag for this menu
471  * @param array $pMenuArray - This is the array with the menu information to print
472  * @param boolean $pRetString - {true/false(default)}
473  * true - the function will return a string
474  * false - the function will print the string directly to STDOUT
475  *
476  * @return string - this will return the link to print on the screen
477  *
478  */
479 function buildMenuToHtml($pHbEnv, $pMenuLevel, $pMenuId, $pMenuArray, $pRetString=false) {
480 
481  $pRetVal = '';
482  // Loop through the menuArray
483  // * Make sure the pMenuArray variable is indeed an array
484  if (is_array($pMenuArray)) {
485 
486  /**
487  * pMenuLevel
488  * 1 - this is the root level, it can be either a group of links or single link
489  * 2 - this is the child level, it is only a link under a group
490  */
491  if ($pMenuLevel == 1) {
492  $pRetVal .= "<ul id='$pMenuId' class='nav root-nav-categories' >\n";
493  } elseif ($pMenuLevel == 2) {
494  $pRetVal .= "<ul class='nav nav-second-level' >\n";
495  }
496 
497  /**
498  * Loop through each of the menu items that have been passed in
499  * Create the appropriate <li tag based on if this is a parent or child
500  */
501  foreach($pMenuArray as $menuIdx => $menuItem) {
502  /**
503  * suppressdetail - This is a parent menu item that has no children. The menu information for these items will be found in the [detail] element
504  * This will give us insight on if we create group header, or link
505  */
506  $itemSuppressDetail = HCU_array_key_value("suppressdetail", $menuItem); // OR intval()
507  $itemSuppressDetail = ($itemSuppressDetail == 1 ? true : false); // Be sure to set the default of this to 0
508 
509  /**
510  * fa-icon This is the font-awesome icon name. It is only the portion of the class after fa eg fa-cogs would produce the value cogs
511  */
512  // The first level is the main level that will have a possible font-awesome icon
513  $itemFaIcon = HCU_array_key_value("fa-icon", $menuItem);
514 
515  $levelClass = ($pMenuLevel == 2 ? 'nav nav-second-level' : 'nav root-nav-categories');
516  /**
517  * Cound the children in the detail element
518  */
519  $childrenCount = HCU_array_item_count('detail', $menuItem);
520 
521  /**
522  * menuGroupHdr - This is the final logic to make sure this is a menu Group header or a link
523  * true - create a menu group
524  * false - create only a link
525  */
526  $menuGroupHdr = (!$itemSuppressDetail && $childrenCount > 0);
527 
528  $pRetVal .= "<li class='" . ($menuGroupHdr ? 'active' : '') . " '>\n";
529 
530  /**
531  * linkDetailAry - determine the details section on where to retrieve the information for the link
532  * Direct links on the root level, that suppressdetail will get the information from the first element in the detail element
533  * All other links will get their detail section from the current menuItem
534  */
535  if ($itemSuppressDetail && is_array(HCU_array_key_value("detail", $menuItem)) && $childrenCount > 0) {
536  // ** get the first element off the 'detail' element array
537  $linkDetailAry = array_pop(HCU_array_key_value("detail", $menuItem));
538  } else {
539  $linkDetailAry = $menuItem;
540  }
541 
542 
543  $linkDetailAry = ($itemSuppressDetail ? HCU_array_key_value("detail", $menuItem)[0] : $menuItem);
544 
545  $pRetVal .= buildMenuLink($pHbEnv, $linkDetailAry, ($menuGroupHdr ? 'parent' : 'child'), $itemFaIcon); // Fetches the <a> (<i></i>) </a>
546 
547  /**
548  * Build child menu if this is a menuGroupHdr
549  */
550  if ($menuGroupHdr) {
551  $pRetVal .= buildMenuToHtml($pHbEnv, 2, '', HCU_array_key_value('detail', $menuItem), true);
552  }
553 
554  $pRetVal .= "</li>\n";
555 
556  }
557  $pRetVal .= "</ul>\n";
558 
559  }
560  /**
561  * How to return the string
562  * pRetString
563  * true - Then this will return a string
564  * false - then this will directly print the string and return a true
565  */
566  if ($pRetString) {
567  return $pRetVal;
568  } else {
569  print $pRetVal;
570  return true;
571  }
572 }
573 
574 
575 
576 /**
577  * 04-2019, note "aside" element is changed to nav element because it's not an aside
578  * @param string $pType {parent, child} - Do we create the 'menu' on top, or the 'aside' menu
579  * @param array $pMenuDetail - This is the array value of the item to print
580  * parent - The group header array value is passed in which will include all of it's details (the parent in a sense)
581  * child - The detail link to print should be passed in (the child)
582  * @param array $phb_env - Current HB_ENV value
583  * @param string $pFaIcon - If there is an icon to be printed, this is the name of the Font-Awesome Icon
584  *
585  * @return string - this will return the link to print on the screen
586  *
587  */
588 function buildMenuLink($pHbEnv, $pMenuDetail, $pType, $pFaIcon='') {
589  $menuLink = "";
590  $useLinkHref = "";
591  $useLinkTarget = "";
592  $relAttr = "";
593  //print_r($pHbEnv);
594  //print_r($pMenuDetail);
595 
596  // ** Create the href
597  /*
598  * SET the beginning of the link. There are issues using the relative URL
599  * IF the href starts with http, then this is already an absolute path, NO
600  * action needed
601  * IF NO http then add the homebankingpath to the beginning
602  *
603  */
604  if ($pType == 'parent') {
605  $useLinkHref = "#";
606  } else {
607  if (substr($pMenuDetail['details_href'], 0, 4) != 'http') {
608  $useLinkHref = $pHbEnv['homebankingpath'] . (substr($pHbEnv['homebankingpath'], -1) != '/' ? '/' : '') . $pMenuDetail['details_href']; // . "?";
609  } else {
610  $useLinkHref = $pMenuDetail['details_href']; // . "?";
611  }
612 
613  $appendQuerySep =(strpos($useLinkHref, '?') === FALSE ? '?' : '&');
614  // ** Do we add cuquery or extra parameters?
615  if ($pMenuDetail['details_hrefUrlQuery'] == 1) {
616  $useLinkHref .= $appendQuerySep . $pHbEnv['cuquery'];
617  // ** Create a unique identifier for the menu id -- ONLY if they are appending CU info
618  // -- li - // Location Item
619  $appendQuerySep = '&';
620  $useLinkHref .= "{$appendQuerySep}li=" . HCU_array_key_value('MenuItemId', $pMenuDetail);
621  }
622  $appendQuerySep =(strpos($useLinkHref, '?') === FALSE ? '?' : '&');
623  // * Extra parameters
624  if ($pMenuDetail['details_hrefExtraParam'] != '') {
625  $useLinkHref .= $appendQuerySep . $pMenuDetail['details_hrefExtraParam'];
626  }
627 
628  // ** Create the target
629  if ($pMenuDetail['details_target'] != '') {
630  $useLinkTarget = "_blank"; // $pMenuDetail['details_target'];
631  }
632 
633  // add message
634  if ($pMenuDetail['details_message'] != '') {
635  $relAttr = "external"; //Adding rel attribute for Open in New Window
636  }
637  }
638  // ** Create the anchor DisplayValue
639  // * menu type should always come from the 'parent' element,
640  // * aside type should always come from the 'child' element
641  // ** NOTE: in both cases this should be the first level 'display' element
642  //
643  // * The language is important here, en_US MUST be defined for proper logic
644  // * if a specific menu item does NOT exist for an alternate language then
645  // * the DEFAULT en_US will be used
646 
647  if ($pMenuDetail['details_display_' . $pHbEnv['Flang']] != '') {
648  $useLinkDisplay = hcu_displayHtml($pMenuDetail['details_display_' . $pHbEnv['Flang']]);
649  } else {
650  // ** USE default menu option
651  $useLinkDisplay = hcu_displayHtml($pMenuDetail['details_display_en_US']);
652  }
653 
654  /*
655  * DETERMINE PLATFORM DISPLAY
656  * evaluate details_platform_dsk AND details_platform_mbl
657  * if both are TRUE, then do nothing
658  * if both are FALSE, do not print
659  * set bootrap classes based on one or other being set
660  */
661  if ($pMenuDetail['details_platform_dsk'] || $pMenuDetail['details_platform_mbl']) {
662  $extraClass = '';
663  if ($pMenuDetail['details_platform_dsk'] === false) {
664  // ** MOBILE ONLY
665  $extraClass = ' visible-xs-block ';
666  } elseif ($pMenuDetail['details_platform_mbl'] === false) {
667  // ** DESKTOP ONLY
668  $extraClass = ' hidden-xs ';
669  } // ** else BOTH ARE SET -- NO EXTRA CLASS NEEDED
670 
671 
672  // ** create the LINK!
673  $targ = (! empty($useLinkTarget))? " target='{$useLinkTarget}'" : null;
674  $rel = (! empty($relAttr)) ? " rel='{$relAttr}'" : null;
675  $menuLink = "<a role='menuitem' class='{$extraClass}' href='{$useLinkHref}'{$targ} {$rel}>";
676 
677  $menuLink .= ($pFaIcon != '' ? "<i class='fa fa-{$pFaIcon} fa-fw'></i> " : "");
678  $menuLink .= $useLinkDisplay;
679  $menuLink .= ($pType == 'parent' ? "<span class='fa arrow'></span>" : "");
680  $menuLink .= "</a>\n";
681  }
682 
683 
684  return $menuLink;
685 }
686 
687 /**
688  *
689  * Return the Feature Menu from the cu_featuremenu table taking into account
690  * the users access list. Return info the caller can use when building its menu.
691  *
692  * @param array $pHbEnv - Current HB_ENV Array
693  * Cu - is needed
694  * Uid is needed
695  * @param string $pPlatform - Which platform (comma delimited string)
696  *
697  * @return array - This will return an empty array for any error
698  * -- Otherwise it will return the menu in the output specified
699  */
700 function FetchMenuArray( $pHbEnv, $pPlatform ) {
701  $retOutput = array();
702 
703  try {
704 
705  /* **** VALIDATION **** */
706  $dbh = $pHbEnv["dbh"];
707 
708  /* Uid is set */
709  $userId = HCU_array_key_value('Uid', $pHbEnv);
710  if (intval($userId) <= 0) {
711  throw new Exception('Build Menu Array - Invalid User Id');
712  }
713 
714  /* output is set */
715  $menuCu = HCU_array_key_value('Cu', $pHbEnv);
716 
717  if ($menuCu == '') {
718  throw new Exception('Build Menu Array - Cu not specified');
719  }
720 
721  // retrieve user access list based on permissions
722  $paramList = Array("Uid" => $userId);
723  $accessListResult = Perm_FeatureAccessList( $dbh, $pHbEnv, $paramList );
724 
725  if ($accessListResult['status']['code'] != '000') {
726  throw new Exception('Build Menu Array - Error Accessing Permissions');
727  }
728 
729  $accessList = $accessListResult['data'][$userId];
730 
731  // get the menu for the platform (no admin)
732  $featureMenuResults = FetchFeatureMenu( $dbh, $menuCu, false, $pPlatform );
733 
734  if ($featureMenuResults['code'] == '000') {
735  if (count($featureMenuResults['data']) == 0) {
736  // Default Data Should be loaded - otherwise throw error
737  throw new ErrorException ("Build Menu Array - Empty Menu");
738  }
739  // ** We now should have a feature menu to build from
740 
741  $featureMenuData = $featureMenuResults['data'];
742 
743  // return as php array
744  $retOutput = BuildMenuArray( $pHbEnv, $featureMenuData, $accessList );
745 
746  } else {
747  // Default Data Should be loaded - otherwise throw error
748  throw new ErrorException ("Build Menu Array - Unable to retrieve menu list");
749  }
750 
751 
752  } catch (Exception $ex) {
753  // ** reset output on error
754  $retOutput = '';
755  // ** Print error to apache error
756  $pHbEnv['SYSENV']['logger']->error( $ex->getMessage());
757 
758  // ** DEFAULT MENU OPTION??
759 
760  }
761 
762  // ** return the menu array
763  return $retOutput;
764 } // FetchMenuArray
765 
766 /* Test if the given user name is in the user account filter list. The list is
767  * comma separated values.
768  */
769 function _PassedUserAccountFilter( $pUsername, $pUserAccountStr ) {
770 
771  $filterPassed = false;
772 
773  $lowerUsername = trim(strtolower($pUsername));
774  $lowerFilter = trim(strtolower($pUserAccountStr));
775 
776  if ($lowerFilter == "") {
777  $filterPassed = true;
778  } else {
779  // get the list into parts
780  $parts = explode( ",", $lowerFilter );
781  if ( count( $parts ) == 0 ) {
782  $filterPassed = true;
783  } else {
784  if ( in_array( $lowerUsername, $parts ) ) {
785  $filterPassed = true;
786  }
787  }
788  }
789 
790  return $filterPassed;
791 } // end _PassedUserAccountFilter
792 
793 /**
794  * PHP Array creation of the menu. The platform filtering should have already taken place.
795  *
796  * @param array $pHbEnv - Current class for HB_ENV
797  * @param array $pFeatureMenu - Array containing the Feature Menu
798  * @param array $pAccessList - Array containing the Access List for the user
799  *
800  * @return array - This returns the menu as a php array.
801  *
802  */
803 function BuildMenuArray( $pHbEnv, $pFeatureMenu, $pAccessList ) {
804  $retMenu = array();
805 
806  for ($i = 0; $i < count( $pFeatureMenu ); $i++) {
807  $menuItemData = $pFeatureMenu[$i];
808 
809  // test if user account filter passed (comma separated values)
810  $passed = _PassedUserAccountFilter( $pHbEnv["username"], HCU_array_key_value('details_memacct_filter', $menuItemData) );
811  if ( !$passed ) {
812  continue;
813  }
814 
815  $menuItemId = HCU_array_key_value('MenuItemId', $menuItemData);
816  $menuDisplayOrder = HCU_array_key_value('DisplayOrder', $menuItemData);
817  $parentId = "";
818  $menuFeatureCode = HCU_array_key_value('FeatureCode', $menuItemData);
819  $menuItemType = HCU_array_key_value('MenuItemType', $menuItemData);
820  $displayNameEnglish = HCU_array_key_value('details_display_en_US', $menuItemData);
821  $displayNameSpanish = HCU_array_key_value('details_display_es_US', $menuItemData);
822  $displayNamePolish = HCU_array_key_value('details_display_pl_US', $menuItemData);
823  $menuItemIcon = HCU_array_key_value('details_fa_icon', $menuItemData);
824  $menuHref = HCU_array_key_value( 'details_href', $menuItemData );
825  $menuCollapse = HCU_array_key_value( 'details_collapse_group', $menuItemData );
826 
827  if ( $pHbEnv["Flang"] == "es_US" ) {
828  $displayName = $displayNameSpanish;
829  } else if ( $pHbEnv["Flang"] == "es_US" ) {
830  $displayName = $displayNamePolish;
831  } else {
832  $displayName = $displayNameEnglish;
833  }
834 
835  // use the same names as came in
836  $thisMenu = array(
837  "menu_item_id" => $menuItemId,
838  "menu_display_order" => $menuDisplayOrder,
839  "menu_parent_id" => $parentId,
840  "menu_feature_code" => $menuFeatureCode,
841  "menu_item_type" => $menuItemType,
842  "menu_display_name_en_US" => $displayNameEnglish,
843  "menu_display_name_es_US" => $displayNameSpanish,
844  "menu_display_name_pl_US" => $displayNamePolish,
845  "menu_display_name" => $displayName,
846  "menu_icon_name" => $menuItemIcon,
847  "menu_script" => $menuHref,
848  "menu_extra_param" => "",
849  "menu_add_cu" => "",
850  "menu_collapse_group" => $menuCollapse,
851  "menu_target" => ""
852  );
853 
854  if ($menuItemType == 'H') {
855  // menu group header
856 
857  $menuChildren = GatherMenuChildren( $pHbEnv, $pFeatureMenu, $pAccessList, $i, $menuItemId );
858 
859  // if no children, don't use the group
860  if ( count( $menuChildren ) ) {
861  // add the item(s) to the menu
862  $thisMenu["menu_children"] = $menuChildren;
863  $retMenu[] = $thisMenu;
864  }
865 
866  } elseif ($menuItemType == 'S') {
867  // ** The feature code MUST be found and {create || access} is true
868  // NOTE: Even for SSOs the menu item must be associated with a feature.
869  $featurePerms = HCU_array_key_value( $menuFeatureCode, $pAccessList );
870 
871  // access is used to determine if the menu includes the feature
872  if ( !HCU_array_key_value('access', $featurePerms) ) {
873  continue;
874  }
875 
876  // test if user account filter passed (comma separated values)
877  $passed = _PassedUserAccountFilter( $pHbEnv["username"], HCU_array_key_value('details_memacct_filter', $menuItemData) );
878  if ( !$passed ) {
879  continue;
880  }
881 
882  // stand-alone - add the missing items
883  $menuHref = HCU_array_key_value( 'details_href', $menuItemData );
884  $menuTarget = HCU_array_key_value('details_target', $menuItemData);
885  $menuExtraParam = HCU_array_key_value('details_hrefExtraParam', $menuItemData);
886  $menuMemAcctFilter = HCU_array_key_value('details_memacct_filter', $menuItemData);
887  $menuAddCU = HCU_array_key_value( 'details_hrefUrlQuery', $menuItemData );
888 
889  $thisMenu["menu_script"] = $menuHref;
890  $thisMenu["menu_extra_param"] = $menuExtraParam;
891  $thisMenu["menu_add_cu"] = $menuAddCU;
892  $thisMenu["menu_target"] = $menuTarget;
893  $thisMenu["menu_new_window"] = $menuTarget; // this is to better name the flag for the apps
894 
895  $retMenu[] = $thisMenu;
896  }
897  // NOTE: type {D} should not be handled by this function directly, they will be ignored, misconfigured menu
898 
899  }
900 
901  return $retMenu;
902 } // end BuildMenuArray
903 
904 /**
905  * PHP Array creation of the menu. The platform filtering should have already taken place.
906  *
907  * @param array $pHbEnv - Current class for HB_ENV
908  * @param array $pFeatureMenu - Array containing the Feature Menu
909  * @param array $pAccessList - Array containing the Access List for the user
910  * @param integer $pStartIndex - Starting point in the Feature Menu (earlier ones already processed)
911  * @param integer $pParentId - Id of the parent menu item
912  *
913  * @return array - This returns the menu as a php array.
914  *
915  */
916 function GatherMenuChildren( $pHbEnv, $pFeatureMenu, $pAccessList, $pStartIndex, $pMenuParentId ) {
917  $retChildren = array();
918 
919  for ($i = $pStartIndex; $i < count( $pFeatureMenu ); $i++) {
920  $menuItemData = $pFeatureMenu[$i];
921 
922  // skip headers
923  $menuItemType = HCU_array_key_value('MenuItemType', $menuItemData);
924 
925  if ( $menuItemType != "D" ) {
926  continue;
927  }
928 
929  // check the parent id
930  $parentId = HCU_array_key_value('ParentId', $menuItemData);
931 
932  if ( $parentId != $pMenuParentId ) {
933  continue;
934  }
935 
936  // verify the user can access the feature
937  $menuFeatureCode = HCU_array_key_value( 'FeatureCode', $menuItemData );
938 
939  // ** The feature code MUST be found and {create || access} is true
940  // NOTE: Even for SSOs the menu item must be associated with a feature.
941  $featurePerms = HCU_array_key_value( $menuFeatureCode, $pAccessList );
942 
943  // access is used to determine if the menu includes the feature
944  if ( !HCU_array_key_value('access', $featurePerms) ) {
945  continue;
946  }
947 
948  // test if user account filter passed (comma separated values)
949  $passed = _PassedUserAccountFilter( $pHbEnv["username"], HCU_array_key_value('details_memacct_filter', $menuItemData) );
950  if ( !$passed ) {
951  continue;
952  }
953 
954  // add the menu item to the return array
955  $menuItemId = HCU_array_key_value( 'MenuItemId', $menuItemData );
956  $menuDisplayOrder = HCU_array_key_value( 'DisplayOrder', $menuItemData );
957  $menuItemType = HCU_array_key_value( 'MenuItemType', $menuItemData );
958  $displayNameEnglish = HCU_array_key_value( 'details_display_en_US', $menuItemData );
959  $displayNameSpanish = HCU_array_key_value( 'details_display_es_US', $menuItemData );
960  $displayNamePolish = HCU_array_key_value( 'details_display_pl_US', $menuItemData );
961  $menuHref = HCU_array_key_value( 'details_href', $menuItemData );
962  $menuItemIcon = HCU_array_key_value( 'details_fa_icon', $menuItemData );
963  $menuTarget = HCU_array_key_value( 'details_target', $menuItemData );
964  $menuExtraParam = HCU_array_key_value( 'details_hrefExtraParam', $menuItemData );
965  $menuAddCU = HCU_array_key_value( 'details_hrefUrlQuery', $menuItemData );
966 
967  if ( $pHbEnv["Flang"] == "es_US" ) {
968  $displayName = $displayNameSpanish;
969  } else if ( $pHbEnv["Flang"] == "es_US" ) {
970  $displayName = $displayNamePolish;
971  } else {
972  $displayName = $displayNameEnglish;
973  }
974 
975  // use the same names as came in
976  $thisMenu = array(
977  "menu_item_id" => $menuItemId,
978  "menu_display_order" => $menuDisplayOrder,
979  "menu_parent_id" => $parentId,
980  "menu_feature_code" => $menuFeatureCode,
981  "menu_item_type" => $menuItemType,
982  "menu_display_name_en_US" => $displayNameEnglish,
983  "menu_display_name_es_US" => $displayNameSpanish,
984  "menu_display_name_pl_US" => $displayNamePolish,
985  "menu_display_name" => $displayName,
986  "menu_script" => $menuHref,
987  "menu_icon_name" => $menuItemIcon,
988  "menu_extra_param" => $menuExtraParam,
989  "menu_add_cu" => $menuAddCU,
990  "menu_target" => $menuTarget,
991  "menu_new_window" => $menuTarget
992  );
993 
994  $retChildren[] = $thisMenu;
995  }
996 
997  return $retChildren;
998 } // end GatherMenuChildren
999 
1000 /**
1001  *
1002  * Evaluate the permissions of a particular feature and if the user does not have the correct rights
1003  * redirect the page to an errorpage
1004  *
1005  * @param integer $pDbh - the current database handle
1006  * @param object $pHbEnv - The current HB_ENV structure
1007  * @param object $pMc - Language Object
1008  * @param string $pFeature - the Feature that must have access
1009  * @param string $pPerm - (default access) the value here will be evaluated in perms structure
1010  * - if false then the error page will be displayed
1011  * @param boolean $pRedirect - (default true) - if true the page will redirect to the error page
1012  * - if false then it returns to caller
1013  * @return boolean
1014  */
1015 function PermCheckFeatureScreen ($pDbh, $pHbEnv, $pMc, $pFeature, $pPerm='', $pRedirect=true) {
1016 
1017  $retVal = false;
1018 
1019  $pPerm = ($pPerm == '' ? 'access' : $pPerm);
1020 
1021  // ** Verify the user can access this feature.
1022  $permissionInputs = array( "feature" => $pFeature );
1023  $accessRights = Perm_AccessRights( $pDbh, $pHbEnv, $permissionInputs );
1024 
1025  // Banking Admin Mode: Restricts access to Account, Balances, History, and Sign Off when coming into banking.
1026  if (HCU_array_key_value('Ca', $pHbEnv) != "" && !in_array(basename($_SERVER['SCRIPT_NAME']), array("hcuAccounts.prg", "hcuHistory.prg", "hcuHistory.data", "hcuLogout.prg")))
1027  {
1028  header ("Location: hcuPermNotice.prg?cu=" . HCU_array_key_value('Cu', $pHbEnv));
1029  exit;
1030  }
1031  if ( ! HCU_array_key_value($pPerm, $accessRights)) {
1032 
1033  if ($pRedirect) {
1034  header ("Location: hcuPermNotice.prg?cu=" . HCU_array_key_value('Cu', $pHbEnv));
1035  // ** DO NOT CONTINUE
1036  exit;
1037  }
1038  } else {
1039  // ** Feature appears to have access
1040  $retVal = true;
1041  }
1042 
1043 
1044  return $retVal;
1045 }
1046 
1047 /**
1048  *
1049  * Evaluate permissions for Admins logging into User Accounts (BAM)
1050  * Redirect to an errorpage
1051  * Only used when not specifying a certain feature for permission
1052  *
1053  * @param integer $pDbh - the current database handle
1054  * @param object $pHbEnv - The current HB_ENV structure
1055  * @param object $pMc - Language Object
1056  * @param boolean $pRedirect - (default true) - if true the page will
1057  * redirect to the error page
1058  * - if false then it returns to caller
1059  * @return boolean
1060  */
1061 function PermCheckBAM ($pDbh, $pHbEnv, $pMc, $pRedirect=true) {
1062 
1063  $retVal = false;
1064 
1065  // Banking Admin Mode: Restricts access to Account, Balances, History, and Sign Off when coming into banking.
1066  if (HCU_array_key_value('Ca', $pHbEnv) != "" && !in_array(basename($_SERVER['SCRIPT_NAME']), array("hcuAccounts.prg", "hcuHistory.prg", "hcuHistory.data", "hcuLogout.prg"))) {
1067  header ("Location: hcuPermNotice.prg?cu=" . HCU_array_key_value('Cu', $pHbEnv));
1068  exit;
1069  } else {
1070  // user has access
1071  $retVal = true;
1072  }
1073 
1074  return $retVal;
1075 }