Odyssey
admJSCrossUseful.i
1 <?php
2 /**
3  * function PrintAuditInit($isAllAdmin = false)
4  * Prints out the initialization for audit.
5  *
6  * @param $isAllAdmin -- If it is all admin, then use a different form to validate and show the user.
7  */
8 function PrintAuditInit($isAllAdmin = false) { ?>
9  <?php if ($isAllAdmin) { ?>
10  $.homecuValidator.setup({formValidate: "searchForm", formStatusField: "formValidateDiv"});
11  <?php } else { ?>
12  $.homecuValidator.setup({formValidate:'auditPrintForm', formStatusField: 'formValidateStatusDiv'});
13  <?php } ?>
14 
15  var grid = $("#auditGrid").kendoGrid({
16  dataSource: {
17  transport: {
18  read: function(options) {
19  options.success(auditData);
20  }
21  },
22  schema: {
23  model: {
24  id: "rown",
25  fields: {
26  rown: {type: "number"},
27  date: {type: "date"},
28  action: {type: "string"},
29  actioncode: {type: "string"},
30  details: {type: "odata"},
31  user: {type: "string"},
32  <?php if ($isAllAdmin) { ?>
33  srcuser: {type: "string"},
34  <?php } ?>
35  script: {type: "string"},
36  checked: {type: "boolean"},
37  isPrinting: {type: "boolean"}
38  }
39  }
40  }
41  },
42  columns: [
43  {template: "<input type='checkbox' class='rowCheckbox'>", attributes: {"class": "checkboxTD"},
44  headerTemplate: "<input type='checkbox' class='allCheckbox'>", width: "45px", sortable: false, filterable: false},
45  {field: "date", title: "Date", format: "{0:G}"},
46  <?php if ($isAllAdmin) { ?>
47  {field: "user", title: "Audit User"},
48  {field: "srcuser", title: "Changed by"},
49  <?php } else { ?>
50  {field: "user", title: "User"},
51  <?php } ?>
52  {field: "action", title: "Action Type"},
53 
54  ],
55  noRecords: {
56  template: "<tr class='noRecordsDiv'><td colspan='4'>No Records Found</td></tr>"
57  },
58  scrollable: false,
59  sortable: true,
60  toolbar: [{name: "print", text: "Print"}<?php if ($isAllAdmin) { ?>, {name: "show", text: "Show Filter"} <?php } ?>],
61  detailTemplate: kendo.template($("#auditDetailTemplate").html()),
62  }).data("kendoGrid");
63 
64  $("#auditGrid").on("click", ".auditDetailContainer .auditShowAllBtn", function() {
65  if ($(this).text().trim() == "Show All") {
66  $(this).closest(".auditDetailContainer").removeClass("hideAA");
67  $(this).text("Show Changed");
68  } else {
69  $(this).closest(".auditDetailContainer").addClass("hideAA");
70  $(this).text("Show All");
71  }
72 
73  return false;
74  });
75 
76  <?php printCheckboxEvents("#auditGrid", ".k-grid-print"); ?>
77 
78  $(".k-grid-print").addClass("k-state-disabled");
79 
80  $(".k-grid-print").click(function() {
81  if (!$(this).hasClass("k-state-disabled")) {
82  PrintAudits();
83  }
84  return false;
85  });
86 
87  $(".k-grid-show").click(function() {
88  if ($(this).text().trim() == "Show Filter") {
89  $(".auditFilterDiv").show();
90  $(this).text("Hide Filter");
91  } else {
92  $(".auditFilterDiv").hide();
93  $(this).text("Show Filter");
94  }
95  });
96 <?php }
97 
98 function printAuditOpenPopup() { ?>
99  function auditOpenPopup(auditData) {
100  var dialog = $("#auditDetailWindow").data("kendoDialog");
101  var template = kendo.template($("#auditDetailTemplate").html());
102 
103  if (dialog == null) {
104  dialog = $("#previewWindow").kendoDialog({
105  title: "Preview",
106  actions: [{text: "Okay", primary: true}],
107  visible: false,
108  maxWidth: "99%",
109  minWidth: 333,
110  open: function() {
111  if (window.activeWindows != null) {
112  window.activeWindows.push(this);
113  }
114  },
115  close: function() {
116  if (window.activeWindows != null) {
117  window.activeWindows.pop();
118  }
119  }
120  }).data("kendoDialog");
121  }
122 
123  dialog.content(template(auditData)).open();
124 
125  var maxHeight1 = 600;
126  var maxHeight2 = $(window).height() - 150;
127  var maxHeight = maxHeight2 >= maxHeight1 ? maxHeight1 : maxHeight2;
128  $(dialog.wrapper).css({top: 5});
129  $("#previewWindow .auditMaxHeight").css({maxHeight: maxHeight, overflowY: "auto", overflowX: "hidden"});
130  }
131 <?php }
132 
133 function PrintPrintAudits($mode) {
134  /**
135  * function PrintAudits()
136  * This opens up a new tab with the audit records for the checked audit records. These will be sorted according to how the audit grid is sorted.
137  */
138  ?>
139  function PrintAudits() {
140  $("<div id='tempAudit' style='display:none;'><div class='container'><div class='row form-group mockKendoTable auditInsertion'></div></div></div>").appendTo("body");
141 
142  var gridData = $("#auditGrid").data("kendoGrid").dataSource.view();
143  var rowTemplate = kendo.template("<div class='tr nobottom'><span class='col-xs-4'>#: action #</span><span class='col-xs-4'>#: user #</span>\
144  <span class='col-xs-4'>#= kendo.toString(date, 'd') #</span></div>\
145  <div class='tr notop'><span class='col-xs-12'><div class='container-fluid'><div class=' col-xs-12'>" + $("#auditDetailTemplate").html() + "</div></div></span></div>");
146 
147  $(".auditInsertion").append("<div class='th'><span class='col-xs-4'>Action</span><span class='col-xs-4'>User</span><span class='col-xs-4'>Date</span></div>")
148 
149  for(var i = 0; i != gridData.length; i++) {
150  var record = gridData[i];
151  if (record.checked) {
152  record.isPrinting = true;
153  $(".auditInsertion").append(rowTemplate(record));
154  }
155  }
156  var newWindow = window.open("", "auditPrint");
157  $("#auditPrintForm [name='shell']").val($("#tempAudit").html());
158  <?php if ($mode == "user") { ?>
159  $("#auditPrintForm [name='title']").val("User Audit of " + $(".kWindowCard .k-window-title").text().split("/")[2].trim());
160  <?php } else if ($mode == "admin") { ?>
161  $("#auditPrintForm [name='title']").val("Admin Audit of " + $(".userHeader .realname.h2").text());
162  <? } else if ($mode == "all admin") { ?>
163  $("#auditPrintForm [name='title']").val("Admin Audit");
164  <?php } ?>
165  $("#auditPrintForm").submit();
166  $("#tempAudit").remove();
167 
168  for(var i = 0; i != gridData.length; i++) {
169  var record = gridData[i];
170  if (record.checked) {
171  record.isPrinting = false;
172  }
173  }
174  }
175 <?php }
176 
177 /**
178  * function PrintAuditTemplates()
179  * Prints audit templates.
180  */
181 function PrintAuditTemplates($isAllAdmin = false) { ?>
182  <script type="text/x-kendo-template" id="auditDetailTemplate">
183  <div class="auditMaxHeight"><div class="container-fluid auditDetailContainer hideAA">
184 
185  # for (var i = 0, iLength = details.length; i != iLength; i++) { #
186  # var tableRow = details[i]; #
187  # if (iLength > 1) { #
188  <?php printHeader("#: tableRow.label # # if (tableRow.type != 'mixed') { # (#: tableRow.type # records) # } #"); ?>
189  # } #
190  # for (var j = 0, jLength = tableRow.rows.length; j != jLength; j++) { #
191  # var rowRow = tableRow.rows[j]; var showBefore = true; var showAfter = true; #
192  # switch(rowRow.type) {
193  case "add": showBefore = false; break;
194  case "remove": showAfter = false; break;
195  }
196  var theseClasses = showBefore && showAfter ? "col-xs-4 col-md-4" : "col-xs-8 col-md-8"; #
197  # if (tableRow.type == 'mixed') { # <?php printHeader("#: rowRow.type # record:"); ?> # } #
198  <div class="row form-group mockKendoTable">
199  # if (!isPrinting && j == 0 && i == 0) { #
200  <a href='\\#' class='auditShowAllBtn'>Show All</a><br>
201  # } #
202  <div class="th">
203  <span class="col-xs-3 col-md-4">Column</span>
204  # if (showBefore) { # <span class="#: theseClasses #">Before</span> # } #
205  # if (showAfter) { # <span class="#: theseClasses #">After</span> # } #
206  <div class="clearfix hidden-xs-block"></div>
207  </div>
208 
209  # for (var k = 0, kLength = rowRow.values.length; k != kLength; k++) { #
210  # var colRow = rowRow.values[k]; var same = !isPrinting && colRow.same ? "aa" : "";#
211  <div class="tr #: same #">
212  <span class="col-xs-3 col-md-4">#: colRow.label #</span>
213  # if (showBefore) { # <span class="#: theseClasses #"># if (colRow.before == "") { # &nbsp; # } else { # #: colRow.before # # } #</span> # } #
214  # if (showAfter) { # <span class="#: theseClasses #"># if (colRow.after == "") { # &nbsp; # } else { # #: colRow.after # # } #</span> # } #
215  <div class="clearfix hidden-xs-block"></div>
216  </div>
217  # } #
218  </div>
219  # } #
220  # } #
221  </div></div>
222  </script>
223 <?php }
224 
225 function printFullTabClickEvents($username, $fullDirtyCheck=false, $onlySaveChanges=false)
226 { ?>
227  $(".fullTab").on("click", ".tabTitles [data-name]", function() {
228  if (!$(this).hasClass("selected")) <?php // If the tab is already selected, we don't care about the click. ?>
229  {
230  var tabs= window.tabs == null ? userSupportContents.tabs : window.tabs;
231  var tab= tabs[$(this).data("name")];
232  var selectedTab= tabs[$(".tabTitles .selected").data("name")];
233 
234  <?php if ($fullDirtyCheck) { ?>
235  var oldTabHash= selectedTab.oldHash;
236  var newTabHash= kendo.stringify(selectedTab.getSaveParameters(false)).hashCode();
237 
238  if (oldTabHash != newTabHash)
239  $(".tabTitles .selected").find(".tabAsterisk").show();
240  else
241  $(".tabTitles .selected").find(".tabAsterisk").hide();
242  $(".fullTab").data("oldTabHash", newTabHash);
243  <?php } ?>
244 
245  <?php if (!$fullDirtyCheck) { ?>
246  potentiallyCancelChanges(selectedTab, tab);
247  <?php } else { ?>
248 
249  $(".tabContents").hide();
250  $(".tabContents[data-name='" + tab.name + "']").show();
251  tab.setupValidator();
252  $(".fullTab .selected").removeClass("selected");
253  $(this).addClass("selected");
254  <?php } ?>
255  }
256  return false;
257  });
258 
259  $(".fullTab").on("click", ".tabSaveBtn", function() {
260  var tabs= window.tabs == null ? userSupportContents.tabs : window.tabs;
261  var tabSelector= $(".tabTitles .selected");
262  var tab= tabs[$(tabSelector).data("name")];
263 
264  <?php if (!$fullDirtyCheck) { ?>
265  saveTab(tab, "stay", null, tabSelector);
266  <?php } else { ?>
267  saveTabs(tabs);
268  <?php } ?>
269  return false;
270  });
271 
272  $(".fullTab").on("click", ".tabCancelBtn", function() {
273  var tabs= window.tabs == null ? userSupportContents.tabs : window.tabs;
274  <?php if (!$fullDirtyCheck) { ?>
275  var tabSelector= $(".tabTitles .selected");
276  var tab= tabs[$(tabSelector).data("name")];
277  potentiallyCancelChanges(tab);
278  <?php } else { ?>
279  potentiallyCancelChanges(tabs);
280  <?php } ?>
281  return false;
282  });
283 <?php }
284 
285 function printTabFunctions($self, $username, $authval, $fullDirtyCheck=false)
286 {
287  /**
288  * function saveTab(tab)
289  * Saves the tab. Now there is only one way to save. This validates the form and calls the data function to save the user and finally does some post-save operations (if relevant).
290  *
291  * @param {} tab -- the tab to save.
292  */
293  if (!$fullDirtyCheck) { ?>
294  function saveTab(tab, onlySaveChanges)
295  {
296  var oldHash= kendo.stringify(previousParameters).hashCode();
297  var newHash= kendo.stringify(tab.getSaveParameters(false)).hashCode();
298  if (newHash == oldHash)
299  {
300  postSaveTab(tab, true);
301  return;
302  }
303 
304  if ($.homecuValidator.validate())
305  {
306  var parameters= tab.getSaveParameters(true);
307  parameters.authval= "<?php echo $authval; ?>";
308  <?php if ($username == "") { ?>
309  parameters.isAdd= "Y";
310  <?php } else { ?>
311  parameters.username= "<?php echo $username; ?>";
312  <?php } ?>
313  parameters.tab= tab.name;
314  showWaitWindow();
315  $.post("<?php echo $self; ?>&operation=saveUser", parameters, function(data) {
316  hideWaitWindow();
317  if (data.error.length > 0)
318  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
319  else if (data.serverIPFoundRelevant && data.serverIPFound === false)
320  window.location.href= "<?php echo $self; ?>";
321  else
322  postSaveTab(tab);
323  });
324  }
325  }
326 
327  <?php } else {
328  /**
329  * function saveTabs(tabs)
330  * This saves all the tabs at once. I swear by the old hashes and the new.
331  *
332  * @param {} tabs -- the tabs to save.
333  */ ?>
334  function saveTabs(tabs)
335  {
336  var valid= true;
337  var parameters= {};
338 
339  if (!$.homecuValidator.validate())
340  valid= false;
341  else
342  {
343  var changed= false;
344  try
345  {
346  for (var tabname in tabs)
347  {
348  if (tabname == "oldHash")
349  continue;
350 
351  var tab= tabs[tabname];
352 
353  tab.setupValidator();
354  if (!$.homecuValidator.validate())
355  throw new exception("Invalid!");
356  }
357 
358  for (var tabname in tabs)
359  {
360  if (tabname == "oldHash")
361  continue;
362 
363  var tab= tabs[tabname];
364  var tabParameters= tab.getSaveParameters(true);
365  changed= changed || tab.oldHash != kendo.stringify(tabParameters).hashCode();
366 
367  <?php // Build parameters according to what is changed in the tabs. ?>
368  for(var parameter in tabParameters)
369  {
370  if (tabParameters.hasOwnProperty(parameter))
371  parameters[parameter]= tabParameters[parameter];
372  }
373 
374  }
375 
376  if (!changed)
377  {
378  if (typeof(postSaveTabs) == "function")
379  postSaveTabs(tabs, []);
380  return;
381  }
382  }
383  catch(e)
384  {
385  valid= false;
386  }
387  }
388 
389  if (valid && changed)
390  {
391  parameters.authval= "<?php echo $authval; ?>";
392  <?php if ($username == "") { ?>
393  parameters.isAdd= "Y";
394  <?php } else { ?>
395  parameters.username= "<?php echo $username; ?>";
396  <?php } ?>
397  parameters.tab= tab.name;
398  showWaitWindow();
399  $.post("<?php echo $self; ?>&operation=saveUser", parameters, function(data) {
400  hideWaitWindow();
401  if (data.error.length > 0)
402  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
403  else
404  {
405  if (typeof(postSaveTabs) == "function")
406  postSaveTabs(tabs, data);
407  }
408 
409  });
410  }
411 
412  }
413  <?php }
414  /**
415  * function postSaveTab(tab, noNotificationPlease)
416  * What happens after a successful save: if a new user, then redirect to the summary tab of the newly created user. Otherwise, do any custom tab-specific things and notify.
417  *
418  * @param {} tab -- the tab to save
419  * @param boolean noNotificationPlease -- if yes, then don't show it in the most Canadian way possible.
420  */
421  ?>
422  function postSaveTab(tab, noNotificationPlease)
423  {
424  $("#formValidateDiv").hide();
425  tab.postChanges();
426  if (!noNotificationPlease)
427  {
428  previousParameters= tab.getSaveParameters(false, true); <?php // If they save and then go to the next tab, it doesn't make sense to ask to save again. ?>
429  showSuccessMessage("User was saved successfully!");
430  }
431  }
432 
433  function loadTabInnards(tab, data)
434  {
435  var tabTemplate= kendo.template($("#tabTemplate").html());
436  var template= kendo.template(tab.template);
437  var record= data.record[0];
438  record.usernamesUsed= data.usernamesUsed;
439  record.tabname= tab.name;
440 
441  <?php if (!$fullDirtyCheck) { ?>
442  $(".fullTab").html(tabTemplate(record));
443  $(".tabContents").html(template(record));
444  <?php } else { ?>
445  $(".fullTab").html(tabTemplate(record));
446  $(".tabContents").hide();
447  $(".tabContents[data-name='" + record.tabname + "']").html(template(record));
448  $(".tabContents[data-name='" + record.tabname + "']").show();
449  <?php } ?>
450  tab.init(record);
451 
452  previousParameters= tab.getSaveParameters(false, true);
453  }
454 
455  <?php
456  /**
457  * function loadTab(tab)
458  * This loads the tab
459  *
460  * @param {} tab -- the tab to be loaded
461  */
462 
463  if (!$fullDirtyCheck) {
464  ?>
465  function loadTab(tab)
466  {
467  showWaitWindow();
468  $.post("<?php echo $self; ?>&operation=readUser", {username: "<?php echo $username; ?>", authval: "<?php echo $authval; ?>", tab: tab.name}, function(data) {
469  hideWaitWindow();
470  if (data.error.length > 0)
471  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
472  else
473  {
474  loadTabInnards(tab, data);
475  }
476  });
477  }
478 
479  <?php } else { ?>
480  function loadTab(tab)
481  {
482  if (loadTab.data == null)
483  {
484  showWaitWindow();
485  $.post("<?php echo $self; ?>&operation=readUser", {username: "<?php echo $username; ?>"}, function(data) {
486  hideWaitWindow();
487  if (data.error.length > 0)
488  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
489  else
490  {
491  loadTab.data= data;
492  loadTabInnards(tab, loadTab.data);
493  }
494  });
495  }
496  else
497  loadTabInnards(tab, loadTab.data);
498  }
499  <?php }
500  /**
501  * function potentiallyCancelChanges(tab, nextTab)
502  * The function to cancel changes if the conditions are met.
503  *
504  * @param {} tab -- the tab to potentially cancel changes made to.
505  * @param {} nextTab -- the next tab to potentially move towards if there are no changes to cancel. If null, then this will potentially go to the user main screen.
506  */
507  if (!$fullDirtyCheck) { ?>
508  function potentiallyCancelChanges(tab, nextTab)
509  {
510  var oldHash= kendo.stringify(previousParameters).hashCode();
511  var newHash= kendo.stringify(tab.getSaveParameters(false, true)).hashCode();
512  if (newHash == oldHash)
513  {
514  if (typeof(tabCancelLogic) == "function")
515  tabCancelLogic(tab, nextTab);
516  else
517  {
518  if (nextTab == null) // Cancel on the bottom
519  $("#redirectForm").submit();
520  else
521  {
522  tab.destroy();
523  loadTab(nextTab);
524  }
525  }
526  return;
527  }
528 
529  var discardChangesDialog= $("#discardChangesDialog").data("kendoDialog");
530  if (discardChangesDialog == null)
531  {
532  discardChangesDialog= $("<div id='discardChangesDialog'></div>").appendTo("body").kendoDialog({
533  title: "Discard Changes",
534  content: "<p>Your changes have not been saved.</p><p>Do you wish to discard your changes?</p>",
535  actions: [
536  {text: "No"},
537  {text: "Yes", primary: true, action: function() {
538  var nextTab= $("#discardChangesDialog").data("nextTab");
539  var tab= $("#discardChangesDialog").data("tab");
540  if (typeof(tabCancelLogic) == "function")
541  tabCancelLogic(tab, nextTab);
542  else
543  {
544  if (nextTab == null) // Cancel on the bottom
545  $("#redirectForm").submit();
546  else
547  {
548  tab.destroy();
549  loadTab(nextTab);
550  }
551  }
552  }}
553  ],
554  visible: false,
555  open: function() {
556  if (window.activeWindows != null)
557  window.activeWindows.push(this);
558  },
559  close: function() {
560  if (window.activeWindows != null)
561  window.activeWindows.pop();
562  }
563  }).data("kendoDialog");
564  }
565 
566  $("#discardChangesDialog").data("tab", tab);
567 
568  if (nextTab == null)
569  $("#discardChangesDialog").data("nextTab", null);
570  else
571  $("#discardChangesDialog").data("nextTab", nextTab);
572  discardChangesDialog.open();
573  }
574 <?php } else { ?>
575 function potentiallyCancelChanges(tabs)
576 {
577  var oldHash= tabs.oldHash;
578  var newHash= [];
579  var parameters= {};
580  var tempParameters= [];
581 
582  for (var tabname in tabs)
583  {
584  if (tabs.hasOwnProperty(tabname) && tabname != "oldHash")
585  {
586  var tab= tabs[tabname];
587  newHash.push(tab.getSaveParameters(false));
588  tempParameters.push(tab.getSaveParameters(true));
589  }
590  }
591 
592  newHash= kendo.stringify(newHash).hashCode();
593  if (newHash == oldHash)
594  {
595  if (typeof(tabsCancelLogic) == "function")
596  tabsCancelLogic(tabs);
597  return;
598  }
599 
600  var discardChangesDialog= $("#discardChangesDialog").data("kendoDialog");
601  if (discardChangesDialog == null)
602  {
603  discardChangesDialog= $("<div id='discardChangesDialog'></div>").appendTo("body").kendoDialog({
604  title: "Discard Changes",
605  content: "<p>Your changes have not been saved.</p><p>Do you wish to discard your changes?</p>",
606  actions: [
607  {text: "No"},
608  {text: "Yes", primary: true, action: function() {
609  var tabs= $("#discardChangesDialog").data("tabs");
610  if (typeof(tabsCancelLogic) == "function")
611  tabsCancelLogic(tabs);
612  }}
613  ],
614  visible: false,
615  open: function() {
616  if (window.activeWindows != null)
617  window.activeWindows.push(this);
618  },
619  close: function() {
620  if (window.activeWindows != null)
621  window.activeWindows.pop();
622  }
623  }).data("kendoDialog");
624  }
625 
626  $("#discardChangesDialog").data("tabs", tabs);
627  discardChangesDialog.open();
628 }
629 <?php }
630 }
631 
632 /**
633  * function loginPrintPublicNote()
634  * Prints the public note for login
635  */
636 function loginPrintPublicNote()
637 { ?>
638  $("#publicNote").click(function(e) {
639  var position= $(this).offset();
640  var notification= $("<div></div>").appendTo("body").kendoNotification({
641  autoHideAfter: 0,
642  width: "400px",
643  position: {
644  top: position.top,
645  left: position.left
646  }
647  }).data("kendoNotification");
648 
649  notification.info('Public computers are found at libraries, schools, Internet cafes, airports, and many other places. <br>You have no control over who uses public computers. \
650  <br>Public computers may be running malicious software like keystroke loggers or be on networks that allow others to get your personal information. \
651  <br><br>We strongly suggest you do <i>NOT</i> use a public computer for digital banking. <br>If you decide to use one anyway, you should check the box so we do not save a security \
652  token to this public computer.');
653  return false;
654  });
655 <?php }
656 
657 /**
658  * function loginPrintSaveToken()
659  * Prints the save token for login
660  */
661 function loginPrintSaveToken()
662 { ?>
663  <div class="well well-sm ">
664  <div class="form-horizontal form-widgets">
665  <div class="form-group">
666  <div class="col-xs-12">
667  <label style="cursor: pointer"><input type="radio" name="chksecure" value="Y" checked>
668  This is my Personal or Business Computer<br>&nbsp;(Save security token on this computer)</label>
669  <br><br>
670  <label style="cursor: pointer">
671  <input type="radio" name="chksecure" value="N">
672  This is a <a href="#" id="publicNote">Public Computer</a><br>&nbsp;(DO NOT Save security token on this computer)</label>
673  </div>
674  </div>
675  </div>
676  </div>
677 <?php }
678 
679 
680 /**
681  * function printValidatePassword()
682  *
683  * This is a javascript function that prints out the validation needed to ensure that the passwords are correct. There needs to be no invalid characters as well as conforming to the password rules.
684  * The password rules are passed from the passconfig column in the cuadmin table.
685  */
686 function printValidatePassword($requirePassword= false)
687 { ?>
688  vp1: function(input) {
689  if (!input.is("[name='oldPassword']"))
690  return true;
691 
692  var password= $(input).val().trim();
693  if (password == "" <?php if (!$requirePassword) { ?> && $("[name='password']").val().trim() != "" <?php } // Need the old password if the password is filled in or required.?>) {
694  $(input).attr("data-vp1-msg", "Old password is required.");
695  return false;
696  }
697  return true;
698  },
699  vp2: function(input) {
700  if (!input.is("[name='showHelp']"))
701  return true;
702  if (!$(input).prop("checked") <?php if (!$requirePassword) { ?> && $("[name='password']").val().trim() != "" <?php } // Need to READ if the password is filled in or required.?>) {
703  $(input).attr("data-vp2-msg", "Please review the recommended password guidelines before saving your new password.");
704  return false;
705  }
706  return true;
707  },
708  validatepassword: function(input) {
709  if (!input.is("[name='password']"))
710  return true;
711 
712  var password= $(input).val().trim();
713 
714  var valid= true;
715  var msg= "";
716 
717  var invalidMatches= password.match(/['"]/g);
718  if (invalidMatches != null && invalidMatches.length > 0) {
719  msg= msg == "" ? "Password has illegal characters." : msg;
720  valid= false;
721  }
722 
723  var rules= $.homecuValidator.passwordRules;
724 
725  if (rules == null || rules.use == null || rules.use != 1)
726  rules= {len: 6, letter: 1, digit: 1};
727 
728  if (rules.len != null && password.length < rules.len) {
729  msg= msg == "" ? "Password requires at least " + rules.len + (rules.len == 1 ? " character." : " characters.") : msg;
730  $(".passreq.len").css("color", "red");
731  $(".passreq.len .fa").addClass("fa-times").removeClass("fa-check");
732  valid= false;
733  } else {
734  $(".passreq.len").css("color", "green");
735  $(".passreq.len .fa").removeClass("fa-times").addClass("fa-check");
736  }
737 
738  var specMatches= password.match(/[!#@$%^&*?_~()-]/g);
739  var lowerMatches= password.match(/[a-z]/g);
740  var upperMatches= password.match(/[A-Z]/g);
741  var digitMatches= password.match(/[0-9]/g);
742 
743  if (rules.spec != null && rules.spec > 0 && (specMatches == null || specMatches.length < rules.spec)) {
744  msg= msg == "" ? "Password requires at least " + rules.spec + " special character" + (rules.spec == 1 ? "." : "s."): msg;
745  $(".passreq.spec").css("color", "red");
746  $(".passreq.spec .fa").addClass("fa-times").removeClass("fa-check");
747  valid= false;
748  } else {
749  $(".passreq.spec").css("color", "green");
750  $(".passreq.spec .fa").removeClass("fa-times").addClass("fa-check");
751  }
752 
753  if (rules.lower != null && rules.lower > 0 && (lowerMatches == null || lowerMatches.length < rules.lower)) {
754  msg= msg == "" ? "Password requires at least " + rules.lower + " lower character" + (rules.lower == 1 ? "." : "s."): msg;
755  $(".passreq.lower").css("color", "red");
756  $(".passreq.lower .fa").addClass("fa-times").removeClass("fa-check");
757  valid= false;
758  } else {
759  $(".passreq.lower").css("color", "green");
760  $(".passreq.lower .fa").removeClass("fa-times").addClass("fa-check");
761  }
762 
763  if (rules.upper != null && rules.upper > 0 && (upperMatches == null || upperMatches.length < rules.upper)) {
764  msg= msg == "" ? "Password requires at least " + rules.upper + " upper character" + (rules.upper == 1 ? "." : "s."): msg;
765  $(".passreq.upper").css("color", "red");
766  $(".passreq.upper .fa").addClass("fa-times").removeClass("fa-check");
767  valid= false;
768  } else {
769  $(".passreq.upper").css("color", "green");
770  $(".passreq.upper .fa").removeClass("fa-times").addClass("fa-check");
771  }
772 
773  if (rules.digit != null && rules.digit > 0 && (digitMatches == null || digitMatches.length < rules.digit)) {
774  msg= msg == "" ? "Password requires at least " + rules.digit + " digit character" + (rules.digit == 1 ? "." : "s."): msg;
775  $(".passreq.digit").css("color", "red");
776  $(".passreq.digit .fa").addClass("fa-times").removeClass("fa-check");
777  valid= false;
778  } else {
779  $(".passreq.digit").css("color", "green");
780  $(".passreq.digit .fa").removeClass("fa-times").addClass("fa-check");
781  }
782 
783  <?php if ($requirePassword) { ?>
784  if (password == "") {
785  $("[name='confirm']").removeClass("k-invalid").addClass("k-valid");
786  msg= "Password is required.";
787  valid= false;
788  }
789  <?php } else { ?>
790  if (password == "")
791  valid= true;
792  <?php } ?>
793 
794  if (!valid) {
795  $(input).attr("data-validatepassword-msg", msg);
796  return false;
797  }
798  return true; <?php // Got through the validation ?>
799  }
800 <?php }
801 
802 function printPasswordRequirementTemplate (){ ?>
803  <script type="text/x-kendo-template" id="passwordRequirementTemplate">
804  # if (pwdRequirements.length > 0) { #
805  <div class="well well-sm row">
806  <div class="col-xs-12">
807  <label for="passRequirements">Minimum Password Requirements:</label>
808  </div>
809  <div class="col-xs-12">
810  <div id="passRequirements" style="width: 200px;">
811  # for(var i=0, length= pwdRequirements.length; i!= length; i++) {
812  var rec= pwdRequirements[i]; #
813  <span class='passreq #= rec.which #' style='color: red;'>
814  <span class='fa fa-times'></span>
815  <span>#= rec.text #</span>
816  </span><br />
817  # } #
818  </div>
819  </div>
820  </div>
821  # } #
822  </script>
823 <?php }
824 
825 
826 /**
827  * function printMatchPasswords()
828  *
829  * This prints out the validation that the password and the confirm password fields match.
830  */
831 function printMatchPasswords()
832 { ?>
833  matchpasswords: function(input)
834  {
835  if (!input.is("[name='confirm']"))
836  return true;
837  if ($(input).val() != $("[name='password']").val())
838  {
839  $(input).attr("data-matchpasswords-msg", "Password must match confirmation.");
840  return false;
841  }
842  return true;
843  }
844 <?php }
845 
846 /**
847  * function printTabPlugin()
848  * Pulled from aMemberSettings.prg and aGroupInfo.prg. Put here because this needs to be updated to align with User Hub tab headers.
849  *
850  * @uses This is a custom jQuery plugin that displays tabbed data. Using an html
851  * element, the user may define a list of tabs with names, icons, content and validators
852  * that will work for each tab.
853  *
854  * @param element DOM : element container for the hcuTabs object
855  * @param options JSON : object containing user ddefined attributes. These attributes
856  * consist of tab definitions including name, display text, icons, content and
857  * validation functions. Custom override functions may be defined as well for select
858  * and validate operations.
859  *
860  * @return hcuTabs object
861  */
862 function printTabPlugin()
863 { ?>
864 <script type="text/x-kendo-template" id="tabHeaderTemplate">
865  # var tabAsterisk= "<div class='tabAsterisk' style='display:none;'><i class='fa fa-asterisk fa-6'></i></div>"; var selectedClass= selected ? "selected" : "";
866  var lastChildClass= lastChild ? "lastChild" : ""; #
867  <div class="#: spacing # #: selectedClass # #: lastChildClass #" data-name="#: title #" data-tab-index="#: index #"><div># if (icon != "") { #<i class="fa #: icon # fa-6"># } #
868  # if (text != "") { #<div class="hidden-xs hidden-sm text">&nbsp;#: text #</div># } # #= tabAsterisk #</i></div>
869 </div>
870 </script>
871 <script type="text/javascript">
872 (function($) {
873 
874  // plugin: content/definition
875  // element: DOM selector for tabs container
876  // options: user defined settings for tabs
877  $.hcuTabs = function(element, options) {
878  var defaults = {
879  tabs: [],
880  select: function() {},
881  validate: function() { return true; }, <?php // This actually doesn't validate, it really just returns if the tab is dirty or not. ?>
882  formValidate: function(tabId) { return true; }, <?php // This actually validates the form to see if there there are errors or not. ?>
883  useDiscardChangesDialog: false,
884  discardChangesTitle: "Discard Changes",
885  discardChangesText: "<p>Do you wish to discard your changes?</p>",
886  discardChangesOkay: function() { return true; },
887  discardChangesWindowStack: []
888  };
889 
890  // plugin: javascript tabs object
891  var plugin = this;
892  plugin.settings = {};
893 
894  // init: 1) Initialize defaults with user defined settings. 2) retrieve content based on element having data-tab attributes. 3) pair the data-tab content with the tabs[i] name.
895  $(element).html("<div class=\"hcu-template\"></div>");
896  var pluginContainer = $(element).find(".hcu-template");
897  var pluginHeader = $("<div class=\"tabTitles\"></div>");
898  var pluginContent = $("<div id=\"tabContent\"></div>");
899  var pluginFooter = $("<div id=\"tabFooter\"></div>");
900 
901  // init: plugin implementation and setup
902  // setup tabs, content, click events
903  plugin.init = function() {
904  plugin.settings = $.extend({}, defaults, options);
905 
906  // append plugin header/content. These are used to alter appearances by using jquery .find() to get the elements needed.
907  pluginContainer.append(pluginHeader);
908  pluginContainer.append(pluginContent);
909  pluginContainer.append(pluginFooter);
910 
911  // define number of tabs per row (max is 4)
912  // number of tabs: 1 = col-12, 2 = col-6, 3 = col-4, 4 = col-3
913  // if user defines more than 4, the default setting is col-3 for
914  // four tabs per row.
915  var pluginTabsLength = plugin.settings.tabs.length;
916  var pluginTabsColumns = 0;
917 
918  switch (pluginTabsLength) {
919  case 1:
920  pluginTabsColumns = 3;
921  break;
922  case 2:
923  pluginTabsColumns = 3;
924  break;
925  case 3:
926  pluginTabsColumns = 3;
927  break;
928  case 4:
929  pluginTabsColumns = 3;
930  break;
931  default:
932  pluginTabsColumns = 3;
933  break;
934  }
935 
936  var headerTemplate = kendo.template($("#tabHeaderTemplate").html());
937 
938  for (var i = 0; i < pluginTabsLength; i++) {
939  var tab = plugin.settings.tabs[i];
940 
941  // define all element of tab DOM
942  var tabContent = null;
943 
944  // build and append tab content if defined
945  if (tab.content) {
946 
947  // if content is string id and not jquery object
948  // get jquery object and store it in place of the string
949  // in the definition.
950  if (typeof tab.content == "string") {
951 
952  // replace any #'s if necessary to ensure correct jquery selector
953  tabContent = $("#" + tab.content);
954  plugin.settings.tabs[i].content = tabContent;
955  } else {
956  tabContent = tab.content;
957  }
958 
959  // check if content is null
960  if (tabContent) {
961  // add data-attrubutes to content for easy access
962  // when selecting and validating
963  tabContent.attr("data-name", tab.title);
964  tabContent.attr("data-tab-index", i);
965 
966  // display content based on selected definitions
967  if (tab.selected) {
968  tabContent.show();
969  } else {
970  tabContent.hide();
971  }
972  } else {
973  tabContent = "";
974  }
975  }
976 
977  // append header and content
978  tab.index = i;
979  tab.lastChild = i == pluginTabsLength - 1;
980  tab.spacing = "col-xs-" + pluginTabsColumns;
981  tab.icon = tab.icon == null ? "" : tab.icon.trim(); // previous code checks if it is defined. KendoTemplate doesn't like nulls.
982  tab.text = tab.text == null ? "" : tab.text.trim();
983  tab.selected = tab.selected == null ? false : tab.selected;
984  pluginHeader.append(headerTemplate(tab));
985  pluginContent.append(tabContent);
986  }
987 
988  if (plugin.settings.useDiscardChangesDialog) {
989  pluginHeader.on("click", "[data-name]", function() {
990 
991  <?php // Find active tab. ?>
992  var activeTab = null;
993  for (var i = 0; i < plugin.settings.tabs.length; i++) {
994  var tab = plugin.settings.tabs[i];
995  if (tab.selected) {
996  activeTab = tab;
997  break;
998  }
999  }
1000 
1001  // remove validation flags from tabs
1002  var tabWarn = $(".tabTitles [data-tab-index=" + activeTab.index + "] .tabAsterisk");
1003 
1004  var dontAdvance = false;
1005 
1006  // call tab validation function
1007  // set warning tag if failure
1008  // must check if the tab has defined a validate function
1009  if (activeTab.validate) {
1010  if (activeTab.validate()) { <?php // This is not actually validating it; rather it is returning if the tab is dirty or not. ?>
1011  tabWarn.hide();
1012  } else {
1013  tabWarn.show();
1014 
1015  if (plugin.settings.formValidate()) { <?php // This is actually validating the tab. ?>
1016  plugin.openDiscardChangesDialog(activeTab, $(this).attr("data-tab-index"), tabWarn); <?php // Pass back something to identify the tab to the other script. ?>
1017  }
1018 
1019  dontAdvance = true; <?php // At this point, either there is an error or there is the discard changes dialog. ?>
1020  }
1021  }
1022 
1023  if (!dontAdvance) {
1024  plugin.select($(this).attr("data-tab-index"));
1025  }
1026 
1027  });
1028 
1029 
1030 
1031  } else {
1032  pluginHeader.on("click", "[data-name]", function() {
1033  plugin.select($(this).attr("data-tab-index"));
1034  });
1035  }
1036 
1037 
1038  // Append footer if exists. If a string, assume the string is the id, otherwise it is a DOM.
1039  var footer = plugin.settings.footer;
1040  if (footer != null) {
1041  pluginFooter.append(typeof footer == "string" ? $("#" + footer) : footer);
1042  }
1043  }
1044 
1045  // select: select tab by index
1046  // index found by data-tab-index attributes
1047  // previous content will be validated if there
1048  // is a validation function defined.
1049  plugin.select = function(e) {
1050 
1051  // get currently selected tab
1052  // get tab index of currently selected tab
1053  // get content of currently selected tab
1054  var tabCurrent = pluginHeader.find(".selected");
1055  var tabCurrentIndex = tabCurrent.attr("data-tab-index");
1056  var tabCurrentContent = pluginContent.find("div[data-tab-index=" + tabCurrentIndex + "]");
1057 
1058  // get clicked tab
1059  // get tab index of clicked tab
1060  // get tab content of clicked tab
1061  var tabSelectedIndex = e;
1062  var tabSelected = pluginHeader.find("div[data-tab-index=" + tabSelectedIndex + "]");
1063  var tabSelectedContent = pluginContent.find("div[data-tab-index=" + tabSelectedIndex + "]");
1064 
1065  // remove selected class from currently selected
1066  // tab and hide its content
1067  tabCurrent.removeClass("selected");
1068  tabCurrentContent.hide();
1069 
1070  // add selected class to clicked tab
1071  // and show its contents
1072  tabSelected.addClass("selected");
1073  tabSelectedContent.show();
1074 
1075  <?php // This attribute needs to be updated. Otherwise, it is useless and unreliable. ?>
1076  plugin.settings.tabs[tabCurrent.index()].selected = false;
1077  plugin.settings.tabs[tabSelected.index()].selected = true;
1078 
1079  // if a select function have been defined by
1080  // the user, call it.
1081  plugin.settings.select();
1082  }
1083 
1084  // validate: validate all tabs in the tabs plugin
1085  // if a tab does not have a validate function
1086  // it will not be validated.
1087  plugin.validate = function() {
1088  var tabValid = true;
1089 
1090  for (var i = 0; i < plugin.settings.tabs.length; i++) {
1091 
1092  // remove validation flags from tabs
1093  var tabWarn = $(".tabTitles [data-tab-index=" + i + "] .tabAsterisk");
1094 
1095  // call tab validation function
1096  // set warning tag if failure
1097  // must check if the tab has defined a validate function
1098  if (plugin.settings.tabs[i].validate) {
1099  var tabValidate = plugin.settings.tabs[i].validate;
1100  if (tabValidate()) {
1101  tabWarn.hide();
1102  } else {
1103  tabValid = false;
1104  tabWarn.show();
1105  }
1106  }
1107 
1108  }
1109 
1110  // if a validate function has been defined
1111  // call the user defined validate function
1112  tabValid = (tabValid && plugin.settings.validate());
1113 
1114  return tabValid;
1115  }
1116 
1117  <?php
1118  /**
1119  * function plugin.openDiscardChangesDialog
1120  * This function creates and opens the discard changes dialog when it is called in the plugin.
1121  * To be called, 1) the plugin must have the "useDiscardChangesDialog" set to true, 2) the user clicks on another tab, 3) there are changes on the current tab.
1122  */
1123  ?>
1124  plugin.openDiscardChangesDialog = function (tab, newIndex, tabWarn) {
1125  var discardChangesDialog = $("#discardChangesDialog").data("kendoDialog");
1126  var title = tab.discardChangesTitle !== undefined ? tab.discardChangesTitle : plugin.settings.discardChangesTitle;
1127  var content = tab.discardChangesText !== undefined ? tab.discardChangesText : plugin.settings.discardChangesText;
1128  var discardChangesOkay = tab.discardChangesOkay !== undefined ? tab.discardChangesOkay : plugin.settings.discardChangesOkay;
1129  if (discardChangesDialog != null) {
1130  discardChangesDialog.destroy();
1131  $("#discardChangesDialog").remove();
1132  }
1133 
1134  discardChangesDialog = $("<div id='discardChangesDialog'></div>").appendTo("body").kendoDialog({
1135  title: title,
1136  content: content,
1137  actions: [
1138  {text: "No"},
1139  {text: "Yes", primary: true, action: function() {
1140  (discardChangesOkay)();
1141  tabWarn.hide();
1142  plugin.select(newIndex); <?php // Advance to the next tab as if there was no discard changes option. ?>
1143  }}
1144  ],
1145  visible: true,
1146  open: function() {
1147  if (plugin.settings.discardChangesWindowStack != null) {
1148  plugin.settings.discardChangesWindowStack.push(this);
1149  }
1150  },
1151  close: function() {
1152  if (plugin.settings.discardChangesWindowStack != null) {
1153  plugin.settings.discardChangesWindowStack.pop();
1154  }
1155  }
1156  }).data("kendoDialog");
1157  }
1158 
1159  // initialize plugin
1160  plugin.init();
1161  }
1162 
1163  // construct new hcuTabs object for DOM element
1164  // if none have been made yet
1165  $.fn.hcuTabs = function(options) {
1166 
1167  var plugin = null;
1168 
1169  if (undefined == $(this).data("hcuTabs")) {
1170  plugin = new $.hcuTabs(this, options);
1171  $(this).data("hcuTabs", plugin);
1172  } else {
1173  plugin = this;
1174  }
1175 
1176  return plugin;
1177  }
1178 
1179 }(jQuery));
1180 </script>
1181 <?php }
1182 
1183 
1184 function printCheckip()
1185 { ?>
1186  checkip: function(input)
1187  {
1188  if(input.is("[name='addCuIpInput']"))
1189  {
1190  var value= $(input).val().trim();
1191  if (value == null || value == "")
1192  return true;
1193  if (!value.match(/^([0-9]{1,3}\.){3}[0-9]{1,3}$/))
1194  {
1195  $(input).attr("data-checkip-msg", "IP is not valid.");
1196  return false;
1197  }
1198 
1199  values= value.split(".");
1200  for(var i=0; i!= values.length; i++)
1201  {
1202  var num= Number(values[i]);
1203  if (num > 255 || num < 0 || (num+"").trim() != values[i].trim())
1204  {
1205  $(input).attr("data-checkip-msg", "IP is not valid.");
1206  return false;
1207  }
1208  }
1209 
1210  var data= $(".ipGrid").data("kendoGrid").dataSource.data();
1211  if ($.grep(data, function(n,i) { return n.ip == value; }).length != 0)
1212  {
1213  $(input).attr("data-checkip-msg", "IP already exists.");
1214  return false;
1215  }
1216  }
1217  return true;
1218  }
1219 <?php }