Odyssey
mUserList.prg
1 <?php
2 /**
3  * File: mUserList.prg
4  * This file will replace web stats. It contains equivalent information for Odyssey clients only.
5  */
6 
7 // ********************************************************************************************************************************************************************************
8 // Top portion: includes and extracting parameters from commandline and/or post.
9 // ********************************************************************************************************************************************************************************
10 
11 $monLibrary = dirname(__FILE__) . "/../library";
12 $sharedLibrary = dirname(__FILE__) . "../../shared/library";
13 require_once("$monLibrary/cu_top.i");
14 require_once("$monLibrary/ck_hticket.i");
15 require_once("$sharedLibrary/commonJsFunctions.i");
16 
17 if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
18  header("Location: /hcuadm/hcu_noperm.prg");
19  exit;
20 }
21 
22 $string = array("filter" => FILTER_SANITIZE_STRING);
23 $params = array("cu" => $string);
24 $vars = array("cu" => "");
25 HCU_ImportVars($vars, "", $params);
26 
27 $cu = HCU_array_key_value("cu", $vars);
28 $cu = $cu === false ? "" : trim($cu);
29 
30 // Credit Union is required so prevent the script from executing if it doesn't exist.
31 if ($cu == "") {
32  header("Location: /hcuadm/hcu_noperm.prg");
33  exit;
34 }
35 
36 // ********************************************************************************************************************************************************************************
37 // Common to .prg and .data (if there is enough lines of code, put it in an include file.)
38 // ********************************************************************************************************************************************************************************
39 
40 /**
41  * function GetMaxRowsList()
42  * This function returns the specified options of the max rows kendoDropDownList. It is used in the prg to set the kendo definition and in the data to verify that it is a correct option.
43  */
44 function GetMaxRowsList() {
45  return array("50", "100", "ALL");
46 }
47 
48 // ********************************************************************************************************************************************************************************
49 // Top of the web page
50 // ********************************************************************************************************************************************************************************
51 
52 // Imports the front end libraries: kendo, bootstrap, JQuery as well as formulates the top part of the web page.
53 printMonitorPageTop("User List", $homecuKendoVersion, $cloudfrontDomainName, $bootstrapVersion, $fontawesomeVersion, true);
54 
55 // Writes out the top header. Null means do not add anything to the options.
56 printMonitorPageMiddle("User List", null);
57 
58 // ********************************************************************************************************************************************************************************
59 // Javascript code
60 // ********************************************************************************************************************************************************************************
61 ?>
62 
63 <script type="text/javascript">
64 
65 <?php // Needed for the wait windows.
66 getShowWaitFunctions(); ?>
67 
68 <?php
69 /**
70  * function InitSearch() : javascript
71  * This function sets up all the controls from the search part of the script.
72  */ ?>
73 function InitSearch() {
74  $.homecuValidator.setup({formValidate: "searchDiv", formStatusField: "searchStatusDiv"});
75 
76  <?php
77  /**
78  * @var memberNumberMTB
79  * This creates a kendoMaskedTextBox. It only allows up to 12 characters of digits (0-9). The input rejects any other character.
80  */
81  ?>
82  var memberNumberMTB = $("[name='memberNumber']").kendoMaskedTextBox({
83  mask: "<?php echo str_repeat('0', 12); ?>"
84  }).data("kendoMaskedTextBox");
85 
86  <?php
87  /**
88  * @var maxRowsDDL
89  * This creates a kendoDropDownList. Filter, dataTextField, and dataValueField are not needed. There are only three options and it is a simple array.
90  * Data comes from a PHP function. This is necessary because it is used in both the prg and data scripts.
91  */
92  ?>
93  var maxRowsDDL = $("#maxRowsDDL").kendoDropDownList({
94  dataSource: {
95  data: <?php echo HCU_JsonEncode(GetMaxRowsList()); ?>
96  }
97  }).data("kendoDropDownList");
98 
99  <?php
100  /**
101  * Anonymous jQuery function
102  * When this link is clicked, all the text input controls are cleared. The DropDownList is set to its default: "50."
103  */
104  ?>
105  $(".clearBtn").click(function() {
106  memberNumberMTB.value(null);
107  $("[name='email']").val(null);
108  $("[name='memberNumber']").val(null);
109  maxRowsDDL.value("50");
110  });
111 
112  <?php
113  /**
114  * Anonymous jQuery function
115  * When this button is clicked, 1) the search DIV is hidden, 2) the results DIV is shown, and 3) there is a data call to get results.
116  * If there is an error in the search DIV, an error is shown and nothing else happens. Currently, that is only when the email field is not a valid email.
117  */
118  ?>
119  $(".searchBtn").click(function() {
120  if ($.homecuValidator.validate()) {
121  $("#resultsGrid").data("kendoGrid").dataSource.read();
122  $("#resultsDiv").show();
123  $("#searchDiv").hide();
124  $.homecuValidator.setup({formValidate: "resultsDiv", formStatusField: "searchResultsDiv"});
125  }
126  });
127 }
128 
129 <?php
130 /**
131  * function InitResults() : javascript
132  * This function sets up all the controls from the results part of the script.
133  */
134 ?>
135 function InitResults() {
136  <?php
137  /**
138  * @var resultsGrid
139  * This creates a kendoGrid for the resultset.
140  */
141  ?>
142  var resultsGrid = $("#resultsGrid").kendoGrid({
143  dataSource: {
144  transport: {
145  read: {
146  url: "/hcuadm/mUserList.data",
147  dataType: "json",
148  type: "POST"
149  },
150  <?php
151  /**
152  * function parameterMap : javascript
153  * This function gets all the parameters from the search DIV. These parameters will be sent down to the data script.
154  */
155  ?>
156  parameterMap: function(data, type) {
157  showWaitWindow();
158  var memberNumber = $("[name='memberNumber']").data("kendoMaskedTextBox").raw().trim();
159  var maxRows = $("#maxRowsDDL").data("kendoDropDownList").value();
160  var userName = $("[name='userName']").val().trim();
161  var email = $("[name='email']").val().trim();
162 
163  return {memberNumber: memberNumber, numRows: maxRows, userName: userName, email: email, cu: "<?php echo $cu; ?>"};
164  }
165  },
166  schema: {
167  model: {
168  id: "login",
169  fields: {
170  login: {type: "number"},
171  user: {type: "string"},
172  member: {type: "string"},
173  email: {type: "string"},
174  lastLogin: {type: "string"},
175  <?php /* Even though this is a date, I will do the formatting and everything server-side.
176  type: date will only be needed if filtering is needed. That is typical a no so keep the type as string. */ ?>
177  hasEstmnt: {type: "boolean"},
178  sort: {type: "number"}
179  }
180  },
181  <?php
182  /**
183  * function parse : javascript
184  * This function gets the data from the data script. It hides the wait window. If there are any errors, then show them. Then return the data portion to the grid.
185  */
186  ?>
187  parse: function(data) {
188  hideWaitWindow();
189 
190  if (data.error.length > 0)
191  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError);
192 
193  return data.data;
194  }
195  }
196  },
197  columns: [
198  {width: 35}, <?php // Icon (defined in rowTemplate) ?>
199  {field: "user", title: "User Name"},
200  {field: "member", title: "Member Number"},
201  {field: "email", title: "Email"},
202  {field: "hasEstmnt", title: "Estatement", width: 100}, <?php // Checkbox defined in rowTemplate ?>
203  {field: "lastLogin", title: "Last Login", sortable: {
204  <?php
205  /**
206  * compare : javascript
207  * This function is needed because kendo treats nulls as before everything else. Therefore, I check to see if it is null or not and if it is then it goes in the back of the list.
208  */
209  ?>
210  compare: function (a, b) {
211  var value = b.sort - a.sort;
212  return value == 0 ? a.lastLogin.localeCompare(b.lastLogin) : value;
213  }
214  }}
215  ],
216  rowTemplate: $("#resultsRowTemplate").html(),
217  autoBind: false, <?php // Do not want to do the read operation immediately. ?>
218  sortable: {
219  allowUnsort: false
220  },
221  noRecords: {
222  template: "<tr><td>No records available</td></tr>"
223  }
224  }).data("kendoGrid");
225 
226  <?php
227  /**
228  * Anonymous jQuery function.
229  * This function 1) clears out the search DIV, 2) hides the results DIV, and 3) shows the search DIV.
230  */
231  ?>
232  $(".backBtn").click(function() {
233  $("[name='memberNumber']").data("kendoMaskedTextBox").value(null);
234  $("[name='userName']").val(null);
235  $("[name='email']").val(null);
236  $("[name='memberNumber']").val(null);
237  $("#maxRowsDDL").data("kendoDropDownList").value("50");
238  $("#resultsDiv").hide();
239  $("#searchDiv").show();
240  $.homecuValidator.setup({formValidate: "searchDiv", formStatusField: "searchStatusDiv"});
241  });
242 
243  <?php
244  /**
245  * Anonymous jQuery function.
246  * This function opens a new tab to log in as the user.
247  */
248  ?>
249  $("#resultsGrid").on("click", "td:has(.loginBtn)", function() {
250  var tr = $(this).closest("tr");
251  var dataItem = resultsGrid.dataItem(tr);
252  var url = "/hcuadm/suCuUser.prg?cucode=" + "<?php echo $cu; ?>" + "&obMbrLogin=CLS" + "&adminuser=" + dataItem.user;
253  window.open(url, "_blank");
254  });
255 }
256 
257 <?php
258 /** Anonymous jQuery function.
259  * When the document is ready, initialize controls in both the search and result DIVs.
260  */
261 ?>
262 $(document).ready(function() {
263  InitSearch();
264  InitResults();
265 });
266 </script>
267 
268 <?php
269 // ********************************************************************************************************************************************************************************
270 // Kendo templates
271 // ********************************************************************************************************************************************************************************
272 ?>
273 
274 <?php
275 /**
276  * @var resultsRowTemplate
277  * This template is applied to every data row in the resultsGrid.
278  */
279 ?>
280 <script type="text/x-kendo-template" id="resultsRowTemplate">
281  # var estatementString = hasEstmnt ? "checked" : ""; #
282  <tr data-uid="#= uid #">
283  <td><a href="\\#" class="loginBtn"><i class="fa fa-external-link"></i></a></td>
284  <td>#: user #</td>
285  <td>#: member #</td>
286  <td>#: email #</td>
287  <td><input type="checkbox" disabled readonly #: estatementString #></td>
288  <td>#: lastLogin #</td>
289  </tr>
290 </script>
291 
292 <?php
293 // ********************************************************************************************************************************************************************************
294 // Local style
295 // ********************************************************************************************************************************************************************************
296 ?>
297 
298 <style>
299 <?php
300 /**
301  * @var local-max-width
302  * This class is so that the contents do not get too wide.
303  */
304 ?>
305 .local-max-width {
306  max-width: 1000px;
307 }
308 
309 <?php
310 /**
311  * @var local-grid-cursor
312  * This class overrides the cursor:pointer setting in hcu-no-td-border. There are no actions in the body of this grid except for clicking on the icon to log in as a user.
313  */
314 ?>
315 .local-grid-cursor tbody {
316  cursor: default;
317 }
318 
319 .local-grid-cursor tbody tr td:eq(0) {
320  cursor: pointer;
321 }
322 </style>
323 
324 <?php
325 // ********************************************************************************************************************************************************************************
326 // HTML of page
327 // ********************************************************************************************************************************************************************************
328 ?>
329 
330 <?php
331 /**
332  * @var searchDiv
333  * This DIV contains all the inputs for searching. There are two clickable links/buttons:
334  * "Clear" -- clears the text inputs and resets the kendoDropDownList.
335  * "Search" -- Makes this DIV invisible and the results DIV visible with the results grid populated.
336  */
337 ?>
338 <div class="local-max-width">
339  <div id="searchDiv" class="container-fluid hcu-template form-horizontal">
340  <div class="form-group">&nbsp;</div>
341  <div class="well well-sm">
342  <div id="searchStatusDiv"></div>
343  <div class="form-group">
344  <label class="col-xs-12 col-sm-3">Member Number</label>
345  <div class="col-xs-12 col-sm-9"><input name="memberNumber" class="hcu-all-100"></div>
346  </div>
347  <div class="form-group">
348  <label class="col-xs-12 col-sm-3">User Name</label>
349  <div class="col-xs-12 col-sm-9"><input type="text" class="k-input k-textbox hcu-all-100" name="userName" maxlength="50"></div>
350  </div>
351  <div class="form-group">
352  <label class="col-xs-12 col-sm-3">Email</label>
353  <div class="col-xs-12 col-sm-9"><input name="email" type="email" class="k-input k-textbox hcu-all-100" maxlength="255" validationMessage="Email is invalid."></div>
354  </div>
355  <div class="form-group">
356  <label class="col-xs-12 col-sm-3">Max Rows</label>
357  <div class="col-xs-12 col-sm-9"><div id="maxRowsDDL" class="hcu-all-100"></div></div>
358  </div>
359  <div class="form-group">
360  <div class="col-xs-12">
361  <div class="hcu-edit-buttons">
362  <a class="clearBtn" href="#">Clear</a>
363  &nbsp;&nbsp;&nbsp;
364  <a class="searchBtn k-button k-primary" href="#"><i class="fa fa-check"></i>Search</a>
365  </div>
366  </div>
367  </div>
368  </div>
369  </div>
370 </div>
371 
372 <?php
373 /**
374  * @var resultsDiv
375  * This DIV contains the results grid. There is one clickable link/button:
376  * "Search Again" -- this makes this DIV invisible and the search DIV visible and cleared/reset.
377  */
378 ?>
379 <div class="local-max-width">
380  <div id="resultsDiv" class="container-fluid hcu-template form-horizontal local-max-width" style="display:none;"> <?php // Needs to match the search DIV for consistency. ?>
381  <div id="searchResultsDiv"></div>
382  <div class="form-group">&nbsp;</div>
383  <div class="form-group">
384  <div class="col-xs-12">
385  <div id="resultsGrid" class="hcu-no-td-border local-grid-cursor"></div>
386  </div>
387  </div>
388  <div class="form-group">
389  <div class="col-xs-12">
390  <div class="hcu-edit-buttons">
391  <a class="backBtn k-button k-primary" href="#"><i class="fa fa-check"></i>Search Again</a>
392  </div>
393  </div>
394  </div>
395  </div>
396 </div>
397 
398 <?php
399 // ********************************************************************************************************************************************************************************
400 // Bottom of page
401 // ********************************************************************************************************************************************************************************
402 
403 // Will print out the closing tags created in the printMonitorPageTop function.
404 printMonitorPageBottom();
405 exit;
Definition: User.php:7