]> git.mjollnir.org Git - moodle.git/commitdiff
Teacher restoring and admin restoring finished.
authorstronk7 <stronk7>
Sun, 3 Aug 2003 00:42:41 +0000 (00:42 +0000)
committerstronk7 <stronk7>
Sun, 3 Aug 2003 00:42:41 +0000 (00:42 +0000)
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. :-)

backup/restore_check.html
backup/restore_execute.html
backup/restore_form.html

index f0e0c19f6eb28f66d65e4e1e59c8c746dcda254d..abe804a380d5b35fd9a4dd3ea2fad96d18a3f7f3 100644 (file)
     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 {
index 7d4b7e220b7dd4c9333f59bf568aa2cb68f88159..09eddafc6ed4d6a0406fd08c5a8ac9bf5435fca9 100644 (file)
     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 "<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;
         }
index 12dd72718c08e941b44b80f002a07a0a7f5da916..c4566f357c439f61cd010bdf00880f9bfe5acabb 100644 (file)
     }
 
     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