summaryrefslogtreecommitdiff
path: root/index.cgi
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-05-28 11:14:56 +0200
committerYorhel <git@yorhel.nl>2016-05-28 11:14:56 +0200
commitd8822b4f11cf8329f556baa2c39449674342afb6 (patch)
tree03d0d51bc9080bf8f324be61772d845e4989c405 /index.cgi
parentf279dd3b87ba14ce82091de46f379f7f16d9e2b9 (diff)
Add pagination to "my pastes" listing
Diffstat (limited to 'index.cgi')
-rwxr-xr-xindex.cgi21
1 files changed, 15 insertions, 6 deletions
diff --git a/index.cgi b/index.cgi
index b75f9ea..bea8ef2 100755
--- a/index.cgi
+++ b/index.cgi
@@ -4,7 +4,7 @@
use strict;
use warnings;
-use POSIX 'strftime';
+use POSIX 'strftime', 'ceil';
use TUWF ':html', 'html_escape';
@@ -116,15 +116,15 @@ sub home {
sub mypastes {
my $self = shift;
my $p = $self->passcode('pc','psp');
+ my $f = $self->formValidate({ post => 'p', required => 0, template => 'uint', min => 1, max => 100, default => 1});
+ return $self->msg('Invalid passcode or page number') if !$p || $f->{_err};
- my $pl = $self->dbAll(q|
+ my($pl) = $self->dbPage({page => $f->{p}, results => 100}, q|
SELECT code, date, syntax, substr(raw, 1, 150) AS preview, length(raw) AS size
- FROM pastes
- WHERE passcode = ?
- ORDER BY date DESC|,
- $p
+ FROM pastes WHERE passcode = ? ORDER BY date DESC|, $p
);
return $self->msg('No pastes with that passcode!') if !@$pl;
+ my $cnt = ceil($self->dbRow('SELECT count(*) AS cnt FROM pastes WHERE passcode = ?', $p)->{cnt} / 100);
$self->htmlHeader('mypastes', 'newpaste');
Tr;
@@ -143,6 +143,15 @@ sub mypastes {
end;
}
end;
+ if($f->{p} > 1 || $cnt > 1) {
+ form method => 'POST', action => '/mypastes', class => 'pagination';
+ input type => 'hidden', name => 'pc', value => $p;
+ b 'Page: ';
+ input type => 'submit', name => 'p', value => $_ for (1..($f->{p} - 1));
+ txt " $f->{p} ";
+ input type => 'submit', name => 'p', value => $_ for(($f->{p}+1)..$cnt);
+ end;
+ }
end;
end 'tr';
$self->htmlFooter;