]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19163 restore - enable course selection for teachers having perms in more than...
authorstronk7 <stronk7>
Tue, 12 May 2009 14:57:40 +0000 (14:57 +0000)
committerstronk7 <stronk7>
Tue, 12 May 2009 14:57:40 +0000 (14:57 +0000)
backup/restore_check.html

index f6d6df0eb0d984c3d30ae680afeacfca3ae589bc..f3026d46d82e329b34704283379ed95c381fbea1 100644 (file)
@@ -1,4 +1,5 @@
 <?php //$Id$
+
     //This page receive all the restore_form data. Then, if existing course
     //has been selected, shows a list of courses to select one.
     //It cheks that the parammeter from restore_form are coherent.
         print_error("siteisnotdefined", 'debug');
     }
 
+    // Non-cached - get accessinfo
+    if (isset($USER->access)) {
+        $accessinfo = $USER->access;
+    } else {
+        $accessinfo = get_user_access_sitewide($USER->id);
+    }
+
+    // Get all the courses the user is able to restore to
+    $mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true, 'c.sortorder ASC',  array('id', 'fullname', 'shortname', 'visible'));
+
+    // Calculate if the user can create courses
+    $cancreatecourses = user_can_create_courses();
+
     //Depending the selected restoreto:
-    // If user is a teacher (and not creator) or we are restoring from within SITEID:
+    // A) If user has 'moodle/site:restore' in more than one course and cannot create courses and he isn't restoring from SITEID:
+    //    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.
+    // B) Else, if user cannot create courses or he is restoring from within SITEID:
     //    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 a creator:
+    // C) If the user is a creator:
     //    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.
+    // NOTE: SITEID is prevented as a source for restoring because it's public area and we must encourage admins
+    // to avoid using it as a "repository" for courses storage.
 
-    //If the user is a teacher and not a creator or we are restoring from within SITEID
-    $cancreatecourses = user_can_create_courses();
-    if (!$cancreatecourses || $id == SITEID) {
-        $restore->course_id = $id;
+    // A) If user has 'moodle/site:restore' in more than one course, cannot create courses and he isn't restoring from SITEID
+    if (count($mycourses) > 1 && !$cancreatecourses && $id != SITEID) {
+        /// Nothing to do, process continues and C) will show the list of courses
+
+    // B) Else, if the user is a teacher and not a creator or we are restoring from within SITEID
+    } else if (!$cancreatecourses || $id == SITEID) {
+        $restore->course_id = $id; /// Force restore to current course, disabling pick course from list
     }
 
+    // C) Arrived here, we have preprocessed all the changes needed by A) and B). Continue with the process
+
     //Set restore->deleting as needed
     if ($restore->restoreto == 0) {
         $restore->deleting = true;
         $restore->deleting = false;
     }
 
-    // Non-cached - get accessinfo
-    if (isset($USER->access)) {
-        $accessinfo = $USER->access;
-    } else {
-        $accessinfo = get_user_access_sitewide($USER->id);
-    }
-    $mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true, 'c.sortorder ASC',  array('id', 'fullname', 'shortname', 'visible'));
-
     //Now, select the course if needed
-    //if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and get_capability_courses('moodle/site:restore')) {
     if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) && count($mycourses) > 1) {
 
         if ($courses = $mycourses) {