ajax.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Chamilo installation
  5. * AJAX requests for the installation.
  6. *
  7. * @package chamilo.install
  8. */
  9. ini_set('display_errors', '1');
  10. ini_set('log_errors', '1');
  11. error_reporting(-1);
  12. require_once __DIR__.'/../../vendor/autoload.php';
  13. define('SYSTEM_INSTALLATION', 1);
  14. define('INSTALL_TYPE_UPDATE', 'update');
  15. define('FORM_FIELD_DISPLAY_LENGTH', 40);
  16. define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
  17. define('MAX_FORM_FIELD_LENGTH', 80);
  18. // Including necessary libraries.
  19. require_once '../inc/lib/api.lib.php';
  20. session_start();
  21. require_once api_get_path(LIBRARY_PATH).'database.constants.inc.php';
  22. require_once 'install.lib.php';
  23. $action = isset($_POST['a']) ? $_POST['a'] : null;
  24. $dbHost = isset($_POST['db_host']) ? $_POST['db_host'] : 'localhost';
  25. $dbUsername = isset($_POST['db_username']) ? $_POST['db_username'] : 'root';
  26. $dbPass = isset($_POST['db_pass']) ? $_POST['db_pass'] : '';
  27. $dbName = isset($_POST['db_name']) ? $_POST['db_name'] : 'chamilo';
  28. $installType = isset($_POST['install_type']) ? $_POST['install_type'] : 'new';
  29. if ($installType === 'new') {
  30. $dbName = null;
  31. }
  32. $dbPort = isset($_POST['db_port']) ? $_POST['db_port'] : 3306;
  33. $manager = connectToDatabase($dbHost, $dbUsername, $dbPass, $dbName, $dbPort);
  34. $db_prefix = api_get_configuration_value('db_prefix') ? api_get_configuration_value('db_prefix') : 'chamilo_';
  35. $db_c_prefix = api_get_configuration_value('table_prefix') ? api_get_configuration_value('table_prefix') : 'crs_';
  36. switch ($action) {
  37. case 'check_crs_tables':
  38. if (empty($dbName)) {
  39. echo 0;
  40. break;
  41. }
  42. $countOfTables = $manager
  43. ->getConnection()
  44. ->executeQuery("SHOW TABLES LIKE '$db_c_prefix$db_prefix%'")
  45. ->rowCount();
  46. echo $countOfTables;
  47. break;
  48. case 'remove_crs_tables':
  49. $statement = $manager
  50. ->getConnection()
  51. ->executeQuery("SHOW TABLES LIKE '$db_c_prefix$db_prefix%'");
  52. while ($table = $statement->fetch(PDO::FETCH_NUM)) {
  53. $manager->getConnection()->executeQuery("DROP TABLE {$table[0]}");
  54. }
  55. break;
  56. default:
  57. break;
  58. }