From 35776c791090f4271ba6ced72fb089eb1551a0ec Mon Sep 17 00:00:00 2001 From: dpavlin Date: Thu, 23 Jun 2005 12:36:22 +0000 Subject: [PATCH] experimental pager support in search git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@9 8392b6e1-25fa-0310-8288-cc32f8e212ea --- conf/config.pl | 2 +- lib/BackupPC/CGI/SearchArchives.pm | 2 +- lib/BackupPC/SearchLib.pm | 93 +++++++++++++----------------- 3 files changed, 42 insertions(+), 55 deletions(-) diff --git a/conf/config.pl b/conf/config.pl index bfbc498..76be330 100644 --- a/conf/config.pl +++ b/conf/config.pl @@ -1745,4 +1745,4 @@ $Conf{CgiCSSFile} = 'BackupPC_stnd.css'; # # add search database using DBD::SQLite which will be created in $TopDir # -$Conf{SearchDB} = "search.db"; +$Conf{SearchDB} = 'search.db'; diff --git a/lib/BackupPC/CGI/SearchArchives.pm b/lib/BackupPC/CGI/SearchArchives.pm index 2ecb773..5506572 100644 --- a/lib/BackupPC/CGI/SearchArchives.pm +++ b/lib/BackupPC/CGI/SearchArchives.pm @@ -155,7 +155,7 @@ ENDSTR my $result; my $rows = ""; - my $grid = BackupPC::SearchLib::displayGrid( BackupPC::SearchLib::getWhere(\%In), 0); + my $grid = BackupPC::SearchLib::displayGrid( BackupPC::SearchLib::getWhere(\%In), 1, $In{'offset'}); $cont .= $grid; } Header( eval("qq{$Lang->{Search_archive}}"), "", 1, "", $cont ); diff --git a/lib/BackupPC/SearchLib.pm b/lib/BackupPC/SearchLib.pm index a18a446..4260839 100644 --- a/lib/BackupPC/SearchLib.pm +++ b/lib/BackupPC/SearchLib.pm @@ -117,9 +117,10 @@ sub getWhere($) { return $retSQL; } -sub getFiles($) +sub getFiles($$) { - my ($where) = @_; + my ($where, $offset) = @_; + my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}", "", "", { RaiseError => 1, AutoCommit => 1 } ); @@ -143,7 +144,7 @@ sub getFiles($) INNER JOIN hosts ON hosts.ID = shares.hostID INNER JOIN backups ON backups.hostID = hosts.ID LEFT JOIN dvds ON dvds.ID = files.dvdid - + }; if (defined($where) && $where ne "") @@ -151,11 +152,26 @@ sub getFiles($) $sql .= " WHERE ". $where; } + $sql .= + q{ + ORDER BY files.id + LIMIT 100 + OFFSET ? * 100 + 1 + }; + + my $st = $dbh->prepare( $sql ); - + if (!defined($offset) && $offset ne "") + { + $st->bind_param(1, $offset); + } + else + { + $st->bind_param(1,0); + } $st->execute; my @ret = (); @@ -307,59 +323,23 @@ EOF3 } -sub displayGrid($$) +sub displayGrid($$$) { - my ($where, $addForm) = @_; + my ($where, $addForm, $offset) = @_; my $retHTML = ""; if ($addForm) { - $retHTML .= < - - -EOF3 - $retHTML .= q{
}; + $retHTML .= q{}; $retHTML .= q{}; } $retHTML .= ""; $retHTML .= " "; - if ($addForm) - { - $retHTML .= ""; - } $retHTML .= ""; - my @files = getFiles($where); + my @files = getFiles($where, $offset); my $file; - if ($addForm) - { - $retHTML .= ""; - $retHTML .= ""; - $retHTML .= ""; - - } foreach $file(@files) { my $ftype = ""; @@ -373,13 +353,6 @@ EOF3 $ftype = "file"; } $retHTML .= ""; - if ($addForm) - { - $retHTML .= ""; - } - $retHTML .= ""; $retHTML .= ""; $retHTML .= ""; @@ -390,7 +363,21 @@ EOF3 $retHTML .= ""; } $retHTML .= "
Host Name Type backup no. size date Media
"; - $retHTML .= ""; - $retHTML .= "
{'id'} - ."\" value=\"".$file->{'id'}."\"> " . $file->{'hname'} ."" . $file->{'fname'} . "" . $ftype . "
"; - if ($addForm) + + + + $retHTML .= ""; + for (my $ii = 1; $ii <= $#files; $ii++) + { + $retHTML .= "$ii"; + if ($ii < $#files) + { + $retHTML .= " | "; + } + } + + + if ($addForm) { $retHTML .= "
"; } -- 2.20.1