diff --git a/course/category.php b/course/category.php index cb173b852b2..d84d21180e8 100644 --- a/course/category.php +++ b/course/category.php @@ -57,9 +57,9 @@ if ($resort and confirm_sesskey()) { if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) { // move it off the range - $count = get_record_sql('SELECT MAX(sortorder) AS max, 1 + $count = get_record_sql('SELECT MIN(sortorder) AS min, 1 FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id); - $count = $count->max + 100; + $count = $count->min; begin_sql(); foreach ($courses as $course) { set_field('course', 'sortorder', $count, 'id', $course->id); diff --git a/lib/datalib.php b/lib/datalib.php index 8deabb7354c..746ee09d1ca 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1343,7 +1343,7 @@ function fix_course_sortorder($categoryid=0, $n=0, $safe=0, $depth=0, $path='') // $mustshift indicates whether the sequence must be shifted to // meet its range $mustshift = false; - if ($min < $n+$tolerance || $min > $n+$tolerance+$catgap ) { + if ($min < $n-$tolerance || $min > $n+$tolerance+$catgap ) { $mustshift = true; }