frontpage == FRONTPAGECOURSELIST) {
+ $catimage = "
";
+ }
+ echo "$catimage wwwroot/course/category.php?id=$category->id\">$category->name";
if ($CFG->frontpage == FRONTPAGECOURSELIST) {
diff --git a/course/search.php b/course/search.php
index b60cd5f6ac3..e97ae12f65f 100644
--- a/course/search.php
+++ b/course/search.php
@@ -6,8 +6,8 @@
require_once("lib.php");
optional_variable($search, ""); // search words
- optional_variable($page, "0"); // which page to show
- optional_variable($perpage, "10"); // which page to show
+ optional_variable($page, "0"); // which page to show
+ optional_variable($perpage, "10"); // how many per page
$search = trim(strip_tags($search));
diff --git a/lib/datalib.php b/lib/datalib.php
index 409956c5e75..53732ec1f7b 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1108,25 +1108,46 @@ function get_site () {
}
-function get_courses($categoryid="all", $sort="sortorder ASC", $fields="*") {
+function get_courses($categoryid="all", $sort="sortorder ASC", $fields="c.*",
+ &$totalcount, $limitfrom="", $limitnum="") {
/// Returns list of courses, for whole site, or category
- if ($categoryid == "all") {
- $courses = get_records("course", "", "", $sort, $fields);
- } else {
- $courses = get_records("course", "category", "$categoryid", $sort, $fields);
+ global $USER, $CFG;
+
+ $categoryselect = "";
+ if ($categoryid != "all") {
+ $categoryselect = "c.category = '$categoryid'";
}
- if ($courses) { /// Remove unavailable courses from the list
- foreach ($courses as $key => $course) {
- if (!$course->visible) {
- if (!isteacher($course->id)) {
- unset($courses[$key]);
- }
- }
+ $teachersonly = "";
+ $teachertable = "";
+ if (!empty($USER)) { // May need to check they are a teacher
+ if (!isadmin()) {
+ $teachersonly = "AND ((c.visible = '1') OR (t.userid = '$USER->id' AND t.course = c.id))";
+ $teachertable = ", {$CFG->prefix}user_teachers t";
}
}
- return $courses;
+
+ if ($limitfrom !== "") {
+ switch ($CFG->dbtype) {
+ case "mysql":
+ $limit = "LIMIT $limitfrom,$limitnum";
+ break;
+ case "postgres7":
+ $limit = "LIMIT $limitnum OFFSET $limitfrom";
+ break;
+ default:
+ $limit = "LIMIT $limitnum,$limitfrom";
+ }
+ } else {
+ $limit = "";
+ }
+
+ $selectsql = "{$CFG->prefix}course c $teachertable WHERE $categoryselect $teachersonly ";
+
+ $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
+
+ return get_records_sql("SELECT $fields FROM $selectsql ORDER BY $sort $limit");
}
diff --git a/lib/weblib.php b/lib/weblib.php
index b2acc194c81..06564935f35 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1618,6 +1618,8 @@ function obfuscate_mailto($email, $label="") {
function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
/// Prints a single paging bar to provide access to other pages (usually in a search)
+ $maxdisplay = 30;
+
if ($totalcount > $perpage) {
echo "".get_string("page").":";
$count = 0;
@@ -1630,7 +1632,7 @@ function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
}
$totalcount -= $perpage;
$count++;
- if ($count > 30) {
+ if ($count > $maxdisplay) {
echo " ...";
break;
}