ajax.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $database = connectToDatabase($dbHost, $dbUsername, $dbPass, $dbName, $dbPort);
  34. $manager = $database->getManager();
  35. $db_prefix = api_get_configuration_value('db_prefix') ? api_get_configuration_value('db_prefix') : 'chamilo_';
  36. $db_c_prefix = api_get_configuration_value('table_prefix') ? api_get_configuration_value('table_prefix') : 'crs_';
  37. switch ($action) {
  38. case 'check_crs_tables':
  39. if (empty($dbName)) {
  40. echo 0;
  41. break;
  42. }
  43. $countOfTables = $manager
  44. ->getConnection()
  45. ->executeQuery("SHOW TABLES LIKE '$db_c_prefix$db_prefix%'")
  46. ->rowCount();
  47. echo $countOfTables;
  48. break;
  49. case 'remove_crs_tables':
  50. $statement = $manager
  51. ->getConnection()
  52. ->executeQuery("SHOW TABLES LIKE '$db_c_prefix$db_prefix%'");
  53. while ($table = $statement->fetch(PDO::FETCH_NUM)) {
  54. $manager->getConnection()->executeQuery("DROP TABLE {$table[0]}");
  55. }
  56. break;
  57. default:
  58. break;
  59. }