setup.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. LoadNextDataFile('', '');
  100. return false; // Stop here for now
  101. }
  102. var iCounter = 0;
  103. function LoadNextDataFile(sData, sTextStatus)
  104. {
  105. //$("#progress").html(sData);
  106. if (iCounter < aFilesToLoad.length)
  107. {
  108. if (iCounter == (aFilesToLoad.length - 1))
  109. {
  110. // Last file in the list (or only 1 file), this completes the session
  111. sSessionStatus = 'end';
  112. }
  113. else if (iCounter == 0)
  114. {
  115. // First file in the list, start the session
  116. sSessionStatus = 'start';
  117. }
  118. else
  119. {
  120. sSessionStatus = 'continue';
  121. }
  122. iPercent = Math.round((100.0 * (1+iCounter)) / aFilesToLoad.length);
  123. sFileName = aFilesToLoad[iCounter];
  124. //alert('Loading file '+sFileName+' ('+iPercent+' %) - '+sSessionStatus);
  125. $("#progress").progression({ Current: iPercent });
  126. iCounter++;
  127. $.get( 'ajax.dataloader.php', { 'file': sFileName, 'percent': iPercent, 'session_status': sSessionStatus }, LoadNextDataFile, 'html');
  128. }
  129. else
  130. {
  131. // We're done
  132. $('#setup').unblock();
  133. $('#GoToNextStep').submit(); // Use the hidden form to navigate to the next step
  134. }
  135. }