From d0b7da6966945806d4e5e9f44a0699249b7fb90f Mon Sep 17 00:00:00 2001 From: jerome Date: Fri, 7 Nov 2008 05:34:42 +0000 Subject: [PATCH] MDL-13987: fix navigation links for Activities Administration page, merged from 19 --- course/search.php | 66 ++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/course/search.php b/course/search.php index ffc0ca31fc..bc9f3c1dcd 100644 --- a/course/search.php +++ b/course/search.php @@ -146,23 +146,21 @@ // get list of courses containing modules if required elseif (!empty($modulelist) and confirm_sesskey()) { $modulename = $modulelist; - if (!$modules = $DB->get_records($modulename)) { - print_error('invalidmodulename', '', '', $modulename); - } + $sql = "SELECT DISTINCT c.id FROM {$CFG->prefix}".$modulelist." module,{$CFG->prefix}course as c" + ." WHERE module.course=c.id"; - // run through modules and get (unique) courses - $courses = array(); - foreach ($modules as $module) { - $courseid = $module->course; - if ($courseid==0) { - continue; - } - if (!$course = $DB->get_record('course', array('id'=>$courseid))) { - print_error('invalidcourseid', '', '', $courseid); + $courseids = $DB->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] = $DB->get_record('course', array('id'=> $courseid->id)); } - $courses[$courseid] = $course; + $i++; } - $totalcount = count($courses); + $totalcount = count($courseids); } else { $courses = get_courses_search($searchterms, "fullname ASC", @@ -190,13 +188,14 @@ print_heading("$strsearchresults: $totalcount"); $encodedsearch = urlencode($search); - print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); - - if ($perpage != 99999 && $totalcount > $perpage) { - echo "

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

"; + + ///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_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink); if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { foreach ($courses as $course) { @@ -317,13 +316,7 @@ } - print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999)); - - if ($perpage != 99999 && $totalcount > $perpage) { - echo "

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

"; - } + print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink); } else { if (!empty($search)) { @@ -340,5 +333,24 @@ print_footer(); + /** + * Print a list navigation bar + * Display page numbers, and a link for displaying all entries + * @param integer $totalcount - number of entry to display + * @param integer $page - page number + * @param integer $perpage - number of entry per page + * @param string $encodedsearch + * @param string $modulelink - module name + */ + function print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink) { + print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch".$modulelink."&perpage=$perpage&",'page',($perpage == 99999)); + + //display + if ($perpage != 99999 && $totalcount > $perpage) { + echo "

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

"; + } + } ?> -- 2.39.5