diff --git a/course/category.php b/course/category.php
index e9df6bc411b..b74127a7655 100644
--- a/course/category.php
+++ b/course/category.php
@@ -213,14 +213,12 @@
/// Print out all the courses
- if (!$courses = get_courses($category->id, "c.sortorder ASC", "c.*", $totalcount, $page*$perpage, $perpage)) {
+ if (!$courses = get_course_pages($category->id, "c.sortorder ASC", "c.*", $totalcount, $page*$perpage, $perpage)) {
print_heading(get_string("nocoursesyet"));
} else {
- echo "
";
print_paging_bar($totalcount, $page, $perpage, "category.php?id=$category->id&perpage=$perpage&");
- echo "";
$strcourses = get_string("courses");
$strselect = get_string("select");
diff --git a/course/search.php b/course/search.php
index e97ae12f65f..5dd76458c46 100644
--- a/course/search.php
+++ b/course/search.php
@@ -66,9 +66,7 @@
print_heading("$strsearchresults: $totalcount");
- echo "";
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&perpage=$perpage&");
- echo "";
foreach ($courses as $course) {
$course->fullname = highlight("$search", $course->fullname);
@@ -81,9 +79,7 @@
print_spacer(5,5);
}
- echo "";
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&perpage=$perpage&");
- echo "";
} else {
print_heading(get_string("nocoursesfound", "", $search));
diff --git a/lib/datalib.php b/lib/datalib.php
index 209544efaa8..569ba3bf939 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1108,8 +1108,7 @@ function get_site () {
}
-function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
- &$totalcount, $limitfrom="", $limitnum="") {
+function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*") {
/// Returns list of courses, for whole site, or category
global $USER, $CFG;
@@ -1132,6 +1131,37 @@ 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";
+
+ return get_records_sql("SELECT $fields FROM $selectsql $teachergroup ORDER BY $sort");
+}
+
+
+function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
+ &$totalcount, $limitfrom="", $limitnum="") {
+/// Returns list of courses, for whole site, or category
+/// Similar to get_courses, but allows paging
+
+ global $USER, $CFG;
+
+ $categoryselect = "";
+ if ($categoryid != "all") {
+ $categoryselect = "c.category = '$categoryid'";
+ }
+
+ $teachertable = "";
+ $teachergroup = "";
+ $visiblecourses = "";
+ if (!empty($USER)) { // May need to check they are a teacher
+ if (!isadmin()) {
+ $visiblecourses = "AND ((c.visible > 0) OR (t.userid = '$USER->id' AND t.course = c.id))";
+ $teachertable = ", {$CFG->prefix}user_teachers t";
+ $teachergroup = "GROUP BY c.id";
+ }
+ } else {
+ $visiblecourses = "AND c.visible > 0";
+ }
+
if ($limitfrom !== "") {
switch ($CFG->dbtype) {
case "mysql":