setup.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. function NameIsValid(name)
  2. {
  3. sName = new String(name);
  4. if (sName.match(/^[A-Za-z][A-Za-z0-9_]*$/)) return true;
  5. return false;
  6. }
  7. function DoSubmit(sMsg, iStep)
  8. {
  9. var bResult = true;
  10. switch(iStep)
  11. {
  12. case 1:
  13. if ($('#db_server').val() == '')
  14. {
  15. alert('Please specify a database server. Use "localhost" for a local DB server.');
  16. bResult = false;
  17. }
  18. else if ($('#db_user').val() == '')
  19. {
  20. alert('Please specify a user name to connect to the database.');
  21. bResult = false;
  22. }
  23. break;
  24. case 2:
  25. if ($("input[@type=radio]:checked").length < 1)
  26. {
  27. alert('Please specify a database name');
  28. bResult = false;
  29. }
  30. else if( ($("#new_db:checked").length == 1))
  31. {
  32. if ($('#new_db_name').val() == '')
  33. {
  34. alert('Please specify the name of the database to create');
  35. bResult = false;
  36. }
  37. else if (!NameIsValid($('#new_db_name').val()))
  38. {
  39. alert($('#new_db_name').val()+' is not a valid database name. Please limit yourself to letters, numbers and the underscore character.');
  40. bResult = false;
  41. }
  42. }
  43. else if ($("#current_db:checked").length == 1)
  44. {
  45. // Special case (DB enumeration failed, user must enter DB name)
  46. if ($("#current_db_name").val() == '')
  47. {
  48. alert('Please specify the name of the database.');
  49. bResult = false;
  50. }
  51. else
  52. {
  53. // Copy the typed value as the value of the radio
  54. $("#current_db").val($("#current_db_name").val());
  55. }
  56. }
  57. if( ($('#db_prefix').val() != '') && (!NameIsValid($('#db_prefix').val())) )
  58. {
  59. alert($('#db_prefix').val()+' is not a valid table name. Please limit yourself to letters, numbers and the underscore character.');
  60. bResult = false;
  61. }
  62. break;
  63. case 3:
  64. if ($('#auth_user').val() == '')
  65. {
  66. alert('Please specify a login name for the administrator account');
  67. bResult = false;
  68. }
  69. else if ($('#auth_pwd').val() != $('#auth_pwd2').val())
  70. {
  71. alert('Retyped password does not match! Please verify the password.');
  72. bResult = false;
  73. }
  74. break;
  75. case 4:
  76. bResult = DoLoadDataAsynchronous();
  77. break;
  78. // Email test page
  79. case 10:
  80. if ($('#to').val() == '')
  81. {
  82. alert('Please specify a destination address');
  83. bResult = false;
  84. }
  85. }
  86. if (bResult)
  87. {
  88. $('#setup').block({message: '<img src="../images/indicator.gif">&nbsp;'+sMsg});
  89. }
  90. return bResult;
  91. }
  92. var aFilesToLoad = new Array();
  93. function DoLoadDataAsynchronous()
  94. {
  95. try
  96. {
  97. // The array aFilesToLoad is populated by this function dynamically written on the server
  98. PopulateDataFilesList();
  99. $('#setup').block({message: '<p>Loading data...<br/><div id=\"progress\">0%</div></p>'});
  100. $('#progress').progression( {Current:0, Maximum: 100, aBackgroundImg: 'orange-progress.gif', aTextColor: '#000000'} );
  101. $('#log').ajaxError(function(e, xhr, settings, exception) { alert('Fatal error detected: '+ xhr.responseText); $('#log').append(xhr.responseText); $('#setup').unblock(); } );
  102. LoadNextDataFile('', '');
  103. }
  104. catch(err)
  105. {
  106. alert('An exception occured: '+err);
  107. }
  108. return false; // Stop here for now
  109. }
  110. var iCounter = 0;
  111. function LoadNextDataFile(sData, sTextStatus)
  112. {
  113. //$("#progress").html(sData);
  114. try
  115. {
  116. if (iCounter < aFilesToLoad.length)
  117. {
  118. if (iCounter == (aFilesToLoad.length - 1))
  119. {
  120. // Last file in the list (or only 1 file), this completes the session
  121. sSessionStatus = 'end';
  122. }
  123. else if (iCounter == 0)
  124. {
  125. // First file in the list, start the session
  126. sSessionStatus = 'start';
  127. }
  128. else
  129. {
  130. sSessionStatus = 'continue';
  131. }
  132. iPercent = Math.round((100.0 * (1+iCounter)) / aFilesToLoad.length);
  133. sFileName = aFilesToLoad[iCounter];
  134. //alert('Loading file '+sFileName+' ('+iPercent+' %) - '+sSessionStatus);
  135. $("#progress").progression({ Current: iPercent });
  136. iCounter++;
  137. $.get( 'ajax.dataloader.php', { 'file': sFileName, 'percent': iPercent, 'session_status': sSessionStatus }, LoadNextDataFile, 'html');
  138. }
  139. else
  140. {
  141. // We're done
  142. $('#setup').unblock();
  143. $('#GoToNextStep').submit(); // Use the hidden form to navigate to the next step
  144. }
  145. }
  146. catch(err)
  147. {
  148. alert('An exception occurred: '+err);
  149. }
  150. }