* * @package chamilo.backup */ require_once __DIR__.'/../inc/global.inc.php'; $current_course_tool = TOOL_COURSE_MAINTENANCE; api_protect_course_script(true); // Check access rights (only teachers are allowed here) if (!api_is_allowed_to_edit()) { api_not_allowed(true); } api_set_more_memory_and_time_limits(); // Section for the tabs $this_section = SECTION_COURSES; // Breadcrumbs $interbreadcrumb[] = [ 'url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'), ]; // Displaying the header $nameTools = get_lang('ImportBackup'); Display::display_header($nameTools); // Display the tool title echo Display::page_header($nameTools); $action = isset($_POST['action']) ? $_POST['action'] : ''; $importOption = isset($_POST['import_option']) ? $_POST['import_option'] : ''; /* MAIN CODE */ $filename = ''; if (Security::check_token('post') && ($action === 'course_select_form' || $importOption === 'full_backup')) { // Clear token Security::clear_token(); $error = false; if ($action === 'course_select_form') { // Partial backup here we recover the documents posted $filename = Session::read('backup_file'); $course = CourseArchiver::readCourse($filename, false); $course = CourseSelectForm::get_posted_course(null, null, null, $course); } else { if ($_POST['backup_type'] === 'server') { $filename = $_POST['backup_server']; $delete_file = false; } else { if ($_FILES['backup']['error'] == 0) { $filename = CourseArchiver::importUploadedFile($_FILES['backup']['tmp_name']); if ($filename === false) { $error = true; } else { $delete_file = false; } Session::write('backup_file', $filename); } else { $error = true; } } if (!$error) { // Full backup $course = CourseArchiver::readCourse($filename, $delete_file); } } if (!$error && is_object($course) && $course->has_resources()) { $cr = new CourseRestorer($course); $cr->set_file_option($_POST['same_file_name_option']); $cr->restore(); echo Display::return_message(get_lang('ImportFinished')); echo ''. get_lang('CourseHomepage').''; } else { if (!$error) { echo Display::return_message(get_lang('NoResourcesInBackupFile'), 'warning'); echo ''.get_lang('TryAgain').''; } elseif ($filename === false) { echo Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'error'); echo ''.get_lang('TryAgain').''; } else { if ($filename == '') { echo Display::return_message(get_lang('SelectBackupFile'), 'error'); echo ''.get_lang('TryAgain').''; } else { echo Display::return_message(get_lang('UploadError'), 'error'); echo ''.get_lang('TryAgain').''; } } } CourseArchiver::cleanBackupDir(); } elseif (Security::check_token('post') && $importOption === 'select_items') { // Clear token Security::clear_token(); if ($_POST['backup_type'] === 'server') { $filename = $_POST['backup_server']; $delete_file = false; } else { $filename = CourseArchiver::importUploadedFile($_FILES['backup']['tmp_name']); $delete_file = false; Session::write('backup_file', $filename); } $course = CourseArchiver::readCourse($filename, $delete_file); if ($course->has_resources() && $filename !== false) { $hiddenFields['same_file_name_option'] = $_POST['same_file_name_option']; // Add token to Course select form $hiddenFields['sec_token'] = Security::get_token(); CourseSelectForm::display_form($course, $hiddenFields); } elseif ($filename === false) { echo Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'error'); echo ''.get_lang('TryAgain').''; } else { echo Display::return_message(get_lang('NoResourcesInBackupFile'), 'warning'); echo ''.get_lang('TryAgain').''; } } else { $user = api_get_user_info(); $backups = CourseArchiver::getAvailableBackups($is_platformAdmin ? null : $user['user_id']); $backups_available = count($backups) > 0; $form = new FormValidator( 'import_backup_form', 'post', api_get_path(WEB_CODE_PATH).'coursecopy/import_backup.php?'.api_get_cidreq(), '', ['enctype' => 'multipart/form-data'] ); $form->addElement('header', get_lang('SelectBackupFile')); $renderer = $form->defaultRenderer(); $renderer->setCustomElementTemplate('