/[BackupPC]/trunk/lib/BackupPC/SearchLib.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/BackupPC/SearchLib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 171 by dpavlin, Mon Oct 10 14:32:31 2005 UTC revision 303 by dpavlin, Sat Jan 28 16:45:46 2006 UTC
# Line 8  use DBI; Line 8  use DBI;
8  use DateTime;  use DateTime;
9  use vars qw(%In $MyURL);  use vars qw(%In $MyURL);
10  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
11    use XML::Writer;
12    use IO::File;
13    
14  my $on_page = 100;  my $on_page = 100;
15  my $pager_pages = 10;  my $pager_pages = 10;
# Line 15  my $pager_pages = 10; Line 17  my $pager_pages = 10;
17  my $dsn = $Conf{SearchDSN};  my $dsn = $Conf{SearchDSN};
18  my $db_user = $Conf{SearchUser} || '';  my $db_user = $Conf{SearchUser} || '';
19    
20  my $hest_index_path = $Conf{HyperEstraierIndex};  my $hest_node_url = $Conf{HyperEstraierIndex};
21    
22  my $dbh;  my $dbh;
23    
# Line 68  sub dates_from_form($) { Line 70  sub dates_from_form($) {
70                  $mm =~ s/\D//g;                  $mm =~ s/\D//g;
71                  $dd =~ s/\D//g;                  $dd =~ s/\D//g;
72    
73                    my $h = my $m = my $s = 0;
74                    if ($suffix eq 'to') {
75                            $h = 23;
76                            $m = 59;
77                            $s = 59;
78                    }
79    
80                  my $dt = new DateTime(                  my $dt = new DateTime(
81                          year => $yyyy,                          year => $yyyy,
82                          month => $mm,                          month => $mm,
83                          day => $dd                          day => $dd,
84                            hour => $h,
85                            minute => $m,
86                            second => $s,
87                  );                  );
88                  print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";                  print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
89                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
# Line 100  sub getWhere($) { Line 112  sub getWhere($) {
112          push @conditions, qq{ files.date >= $files_from } if ($files_from);          push @conditions, qq{ files.date >= $files_from } if ($files_from);
113          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
114    
115          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(" and ",@conditions);
116    
117          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
118          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'});
# Line 108  sub getWhere($) { Line 120  sub getWhere($) {
120          return join(" and ", @conditions);          return join(" and ", @conditions);
121  }  }
122    
123    my $sort_def = {
124            search => {
125                    default => 'date_a',
126                    sql => {
127                            share_d => 'shares.name DESC',
128                            share_a => 'shares.name ASC',
129                            path_d => 'files.path DESC',
130                            path_a => 'files.path ASC',
131                            num_d => 'files.backupnum DESC',
132                            num_a => 'files.backupnum ASC',
133                            size_d => 'files.size DESC',
134                            size_a => 'files.size ASC',
135                            date_d => 'files.date DESC',
136                            date_a => 'files.date ASC',
137                    },
138                    est => {
139                            share_d => 'sname STRD',
140                            share_a => 'sname STRA',
141                            path_d => 'filepath STRD',
142                            path_a => 'filepath STRA',
143                            num_d => 'backupnum NUMD',
144                            num_a => 'backupnum NUMA',
145                            size_d => 'size NUMD',
146                            size_a => 'size NUMA',
147                            date_d => 'date NUMD',
148                            date_a => 'date NUMA',
149                    }
150            }, burn => {
151                    default => 'date_a',
152                    sql => {
153                            share_d => 'host DESC, share DESC',
154                            share_a => 'host ASC, share ASC',
155                            num_d => 'backupnum DESC',
156                            num_a => 'backupnum ASC',
157                            date_d => 'date DESC',
158                            date_a => 'date ASC',
159                            age_d => 'age DESC',
160                            age_a => 'age ASC',
161                            size_d => 'size DESC',
162                            size_a => 'size ASC',
163                            incsize_d => 'inc_size DESC',
164                            incsize_a => 'inc_size ASC',
165                    }
166            }
167    };
168    
169    sub getSort($$$) {
170            my ($part,$type, $sort_order) = @_;
171    
172            die "unknown part: $part" unless ($sort_def->{$part});
173            die "unknown type: $type" unless ($sort_def->{$part}->{$type});
174    
175            $sort_order ||= $sort_def->{$part}->{'default'};
176    
177            if (my $ret = $sort_def->{$part}->{$type}->{$sort_order}) {
178                    return $ret;
179            } else {
180                    # fallback to default sort order
181                    return $sort_def->{$part}->{$type}->{ $sort_def->{$part}->{'default'} };
182            }
183    }
184    
185  sub getFiles($) {  sub getFiles($) {
186          my ($param) = @_;          my ($param) = @_;
# Line 139  sub getFiles($) { Line 212  sub getFiles($) {
212          my $where = getWhere($param);          my $where = getWhere($param);
213          $sql_where = " WHERE ". $where if ($where);          $sql_where = " WHERE ". $where if ($where);
214    
215            my $order = getSort('search', 'sql', $param->{'sort'});
216    
217          my $sql_order = qq{          my $sql_order = qq{
218                  ORDER BY files.date                  ORDER BY $order
219                  LIMIT $on_page                  LIMIT $on_page
220                  OFFSET ?                  OFFSET ?
221          };          };
# Line 176  sub getHyperEstraier_url($) { Line 251  sub getHyperEstraier_url($) {
251    
252          return unless $use_hest;          return unless $use_hest;
253    
254          use HyperEstraier;          use Search::Estraier;
255          my ($index_path, $index_node_url);          die "direct access to Hyper Estraier datatase is no longer supported. Please use estmaster\n"
256                    unless ($use_hest =~ m#^http://#);
257    
258          if ($use_hest =~ m#^http://#) {          return $use_hest;
                 $index_node_url = $use_hest;  
         } else {  
                 $index_path = $TopDir . '/' . $index_path;  
                 $index_path =~ s#//#/#g;  
         }  
         return ($index_path, $index_node_url);  
259  }  }
260    
261  sub getFilesHyperEstraier($) {  sub getFilesHyperEstraier($) {
# Line 194  sub getFilesHyperEstraier($) { Line 264  sub getFilesHyperEstraier($) {
264          my $offset = $param->{'offset'} || 0;          my $offset = $param->{'offset'} || 0;
265          $offset *= $on_page;          $offset *= $on_page;
266    
267          die "no index_path?" unless ($hest_index_path);          die "no Hyper Estraier node URL?" unless ($hest_node_url);
   
         use HyperEstraier;  
   
         my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path);  
268    
269          # open the database          # open the database
270          my $db;          my $db;
271          if ($index_path) {          if ($hest_node_url) {
272                  $db = HyperEstraier::Database->new();                  $db ||= Search::Estraier::Node->new($hest_node_url);
                 $db->open($index_path, $HyperEstraier::ESTDBREADER);  
         } elsif ($index_node_url) {  
                 $db ||= HyperEstraier::Node->new($index_node_url);  
273                  $db->set_auth('admin', 'admin');                  $db->set_auth('admin', 'admin');
274          } else {          } else {
275                  die "BUG: unimplemented";                  die "BUG: unimplemented";
276          }          }
277    
278          # create a search condition object          # create a search condition object
279          my $cond = HyperEstraier::Condition->new();          my $cond = Search::Estraier::Condition->new();
280    
281          my $q = $param->{'search_filename'};          my $q = $param->{'search_filename'};
282          my $shareid = $param->{'search_share'};          my $shareid = $param->{'search_share'};
# Line 238  sub getFilesHyperEstraier($) { Line 301  sub getFilesHyperEstraier($) {
301          $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);          $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
302    
303  #       $cond->set_max( $offset + $on_page );  #       $cond->set_max( $offset + $on_page );
304          $cond->set_options( $HyperEstraier::Condition::SURE );          $cond->set_options( SURE => 1 );
305          $cond->set_order( 'date NUMA' );          $cond->set_order( getSort('search', 'est', $param->{'sort'} ) );
306    
307          # get the result of search          # get the result of search
308          my @res;          my @res;
309          my ($result, $hits);          my ($result, $hits);
310    
311          if ($index_path) {          if ($hest_node_url) {
312                  $result = $db->search($cond, 0);                  $result = $db->search($cond, 0);
313                  $hits = $result->size;                  if ($result) {
314          } elsif ($index_node_url) {                          $hits = $result->doc_num;
315                  $result = $db->search($cond, 0);                  } else {
316                  $hits = $result->doc_num;                          $hits = 0;
317                    }
318          } else {          } else {
319                  die "BUG: unimplemented";                  die "BUG: unimplemented";
320          }          }
# Line 260  sub getFilesHyperEstraier($) { Line 324  sub getFilesHyperEstraier($) {
324                  last if ($i >= $hits);                  last if ($i >= $hits);
325    
326                  my $doc;                  my $doc;
327                  if ($index_path) {                  if ($hest_node_url) {
                         my $id = $result->get($i);  
                         $doc = $db->get_doc($id, 0);  
                 } elsif ($index_node_url) {  
328                          $doc = $result->get_doc($i);                          $doc = $result->get_doc($i);
329                  } else {                  } else {
330                          die "BUG: unimplemented";                          die "BUG: unimplemented";
331                  }                  }
332    
333                  my $row;                  my $row;
334                  foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) {                  foreach my $c (qw/fid hname sname backupnum filepath date type size/) {
335                          $row->{$c} = $doc->attr($c);                          $row->{$c} = $doc->attr($c);
336                  }                  }
337                  push @res, $row;                  push @res, $row;
# Line 295  sub getGzipName($$$) Line 356  sub getGzipName($$$)
356                    
357  }  }
358    
359    sub get_tgz_size_by_name($) {
360            my $name = shift;
361    
362            my $tgz = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.$name;
363    
364            my $size = -1;
365    
366            if (-f "${tgz}.tar.gz") {
367                    $size = (stat("${tgz}.tar.gz"))[7];
368            } elsif (-d $tgz) {
369                    opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
370                    my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir);
371                    $size = 0;
372                    foreach my $part (@parts) {
373                            $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
374                    }
375                    closedir $dir;
376            } else {
377                    return -1;
378            }
379    
380            return $size;
381    }
382    
383  sub getGzipSize($$)  sub getGzipSize($$)
384  {  {
385          my ($hostID, $backupNum) = @_;          my ($hostID, $backupNum) = @_;
         my $ret;  
386          my $sql;          my $sql;
387          my $dbh = get_dbh();          my $dbh = get_dbh();
388                    
# Line 316  sub getGzipSize($$) Line 400  sub getGzipSize($$)
400          $sth->execute($hostID, $backupNum);          $sth->execute($hostID, $backupNum);
401    
402          my $row = $sth->fetchrow_hashref();          my $row = $sth->fetchrow_hashref();
403            
404          my (undef,undef,undef,undef,undef,undef,undef,$ret,undef,undef,undef,undef,undef) =          return get_tgz_size_by_name(
405                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})
406                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));          );
           
         return $ret;      
407  }  }
408    
409  sub getBackupsNotBurned() {  sub getVolumes($) {
410            my $id = shift;
411    
412            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
413    
414            my $sth = $dbh->prepare(qq{
415                    select
416                            size
417                    from backup_parts
418                    where backup_id = ?
419                    order by part_nr asc
420            });
421    
422            $sth->execute($id);
423    
424            my $cumulative_size = 0;
425            my $volumes = 1;
426    
427            while(my ($size) = $sth->fetchrow_array) {
428                    if ($cumulative_size + $size > $max_archive_size) {
429                            $volumes++;
430                            $cumulative_size = $size;
431                    } else {
432                            $cumulative_size += $size;
433                    }
434            }
435    
436            return ($volumes,$cumulative_size);
437    }
438    
439    sub getBackupsNotBurned($) {
440    
441            my $param = shift;
442          my $dbh = get_dbh();          my $dbh = get_dbh();
443    
444          my $sql = q{          my $order = getSort('burn', 'sql', $param->{'sort'});
445    
446    print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql order: $order\n";
447    
448            my $sql = qq{
449                  SELECT                  SELECT
450                          backups.hostID AS hostID,                          backups.hostID AS hostID,
451                          hosts.name AS host,                          hosts.name AS host,
# Line 336  sub getBackupsNotBurned() { Line 453  sub getBackupsNotBurned() {
453                          backups.num AS backupnum,                          backups.num AS backupnum,
454                          backups.type AS type,                          backups.type AS type,
455                          backups.date AS date,                          backups.date AS date,
456                            date_part('epoch',now()) - backups.date as age,
457                          backups.size AS size,                          backups.size AS size,
458                          backups.id AS id,                          backups.id AS id,
459                          backups.inc_size AS inc_size                          backups.inc_size AS inc_size,
460                            backups.parts AS parts
461                  FROM backups                  FROM backups
462                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
463                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
# Line 354  sub getBackupsNotBurned() { Line 473  sub getBackupsNotBurned() {
473                          backups.type,                          backups.type,
474                          backups.date,                          backups.date,
475                          backups.size,                          backups.size,
476                          backups.inc_size                          backups.inc_size,
477                  ORDER BY backups.date                          backups.parts
478                    ORDER BY $order
479          };          };
480          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
481          my @ret;          my @ret;
482          $sth->execute();          $sth->execute();
483    
484          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
485                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );
486                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
487    
488                  # do some cluster calculation (approximate) and convert to kB                  my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
489                  $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2);                  if ($row->{size} > $max_archive_size) {
490                            ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id});
491                    }
492    
493                    $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024);
494    
495                    # do some cluster calculation (approximate)
496                    $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 )  * 2);
497                    $row->{inc_size_calc} ||= $row->{inc_size};
498                  push @ret, $row;                  push @ret, $row;
499          }          }
500                
501          return @ret;                return @ret;
502  }  }
503    
504  sub displayBackupsGrid() {  sub displayBackupsGrid($) {
505    
506            my $param = shift;
507    
508            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
509            my $max_archive_file_size = $Conf{MaxArchiveFileSize}  || die "no MaxFileInSize";
510    
511          my $retHTML .= q{          my $retHTML .= q{
512                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
# Line 480  DIV#fixedBox #submitBurner { Line 613  DIV#fixedBox #submitBurner {
613          z-index: 3;          z-index: 3;
614          background-color: transparent;          background-color: transparent;
615  }  }
616    
617    #volumes {
618            padding: 0.4em;
619            display: none;
620            width: 100%;
621            font-size: 80%;
622            color: #ff0000;
623            text-align: center;
624    }
625  -->  -->
626  </style>  </style>
627  <script type="text/javascript">  <script type="text/javascript">
# Line 489  var debug_div = null; Line 631  var debug_div = null;
631  EOF3  EOF3
632    
633          # take maximum archive size from configuration          # take maximum archive size from configuration
634          $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';          $retHTML .= qq{
635    var media_size = $max_archive_size ;
636    var max_file_size = $max_archive_file_size;
637    
638    };
639    
640          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
641    
# Line 550  function checkAll(location) { Line 696  function checkAll(location) {
696          update_sum(suma);          update_sum(suma);
697  }  }
698    
699  function update_sum(suma) {  function update_sum(suma, suma_disp) {
700            if (! suma_disp) suma_disp = suma;
701            suma_disp = Math.floor(suma_disp / 1024);
702            element_id('forma').elements['totalsize_kb'].value = suma_disp;
703          element_id('forma').elements['totalsize'].value = suma;          element_id('forma').elements['totalsize'].value = suma;
704          pbar_set(suma, media_size);          pbar_set(suma, media_size);
705          debug('total size: ' + suma);          debug('total size: ' + suma);
706  }  }
707    
708    function update_size(name, checked, suma) {
709            var size = parseInt( element_id("fss" + name).value);
710    
711            if (checked) {
712                    suma += size;
713            } else {
714                    suma -= size;
715            }
716    
717            var volumes = parseInt( element_id("prt" + name).value);
718            debug('update_size('+name+','+checked+') suma: '+suma+' volumes: '+volumes);
719            if (volumes > 1) {
720                    if (checked) {
721                            element_id("volumes").innerHTML = "This will take "+volumes+" mediums!";
722                            element_id("volumes").style.display = 'block';
723                            suma = size;
724                            update_sum(suma);
725                    } else {
726                            suma -= size;
727                            element_id("volumes").style.display = 'none';
728                    }
729            }
730    
731            return suma;
732    }
733    
734  function sumiraj(e) {  function sumiraj(e) {
735          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
736          var len = element_id('forma').elements.length;          var len = element_id('forma').elements.length;
737          if (e) {          if (e) {
738                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);                  suma = update_size(e.name.substr(3), e.checked, suma);
739                  if (e.checked) {                  if (suma < 0) suma = 0;
                         suma += size;  
                 } else {  
                         suma -= size;  
                 }  
740          } else {          } else {
741                  suma = 0;                  suma = 0;
742                  for (var i = 0; i < len; i++) {                  for (var i = 0; i < len; i++) {
743                          var e = element_id('forma').elements[i];                          var fel = element_id('forma').elements[i];
744                          if (e.name != 'all' && e.checked && e.name.substr(0,3) == 'fcb') {                          if (fel.name != 'all' && fel.checked && fel.name.substr(0,3) == 'fcb') {
745                                  var el = element_id("fss" + e.name.substr(3));                                  suma = update_size(fel.name.substr(3), fel.checked, suma);
                                 if (el && el.value) suma += parseInt(el.value) || 0;  
746                          }                          }
747                  }                  }
748          }          }
# Line 654  self.onload = self.document.onload = sel Line 824  self.onload = self.document.onload = sel
824  </script>  </script>
825  <div id="fixedBox">  <div id="fixedBox">
826    
827  Size: <input type="text" name="totalsize" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB  <input type="hidden" name="totalsize"/>
828    Size: <input type="text" name="totalsize_kb" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
829    
830  <div id="mContainer">  <div id="mContainer">
831          <div id="gradient">&nbsp;</div>          <div id="gradient">&nbsp;</div>
# Line 663  Size: <input type="text" name="totalsize Line 834  Size: <input type="text" name="totalsize
834  </div>  </div>
835  <br/>  <br/>
836    
837    <div id="volumes">&nbsp;</div>
838    
839  Note:  Note:
840  <textarea name="note" cols="10" rows="5" id="note"></textarea>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
841    
# Line 683  EOF3 Line 856  EOF3
856                          <td class="tableheader">                          <td class="tableheader">
857                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
858                          </td>                          </td>
859                          <td align="center">Share</td>          } .
860                          <td align="center">Backup no</td>                  sort_header($param, 'Share', 'share', 'center') .
861                    sort_header($param, '#', 'num', 'center') .
862            qq{
863                          <td align="center">Type</td>                          <td align="center">Type</td>
864                          <td align="center">date</td>          } .
865                          <td align="center">age/days</td>                  sort_header($param, 'Date', 'date', 'center') .
866                          <td align="center">size/MB</td>                  sort_header($param, 'Age/days', 'age', 'center') .
867                          <td align="center">gzip size/kB</td>                  sort_header($param, 'Size/Mb', 'size', 'center') .
868                          </tr>                  sort_header($param, 'gzip size/Kb', 'incsize', 'center') .
869            qq{
870                            <td align="center">medias</td></tr>
871          };          };
872    
873          my @color = (' bgcolor="#e0e0e0"', '');          my @color = (' bgcolor="#e0e0e0"', '');
# Line 699  EOF3 Line 875  EOF3
875          my $i = 0;          my $i = 0;
876          my $host = '';          my $host = '';
877    
878          foreach my $backup ( getBackupsNotBurned() ) {          foreach my $backup ( getBackupsNotBurned($param) ) {
879    
880                  if ($host ne $backup->{'host'}) {                  if ($host ne $backup->{'host'}) {
881                          $i++;                          $i++;
# Line 718  EOF3 Line 894  EOF3
894                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
895                  }                  }
896    
897                    my $img_url = $Conf{CgiImageDirURL};
898    
899                  $retHTML .=                  $retHTML .=
900                          '</td>' .                          '</td>' .
901                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 726  EOF3 Line 904  EOF3
904                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
905                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
906                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
907                          '<td align="right">' . $backup->{'inc_size'} .                          '<td align="right">' . sprintf("%0.1f", $backup->{'inc_size'} / 1024 ) .
908                          '<input type="hidden" iD="fss'.$checkbox_key .'" value="'. $backup->{'inc_size'} .'"></td>' .                          '<input type="hidden" id="fss'.$checkbox_key .'" value="'. $backup->{'inc_size_calc'} .'"></td>' .
909                            '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'volumes'} .'"></td>' .
910                            '<td align="left">' . ( qq{<img src="$img_url/icon-cd.gif" alt="media">} x $backup->{volumes} ) . '</td>' .
911    
912                          "</tr>\n";                          "</tr>\n";
913          }          }
# Line 779  sub displayGrid($) { Line 959  sub displayGrid($) {
959          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
960                  <tr class="fviewheader">                  <tr class="fviewheader">
961                  <td></td>                  <td></td>
962                  <td align="center">Share</td>          };
963                  <td align="center">Type and Name</td>  
964                  <td align="center">#</td>          sub sort_header($$$$) {
965                  <td align="center">Size</td>                  my ($param, $display, $name, $align) = @_;
966                  <td align="center">Date</td>  
967                    my ($sort_what, $sort_direction) = split(/_/,$param->{'sort'},2);
968    
969                    my $old_sort = $param->{'sort'};
970    
971                    my $html = qq{<td align="$align"};
972                    my $arrow = '';
973    
974                    if (lc($sort_what) eq lc($name)) {
975                            my $direction = lc($sort_direction);
976    
977                            # swap direction or fallback to default
978                            $direction =~ tr/ad/da/;
979                            $direction = 'a' unless ($direction =~ /[ad]/);
980    
981                            $param->{'sort'} = $name . '_' . $direction;
982                            $html .= ' style="border: 1px solid #808080;"';
983                    
984                            # add unicode arrow for direction
985                            $arrow .= '&nbsp;';
986                            $arrow .= $direction eq 'a'  ?  '&#9650;'
987                                    : $direction eq 'd'  ?  '&#9660;'
988                                    :                       ''
989                                    ;
990    
991                    } else {
992                            $param->{'sort'} = $name . '_a';
993                    }
994    
995                    $html .= '><a href="' . page_uri($param) . '">' . $display . '</a>' . $arrow . '</td>';
996                    $param->{'sort'} = $old_sort;
997    
998                    return $html;
999            }
1000    
1001            $retHTML .=
1002                    sort_header($param, 'Share', 'share', 'center') .
1003                    sort_header($param, 'Type and Name', 'path', 'center') .
1004                    sort_header($param, '#', 'num', 'center') .
1005                    sort_header($param, 'Size', 'size', 'center') .
1006                    sort_header($param, 'Date', 'date', 'center');
1007    
1008            $retHTML .= qq{
1009                  <td align="center">Media</td>                  <td align="center">Media</td>
1010                  </tr>                  </tr>
1011          };          };
# Line 803  sub displayGrid($) { Line 1025  sub displayGrid($) {
1025                  return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);                  return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);
1026          }          }
1027    
1028            my $sth_archived;
1029            my %archived_cache;
1030    
1031            sub check_archived($$$) {
1032                    my ($host, $share, $num) = @_;
1033    
1034                    if (my $html = $archived_cache{"$host $share $num"}) {
1035                            return $html;
1036                    }
1037    
1038                    $sth_archived ||= $dbh->prepare(qq{
1039                            select
1040                                    dvd_nr, note,
1041                                    count(archive_burned.copy) as copies
1042                            from archive
1043                            inner join archive_burned on archive_burned.archive_id = archive.id
1044                            inner join archive_backup on archive.id = archive_backup.archive_id
1045                            inner join backups on backups.id = archive_backup.backup_id
1046                            inner join hosts on hosts.id = backups.hostid
1047                            inner join shares on shares.id = backups.shareid
1048                            where hosts.name = ? and shares.name = ? and backups.num = ?
1049                            group by dvd_nr, note
1050                    });
1051    
1052                    my @mediums;
1053    
1054                    $sth_archived->execute($host, $share, $num);
1055                    while (my $row = $sth_archived->fetchrow_hashref()) {
1056                            push @mediums, '<abbr title="' .
1057                                    $row->{'note'} .
1058                                    ' [' . $row->{'copies'} . ']' .
1059                                    '">' .$row->{'dvd_nr'} .
1060                                    '</abbr>';
1061                    }
1062    
1063                    my $html = join(", ",@mediums);
1064                    $archived_cache{"$host $share $num"} = $html;
1065                    return $html;
1066            }
1067    
1068          my $i = $offset * $on_page;          my $i = $offset * $on_page;
1069    
1070          foreach $file (@{ $files }) {          foreach $file (@{ $files }) {
# Line 819  sub displayGrid($) { Line 1081  sub displayGrid($) {
1081                          qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .                          qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .
1082                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
1083                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
1084                          qq{<td class="fviewborder">} . '?' . qq{</td>};                          qq{<td class="fviewborder">} . check_archived( $file->{'hname'}, $file->{'sname'}, $file->{'backupnum'} ) . qq{</td>};
1085    
1086                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
1087          }          }
# Line 834  sub displayGrid($) { Line 1096  sub displayGrid($) {
1096          my $max_page = int( $results / $on_page );          my $max_page = int( $results / $on_page );
1097          my $page = 0;          my $page = 0;
1098    
1099          sub page_link($$$) {          sub page_uri($) {
1100                  my ($param,$page,$display) = @_;                  my $param = shift || die "no param?";
   
                 $param->{'offset'} = $page;  
1101    
1102                  my $html = '<a href = "' . $MyURL;                  my $uri = $MyURL;
1103                  my $del = '?';                  my $del = '?';
1104                  foreach my $k (keys %{ $param }) {                  foreach my $k (keys %{ $param }) {
1105                          if ($param->{$k}) {                          if ($param->{$k}) {
1106                                  $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};                                  $uri .= $del . $k . '=' . ${EscURI( $param->{$k} )};
1107                                  $del = '&';                                  $del = '&';
1108                          }                          }
1109                  }                  }
1110                  $html .= '">' . $display . '</a>';                  return $uri;
1111            }
1112    
1113            sub page_link($$$) {
1114                    my ($param,$page,$display) = @_;
1115    
1116                    $param->{'offset'} = $page if (defined($page));
1117    
1118                    my $html = '<a href = "' . page_uri($param) . '">' . $display . '</a>';
1119          }          }
1120    
1121          $retHTML .= '<div style="text-align: center;">';          $retHTML .= '<div style="text-align: center;">';

Legend:
Removed from v.171  
changed lines
  Added in v.303

  ViewVC Help
Powered by ViewVC 1.1.26