Odyssey
aGroupHub.prg
1 <?php
2 /**
3  * @package GroupHub
4  * @author MGHandy
5  *
6  * @uses admin users may search and select groups. Upon selecting a group, the admin user
7  * will have the options of viewing the groups's rights, information and delete.
8  *
9  * @uses payload entry point: pre-select a group by sending an encrypted
10  * payload to the group hub from another script.
11  *
12  * @param $operation string: selected group hub operation, not currently needed.
13  * @param $payload string: encrypted data string holding group information
14  * to be displayed.
15  */
16 
17 require_once("$admLibrary/aGroupSupport.i");
18 
19 try {
20  $admVars = array();
21  $admOk = array(
22  "operation" => array("filter" => FILTER_SANITIZE_STRING),
23  "payload" => array("filter" => FILTER_SANITIZE_URL)
24  );
25  HCU_ImportVars($admVars, "GROUP_HUB", $admOk);
26 
27 
28  $gOperation = isset($admVars["GROUP_HUB"]["operation"]) ? $admVars["GROUP_HUB"]["operation"] : null;
29  $gPayload = isset($admVars["GROUP_HUB"]["payload"]) ? $admVars["GROUP_HUB"]["payload"] : null;
30 
31  // if a payload exists, decode into group array
32  $gGroup = $gPayload ?
33  GroupDecrypt($SYSENV, $Cu, $gPayload) :
34  null;
35 
36  // Seems to be a problem with having a payload inside a payload. Group > User > Group > User etc. doesn't work.
37  for($i = 0; $i < count($gGroup["group"]["g_primary"]); $i++)
38  {
39  $primary = $gGroup["group"]["g_primary"][$i];
40  $gGroup["group"]["g_primary"][$i]["p_payload"]= urlencode(encryptUser($Cu, $primary, false));
41  }
42 
43  $gGroup = HCU_JsonEncode($gGroup);
44 
45  // Get advanced permissions
46  $advPerm = checkPerm($Cn, "userSupportAdv", $Cu)[1] == 1;
47 
48  PrintGroupHub($gPayload, $gGroup, $advPerm);
49 
50 } catch (Exception $e) {
51  $SYSENV['logger']->error($e->getMessage());
52  exit;
53 }
54 
55 ?>
56 
57 <?php function PrintGroupHub($pPayload, $pGroup, $pAdvPerm) {
58  $disabledLabel = $pAdvPerm ? "false" : "true";
59 ?>
60 <script type="text/x-kendo-template" id="contentSearch">
61  <div class='search' data-name="#: name #" data-ft="#: ft #"><a href='\\#'><i class='fa #: icon # fa-3x'></i><br>#: text #</a></div>
62 </script>
63 
64 <script type="text/x-kendo-template" id="contentResults">
65 <div class="infoDiv">
66 # if (display) {
67  var primaries= [];
68  for(var i=0; i!= g_primary.length; i++) {
69  primaries.push('<a href="main.prg?ft=22&payload=' + g_primary[i].p_payload + '">' + g_primary[i].p_name + '<i class="fa fa-user fa-fw"></i></a>');
70  }
71  primaries= primaries.join(","); #
72  <?php printHubLabelBlock(array("Group Name" => "# if (g_name == null) { # (None) # } else { # #: g_name # # } #",
73  "User Count" => "#: g_count #",
74  "Profile Name" => "# if (g_profile == null) { # (None) # } else { # #: g_profile # # } #",
75  "&nbsp;" => "&nbsp;",
76  "Primary Owner# if (g_primary.length > 1) { #(s)# } #" => "# if (g_primary.length == 0) { # (None) # } else { # #= primaries # # } #")); ?>
77 
78  #if(g_primary.length > 1) {#
79  <div class="col-xs-12">
80  <p><span class="fa fa-exclamation-triangle" style="color: \#ff9800;"></span> This group has multiple primary owners. Please use the "Group Information" card below to correct the issue.</p>
81  </div>
82  #}#
83 </div>
84 # } else { #
85  <div class='noUserFound'><div>No Group Found</div></div>
86 # } #
87 </div>
88 </script>
89 
90 <script type="text/x-kendo-template" id="contentCards">
91  # var disabledLabel = disabled === true ? "vsgDisabled" : (disabled === "norights" ? "vsgDisabled dtooltip" : ""); #
92  <div class="col-md-4 col-xs-6 cardDiv openFt aa #: disabledLabel #" data-name="#: name #" data-ft="#: ft #">
93  <a href="\\#" class="goBtn">
94  <div class="features-column center col-md-12">
95  <div class="features-box-header">
96  <i class="fa fa-3x #: icon #"></i>
97  <h6 class='textSpan'>#: text #</h6>
98  </div>
99 
100  <div class="feature-box-content center col-md-11">
101  <p class="vsgSecondary hidden-xs hidden-sm">#= desc #</p>
102  </div>
103  </div>
104  </a>
105  </div>
106 </script>
107 <script id="titleTemplate" type="text/x-kendo-template">
108  Group Hub # if (cardTitle != null && cardTitle.trim() != "") { # / #: cardTitle # # } #
109  # if (g_name != null && g_name.trim() != "") { # / #= g_name # # } #
110 </script>
111 
112 <div id="cardContainerDiv">
113  <div class="well well-sm borderless">
114  <h2 id="titleContainerDiv" class="hubTitle"></h2>
115  <div id="resultContainerDiv"></div>
116  </div>
117 </div>
118 <div id="cardContent"></div>
119 
120 <?php
121 /**
122  * @package GroupHub
123  * @uses this objectis used to display and interact with the group hub and its features.
124  *
125  * @var Init public: public call to initialize data/view/action objects,
126  * @var Call public: callback for group modules to update display or encryption.
127  * This function facilitates updating/loading request modules with encrypted group data
128  * as well as display of selected group data.
129  *
130  * @var InitDataSources private: initialize all data sources/objects
131  * @var InitDataViews private: initialize all data views/objects
132  * @var InitDataActions private: initialize all user actions on html.
133  *
134  * @var EventCardClick private: send request to view the clicked module.
135  */
136 ?>
137 <script type="text/javascript">
138 <?php getShowWaitFunctions(); ?>
139 var groupWindows = null;
140 var groupHub = null;
141 
142 var GroupHub = function() {
143  ghPayload = null;
144  ghGroup = null;
145  ghResults = null;
146  ghSearchOptionSelected= null;
147  ghSearchRowSelected= null;
148 
149  ghWindowContainer = null;
150  ghWindow = null;
151 
152  ghHeader = null;
153  ghHeaderContent = null;
154  ghHeaderSearchContent = null;
155  ghHeaderResultsContent = null;
156  ghHeaderSearchView = null;
157  ghHeaderResultsView = null;
158 
159  ghTitle = null;
160  ghTitleContent = null;
161  ghTitleView = null;
162 
163  ghCards = null;
164  ghCardsView = null;
165  ghCardsData = null;
166 
167  var EventCardClick = function(e) {
168  var card = $(this);
169  var cardFt = card.data("ft");
170  var cardName = card.data("name");
171 
172  if (ghCardsData[cardName].display.disabled) {
173  return;
174  }
175 
176  // close on the card object will call the kendo
177  // destory for every window and dialog for that card
178  // in order to keep the html clear and save memory.
179  if (ghWindow) {
180  ghWindow.Close();
181  }
182 
183  // clear out any left over html from the content div
184  // load the clicked card
185  $(ghWindowContainer).empty();
186  $(ghWindowContainer).load("main.prg?ft=" + cardFt, function(response) {
187  switch (cardName) {
188  case "GroupSearch":
189  ghWindow = new GroupSearch();
190  ghWindow.Data(ghResults, ghSearchOptionSelected, ghSearchRowSelected);
191  break;
192  case "GroupSettings":
193  ghWindow = new GroupSettings();
194  break;
195  case "GroupUsers":
196  ghWindow = new GroupUsers();
197  break;
198  case "GroupRights":
199  ghWindow = new GroupRights();
200  break;
201  case "GroupDelete":
202  ghWindow = new GroupDelete();
203  break;
204  }
205 
206  // give the card a fresh window stack
207  groupWindows = [];
208 
209  // initialize the card with the callback function
210  // to the hub.
211  // Open the card giving it the new window stack.
212  ghWindow.Init(groupHub.Call, ghWindowContainer);
213  ghWindow.Open(groupWindows);
214  });
215  }
216 
217  var InitDataSources = function() {
218  ghCardsData = {
219  "GroupRights": {
220  display: {
221  ft: "102103",
222  icon: "fa-cubes", name: "GroupRights",
223  text: "Group Rights", desc: "Manage the group rights and limitations to banking features", disabled: <?php echo $disabledLabel; ?>}
224  },
225  "GroupSettings": {
226  display: {
227  ft: "102104",
228  icon: "fa-tasks", name: "GroupSettings",
229  text: "Group Settings", desc: "Settings specific to this group.", disabled: <?php echo $disabledLabel; ?>}
230  },
231  "GroupUsers": {
232  display: {
233  ft: "102105",
234  icon: "fa-user-circle-o", name: "GroupUsers",
235  text: "Group Users", desc: "Show all users in this group.", disabled: false }
236  },
237  "GroupDelete": {
238  display: {
239  ft: "102106",
240  icon: "fa-trash", name: "GroupDelete",
241  text: "Delete Group", desc: "&nbsp;", disabled: false }
242  },
243  "GroupSearch": {
244  display: {
245  ft: "102102",
246  icon: "fa-search", name: "GroupSearch",
247  text: "Search", desc: "", disabled: false
248  }
249  }
250  };
251  }
252 
253  var InitDataViews = function() {
254  ghTitle = $("#titleContainerDiv");
255  ghTitleContent = kendo.template($("#titleTemplate").html());
256  ghTitleView = ghTitleContent({ cardTitle: null,g_name: null });
257  ghTitle.append(ghTitleView);
258 
259  ghHeader = $("#resultContainerDiv");
260  ghHeaderSearchContent = kendo.template($("#contentSearch").html());
261  ghHeaderResultsContent = kendo.template($("#contentResults").html());
262  ghHeaderSearchView = ghHeaderSearchContent(ghCardsData["GroupSearch"].display);
263  ghHeaderResultsView = ghHeaderResultsContent({ display: false });
264  ghHeader.append(ghHeaderSearchView);
265  ghHeader.append(ghHeaderResultsView);
266 
267  ghCards = $("#cardContainerDiv");
268  ghCardsContent = kendo.template($("#contentCards").html());
269  ghCards.find(".cardDiv").hide();
270 
271  ghWindowContainer = $("#cardContent");
272 
273  <?php if (!$pAdvPerm) { ?>
274  InitPermTooltips();
275  <?php } ?>
276  }
277 
278  <?php
279  /**
280  * function InitPermTooltips()
281  * Initializes the tooltip when the user doesn't have full permissions.
282  */ ?>
283  function InitPermTooltips() {
284  <?php // set up the tooltips this way so the defaults can be used ?>
285  var toolTipProps = homecuTooltip.defaults;
286  toolTipProps.filter = ".vsgDisabled.dtooltip";
287 
288  toolTipProps.showOn = "click mouseenter";
289  toolTipProps.content = function(e) {
290  var text = "";
291  if ($(e.target).is("[data-name]")) {
292  var card = "";
293  switch ($(e.target).data("name")) {
294  case "GroupRights":
295  card = "change group rights";
296  break;
297  case "GroupSettings":
298  card = "change group settings";
299  break;
300  }
301  text = card == "" ? "" : "You do not have permission to " + card + ".";
302  }
303  return text;
304  };
305  toolTipProps.show = function(e) {
306  if( this.content.text() !== "") {
307  $('[role="tooltip"]').css("visibility", "visible");
308  }
309  };
310  toolTipProps.hide = function() {
311  $('[role="tooltip"]').css("visibility", "hidden");
312  };
313 
314  $("#cardContainerDiv").kendoTooltip(toolTipProps).data("kendoTooltip");
315  }
316 
317  var InitDataActions = function() {
318  ghHeader.find(".search").off();
319  ghHeader.find(".search").on("click", EventCardClick);
320  ghCards.find(".cardDiv").off();
321  ghCards.find(".cardDiv").on("click", EventCardClick);
322  }
323 
324  this.Call = function(action, data) {
325  // Populate breadcrumb at top of hub page
326  if (data && data.group) {
327  var template= kendo.template($("#titleTemplate").html());
328  $(".hubTitle").html(template({g_name: data.group.g_name, cardTitle: null}));
329  }
330 
331  switch (action) {
332  case "updateGroupInfo":
333  // unencrypted group data for display to the group hub
334  // data is the group information to be displayed
335  // empty the display, put new data in
336  ghGroup = data.group;
337  ghGroup.g_name = ghGroup.g_name ? ghGroup.g_name.trim() : "";
338  ghGroup.g_profile = ghGroup.g_profile ? ghGroup.g_profile.trim() : "";
339  ghGroup.g_primary = ghGroup.g_primary ? ghGroup.g_primary : [];
340  ghGroup.g_user = ghGroup.g_user ? ghGroup.g_user.trim() : "";
341  ghGroup.g_count = parseInt(ghGroup.g_count);
342  ghGroup.display = true;
343 
344  ghHeader.empty();
345  ghHeaderSearchView = ghHeaderSearchContent(ghCardsData["GroupSearch"].display);
346  ghHeaderResultsView = ghHeaderResultsContent(ghGroup);
347  ghHeader.append(ghHeaderSearchView);
348  ghHeader.append(ghHeaderResultsView);
349 
350  ghCardsView = "";
351  for(var key in ghCardsData) {
352  if (["GroupSearch"].indexOf(key) !== -1) {
353  continue;
354  } else if (["GroupSettings", "GroupRights"].indexOf(key) !== -1) {
355  <?php if ($pAdvPerm) { ?>
356  if (ghGroup.g_count == 0) {
357  ghCardsData[key].display.disabled = true;
358  } else {
359  ghCardsData[key].display.disabled = false;
360  }
361  <?php } else { ?>
362  ghCardsData[key].display.disabled = "norights";
363  <?php } ?>
364  } else if (["GroupUsers", "GroupInfo"].indexOf(key) !== -1) {
365  if (ghGroup.g_count == 0) {
366  ghCardsData[key].display.disabled = true;
367  } else {
368  ghCardsData[key].display.disabled = false;
369  }
370  }
371  ghCardsView += ghCardsContent(ghCardsData[key].display);
372  }
373  ghCards.find(".cardDiv").remove();
374  ghCards.append(ghCardsView);
375  ghCards.show();
376 
377  InitDataActions();
378  break;
379  case "updateGroupEncrypt":
380 
381  // data is the updated group encryption payload.
382  // this will be given to each card as it is opened.
383  ghPayload = data;
384  break;
385  case "updateGroupResults":
386 
387  // save search results for next time the search window is opened
388  ghResults = data;
389  break;
390  case "removeGroupInfo":
391  ghPayload = null;
392  ghGroup = null;
393 
394  ghHeader.empty();
395  ghTitle.empty();
396 
397  InitDataSources();
398  InitDataViews();
399  InitDataActions();
400  break;
401  default:
402 
403  // loaded card needs to get payload and group info
404  // data is the actual javascript card object,
405  // Data is the public function we pass the payload and group info
406  // for saving to the object
407  data.Data(ghPayload, ghGroup);
408  break;
409  }
410  }
411 
412  this.Init = function(payload, group) {
413  InitDataSources();
414  InitDataViews();
415  InitDataActions();
416 
417  ghPayload = payload;
418  ghGroup = group;
419 
420  if (ghPayload && ghGroup.group) {
421  this.Call("updateGroupEncrypt", ghPayload);
422  this.Call("updateGroupInfo", ghGroup);
423  } else {
424  ghHeader.find(".search").trigger("click");
425  }
426  }
427 }
428 
429 $(document).ready(function() {
430  var payload = "<?php echo $pPayload ?>";
431  var group = <?php echo $pGroup; ?>;
432 
433  groupWindows = [];
434  groupHub = new GroupHub();
435  groupHub.Init(payload, group);
436 });
437 
438 $(document).on("click", ".k-overlay", function() {
439  if (groupWindows.length > 0) {
440  var openWindow = groupWindows[groupWindows.length - 1];
441  openWindow.close();
442  }
443 });
444 
445 </script>
446 <?php }