import.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../../../main/inc/global.inc.php';
  5. $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
  6. // Security
  7. api_protect_admin_script();
  8. Virtual::checkSettings();
  9. $plugin = VChamiloPlugin::create();
  10. $form = new FormValidator('import', 'post', api_get_self());
  11. // Database host.
  12. $form->addHeader(get_lang('From'));
  13. $form->addText('root_web', [$plugin->get_lang('rootweb'), 'Example: http://www.chamilo.org/']);
  14. $form->addText('db_host', $plugin->get_lang('dbhost'));
  15. $form->applyFilter('db_host', 'trim');
  16. // Database login.
  17. $form->addText('db_user', $plugin->get_lang('dbuser'));
  18. $form->applyFilter('db_user', 'trim');
  19. // Database password.
  20. $form->addElement(
  21. 'password',
  22. 'db_password',
  23. $plugin->get_lang('dbpassword'),
  24. array('id' => 'id_vdbpassword')
  25. );
  26. // Database name.
  27. $form->addText('main_database', [$plugin->get_lang('maindatabase')]);
  28. $form->addText(
  29. 'configuration_file',
  30. [
  31. $plugin->get_lang('ConfigurationPath'),
  32. get_lang('Example').': /var/www/site/app/config/configuration.php'
  33. ],
  34. true
  35. );
  36. $encryptList = Virtual::getEncryptList();
  37. $form->addSelect(
  38. 'password_encryption',
  39. get_lang('EncryptMethodUserPass'),
  40. $encryptList
  41. );
  42. $encryptList = Virtual::getEncryptList();
  43. $versionList = [
  44. '1.11.x',
  45. '1.10.x',
  46. '1.9.x'
  47. ];
  48. $form->addSelect(
  49. 'version',
  50. $plugin->get_lang('FromVersion'),
  51. array_combine($versionList, $versionList)
  52. );
  53. $form->addText(
  54. 'course_path',
  55. [
  56. $plugin->get_lang('CoursePath'),
  57. get_lang('Example').': /var/www/site/virtual/var/courses'
  58. ],
  59. true
  60. );
  61. $form->addText(
  62. 'home_path',
  63. [
  64. $plugin->get_lang('HomePath'),
  65. get_lang('Example').': /var/www/site/virtual/var/home'
  66. ],
  67. true
  68. );
  69. $form->addText(
  70. 'upload_path',
  71. [
  72. $plugin->get_lang('UploadPath'),
  73. get_lang('Example').': /var/www/site/virtual/var/upload'
  74. ],
  75. true
  76. );
  77. $form->addHeader(get_lang('To'));
  78. $form->addText('to_db_host', $plugin->get_lang('dbhost'));
  79. $form->applyFilter('to_db_host', 'trim');
  80. // Database login.
  81. $form->addText('to_db_user', $plugin->get_lang('dbuser'));
  82. $form->applyFilter('to_db_user', 'trim');
  83. // Database password.
  84. $form->addElement(
  85. 'password',
  86. 'to_db_password',
  87. $plugin->get_lang('dbpassword'),
  88. array('id' => 'id_vdbpassword')
  89. );
  90. // Database name.
  91. $form->addText('to_main_database',
  92. [
  93. $plugin->get_lang('maindatabase'),
  94. $plugin->get_lang('DatabaseDescription'),
  95. ]
  96. );
  97. $form->addButtonSave($plugin->get_lang('savechanges'), 'submitbutton');
  98. $content = $form->returnForm();
  99. if ($form->validate()) {
  100. $values = $form->getSubmitValues();
  101. $coursePath = $values['course_path'];
  102. $homePath = $values['home_path'];
  103. $confFile = $values['configuration_file'];
  104. if (is_dir($coursePath) &&
  105. is_dir($homePath) &&
  106. file_exists($confFile) &&
  107. is_readable($confFile)
  108. ) {
  109. $currentHost = api_get_configuration_value('db_host');
  110. $currentDatabase = api_get_configuration_value('main_database');
  111. $currentUser = api_get_configuration_value('db_user');
  112. $currentPassword = api_get_configuration_value('db_password');
  113. if ($values['to_main_database'] !== $currentDatabase &&
  114. $values['to_db_user'] !== $currentUser &&
  115. $values['to_db_password'] !== $currentPassword
  116. ) {
  117. } else {
  118. Display::addFlash(
  119. Display::return_message(
  120. $plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo'),
  121. 'warning'
  122. )
  123. );
  124. }
  125. $vchamilo = new stdClass();
  126. $vchamilo->main_database = $values['main_database'];
  127. $vchamilo->db_user = $values['db_user'];
  128. $vchamilo->db_password = $values['db_password'];
  129. $vchamilo->db_host = $values['db_host'];
  130. $vchamilo->root_web = $values['root_web'];
  131. $vchamilo->import_to_main_database = $values['to_main_database'];
  132. $vchamilo->import_to_db_user = $values['to_db_user'];
  133. $vchamilo->import_to_db_password = $values['to_db_password'];
  134. $vchamilo->import_to_db_host = $values['to_db_host'];
  135. $vchamilo->course_path = $values['course_path'];
  136. $vchamilo->home_path = $values['home_path'];
  137. $vchamilo->upload_path = $values['upload_path'];
  138. $vchamilo->password_encryption = $values['password_encryption'];
  139. Virtual::importInstance($vchamilo, $values['version']);
  140. Virtual::redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
  141. }
  142. }
  143. $tpl = new Template(get_lang('Import'), true, true, false, true, false);
  144. $tpl->assign('content', $content);
  145. $tpl->display_one_col_template();