]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15355 restore - proper category selection when restoring from SITE + improved...
authorstronk7 <stronk7>
Sat, 23 May 2009 20:56:32 +0000 (20:56 +0000)
committerstronk7 <stronk7>
Sat, 23 May 2009 20:56:32 +0000 (20:56 +0000)
backup/restore_form.html

index 6bd34e416173f30c8088ecfe682b638ebb0f5d2c..f7a10abf974f29421445e41dc2d827e1f3f50e05 100644 (file)
@@ -239,14 +239,23 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
         echo '<label for="menurestore_restorecatto">'.get_string ('category').'</label>';
         echo "</td>";
         echo "<td>";
-        // Category selection isn't alowed if restoring from within SITEID course
-        if ($id != SITEID) {
-            make_categories_list($categories, $parents);
-            choose_from_menu($categories, "restore_restorecatto", $course_header->category->id, "");
+        // Get the list of categories where the user can create courses
+        make_categories_list($categories, $parents, 'moodle/course:create');
+        $category_default = null;
+        // Best default 1: restoring in same site, use category of original course if available
+        if (backup_is_same_site($info) &&
+            !empty($course_header->category->id) &&
+            array_key_exists($course_header->category->id, $categories)) {
+            $category_default = $course_header->category->id;
+        // Best default 2: restore to the category of the course we are restoring from if available
         } else {
-            print_string('notavailable');
-            echo '<input type="hidden" name="restore_restorecatto" id="menurestore_restorecatto" value="0" />';
+            $fromcat = $DB->get_field('course', 'category', array('id' => $id));
+            if (!empty($fromcat) &&
+                array_key_exists($fromcat, $categories)) {
+                $category_default = $fromcat;
+            }
         }
+        choose_from_menu($categories, 'restore_restorecatto', $category_default, "");
         echo "</td>";
         echo "</tr>";