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!"); } ?>
"; echo ""; if (iscreator()) { //display these fields conditionally echo ""; echo ""; echo ""; echo ""; echo ""; echo " "; echo ""; } //Line echo ""; //Now, check modules and info and show posibilities if ($allmods = get_records("modules") ) { //Print option to select/deselect everything with 1 click. echo ""; echo ""; echo ""; echo ""; echo ""; $currentrow = 0; foreach ($allmods as $mod) { $modname = $mod->name; $modrestore = $modname."_restore_mods"; //If exists the lib & function $exist = "exists_".$modname; $restore_var = "restore_".$modname; $user_info_var = "restore_user_info_".$modname; if (isset($$exist)) { if ($$exist) { //Now check that we have that module info in the backup file if (isset($info->mods[$modname]) && $info->mods[$modname]->backup == "true") { //Print the full tr echo ""; echo ""; if (isset($info->mods[$modname]->instances)) { $instances = $info->mods[$modname]->instances; } if (!empty($instances) && is_array($instances)) { echo ''; } } else { //Module isn't restorable echo ""; echo ""; } } else { //Module isn't restorable echo ""; echo ""; } } else { //Module isn't restorable echo ""; echo ""; } $currentrow = ($currentrow + 1) % 2; } //Line echo ""; //Now print the Metacourse tr echo ""; echo ""; //Now print the Users tr echo ""; echo ""; //Now print the Logs tr echo ""; echo ""; //Now print the User Files tr echo ""; echo ""; //Now print the Course Files tr echo ""; echo ""; //Now print the Messages tr echo ""; echo ""; } ?>
"; echo get_string("restoreto").":"; echo ""; if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $restore_restoreto_options[0] = get_string("existingcoursedeleting"); $restore_restoreto_options[1] = get_string("existingcourseadding"); $restore_restoreto_options[2] = get_string("newcourse"); } else { // fix for MDL-7773 $restore_restoreto_options[0] = get_string("currentcoursedeleting"); $restore_restoreto_options[1] = get_string("currentcourseadding"); } choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, ""); echo "
"; print_string("shortname"); echo " :shortname\" alt=\"".get_string("shortname")."\" />" ; helpbutton("courseshortname", get_string("shortname")) ; if (isset($err["shortname"])) formerr($err["shortname"]); echo "
"; print_string("fullname"); echo " :fullname\" alt=\" ".get_string("fullname")."\" />" ; helpbutton("coursefullname", get_string("fullname")) ; if (isset($err["fullname"])) formerr($err["fullname"]); echo"
"; print_string("startdate"); echo ":"; print_date_selector("startday", "startmonth", "startyear", $form1->startdate); helpbutton("coursestartdate", get_string("startdate")); echo "

"; echo ''.get_string("include").":"; echo ""; echo "". get_string("all")."/"; echo "". get_string("none").""; echo ""; echo ' '; echo ""; echo "". get_string("all")."/"; echo "". get_string("none").""; echo "

 "; echo ""; $restore_options[1] = get_string("yes"); $restore_options[0] = get_string("no"); //choose_from_menu($restore_options, $restore_var, $$restore_var, ""); //choose_from_radio($restore_options, $restore_var, $$restore_var); //Print the checkbox print_checkbox($restore_var, $$restore_var, $$restore_var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'restore_'.$modname.'\',this.checked)'); //If backup contains user data, then show menu, else fix it to //without user data echo " "; echo ""; if ($info->mods[$modname]->userinfo == "true") { $restore_user_options[1] = get_string("yes"); $restore_user_options[0] = get_string("no"); //choose_from_menu($restore_user_options, $user_info_var, $$user_info_var, ""); //choose_from_radio($restore_user_options, $user_info_var, $$user_info_var); print_checkbox($user_info_var, $$user_info_var, $$user_info_var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'restore_user_info_'.$modname.'\',this.checked)'); } else { //Module haven't userdata echo get_string("withoutuserdata"); echo ""; } echo "
'; foreach ($instances as $instance) { echo ''; } echo '
'; $var = 'restore_'.$modname.'_instance_'.$instance->id; $$var = optional_param($var,1); print_checkbox($var,$$var,$$var,$instance->name,$instance->name,'this.form.elements[\'restore_'.$modname.'\'].checked=1;'); echo ' '; $var = 'restore_user_info_'.$modname.'_instance_'.$instance->id; $$var = optional_param($var,1); if ($info->mods[$modname]->instances[$instance->id]->userinfo == 'true') { print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'restore_user_info_'.$modname.'\'].checked=1;'); } else { echo ''; } echo '

"; echo get_string("metacourse").":"; echo ""; //If metacourse are in the backup file, show menu, else fixed to no if ($info->backup_metacourse == "true") { $metacourse_options[0] = get_string("no"); $metacourse_options[1] = get_string("yes"); choose_from_menu($metacourse_options, "restore_metacourse", $restore_metacourse, ""); } else { echo get_string("no"); echo ""; } echo "
"; echo get_string("users").":"; echo ""; //If some user is present in the backup file if ($info->backup_users == "all" or $info->backup_users == "course") { //If all users are in the backup file if ($info->backup_users == "all") { $user_options[0] = get_string("all"); } $user_options[1] = get_string("course"); $user_options[2] = get_string("none"); choose_from_menu($user_options, "restore_users", $restore_users, ""); } else { echo get_string("none"); echo ""; } echo "
"; echo get_string("logs").":"; echo ""; //If logs are in the backup file, show menu, else fixed to no if ($info->backup_logs == "true") { $log_options[0] = get_string("no"); $log_options[1] = get_string("yes"); choose_from_menu($log_options, "restore_logs", $restore_logs, ""); } else { echo get_string("no"); echo ""; } echo "
"; echo get_string ("userfiles").":"; echo ""; //If user files are in the backup file, show menu, else fixed to no if ($info->backup_user_files == "true") { $user_file_options[0] = get_string("no"); $user_file_options[1] = get_string("yes"); choose_from_menu($user_file_options, "restore_user_files", $restore_user_files, ""); } else { echo get_string("no"); echo ""; } echo "
"; echo get_string ("coursefiles").":"; echo ""; echo ""; echo ""; //If course files are in the backup file, show menu, else fixed to no if ($info->backup_course_files == "true") { $course_file_options[0] = get_string("no"); $course_file_options[1] = get_string("yes"); choose_from_menu($course_file_options, "restore_course_files", $restore_course_files, ""); } else { echo get_string("no"); echo ""; } echo "
"; //This tr is slighty different. Everything becomes hidden if //we haven't messages is the backup, to avoid confusions to users. //If messages are in the backup file, show menu, else fixed to no and show nothing if ($info->backup_messages == "true") { echo get_string ('messages','message').":"; echo ""; $message_options[0] = get_string("no"); $message_options[1] = get_string("yes"); choose_from_menu($message_options, "restore_messages", $restore_messages, ""); } else { echo " "; echo ""; } echo "

dataroot."/temp/backup/".$backup_unique_code."/moodle.xml"; $info = restore_read_xml_info($xml_file); if ($course->id == SITEID) { $siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_SYSTEM, SITEID), "shortname"); } else { $siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "shortname"); } echo (''); echo (''); if ($info->backup_moodle_version < 2006092801) { // 1.6 and below backup /// Editting teacher echo (''); /// Non-editting teacher echo (''); /// Student echo (''); } else { // 1.7 and above backup $roles = restore_read_xml_roles($xml_file); if (!empty($roles->roles)) { // possible to have course with no roles foreach ($roles->roles as $roleid=>$role) { echo (''); } } } // end else echo ('
'.get_string('sourcerole').''.get_string('targetrole').'
'); print_string('defaultcourseteacher'); echo (''); // get the first teacheredit legacy $roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, get_context_instance(CONTEXT_SYSTEM, SITEID)); $editteacher = array_shift($roles); choose_from_menu ($siterolesarray, "defaultteacheredit", $editteacher->id, 'new role', '', '0'); echo ('
'); print_string('noneditingteacher'); echo (''); // get the first teacheredit legacy $roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW, get_context_instance(CONTEXT_SYSTEM, SITEID)); $teacher = array_shift($roles); choose_from_menu ($siterolesarray, "defaultteacher", $teacher->id, 'new role', '', '0'); echo ('
'); print_string('defaultcoursestudent'); echo (''); // get the first teacheredit legacy $roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW, get_context_instance(CONTEXT_SYSTEM, SITEID)); $studentrole = array_shift($roles); choose_from_menu ($siterolesarray, "defaultstudent", $studentrole->id, 'new role', '', '0'); echo ('
'); echo $role->shortname; echo (''); // see if any short name match $matchrole = 0; foreach ($siterolesarray as $siteroleid=>$siteroleshortname) { if ($siteroleshortname == $role->shortname) { $matchrole = $siteroleid; break; } } choose_from_menu ($siterolesarray, "roles_".$roleid, $matchrole, 'new role', '', '0'); echo ('
'); // end of role mappings table ?>
" /> " />