Odyssey
hcuProfileEmail.prg
1 <?php
2  /*
3  * File: hcuProfileEmail
4  *
5  * Purpose: Handle the client-side updating of the user's email info.
6  *
7  */
8 
9  // ** SET SCRIPT LEVEL VARIABLES
10  $serviceShowInfo = true;
11  $serviceLoadMenu = true;
12  $serviceShowMenu = true;
13 
14  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
15  require_once(dirname(__FILE__) . '/../library/hcuService.i');
16 
17  /*
18  * ** CHECK USER FEATURE PERMISSIONS **
19  * NOTE: DOES NOT RETURN ON FAILURE
20  */
21  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_BASIC);
22 
23  // ** INSERT BUSINESS LOGIC FOR THIS FORM
24 
25  // ** SET VARIABLES FOR WEBSITE FLAGS
26  $EMAIL_FLAG = GetMsgTxValue('MSGTX_FORCE_EM');
27 
28  // ** INCLUDE PRE CONTENT SCRIPT
29  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
30 
31  /*
32  * ** START CONTENT
33  */
34  // see if admin is requiring email validation
35  $emailRequired = ($HB_ENV['Fmsg_tx'] & $EMAIL_FLAG);
36 
37  // read the current settings
38  $defaultEmail = "";
39  $defaultEgenl = "";
40  $sql = "SELECT email, egenl_flag FROM {$HB_ENV['Cu']}user WHERE user_name='{$HB_ENV['Cn']}'";
41  $profileRS = db_query( $sql, $dbh );
42  if ( $profileRow = db_fetch_array( $profileRS, 0 ) ) {
43  $defaultEmail = trim( $profileRow['email'] );
44  $defaultEgenl = trim( $profileRow['egenl_flag'] );
45  }
46  db_free_result($profileRS);
47 
48  // get any email alerts so user has the option of updating those email addresses, also
49  $alertInfo = Get_AlertsDetailed( $dbh, $HB_ENV["Cu"], $HB_ENV["Uid"], $HB_ENV["Fset3"]);
50  $alertData = $alertInfo['data'];
51 
52  $hasAlertEmail = count( $alertData ) > 0;
53 
54  ?>
55 <script type="text/javascript">
56  $(document).ready(function() {
57  var dsProfileEmail = new kendo.data.DataSource({
58  autoSync: false,
59  batch: false,
60  pageSize: 10,
61  error: function(e) {
62  },
63  transport: {
64  read: {
65  url: "hcuProfile.data?cu=<?php echo $HB_ENV["Cu"] ?>",
66  dataType: "json",
67  contentType: "application/json",
68  type: "GET",
69  data: {
70  action: "thisshouldgetoverwritten"
71  },
72  cache: false
73  }
74  },
75  schema: {
76  parse: function(response) {
77  // not showing data, so return empty array
78  var display = [];
79  return display;
80  }
81  },
82  requestStart: function(e) {
83  ShowWaitWindow();
84  },
85  requestEnd: function(e) {
86  var error = null;
87 
88  // stop the progress bar
89  CloseWaitWindow();
90 
91  // see if there is an error
92  if ( e.response && e.response.homecuErrors )
93  error = e.response.homecuErrors;
94 
95  if ( error && error.length > 0 ) {
96  e.preventDefault();
97  // make sure only old data
98  this.cancelChanges();
99  // show the error information
100  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
101  } else {
102  if ( e.response && e.response.homecuInfo && (e.response.homecuInfo.message.length > 0) ) {
103  ShowStatus( e.response.homecuInfo.message );
104  }
105 
106  // present the device key to the apps
107  if ( e.response.homecuData &&
108  e.response.homecuData.homecuKey &&
109  (e.response.homecuData.homecuKey.length > 0) ) {
110  var appInfo = JSON.stringify( { deviceKey: e.response.homecuData.homecuKey } );
111 
112  <?php if ( $HB_ENV["platform"] == "ADA" ) : ?>
113  AndroidController.notifyCommand("NEW_DEVICE_KEY", appInfo);
114  <?php elseif ( $HB_ENV["platform"] == "APP" ) : ?>
115  var postObject = {
116  body: {
117  cmd: "NEW_DEVICE_KEY",
118  params: appInfo
119  }
120  };
121  window.webkit.messageHandlers.interOp.postMessage(postObject);
122  <?php endif ?>
123  }
124 
125  var grid = $("#gridAlertEmails").data("kendoGrid");
126 
127  // REFRESH DATA & GRID
128  if (grid) {
129  grid_ds = grid.dataSource;
130  grid_ds.read();
131  grid.refresh();
132  }
133 
134  <?php
135  // let apps know we did an update to profile info
136  if ( $HB_ENV["platform"] == "APP" || $HB_ENV["platform"] == "ADA" ) {
137  $paramsForApps = array( "script" => "ProfileEmail" );
138  $paramsJSON = HCU_JsonEncode($paramsForApps);
139  ?>
140  var appInfo = '<?php echo $paramsJSON; ?>';
141 
142  <?php if ( $HB_ENV["platform"] == "ADA" ) : ?>
143  AndroidController.notifyCommand("PROFILE_UPDATE", appInfo);
144  <?php elseif ( $HB_ENV["platform"] == "APP" ) : ?>
145  var postObject = {
146  body: {
147  cmd: "PROFILE_UPDATE",
148  params: appInfo
149  }
150  };
151  window.webkit.messageHandlers.interOp.postMessage(postObject);
152  <?php endif ?>
153  <?php
154  }
155  ?>
156 
157  }
158  }
159 
160  });
161 
162 
163 
164  // status will be shown in the default info location
165  function ShowStatus( statusMessage ) {
166  $.homecuValidator.settings.formStatusField = "formStatus";
167  $.homecuValidator.settings.formInfoTitle = "";
168  $.homecuValidator.displayMessage(statusMessage);
169  }
170 
171  function ClearStatus( ) {
172  $.homecuValidator.settings.formStatusField = "formStatus";
173  $.homecuValidator.settings.formInfoTitle = "";
174  $.homecuValidator.displayMessage(null);
175  }
176 
177  $("#btnUpdate").click( function() {
178  if ($.homecuValidator.validate()) {
179  var alertEmails = "";
180 
181  // GRID INFORMATION, grid, datasource, number of rows
182  var grid = $("#gridAlertEmails").data("kendoGrid");
183  if (grid) {
184  var grid_ds = grid.dataSource;
185  var grid_nr = grid_ds.total();
186 
187  if (grid_nr > 0) {
188 
189  for(var i = 0; i < grid_nr; i++) {
190 
191  // GET ROW
192  var row = grid_ds.at(i);
193  if($("#email"+row.id).prop('checked')) {
194 
195  if(alertEmails.length > 0) {
196  alertEmails = alertEmails + "|";
197  }
198  alertEmails = alertEmails + row["email"];
199  }
200  }
201  }
202  }
203 
204  var request = {
205  action: "email_save",
206  email: $("#emailAddress").val(),
207  emailValid: ($("#profileEmailValid").prop("checked") ? "Y" : "N"),
208  egenl: ($("#profileEgenl").prop("checked") ? "Y" : "N"),
209  alertEmails: alertEmails
210  };
211 
212  ShowWaitWindow();
213 
214  dsProfileEmail.transport.type = "POST";
215  dsProfileEmail.read( request );
216 
217  }
218  });
219 
220 
221  // MOBILE COLUMN TEMPLATE
222  var mobile_column_data = "";
223  mobile_column_data += "<div class=\"account_cell_desc\"><strong><?php echo $MC->msg("Alert Type", HCU_DISPLAY_AS_JS); ?>:</strong></div> <div class=\"account_cell_value\">#= type #</div>";
224 
225  mobile_column_data += "<div class=\"account_cell_desc\"><strong><?php echo $MC->msg("Alert Email Address", HCU_DISPLAY_AS_JS); ?>:</strong></div> <div class=\"account_cell_value\">#= email #</div>";
226 
227  $('#gridAlertEmails').kendoGrid({
228  dataSource: {
229  transport: {
230  read: {
231  url: "hcuProfile.data?cu=<?php echo $HB_ENV["Cu"] ?>",
232  dataType: "json",
233  contentType: "application/json",
234  type: "GET",
235  data: {
236  action: "read_alert_emails"
237  },
238  cache: false
239  }
240  },
241  requestStart: function() {
242  ShowWaitWindow();
243  },
244  requestEnd: function() {
245  CloseWaitWindow();
246  },
247  schema: {
248  parse: function(data) {
249  return data.homecuData;
250  }
251  }
252  },
253  sortable: {
254  mode: "single",
255  allowUnsort: false
256  },
257  pageable: false,
258  autoBind: true,
259  editable: false,
260  selectable: "row",
261  columns: [
262  {
263  field: "type",
264  title: "<?php echo $MC->msg("Alert Type", HCU_DISPLAY_AS_JS); ?>",
265  editable: false,
266  minScreenWidth: 768
267  },
268  {
269  field: "email",
270  title: "<?php echo $MC->msg("Alert Email Address", HCU_DISPLAY_AS_JS); ?>",
271  editable: false,
272  minScreenWidth: 768
273  },
274  {
275  title: "<?php echo $MC->msg("Alerts", HCU_DISPLAY_AS_JS); ?>",
276  template: mobile_column_data
277  },
278  {
279  field: "choice",
280  title: "<?php echo $MC->msg("Update", HCU_DISPLAY_AS_JS); ?>",
281  width: 65,
282  template: "<input type='checkbox' id='email#=id#' #= choice === 'Y' ? 'checked=checked' : '' #></input>",
283  editable: false
284  }
285  ],
286  change: function(e) {
287  e.preventDefault();
288 
289  var selectedRow = this.dataItem(this.select());
290  var rowChecked = $("#email"+selectedRow["id"]).prop("checked");
291 
292  $("#email"+selectedRow["id"]).prop("checked", !rowChecked);
293 
294  // cause the check box to be clicked
295  // NOTE: the onclick handler will return "false" to prevent a "double click" when clicking on the checkbox itself
296  return false;
297  },
298  dataBound: function () {
299  $("table tbody tr").hover(
300  function() {
301  $(this).toggleClass("k-state-hover");
302  }
303 
304  );
305  }
306  });
307 
308 
309  // set up some validation, using the default error location
310  $.homecuValidator.setup({formValidate: "formProfile",
311  formErrorTitle: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>"});
312 
313  // Must hide confirmation email until
314  // the user makes a change to the original
315  // email
316 
317  // On change, display the email field
318  // add required and homecu validator fields
319 
320  // Also if email is required, disable the checkbox
321  // after checking.
322  $("#emailConfirmSection").hide();
323  $("#emailAddress").change(function(){
324  $("#profileEmailValid").prop("checked", true);
325  $("#profileEmailValid").prop("disabled", true);
326  $("#emailConfirmSection").show();
327  $("#emailAddressConfirm").attr("required", "required");
328  $("#emailAddressConfirm").attr("homecu-match", "email");
329  $("#emailAddressConfirm").attr("homecu-equals", "email_match");
330  });
331 
332  //
333 
334  // CHECK SIZE TO HIDE LAST COLUMN, LAST COLUMN ONLY VISIBLE IN MOBILE
335  var width = $(window).width();
336  var grid = $("#gridAlertEmails").data("kendoGrid");
337 
338  // INITIAL CHECK IN PAGE OPEN
339  if (grid) {
340  if ($(window).width() >= 768) {
341  grid.hideColumn(2);
342  } else {
343  grid.showColumn(2);
344  }
345 
346  // CHECK ON PAGE RESIZE
347  $(window).resize(function() {
348  width = $(window).width();
349 
350  if (width >= 768) {
351  grid.hideColumn(2);
352  } else {
353  grid.showColumn(2);
354  }
355  });
356  }
357  });
358 
359 </script>
360 
361 <!-- STYLES -->
362 <style type="text/css">
363 .hcuProfileEmailDiv {
364  min-width: 300px;
365  max-width: 700px;
366  margin-left: 0px;
367  margin-top: 15px;
368 }
369 
370 .container-fluid-margin {
371  margin: 15px;
372 }
373 
374 .k-block > .k-header {
375  white-space: normal;
376  height: 100%;
377 }
378 
379 .hcu-info-margin, .hcu-error-margin {
380  margin: 15px 0;
381 }
382 
383 .hcu-info-padding, .hcu-error-padding {
384  padding: 15px;
385 }
386 
387 .hcu-full-width {
388  width: 100%;
389 }
390 /* top-bottom margin */
391 .hcu-container-margin {
392  margin: 15px 0;
393 }
394 .hcu-no-padding {
395  padding: 0;
396 }
397 
398 .hcu-cursor-pointer {
399  cursor: pointer;
400 }
401 
402 .account_cell_desc {
403  width: 50%;
404  float: left;
405 
406  text-align: left;
407 }
408 
409 .account_cell_value {
410  width: 50%;
411  float: left;
412 
413  text-align: right;
414 }
415 
416 @media only screen and (max-width: 500px) {
417  .account_cell_desc {
418  width: 100%;
419  text-align: left;
420  }
421 
422  .account_cell_value {
423  width: 100%;
424  text-align: left;
425  }
426 }
427 </style>
428 
429 <!-- HTML CONTENT -->
430 <div class="container-fluid hcuProfileEmailDiv">
431  <div class="well well-sm">
432 
433  <!-- HEADER -->
434  <div>
435  <h3><?php echo $MC->msg('Change Email Settings', HCU_DISPLAY_AS_HTML); ?></h3>
436  </div>
437 
438  <!-- FORM ELEMENTS -->
439  <form id="formProfile" name="formProfile">
440  <fieldset>
441  <div class="col-xs-12 col-sm-6 hcu-container-margin">
442 
443  <label for="emailAddress" class="hcu-full-width">
444  <?php echo $MC->msg("Email Address", HCU_DISPLAY_AS_HTML); ?>:
445  </label>
446 
447  <input type="email" name="emailAddress"
448  id="emailAddress"
449  class="k-textbox hcu-full-width email_match"
450  value="<?php echo $defaultEmail ?>"
451  placeholder="<?php echo $MC->msg('Email Address', HCU_DISPLAY_AS_HTML); ?>"
452  homecu-match="email"
453  data-email-msg="<?php echo $MC->msg('Email appears invalid', HCU_DISPLAY_AS_HTML) ?>"
454  data-homecuCustomMatch-msg="<?php echo $MC->msg('Email appears invalid', HCU_DISPLAY_AS_HTML) ?>"
455  data-required-msg="<?php echo $MC->msg('EMail Missing', HCU_DISPLAY_AS_HTML) ?>"
456  required >
457 
458  </div>
459 
460  <div class="col-xs-12 col-sm-6 hcu-container-margin" id="emailConfirmSection">
461 
462  <label for="emailAddressConfirm" class="hcu-full-width">
463  <?php echo $MC->msg("Confirm Email Address", HCU_DISPLAY_AS_HTML); ?>:
464  </label>
465 
466  <input type="email" name="emailAddressConfirm"
467  id="emailAddressConfirm"
468  class="k-textbox hcu-full-width email_match"
469  placeholder="<?php echo $MC->msg('Confirm Email Address', HCU_DISPLAY_AS_HTML); ?>"
470  data-email-msg="<?php echo $MC->msg('Email appears invalid', HCU_DISPLAY_AS_HTML) ?>"
471  data-homecuCustomMatch-msg="<?php echo $MC->msg('Email appears invalid', HCU_DISPLAY_AS_HTML) ?>"
472  data-homecuCustomEquals-msg="<?php echo $MC->msg('Email Confirm Mismatch', HCU_DISPLAY_AS_HTML); ?>"
473  data-required-msg="<?php echo $MC->msg('Please confirm email', HCU_DISPLAY_AS_HTML) ?>">
474  </div>
475  </fieldset>
476 
477  <fieldset>
478  <?php if ($emailRequired): ?>
479  <div class="col-xs-12 hcu-container-margin checkbox">
480 
481  <label for="profileEmailValid" id="profileEmailValidTxt" class="hcu-cursor-pointer">
482  <input type="checkbox" name="profileEmailValid"
483  id="profileEmailValid"
484  class=""
485  data-required-msg="<?php echo $MC->msg("Please confirm email", HCU_DISPLAY_AS_HTML); ?>"
486  required >
487  <?php echo $MC->msg('Bad Email Flag 2', HCU_DISPLAY_AS_HTML); ?>
488  </label>
489 
490  </div>
491  <?php endif; ?>
492 
493  <div class="col-xs-12 hcu-container-margin checkbox">
494 
495  <label for="profileEgenl" id="profileEgenlTxt" class="hcu-cursor-pointer">
496  <input type="checkbox" name="profileEgenl"
497  id="profileEgenl"
498  value="Y"
499  <?php echo ($defaultEgenl == "N" ? "" : "checked") ?>>
500  <?php echo $MC->msg('Yes Email List', HCU_DISPLAY_AS_HTML); ?>
501  </label>
502 
503  </div>
504  </fieldset>
505 
506  <?php if ($hasAlertEmail): ?>
507  <fieldset id="updateAlertEmails">
508  <div class="col-xs-12 hcu-container-margin">
509  <span>
510  <i><?php echo $MC->msg( "Alert email message.", HCU_DISPLAY_AS_HTML ); ?></i>
511  </span>
512  <div id="gridAlertEmails"></div>
513  </div>
514  </fieldset>
515  <?php endif; ?>
516 
517  </form>
518 
519  </div>
520  <div class="hcu-template">
521  <div class="hcu-edit-buttons k-state-default">
522  &emsp;
523  <a href="##" id="btnUpdate" class="k-button k-primary">
524  <i class="fa fa-check fa-lg"></i><?php echo $MC->msg("Update", HCU_DISPLAY_AS_HTML); ?>
525  </a>
526  </div>
527  </div>
528 </div>
529 <?php
530  /*
531  * ** END CONTENT
532  */
533 
534  // ** INCLUDE POST CONTENT SCRIPT
535  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
536 
537 ?>