From: stronk7 Date: Sun, 3 Aug 2003 00:42:41 +0000 (+0000) Subject: Teacher restoring and admin restoring finished. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=be2a6fc6ca899ecf28b1b53197e4d6abb04f2c80;p=moodle.git Teacher restoring and admin restoring finished. Allow restore into new course (only admins), restore into existing course deleting old and restore into existing course adding to old Teachers are limited to "current course" while admins ca select any course. :-) --- diff --git a/backup/restore_check.html b/backup/restore_check.html index f0e0c19f6e..abe804a380 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -98,8 +98,14 @@ 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 @@ -108,16 +114,43 @@ } //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 "id&launch=check&file=$file\">$course->fullname ($course->shortname)
"; + echo "id&launch=check&id=$id&file=$file\">$course->fullname ($course->shortname)
"; } print_simple_box_end(); } else { @@ -125,7 +158,7 @@ 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. @@ -151,6 +184,7 @@ echo "
"; $hidden["launch"] = "execute"; $hidden["file"] = $file; + $hidden["id"] = $id; print_single_button("restore.php", $hidden, get_string("restorecoursenow"),"post"); echo "
"; } else { diff --git a/backup/restore_execute.html b/backup/restore_execute.html index 7d4b7e220b..09eddafc6e 100644 --- a/backup/restore_execute.html +++ b/backup/restore_execute.html @@ -14,8 +14,14 @@ 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 @@ -52,7 +58,7 @@ //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 "
  • ".get_string("creatingnewcourse"); $status = restore_create_new_course($restore,$course_header); //Print course fullname and shortname and category @@ -71,18 +77,41 @@ echo ""; + //If we have selected to restore deleting, we do it now. + if ($restore->deleting) { + echo "
  • ".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 "
  • ".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 "
  • ".get_string("checkingsections"); $status = restore_create_sections($restore,$xml_file); + //Error } else { $status = false; } diff --git a/backup/restore_form.html b/backup/restore_form.html index 12dd72718c..c4566f357c 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -84,7 +84,12 @@ } if (!isset($restore_restoreto)) { - $restore_restoreto = 1; + if (isteacher($id) and !isadmin()) { + $restore_restoreto = 1; + } + if (isadmin()) { + $restore_restoreto = 2; + } } if ($count == 0) { @@ -103,8 +108,15 @@ echo "

    "; echo get_string("restoreto").":"; echo ""; - $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 ""; //Line