diff --git a/course/search.php b/course/search.php index bfe4d8d93c6..7845486e2bd 100644 --- a/course/search.php +++ b/course/search.php @@ -146,23 +146,22 @@ // get list of courses containing modules if required elseif (!empty($modulelist) and confirm_sesskey()) { $modulename = $modulelist; - if (!$modules = get_records($modulename)) { - error( "Could not read data for module=$modulename" ); - } - // run through modules and get (unique) courses - $courses = array(); - foreach ($modules as $module) { - $courseid = $module->course; - if ($courseid==0) { - continue; + $sql = "SELECT DISTINCT c.id FROM {$CFG->prefix}".$modulelist." module,{$CFG->prefix}course as c" + ." WHERE module.course=c.id"; + + $courseids = get_records_sql($sql); + + $firstcourse = $page*$perpage; + $lastcourse = $page*$perpage + $perpage -1; + $i = 0; + foreach ($courseids as $courseid) { + if ($i>= $firstcourse && $i<=$lastcourse) { + $courses[$courseid->id] = get_record('course', 'id', $courseid->id); } - if (!$course = get_record('course', 'id', $courseid)) { - error( "Could not read data for courseid=$courseid" ); - } - $courses[$courseid] = $course; + $i++; } - $totalcount = count($courses); + $totalcount = count($courseids); } else { $courses = get_courses_search($searchterms, "fullname ASC", @@ -190,11 +189,18 @@ print_heading("$strsearchresults: $totalcount"); $encodedsearch = urlencode(stripslashes($search)); - print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); + + ///add the module parameter to the paging bar if they exists + $modulelink = ""; + if (!empty($modulelist) and confirm_sesskey()) { + $modulelink = "&modulelist=".$modulelist."&sesskey=".$USER->sesskey; + } + + print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch".$modulelink."&perpage=$perpage&",'page',($perpage == 99999)); if ($perpage != 99999 && $totalcount > $perpage) { echo "

"; - echo "".get_string("showall", "", $totalcount).""; + echo "".get_string("showall", "", $totalcount).""; echo "

"; }