<!-- <% $foo %> -->
<b>Showing <% ($offset + 1) %> through <% ($offset + $limit) %> of <% $found %>.<br>
<a href="<% $uri %>offset=0&limit=<% $limit %>">First</a> |
% if ($offset > 0) {
<a href="<% $uri %>offset=<% $offset - $limit > 0 ? $offset - $limit : 0 %>&limit=<% $limit %>">Previous <% $limit %></a> |
% }
% if ($offset + $limit < $found) {
<a href="<% $uri %>offset=<% $offset + $limit %>&limit=<% $limit %>">Next <% $limit %></a> |
% }
<a href="<% $uri %>offset=<% $lastoff %>&limit=<% $limit %>">Last</a> |
<a href="<% $uri %>offset=0&limit=<% $found %>">All</a> <p> 

<%args>
$rooturi
$limit
$offset
$found
</%args>

<%init>
# Constructs an HTML snippet that can be used for paging through large result
# lists.  It's up to the calling code to ensure that $limit, $offset and $found
# are known and compatible.

if (ref($limit)) {
    $limit = $limit->[-1];      # got two limits (from user-entered), pick last one
}
my $foo = "rooturi=$rooturi limit=$limit offset=$offset found=$found";

my $uri;
my $formuri;
if (!$rooturi) {
    # If empty, start with '?', otherwise concat with '&'.
    $uri = "?found=$found&";
}
else {
    $uri = "$rooturi&found=$found&";
}

my $lastoff = $found - $limit;
if ($lastoff < 0) {
    $lastoff = 0;
}

if ($offset + $limit > $found) {
    $limit = $found - $offset;
}

</%init>

