--- trunk/lib/BackupPC/SearchLib.pm 2005/08/26 23:37:10 79 +++ 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{ @@ -231,7 +236,7 @@ $retHTML .= q{}; } $retHTML .= qq{ -
} . $file->{'sharename'} . qq{ | } . - qq{} . hilite_html( $file->{'fpath'}, $hilite ) . qq{ | } . + qq{} . hilite_html( $file->{'fpath'}, $hilite ) . qq{ | } . qq{} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupno'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'fpath'} )}, $file->{'backupno'} ) . qq{ | } . qq{} . $file->{'size'} . qq{ | } . qq{} . epoch_to_iso( $file->{'date'} ) . qq{ | } .