import_moodle.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @package chamilo.backup
  8. */
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  11. api_protect_course_script(true);
  12. // Check access rights (only teachers are allowed here)
  13. if (!api_is_allowed_to_edit()) {
  14. api_not_allowed(true);
  15. }
  16. // Remove memory and time limits as much as possible as this might be a long process...
  17. if (function_exists('ini_set')) {
  18. api_set_memory_limit('256M');
  19. ini_set('max_execution_time', 1800);
  20. }
  21. // Section for the tabs
  22. $this_section = SECTION_COURSES;
  23. // Breadcrumbs
  24. $interbreadcrumb[] = array(
  25. 'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php?'.api_get_cidreq(),
  26. 'name' => get_lang('Maintenance')
  27. );
  28. $form = new FormValidator('import_moodle');
  29. $form->addFile('moodle_file', get_lang('MoodleFile'));
  30. $form->addButtonImport(get_lang('Import'));
  31. if ($form->validate()) {
  32. $file = $_FILES['moodle_file'];
  33. $moodleImport = new MoodleImport();
  34. $responseImport = $moodleImport->import($file);
  35. Display::cleanFlashMessages();
  36. if ($responseImport) {
  37. Display::addFlash(
  38. Display::return_message(
  39. get_lang('MoodleFileImportedSuccessfully'),
  40. 'success'
  41. )
  42. );
  43. } else {
  44. Display::addFlash(
  45. Display::return_message(get_lang('ErrorImportingFile'), 'error')
  46. );
  47. }
  48. }
  49. $template = new Template(get_lang('ImportFromMoodle'));
  50. $infoMsg = Display::return_message(get_lang('ImportFromMoodleInstructions'), 'normal', false);
  51. $template->assign('info_msg', $infoMsg);
  52. $template->assign('form', $form->returnForm());
  53. $templateName = $template->get_template('coursecopy/import_moodle.tpl');
  54. $content = $template->fetch($templateName);
  55. $template->assign('header', get_lang('ImportFromMoodle'));
  56. $template->assign('content', $content);
  57. $template->display_one_col_template();