--- trunk/lib/BackupPC/SearchLib.pm 2005/08/26 23:50:05 80 +++ trunk/lib/BackupPC/SearchLib.pm 2005/08/28 10:14:48 83 @@ -37,9 +37,8 @@ return $iso; } -sub getWhere($) { - my ($param) = @_; - my @conditions; +sub dates_from_form($) { + my $param = shift || return; sub mk_epoch_date($$) { my ($name,$suffix) = @_; @@ -57,32 +56,37 @@ return $dt->epoch || 'NULL'; } - my $backup_from = mk_epoch_date('search_backup', 'from'); + return ( + mk_epoch_date('search_backup', 'from'), + mk_epoch_date('search_backup', 'to'), + mk_epoch_date('search', 'from'), + mk_epoch_date('search', 'to'), + ); +} + + +sub getWhere($) { + my $param = shift || return; + + my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param); + + my @conditions; push @conditions, qq{ backups.date >= $backup_from } if ($backup_from); - my $backup_to = mk_epoch_date('search_backup', 'to'); push @conditions, qq{ backups.date <= $backup_to } if ($backup_to); - - my $files_from = mk_epoch_date('search', 'from'); push @conditions, qq{ files.date >= $files_from } if ($files_from); - my $files_to = mk_epoch_date('search', 'to'); push @conditions, qq{ files.date <= $files_to } if ($files_to); print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions); - - push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'}); + push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'}); push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); - return ( - join(" and ", @conditions), - $files_from, $files_to, - $backup_from, $backup_to - ); + return join(" and ", @conditions); } sub getFiles($$) { - my ($where, $offset) = @_; + my ($param, $offset) = @_; my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); @@ -113,6 +117,7 @@ }; my $sql_where; + my $where = getWhere($param); $sql_where = " WHERE ". $where if ($where); my $sql_order = qq{ @@ -289,13 +294,17 @@ return $retHTML; } -sub displayGrid($$$$) { - my ($where, $addForm, $offset, $hilite) = @_; +sub displayGrid($$) { + my ($param, $addForm) = @_; + + my $offset = $param->{'offset'}; + my $hilite = $param->{'search_filename'}; + my $retHTML = ""; my $start_t = time(); - my ($results, $files) = getFiles($where, $offset); + my ($results, $files) = getFiles($param, $offset); my $dur_t = time() - $start_t; my $dur = sprintf("%0.4fs", $dur_t);