From: stronk7 Date: Tue, 12 May 2009 14:57:40 +0000 (+0000) Subject: MDL-19163 restore - enable course selection for teachers having perms in more than... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=94ba4c9eb858b427f7ee95c11df2fba2667fcd6a;p=moodle.git MDL-19163 restore - enable course selection for teachers having perms in more than 1 course ; merged from 19_STABLE --- diff --git a/backup/restore_check.html b/backup/restore_check.html index f6d6df0eb0..f3026d46d8 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -1,4 +1,5 @@ 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; @@ -232,16 +258,7 @@ $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) {