tab2.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. function validateAuth()
  2. {
  3. $error = false;
  4. if(document.getElementById("fsync_auth_apikey").value == '')
  5. {
  6. document.getElementById("fsync_auth_apikey_error").style.display = "block";
  7. $error = true;
  8. }
  9. else
  10. {
  11. document.getElementById("fsync_auth_apikey_error").style.display = "none";
  12. }
  13. if(document.getElementById("fsync_auth_username").value == '')
  14. {
  15. document.getElementById("fsync_auth_username_error").style.display = "block";
  16. $error = true;
  17. }
  18. else
  19. {
  20. document.getElementById("fsync_auth_username_error").style.display = "none";
  21. }
  22. if(document.getElementById("fsync_auth_password").value == '')
  23. {
  24. document.getElementById("fsync_auth_password_error").style.display = "block";
  25. $error = true;
  26. }
  27. else
  28. {
  29. document.getElementById("fsync_auth_password_error").style.display = "none";
  30. }
  31. if(document.getElementById("fsync_auth_fiscalcode").value == '')
  32. {
  33. document.getElementById("fsync_auth_fiscalcode_error").style.display = "block";
  34. $error = true;
  35. }
  36. else
  37. {
  38. document.getElementById("fsync_auth_fiscalcode_error").style.display = "none";
  39. }
  40. if($error)
  41. {
  42. return false;
  43. }
  44. else
  45. {
  46. testAuth();
  47. }
  48. }
  49. function submitAuthForm()
  50. {
  51. document.getElementById("authform_error").style.display = "none";
  52. validateAuth();
  53. }
  54. function ascii_to_hexa(str)
  55. {
  56. var arr1 = [];
  57. for (var n = 0, l = str.length; n < l; n ++)
  58. {
  59. var hex = Number(str.charCodeAt(n)).toString(16);
  60. arr1.push(hex);
  61. }
  62. return arr1.join('');
  63. }
  64. function testAuth()
  65. {
  66. var params = '';
  67. params += '&fsync_auth_apikey=' + document.getElementById("fsync_auth_apikey").value;
  68. params += '&fsync_auth_username=' + document.getElementById("fsync_auth_username").value;
  69. params += '&fsync_auth_password=' + document.getElementById("fsync_auth_password").value;
  70. params += '&fsync_auth_fiscalcode=' + document.getElementById("fsync_auth_fiscalcode").value;
  71. params = encodeURI(params);
  72. var xhttp;
  73. xhttp = new XMLHttpRequest();
  74. xhttp.onreadystatechange = function() {
  75. if (this.readyState == 4 && this.status == 200) {
  76. if( this.responseText == '')
  77. {
  78. document.getElementById("fsync_auth_password").value = ascii_to_hexa(document.getElementById("fsync_auth_password").value);
  79. document.getElementById('save-auth-btn').classList.remove('btn-green');
  80. document.getElementById('save-auth-btn').innerHTML = '<img src="View/img/loader.gif" />';
  81. document.getElementById('auth_form').submit();
  82. }
  83. else
  84. {
  85. document.getElementById("authform_error").style.display = "block";
  86. document.getElementById("authform_error").innerHTML = this.responseText;
  87. }
  88. }
  89. };
  90. xhttp.open("GET","ajax.php?random=" + Math.random() + "&action=testAuth" + params,true);
  91. xhttp.send();
  92. }