16 |
my $db_user = $Conf{SearchUser} || ''; |
my $db_user = $Conf{SearchUser} || ''; |
17 |
|
|
18 |
sub getUnits() { |
sub getUnits() { |
19 |
my @ret = (); |
my @ret; |
20 |
my $tmp; |
|
21 |
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
22 |
my $st = |
my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares} ); |
23 |
$dbh->prepare( |
$sth->execute(); |
24 |
" SELECT shares.ID AS ID, shares.share AS name FROM shares;"); |
push @ret, { 'id' => '', 'share' => '-'}; # dummy any |
25 |
$st->execute(); |
|
26 |
push (@ret, { 'ID' => '', 'name' => '-'}); |
while ( my $row = $sth->fetchrow_hashref() ) { |
27 |
while ( $tmp = $st->fetchrow_hashref() ) { |
push @ret, $row; |
28 |
push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } ); |
} |
29 |
} |
$dbh->disconnect(); |
30 |
$dbh->disconnect(); |
return @ret; |
|
return @ret; |
|
31 |
} |
} |
32 |
|
|
33 |
sub epoch_to_iso { |
sub epoch_to_iso { |
34 |
my $t = shift || return; |
my $t = shift || return; |
35 |
my $dt = DateTime->from_epoch( epoch => $t ) || return; |
my $dt = DateTime->from_epoch( epoch => $t ) || return; |
36 |
print STDERR "$t == ",$dt->epoch,"\n"; |
print STDERR "BUG: $t != " . $dt->epoch . "\n" unless ($t == $dt->epoch); |
37 |
return $dt->ymd . ' ' . $dt->hms; |
return $dt->ymd . ' ' . $dt->hms; |
38 |
} |
} |
39 |
|
|
67 |
my $files_to = mk_epoch_date('search', 'to'); |
my $files_to = mk_epoch_date('search', 'to'); |
68 |
push @conditions, qq{ files.date <= $files_to } if ($files_to); |
push @conditions, qq{ files.date <= $files_to } if ($files_to); |
69 |
|
|
70 |
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); |
71 |
|
|
72 |
push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'}); |
push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'}); |
73 |
|
|
74 |
push (@conditions, " upper(files.name) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); |
push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); |
75 |
|
|
76 |
return ( |
return ( |
77 |
join(" and ", @conditions), |
join(" and ", @conditions), |
94 |
files.backupNum AS backupNum, |
files.backupNum AS backupNum, |
95 |
files.name AS filename, |
files.name AS filename, |
96 |
files.path AS filepath, |
files.path AS filepath, |
|
shares.share||files.fullpath AS networkPath, |
|
97 |
files.date AS date, |
files.date AS date, |
98 |
files.type AS filetype, |
files.type AS filetype, |
99 |
files.size AS size, |
files.size AS size, |
|
}; |
|
|
|
|
|
my $sql_dvd_cols = qq{ |
|
100 |
dvds.name AS dvd |
dvds.name AS dvd |
101 |
}; |
}; |
102 |
|
|
116 |
|
|
117 |
my $sql_order = qq{ |
my $sql_order = qq{ |
118 |
ORDER BY files.id |
ORDER BY files.id |
119 |
LIMIT $on_page |
LIMIT $on_page |
120 |
OFFSET ? |
OFFSET ? |
121 |
}; |
}; |
122 |
|
|
123 |
|
my $sql_count = qq{ select count(files.id) $sql_from $sql_where }; |
124 |
|
my $sql_results = qq{ select $sql_cols $sql_from $sql_dvd_from $sql_where $sql_order }; |
125 |
|
|
126 |
$offset ||= 0; |
$offset ||= 0; |
127 |
$offset = ($offset * $on_page) + 1; |
$offset = ($offset * $on_page); |
128 |
|
|
129 |
my $sth = $dbh->prepare(qq{ select count(files.id) $sql_from $sql_where }); |
my $sth = $dbh->prepare($sql_count); |
130 |
$sth->execute(); |
$sth->execute(); |
|
|
|
131 |
my ($results) = $sth->fetchrow_array(); |
my ($results) = $sth->fetchrow_array(); |
132 |
|
|
133 |
$sth = $dbh->prepare(qq{ select $sql_cols $sql_dvd_cols $sql_from $sql_dvd_from $sql_where $sql_order }); |
$sth = $dbh->prepare($sql_results); |
134 |
$sth->execute( $offset ); |
$sth->execute( $offset ); |
135 |
|
|
136 |
|
if ($sth->rows != $results) { |
137 |
|
my $bug = "$0 BUG: [[ $sql_count ]] = $results while [[ $sql_results ]] = " . $sth->rows; |
138 |
|
$bug =~ s/\s+/ /gs; |
139 |
|
print STDERR "$bug\n"; |
140 |
|
} |
141 |
|
|
142 |
my @ret; |
my @ret; |
143 |
|
|
144 |
while (my $row = $sth->fetchrow_hashref()) { |
while (my $row = $sth->fetchrow_hashref()) { |
157 |
'dvd' => $row->{'dvd'} |
'dvd' => $row->{'dvd'} |
158 |
}); |
}); |
159 |
} |
} |
160 |
|
|
161 |
$sth->finish(); |
$sth->finish(); |
162 |
$dbh->disconnect(); |
$dbh->disconnect(); |
163 |
return ($results, \@ret); |
return ($results, \@ret); |
293 |
my ($where, $addForm, $offset, $hilite) = @_; |
my ($where, $addForm, $offset, $hilite) = @_; |
294 |
my $retHTML = ""; |
my $retHTML = ""; |
295 |
|
|
|
if ($addForm) { |
|
|
$retHTML .= qq{<form name="forma" method="GET" action="$MyURL">}; |
|
|
$retHTML.= qq{<input type="hidden" value="search" name="action">}; |
|
|
$retHTML .= qq{<input type="hidden" value="results" name="search_results">}; |
|
|
} |
|
|
|
|
296 |
my $start_t = time(); |
my $start_t = time(); |
297 |
|
|
298 |
my ($results, $files) = getFiles($where, $offset); |
my ($results, $files) = getFiles($where, $offset); |
302 |
|
|
303 |
my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page); |
my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page); |
304 |
|
|
305 |
|
if ($results <= 0) { |
306 |
|
$retHTML .= qq{ |
307 |
|
<p style="color: red;">No results found...</p> |
308 |
|
}; |
309 |
|
return $retHTML; |
310 |
|
} else { |
311 |
|
# DEBUG |
312 |
|
#use Data::Dumper; |
313 |
|
#$retHTML .= '<pre>' . Dumper($files) . '</pre>'; |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
if ($addForm) { |
318 |
|
$retHTML .= qq{<form name="forma" method="GET" action="$MyURL">}; |
319 |
|
$retHTML.= qq{<input type="hidden" value="search" name="action">}; |
320 |
|
$retHTML .= qq{<input type="hidden" value="results" name="search_results">}; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
$retHTML .= qq{ |
$retHTML .= qq{ |
325 |
<br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur) |
<br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur) |
326 |
<table style="fview" width="100%"> |
<table style="fview" width="100%"> |