* @package chamilo.backup
*/
/* INIT SECTION */
// Language files that need to be included
$language_file = array('exercice', 'coursebackup', 'admin');
// Including the global initialization file
require '../inc/global.inc.php';
// 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')) {
ini_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);
// Include additional libraries
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once 'classes/CourseBuilder.class.php';
require_once 'classes/CourseArchiver.class.php';
require_once 'classes/CourseRestorer.class.php';
require_once 'classes/CourseSelectForm.class.php';
// Display the tool title
api_display_tool_title($nameTools);
/* MAIN CODE */
if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (isset($_POST['import_option']) && $_POST['import_option'] == 'full_backup' )) {
$error = false;
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
// Partial backup here we recover the documents posted
$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 && $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').
''.get_lang('CourseHomepage').'', false);
} else {
if (!$error) {
Display::display_warning_message(get_lang('NoResourcesInBackupFile').
''.get_lang('TryAgain').'', false);
} elseif ($filename === false) {
Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin').
''.get_lang('TryAgain').'', false);
} else {
Display::display_error_message(api_ucfirst(get_lang('UploadError')).
''.get_lang('TryAgain').'', false);
}
}
CourseArchiver::clean_backup_dir();
} elseif (isset($_POST['import_option']) && $_POST['import_option'] == 'select_items') {
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)) {
CourseSelectForm::display_form($course, array('same_file_name_option' => $_POST['same_file_name_option']));
} elseif ($filename === false) {
Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin').
''.get_lang('TryAgain').'', false);
} else {
Display::display_warning_message(get_lang('NoResourcesInBackupFile').
''.get_lang('TryAgain').'', false);
}
} else {
$user = api_get_user_info();
$backups = CourseArchiver::get_available_backups($is_platformAdmin?null:$user['user_id']);
$backups_available = count($backups) > 0;
echo ''.get_lang('SelectBackupFile').'
';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
$form = new FormValidator('import_backup_form', 'post', 'import_backup.php', '', 'multipart/form-data');
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('