Odyssey
hcuProfileAlias.prg
1 <?php
2  /*
3  * File: hcuProfileAlias
4  *
5  * Purpose: Handle the client-side updating of the user's alias.
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  $HB_ENV["HCUPOST"]= array("action" => "");
26  HCU_ImportVars($HB_ENV, 'HCUPOST', array("action" => "string"));
27 
28  if ($HB_ENV["HCUPOST"]["action"] == "test_alias" ) {
29  header('Content-Type: application/json');
30 
31  // get the user alias to test
32  $userAlias = trim($_POST["alias"]);
33 
34  // some basic tests
35  $aryReply = array( "result" => FALSE, "message" => $MC->msg( "Error" , HCU_DISPLAY_AS_JS) );
36 
37  // * Validate user alias length
38  if ( strlen( $userAlias ) >= 0 && strlen( $userAlias ) < 6 ) {
39  $aryReply = array( "result" => FALSE, "message" => $MC->msg('Username too short', HCU_DISPLAY_AS_JS) );
40  } else if ( strlen( $userAlias ) > 5 && !check_alias_format( $userAlias ) ) {
41  // * Validate the useralias is correct format
42  $aryReply = array( "result" => FALSE, "message" => $MC->msg('Username appears invalid', HCU_DISPLAY_AS_JS) );
43  } else if ( check_alias_available( $dbh, $HB_ENV, $userAlias ) ) {
44  $aryReply = array( "result" => TRUE, "message" => $MC->msg( "Available", HCU_DISPLAY_AS_JS) );
45  } else {
46  $aryReply = array( "result" => FALSE, "message" => $MC->msg( "Username not available" , HCU_DISPLAY_AS_JS) );
47  }
48 
49  print HCU_JsonEncode($aryReply);
50 
51  exit;
52  }
53 
54 
55 
56 
57  // ** SET VARIABLES FOR WEBSITE FLAGS
58 
59  // ** INCLUDE PRE CONTENT SCRIPT
60  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
61 
62  /*
63  * ** START CONTENT
64  */
65 
66  $maymust=(($HB_ENV["Fset2"] & $CU2_ALIAS_REQ) == $CU2_ALIAS_REQ ? $MC->msg('must', HCU_DISPLAY_AS_HTML) : $MC->msg('may', HCU_DISPLAY_AS_HTML));
67 
68  $Cu = $HB_ENV["Cu"];
69  $Cn = $HB_ENV["Cn"];
70 
71  ?>
72 <script type="text/javascript">
73  var dsProfileAlias;
74  $(document).ready(function() {
75  dsProfileAlias = new kendo.data.DataSource({
76  autoSync: false,
77  batch: false,
78  pageSize: 10,
79  transport: {
80  update: {
81  url: "hcuProfile.data?cu=<?php echo $HB_ENV["cu"] ?>",
82  dataType: "json",
83  contentType: "application/x-www-form-urlencoded",
84  type: "POST",
85  data: {
86  action: "usr_save"
87  },
88  cache: false
89  },
90  },
91  schema: {
92  model: { id: "id" },
93  parse: function(response) {
94  // not showing data, so return empty array
95  var display = [];
96  return display;
97  }
98  },
99  requestStart: function(e) {
100  ShowWaitWindow();
101  kendo.ui.progress($("#profile"), true);
102  },
103  requestEnd: function(e) {
104  CloseWaitWindow();
105 
106  var error = null;
107 
108  // stop the progress bar
109  kendo.ui.progress($("#profile"), false);
110 
111  // see if there is an error
112  if ( e.response && e.response.homecuErrors )
113  error = e.response.homecuErrors;
114 
115  if ( error && error.length > 0 ) {
116  e.preventDefault();
117  // make sure only old data
118  this.cancelChanges();
119  // show the error information
120  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
121  } else {
122  if ( e.response && e.response.homecuInfo && (e.response.homecuInfo.message.length > 0) ) {
123  ShowStatus( e.response.homecuInfo.message );
124  }
125 
126  // present the device key to the apps
127  if ( e.response.homecuData &&
128  e.response.homecuData.homecuKey &&
129  (e.response.homecuData.homecuKey.length > 0) ) {
130  var appInfo = JSON.stringify( { deviceKey: e.response.homecuData.homecuKey,
131  newUsername: $("#profileAlias1").val() } );
132 
133  <?php if ( $HB_ENV["platform"] == "ADA" ) : ?>
134  AndroidController.notifyCommand("NEW_DEVICE_KEY", appInfo);
135  <?php elseif ( $HB_ENV["platform"] == "APP" ) : ?>
136  var postObject = {
137  body: {
138  cmd: "NEW_DEVICE_KEY",
139  params: appInfo
140  }
141  };
142  window.webkit.messageHandlers.interOp.postMessage(postObject);
143  <?php endif ?>
144  }
145 
146  // if no error, clear out some of the values
147  $("#profilePasswordCurr").val("");
148  $("#profileAlias2").val("");
149  }
150  }
151 
152  });
153 
154  // status will be shown in the default info location
155  function ShowStatus( statusMessage ) {
156  $.homecuValidator.settings.formStatusField = "formStatus";
157  $.homecuValidator.settings.formInfoTitle = "";
158  $.homecuValidator.displayMessage(statusMessage);
159  }
160 
161  function ClearStatus( ) {
162  $.homecuValidator.settings.formStatusField = "formStatus";
163  $.homecuValidator.settings.formInfoTitle = "";
164  $.homecuValidator.displayMessage(null);
165  }
166 
167  $("#btnUpdate").click( function() {
168  if ( $.homecuValidator.validate() ) {
169  var request = {
170  action: "usr_save",
171  old: $("#profilePasswordCurr").val(),
172  user_alias: $.trim($("#profileAlias1").val()),
173  user_alias2: $.trim($("#profileAlias2").val())
174  };
175 
176  // CREATE FALSE DATA TO CALL UPDATE ON DATA SOURCE
177  dsProfileAlias.data([{id: 0}]);
178  dsProfileAlias.data()[0].dirty = true;
179 
180  // SET UPDATE REQUEST AND CALL
181  dsProfileAlias.transport.options.update.data = request;
182  dsProfileAlias.sync();
183  }
184  });
185 
186  // set up some validation, using the default error location
187  $.homecuValidator.setup({
188  formValidate: "formProfile",
189  formErrorTitle: "<?php echo $MC->msg("Error Occurred", HCU_DISPLAY_AS_JS) ?>"});
190 
191  homecuTooltip.bind({
192  reenterTip: "<?php echo $MC->msg("Tip Re-enter Password", HCU_DISPLAY_AS_JS); ?>",
193  aliasTip1: "<?php echo $MC->combo_msg('Username Set',HCU_DISPLAY_AS_JS,'#MAYMUST#',"$maymust"); ?>",
194  aliasTip2: "<?php echo $MC->msg("Username again to confirm", HCU_DISPLAY_AS_JS); ?>"
195  });
196 
197  $('#testAlias').click(function() {
198  var userAlias = $.trim($("#profileAlias1").val());
199 
200  // disable the button
201  $(this).prop("disabled","disabled");
202  $("#testAliasResult").html( "" );
203  $("#testAliasResult").css( "display", "inline" );
204 
205  // start AJAX
206  var parameters = { "action": "test_alias",
207  "alias": userAlias };
208  $.ajax({
209  url: "<?php echo $HB_ENV['loginpath'] . "/" . $HB_ENV['currentscript'] . "?" . $HB_ENV['cuquery']; ?>",
210  type: "post",
211  data: parameters
212  })
213  .done(function( data, textStatus, jqXHR ) {
214  // Show the result
215  var message = null;
216  if (data.result) {
217  message = "<i class='fa fa-check-circle fa-2x' style='color:green;'></i>";
218  $.homecuValidator.hideMessage();
219  } else {
220  message = "<i class='fa fa-ban fa-2x' style='color:red;'></i>";
221  $.homecuValidator.displayMessage(data.message, $.homecuValidator.settings.statusError);
222  }
223 
224  $("#testAliasResult").html( message );
225  })
226  .fail(function(jqXHR, textStatus, errorThrown) {
227  $("#testAliasResult").html( "<?php echo $MC->msg( "Error" , HCU_DISPLAY_AS_HTML); ?>" );
228  $("#testAliasResult").css("color", "red");
229  })
230  .always(function(jqXHR, textStatus, errorThrown) {
231  $("#testAlias").removeProp("disabled");
232  $("#testAliasResult").delay(5000).fadeOut(100);
233  });
234 
235  });
236 
237  });
238 
239 </script>
240 
241 <!-- STYLE CONTENT -->
242 <style type="text/css">
243 .hcuProfileAliasDiv {
244  min-width: 300px;
245  max-width: 700px;
246  margin-left: 0px;
247  margin-top: 15px;
248 }
249 
250 .k-block > .k-header {
251  white-space: normal;
252  height: 100%;
253 }
254 
255 .hcu-info-margin, .hcu-error-margin {
256  margin: 15px 0;
257 }
258 
259 .hcu-info-padding, .hcu-error-padding {
260  padding: 15px;
261 }
262 
263 .hcu-full-width {
264  width: 100%;
265 }
266 
267 /* top-bottom margin */
268 .hcu-container-margin {
269  margin: 15px 0;
270 }
271 
272 .hcu-no-padding {
273  padding: 0;
274 }
275 </style>
276 <!-- HTML CONTENT -->
277 <div class="container-fluid hcuProfileAliasDiv">
278  <div class="well well-sm">
279 
280  <!-- HEADER -->
281  <div>
282  <h3><?php echo $MC->msg('Username', HCU_DISPLAY_AS_HTML); ?></h3>
283  </div>
284 
285  <!-- FORM CONTENT -->
286  <form id='formProfile' name='formProfile'>
287  <fieldset>
288  <div class="col-xs-12 col-sm-6 hcu-container-margin">
289  <label for="profilePasswordCurr">
290  <span><?php echo $MC->msg('Re-enter Password', HCU_DISPLAY_AS_HTML); ?>: </span>
291  <span class="fa fa-question-circle-o" id="reenterTip"></span>
292  </label>
293 
294  <input type="password" name="profilePasswordCurr"
295  id="profilePasswordCurr"
296  class="k-textbox hcu-full-width"
297  placeholder="<?php echo $MC->msg('Re-enter Password', HCU_DISPLAY_AS_HTML); ?>"
298  data-required-msg="<?php echo $MC->msg('Invalid login or password', HCU_DISPLAY_AS_HTML) ?>"
299  required >
300  </div>
301  </fieldset>
302 
303  <fieldset>
304  <div class="col-xs-12 col-sm-6 hcu-container-margin">
305  <label for="profileAlias1">
306  <span><?php echo $MC->msg('Username', HCU_DISPLAY_AS_HTML); ?>: </span>
307  <span class="fa fa-question-circle-o" id="aliasTip1"></span>
308  </label>
309 
310  <input type="text" name="profileAlias1"
311  id="profileAlias1"
312  class="k-textbox hcu-full-width must_equal"
313  placeholder="<?php echo $MC->msg('Username', HCU_DISPLAY_AS_HTML); ?>"
314  value="<?php echo $Cn; ?>"
315  homecu-minlen="6"
316  data-required-msg="<?php echo $MC->msg('Username Required', HCU_DISPLAY_AS_HTML) ?>"
317  data-homecuCustomMinLen-msg="<?php echo $MC->msg('Username too short', HCU_DISPLAY_AS_HTML) ?>"
318  required >
319  </div>
320 
321  <div class="col-xs-12 col-sm-6 hcu-container-margin">
322  <label for="profileAlias2">
323  <span><?php echo $MC->msg('Confirm Username', HCU_DISPLAY_AS_HTML); ?>: </span>
324  <span class="fa fa-question-circle-o" id="aliasTip2"></span>
325  </label>
326 
327  <input type="text" name="profileAlias2"
328  id="profileAlias2"
329  class="k-textbox hcu-full-width must_equal"
330  homecu-minlen="6"
331  homecu-equals="must_equal"
332  placeholder="<?php echo $MC->msg('Confirm Username', HCU_DISPLAY_AS_HTML); ?>"
333  data-required-msg="<?php echo $MC->msg('Username Required', HCU_DISPLAY_AS_HTML) ?>"
334  data-homecuCustomMinLen-msg="<?php echo $MC->msg('Username too short', HCU_DISPLAY_AS_HTML) ?>"
335  required >
336  </div>
337  </fieldset>
338 
339  <fieldset>
340  <div class="col-xs-12 col-sm-6 hcu-container-margin">
341  <div class="col-xs-10 hcu-no-padding"><a id='testAlias' class='k-button'><?php echo $MC->msg("Test Username", HCU_DISPLAY_AS_HTML); ?></a></div>
342  <div class="col-xs-2 hcu-no-padding"><span id='testAliasResult'>&nbsp;</span></div>
343  </div>
344  </fieldset>
345 
346  </form>
347  </div>
348  <div class="hcu-template">
349  <div class="hcu-edit-buttons k-state-default">
350  &emsp;
351  <a href="##" id="btnUpdate" class="k-button k-primary">
352  <i class="fa fa-check fa-lg"></i><?php echo $MC->msg("Update", HCU_DISPLAY_AS_HTML); ?>
353  </a>
354  </div>
355  </div>
356 </div>
357 
358 
359 <?php
360  /*
361  * ** END CONTENT
362  */
363 
364  // ** INCLUDE POST CONTENT SCRIPT
365  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
366 
367 ?>