require_once("lib.php");
require_variable($id); // Category id
+ optional_variable($page, "0"); // which page to show
+ optional_variable($perpage, "20"); // how many per page
if (!$site = get_site()) {
/// Print out all the courses
- if (!$courses = get_courses($category->id)) {
+ if (!$courses = get_courses($category->id, "sortorder ASC", "c.*", $totalcount, $page*$perpage, $perpage)) {
print_heading(get_string("nocoursesyet"));
} else {
+ echo "<center>";
+ print_paging_bar($totalcount, $page, $perpage, "category.php?id=$category->id&perpage=$perpage&");
+ echo "</center>";
+
$strcourses = get_string("courses");
$strselect = get_string("select");
$stredit = get_string("edit");
for ($i=0; $i<$depth;$i++) {
echo "<ul style=\"margin-bottom:0;margin-top:0\">";
}
- echo "<font size=+1><a $catlinkcss ".
+
+ $catimage = "";
+ if ($CFG->frontpage == FRONTPAGECOURSELIST) {
+ $catimage = "<img src=\"$pixpath/i/course.gif\ width=16 height=16 border=0>";
+ }
+ echo "<font size=+1>$catimage <a $catlinkcss ".
"href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a></font>";
if ($CFG->frontpage == FRONTPAGECOURSELIST) {
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));
}
-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");
}
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 "<p>".get_string("page").":";
$count = 0;
}
$totalcount -= $perpage;
$count++;
- if ($count > 30) {
+ if ($count > $maxdisplay) {
echo " ...";
break;
}