4 |
use strict; |
use strict; |
5 |
use BackupPC::CGI::Lib qw(:all); |
use BackupPC::CGI::Lib qw(:all); |
6 |
use BackupPC::Attrib qw(:all); |
use BackupPC::Attrib qw(:all); |
|
use Data::Dumper; |
|
7 |
use DBI; |
use DBI; |
8 |
|
use DateTime; |
9 |
|
use vars qw(%In $MyURL); |
10 |
|
use Time::HiRes qw/time/; |
11 |
|
|
12 |
|
my $on_page = 100; |
13 |
|
my $pager_pages = 10; |
14 |
|
|
15 |
|
my $dsn = $Conf{SearchDSN}; |
16 |
|
my $db_user = $Conf{SearchUser} || ''; |
17 |
|
|
18 |
sub getUnits() { |
sub getUnits() { |
19 |
my @ret = (); |
my @ret = (); |
20 |
my $tmp; |
my $tmp; |
21 |
my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}", |
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
|
"", "", { RaiseError => 1, AutoCommit => 1 } ); |
|
22 |
my $st = |
my $st = |
23 |
$dbh->prepare( |
$dbh->prepare( |
24 |
" SELECT shares.ID AS ID, shares.share AS name FROM shares;"); |
" SELECT shares.ID AS ID, shares.share AS name FROM shares;"); |
31 |
return @ret; |
return @ret; |
32 |
} |
} |
33 |
|
|
34 |
|
sub epoch_to_iso { |
35 |
|
my $t = shift || return; |
36 |
|
my $dt = DateTime->from_epoch( epoch => $t ) || return; |
37 |
|
print STDERR "$t == ",$dt->epoch,"\n"; |
38 |
|
return $dt->ymd . ' ' . $dt->hms; |
39 |
|
} |
40 |
|
|
41 |
sub getWhere($) { |
sub getWhere($) { |
42 |
my ($param) = @_; |
my ($param) = @_; |
43 |
my @conditions; |
my @conditions; |
44 |
|
|
45 |
sub mk_iso_date($$) { |
sub mk_epoch_date($$) { |
46 |
my ($name,$suffix) = @_; |
my ($name,$suffix) = @_; |
47 |
|
|
48 |
my $yyyy = $param->{ $name . '_year_' . $suffix} || return; |
my $yyyy = $param->{ $name . '_year_' . $suffix} || return; |
50 |
( $suffix eq 'from' ? 1 : 12); |
( $suffix eq 'from' ? 1 : 12); |
51 |
my $dd .= $param->{ $name . '_day_' . $suffix} || |
my $dd .= $param->{ $name . '_day_' . $suffix} || |
52 |
( $suffix eq 'from' ? 1 : 31); |
( $suffix eq 'from' ? 1 : 31); |
53 |
return sprintf("%04d-%02d-%02d", $yyyy, $mm, $dd); |
my $dt = new DateTime( |
54 |
} |
year => $yyyy, |
55 |
|
month => $mm, |
56 |
my $backup_from = mk_iso_date('search_backup', 'from'); |
day => $dd |
57 |
push @conditions, qq{ date(backups.date, 'unixepoch','localtime') >= '$backup_from' } if ($backup_from); |
); |
58 |
my $backup_to = mk_iso_date('search_backup', 'to'); |
return $dt->epoch || 'NULL'; |
59 |
push @conditions, qq{ date(backups.date, 'unixepoch','localtime') <= '$backup_to' } if ($backup_to); |
} |
60 |
|
|
61 |
my $files_from = mk_iso_date('search', 'from'); |
my $backup_from = mk_epoch_date('search_backup', 'from'); |
62 |
push @conditions, qq{ date(files.date, 'unixepoch','localtime') >= '$files_from' } if ($files_from); |
push @conditions, qq{ backups.date >= $backup_from } if ($backup_from); |
63 |
my $files_to = mk_iso_date('search', 'to'); |
my $backup_to = mk_epoch_date('search_backup', 'to'); |
64 |
push @conditions, qq{ date(files.date, 'unixepoch','localtime') <= '$files_to' } if ($files_to); |
push @conditions, qq{ backups.date <= $backup_to } if ($backup_to); |
65 |
|
|
66 |
|
my $files_from = mk_epoch_date('search', 'from'); |
67 |
|
push @conditions, qq{ files.date >= $files_from } if ($files_from); |
68 |
|
my $files_to = mk_epoch_date('search', 'to'); |
69 |
|
push @conditions, qq{ files.date <= $files_to } if ($files_to); |
70 |
|
|
71 |
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); |
72 |
|
|
73 |
push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'}); |
push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'}); |
74 |
|
|
75 |
push (@conditions, " files.name LIKE '".$param->{'search_filename'}."%'") if ($param->{'search_filename'}); |
push (@conditions, " upper(files.name) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); |
76 |
|
|
77 |
return ( |
return ( |
78 |
join(" and ", @conditions), |
join(" and ", @conditions), |
82 |
} |
} |
83 |
|
|
84 |
|
|
85 |
sub getFiles($$) |
sub getFiles($$) { |
86 |
{ |
my ($where, $offset) = @_; |
87 |
my ($where, $offset) = @_; |
|
88 |
|
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
89 |
|
|
90 |
my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}", |
my $sql_cols = qq{ |
91 |
"", "", { RaiseError => 1, AutoCommit => 1 } ); |
files.id AS fid, |
92 |
my $sql = |
hosts.name AS hname, |
93 |
q{ |
shares.name AS sname, |
94 |
SELECT files.id AS fid, |
shares.share AS sharename, |
95 |
hosts.name AS hname, |
files.backupNum AS backupNum, |
96 |
shares.name AS sname, |
files.name AS filename, |
97 |
shares.share AS sharename, |
files.path AS filepath, |
98 |
files.backupNum AS backupNum, |
shares.share||files.fullpath AS networkPath, |
99 |
files.name AS filename, |
files.date AS date, |
100 |
files.path AS filepath, |
files.type AS filetype, |
101 |
shares.share||files.fullpath AS networkPath, |
files.size AS size, |
102 |
date(files.date, 'unixepoch', 'localtime') AS date, |
}; |
103 |
files.type AS filetype, |
|
104 |
files.size AS size, |
my $sql_dvd_cols = qq{ |
105 |
dvds.name AS dvd |
dvds.name AS dvd |
106 |
|
}; |
107 |
|
|
108 |
|
my $sql_from = qq{ |
109 |
FROM files |
FROM files |
110 |
INNER JOIN shares ON files.shareID=shares.ID |
INNER JOIN shares ON files.shareID=shares.ID |
111 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
INNER JOIN hosts ON hosts.ID = shares.hostID |
112 |
INNER JOIN backups ON backups.num = files.backupNum and backups.hostID = hosts.ID |
INNER JOIN backups ON backups.num = files.backupNum and backups.hostID = hosts.ID |
113 |
|
}; |
114 |
|
|
115 |
|
my $sql_dvd_from = qq{ |
116 |
LEFT JOIN dvds ON dvds.ID = files.dvdid |
LEFT JOIN dvds ON dvds.ID = files.dvdid |
117 |
}; |
}; |
118 |
|
|
119 |
if (defined($where) && $where ne "") |
my $sql_where; |
120 |
{ |
$sql_where = " WHERE ". $where if ($where); |
|
$sql .= " WHERE ". $where; |
|
|
} |
|
121 |
|
|
122 |
$sql .= |
my $sql_order = qq{ |
123 |
q{ |
ORDER BY files.id |
124 |
ORDER BY files.id |
LIMIT $on_page |
125 |
LIMIT 100 |
OFFSET ? |
|
OFFSET ? * 100 + 1 |
|
126 |
}; |
}; |
|
|
|
|
|
|
|
|
|
|
my $st = $dbh->prepare( |
|
|
$sql |
|
|
); |
|
|
if (!defined($offset) && $offset ne "") |
|
|
{ |
|
|
$st->bind_param(1, $offset); |
|
|
} |
|
|
else |
|
|
{ |
|
|
$st->bind_param(1,0); |
|
|
} |
|
|
$st->execute; |
|
|
|
|
|
my @ret = (); |
|
|
my $tmp; |
|
|
|
|
|
while ($tmp = $st->fetchrow_hashref()) |
|
|
{ |
|
|
push(@ret, { |
|
|
'hname' => $tmp->{'hname'}, |
|
|
'sname' => $tmp->{'sname'}, |
|
|
'sharename' => $tmp->{'sharename'}, |
|
|
'backupno' => $tmp->{'backupNum'}, |
|
|
'fname' => $tmp->{'filename'}, |
|
|
'fpath' => $tmp->{'filepath'}, |
|
|
'networkpath' => $tmp->{'networkPath'}, |
|
|
'date' => $tmp->{'date'}, |
|
|
'type' => $tmp->{'filetype'}, |
|
|
'size' => $tmp->{'size'}, |
|
|
'id' => $tmp->{'fid'}, |
|
|
'dvd' => $tmp->{'dvd'} |
|
|
} |
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
$st->finish(); |
|
|
$dbh->disconnect(); |
|
|
return @ret; |
|
|
} |
|
127 |
|
|
128 |
sub getBackupsNotBurned() |
$offset ||= 0; |
129 |
{ |
$offset = ($offset * $on_page) + 1; |
130 |
my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}", |
|
131 |
"", "", { RaiseError => 1, AutoCommit => 1 } ); |
my $sth = $dbh->prepare(qq{ select count(files.id) $sql_from $sql_where }); |
132 |
my $sql = q{ |
$sth->execute(); |
133 |
SELECT |
|
134 |
hosts.ID AS hostID, |
my ($results) = $sth->fetchrow_array(); |
135 |
hosts.name AS host, |
|
136 |
backups.num AS backupno, |
$sth = $dbh->prepare(qq{ select $sql_cols $sql_dvd_cols $sql_from $sql_dvd_from $sql_where $sql_order }); |
137 |
backups.type AS type, |
$sth->execute( $offset ); |
138 |
backups.date AS date |
|
139 |
FROM backups, shares, files, hosts |
my @ret; |
140 |
WHERE |
|
141 |
backups.num = files.backupNum AND |
while (my $row = $sth->fetchrow_hashref()) { |
142 |
shares.ID = files.shareID AND |
push(@ret, { |
143 |
backups.hostID = shares.hostID AND |
'hname' => $row->{'hname'}, |
144 |
hosts.ID = backups.hostID AND |
'sname' => $row->{'sname'}, |
145 |
files.dvdid IS NULL |
'sharename' => $row->{'sharename'}, |
146 |
GROUP BY |
'backupno' => $row->{'backupnum'}, |
147 |
backups.hostID, backups.num |
'fname' => $row->{'filename'}, |
148 |
}; |
'fpath' => $row->{'filepath'}, |
149 |
my $st = $dbh -> prepare( $sql ); |
'networkpath' => $row->{'networkpath'}, |
150 |
my @ret = (); |
'date' => $row->{'date'}, |
151 |
$st -> execute(); |
'type' => $row->{'filetype'}, |
152 |
|
'size' => $row->{'size'}, |
153 |
while ( my $tmp = $st -> fetchrow_hashref() ) |
'id' => $row->{'fid'}, |
154 |
{ |
'dvd' => $row->{'dvd'} |
155 |
push(@ret, { |
}); |
156 |
'host' => $tmp->{'host'}, |
} |
157 |
'hostid' => $tmp->{'hostID'}, |
|
158 |
'backupno' => $tmp->{'backupno'}, |
$sth->finish(); |
159 |
'type' => $tmp->{'type'}, |
$dbh->disconnect(); |
160 |
'date' => $tmp->{'date'} |
return ($results, \@ret); |
161 |
|
} |
162 |
|
|
163 |
|
sub getBackupsNotBurned() { |
164 |
|
|
165 |
|
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); |
166 |
|
my $sql = q{ |
167 |
|
SELECT |
168 |
|
hosts.ID AS hostid, |
169 |
|
min(hosts.name) AS host, |
170 |
|
backups.num AS backupno, |
171 |
|
min(backups.type) AS type, |
172 |
|
min(backups.date) AS date |
173 |
|
FROM backups, shares, files, hosts |
174 |
|
WHERE |
175 |
|
backups.num = files.backupNum AND |
176 |
|
shares.ID = files.shareID AND |
177 |
|
backups.hostID = shares.hostID AND |
178 |
|
hosts.ID = backups.hostID AND |
179 |
|
files.dvdid IS NULL |
180 |
|
GROUP BY |
181 |
|
backups.hostID, backups.num, hosts.id |
182 |
|
}; |
183 |
|
my $sth = $dbh->prepare( $sql ); |
184 |
|
my @ret; |
185 |
|
$sth->execute(); |
186 |
|
|
187 |
|
while ( my $row = $sth->fetchrow_hashref() ) { |
188 |
|
push(@ret, { |
189 |
|
'host' => $row->{'host'}, |
190 |
|
'hostid' => $row->{'hostid'}, |
191 |
|
'backupno' => $row->{'backupno'}, |
192 |
|
'type' => $row->{'type'}, |
193 |
|
'date' => $row->{'date'} |
194 |
} |
} |
195 |
); |
); |
196 |
} |
} |
197 |
|
|
198 |
return @ret; |
return @ret; |
199 |
} |
} |
200 |
|
|
201 |
sub displayBackupsGrid() |
sub displayBackupsGrid() |
202 |
{ |
{ |
203 |
my $retHTML = ""; |
my $retHTML = ""; |
204 |
my $addForm = 1; |
my $addForm = 1; |
205 |
|
|
206 |
if ($addForm) |
if ($addForm) { |
|
{ |
|
207 |
|
|
208 |
$retHTML .= <<EOF3; |
$retHTML .= <<EOF3; |
209 |
<script language="javascript" type="text/javascript"> |
<script language="javascript" type="text/javascript"> |
226 |
//--> |
//--> |
227 |
</script> |
</script> |
228 |
EOF3 |
EOF3 |
229 |
$retHTML .= q{<form name="forma" method="POST" action="}."$MyURL"."?action=burn\""; |
$retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\""; |
230 |
$retHTML.= q{<input type="hidden" value="burn" name="action">}; |
$retHTML.= q{<input type="hidden" value="burn" name="action">}; |
231 |
$retHTML .= q{<input type="hidden" value="results" name="search_results">}; |
$retHTML .= q{<input type="hidden" value="results" name="search_results">}; |
232 |
} |
} |
233 |
$retHTML .= "<table style=\"fview\">"; |
$retHTML .= qq{<table style="fview"><tr>}; |
234 |
$retHTML .= "<tr> "; |
|
235 |
if ($addForm) |
if ($addForm) { |
|
{ |
|
236 |
$retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>"; |
$retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>"; |
237 |
} |
} |
238 |
$retHTML .= "<td class=\"tableheader\">Host</td> <td class=\"tableheader\">Backup no</td> <td class=\"tableheader\">Type</td> <td class=\"tableheader\">date</td></tr>"; |
$retHTML .= qq{<td class="tableheader">Host</td><td class="tableheader">Backup no</td><td class="tableheader">Type</td><td class="tableheader">date</td></tr>}; |
239 |
my @backups = getBackupsNotBurned(); |
|
240 |
my $backup; |
my @backups = getBackupsNotBurned(); |
241 |
|
my $backup; |
242 |
if ($addForm) |
|
243 |
{ |
if ($addForm) { |
244 |
$retHTML .= "<tr>"; |
$retHTML .= qq{<tr><td colspan=7 style="tableheader"> |
245 |
$retHTML .= "<td colspan=7 style=\"tableheader\">"; |
<input type="submit" value="Burn selected backups on medium" name="submitBurner"> |
246 |
$retHTML .= "<input type=\"submit\" value=\"Burn selected backups on medium\" name=\"submitBurner\">"; |
</td></tr>}; |
|
$retHTML .= "</td>"; |
|
|
$retHTML .= "</tr>"; |
|
|
|
|
247 |
} |
} |
248 |
foreach $backup(@backups) |
|
249 |
{ |
foreach $backup(@backups) { |
250 |
my $ftype = ""; |
|
251 |
|
my $ftype = ""; |
252 |
|
|
253 |
$retHTML .= "<tr>"; |
$retHTML .= "<tr>"; |
254 |
if ($addForm) |
if ($addForm) { |
255 |
{ |
$retHTML .= qq{<td class="fview"><input type="checkbox" name="fcb} . |
256 |
$retHTML .= "<td class=\"fview\"> <input type=\"checkbox\" name=\"fcb" |
$backup->{'hostid'}."_".$backup->{'backupno'} . |
257 |
.$backup->{'hostid'}."_".$backup->{'backupno'} |
qq{" value="} . $backup->{'hostid'}."_".$backup->{'backupno'} . |
258 |
."\" value=\"".$backup->{'hostid'}."_".$backup->{'backupno'}."\"> </td>"; |
qq{"></td>}; |
259 |
} |
} |
260 |
|
|
261 |
$retHTML .= "<td class=\"fviewborder\">" . $backup->{'host'} . "</td>"; |
$retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' . |
262 |
$retHTML .= "<td class=\"fviewborder\">" . $backup->{'backupno'} . "</td>"; |
'<td class="fviewborder">' . $backup->{'backupno'} . '</td>' . |
263 |
$retHTML .= "<td class=\"fviewborder\">" . $backup->{'type'} . "</td>"; |
'<td class="fviewborder">' . $backup->{'type'} . '</td>' . |
264 |
$retHTML .= "<td class=\"fviewborder\">" . $backup->{'date'} . "<td>"; |
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '<td>' . |
265 |
$retHTML .= "</tr>"; |
'</tr>'; |
266 |
} |
} |
267 |
$retHTML .= "</table>"; |
|
268 |
if ($addForm) |
$retHTML .= "</table>"; |
269 |
{ |
|
270 |
$retHTML .= "</form>"; |
if ($addForm) { |
271 |
} |
$retHTML .= "</form>"; |
272 |
|
} |
273 |
|
|
274 |
return $retHTML; |
return $retHTML; |
275 |
|
} |
|
|
|
|
} |
|
276 |
|
|
277 |
sub displayGrid($$$$) { |
sub displayGrid($$$$) { |
278 |
my ($where, $addForm, $offset, $hilite) = @_; |
my ($where, $addForm, $offset, $hilite) = @_; |
279 |
my $retHTML = ""; |
my $retHTML = ""; |
280 |
|
|
281 |
if ($addForm) { |
if ($addForm) { |
282 |
$retHTML .= qq{<form name="forma" method="POST" action="}.$MyURL.qq{?action=search">}; |
$retHTML .= qq{<form name="forma" method="GET" action="$MyURL">}; |
283 |
$retHTML.= qq{<input type="hidden" value="search" name="action">}; |
$retHTML.= qq{<input type="hidden" value="search" name="action">}; |
284 |
$retHTML .= qq{<input type="hidden" value="results" name="search_results">}; |
$retHTML .= qq{<input type="hidden" value="results" name="search_results">}; |
285 |
} |
} |
286 |
|
|
287 |
|
my $start_t = time(); |
288 |
|
|
289 |
|
my ($results, $files) = getFiles($where, $offset); |
290 |
|
|
291 |
|
my $dur_t = time() - $start_t; |
292 |
|
my $dur = sprintf("%0.4fs", $dur_t); |
293 |
|
|
294 |
|
my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page); |
295 |
|
|
296 |
$retHTML .= qq{ |
$retHTML .= qq{ |
297 |
|
<br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur) |
298 |
<table style="fview" width="100%"> |
<table style="fview" width="100%"> |
299 |
<tr> |
<tr> |
300 |
<td class="tableheader">Host</td> |
<td class="tableheader">Share</td> |
301 |
<td class="tableheader">Name</td> |
<td class="tableheader">Name</td> |
302 |
<td class="tableheader">Type</td> |
<td class="tableheader">Type</td> |
303 |
<td class="tableheader">#</td> |
<td class="tableheader">#</td> |
306 |
<td class="tableheader">Media</td> |
<td class="tableheader">Media</td> |
307 |
</tr> |
</tr> |
308 |
}; |
}; |
309 |
my @files = getFiles($where, $offset); |
|
310 |
my $file; |
my $file; |
311 |
|
|
312 |
sub hilite_html($$) { |
sub hilite_html($$) { |
315 |
return $html; |
return $html; |
316 |
} |
} |
317 |
|
|
318 |
foreach $file (@files) { |
sub restore_link($$$$$$) { |
319 |
|
my $type = shift; |
320 |
|
my $action = 'RestoreFile'; |
321 |
|
$action = 'browse' if (lc($type) eq 'dir'); |
322 |
|
return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_); |
323 |
|
} |
324 |
|
|
325 |
|
foreach $file (@{ $files }) { |
326 |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
327 |
$retHTML .= "<tr>"; |
$retHTML .= "<tr>"; |
328 |
|
|
329 |
foreach my $v (( |
foreach my $v (( |
330 |
$file->{'hname'}, |
$file->{'sharename'}, |
331 |
qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center"> } . hilite_html( $file->{'fpath'}, $hilite ), |
qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center"> } . hilite_html( $file->{'fpath'}, $hilite ), |
332 |
$typeStr, |
$typeStr, |
333 |
$file->{'backupno'}, |
restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ), |
334 |
$file->{'size'}, |
$file->{'size'}, |
335 |
$file->{'date'}, |
epoch_to_iso( $file->{'date'} ), |
336 |
$file->{'dvd'} |
$file->{'dvd'} |
337 |
)) { |
)) { |
338 |
$retHTML .= qq{<td class="fviewborder">$v</td>}; |
$retHTML .= qq{<td class="fviewborder">$v</td>}; |
342 |
} |
} |
343 |
$retHTML .= "</table>"; |
$retHTML .= "</table>"; |
344 |
|
|
345 |
# skip pager |
# all variables which has to be transfered |
346 |
return $retHTML; |
foreach my $n (qw/search_day_from search_month_from search_year_from search_day_to search_month_to search_year_to search_backup_day_from search_backup_month_from search_backup_year_from search_backup_day_to search_backup_month_to search_backup_year_to search_filename offset/) { |
347 |
|
$retHTML .= qq{<INPUT TYPE="hidden" NAME="$n" VALUE="$In{$n}">\n}; |
348 |
|
} |
349 |
|
|
350 |
|
my $del = ''; |
351 |
|
my $max_page = int( $results / $on_page ); |
352 |
|
my $page = 0; |
353 |
|
|
354 |
|
my $link_fmt = '<a href = "#" onclick="document.forma.offset.value=%d;document.forma.submit();">%s</a>'; |
355 |
|
|
356 |
|
$retHTML .= '<div style="text-align: center;">'; |
357 |
|
|
358 |
$retHTML .= "<INPUT TYPE=\"hidden\" VALUE=\"\" NAME=\"offset\">"; |
if ($offset > 0) { |
359 |
for (my $ii = 1; $ii <= $#files; $ii++) { |
$retHTML .= sprintf($link_fmt, $offset - 1, '<<') . ' '; |
360 |
$retHTML .= "<a href = \"#\" onclick=\"document.forma.offset.value=$ii;document.forma.submit();\">$ii</a>"; |
} |
361 |
if ($ii < $#files) { |
|
362 |
$retHTML .= " | "; |
while ($page <= $max_page) { |
363 |
|
if ($page == $offset) { |
364 |
|
$retHTML .= $del . '<b>' . ($page + 1) . '</b>'; |
365 |
|
} else { |
366 |
|
$retHTML .= $del . sprintf($link_fmt, $page, $page + 1); |
367 |
|
} |
368 |
|
|
369 |
|
if ($page < $offset - $pager_pages && $page != 0) { |
370 |
|
$retHTML .= " ... "; |
371 |
|
$page = $offset - $pager_pages; |
372 |
|
$del = ''; |
373 |
|
} elsif ($page > $offset + $pager_pages && $page != $max_page) { |
374 |
|
$retHTML .= " ... "; |
375 |
|
$page = $max_page; |
376 |
|
$del = ''; |
377 |
|
} else { |
378 |
|
$del = ' | '; |
379 |
|
$page++; |
380 |
} |
} |
381 |
} |
} |
382 |
|
|
383 |
|
if ($offset < $max_page) { |
384 |
|
$retHTML .= ' ' . sprintf($link_fmt, $offset + 1, '>>'); |
385 |
|
} |
386 |
|
|
387 |
|
$retHTML .= "</div>"; |
388 |
|
|
389 |
$retHTML .= "</form>" if ($addForm); |
$retHTML .= "</form>" if ($addForm); |
390 |
|
|
391 |
return $retHTML; |
return $retHTML; |
392 |
} |
} |
393 |
|
|