/[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 128 by dpavlin, Thu Sep 22 13:31:04 2005 UTC revision 262 by dpavlin, Tue Dec 13 00:10:44 2005 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 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 182  sub getHyperEstraier_url($) { Line 257  sub getHyperEstraier_url($) {
257          if ($use_hest =~ m#^http://#) {          if ($use_hest =~ m#^http://#) {
258                  $index_node_url = $use_hest;                  $index_node_url = $use_hest;
259          } else {          } else {
260                  $index_path = $TopDir . '/' . $index_path;                  $index_path = $TopDir . '/' . $use_hest;
261                  $index_path =~ s#//#/#g;                  $index_path =~ s#//#/#g;
262          }          }
263          return ($index_path, $index_node_url);          return ($index_path, $index_node_url);
# Line 239  sub getFilesHyperEstraier($) { Line 314  sub getFilesHyperEstraier($) {
314    
315  #       $cond->set_max( $offset + $on_page );  #       $cond->set_max( $offset + $on_page );
316          $cond->set_options( $HyperEstraier::Condition::SURE );          $cond->set_options( $HyperEstraier::Condition::SURE );
317          $cond->set_order( 'date NUMA' );          $cond->set_order( getSort('search', 'est', $param->{'sort'} ) );
318    
319          # get the result of search          # get the result of search
320          my @res;          my @res;
# Line 270  sub getFilesHyperEstraier($) { Line 345  sub getFilesHyperEstraier($) {
345                  }                  }
346    
347                  my $row;                  my $row;
348                  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/) {
349                          $row->{$c} = $doc->attr($c);                          $row->{$c} = $doc->attr($c);
350                  }                  }
351                  push @res, $row;                  push @res, $row;
# Line 288  sub getGzipName($$$) Line 363  sub getGzipName($$$)
363          $ret =~ s/\\h/$host/ge;          $ret =~ s/\\h/$host/ge;
364          $ret =~ s/\\s/$share/ge;          $ret =~ s/\\s/$share/ge;
365          $ret =~ s/\\n/$backupnum/ge;          $ret =~ s/\\n/$backupnum/ge;
366            
367            $ret =~ s/__+/_/g;
368    
369          return $ret;          return $ret;
370                    
371  }  }
372    
373  sub getBackupsNotBurned() {  sub get_tgz_size_by_name($) {
374            my $name = shift;
375    
376            my $tgz = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.$name;
377    
378            my $size = -1;
379    
380            if (-f "${tgz}.tar.gz") {
381                    $size = (stat("${tgz}.tar.gz"))[7];
382            } elsif (-d $tgz) {
383                    opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
384                    my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir);
385                    $size = 0;
386                    foreach my $part (@parts) {
387                            $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
388                    }
389                    closedir $dir;
390            } else {
391                    return -1;
392            }
393    
394            return $size;
395    }
396    
397    sub getGzipSize($$)
398    {
399            my ($hostID, $backupNum) = @_;
400            my $sql;
401            my $dbh = get_dbh();
402            
403            $sql = q{
404                                    SELECT hosts.name  as host,
405                                               shares.name as share,
406                                               backups.num as backupnum
407                                    FROM hosts, backups, shares
408                                    WHERE shares.id=backups.shareid AND
409                                              hosts.id =backups.hostid AND
410                                              hosts.id=? AND
411                                              backups.num=?
412                            };
413            my $sth = $dbh->prepare($sql);
414            $sth->execute($hostID, $backupNum);
415    
416            my $row = $sth->fetchrow_hashref();
417    
418            return get_tgz_size_by_name(
419                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})
420            );
421    }
422    
423    sub getVolumes($) {
424            my $id = shift;
425    
426            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
427    
428            my $sth = $dbh->prepare(qq{
429                    select
430                            size
431                    from backup_parts
432                    where backup_id = ?
433                    order by part_nr asc
434            });
435    
436            $sth->execute($id);
437    
438            my $cumulative_size = 0;
439            my $volumes = 1;
440    
441            while(my ($size) = $sth->fetchrow_array) {
442                    if ($cumulative_size + $size > $max_archive_size) {
443                            $volumes++;
444                            $cumulative_size = $size;
445                    } else {
446                            $cumulative_size += $size;
447                    }
448            }
449    
450            return ($volumes,$cumulative_size);
451    }
452    
453    sub getBackupsNotBurned($) {
454    
455            my $param = shift;
456          my $dbh = get_dbh();          my $dbh = get_dbh();
457    
458          my $sql = q{          my $order = getSort('burn', 'sql', $param->{'sort'});
459    
460    print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql order: $order\n";
461    
462            my $sql = qq{
463                  SELECT                  SELECT
464                          backups.hostID AS hostID,                          backups.hostID AS hostID,
465                          hosts.name AS host,                          hosts.name AS host,
466                          shares.name AS share,                          shares.name AS share,
467                          backups.id AS backupnum,                          backups.num AS backupnum,
468                          backups.type AS type,                          backups.type AS type,
469                          backups.date AS date,                          backups.date AS date,
470                          backups.size AS size                          date_part('epoch',now()) - backups.date as age,
471                            backups.size AS size,
472                            backups.id AS id,
473                            backups.inc_size AS inc_size,
474                            backups.parts AS parts
475                  FROM backups                  FROM backups
476                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
477                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
478                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id AND archive_backup.backup_id IS NULL                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
479                  WHERE backups.size > 0                  WHERE backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL
480                  GROUP BY                  GROUP BY
481                          backups.hostID,                          backups.hostID,
482                          hosts.name,                          hosts.name,
# Line 320  sub getBackupsNotBurned() { Line 486  sub getBackupsNotBurned() {
486                          backups.id,                          backups.id,
487                          backups.type,                          backups.type,
488                          backups.date,                          backups.date,
489                          backups.size                          backups.size,
490                  ORDER BY backups.date                          backups.inc_size,
491                            backups.parts
492                    ORDER BY $order
493          };          };
494          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
495          my @ret;          my @ret;
496          $sth->execute();          $sth->execute();
497    
498          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
499                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );
500                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
501                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =  
502                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
503                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  if ($row->{size} > $max_archive_size) {
504                  $row->{'fs_size'} = $fs_size;                          ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id});
505                    }
506    
507                    $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024);
508    
509                    # do some cluster calculation (approximate)
510                    $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 )  * 2);
511                    $row->{inc_size_calc} ||= $row->{inc_size};
512                  push @ret, $row;                  push @ret, $row;
513          }          }
514                
515          return @ret;                return @ret;
516  }  }
517    
518  sub displayBackupsGrid() {  sub displayBackupsGrid($) {
519    
520            my $param = shift;
521    
522            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
523            my $max_archive_file_size = $Conf{MaxArchiveFileSize}  || die "no MaxFileInSize";
524    
525          my $retHTML .= q{          my $retHTML .= q{
526                  <form id="forma" method="POST" action=};                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
                 $retHTML .= "\"".$MyURL."\"";  
                 $retHTML .= q{?action=burn>  
527          };          };
528    
529          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
530  <style>  <style type="text/css">
531  <!--  <!--
532    DIV#fixedBox {
 div#fixedBox {  
533          position: absolute;          position: absolute;
534          bottom: 1em;          top: 50em;
535          left: 0.5em;          left: -24%;
536          padding: 0.5em;          padding: 0.5em;
537          width: 10em;          width: 20%;
538          background: #e0f0e0;          background-color: #E0F0E0;
539          border: 1px solid #00ff00;          border: 1px solid #00C000;
 }  
 @media screen {  
         div#fixedBox {  
                 position: fixed;  
         }  
         /* Don't do this at home */  
         * html {  
                 overflow-y: hidden;  
         }  
         * html body {  
                 overflow-y: auto;  
                 height: 100%;  
                 padding: 0 1em 0 12em;  
                 font-size: 100%;  
         }  
         * html div#fixedBox {  
                 position: absolute;      
         }  
         /* All done. */  
540  }  }
541    
542  #mContainer {  DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
543          position: relative;          font-size: 10pt;
544    }
545    
546    FORM>DIV#fixedBox {
547            position: fixed !important;
548            left: 0.5em !important;
549            top: auto !important;
550            bottom: 1em !important;
551            width: 15% !important;
552    }
553    
554    DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
555            border: 1px solid #00C000;
556    }
557    
558    DIV#fixedBox #note {
559            display: block;
560          width: 100%;          width: 100%;
         height: 1.1em;  
         padding: 0px;  
         border: 1px solid #000000;  
561  }  }
562    
563  #gradient {  DIV#fixedBox #submitBurner {
564          position: absolute;          display: block;
         top: 0px;  
         left: 0px;  
565          width: 100%;          width: 100%;
566            margin-top: 0.5em;
567            cursor: pointer;
568    }
569    
570    * HTML {
571            overflow-y: hidden;
572    }
573    
574    * HTML BODY {
575            overflow-y: auto;
576          height: 100%;          height: 100%;
577          display: block;          font-size: 100%;
         background-color: #ffff00;  
578  }  }
579    
580  #mask {  * HTML DIV#fixedBox {
581          position: absolute;          position: absolute;
582          top: 0px;  }
583          left: 0px;  
584    #mContainer, #gradient, #mask, #progressIndicator {
585            display: block;
586          width: 100%;          width: 100%;
587          height: 100%;          font-size: 10pt;
588            font-weight: bold;
589            text-align: center;
590            vertical-align: middle;
591            padding: 1px;
592    }
593    
594    #gradient, #mask, #progressIndicator {
595            left: 0;
596            border-width: 1px;
597            border-style: solid;
598            border-color: #000000;
599            color: #404040;
600            margin: 0.4em;
601            position: absolute;
602            margin-left: -1px;
603            margin-top: -1px;
604            margin-bottom: -1px;
605            overflow: hidden;
606    }
607    
608    #mContainer {
609          display: block;          display: block;
610          font-size: 1px;          position: relative;
611            padding: 0px;
612            margin-top: 0.4em;
613            margin-bottom: 0.5em;
614    }
615    
616    #gradient {
617            z-index: 1;
618            background-color: #FFFF00;
619    }
620    
621    #mask {
622            z-index: 2;
623          background-color: #FFFFFF;          background-color: #FFFFFF;
         overflow: hidden;  
624  }  }
625    
626  #progressIndicator {  #progressIndicator {
627          position: absolute;          z-index: 3;
628          top: 0px;          background-color: transparent;
629          left: 0px;  }
630    
631    #volumes {
632            padding: 0.4em;
633            display: none;
634          width: 100%;          width: 100%;
635          height: 100%;          font-size: 80%;
636          display: block;          color: #ff0000;
         font-weight: bold;  
         color: #404040;  
         font-size: 10pt;  
637          text-align: center;          text-align: center;
638  }  }
   
639  -->  -->
640  </style>  </style>
641  <script language="javascript" type="text/javascript">  <script type="text/javascript">
642  <!--  <!--
643    
644  var debug_div = null;  var debug_div = null;
645  var media_size = 4400 * 1024;  EOF3
646    
647            # take maximum archive size from configuration
648            $retHTML .= qq{
649    var media_size = $max_archive_size ;
650    var max_file_size = $max_archive_file_size;
651    
652    };
653    
654            $retHTML .= <<'EOF3';
655    
656  function debug(msg) {  function debug(msg) {
657  //      return; // Disable debugging  //      return; // Disable debugging
# Line 460  function element_id(name,element) { Line 681  function element_id(name,element) {
681  }  }
682    
683  function checkAll(location) {  function checkAll(location) {
684          var len = element_id('forma').elements.length;          var f = element_id('forma') || null;
685            if (!f) return false;
686    
687            var len = f.elements.length;
688          var check_all = element_id('allFiles');          var check_all = element_id('allFiles');
689            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
690    
691          for (var i = 0; i < len; i++) {          for (var i = 0; i < len; i++) {
692                    var e = f.elements[i];
693                  var e = element_id('forma').elements[i];                  if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
                 if ((e.checked || !e.checked) && e.name != 'all') {  
694                          if (check_all.checked) {                          if (check_all.checked) {
695                                  e.checked = true;                                  if (e.checked) continue;
696                                    var el = element_id("fss" + e.name.substr(3));
697                                    var size = parseInt(el.value) || 0;
698                                    debug('suma: '+suma+' size: '+size);
699                                    if ((suma + size) < media_size) {
700                                            suma += size;
701                                            e.checked = true;
702                                    } else {
703                                            break;
704                                    }
705                          } else {                          } else {
706                                  e.checked = false;                                  e.checked = false;
707                          }                          }
708                  }                  }
709          }          }
710            update_sum(suma);
711    }
712    
713          sumiraj();  function update_sum(suma, suma_disp) {
714            if (! suma_disp) suma_disp = suma;
715            suma_disp = Math.floor(suma_disp / 1024);
716            element_id('forma').elements['totalsize_kb'].value = suma_disp;
717            element_id('forma').elements['totalsize'].value = suma;
718            pbar_set(suma, media_size);
719            debug('total size: ' + suma);
720  }  }
721        
722  function sumiraj(e) {  function update_size(name, checked, suma) {
723          var suma = parseInt(element_id('forma').totalsize.value) || 0;          var size = parseInt( element_id("fss" + name).value);
724          var len = element_id('forma').elements.length;  
725          if (e) {          if (checked) {
726                  var size = parseInt( element_id("fss" + e.name.substr(3)).value );                  suma += size;
727                  if (e.checked) {          } else {
728                          suma += size;                  suma -= size;
729            }
730    
731            var volumes = parseInt( element_id("prt" + name).value);
732            debug('update_size('+name+','+checked+') suma: '+suma+' volumes: '+volumes);
733            if (volumes > 1) {
734                    if (checked) {
735                            element_id("volumes").innerHTML = "This will take "+volumes+" mediums!";
736                            element_id("volumes").style.display = 'block';
737                            suma = size;
738                            update_sum(suma);
739                  } else {                  } else {
740                          suma -= size;                          suma -= size;
741                            element_id("volumes").style.display = 'none';
742                  }                  }
743            }
744    
745            return suma;
746    }
747    
748    function sumiraj(e) {
749            var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
750            var len = element_id('forma').elements.length;
751            if (e) {
752                    suma = update_size(e.name.substr(3), e.checked, suma);
753                    if (suma < 0) suma = 0;
754          } else {          } else {
755                  suma = 0;                  suma = 0;
756                  for (var i = 0; i < len; i++) {                  for (var i = 0; i < len; i++) {
757                          var e = element_id('forma').elements[i];                          var fel = element_id('forma').elements[i];
758                          if (e.name != 'all' && e.checked && e.name.substr(0,3) == 'fcb') {                          if (fel.name != 'all' && fel.checked && fel.name.substr(0,3) == 'fcb') {
759                                  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;  
760                          }                          }
761                  }                  }
762          }          }
763          element_id('forma').totalsize.value = suma;          update_sum(suma);
         pbar_set(suma, media_size);  
         debug('total size: '+suma);  
764          return suma;          return suma;
765  }  }
766    
767  /* progress bar */  /* progress bar */
768    
769  var _pbar_width = 0;  var _pbar_width = null;
770  var _pbar_warn = 10;    // change color in last 10%  var _pbar_warn = 10;    // change color in last 10%
771    
772  function pbar_reset() {  function pbar_reset() {
773          element_id("mask").style.left = "0px";          element_id("mask").style.left = "0px";
774          _pbar_width = element_id("mContainer").offsetWidth - 2;          _pbar_width = element_id("mContainer").offsetWidth - 2;
775          element_id("mask").style.width = _pbar_width + "px";          element_id("mask").style.width = _pbar_width + "px";
         element_id("progressIndicator").style.zIndex  = 10;  
776          element_id("mask").style.display = "block";          element_id("mask").style.display = "block";
777            element_id("progressIndicator").style.zIndex  = 10;
778          element_id("progressIndicator").innerHTML = "0";          element_id("progressIndicator").innerHTML = "0";
779  }  }
780    
781  function dec2hex(d) {  function dec2hex(d) {
782          var hch="0123456789ABCDEF";          var hch = '0123456789ABCDEF';
783          var a=d%16;          var a = d % 16;
784          var q=(d-a)/16;          var q = (d - a) / 16;
785          return hch.charAt(q)+hch.charAt(a);          return hch.charAt(q) + hch.charAt(a);
786  }  }
787    
   
788  function pbar_set(amount, max) {  function pbar_set(amount, max) {
789            debug('pbar_set('+amount+', '+max+')');
790    
791          debug('pbar_set( '+amount+' , '+max+' )');          if (_pbar_width == null) {
792                    var _mc = element_id("mContainer");
793          curWidth = parseInt(element_id("mask").offsetWidth);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
794          curLeft = parseInt(element_id("mask").offsetLeft);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
795                    if (_pbar_width == null) _pbar_width = 0;
796            }
797    
798          var pcnt = Math.floor( amount * 100 / max );          var pcnt = Math.floor(amount * 100 / max);
799          var p90 = 100 - _pbar_warn;          var p90 = 100 - _pbar_warn;
800          var pcol = pcnt - p90;          var pcol = pcnt - p90;
801          if (pcol < _pbar_warn) {          if (Math.round(pcnt) <= 100) {
802                  if (pcol < 0) pcol = 0;                  if (pcol < 0) pcol = 0;
803                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
804                  if (e && e.disabled) {                  debug('enable_button');
805                          debug('enable_button');                  e.disabled = false;
806                          var a = e.getAttributeNode('disabled') || null;                  var a = e.getAttributeNode('disabled') || null;
807                          if (a) e.removeAttributeNode(a);                  if (a) e.removeAttributeNode(a);
808                  }          } else {
         } else if (pcol > _pbar_warn) {  
809                  debug('disable button');                  debug('disable button');
810                  pcol = _pbar_warn;                  pcol = _pbar_warn;
811                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
812                  if (! e.disabled) e.disabled = true;                  if (!e.disabled) e.disabled = true;
813          }          }
814          var col_g = Math.floor( ( _pbar_warn - pcol ) * 255 / _pbar_warn );          var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
815          var col = '#ff' + dec2hex( col_g ) + '00';          var col = '#FF' + dec2hex(col_g) + '00';
816    
817          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
818          element_id("gradient").style.backgroundColor = col;          element_id("gradient").style.backgroundColor = col;
819    
         var size = parseInt( _pbar_width * amount / max );  
   
         curWidth = _pbar_width - size;  
         curLeft = size ;  
   
         //debug('size: '+size+' curWidth '+curWidth+' curLeft: '+curLeft);  
   
820          element_id("progressIndicator").innerHTML = pcnt + '%';          element_id("progressIndicator").innerHTML = pcnt + '%';
821          //element_id("progressIndicator").innerHTML = amount;          //element_id("progressIndicator").innerHTML = amount;
822    
823          if (curLeft > _pbar_width) {          element_id("mask").style.clip = 'rect(' + Array(
824                  element_id("mask").style.display = "none";                  '0px',
825                  return;                  element_id("mask").offsetWidth + 'px',
826          } else {                  element_id("mask").offsetHeight + 'px',
827                  element_id("mask").style.display = "";                  Math.round(_pbar_width * amount / max) + 'px'
828          }          ).join(' ') + ')';
   
         //if(parseInt(element_id("mask").offsetWidth)>10)  
         element_id("mask").style.width = curWidth + "px";  
         element_id("mask").style.left = curLeft + "px";  
   
829  }  }
830    
831  if (!self.body) self.body = new Object();  if (!self.body) self.body = new Object();
832  self.onload = self.document.onload = self.body.onload = function() {  self.onload = self.document.onload = self.body.onload = function() {
833          pbar_reset();          //pbar_reset();
834          sumiraj();          sumiraj();
835  }  };
836    
837  //-->  // -->
838  </script>  </script>
839  <div id="fixedBox">  <div id="fixedBox">
840    
841  Size:  <input type="hidden" name="totalsize"/>
842  <input type="text" name="totalsize" size="7" readonly>  Size: <input type="text" name="totalsize_kb" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
843    
844  <div id="mContainer">  <div id="mContainer">
845          <div id="gradient"></div>          <div id="gradient">&nbsp;</div>
846          <div id="mask"></div>          <div id="mask">&nbsp;</div>
847          <div id="progressIndicator">&nbsp;</div>          <div id="progressIndicator">0%</div>
848  </div>  </div>
   
849  <br/>  <br/>
850    
851    <div id="volumes">&nbsp;</div>
852    
853  Note:  Note:
854  <br/>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
855  <textarea name="note" cols="10" rows="5">  
856  </textarea>  <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
 <br/>  
 <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner">  
857    
858  </div>  </div>
859  <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">  <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">
# Line 620  EOF3 Line 868  EOF3
868                          <td class="tableheader">                          <td class="tableheader">
869                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
870                          </td>                          </td>
871                          <td align="center">Share</td>          } .
872                          <td align="center">Backup no</td>                  sort_header($param, 'Share', 'share', 'center') .
873                    sort_header($param, '#', 'num', 'center') .
874            qq{
875                          <td align="center">Type</td>                          <td align="center">Type</td>
876                          <td align="center">date</td>          } .
877                          <td align="center">age/days</td>                  sort_header($param, 'Date', 'date', 'center') .
878                          <td align="center">size/MB</td>                  sort_header($param, 'Age/days', 'age', 'center') .
879                          <td align="center">gzip size</td>                  sort_header($param, 'Size/Mb', 'size', 'center') .
880                          </tr>                  sort_header($param, 'gzip size/Kb', 'incsize', 'center') .
881            qq{
882                            <td align="center">medias</td></tr>
883          };          };
884    
885          my @color = (' bgcolor="#e0e0e0"', '');          my @color = (' bgcolor="#e0e0e0"', '');
# Line 636  EOF3 Line 887  EOF3
887          my $i = 0;          my $i = 0;
888          my $host = '';          my $host = '';
889    
890          foreach my $backup ( getBackupsNotBurned() ) {          foreach my $backup ( getBackupsNotBurned($param) ) {
891    
892                  if ($host ne $backup->{'host'}) {                  if ($host ne $backup->{'host'}) {
893                          $i++;                          $i++;
# Line 644  EOF3 Line 895  EOF3
895                  }                  }
896                  my $ftype = "";                  my $ftype = "";
897    
898                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
899    
900                  $retHTML .=                  $retHTML .=
901                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
902                          <td class="fview">';                          <td class="fview">';
903                  # FIXME  
904                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);                  if (($backup->{'inc_size'} || 0) > 0) {
                 if (($backup->{'fs_size'} || 0) > 0) {  
905                          $retHTML .= '                          $retHTML .= '
906                          <input type="checkbox" name="fcb' .                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
                         $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                         '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                         '" onClick="sumiraj(this);">';  
907                  }                  }
908    
909                    my $img_url = $Conf{CgiImageDirURL};
910    
911                  $retHTML .=                  $retHTML .=
912                          '</td>' .                          '</td>' .
913                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 664  EOF3 Line 916  EOF3
916                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
917                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
918                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
919                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . sprintf("%0.1f", $backup->{'inc_size'} / 1024 ) .
920                          '<input type="hidden" iD="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '" value="'. $backup->{'fs_size'} .'"></td>' .                          '<input type="hidden" id="fss'.$checkbox_key .'" value="'. $backup->{'inc_size_calc'} .'"></td>' .
921                            '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'volumes'} .'"></td>' .
922                            '<td align="left">' . ( qq{<img src="$img_url/icon-cd.gif" alt="media">} x $backup->{volumes} ) . '</td>' .
923    
924                          "</tr>\n";                          "</tr>\n";
925          }          }
# Line 717  sub displayGrid($) { Line 971  sub displayGrid($) {
971          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
972                  <tr class="fviewheader">                  <tr class="fviewheader">
973                  <td></td>                  <td></td>
974                  <td align="center">Share</td>          };
975                  <td align="center">Type and Name</td>  
976                  <td align="center">#</td>          sub sort_header($$$$) {
977                  <td align="center">Size</td>                  my ($param, $display, $name, $align) = @_;
978                  <td align="center">Date</td>  
979                    my ($sort_what, $sort_direction) = split(/_/,$param->{'sort'},2);
980    
981                    my $old_sort = $param->{'sort'};
982    
983                    my $html = qq{<td align="$align"};
984                    my $arrow = '';
985    
986                    if (lc($sort_what) eq lc($name)) {
987                            my $direction = lc($sort_direction);
988    
989                            # swap direction or fallback to default
990                            $direction =~ tr/ad/da/;
991                            $direction = 'a' unless ($direction =~ /[ad]/);
992    
993                            $param->{'sort'} = $name . '_' . $direction;
994                            $html .= ' style="border: 1px solid #808080;"';
995                    
996                            # add unicode arrow for direction
997                            $arrow .= '&nbsp;';
998                            $arrow .= $direction eq 'a'  ?  '&#9650;'
999                                    : $direction eq 'd'  ?  '&#9660;'
1000                                    :                       ''
1001                                    ;
1002    
1003                    } else {
1004                            $param->{'sort'} = $name . '_a';
1005                    }
1006    
1007                    $html .= '><a href="' . page_uri($param) . '">' . $display . '</a>' . $arrow . '</td>';
1008                    $param->{'sort'} = $old_sort;
1009    
1010                    return $html;
1011            }
1012    
1013            $retHTML .=
1014                    sort_header($param, 'Share', 'share', 'center') .
1015                    sort_header($param, 'Type and Name', 'path', 'center') .
1016                    sort_header($param, '#', 'num', 'center') .
1017                    sort_header($param, 'Size', 'size', 'center') .
1018                    sort_header($param, 'Date', 'date', 'center');
1019    
1020            $retHTML .= qq{
1021                  <td align="center">Media</td>                  <td align="center">Media</td>
1022                  </tr>                  </tr>
1023          };          };
# Line 741  sub displayGrid($) { Line 1037  sub displayGrid($) {
1037                  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, @_);
1038          }          }
1039    
1040            my $sth_archived;
1041            my %archived_cache;
1042    
1043            sub check_archived($$$) {
1044                    my ($host, $share, $num) = @_;
1045    
1046                    if (my $html = $archived_cache{"$host $share $num"}) {
1047                            return $html;
1048                    }
1049    
1050                    $sth_archived ||= $dbh->prepare(qq{
1051                            select
1052                                    dvd_nr, note,
1053                                    count(archive_burned.copy) as copies
1054                            from archive
1055                            inner join archive_burned on archive_burned.archive_id = archive.id
1056                            inner join archive_backup on archive.id = archive_backup.archive_id
1057                            inner join backups on backups.id = archive_backup.backup_id
1058                            inner join hosts on hosts.id = backups.hostid
1059                            inner join shares on shares.id = backups.shareid
1060                            where hosts.name = ? and shares.name = ? and backups.num = ?
1061                            group by dvd_nr, note
1062                    });
1063    
1064                    my @mediums;
1065    
1066                    $sth_archived->execute($host, $share, $num);
1067                    while (my $row = $sth_archived->fetchrow_hashref()) {
1068                            push @mediums, '<abbr title="' .
1069                                    $row->{'note'} .
1070                                    ' [' . $row->{'copies'} . ']' .
1071                                    '">' .$row->{'dvd_nr'} .
1072                                    '</abbr>';
1073                    }
1074    
1075                    my $html = join(", ",@mediums);
1076                    $archived_cache{"$host $share $num"} = $html;
1077                    return $html;
1078            }
1079    
1080          my $i = $offset * $on_page;          my $i = $offset * $on_page;
1081    
1082          foreach $file (@{ $files }) {          foreach $file (@{ $files }) {
# Line 757  sub displayGrid($) { Line 1093  sub displayGrid($) {
1093                          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>} .
1094                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
1095                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
1096                          qq{<td class="fviewborder">} . '?' . qq{</td>};                          qq{<td class="fviewborder">} . check_archived( $file->{'hname'}, $file->{'sname'}, $file->{'backupnum'} ) . qq{</td>};
1097    
1098                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
1099          }          }
# Line 772  sub displayGrid($) { Line 1108  sub displayGrid($) {
1108          my $max_page = int( $results / $on_page );          my $max_page = int( $results / $on_page );
1109          my $page = 0;          my $page = 0;
1110    
1111          sub page_link($$$) {          sub page_uri($) {
1112                  my ($param,$page,$display) = @_;                  my $param = shift || die "no param?";
   
                 $param->{'offset'} = $page;  
1113    
1114                  my $html = '<a href = "' . $MyURL;                  my $uri = $MyURL;
1115                  my $del = '?';                  my $del = '?';
1116                  foreach my $k (keys %{ $param }) {                  foreach my $k (keys %{ $param }) {
1117                          if ($param->{$k}) {                          if ($param->{$k}) {
1118                                  $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};                                  $uri .= $del . $k . '=' . ${EscURI( $param->{$k} )};
1119                                  $del = '&';                                  $del = '&';
1120                          }                          }
1121                  }                  }
1122                  $html .= '">' . $display . '</a>';                  return $uri;
1123            }
1124    
1125            sub page_link($$$) {
1126                    my ($param,$page,$display) = @_;
1127    
1128                    $param->{'offset'} = $page if (defined($page));
1129    
1130                    my $html = '<a href = "' . page_uri($param) . '">' . $display . '</a>';
1131          }          }
1132    
1133          $retHTML .= '<div style="text-align: center;">';          $retHTML .= '<div style="text-align: center;">';

Legend:
Removed from v.128  
changed lines
  Added in v.262

  ViewVC Help
Powered by ViewVC 1.1.26