Index: my/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/my/index.php,v
retrieving revision 1.16.2.5
diff -u -r1.16.2.5 index.php
--- my/index.php	7 Apr 2009 07:46:25 -0000	1.16.2.5
+++ my/index.php	15 Apr 2009 07:08:39 -0000
@@ -26,6 +26,7 @@
 
 
     $edit        = optional_param('edit', -1, PARAM_BOOL);
+    $all         = optional_param('all',  0,  PARAM_BOOL);
     $blockaction = optional_param('blockaction', '', PARAM_ALPHA);
 
     $PAGE = page_create_instance($USER->id);
@@ -63,23 +64,39 @@
     print_container_start(TRUE);
 
 /// The main overview in the middle of the page
-    $courses_limit = 21;
-    if (!empty($CFG->mycoursesperpage)) {
-        $courses_limit = $CFG->mycoursesperpage;
-    }
-    $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
-    $site = get_site();
-    $course = $site; //just in case we need the old global $course hack
+    if ($CFG->mycoursesperpage === '0' && empty($all)) {
+        // that means shouldn't display any courses here
+        $courses = array();
+        // make $total always bigger than count($courses)
+        // a "show all link" will be shown at the bottom
+        $total = 1;
+    } else {
+        if (!empty($CFG->mycoursesperpage) && empty($all)) {
+            $courses_limit = $CFG->mycoursesperpage;
+        }
+        $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false);
 
-    if (array_key_exists($site->id,$courses)) {
-        unset($courses[$site->id]);
-    }
+        $site = get_site();
+        $course = $site; //just in case we need the old global $course hack
 
-    foreach ($courses as $c) {
-        if (isset($USER->lastcourseaccess[$c->id])) {
-            $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
-        } else {
-            $courses[$c->id]->lastaccess = 0;
+        if (array_key_exists($site->id,$courses)) {
+            unset($courses[$site->id]);
+        }
+
+        $total = count($courses);
+        $count = 0;
+        foreach ($courses as $n=>$c) {
+            $count++;
+            if (($count >= ($total - $courses_limit)) && empty($all)) {
+                unset($courses[$n]);
+                $count++;
+                continue;
+            }
+            if (isset($USER->lastcourseaccess[$c->id])) {
+                $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
+            } else {
+                $courses[$c->id]->lastaccess = 0;
+            }
         }
     }
     
@@ -89,9 +106,13 @@
         print_overview($courses);
     }
     
-    // if more than 20 courses
-    if (count($courses) > 20) {
-        echo '<br />...';  
+    // if more than number of courses limit
+    if ($total >= count($courses)) {
+        if (empty($all)) {
+            echo '<a href="index.php?all=1">'.get_string('showall', 'my').'</a>';
+        } else {
+            echo '<a href="index.php">'.get_string('showcourses', 'my', $CFG->mycoursesperpage);
+        }
     }
     
     print_container_end();
