]> git.mjollnir.org Git - moodle.git/commitdiff
Some better paging that now works with any number of pages
authormoodler <moodler>
Thu, 21 Aug 2003 13:47:14 +0000 (13:47 +0000)
committermoodler <moodler>
Thu, 21 Aug 2003 13:47:14 +0000 (13:47 +0000)
lib/weblib.php

index 06564935f359d927eea64f8ce019e54e77000c34..91dd2f0e09570d1904d9c1ba1805d0c706119627 100644 (file)
@@ -1618,30 +1618,35 @@ 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;
+    $maxdisplay = 20;
 
     if ($totalcount > $perpage) {
+        $lastpage = ceil($totalcount / $perpage);
+        if ($page > 15) {
+            $startpage = $page - 10;
+        } else {
+            $startpage = 0;
+        }
+        echo "<center>";
         echo "<p>".get_string("page").":";
-        $count = 0;
-        while ($totalcount > 0) {
-            $displaypage = $count+1;
-            if ($page == $count) {
+        $currpage = $startpage;
+        $displaycount = 0;
+        while ($displaycount < $maxdisplay and $currpage < $lastpage) {
+            $displaypage = $currpage+1;
+            if ($page == $currpage) {
                 echo "&nbsp;&nbsp;$displaypage";
             } else {
-                echo "&nbsp;&nbsp;<a href=\"{$baseurl}page=$count\">$displaypage</a>";
-            }
-            $totalcount -= $perpage;
-            $count++;
-            if ($count > $maxdisplay) {
-                echo "&nbsp;...";
-                break;
+                echo "&nbsp;&nbsp;<a href=\"{$baseurl}page=$currpage\">$displaypage</a>";
             }
+            $displaycount++;
+            $currpage++;
         }
         $pagenum = $page + 1;
-        if ($pagenum != $count) {
+        if ($pagenum != $displaypage) {
             echo "&nbsp;&nbsp;(<a href=\"{$baseurl}page=$pagenum\">".get_string("next")."</a>)";
         }
         echo "</p>";
+        echo "</center>";
     }
 }