Odyssey
userSupportHub.prg
1 <?php
2 /**
3  * @package UserSupport (Subpackage head)
4  * @author SPB
5  *
6  * This script is run when the user clicks on the user hub link on the left menu.
7  */
8 
9  // Get advanced permissions
10 $advPerm = checkPerm($Cn, "userSupportAdv", $Cu)[1] == 1;
11 $bamPerm = checkPerm($Cn, "MemAccount", $Cu)[1] == 1;
12 $isEmployee = false;
13 $isMasterUser = $Cn === strtolower(trim($Cu));
14 
15 require_once("$admLibrary/userSearch.i");
16 
17 if ($advPerm) {
18  require_once("$admLibrary/addUser.i");
19 }
20 
21 $self = "$menu_link?ft=$ft";
22 
23 $string = array("filter" => FILTER_DEFAULT);
24 $parameters = array("a" => array("payload" => ""));
25 HCU_ImportVars($parameters, "a", array("payload" => $string));
26 
27 $payload = HCU_array_key_exists("payload", $parameters["a"]) ? trim($parameters["a"]["payload"]) : "";
28 $userRecord = array();
29 $counts = array();
30 if ($payload != "") {
31  try {
32  $userRecord = HCU_PayloadDecode($Cu, $payload);
33  $counts = getUserHubCounts($dbh, $Cu, intval($userRecord["user_id"]));
34 
35  $groupEncryption = encryptGroup($dbh, $Cu, $userRecord);
36 
37  // Employee permissions:
38  // If Admin user is not the master user -AND-
39  // employee is not limited to not see BAM (generally) -AND-
40  // employee flag on user is set -THEN-
41  // false (but show different msg than bamPerm failure) -OTHERWISE-
42  // true
43  if (!$isMasterUser && $bamPerm) {
44  $isEmployee = HCU_array_key_exists("employee", $userRecord) && $userRecord["employee"] === "Y";
45  }
46  } catch(exception $e) {}
47 }
48 $groupEncryption = isset($groupEncryption) ? $groupEncryption : "";
49 
50 ?>
51 <script type="text/javascript">
52 <?php
53 // Library javascript functions
54 
55 getShowWaitFunctions();
56 
57 // Javascript functions defined here
58 // NEED to separate fts here because basic user can search but CANNOT add user.
59 printUserSearch("$menu_link?ft=16", "userHubCallback", true, $advPerm);
60 printInitCards($menu_link, $advPerm, $bamPerm, $isEmployee, $isMasterUser);
61 
62 if ($advPerm) {
63  printAddNewUser("$menu_link?ft=17", "userHubCallback", $dbh, $Cu);
64 }
65 
66 ?>
67  var payload = "<?php echo $payload; ?>";
68  var groupPayload = "<?php echo $groupEncryption; ?>";
69  var ghSearchOptionSelected = null;
70  var ghSearchRowSelected = null;
71  function openAccountTab() {
72  $("#accountTabForm").submit();
73  return false;
74  }
75 
76  var activeWindows = [];
77  $(document).ready(function() {
78  <?php if (count($userRecord) == 0) { ?>
79  openUserSearch();
80  <?php } ?>
81  initCardDiv();
82 
83  <?php printClickOverlayEvent();
84  if (count($userRecord) != 0) { ?>
85  userHubCallback("successfulOneRecord", payload, <?php echo HCU_JsonEncode($userRecord); ?>, <?php echo HCU_JsonEncode($counts); ?>, groupPayload);
86  <?php } ?>
87 
88  InitPermTooltips();
89  });
90 
91  <?php
92  /**
93  * function InitPermTooltips()
94  * Initializes the tooltip when the user doesn't have full permissions.
95  */ ?>
96  function InitPermTooltips() {
97  <?php // set up the tooltips this way so the defaults can be used ?>
98  var toolTipProps = homecuTooltip.defaults;
99  toolTipProps.filter = ".vsgDisabled.dtooltip";
100 
101  toolTipProps.showOn = "click mouseenter";
102  toolTipProps.content = function(e) {
103  var text = "";
104  if ($(e.target).is("[data-tabname]")) {
105  var card = "";
106  if ($(e.target).hasClass("employeePerm")) {
107  text = "You cannot view an employee's account.";
108  } else {
109  switch ($(e.target).data("tabname")) {
110  case "addUser":
111  card = "add user";
112  break;
113  case "accessControl":
114  card = "view account access";
115  break;
116  case "rights":
117  card = "view user rights";
118  break;
119  case "delete":
120  card = "delete user";
121  break;
122  case "viewUser":
123  card = "view user accounts";
124  break;
125  }
126  text = card == "" ? "" : "You do not have permission to " + card + ".";
127  }
128  }
129  return text;
130  };
131  toolTipProps.show = function(e) {
132  if( this.content.text() !== "") {
133  $('[role="tooltip"]').css("visibility", "visible");
134  }
135  };
136  toolTipProps.hide = function() {
137  $('[role="tooltip"]').css("visibility", "hidden");
138  };
139 
140  $("#cardContainerDiv").kendoTooltip(toolTipProps).data("kendoTooltip");
141  }
142 
143  </script>
144  <script id="userInfoTemplate" type="text/x-kendo-template">
145  # if (unencrypted == null) { #
146  <div class='noUserFound'><div>No User Found</div></div>
147  # } else { #
148  <?php printHubLabelBlock(array("User" => "# if (unencrypted.user_name == null || unencrypted.user_name == '') { # &nbsp; # } else { # #: unencrypted.user_name # # } #",
149  "Email" => "# if (unencrypted.email == null || unencrypted.email == '') { # &nbsp; # } else { # #: unencrypted.email # # } #",
150  "Phone" => "# if (unencrypted.cellnumber == null || unencrypted.cellnumber == '') { # &nbsp; # } else { # #: unencrypted.cellnumber # # } #",
151  "Group" => "# if (unencrypted.group_name == null || unencrypted.group_name == '') { # &nbsp; # } else { # "
152  . "<a href='\\#' id='userInfoGroupLink'>#: unencrypted.group_name # <i class=\"fa fa-users fa-fw\"></i></a> (#: unencrypted.profile_desc #) # } #")); ?>
153  # } #
154  </script>
155  <?php printUserSearchTemplate(); ?>
156  <script id="titleTemplate" type="text/x-kendo-template">
157  User Hub # if (cardTitle != null && cardTitle.trim() != "") { # / #: cardTitle # # } #
158  # if (user_name != null && user_name.trim() != "") { # / #: user_name # # } #
159  </script>
160  <div id="cardContainerDiv" class="hideAA"></div>
161  <form id="accountTabForm" action="<?php echo $menu_link; ?>?ft=9" method="post" target="_blank">
162  <input type="hidden" name="payload" value="">
163  </form>
164  <div id="groupSearchModule"></div>
165  <form id="groupLinkRedirect" action="<?php echo $menu_link ?>?ft=102101" method="post">
166  <input type="hidden" name="payload" value="">
167  </form>
168 <?php
169 /**
170  * function getTabList()
171  * This is an array of all the needed attributes of each card. Ft needs to point to the FT that the tab script originates. In Main, $just_script needs to be set to true.
172  */
173 function getTabList() {
174  return array(
175  "search" => array("name" => "search", "text" => "Search", "shortDescription" => "Search for another user.", "icon" => "fa-search"),
176  "other" => array(
177  array("name" => "addUser", "text" => "Add User", "shortDescription" => "Add user to this user's group", "icon" => "fa-plus", "ft" => 15),
178  array("name" => "showRelated", "text" => "Show Related", "shortDescription" => "Show users sharing this user's accounts", "icon" => "fa-sitemap", "ft" => 6),
179  array("name" => "accessControl", "text" => "Access Control", "shortDescription" => "Manage access to member accounts and sub-accounts", "icon" => "fa-asterisk", "ft" => 5),
180  array("name" => "status", "text" => "Status", "shortDescription" => "Status and settings for this user", "icon" => "fa-tasks", "ft" => 1),
181  array("name" => "audit", "text" => "Events", "shortDescription" => "Show changes to this user's account information", "icon" => "fa-calendar", "ft" => 2),
182  array("name" => "rights", "text" => "User Rights", "shortDescription" => "Manage this user's rights and limitations for banking features", "icon" => "fa-cubes", "ft" => 4),
183  array("name" => "viewUser", "text" => "View User Accounts", "shortDescription" => "Enter Banking Access Mode for this user", "icon" => "fa-list", "callJs" => "openAccountTab()"),
184  array("name" => "alerts", "text" => "User Alerts", "shortDescription" => "Manage alerts this user has configured", "icon" => "fa-bell", "ft" => 8),
185  array("name" => "repeat", "text" => "Scheduled Transfers", "shortDescription" => "Manage scheduled transfers for this user", "icon" => "fa-calendar-check-o", "ft" => 13),
186  array("name" => "secureMessages", "text" => "Secure Messages", "shortDescription" => "Show conversations with this user", "icon" => "fa-comments", "ft" => 3),
187  array("name" => "delete", "text" => "Delete User", "shortDescription" => "&nbsp;", "icon" => "fa-trash", "ft" => 7)
188  ));
189 }
190 
191 
192 /**
193  * function printInitCards($menu_link)
194  * This prints out the javascript functions needed to initialize cards
195  *
196  * @param string $menu_link -- points to the main script (with no ft).
197  */
198 function printInitCards($menu_link, $advPerm, $bamPerm, $isEmployee, $isMasterUser) {
199  $tabs = getTabList();
200  ?>
201  var payload = "", foundUser = false;
202  function initCardDiv() {
203  var cardPopupWindow = $("#cardPopupWindow").data("kendoWindow");
204  if (cardPopupWindow != null) {
205  return;
206  }
207 
208  var template = "<div class='col-xs-12'><div class='well well-sm row borderless'>\
209  <h2 class='hubTitle'><span class='hcu-breadcrumb'>User Hub</span></h2>\
210  <div class='search'><a href='#'><i class='fa <?php echo $tabs["search"]["icon"]; ?> fa-3x'></i><br>Search</a></div>\
211  <div class='infoDiv'></div>\
212  </div></div>";
213 
214  <?php foreach($tabs["other"] as $index => $tab) {
215  $dataFt = "";
216  $openClass = "";
217  $disabledClass = "";
218  $aStart = "<a href='#' class='goBtn'>";
219  $aEnd = "</a>";
220  if (!$advPerm && in_array($tab["name"], array("addUser", "accessControl", "rights", "delete"))) {
221  $openClass = "openFt";
222  $disabledClass = "vsgDisabled dtooltip";
223  $aStart = "";
224  $aEnd = "";
225  } else if ($tab["name"] == "viewUser") {
226  $disabledClass = "vsgDisabled dtooltip";
227 
228  if (!$isMasterUser && $bamPerm && $isEmployee) {
229  $disabledClass .= " employeePerm";
230  } else if ($isMasterUser || $bamPerm) {
231  $disabledClass = "";
232  } ?>
233 
234  $("#cardContainerDiv").on("click", "[data-tabname='<?php echo $tab["name"]; ?>']:not(.vsgDisabled) .goBtn", function () {
235  <?php echo $tab["callJs"] . "\n"; ?>
236  return false;
237  });
238  <?php
239  } else if (HCU_array_key_exists("ft", $tab)) {
240  $dataFt = "data-ft='" . $tab["ft"] . "'";
241  $openClass = "openFt";
242  } else if (HCU_array_key_exists("callJs", $tab)) { ?>
243  $("#cardContainerDiv").on("click", "[data-tabname='<?php echo $tab["name"]; ?>']:not(.vsgDisabled) .goBtn", function () {
244  <?php echo $tab["callJs"] . "\n"; ?>
245  return false;
246  });
247  <?php } ?>
248  template += "<div class='col-md-4 col-xs-6 cardDiv <?php echo $openClass; ?> aa <?php echo $disabledClass; ?>'"
249  + " data-tabname='<?php echo $tab["name"]; ?>' <?php echo $dataFt; ?>>"
250  + "<?php echo $aStart; ?><div class='features-column col-md-12 center'><div class='features-box-header'>"
251  + "<i class='fa <?php echo $tab["icon"]; ?> fa-3x'></i><h6 class='textSpan'><?php echo $tab["text"]; ?></h6></div><div class='feature-box-content col-md-11 center'>"
252  + "<p class='vsgSecondary hidden-xs hidden-sm'><?php echo $tab["shortDescription"]; ?></p></div></div><?php echo $aEnd; ?></div>";
253  <?php } ?>
254 
255  $("#cardContainerDiv").html(template);
256 
257  var template = kendo.template($("#userInfoTemplate").html());
258  $("#cardContainerDiv .infoDiv").html(template({unencrypted: null}));
259 
260  $("#cardContainerDiv").on("click", ".search a", function() {
261  if ($(".k-overlay:visible").length == 0) {
262  openUserSearch(userHubCallback);
263  }
264  return false;
265  });
266 
267  $("#cardContainerDiv").on("click", ".cardDiv.openFt .goBtn", function() {
268  openTabWindow(this);
269  return false;
270  });
271 
272  $("#cardContainerDiv").on("click", "#userInfoGroupLink", function() {
273  $("#groupLinkRedirect").submit();
274  return false;
275  });
276 
277  $("#cardContainerDiv").on("click", "#userInfoAccountLink", function() {
278  $("#accountLinkRedirect").submit();
279  return false;
280  });
281  }
282 
283  <?php
284  /**
285  * Opens the tab window.
286  * @param cardToOpen -- the HTML element of the card to open.
287  * @param doInitialize -- initialize it.
288  */ ?>
289  function openTabWindow(cardToOpen, doInitialize) {
290  if (doInitialize || ($(".k-overlay:visible").length == 0 && !$(cardToOpen).closest(".openFt").hasClass("vsgDisabled"))) {
291  var data = $(cardToOpen).closest(".cardDiv").data();
292 
293  var externalTabWindow = $("#externalTabWindow").data("kendoWindow");
294  if (externalTabWindow == null) {
295  externalTabWindow = $("<div id='externalTabWindow'></div>").appendTo("body").kendoWindow({
296  visible: false,
297  minWidth: 768,
298  maxWidth: "90%",
299  modal: true,
300  resizable: false,
301  draggable: true,
302  <?php
303  /**
304  * open: function()
305  *
306  * This checks to see if the included script has set the $("#externalTabWindow").data("preferredHeight"); attribute. If it has, then the window is that height.
307  * Otherwise, it will be the whole height of the browser window minus a couple of pixels.
308  */
309  ?>
310  open: function() {
311  if (window.activeWindows != null) {
312  window.activeWindows.push(this);
313  }
314 
315  if (typeof(userSupportDoOnActivate) == "function") {
316  userSupportDoOnActivate();
317  }
318 
319  resizingAndWhatnot(this);
320  },
321  <?php
322  /**
323  * close: function(e)
324  *
325  * This has a couple of parameters: "shouldClose" and "isClosing." If the subscript has already validated stuff and is forcing a close on this window, then the call
326  * to this window.close() needs to be wrapped with the "isClosing" attribute. If it isn't, then the "shouldClose" variable is set.
327  * Then a hook function "userSupportDoOnClose" is called. If it exists, then this is called and this is where any "Discard Changes" popups are defined.
328  */
329  ?>
330  close: function(e) {
331  $("#externalTabWindow").data("preferredHeight", null);
332  $("#externalTabWindow").data("shouldClose", true);
333  if (!$("#externalTabWindow").data("isClosing")) {
334  if (typeof(userSupportDoOnClose) == "function") {
335  userSupportDoOnClose();
336  }
337  }
338  if ($("#externalTabWindow").data("shouldClose")) {
339  if (window.activeWindows != null) {
340  window.activeWindows.pop();
341  }
342  } else {
343  e.preventDefault();
344  return false;
345  }
346 
347  $("#externalTabWindow").find("script").each(function() {
348  var matches = $(this).html().trim().match(/function\s*[a-z_]+/gi);
349  if (matches != null) { <?php // Ignore kendo templates ?>
350  for(var i = 0; i != matches.length; i++) {
351  var thisFunction = matches[i].replace(/function\s*/gi, "");
352  window[thisFunction] = undefined;
353  }
354  }
355  });
356 
357  window.userSupportContents = undefined;
358 
359  // Remove any windows/dialogs created so that there are no potential conflicts with other cards.
360  var selector = $("body > .k-window:not(:has(.searchDialog),.kWindowCard,:has(#homecuSubmitWait))");
361  kendo.destroy($(selector));
362  $(selector).remove();
363 
364  kendo.destroy($("#externalTabWindow *"));
365  $("body").off("click.userSupportHubNamespace");
366  <?php // This generically destroys any kendo widgets within the tab. Without the asterisk, it will also destroy the window itself. ?>
367  }
368  }).data("kendoWindow");
369 
370  $("#externalTabWindow").closest(".k-window").addClass("kWindowCard");
371  }
372 
373  var titleTemplate = kendo.template($("#titleTemplate").html());
374  var templateData = $("#cardContainerDiv").data("unencrypted");
375  templateData.cardTitle = $(cardToOpen).closest(".cardDiv").find(".textSpan").text().trim();
376  externalTabWindow.title(titleTemplate(templateData));
377 
378  $.post("<?php echo $menu_link; ?>?ft=" + data.ft, {payload: payload}, function(returnData) {
379  externalTabWindow.content(returnData).open();
380  });
381  }
382  }
383 
384 
385  <?php
386  /**
387  * function resizingAndWhatnot(externalWindow)
388  * Does the resizing for the window.
389  *
390  * @param externalWindow -- the external window to resize.
391  */
392  ?>
393  function resizingAndWhatnot(externalWindow) {
394  var kWindow = $(externalWindow.wrapper);
395  externalWindow.center();
396  var preferredHeight = $("#externalTabWindow").data("preferredHeight");
397  var preferredWidth = $("#externalTabWindow").data("preferredWidth");
398  var maxHeight = $(window).height() - 150;
399 
400  var height = preferredHeight == null ? maxHeight : (preferredHeight == "auto" ? "initial" : (preferredHeight > maxHeight ? maxHeight : preferredHeight));
401  $(kWindow).css({position: "absolute", top: "10px", height: height});
402  }
403 
404  <?php
405  /**
406  * function userHubCallback(mode, message, unencrypted, counts)
407  * This is the function that is called when the user search is done (whether a fail or a success).
408  *
409  * @param string mode -- "successfulOneRecord", "successfulSelection", "invalidFind", "invalidSearch"
410  * @param string message -- the encrypted message which will be passed to each of the tab scripts.
411  * @param array unencrypted -- the unencrypted row for values on THIS page (if relevant).
412  * @param array counts -- if from the user hub, then there another call for the counts (for the secure message count for example.)
413  */
414  ?>
415  function userHubCallback(mode, message, unencrypted, counts, groupEncryption, openAccessControl) {
416  if (unencrypted != null) {
417  var template = kendo.template($("#titleTemplate").html());
418  $(".hubTitle").html(template({user_name: unencrypted.user_name, cardTitle: null, name: unencrypted.name}));
419  }
420 
421  $("#cardContainerDiv").data("unencrypted", unencrypted);
422  $("#groupLinkRedirect [name='payload']").val(groupEncryption);
423 
424  if (mode == "successfulSelection" || mode == "successfulOneRecord") {
425  payload = message;
426 
427  var template = kendo.template($("#userInfoTemplate").html());
428  $("#cardContainerDiv .infoDiv").html(template({unencrypted: unencrypted}));
429  if (unencrypted != null) {
430  foundUser = true;
431  $("#cardContainerDiv").removeClass("hideAA");
432  }
433 
434  <?php // Apply counts to secure messages and whatever other cards need it. ?>
435 
436  if (counts.secureMessages > 0) {
437  var number = counts.secureMessages > 9 ? "9+" : counts.secureMessages + "";
438  $(".cardDiv[data-tabname='secureMessages'] i").html("<span class='badge'>"+number+"</span>");
439  } else {
440  $(".cardDiv[data-tabname='secureMessages'] i").empty();
441  }
442  $("#accountTabForm [name='payload']").val(payload);
443 
444  if (openAccessControl != null && openAccessControl) {
445  openTabWindow($(".cardDiv.openFt[data-tabname='accessControl'] .goBtn"), true);
446  }
447 
448  <?php if (!$isMasterUser && $bamPerm) { ?>
449  var isEmployee = unencrypted.employee === "Y";
450  if (isEmployee) {
451  $("[data-tabname='viewUser']").addClass("dtooltip vsgDisabled employeePerm");
452  } else {
453  <?php if (!$bamPerm) { ?>
454  $("[data-tabname='viewUser']").removeClass("employeePerm");
455  <?php } else { ?>
456  $("[data-tabname='viewUser']").removeClass("dtooltip vsgDisabled employeePerm");
457  <?php } ?>
458  }
459  <?php } ?>
460  }
461  }
462 <?php }
Definition: User.php:7