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
$categoryselect = "";
if ($categoryid != "all") {
- $categoryselect = "c.category = '$categoryid'";
+ $categoryselect = "WHERE c.category = '$categoryid'";
}
$teachertable = "";
$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");
}