37 |
return $iso; |
return $iso; |
38 |
} |
} |
39 |
|
|
40 |
sub getWhere($) { |
sub dates_from_form($) { |
41 |
my ($param) = @_; |
my $param = shift || return; |
|
my @conditions; |
|
42 |
|
|
43 |
sub mk_epoch_date($$) { |
sub mk_epoch_date($$) { |
44 |
my ($name,$suffix) = @_; |
my ($name,$suffix) = @_; |
56 |
return $dt->epoch || 'NULL'; |
return $dt->epoch || 'NULL'; |
57 |
} |
} |
58 |
|
|
59 |
my $backup_from = mk_epoch_date('search_backup', 'from'); |
return ( |
60 |
|
mk_epoch_date('search_backup', 'from'), |
61 |
|
mk_epoch_date('search_backup', 'to'), |
62 |
|
mk_epoch_date('search', 'from'), |
63 |
|
mk_epoch_date('search', 'to'), |
64 |
|
); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
sub getWhere($) { |
69 |
|
my $param = shift || return; |
70 |
|
|
71 |
|
my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param); |
72 |
|
|
73 |
|
my @conditions; |
74 |
push @conditions, qq{ backups.date >= $backup_from } if ($backup_from); |
push @conditions, qq{ backups.date >= $backup_from } if ($backup_from); |
|
my $backup_to = mk_epoch_date('search_backup', 'to'); |
|
75 |
push @conditions, qq{ backups.date <= $backup_to } if ($backup_to); |
push @conditions, qq{ backups.date <= $backup_to } if ($backup_to); |
|
|
|
|
my $files_from = mk_epoch_date('search', 'from'); |
|
76 |
push @conditions, qq{ files.date >= $files_from } if ($files_from); |
push @conditions, qq{ files.date >= $files_from } if ($files_from); |
|
my $files_to = mk_epoch_date('search', 'to'); |
|
77 |
push @conditions, qq{ files.date <= $files_to } if ($files_to); |
push @conditions, qq{ files.date <= $files_to } if ($files_to); |
78 |
|
|
79 |
print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions); |
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'}); |
|
80 |
|
|
81 |
|
push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'}); |
82 |
push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); |
push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); |
83 |
|
|
84 |
return ( |
return join(" and ", @conditions); |
|
join(" and ", @conditions), |
|
|
$files_from, $files_to, |
|
|
$backup_from, $backup_to |
|
|
); |
|
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
sub getFiles($$) { |
sub getFiles($$) { |
89 |
my ($where, $offset) = @_; |
my ($param, $offset) = @_; |
90 |
|
|
91 |
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
92 |
|
|
117 |
}; |
}; |
118 |
|
|
119 |
my $sql_where; |
my $sql_where; |
120 |
|
my $where = getWhere($param); |
121 |
$sql_where = " WHERE ". $where if ($where); |
$sql_where = " WHERE ". $where if ($where); |
122 |
|
|
123 |
my $sql_order = qq{ |
my $sql_order = qq{ |
294 |
return $retHTML; |
return $retHTML; |
295 |
} |
} |
296 |
|
|
297 |
sub displayGrid($$$$) { |
sub displayGrid($$) { |
298 |
my ($where, $addForm, $offset, $hilite) = @_; |
my ($param, $addForm) = @_; |
299 |
|
|
300 |
|
my $offset = $param->{'offset'}; |
301 |
|
my $hilite = $param->{'search_filename'}; |
302 |
|
|
303 |
my $retHTML = ""; |
my $retHTML = ""; |
304 |
|
|
305 |
my $start_t = time(); |
my $start_t = time(); |
306 |
|
|
307 |
my ($results, $files) = getFiles($where, $offset); |
my ($results, $files) = getFiles($param, $offset); |
308 |
|
|
309 |
my $dur_t = time() - $start_t; |
my $dur_t = time() - $start_t; |
310 |
my $dur = sprintf("%0.4fs", $dur_t); |
my $dur = sprintf("%0.4fs", $dur_t); |