setup.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // The array aFilesToLoad is populated by this function dynamically written on the server
  96. PopulateDataFilesList();
  97. $('#setup').block({message: '<p>Loading data...<br/><div id=\"progress\">0%</div></p>'});
  98. $('#progress').progression( {Current:0, Maximum: 100, aBackgroundImg: 'orange-progress.gif', aTextColor: '#000000'} );
  99. $('#log').ajaxError(function(e, xhr, settings, exception) { alert('Fatal error detected: '+ xhr.responseText); $('#log').append(xhr.responseText); $('#setup').unblock(); } );
  100. LoadNextDataFile('', '');
  101. return false; // Stop here for now
  102. }
  103. var iCounter = 0;
  104. function LoadNextDataFile(sData, sTextStatus)
  105. {
  106. //$("#progress").html(sData);
  107. if (iCounter < aFilesToLoad.length)
  108. {
  109. if (iCounter == (aFilesToLoad.length - 1))
  110. {
  111. // Last file in the list (or only 1 file), this completes the session
  112. sSessionStatus = 'end';
  113. }
  114. else if (iCounter == 0)
  115. {
  116. // First file in the list, start the session
  117. sSessionStatus = 'start';
  118. }
  119. else
  120. {
  121. sSessionStatus = 'continue';
  122. }
  123. iPercent = Math.round((100.0 * (1+iCounter)) / aFilesToLoad.length);
  124. sFileName = aFilesToLoad[iCounter];
  125. //alert('Loading file '+sFileName+' ('+iPercent+' %) - '+sSessionStatus);
  126. $("#progress").progression({ Current: iPercent });
  127. iCounter++;
  128. $.get( 'ajax.dataloader.php', { 'file': sFileName, 'percent': iPercent, 'session_status': sSessionStatus }, LoadNextDataFile, 'html');
  129. }
  130. else
  131. {
  132. // We're done
  133. $('#setup').unblock();
  134. $('#GoToNextStep').submit(); // Use the hidden form to navigate to the next step
  135. }
  136. }