Odyssey
userSupportShowRelated.prg
1 <?php
2 /**
3  * @package UserSupport (Subpackage show related)
4  * @author SPB
5  *
6  * This script is run when the user opens up the show related card in the user hub. It cannot be run independently of that.
7  */
8 require_once("$admLibrary/userSearch.i"); // Needed for encryptUser
9 require_once("$admLibrary/aMemberSupport.i");
10 $parameters = array("a" => array("operation" => "", "payload" => "", "ft" => "", "userId" => ""));
11 $string = array("filter" => HCUFILTER_INPUT_STRING);
12 HCU_ImportVars($parameters, "a", array("operation" => $string, "payload" => $string, "ft" => $string, "userId" => $string));
13 extract($parameters["a"]);
14 
15 $operation = is_null($operation) ? "" : trim($operation);
16 $showSQL = $SYSENV["devmode"];
17 
18 try {
19  $userId = HCU_PayloadDecode($Cu, $payload);
20 } catch(exception $e) { ?>
21  <div class='noUserFound'><div>No User Found</div></div>
22 <?php exit;
23 }
24 printPage("$menu_link?ft=$ft", $userId["user_id"], getShowRelated($SYSENV, $dbh, $Cu, $userId["user_id"], $showSQL));
25 
26 /**
27  * function getShowRelated($dbh, $Cu, $userId)
28  * This function shows the related users of the particular user
29  *
30  * @param integer $dbh -- the database connection
31  * @param string $Cu -- the credit union
32  * @param integer $userId -- the user id banking side
33  * @param boolean $showSQL -- to turn off the SQL when not in DEVMODE.
34  *
35  * @return "sql" -- any sqls used, "code" -- zero if there is no errors; nonzero if there is an error found, "error" -- the last error or an empty array, "relatedData" -- the data to return
36  */
37 function getShowRelated($pEnv, $dbh, $Cu, $userId, $showSQL) {
38  $sqls = array();
39 
40  try {
41  $sql = "select a.user_id, a.user_name, a.email, a.name, g.group_name, p.profile_code, g.group_id, p.profile_id, p.description as profile_desc,
42  a.is_group_primary, a.lastlogin, a.employee from ${Cu}user u
43  left join ${Cu}group g on u.group_id = g.group_id
44  inner join ${Cu}user a on g.group_id = a.group_id
45  left join cu_profile p on g.profile_id = p.profile_id
46  where u.user_id = $userId and a.user_id is not null and u.user_id <> a.user_id order by a.user_name";
47  $sqls[] = $sql;
48 
49  $sth = db_query($sql, $dbh);
50  if (!$sth) {
51  throw new exception("Show Related query failed.", 1);
52  }
53 
54  $relatedData = array();
55  for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
56  $row["isPrimary"] = isset($row["is_group_primary"]) ? trim($row["is_group_primary"]) == "t" : false;
57  $row["subUsers"] = array();
58 
59  $row["name"] = isset($row["name"]) ? trim($row["name"]) : "";
60  $row["profile_code"] = isset($row["profile_code"]) ? trim($row["profile_code"]) : "";
61  $row["group_name"] = isset($row["group_name"]) ? trim($row["group_name"]) : "";
62  $row["email"] = isset($row["email"]) ? trim($row["email"]) : "";
63  $row["employee"] = isset($row["employee"]) ? trim($row["employee"]) : "";
64 
65  // payload for user selection in user hub
66  $encryptedUser = encryptUser($Cu, $row, false);
67  $encryptedUser = urlencode($encryptedUser);
68  $row["encryption"] = $encryptedUser;
69 
70  $relatedData[intval($row["user_id"])] = $row;
71  }
72  $returnArray = array("sql" => $sqls, "code" => 0, "error" => array(), "relatedData" => array_values($relatedData));
73  } catch(exception $e) {
74  $returnArray = array("sql" => $sqls, "code" => $e->getCode(), "error" => array($e->getMessage()));
75  }
76 
77  if (!$showSQL) {
78  unset($returnArray["sql"]);
79  }
80  return $returnArray;
81 }
82 
83 /**
84  * function printPage($self, $userId, $readData)
85  * This function will print out the popup for the audit.
86  */
87 function printPage($self, $userId, $readData) { ?>
88  <script type="text/javascript">
89  //# sourceURL=showRelated.js
90 
91  <?php
92  /**
93  * function init()
94  * This initializes stuff including but not limited to the Big Bang.
95  */
96  ?>
97  function init() {
98  $.homecuValidator.setup({formValidate:'showRelatedDiv', formStatusField: 'formValidateDiv'});
99  $("#externalTabWindow").data("preferredHeight", "auto");
100  var showRelatedData = [];
101  var columns = [
102  {headerTemplate: "&nbsp;", headerAttributes: {"class": "hierarchyCell"}, width: 45},
103  {field: "user_name", title: "User", attributes: {"class": "showEllipsis"}},
104  {field: "name", title: "Name", attributes: {"class": "hidden-xs hidden-sm showEllipsis"}, headerAttributes: {"class": "hidden-xs hidden-sm"}},
105  {field: "email", title: "Email", attributes: {"class": "showEllipsis"}},
106  {field: "lastlogin", title: "Last Sign in", attributes: {"class": "hidden-xs hidden-sm"}, headerAttributes: {"class": "hidden-xs hidden-sm"}}
107  ];
108 
109  var showRelatedGrid = $("#showRelatedGrid").kendoGrid({
110  dataSource: {
111  transport: {
112  read: function (options) {
113  options.success(showRelatedData);
114  }
115  },
116  schema: {
117  model: {
118  id: "user_id",
119  fields: {
120  user_id: {type: "number"},
121  user_name: {type: "string"},
122  name: {type: "string"},
123  email: {type: "email"},
124  lastlogin: {type: "string"},
125  isPrimary: {type: "boolean"},
126  subUsers: {type: "odata"},
127  group_name: {type: "string"},
128  profile_code: {type: "string"},
129  encryption: {type: "string"},
130  }
131  }
132  }
133  },
134  columns: columns,
135  rowTemplate: $("#rowTemplate").html(),
136  noRecords: {
137  template: "<tr><td colspan='5'><span class='hcu-secondary'><span class='vsgSecondary'>No Records Found</span></span></td></tr>"
138  },
139  height: 400,
140  dataBound: function() {
141  $("#showRelatedGrid").css({height: "initial", maxHeight: 400, overflowY: "auto", overflowX: "initial"});
142  $("#showRelatedGrid .k-grid-content").css({height: "initial"});
143  },
144  autoBind: false
145  }).data("kendoGrid");
146 
147  $("#showRelatedGrid colgroup").each(function() {
148  $(this).find("col").each(function(index) {
149  if ([2,5].indexOf(index) != -1) {
150  $(this).addClass("hidden-xs hidden-sm");
151  }
152  })
153  });
154 
155  var data = <?php echo HCU_JsonEncode($readData); ?>;
156  if (data.error.length > 0) {
157  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
158  } else {
159  showRelatedData = new kendo.data.ObservableArray(data.relatedData);
160  showRelatedGrid.dataSource.read();
161  }
162 
163  $(".showRelatedDiv").on("click", ".cancelBtn", function() {
164  postPostPostPost();
165  return false;
166  });
167 
168  <?php printExtendShowOverflown(); ?>
169 
170  var toolTipProps = homecuTooltip.defaults;
171  toolTipProps.filter = ".showEllipsis:visible:overflown";
172  toolTipProps.content = function(e) {
173  return $(e.target).text().trim();
174  };
175 
176  $("#showRelatedGrid").kendoTooltip(toolTipProps);
177  }
178 
179  <?php
180  /**
181  * function postPostPostPost()
182  * This obviously happens after everything else.
183  */
184  ?>
185  function postPostPostPost() {
186  $("#externalTabWindow").data("isClosing", true);
187  $("#externalTabWindow").data("kendoWindow").close();
188  $("#externalTabWindow").data("isClosing", false);
189  }
190 
191  init();
192  </script>
193  <script type="text/x-kendo-template" id="rowTemplate">
194  <tr data-uid="#: uid #">
195  <td># if (isPrimary) { # <i class="fa fa-asterisk"></i> # } else { # &nbsp; # } #</td>
196  <td class="showEllipsis"># if (user_name == null) { # &nbsp; # } else { # <a href="main.prg?ft=22&payload=#: encryption #">#: user_name #<i class="fa fa-user fa-fw"></i></a>
197  # } #</td>
198  <td class="hidden-xs hidden-sm showEllipsis"># if (name == null) { # &nbsp; # } else { # #: name # # } #</td>
199  <td class="showEllipsis"># if (email == null) { # &nbsp; # } else { # #: email # # } #</td>
200  <td class="hidden-xs hidden-sm showEllipsis"># if (lastlogin == null) { # &nbsp; # } else { # #: lastlogin # # } #</td>
201  </tr>
202  </script>
203  <div class="container hcu-all-100 showRelatedDiv vsgPrimary hcu-template" id="showRelatedDiv">
204  <div class="row">
205  <div id="formValidateDiv" class="k-block k-error-colored" style="display:none"></div>
206  </div>
207  <div class="hcu-secondary">
208  <div class="row small vsgSecondary">
209  Click a row to select. <i class="fa fa-asterisk"></i> means that user is primary for the group.
210  <div class="visible-xs-inline visible-sm-inline"> Rotate device to see more columns.</div>
211  </div>
212  </div>
213  <div class="row">
214  <div id="showRelatedGrid" class="overrideGridHeight"></div>
215  </div>
216  <div class="hcu-edit-buttons k-state-default row">
217  <a class="cancelBtn" href="#">Cancel</a>
218  </div>
219  </div>
220 <?php }
Definition: User.php:7