if ( !defined($In{search_results}) ) {
$html .= eval(q{ ${h2("Search criteria")}});
+
$html .= $form;
} else {
$html .= eval(q{ ${h2("Search results")}});
+
my $fif = new HTML::FillInForm;
$html .= $fif->fill(scalarref => \$form, fdat => \%In);
- my ($where, $from_f, $to_f, $from_b, $to_b) = BackupPC::SearchLib::getWhere(\%In);
-
- my $q = $In{'search_filename'};
-
- # DEBUG
- #$html .= "<small>";
- #$html .= "Filename filter: $q</br>" if ($q);
- #$html .= "Files date limit: $from_f - $to_f</br>" if ($from_f || $to_f);
- #$html .= "Backup date limit: $from_b - $to_b</br>" if ($from_b || $to_b);
- #$html .= "</small>";
-
- $html .= BackupPC::SearchLib::displayGrid( $where, 1, $In{'offset'}, $q);
+ $html .= BackupPC::SearchLib::displayGrid( \%In, 1 );
}
Header( eval("qq{$Lang->{Search_archive}}"), "", 1, "", $html );
return $iso;
}
-sub getWhere($) {
- my ($param) = @_;
- my @conditions;
+sub dates_from_form($) {
+ my $param = shift || return;
sub mk_epoch_date($$) {
my ($name,$suffix) = @_;
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 } );
};
my $sql_where;
+ my $where = getWhere($param);
$sql_where = " WHERE ". $where if ($where);
my $sql_order = qq{
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);