Odyssey
MbrExHcuEZCARD.i
1 <?php
2 
3 $HcuEZCARDi = new class()
4 {
5  public function parms_parse($payload) {
6  /*
7  * parms_parse - explode parms into component values
8  * called after reading record from database
9  */
10 
11  list($card4, $cardsig, $cardtype) = explode(',', $payload);
12  return array('card4' => $card4, 'cardsig' => $cardsig, 'cardtype' => $cardtype);
13  }
14 
15  public function parms_validate($parms) {
16  $dms_ok = array('card4' => 'string', 'cardsig' => 'string',
17  'cardtype' => 'string',);
18  dms_import_v2($parms, "HCUPOST", $dms_ok);
19  /*
20  * parms_validate - check entries before attemtping db update
21  * includes readying for db write
22  * called after form post, so import the needed form values
23  */
24  if (empty($parms['HCUPOST']['card4'])) {
25  $errors[] = 'Card Last 4 Required';
26  } else {
27  if (preg_match("/\D/", $parms['HCUPOST']['card4']) || strlen($parms['HCUPOST']['card4']) <> 4) {
28  $errors[] = "Card Last 4 must be 4 digits";
29  }
30  }
31  if (empty($parms['HCUPOST']['cardsig'])) {
32  $errors[] = 'Card Signature Required';
33  } else {
34  if (strlen($parms['HCUPOST']['cardsig']) <> 44) {
35  $errors[] = "Card Signature must be 44 characters";
36  }
37  /*
38  * calculating card signature includes replacing [+/=] with [-_.]
39  * so if [+/=] occurs, it is an error
40  * Next, put them back and decode to test for other non-base64 characters
41  */
42  if (preg_match("/[+\/=]/", $parms['HCUPOST']['cardsig'])) {
43  $errors[] = "Card Signature contains invalid characters";
44  }
45  $patterns = array("/-/", "/_/", "/\./");
46  $repl = array("+", "/", "=");
47  $b64str = preg_replace($patterns, $repl, $parms['HCUPOST']['cardsig']);
48  if (!base64_decode($b64str)) {
49  $errors[] = "Card Signature contains invalid characters";
50  }
51  }
52  if (empty($parms['HCUPOST']['cardtype'])) {
53  # default value
54  $parms['HCUPOST']['cardtype'] = 'P';
55  }
56  if (preg_match("/[^PC123456789]/", $parms['HCUPOST']['cardtype'])) {
57  $errors[] = "Invalid Card Type";
58  }
59  if (sizeof($errors)) {
60  $payload[data] = '';
61  $payload[errors] = $errors;
62  } else {
63  $payload[data] = "{$parms['HCUPOST']['card4']},{$parms['HCUPOST']['cardsig']},{$parms['HCUPOST']['cardtype']}";
64  }
65  return $payload;
66  }
67 
68  public function printTemplate()
69  { ?>
70  <span id="popupNotification"></span>
71  <div id='gridMsg' style="100%"></div>
72  <div id="window"></div>
73  <div id="winErr"></div>
74  <?php }
75 
76  public function printGlobals()
77  { ?>
78  var tValues = [ {'value':'', 'text':'...Choose...'}, {'value':'P', 'text':'P'}, {'value':'1', 'text':'1'}, {'value': '2', 'text': '2'}, {'value': '3', 'text': '3'}];
79  var isCreating;
80 
81  <?php }
82 
83  public function printInit($crudhost, $trustid, $fromUserHub=false)
84  { ?>
85  var windowTemplate= 'Delete card ending in <strong>#= card4 #</strong> for member <strong>#= accountnumber #</strong>? </p>\
86  <button class="k-button" id="yesButton">Yes</button>\
87  <button class="k-button" id="noButton"> No</button>';
88 
89  var windowError= '#= Message #</p>\
90  <button class="k-button" id="errCloseButton">Close</button>';
91 
92  windowTemplate = kendo.template(windowTemplate);
93  var windowT = $("#window").kendoWindow({
94  title: "Please Confirm",
95  visible: false, //the window will not appear before its .open method is called
96  width: "400px",
97  modal: true,
98  close: function()
99  {
100  if (window.activeWindows != null)
101  window.activeWindows.pop();
102  },
103  open: function()
104  {
105  if (window.activeWindows != null)
106  window.activeWindows.push(this);
107  }
108  }).data("kendoWindow");
109 
110  windowError = kendo.template(windowError);
111  var winErr = $("#winErr").kendoWindow({
112  title: "Error",
113  visible: false, //the window will not appear before its .open method is called
114  actions: ["Close"],
115  modal: true,
116  width: "400px",
117  close: function()
118  {
119  if (window.activeWindows != null)
120  window.activeWindows.pop();
121  },
122  open: function()
123  {
124  if (window.activeWindows != null)
125  window.activeWindows.push(this);
126  }
127  }).data("kendoWindow");
128 
129  var popupNotification = $("#popupNotification").kendoNotification().data("kendoNotification");
130  popupNotification.setOptions({
131  appendTo: "body",
132  stacking: 'up',
133  autoHideAfter: 5000
134  });
135 
136  var crudServiceBaseUrl = "<?php echo $crudhost; ?>?ft=534&trustid=<?php echo $trustid; ?>";
137  <?php if ($fromUserHub) { ?>
138  crudServiceBaseUrl+= "&userid=" + $("#selectedId").text();
139  <?php } ?>
140  var dataSource = new kendo.data.DataSource({
141  autoSync: false,
142  batch: false,
143  serverFiltering: false,
144  serverPaging: false,
145  page: 1,
146  pageSize: 20,
147  cache: false,
148  transport: {
149  read: {
150  type: "GET",
151  url: crudServiceBaseUrl + "&action=read",
152  dataType: "json"
153  },
154  update: {
155  type: "POST",
156  url: crudServiceBaseUrl + "&action=update",
157  dataType: "json"
158  },
159  destroy: {
160  type: "POST",
161  url: crudServiceBaseUrl + "&action=delete",
162  dataType: "json"
163  },
164  create: {
165  type: "POST",
166  url: crudServiceBaseUrl + "&action=new",
167  dataType: "json"
168  },
169  parameterMap: function(options, operation) {
170  if (operation !== "read" && options.models) {
171  return {models: kendo.stringify(options.models)};
172  } else if (operation === 'create' || operation === 'update' || operation === 'destroy') {
173  return options;
174  }
175  }
176  },
177  schema: {
178  data: "homecuData",
179  total: function(response)
180  {
181  return response.homecuData.length;
182  },
183  errors: function(response)
184  {
185  return response.homecuErrors != null && response.homecuErrors.length > 0 ? response.homecuErrors : null;
186  },
187  parse: function(response)
188  {
189  var returnValue= response.Results[0];
190  if (returnValue.homecuInfo != null && returnValue.homecuInfo.length > 0)
191  popupNotification.show(returnValue.homecuInfo, "info");
192  return returnValue;
193  },
194  model: {
195  id: "keyid",
196  fields: {
197  keyid: {type: 'number', editable: false},
198  userid: {type: "number", editable: false},
199  accountnumber: { type: 'string', editable: false},
200  parms: { type: 'string'},
201  card4: { type: 'string', validation: {required: { message: "Card Last-4 Required" }} },
202  cardsig: { type: 'string', validation: {required: { message: "Card Signature Required"}} },
203  cardtype: { type: 'string', validation: {required: { message: "Card Type Required" }}, defaultValue: 'P' }
204  }
205  }
206  },
207  error: function(e)
208  {
209  grid.cancelRow();
210  winErr.content(windowError({Message: e.errors.join("<br>")})); //send the err data object to the template and render it
211  $("#winErr").closest(".k-window.k-widget").css({<?php printTopCenterCss(200, "", "jsGuts"); ?>});
212  winErr.open();
213  }
214  });
215 
216  var grid= $("#gridMsg").kendoGrid({
217  dataSource: dataSource,
218  <?php if (!$fromUserHub) { //This card is set up to only be able to add one record per account. Thus there is no need to sort from the userhub.?>
219  pageable: {
220  pageSizes: [10, 20, 50],
221  info: true,
222  refresh: true,
223  messages: {
224  display: "Showing {0}-{1} from {2} data items"
225  }
226  },
227  filterable: {extra: false},
228  sortable: true,
229  <?php } ?>
230  batch: false,
231  columns: [
232  { field: "userid", title: "User", width: "100px"},
233  { field:"accountnumber", title: "Member", width: "120px"},
234  { field: "card4", title:"Last 4", width: "100px", editor: function(container, options) {
235  var input = $("<input class='k-input k-textbox' maxlength='4' name='" + options.field + "'>").appendTo(container);
236  }},
237  { field: "cardsig", title:"Signature", width: "300px" },
238  { field: "cardtype", title:"Type", values: tValues, width: "100px" },
239  { command: [{name: "edit", text: "Change"}, {name: "Delete"}], title: "&nbsp;", width: "200px" }],
240  <?php if ($fromUserHub) { ?>
241  toolbar: ["create"],
242  <?php } else { ?>
243  toolbar: [{name: "customCreate", text: "<span class='k-icon k-add'></span> Add New Record"}],
244  <?php } ?>
245  editable: "inline",
246  edit: function(e)
247  {
248  if (e.model.isNew())
249  {
250  e.model.userid= $("#selectedAccntId").text();
251  e.model.accountnumber= $("#selectedAccnt").text();
252 
253  <?php if (!$fromUserHub) { ?>
254  e.container.find("td:eq(0)").text($("#selectedAccnt").text());
255  <?php } ?>
256  }
257  },
258  noRecords: {
259  template: "<tr><td colspan='<?php echo $fromUserHub ? 5 : 4; ?>'>No Records Found!</td></tr>"
260  }
261  }).data("kendoGrid");
262 
263  <?php if (!$fromUserHub) { ?>
264  $("#gridMsg").on("click", ".k-grid-customCreate", function() {
265  searchUser(function(dataItem) {
266  grid.addRow(); // Should have the selected accnt and primary user in the variables ready for the edit function.
267  $(".k-grid-edit-row .k-input:first").focus();
268  });
269  return false;
270  });
271  <?php } ?>
272 
273  $("#winErr").on("click", "#errCloseButton", function() {
274  winErr.close();
275  return false;
276  });
277 
278  var deleteDataItem= null;
279  $("#gridMsg").on("click", ".k-grid-Delete", function(e) {
280  var tr = $(e.target).closest("tr"); //get the row for deletion
281  deleteDataItem = grid.dataItem(tr); //get the row data so it can be referred later
282  windowT.content(windowTemplate(deleteDataItem)); //send the row data object to the template and render it
283  $("#window").closest(".k-window.k-widget").css({<?php printTopCenterCss(200, "", "jsGuts"); ?>});
284  windowT.open();
285  return false;
286  });
287 
288  $("#window").on("click", "#yesButton", function() {
289  dataSource.remove(deleteDataItem) //prepare a "destroy" request
290  dataSource.sync() //actually send the request (might be omitted if the autoSync option is enabled in the dataSource)
291  windowT.close();
292  return false;
293  });
294 
295  $("#window").on("click", "#noButton", function() {
296  windowT.close();
297  return false;
298  });
299  <?php }
300 
301  public function parms_disp4edit($findTab, $searchTab, $crudhost, $Cu, $trustid) {
302  /*
303  * parms_disp4edit - layout screen for display / edit values
304  */
305  $this->printTemplate();
306  printSearchTemplates($searchTab, $findTab);
307  printExtKeyStyle();
308  ?>
309  <script>
310  <?php // Library javascript functions
311  getShowWaitFunctions();
312  searchOutsideHub($searchTab, $findTab);
313  $this->printGlobals(); ?>
314  var activeWindows= [];
315  $(document).ready(function() {
316  <?php $this->printInit($crudhost, $trustid);
317  printClickOverlayEvent();
318  ?>
319  });
320  </script>
321  <?php
322  } // end parms_disp4edit
323 } // end class
324 ?>