combine ticket notification scrips, #15353
[freeside.git] / httemplate / elements / pager.html
1 % my %opt = @_;
2 % my $pager = '';
3 %
4 % if ( $opt{'total'} != $opt{'num_rows'} && $opt{'maxrecords'} ) {
5 %
6 %   unless ( $opt{'offset'} == 0 ) {
7 %     $cgi->param('offset', $opt{'offset'} - $opt{'maxrecords'});
8
9       <A HREF="<% $cgi->self_url %>"><B><FONT SIZE="+1">Previous</FONT></B></A>
10
11 %   }
12 %
13 %   my $page = 0;
14 %   my $prevpage = 0;
15 %   my $over = 0;
16 %   my $step = $opt{total} / 10; # 10 evenly spaced
17 %   for ( my $poff = 0; $poff < $opt{total}; $poff += $opt{maxrecords} ) {
18 %     $page++;
19 %       
20 %     next unless
21 %          $page <= 4                                          #first four
22 %       || $page >= ( $opt{total} / $opt{maxrecords} ) - 3     #last four
23 %       || abs( ($opt{offset}-$poff) / $opt{maxrecords} ) <= 3 #w/i 3 of current
24 %       || $poff > $over                                       # evenly spaced
25 %     ;           
26 %
27 %     $over += $step if $poff > $over;
28 %
29 %     if ( $opt{'offset'} == $poff ) {
30
31         <FONT SIZE="+2"><% $page %></FONT>
32
33 %     } else {
34 %       $cgi->param('offset', $poff);
35 %
36 %       if ( $page > $prevpage+1 ) {
37           ...
38 %       }
39
40         <A HREF="<% $cgi->self_url %>"><% $page %></A>
41
42 %     }
43 %
44 %     $prevpage = $page;
45 %
46 %   }
47 %
48 %   unless ( $opt{'offset'} + $opt{'maxrecords'} > $opt{'total'} ) {
49 %     $cgi->param('offset', $opt{'offset'} + $opt{'maxrecords'});
50
51       <A HREF="<% $cgi->self_url %>"><B><FONT SIZE="+1">Next</FONT></B></A>
52 %
53 %   }
54 %
55 % }