/[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 253 by dpavlin, Mon Dec 12 13:41:08 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 { !/^\./ && -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            }
391    
392            return $size;
393    }
394    
395    sub getGzipSize($$)
396    {
397            my ($hostID, $backupNum) = @_;
398            my $sql;
399            my $dbh = get_dbh();
400            
401            $sql = q{
402                                    SELECT hosts.name  as host,
403                                               shares.name as share,
404                                               backups.num as backupnum
405                                    FROM hosts, backups, shares
406                                    WHERE shares.id=backups.shareid AND
407                                              hosts.id =backups.hostid AND
408                                              hosts.id=? AND
409                                              backups.num=?
410                            };
411            my $sth = $dbh->prepare($sql);
412            $sth->execute($hostID, $backupNum);
413    
414            my $row = $sth->fetchrow_hashref();
415    
416            return get_tgz_size_by_name(
417                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})
418            );
419    }
420    
421    sub getBackupsNotBurned($) {
422    
423            my $param = shift;
424          my $dbh = get_dbh();          my $dbh = get_dbh();
425    
426          my $sql = q{          my $order = getSort('burn', 'sql', $param->{'sort'});
427    
428    print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql order: $order\n";
429    
430            my $sql = qq{
431                  SELECT                  SELECT
432                          backups.hostID AS hostID,                          backups.hostID AS hostID,
433                          hosts.name AS host,                          hosts.name AS host,
434                          shares.name AS share,                          shares.name AS share,
435                          backups.id AS backupnum,                          backups.num AS backupnum,
436                          backups.type AS type,                          backups.type AS type,
437                          backups.date AS date,                          backups.date AS date,
438                          backups.size AS size                          date_part('epoch',now()) - backups.date as age,
439                            backups.size AS size,
440                            backups.id AS id,
441                            backups.inc_size AS inc_size,
442                            backups.parts AS parts
443                  FROM backups                  FROM backups
444                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
445                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
446                  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
447                  WHERE backups.size > 0                  WHERE backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL
448                  GROUP BY                  GROUP BY
449                          backups.hostID,                          backups.hostID,
450                          hosts.name,                          hosts.name,
# Line 320  sub getBackupsNotBurned() { Line 454  sub getBackupsNotBurned() {
454                          backups.id,                          backups.id,
455                          backups.type,                          backups.type,
456                          backups.date,                          backups.date,
457                          backups.size                          backups.size,
458                  ORDER BY backups.date                          backups.inc_size,
459                            backups.parts
460                    ORDER BY $order
461          };          };
462          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
463          my @ret;          my @ret;
464          $sth->execute();          $sth->execute();
465    
466          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
467                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );
468                    #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
469                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
470                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =  
471                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  # do some cluster calculation (approximate) and convert to kB
472                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2);
                 $row->{'fs_size'} = $fs_size;  
473                  push @ret, $row;                  push @ret, $row;
474          }          }
475                
476          return @ret;                return @ret;      
477  }  }
478    
479  sub displayBackupsGrid() {  sub displayBackupsGrid($) {
480    
481            my $param = shift;
482    
483            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
484            my $max_archive_file_size = $Conf{MaxArchiveFileSize}  || die "no MaxFileInSize";
485    
486          my $retHTML .= q{          my $retHTML .= q{
487                  <form id="forma" method="POST" action=};                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
                 $retHTML .= "\"".$MyURL."\"";  
                 $retHTML .= q{?action=burn>  
488          };          };
489    
490          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
491  <style>  <style type="text/css">
492  <!--  <!--
493    DIV#fixedBox {
 div#fixedBox {  
494          position: absolute;          position: absolute;
495          bottom: 1em;          top: 50em;
496          left: 0.5em;          left: -24%;
497          padding: 0.5em;          padding: 0.5em;
498          width: 10em;          width: 20%;
499          background: #e0f0e0;          background-color: #E0F0E0;
500          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. */  
501  }  }
502    
503  #mContainer {  DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
504          position: relative;          font-size: 10pt;
505    }
506    
507    FORM>DIV#fixedBox {
508            position: fixed !important;
509            left: 0.5em !important;
510            top: auto !important;
511            bottom: 1em !important;
512            width: 15% !important;
513    }
514    
515    DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
516            border: 1px solid #00C000;
517    }
518    
519    DIV#fixedBox #note {
520            display: block;
521          width: 100%;          width: 100%;
         height: 1.1em;  
         padding: 0px;  
         border: 1px solid #000000;  
522  }  }
523    
524  #gradient {  DIV#fixedBox #submitBurner {
525          position: absolute;          display: block;
         top: 0px;  
         left: 0px;  
526          width: 100%;          width: 100%;
527            margin-top: 0.5em;
528            cursor: pointer;
529    }
530    
531    * HTML {
532            overflow-y: hidden;
533    }
534    
535    * HTML BODY {
536            overflow-y: auto;
537          height: 100%;          height: 100%;
538          display: block;          font-size: 100%;
         background-color: #ffff00;  
539  }  }
540    
541  #mask {  * HTML DIV#fixedBox {
542          position: absolute;          position: absolute;
543          top: 0px;  }
544          left: 0px;  
545    #mContainer, #gradient, #mask, #progressIndicator {
546            display: block;
547          width: 100%;          width: 100%;
548          height: 100%;          font-size: 10pt;
549            font-weight: bold;
550            text-align: center;
551            vertical-align: middle;
552            padding: 1px;
553    }
554    
555    #gradient, #mask, #progressIndicator {
556            left: 0;
557            border-width: 1px;
558            border-style: solid;
559            border-color: #000000;
560            color: #404040;
561            margin: 0.4em;
562            position: absolute;
563            margin-left: -1px;
564            margin-top: -1px;
565            margin-bottom: -1px;
566            overflow: hidden;
567    }
568    
569    #mContainer {
570          display: block;          display: block;
571          font-size: 1px;          position: relative;
572            padding: 0px;
573            margin-top: 0.4em;
574            margin-bottom: 0.5em;
575    }
576    
577    #gradient {
578            z-index: 1;
579            background-color: #FFFF00;
580    }
581    
582    #mask {
583            z-index: 2;
584          background-color: #FFFFFF;          background-color: #FFFFFF;
         overflow: hidden;  
585  }  }
586    
587  #progressIndicator {  #progressIndicator {
588          position: absolute;          z-index: 3;
589          top: 0px;          background-color: transparent;
590          left: 0px;  }
591    
592    #parts {
593            padding: 0.4em;
594            display: none;
595          width: 100%;          width: 100%;
596          height: 100%;          font-size: 80%;
597          display: block;          color: #ff0000;
         font-weight: bold;  
         color: #404040;  
         font-size: 10pt;  
598          text-align: center;          text-align: center;
599  }  }
   
600  -->  -->
601  </style>  </style>
602  <script language="javascript" type="text/javascript">  <script type="text/javascript">
603  <!--  <!--
604    
605  var debug_div = null;  var debug_div = null;
606  var media_size = 4400 * 1024;  EOF3
607    
608            # take maximum archive size from configuration
609            $retHTML .= qq{
610    var media_size = $max_archive_size ;
611    var max_file_size = $max_archive_file_size;
612    
613    };
614    
615            $retHTML .= <<'EOF3';
616    
617  function debug(msg) {  function debug(msg) {
618  //      return; // Disable debugging          return; // Disable debugging
619    
620          if (! debug_div) debug_div = document.getElementById('debug');          if (! debug_div) debug_div = document.getElementById('debug');
621    
# Line 460  function element_id(name,element) { Line 642  function element_id(name,element) {
642  }  }
643    
644  function checkAll(location) {  function checkAll(location) {
645          var len = element_id('forma').elements.length;          var f = element_id('forma') || null;
646            if (!f) return false;
647    
648            var len = f.elements.length;
649          var check_all = element_id('allFiles');          var check_all = element_id('allFiles');
650            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
651    
652          for (var i = 0; i < len; i++) {          for (var i = 0; i < len; i++) {
653                    var e = f.elements[i];
654                  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') {  
655                          if (check_all.checked) {                          if (check_all.checked) {
656                                  e.checked = true;                                  if (e.checked) continue;
657                                    var el = element_id("fss" + e.name.substr(3));
658                                    var size = parseInt(el.value) || 0;
659                                    debug('suma: '+suma+' size: '+size);
660                                    if ((suma + size) < media_size) {
661                                            suma += size;
662                                            e.checked = true;
663                                    } else {
664                                            break;
665                                    }
666                          } else {                          } else {
667                                  e.checked = false;                                  e.checked = false;
668                          }                          }
669                  }                  }
670          }          }
671            update_sum(suma);
672    }
673    
674          sumiraj();  function update_sum(suma, suma_disp) {
675            if (! suma_disp) suma_disp = suma;
676            element_id('forma').elements['totalsize'].value = suma_disp;
677            pbar_set(suma, media_size);
678            debug('total size: ' + suma);
679  }  }
680        
681  function sumiraj(e) {  function sumiraj(e) {
682          var suma = parseInt(element_id('forma').totalsize.value) || 0;          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
683          var len = element_id('forma').elements.length;          var len = element_id('forma').elements.length;
684          if (e) {          if (e) {
685                  var size = parseInt( element_id("fss" + e.name.substr(3)).value );                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);
686                  if (e.checked) {                  if (e.checked) {
687                          suma += size;                          suma += size;
688                  } else {                  } else {
689                          suma -= size;                          suma -= size;
690                  }                  }
691    
692                    var parts = parseInt( element_id("prt" + e.name.substr(3)).value);
693                    if (suma > max_file_size && suma == size && parts > 1) {
694                            element_id("parts").innerHTML = "This will take "+parts+" mediums!";
695                            element_id("parts").style.display = 'block';
696                            update_sum(media_size, suma);
697                            suma = media_size;
698                            return suma;
699                    } else {
700                            element_id("parts").style.display = 'none';
701                    }
702    
703                    if (suma < 0) suma = 0;
704          } else {          } else {
705                  suma = 0;                  suma = 0;
706                  for (var i = 0; i < len; i++) {                  for (var i = 0; i < len; i++) {
# Line 498  function sumiraj(e) { Line 711  function sumiraj(e) {
711                          }                          }
712                  }                  }
713          }          }
714          element_id('forma').totalsize.value = suma;          update_sum(suma);
         pbar_set(suma, media_size);  
         debug('total size: '+suma);  
715          return suma;          return suma;
716  }  }
717    
718  /* progress bar */  /* progress bar */
719    
720  var _pbar_width = 0;  var _pbar_width = null;
721  var _pbar_warn = 10;    // change color in last 10%  var _pbar_warn = 10;    // change color in last 10%
722    
723  function pbar_reset() {  function pbar_reset() {
724          element_id("mask").style.left = "0px";          element_id("mask").style.left = "0px";
725          _pbar_width = element_id("mContainer").offsetWidth - 2;          _pbar_width = element_id("mContainer").offsetWidth - 2;
726          element_id("mask").style.width = _pbar_width + "px";          element_id("mask").style.width = _pbar_width + "px";
         element_id("progressIndicator").style.zIndex  = 10;  
727          element_id("mask").style.display = "block";          element_id("mask").style.display = "block";
728            element_id("progressIndicator").style.zIndex  = 10;
729          element_id("progressIndicator").innerHTML = "0";          element_id("progressIndicator").innerHTML = "0";
730  }  }
731    
732  function dec2hex(d) {  function dec2hex(d) {
733          var hch="0123456789ABCDEF";          var hch = '0123456789ABCDEF';
734          var a=d%16;          var a = d % 16;
735          var q=(d-a)/16;          var q = (d - a) / 16;
736          return hch.charAt(q)+hch.charAt(a);          return hch.charAt(q) + hch.charAt(a);
737  }  }
738    
   
739  function pbar_set(amount, max) {  function pbar_set(amount, max) {
740            debug('pbar_set('+amount+', '+max+')');
741    
742          debug('pbar_set( '+amount+' , '+max+' )');          if (_pbar_width == null) {
743                    var _mc = element_id("mContainer");
744          curWidth = parseInt(element_id("mask").offsetWidth);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
745          curLeft = parseInt(element_id("mask").offsetLeft);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
746                    if (_pbar_width == null) _pbar_width = 0;
747            }
748    
749          var pcnt = Math.floor( amount * 100 / max );          var pcnt = Math.floor(amount * 100 / max);
750          var p90 = 100 - _pbar_warn;          var p90 = 100 - _pbar_warn;
751          var pcol = pcnt - p90;          var pcol = pcnt - p90;
752          if (pcol < _pbar_warn) {          if (Math.round(pcnt) <= 100) {
753                  if (pcol < 0) pcol = 0;                  if (pcol < 0) pcol = 0;
754                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
755                  if (e && e.disabled) {                  debug('enable_button');
756                          debug('enable_button');                  e.disabled = false;
757                          var a = e.getAttributeNode('disabled') || null;                  var a = e.getAttributeNode('disabled') || null;
758                          if (a) e.removeAttributeNode(a);                  if (a) e.removeAttributeNode(a);
759                  }          } else {
         } else if (pcol > _pbar_warn) {  
760                  debug('disable button');                  debug('disable button');
761                  pcol = _pbar_warn;                  pcol = _pbar_warn;
762                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
763                  if (! e.disabled) e.disabled = true;                  if (!e.disabled) e.disabled = true;
764          }          }
765          var col_g = Math.floor( ( _pbar_warn - pcol ) * 255 / _pbar_warn );          var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
766          var col = '#ff' + dec2hex( col_g ) + '00';          var col = '#FF' + dec2hex(col_g) + '00';
767    
768          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
769          element_id("gradient").style.backgroundColor = col;          element_id("gradient").style.backgroundColor = col;
770    
         var size = parseInt( _pbar_width * amount / max );  
   
         curWidth = _pbar_width - size;  
         curLeft = size ;  
   
         //debug('size: '+size+' curWidth '+curWidth+' curLeft: '+curLeft);  
   
771          element_id("progressIndicator").innerHTML = pcnt + '%';          element_id("progressIndicator").innerHTML = pcnt + '%';
772          //element_id("progressIndicator").innerHTML = amount;          //element_id("progressIndicator").innerHTML = amount;
773    
774          if (curLeft > _pbar_width) {          element_id("mask").style.clip = 'rect(' + Array(
775                  element_id("mask").style.display = "none";                  '0px',
776                  return;                  element_id("mask").offsetWidth + 'px',
777          } else {                  element_id("mask").offsetHeight + 'px',
778                  element_id("mask").style.display = "";                  Math.round(_pbar_width * amount / max) + 'px'
779          }          ).join(' ') + ')';
   
         //if(parseInt(element_id("mask").offsetWidth)>10)  
         element_id("mask").style.width = curWidth + "px";  
         element_id("mask").style.left = curLeft + "px";  
   
780  }  }
781    
782  if (!self.body) self.body = new Object();  if (!self.body) self.body = new Object();
783  self.onload = self.document.onload = self.body.onload = function() {  self.onload = self.document.onload = self.body.onload = function() {
784          pbar_reset();          //pbar_reset();
785          sumiraj();          sumiraj();
786  }  };
787    
788  //-->  // -->
789  </script>  </script>
790  <div id="fixedBox">  <div id="fixedBox">
791    
792  Size:  Size: <input type="text" name="totalsize" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
 <input type="text" name="totalsize" size="7" readonly>  
793    
794  <div id="mContainer">  <div id="mContainer">
795          <div id="gradient"></div>          <div id="gradient">&nbsp;</div>
796          <div id="mask"></div>          <div id="mask">&nbsp;</div>
797          <div id="progressIndicator">&nbsp;</div>          <div id="progressIndicator">0%</div>
798  </div>  </div>
   
799  <br/>  <br/>
800    
801    <div id="parts">&nbsp;</div>
802    
803  Note:  Note:
804  <br/>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
805  <textarea name="note" cols="10" rows="5">  
806  </textarea>  <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
 <br/>  
 <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner">  
807    
808  </div>  </div>
809    <!--
810  <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;">
811  no debug output yet  no debug output yet
812  </div>  </div>
813    -->
814  EOF3  EOF3
815          $retHTML .= q{          $retHTML .= q{
816                          <input type="hidden" value="burn" name="action">                          <input type="hidden" value="burn" name="action">
# Line 620  EOF3 Line 820  EOF3
820                          <td class="tableheader">                          <td class="tableheader">
821                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
822                          </td>                          </td>
823                          <td align="center">Share</td>          } .
824                          <td align="center">Backup no</td>                  sort_header($param, 'Share', 'share', 'center') .
825                    sort_header($param, '#', 'num', 'center') .
826            qq{
827                          <td align="center">Type</td>                          <td align="center">Type</td>
828                          <td align="center">date</td>          } .
829                          <td align="center">age/days</td>                  sort_header($param, 'Date', 'date', 'center') .
830                          <td align="center">size/MB</td>                  sort_header($param, 'Age/days', 'age', 'center') .
831                          <td align="center">gzip size</td>                  sort_header($param, 'Size/Mb', 'size', 'center') .
832                    sort_header($param, 'gzip size/Kb', 'incsize', 'center') .
833            qq{
834                          </tr>                          </tr>
   
835          };          };
836    
837          my @color = (' bgcolor="#e0e0e0"', '');          my @color = (' bgcolor="#e0e0e0"', '');
# Line 636  EOF3 Line 839  EOF3
839          my $i = 0;          my $i = 0;
840          my $host = '';          my $host = '';
841    
842          foreach my $backup ( getBackupsNotBurned() ) {          foreach my $backup ( getBackupsNotBurned($param) ) {
843    
844                  if ($host ne $backup->{'host'}) {                  if ($host ne $backup->{'host'}) {
845                          $i++;                          $i++;
# Line 644  EOF3 Line 847  EOF3
847                  }                  }
848                  my $ftype = "";                  my $ftype = "";
849    
850                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
851    
852                  $retHTML .=                  $retHTML .=
853                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
854                          <td class="fview">';                          <td class="fview">';
855                  # FIXME  
856                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);                  if (($backup->{'inc_size'} || 0) > 0) {
                 if (($backup->{'fs_size'} || 0) > 0) {  
857                          $retHTML .= '                          $retHTML .= '
858                          <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);">';  
859                  }                  }
860    
861                  $retHTML .=                  $retHTML .=
862                          '</td>' .                          '</td>' .
863                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 664  EOF3 Line 866  EOF3
866                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
867                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
868                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
869                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . $backup->{'inc_size'} .
870                          '<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'} .'"></td>' .
871                            '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'parts'} .'"></td>' .
872    
873                          "</tr>\n";                          "</tr>\n";
874          }          }
# Line 717  sub displayGrid($) { Line 920  sub displayGrid($) {
920          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
921                  <tr class="fviewheader">                  <tr class="fviewheader">
922                  <td></td>                  <td></td>
923                  <td align="center">Share</td>          };
924                  <td align="center">Type and Name</td>  
925                  <td align="center">#</td>          sub sort_header($$$$) {
926                  <td align="center">Size</td>                  my ($param, $display, $name, $align) = @_;
927                  <td align="center">Date</td>  
928                    my ($sort_what, $sort_direction) = split(/_/,$param->{'sort'},2);
929    
930                    my $old_sort = $param->{'sort'};
931    
932                    my $html = qq{<td align="$align"};
933                    my $arrow = '';
934    
935                    if (lc($sort_what) eq lc($name)) {
936                            my $direction = lc($sort_direction);
937    
938                            # swap direction or fallback to default
939                            $direction =~ tr/ad/da/;
940                            $direction = 'a' unless ($direction =~ /[ad]/);
941    
942                            $param->{'sort'} = $name . '_' . $direction;
943                            $html .= ' style="border: 1px solid #808080;"';
944                    
945                            # add unicode arrow for direction
946                            $arrow .= '&nbsp;';
947                            $arrow .= $direction eq 'a'  ?  '&#9650;'
948                                    : $direction eq 'd'  ?  '&#9660;'
949                                    :                       ''
950                                    ;
951    
952                    } else {
953                            $param->{'sort'} = $name . '_a';
954                    }
955    
956                    $html .= '><a href="' . page_uri($param) . '">' . $display . '</a>' . $arrow . '</td>';
957                    $param->{'sort'} = $old_sort;
958    
959                    return $html;
960            }
961    
962            $retHTML .=
963                    sort_header($param, 'Share', 'share', 'center') .
964                    sort_header($param, 'Type and Name', 'path', 'center') .
965                    sort_header($param, '#', 'num', 'center') .
966                    sort_header($param, 'Size', 'size', 'center') .
967                    sort_header($param, 'Date', 'date', 'center');
968    
969            $retHTML .= qq{
970                  <td align="center">Media</td>                  <td align="center">Media</td>
971                  </tr>                  </tr>
972          };          };
# Line 741  sub displayGrid($) { Line 986  sub displayGrid($) {
986                  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, @_);
987          }          }
988    
989            my $sth_archived;
990            my %archived_cache;
991    
992            sub check_archived($$$) {
993                    my ($host, $share, $num) = @_;
994    
995                    if (my $html = $archived_cache{"$host $share $num"}) {
996                            return $html;
997                    }
998    
999                    $sth_archived ||= $dbh->prepare(qq{
1000                            select
1001                                    dvd_nr, note,
1002                                    count(archive_burned.copy) as copies
1003                            from archive
1004                            inner join archive_burned on archive_burned.archive_id = archive.id
1005                            inner join archive_backup on archive.id = archive_backup.archive_id
1006                            inner join backups on backups.id = archive_backup.backup_id
1007                            inner join hosts on hosts.id = backups.hostid
1008                            inner join shares on shares.id = backups.shareid
1009                            where hosts.name = ? and shares.name = ? and backups.num = ?
1010                            group by dvd_nr, note
1011                    });
1012    
1013                    my @mediums;
1014    
1015                    $sth_archived->execute($host, $share, $num);
1016                    while (my $row = $sth_archived->fetchrow_hashref()) {
1017                            push @mediums, '<abbr title="' .
1018                                    $row->{'note'} .
1019                                    ' [' . $row->{'copies'} . ']' .
1020                                    '">' .$row->{'dvd_nr'} .
1021                                    '</abbr>';
1022                    }
1023    
1024                    my $html = join(", ",@mediums);
1025                    $archived_cache{"$host $share $num"} = $html;
1026                    return $html;
1027            }
1028    
1029          my $i = $offset * $on_page;          my $i = $offset * $on_page;
1030    
1031          foreach $file (@{ $files }) {          foreach $file (@{ $files }) {
# Line 757  sub displayGrid($) { Line 1042  sub displayGrid($) {
1042                          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>} .
1043                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
1044                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
1045                          qq{<td class="fviewborder">} . '?' . qq{</td>};                          qq{<td class="fviewborder">} . check_archived( $file->{'hname'}, $file->{'sname'}, $file->{'backupnum'} ) . qq{</td>};
1046    
1047                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
1048          }          }
# Line 772  sub displayGrid($) { Line 1057  sub displayGrid($) {
1057          my $max_page = int( $results / $on_page );          my $max_page = int( $results / $on_page );
1058          my $page = 0;          my $page = 0;
1059    
1060          sub page_link($$$) {          sub page_uri($) {
1061                  my ($param,$page,$display) = @_;                  my $param = shift || die "no param?";
1062    
1063                  $param->{'offset'} = $page;                  my $uri = $MyURL;
   
                 my $html = '<a href = "' . $MyURL;  
1064                  my $del = '?';                  my $del = '?';
1065                  foreach my $k (keys %{ $param }) {                  foreach my $k (keys %{ $param }) {
1066                          if ($param->{$k}) {                          if ($param->{$k}) {
1067                                  $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};                                  $uri .= $del . $k . '=' . ${EscURI( $param->{$k} )};
1068                                  $del = '&';                                  $del = '&';
1069                          }                          }
1070                  }                  }
1071                  $html .= '">' . $display . '</a>';                  return $uri;
1072            }
1073    
1074            sub page_link($$$) {
1075                    my ($param,$page,$display) = @_;
1076    
1077                    $param->{'offset'} = $page if (defined($page));
1078    
1079                    my $html = '<a href = "' . page_uri($param) . '">' . $display . '</a>';
1080          }          }
1081    
1082          $retHTML .= '<div style="text-align: center;">';          $retHTML .= '<div style="text-align: center;">';

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

  ViewVC Help
Powered by ViewVC 1.1.26