require_login();
//Check admin
- if (!isadmin()) {
- error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ if (!empty($id)) {
+ if (!isteacher($id)) {
+ error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ }
+ } else {
+ if (!isadmin()) {
+ error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ }
}
//Check site
}
//Depending the selected restoreto:
- // 0-Existing course: Select the destination course and launch the check again.
- // 1-New course: Create the restore object (checking everything) and launch the execute.
+ // If user is a teacher (and nor admin):
+ // 0-Current course, deleting: Put $restore->course_id and $restore->deleting (true), create the restore object
+ // 1-Current course, adding: Put $restore->course_id and $restore->deleting (false), create the restore object
+ // If the uses is an admin:
+ // 0-Existing course, deleting: Select the destination course and launch the check again, then
+ // put $restore->course_id and $restore->deleting (true), create the restore object.
+ // 1-Existing course, adding: Select the destination course and launch the check again, then
+ // put $restore->course_id and $restore->deleting (false), create the restore object.
+ // 2-New course: Create the restore object and launch the execute.
+
+ //If the user is a teacher and not an admin
+ if (isteacher($id) and !isadmin()) {
+ $restore->course_id = $id;
+ if ($restore->restoreto == 0) {
+ $restore->deleting = true;
+ } else {
+ $restore->deleting = false;
+ }
+ }
+
+ //If the user is an admin
+ if (isadmin()) {
+ //Set restore->deleting as needed
+ if ($restore->restoreto == 0) {
+ $restore->deleting = true;
+ } else {
+ $restore->deleting = false;
+ }
+ }
- //Select course
- if (($restore->restoreto == 0) and ($restore->course_id == 0)) {
+ //Now, select the course if needed
+ if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and (isadmin())) {
if ($courses = get_courses()) {
print_heading(get_string("choosecourse"));
print_simple_box_start("CENTER");
foreach ($courses as $course) {
- echo "<A HREF=\"restore.php?course_id=$course->id&launch=check&file=$file\">$course->fullname ($course->shortname)</A><BR>";
+ echo "<A HREF=\"restore.php?course_id=$course->id&launch=check&id=$id&file=$file\">$course->fullname ($course->shortname)</A><BR>";
}
print_simple_box_end();
} else {
print_continue("$CFG->wwwroot/$CFG->admin/index.php");
}
//Checks everything and execute restore
- } else if ((($restore->restoreto == 0) and ($restore->course_id != 0)) or ($restore->restoreto == 1)) {
+ } else if ((($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id != 0)) or ($restore->restoreto == 2)) {
$show_continue_button = true;
//Check if we've selected any mod's user info and restore->users
//is set to none. Change it to course and inform.
echo "<CENTER>";
$hidden["launch"] = "execute";
$hidden["file"] = $file;
+ $hidden["id"] = $id;
print_single_button("restore.php", $hidden, get_string("restorecoursenow"),"post");
echo "</CENTER>";
} else {
require_login();
//Check admin
- if (!isadmin()) {
- error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ if (!empty($id)) {
+ if (!isteacher($id)) {
+ error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ }
+ } else {
+ if (!isadmin()) {
+ error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ }
}
//Check site
//If we've selected to restore into new course
//create it (course)
//Saving conversion id variables into backup_tables
- if ($restore->restoreto ==1) {
+ if ($restore->restoreto == 2) {
echo "<li>".get_string("creatingnewcourse");
$status = restore_create_new_course($restore,$course_header);
//Print course fullname and shortname and category
echo "<ul>";
echo "<li>".get_string("from").": ".$course_header->course_fullname." (".$course_header->course_shortname.")";
echo "<li>".get_string("to").": ".$course->fullname." (".$course->shortname.")";
+ if (($restore->deleting)) {
+ echo "<li>".get_string("deletingexistingcoursedata");
+ } else {
+ echo "<li>".get_string("addingdatatoexisting");
+ }
echo "</ul>";
+ //If we have selected to restore deleting, we do it now.
+ if ($restore->deleting) {
+ echo "<li>".get_string("deletingcoursedata");
+ $status = remove_course_contents($restore->course_id,false) and
+ delete_dir_contents($CFG->dataroot."/".$restore->course_id,"backupdata");
+ if ($status) {
+ //Now , this situation is equivalent to the "restore to new course" one (we
+ //have a course record and nothing more), so define it as "to new course"
+ $restore->restoreto = 2;
+ } else {
+ notify("An error occurred while deleting some of the course contents.");
+ }
+ }
+ } else {
+ $status = false;
}
}
//Now create the course_sections and their associated course_modules
if ($status) {
- if ($restore->restoreto == 1) {
+ //Into new course
+ if ($restore->restoreto == 2) {
echo "<li>".get_string("creatingsections");
$status = restore_create_sections($restore,$xml_file);
- } else if ($restore->restoreto == 0) {
+ //Into existing course
+ } else if ($restore->restoreto == 0 or $restore->restoreto == 1) {
echo "<li>".get_string("checkingsections");
$status = restore_create_sections($restore,$xml_file);
+ //Error
} else {
$status = false;
}
}
if (!isset($restore_restoreto)) {
- $restore_restoreto = 1;
+ if (isteacher($id) and !isadmin()) {
+ $restore_restoreto = 1;
+ }
+ if (isadmin()) {
+ $restore_restoreto = 2;
+ }
}
if ($count == 0) {
echo "<td align=\"right\"><P><b>";
echo get_string("restoreto").":</b>";
echo "</td><td>";
- $restore_restoreto_options[0] = get_string("existingcourse");
- $restore_restoreto_options[1] = get_string("newcourse");
+ if (isteacher($id) and !isadmin()) {
+ $restore_restoreto_options[0] = get_string("currentcoursedeleting");
+ $restore_restoreto_options[1] = get_string("currentcourseadding");
+ }
+ if (isadmin()) {
+ $restore_restoreto_options[0] = get_string("existingcoursedeleting");
+ $restore_restoreto_options[1] = get_string("existingcourseadding");
+ $restore_restoreto_options[2] = get_string("newcourse");
+ }
choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
echo "</td></tr>";
//Line