import_moodle.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Import a backup from moodle system.
  5. *
  6. * @author José Loguercio <jose.loguercio@beeznest.com>
  7. *
  8. * @package chamilo.backup
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  12. api_protect_course_script(true);
  13. // Check access rights (only teachers are allowed here)
  14. if (!api_is_allowed_to_edit()) {
  15. api_not_allowed(true);
  16. }
  17. api_set_more_memory_and_time_limits();
  18. // Section for the tabs
  19. $this_section = SECTION_COURSES;
  20. // Breadcrumbs
  21. $interbreadcrumb[] = [
  22. 'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php?'.api_get_cidreq(),
  23. 'name' => get_lang('Backup'),
  24. ];
  25. $form = new FormValidator('import_moodle', 'post', api_get_self().'?'.api_get_cidreq());
  26. $form->addFile('moodle_file', get_lang('Moodle course file'));
  27. $form->addButtonImport(get_lang('Import'));
  28. if ($form->validate()) {
  29. $file = $_FILES['moodle_file'];
  30. $moodleImport = new MoodleImport();
  31. try {
  32. $responseImport = $moodleImport->import($file);
  33. Display::addFlash(
  34. Display::return_message(
  35. get_lang('Moodle course fileImportedSuccessfully'),
  36. 'success'
  37. )
  38. );
  39. } catch (Exception $exception) {
  40. Display::addFlash(
  41. Display::return_message($exception->getMessage(), 'error')
  42. );
  43. }
  44. }
  45. $template = new Template(get_lang('Import from Moodle'));
  46. $infoMsg = Display::return_message(get_lang('Import from MoodleInstructions'), 'normal', false);
  47. $template->assign('info_msg', $infoMsg);
  48. $template->assign('form', $form->returnForm());
  49. $templateName = $template->get_template('coursecopy/import_moodle.tpl');
  50. $content = $template->fetch($templateName);
  51. $template->assign('header', get_lang('Import from Moodle'));
  52. $template->assign('content', $content);
  53. $template->display_one_col_template();