From 7a7ac154a457fc48e3f6f4f09e01eedaaef94d57 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 22 Aug 2003 12:49:37 +0000 Subject: [PATCH] Some small fixes when deleting a category --- course/index.php | 8 +++++++- lib/datalib.php | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/course/index.php b/course/index.php index 06c831771c..30e30927ca 100644 --- a/course/index.php +++ b/course/index.php @@ -103,6 +103,7 @@ 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!"); @@ -220,11 +221,16 @@ /// 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 diff --git a/lib/datalib.php b/lib/datalib.php index 4bafe4848b..19b18f0547 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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"); } -- 2.39.5