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