info)) {
error( 'info object missing from session' );
}
if (!($course_header = $SESSION->course_header)) {
error( 'course_header object missing from session' );
}
//Check that we have all we need
//backup_unique_code
$backup_unique_code = required_param( 'backup_unique_code' );
//file
$file = required_param( 'file' );
//Check login
require_login();
//Check admin
if (!empty($id)) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
}
//Check site
if (!$site = get_site()) {
error("Site not found!");
}
//Checks for the required files/functions to restore every mod
$count = 0;
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
$modrestore = $modname."_restore_mods";
if (file_exists($modfile)) {
include_once($modfile);
if (function_exists($modrestore)) {
$var = "exists_".$modname;
$$var = true;
$count++;
}
}
//Check data
//Check module info
$var = "restore_".$modname;
if (!isset($$var)) {
$$var = 1;
}
//Check include user info
$var = "restore_user_info_".$modname;
if (!isset($$var)) {
$$var = 1;
}
}
}
//Check other parameters
if (!isset($restore_metacourse)) {
$restore_metacourse = 1;
}
if (!isset($restore_users)) {
$restore_users = 1;
}
if (!isset($restore_logs)) {
$restore_logs = 1;
}
if (!isset($restore_user_files)) {
$restore_user_files = 1;
}
if (!isset($restore_course_files)) {
$restore_course_files = 1;
}
if (!isset($restore_messages)) {
$restore_messages = 1;
}
if (!isset($restore_restoreto)) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$restore_restoreto = 1;
}
if (has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$restore_restoreto = 2;
}
}
if(!isset($form1->startdate)) {
$form1->startdate = $course_header->course_startdate; //$course_header->course_startdate;
}
if (empty($form1->shortname)) {
$form1->shortname = $course_header->course_shortname; //'_shortname'; //$course_header->course_shortname;
}
if (empty($form1->fullname)) {
$form1->fullname = $course_header->course_fullname; // '_fullname'; //$course_header->course_fullname;
}
if ($count == 0) {
notice("No restorable modules are installed!");
}
?>