setup.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. }
  78. if (bResult)
  79. {
  80. $('#setup').block({message: '<img src="../images/indicator.gif">&nbsp;'+sMsg});
  81. }
  82. return bResult;
  83. }
  84. var aFilesToLoad = new Array();
  85. function DoLoadDataAsynchronous()
  86. {
  87. // Check if sample data must be loaded, or just the menus
  88. aFilesToLoad[aFilesToLoad.length] = './menus.xml'; // First load the menus
  89. if (($("#sample_data:checked").length == 1))
  90. {
  91. PopulateDataFilesList(); // Function created in PHP to get the list of XML files on the server
  92. }
  93. $('#setup').block({message: '<p>Loading data...<br/><div id=\"progress\">0%</div></p>'});
  94. $('#progress').progression( {Current:0, Maximum: 100, aBackgroundImg: 'orange-progress.gif', aTextColor: '#000000'} );
  95. LoadNextDataFile('', '');
  96. return false; // Stop here for now
  97. }
  98. var iCounter = 0;
  99. function LoadNextDataFile(sData, sTextStatus)
  100. {
  101. //$("#progress").html(sData);
  102. if (iCounter < aFilesToLoad.length)
  103. {
  104. if (iCounter == (aFilesToLoad.length - 1))
  105. {
  106. // Last file in the list (or only 1 file), this completes the session
  107. sSessionStatus = 'end';
  108. }
  109. else if (iCounter == 0)
  110. {
  111. // First file in the list, start the session
  112. sSessionStatus = 'start';
  113. }
  114. else
  115. {
  116. sSessionStatus = 'continue';
  117. }
  118. iPercent = Math.round((100.0 * (1+iCounter)) / aFilesToLoad.length);
  119. sFileName = aFilesToLoad[iCounter];
  120. //alert('Loading file '+sFileName+' ('+iPercent+' %) - '+sSessionStatus);
  121. $("#progress").progression({ Current: iPercent });
  122. iCounter++;
  123. $.get( 'ajax.dataloader.php', { 'file': sFileName, 'percent': iPercent, 'session_status': sSessionStatus }, LoadNextDataFile, 'html');
  124. }
  125. else
  126. {
  127. // We're done
  128. $('#setup').unblock();
  129. $('#GoToNextStep').submit(); // Use the hidden form to navigate to the next step
  130. }
  131. }