]> git.mjollnir.org Git - moodle.git/commitdiff
Some small fixes when deleting a category
authormoodler <moodler>
Fri, 22 Aug 2003 12:49:37 +0000 (12:49 +0000)
committermoodler <moodler>
Fri, 22 Aug 2003 12:49:37 +0000 (12:49 +0000)
course/index.php
lib/datalib.php

index 06c831771c20d5186cb81ab2852b488fb49d5086..30e30927cac0ec4e68268663cbb038646280d944 100644 (file)
                 notify(get_string("categorydeleted", "", $tempcat->name));
             }
             if ($children = get_records("course_categories", "parent", $tempcat->id)) {
+                // Send the children to live with their grandparent
                 foreach ($children as $childcat) {
                     if (! set_field("course_categories", "parent", $tempcat->parent, "id", $childcat->id)) {
                         notify("Could not update a child category!");
 
 /// Find any orphan courses that don't yet have a valid category and set to default
     if ($courses = get_courses()) {
+        $foundorphans = false;
         foreach ($courses as $course) {
-            if ($course->category and !isset( $categories[$course->category] )) {
+            if ($course->category and !isset($categories[$course->category])) {
                 set_field("course", "category", $default, "id", $course->id);
+                $foundorphans = true;
             }
         }
+        if ($foundorphans) {
+            fix_course_sortorder($default);
+        }
     }
 
 /// Print form for creating new categories
index 4bafe4848be4d9988c706e688d77a38cf9a3b9f3..19b18f05479f558e4192af296380bde06a69fa28 100644 (file)
@@ -1115,7 +1115,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
 
     $categoryselect = "";
     if ($categoryid != "all") {
-        $categoryselect = "c.category = '$categoryid'";
+        $categoryselect = "WHERE c.category = '$categoryid'";
     }
 
     $teachertable = "";
@@ -1131,7 +1131,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
         $visiblecourses = "AND c.visible > 0";
     }
 
-    $selectsql = "{$CFG->prefix}course c $teachertable WHERE $categoryselect $visiblecourses";
+    $selectsql = "{$CFG->prefix}course c $teachertable $categoryselect $visiblecourses";
 
     return get_records_sql("SELECT $fields FROM $selectsql $teachergroup ORDER BY $sort");
 }