* @package chamilo.backup */ require_once '../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); } // Remove memory and time limits as much as possible as this might be a long process... if (function_exists('ini_set')) { api_set_memory_limit('256M'); ini_set('max_execution_time', 1800); } // Section for the tabs $this_section = SECTION_COURSES; // Breadcrumbs $interbreadcrumb[] = array( '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); /* MAIN CODE */ $filename = ''; if (Security::check_token('post') && ( ( isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || ( isset($_POST['import_option']) && $_POST['import_option'] == 'full_backup' ) ) ) { // Clear token Security::clear_token(); $error = false; if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') { // Partial backup here we recover the documents posted // This gets $_POST['course']. Beware that when using Suhosin, // the post.max_value_length limit might get in the way of the // restoration of a course with many items. A value of 1,000,000 bytes // might be too short. $course = CourseSelectForm::get_posted_course(); } else { if ($_POST['backup_type'] == 'server') { $filename = $_POST['backup_server']; $delete_file = false; } else { if ($_FILES['backup']['error'] == 0) { $filename = CourseArchiver::import_uploaded_file( $_FILES['backup']['tmp_name'] ); if ($filename === false) { $error = true; } else { $delete_file = true; } } else { $error = true; } } if (!$error) { // Full backup $course = CourseArchiver::read_course($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(); Display::display_normal_message(get_lang('ImportFinished')); echo '' . get_lang('CourseHomepage') . ''; } else { if (!$error) { Display::display_warning_message(get_lang('NoResourcesInBackupFile')); echo '' . get_lang('TryAgain') . ''; } elseif ($filename === false) { Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin')); echo '' . get_lang('TryAgain') . ''; } else { if ($filename == '') { Display::display_error_message(get_lang('SelectBackupFile')); echo '' . get_lang('TryAgain') . ''; } else { Display::display_error_message(get_lang('UploadError')); echo '' . get_lang('TryAgain') . ''; } } } CourseArchiver::clean_backup_dir(); } elseif (Security::check_token('post') && ( isset($_POST['import_option']) && $_POST['import_option'] == 'select_items' ) ) { // Clear token Security::clear_token(); if ($_POST['backup_type'] == 'server') { $filename = $_POST['backup_server']; $delete_file = false; } else { $filename = CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']); $delete_file = true; } $course = CourseArchiver::read_course($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) { Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin')); echo '' . get_lang('TryAgain') . ''; } else { Display::display_warning_message(get_lang('NoResourcesInBackupFile')); echo '' . get_lang('TryAgain') . ''; } } else { $user = api_get_user_info(); $backups = CourseArchiver::get_available_backups( $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(), '', array('enctype' => 'multipart/form-data') ); $form->addElement('header', get_lang('SelectBackupFile')); $renderer = $form->defaultRenderer(); $renderer->setCustomElementTemplate('