2 package BackupPC::SearchLib;
5 use BackupPC::CGI::Lib qw(:all);
6 use BackupPC::Attrib qw(:all);
9 use vars qw(%In $MyURL);
10 use Time::HiRes qw/time/;
13 use Search::Estraier 0.04;
18 my $dsn = $Conf{SearchDSN};
19 my $db_user = $Conf{SearchUser} || '';
21 my $hest_node_url = $Conf{HyperEstraierIndex};
28 $dbh ||= DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
36 my $sth = $dbh->prepare(qq{
39 hosts.name || ':' || shares.name as share
41 JOIN hosts on hostid = hosts.id
45 push @ret, { 'id' => '', 'share' => '-'}; # dummy any
47 while ( my $row = $sth->fetchrow_hashref() ) {
54 my $t = shift || return;
55 my $iso = BackupPC::Lib::timeStamp(undef, $t);
56 $iso =~ s/\s/ /g;
60 sub dates_from_form($) {
61 my $param = shift || return;
63 sub mk_epoch_date($$) {
64 my ($name,$suffix) = @_;
66 my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef;
67 my $mm .= $param->{ $name . '_month_' . $suffix} ||
68 ( $suffix eq 'from' ? 1 : 12);
69 my $dd .= $param->{ $name . '_day_' . $suffix} ||
70 ( $suffix eq 'from' ? 1 : 31);
76 my $h = my $m = my $s = 0;
77 if ($suffix eq 'to') {
83 my $dt = new DateTime(
91 print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
92 return $dt->epoch || 'NULL';
96 mk_epoch_date('search_backup', 'from'),
97 mk_epoch_date('search_backup', 'to'),
98 mk_epoch_date('search', 'from'),
99 mk_epoch_date('search', 'to'),
108 my $param = shift || return;
110 my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
113 push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
114 push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
115 push @conditions, qq{ files.date >= $files_from } if ($files_from);
116 push @conditions, qq{ files.date <= $files_to } if ($files_to);
118 print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" and ",@conditions);
120 push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
121 push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
123 if ( $param->{burned} ) {
124 my $is_what = 'is null';
125 $is_what = '= 1' if ($param->{burned} eq 'burned');
126 push @conditions, "archive_burned.part $is_what";
127 push @conditions, "archive_burned.copy $is_what";
130 return join(" and ", @conditions);
137 share_d => 'shares.name DESC',
138 share_a => 'shares.name ASC',
139 path_d => 'files.path DESC',
140 path_a => 'files.path ASC',
141 num_d => 'files.backupnum DESC',
142 num_a => 'files.backupnum ASC',
143 size_d => 'files.size DESC',
144 size_a => 'files.size ASC',
145 date_d => 'files.date DESC',
146 date_a => 'files.date ASC',
149 share_d => 'sname STRD',
150 share_a => 'sname STRA',
151 path_d => 'filepath STRD',
152 path_a => 'filepath STRA',
153 num_d => 'backupnum NUMD',
154 num_a => 'backupnum NUMA',
155 size_d => 'size NUMD',
156 size_a => 'size NUMA',
157 date_d => 'date NUMD',
158 date_a => 'date NUMA',
163 share_d => 'host DESC, share DESC',
164 share_a => 'host ASC, share ASC',
165 num_d => 'backupnum DESC',
166 num_a => 'backupnum ASC',
167 date_d => 'date DESC',
168 date_a => 'date ASC',
171 size_d => 'size DESC',
172 size_a => 'size ASC',
173 incsize_d => 'inc_size DESC',
174 incsize_a => 'inc_size ASC',
180 my ($part,$type, $sort_order) = @_;
182 die "unknown part: $part" unless ($sort_def->{$part});
183 die "unknown type: $type" unless ($sort_def->{$part}->{$type});
185 $sort_order ||= $sort_def->{$part}->{'default'};
187 if (my $ret = $sort_def->{$part}->{$type}->{$sort_order}) {
190 # fallback to default sort order
191 return $sort_def->{$part}->{$type}->{ $sort_def->{$part}->{'default'} };
198 my $offset = $param->{'offset'} || 0;
206 shares.name AS sname,
207 files.backupnum AS backupnum,
208 files.path AS filepath,
216 INNER JOIN shares ON files.shareID=shares.ID
217 INNER JOIN hosts ON hosts.ID = shares.hostID
218 INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = files.shareID
222 my $where = getWhere($param);
223 $sql_where = " WHERE ". $where if ($where);
225 # do we have to add tables for burned media?
226 if ( $param->{burned} ) {
228 LEFT OUTER JOIN archive_backup on archive_backup.backup_id = backups.id
229 LEFT OUTER JOIN archive_burned on archive_burned.archive_id = archive_backup.archive_id
233 my $order = getSort('search', 'sql', $param->{'sort'});
241 my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
242 my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
244 my $sth = $dbh->prepare($sql_count);
246 my ($results) = $sth->fetchrow_array();
248 $sth = $dbh->prepare($sql_results);
249 $sth->execute( $offset );
251 if ($sth->rows != $results) {
252 my $bug = "$0 BUG: [[ $sql_count ]] = $results while [[ $sql_results ]] = " . $sth->rows;
254 print STDERR "$bug\n";
259 while (my $row = $sth->fetchrow_hashref()) {
264 return ($results, \@ret);
267 sub getFilesHyperEstraier($) {
270 my $offset = $param->{'offset'} || 0;
273 die "no Hyper Estraier node URL?" unless ($hest_node_url);
277 if ($hest_node_url) {
278 $db ||= Search::Estraier::Node->new($hest_node_url);
279 $db->set_auth('admin', 'admin');
281 die "BUG: unimplemented";
284 # create a search condition object
285 my $cond = Search::Estraier::Condition->new();
287 my $q = $param->{'search_filename'};
288 my $shareid = $param->{'search_share'};
290 if (length($q) > 0) {
292 $cond->add_attr("filepath ISTRINC $q");
295 # set the search phrase to the search condition object
296 $cond->set_phrase($q);
299 my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
301 $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
302 $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
304 $cond->add_attr("date NUMGE $files_from") if ($files_from);
305 $cond->add_attr("date NUMLE $files_to") if ($files_to);
307 $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
309 $cond->set_max( $offset + $on_page );
310 $cond->set_options( 'SURE' );
311 $cond->set_order( getSort('search', 'est', $param->{'sort'} ) );
313 # get the result of search
317 if ($hest_node_url) {
318 $result = $db->search($cond, 0);
320 $hits = $result->hits;
326 die "BUG: unimplemented";
329 # for each document in result
330 for my $i ($offset .. ($offset + $on_page - 1)) {
331 last if ($i >= $result->doc_num);
334 if ($hest_node_url) {
335 $doc = $result->get_doc($i);
337 die "BUG: unimplemented";
341 foreach my $c (qw/fid hname sname backupnum filepath date type size/) {
342 $row->{$c} = $doc->attr($c);
347 return ($hits, \@res);
352 my ($host, $share, $backupnum) = @_;
353 my $ret = $Conf{GzipSchema};
356 $ret =~ s/\\h/$host/ge;
357 $ret =~ s/\\s/$share/ge;
358 $ret =~ s/\\n/$backupnum/ge;
366 sub get_tgz_size_by_name($) {
369 my $tgz = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.$name;
372 my $Dir = $Conf{InstallDir}."/data/log";
374 if (-f "${tgz}.tar.gz") {
375 $size = (stat("${tgz}.tar.gz"))[7];
377 opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
378 my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir);
380 foreach my $part (@parts) {
381 my $currSize = (stat("$tgz/$part"))[7];
382 $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
393 sub getGzipSizeFromBackupID($) {
397 SELECT hosts.name as host,
398 shares.name as share,
399 backups.num as backupnum
400 FROM hosts, backups, shares
401 WHERE shares.id=backups.shareid AND
402 hosts.id =backups.hostid AND
405 my $sth = $dbh->prepare($sql);
406 $sth->execute($backupID);
407 my $row = $sth->fetchrow_hashref();
409 return get_tgz_size_by_name(
410 getGzipName($row->{'host'}, $row->{share}, $row->{backupnum})
416 my ($hostID, $backupNum) = @_;
421 SELECT hosts.name as host,
422 shares.name as share,
423 backups.num as backupnum
424 FROM hosts, backups, shares
425 WHERE shares.id=backups.shareid AND
426 hosts.id =backups.hostid AND
430 my $sth = $dbh->prepare($sql);
431 $sth->execute($hostID, $backupNum);
433 my $row = $sth->fetchrow_hashref();
435 return get_tgz_size_by_name(
436 getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})
443 my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
445 my $sth = $dbh->prepare(qq{
455 my $cumulative_size = 0;
458 while(my ($size) = $sth->fetchrow_array) {
459 if ($cumulative_size + $size > $max_archive_size) {
461 $cumulative_size = $size;
463 $cumulative_size += $size;
467 return ($volumes,$cumulative_size);
470 sub getBackupsNotBurned($) {
475 my $order = getSort('burn', 'sql', $param->{'sort'});
477 print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql order: $order\n";
481 backups.hostID AS hostID,
483 shares.name AS share,
484 backups.num AS backupnum,
485 backups.type AS type,
486 backups.date AS date,
487 date_part('epoch',now()) - backups.date as age,
488 backups.size AS size,
490 backups.inc_size AS inc_size,
491 backups.parts AS parts
493 INNER JOIN shares ON backups.shareID=shares.ID
494 INNER JOIN hosts ON backups.hostID = hosts.ID
495 LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
496 WHERE backups.inc_size > 0 AND backups.size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL AND backups.parts > 0
511 my $sth = $dbh->prepare( $sql );
515 while ( my $row = $sth->fetchrow_hashref() ) {
516 $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );
517 #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
519 my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
520 if ($row->{size} > $max_archive_size) {
521 ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id});
524 $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024);
526 # do some cluster calculation (approximate)
527 $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 ) * 2);
528 $row->{inc_size_calc} ||= $row->{inc_size};
535 sub displayBackupsGrid($) {
539 my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
540 my $max_archive_file_size = $Conf{MaxArchiveFileSize} || die "no MaxFileInSize";
543 <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
546 $retHTML .= <<'EOF3';
547 <style type="text/css">
555 background-color: #E0F0E0;
556 border: 1px solid #00C000;
559 DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
564 position: fixed !important;
565 left: 0.5em !important;
566 top: auto !important;
567 bottom: 1em !important;
568 width: 15% !important;
571 DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
572 border: 1px solid #00C000;
580 DIV#fixedBox #submitBurner {
597 * HTML DIV#fixedBox {
601 #mContainer, #gradient, #mask, #progressIndicator {
607 vertical-align: middle;
611 #gradient, #mask, #progressIndicator {
615 border-color: #000000;
630 margin-bottom: 0.5em;
635 background-color: #FFFF00;
640 background-color: #FFFFFF;
645 background-color: transparent;
658 <script type="text/javascript">
664 # take maximum archive size from configuration
666 var media_size = $max_archive_size ;
667 var max_file_size = $max_archive_file_size;
671 $retHTML .= <<'EOF3';
673 function debug(msg) {
674 return; // Disable debugging
676 if (! debug_div) debug_div = document.getElementById('debug');
678 // this will create debug div if it doesn't exist.
680 debug_div = document.createElement('div');
681 if (document.body) document.body.appendChild(debug_div);
682 else debug_div = null;
685 debug_div.appendChild(document.createTextNode(msg));
686 debug_div.appendChild(document.createElement("br"));
691 var element_id_cache = Array();
693 function element_id(name,element) {
694 if (! element_id_cache[name]) {
695 element_id_cache[name] = self.document.getElementById(name);
697 return element_id_cache[name];
700 function checkAll(location) {
701 var f = element_id('forma') || null;
702 if (!f) return false;
704 var len = f.elements.length;
705 var check_all = element_id('allFiles');
706 var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
708 for (var i = 0; i < len; i++) {
709 var e = f.elements[i];
710 if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
711 if (check_all.checked) {
712 if (e.checked) continue;
713 var el = element_id("fss" + e.name.substr(3));
714 var size = parseInt(el.value) || 0;
715 debug('suma: '+suma+' size: '+size);
716 if ((suma + size) < media_size) {
730 function update_sum(suma, suma_disp) {
731 if (! suma_disp) suma_disp = suma;
732 suma_disp = Math.floor(suma_disp / 1024);
733 element_id('forma').elements['totalsize_kb'].value = suma_disp;
734 element_id('forma').elements['totalsize'].value = suma;
735 pbar_set(suma, media_size);
736 debug('total size: ' + suma);
739 function update_size(name, checked, suma) {
740 var size = parseInt( element_id("fss" + name).value);
748 var volumes = parseInt( element_id("prt" + name).value);
749 debug('update_size('+name+','+checked+') suma: '+suma+' volumes: '+volumes);
752 element_id("volumes").innerHTML = "This will take "+volumes+" mediums!";
753 element_id("volumes").style.display = 'block';
758 element_id("volumes").style.display = 'none';
765 function sumiraj(e) {
766 var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
767 var len = element_id('forma').elements.length;
769 suma = update_size(e.name.substr(3), e.checked, suma);
770 if (suma < 0) suma = 0;
773 for (var i = 0; i < len; i++) {
774 var fel = element_id('forma').elements[i];
775 if (fel.name != 'all' && fel.checked && fel.name.substr(0,3) == 'fcb') {
776 suma = update_size(fel.name.substr(3), fel.checked, suma);
786 var _pbar_width = null;
787 var _pbar_warn = 10; // change color in last 10%
789 function pbar_reset() {
790 element_id("mask").style.left = "0px";
791 _pbar_width = element_id("mContainer").offsetWidth - 2;
792 element_id("mask").style.width = _pbar_width + "px";
793 element_id("mask").style.display = "block";
794 element_id("progressIndicator").style.zIndex = 10;
795 element_id("progressIndicator").innerHTML = "0";
798 function dec2hex(d) {
799 var hch = '0123456789ABCDEF';
801 var q = (d - a) / 16;
802 return hch.charAt(q) + hch.charAt(a);
805 function pbar_set(amount, max) {
806 debug('pbar_set('+amount+', '+max+')');
808 if (_pbar_width == null) {
809 var _mc = element_id("mContainer");
810 if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
811 if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
812 if (_pbar_width == null) _pbar_width = 0;
815 var pcnt = Math.floor(amount * 100 / max);
816 var p90 = 100 - _pbar_warn;
817 var pcol = pcnt - p90;
818 if (Math.round(pcnt) <= 100) {
819 if (pcol < 0) pcol = 0;
820 var e = element_id("submitBurner");
821 debug('enable_button');
823 var a = e.getAttributeNode('disabled') || null;
824 if (a) e.removeAttributeNode(a);
826 debug('disable button');
828 var e = element_id("submitBurner");
829 if (!e.disabled) e.disabled = true;
831 var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
832 var col = '#FF' + dec2hex(col_g) + '00';
834 //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
835 element_id("gradient").style.backgroundColor = col;
837 element_id("progressIndicator").innerHTML = pcnt + '%';
838 //element_id("progressIndicator").innerHTML = amount;
840 element_id("mask").style.clip = 'rect(' + Array(
842 element_id("mask").offsetWidth + 'px',
843 element_id("mask").offsetHeight + 'px',
844 Math.round(_pbar_width * amount / max) + 'px'
848 if (!self.body) self.body = new Object();
849 self.onload = self.document.onload = self.body.onload = function() {
858 <input type="hidden" name="totalsize"/>
859 Size: <input type="text" name="totalsize_kb" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
861 <div id="mContainer">
862 <div id="gradient"> </div>
863 <div id="mask"> </div>
864 <div id="progressIndicator">0%</div>
868 <div id="volumes"> </div>
871 <textarea name="note" cols="10" rows="5" id="note"></textarea>
873 <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
877 <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">
883 <input type="hidden" value="burn" name="action">
884 <input type="hidden" value="results" name="search_results">
885 <table style="fview" border="0" cellspacing="0" cellpadding="2">
886 <tr class="tableheader">
887 <td class="tableheader">
888 <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
891 sort_header($param, 'Share', 'share', 'center') .
892 sort_header($param, '#', 'num', 'center') .
894 <td align="center">Type</td>
896 sort_header($param, 'Date', 'date', 'center') .
897 sort_header($param, 'Age/days', 'age', 'center') .
898 sort_header($param, 'Size/Mb', 'size', 'center') .
899 sort_header($param, 'gzip size/Kb', 'incsize', 'center') .
901 <td align="center">medias</td></tr>
904 my @color = (' bgcolor="#e0e0e0"', '');
909 foreach my $backup ( getBackupsNotBurned($param) ) {
911 if ($host ne $backup->{'host'}) {
913 $host = $backup->{'host'};
917 my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
920 '<tr' . $color[$i %2 ] . '>
923 if (($backup->{'inc_size'} || 0) > 0) {
925 <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
928 my $img_url = $Conf{CgiImageDirURL};
932 '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
933 '<td align="center">' . $backup->{'backupnum'} . '</td>' .
934 '<td align="center">' . $backup->{'type'} . '</td>' .
935 '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
936 '<td align="center">' . $backup->{'age'} . '</td>' .
937 '<td align="right">' . $backup->{'size'} . '</td>' .
938 '<td align="right">' . sprintf("%0.1f", $backup->{'inc_size'} / 1024 ) .
939 '<input type="hidden" id="fss'.$checkbox_key .'" value="'. $backup->{'inc_size_calc'} .'"></td>' .
940 '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'volumes'} .'"></td>' .
941 '<td align="left">' . ( qq{<img src="$img_url/icon-cd.gif" alt="media">} x $backup->{volumes} ) . '</td>' .
946 $retHTML .= "</table>";
947 $retHTML .= "</form>";
955 my $offset = $param->{'offset'};
956 my $hilite = $param->{'search_filename'};
960 my $start_t = time();
962 my ($results, $files);
963 if ($param->{'use_hest'} && length($hilite) > 0) {
964 ($results, $files) = getFilesHyperEstraier($param);
966 ($results, $files) = getFiles($param);
969 my $dur_t = time() - $start_t;
970 my $dur = sprintf("%0.4fs", $dur_t);
972 my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);
976 <p style="color: red;">No results found...</p>
982 #$retHTML .= '<pre>' . Dumper($files) . '</pre>';
988 Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
990 <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
991 <tr class="fviewheader">
995 sub sort_header($$$$) {
996 my ($param, $display, $name, $align) = @_;
998 my ($sort_what, $sort_direction) = split(/_/,$param->{'sort'},2);
1000 my $old_sort = $param->{'sort'};
1002 my $html = qq{<td align="$align"};
1005 if (lc($sort_what) eq lc($name)) {
1006 my $direction = lc($sort_direction);
1008 # swap direction or fallback to default
1009 $direction =~ tr/ad/da/;
1010 $direction = 'a' unless ($direction =~ /[ad]/);
1012 $param->{'sort'} = $name . '_' . $direction;
1013 $html .= ' style="border: 1px solid #808080;"';
1015 # add unicode arrow for direction
1017 $arrow .= $direction eq 'a' ? '▲'
1018 : $direction eq 'd' ? '▼'
1023 $param->{'sort'} = $name . '_a';
1026 $html .= '><a href="' . page_uri($param) . '">' . $display . '</a>' . $arrow . '</td>';
1027 $param->{'sort'} = $old_sort;
1033 sort_header($param, 'Share', 'share', 'center') .
1034 sort_header($param, 'Type and Name', 'path', 'center') .
1035 sort_header($param, '#', 'num', 'center') .
1036 sort_header($param, 'Size', 'size', 'center') .
1037 sort_header($param, 'Date', 'date', 'center');
1040 <td align="center">Media</td>
1046 sub hilite_html($$) {
1047 my ($html, $search) = @_;
1048 $html =~ s#($search)#<b>$1</b>#gis;
1052 sub restore_link($$$$$$) {
1054 my $action = 'RestoreFile';
1055 $action = 'browse' if (lc($type) eq 'dir');
1056 return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);
1062 sub check_archived($$$) {
1063 my ($host, $share, $num) = @_;
1065 if (my $html = $archived_cache{"$host $share $num"}) {
1069 $sth_archived ||= $dbh->prepare(qq{
1072 count(archive_burned.copy) as copies
1074 inner join archive_burned on archive_burned.archive_id = archive.id
1075 inner join archive_backup on archive.id = archive_backup.archive_id
1076 inner join backups on backups.id = archive_backup.backup_id
1077 inner join hosts on hosts.id = backups.hostid
1078 inner join shares on shares.id = backups.shareid
1079 where hosts.name = ? and shares.name = ? and backups.num = ?
1080 group by dvd_nr, note
1085 $sth_archived->execute($host, $share, $num);
1086 while (my $row = $sth_archived->fetchrow_hashref()) {
1087 push @mediums, '<abbr title="' .
1089 ' [' . $row->{'copies'} . ']' .
1090 '">' .$row->{'dvd_nr'} .
1094 my $html = join(", ",@mediums);
1095 $archived_cache{"$host $share $num"} = $html;
1099 my $i = $offset * $on_page;
1101 foreach $file (@{ $files }) {
1104 my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
1105 $retHTML .= qq{<tr class="fviewborder">};
1107 $retHTML .= qq{<td class="fviewborder">$i</td>};
1110 qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} .
1111 qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.png" alt="$typeStr" align="middle"> } . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} .
1112 qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .
1113 qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
1114 qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
1115 qq{<td class="fviewborder">} . check_archived( $file->{'hname'}, $file->{'sname'}, $file->{'backupnum'} ) . qq{</td>};
1117 $retHTML .= "</tr>";
1119 $retHTML .= "</table>";
1121 # all variables which has to be transfered
1122 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/) {
1123 $retHTML .= qq{<INPUT TYPE="hidden" NAME="$n" VALUE="$In{$n}">\n};
1127 my $max_page = int( $results / $on_page );
1131 my $param = shift || die "no param?";
1135 foreach my $k (keys %{ $param }) {
1137 $uri .= $del . $k . '=' . ${EscURI( $param->{$k} )};
1144 sub page_link($$$) {
1145 my ($param,$page,$display) = @_;
1147 $param->{'offset'} = $page if (defined($page));
1149 my $html = '<a href = "' . page_uri($param) . '">' . $display . '</a>';
1152 $retHTML .= '<div style="text-align: center;">';
1155 $retHTML .= page_link($param, $offset - 1, '<<') . ' ';
1158 while ($page <= $max_page) {
1159 if ($page == $offset) {
1160 $retHTML .= $del . '<b>' . ($page + 1) . '</b>';
1162 $retHTML .= $del . page_link($param, $page, $page + 1);
1165 if ($page < $offset - $pager_pages && $page != 0) {
1166 $retHTML .= " ... ";
1167 $page = $offset - $pager_pages;
1169 } elsif ($page > $offset + $pager_pages && $page != $max_page) {
1170 $retHTML .= " ... ";
1179 if ($offset < $max_page) {
1180 $retHTML .= ' ' . page_link($param, $offset + 1, '>>');
1183 $retHTML .= "</div>";