/[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 161 by dpavlin, Mon Oct 10 13:39:13 2005 UTC
# Line 288  sub getGzipName($$$) Line 288  sub getGzipName($$$)
288          $ret =~ s/\\h/$host/ge;          $ret =~ s/\\h/$host/ge;
289          $ret =~ s/\\s/$share/ge;          $ret =~ s/\\s/$share/ge;
290          $ret =~ s/\\n/$backupnum/ge;          $ret =~ s/\\n/$backupnum/ge;
291            
292            $ret =~ s/__+/_/g;
293    
294          return $ret;          return $ret;
295                    
296  }  }
297    
298    sub getGzipSize($$)
299    {
300            my ($hostID, $backupNum) = @_;
301            my $ret;
302            my $sql;
303            my $dbh = get_dbh();
304            
305            $sql = q{
306                                    SELECT hosts.name  as host,
307                                               shares.name as share,
308                                               backups.num as backupnum
309                                    FROM hosts, backups, shares
310                                    WHERE shares.id=backups.shareid AND
311                                              hosts.id =backups.hostid AND
312                                              hosts.id=? AND
313                                              backups.num=?
314                            };
315            my $sth = $dbh->prepare($sql);
316            $sth->execute($hostID, $backupNum);
317    
318            my $row = $sth->fetchrow_hashref();
319            
320            my (undef,undef,undef,undef,undef,undef,undef,$ret,undef,undef,undef,undef,undef) =
321                            stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
322                                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
323            
324            return $ret;    
325    }
326    
327  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
328    
329          my $dbh = get_dbh();          my $dbh = get_dbh();
# Line 302  sub getBackupsNotBurned() { Line 333  sub getBackupsNotBurned() {
333                          backups.hostID AS hostID,                          backups.hostID AS hostID,
334                          hosts.name AS host,                          hosts.name AS host,
335                          shares.name AS share,                          shares.name AS share,
336                          backups.id AS backupnum,                          backups.num AS backupnum,
337                          backups.type AS type,                          backups.type AS type,
338                          backups.date AS date,                          backups.date AS date,
339                          backups.size AS size                          backups.size AS size,
340                            backups.id AS id,
341                            backups.inc_size AS inc_size
342                  FROM backups                  FROM backups
343                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
344                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
345                  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
346                  WHERE backups.size > 0                  WHERE backups.size > 0 AND backups.inc_size > 0 AND archive_backup.backup_id IS NULL
347                  GROUP BY                  GROUP BY
348                          backups.hostID,                          backups.hostID,
349                          hosts.name,                          hosts.name,
# Line 320  sub getBackupsNotBurned() { Line 353  sub getBackupsNotBurned() {
353                          backups.id,                          backups.id,
354                          backups.type,                          backups.type,
355                          backups.date,                          backups.date,
356                          backups.size                          backups.size,
357                            backups.inc_size
358                  ORDER BY backups.date                  ORDER BY backups.date
359          };          };
360          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
# Line 330  sub getBackupsNotBurned() { Line 364  sub getBackupsNotBurned() {
364          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
365                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
366                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
367                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =  
368                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  # do some cluster calculation (approximate) and convert to kB
369                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  $row->{'inc_size'} = int($row->{'inc_size'} / ( 2 * 1024) * 2);
                 $row->{'fs_size'} = $fs_size;  
370                  push @ret, $row;                  push @ret, $row;
371          }          }
372                
# Line 343  sub getBackupsNotBurned() { Line 376  sub getBackupsNotBurned() {
376  sub displayBackupsGrid() {  sub displayBackupsGrid() {
377    
378          my $retHTML .= q{          my $retHTML .= q{
379                  <form id="forma" method="POST" action=};                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
                 $retHTML .= "\"".$MyURL."\"";  
                 $retHTML .= q{?action=burn>  
380          };          };
381    
382          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
383  <style>  <style type="text/css">
384  <!--  <!--
385    DIV#fixedBox {
 div#fixedBox {  
386          position: absolute;          position: absolute;
387          bottom: 1em;          top: 50em;
388          left: 0.5em;          left: -24%;
389          padding: 0.5em;          padding: 0.5em;
390          width: 10em;          width: 20%;
391          background: #e0f0e0;          background-color: #E0F0E0;
392          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. */  
393  }  }
394    
395  #mContainer {  DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
396          position: relative;          font-size: 10pt;
         width: 100%;  
         height: 1.1em;  
         padding: 0px;  
         border: 1px solid #000000;  
397  }  }
398    
399  #gradient {  FORM>DIV#fixedBox {
400          position: absolute;          position: fixed !important;
401          top: 0px;          left: 0.5em !important;
402          left: 0px;          top: auto !important;
403          width: 100%;          bottom: 1em !important;
404          height: 100%;          width: 15% !important;
405    }
406    
407    DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
408            border: 1px solid #00C000;
409    }
410    
411    DIV#fixedBox #note {
412          display: block;          display: block;
413          background-color: #ffff00;          width: 100%;
414  }  }
415    
416  #mask {  DIV#fixedBox #submitBurner {
417          position: absolute;          display: block;
         top: 0px;  
         left: 0px;  
418          width: 100%;          width: 100%;
419            margin-top: 0.5em;
420            cursor: pointer;
421    }
422    
423    * HTML {
424            overflow-y: hidden;
425    }
426    
427    * HTML BODY {
428            overflow-y: auto;
429          height: 100%;          height: 100%;
430          display: block;          font-size: 100%;
         font-size: 1px;  
         background-color: #FFFFFF;  
         overflow: hidden;  
431  }  }
432    
433  #progressIndicator {  * HTML DIV#fixedBox {
434          position: absolute;          position: absolute;
435          top: 0px;  }
436          left: 0px;  
437          width: 100%;  #mContainer, #gradient, #mask, #progressIndicator {
         height: 100%;  
438          display: block;          display: block;
439          font-weight: bold;          width: 100%;
         color: #404040;  
440          font-size: 10pt;          font-size: 10pt;
441            font-weight: bold;
442          text-align: center;          text-align: center;
443            vertical-align: middle;
444            padding: 1px;
445    }
446    
447    #gradient, #mask, #progressIndicator {
448            left: 0;
449            border-width: 1px;
450            border-style: solid;
451            border-color: #000000;
452            color: #404040;
453            margin: 0.4em;
454            position: absolute;
455            margin-left: -1px;
456            margin-top: -1px;
457            margin-bottom: -1px;
458            overflow: hidden;
459    }
460    
461    #mContainer {
462            display: block;
463            position: relative;
464            padding: 0px;
465            margin-top: 0.4em;
466            margin-bottom: 0.5em;
467    }
468    
469    #gradient {
470            z-index: 1;
471            background-color: #FFFF00;
472    }
473    
474    #mask {
475            z-index: 2;
476            background-color: #FFFFFF;
477  }  }
478    
479    #progressIndicator {
480            z-index: 3;
481            background-color: transparent;
482    }
483  -->  -->
484  </style>  </style>
485  <script language="javascript" type="text/javascript">  <script type="text/javascript">
486  <!--  <!--
487    
488  var debug_div = null;  var debug_div = null;
489  var media_size = 4400 * 1024;  EOF3
490    
491            # take maximum archive size from configuration
492            $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';
493    
494            $retHTML .= <<'EOF3';
495    
496  function debug(msg) {  function debug(msg) {
497  //      return; // Disable debugging  //      return; // Disable debugging
# Line 460  function element_id(name,element) { Line 521  function element_id(name,element) {
521  }  }
522    
523  function checkAll(location) {  function checkAll(location) {
524          var len = element_id('forma').elements.length;          var f = element_id('forma') || null;
525            if (!f) return false;
526    
527            var len = f.elements.length;
528          var check_all = element_id('allFiles');          var check_all = element_id('allFiles');
529            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
530    
531          for (var i = 0; i < len; i++) {          for (var i = 0; i < len; i++) {
532                    var e = f.elements[i];
533                  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') {  
534                          if (check_all.checked) {                          if (check_all.checked) {
535                                  e.checked = true;                                  if (e.checked) continue;
536                                    var el = element_id("fss" + e.name.substr(3));
537                                    var size = parseInt(el.value) || 0;
538                                    debug('suma: '+suma+' size: '+size);
539                                    if ((suma + size) < media_size) {
540                                            suma += size;
541                                            e.checked = true;
542                                    } else {
543                                            break;
544                                    }
545                          } else {                          } else {
546                                  e.checked = false;                                  e.checked = false;
547                          }                          }
548                  }                  }
549          }          }
550            update_sum(suma);
551    }
552    
553          sumiraj();  function update_sum(suma) {
554            element_id('forma').elements['totalsize'].value = suma;
555            pbar_set(suma, media_size);
556            debug('total size: ' + suma);
557  }  }
558        
559  function sumiraj(e) {  function sumiraj(e) {
560          var suma = parseInt(element_id('forma').totalsize.value) || 0;          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
561          var len = element_id('forma').elements.length;          var len = element_id('forma').elements.length;
562          if (e) {          if (e) {
563                  var size = parseInt( element_id("fss" + e.name.substr(3)).value );                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);
564                  if (e.checked) {                  if (e.checked) {
565                          suma += size;                          suma += size;
566                  } else {                  } else {
# Line 498  function sumiraj(e) { Line 576  function sumiraj(e) {
576                          }                          }
577                  }                  }
578          }          }
579          element_id('forma').totalsize.value = suma;          update_sum(suma);
         pbar_set(suma, media_size);  
         debug('total size: '+suma);  
580          return suma;          return suma;
581  }  }
582    
583  /* progress bar */  /* progress bar */
584    
585  var _pbar_width = 0;  var _pbar_width = null;
586  var _pbar_warn = 10;    // change color in last 10%  var _pbar_warn = 10;    // change color in last 10%
587    
588  function pbar_reset() {  function pbar_reset() {
589          element_id("mask").style.left = "0px";          element_id("mask").style.left = "0px";
590          _pbar_width = element_id("mContainer").offsetWidth - 2;          _pbar_width = element_id("mContainer").offsetWidth - 2;
591          element_id("mask").style.width = _pbar_width + "px";          element_id("mask").style.width = _pbar_width + "px";
         element_id("progressIndicator").style.zIndex  = 10;  
592          element_id("mask").style.display = "block";          element_id("mask").style.display = "block";
593            element_id("progressIndicator").style.zIndex  = 10;
594          element_id("progressIndicator").innerHTML = "0";          element_id("progressIndicator").innerHTML = "0";
595  }  }
596    
597  function dec2hex(d) {  function dec2hex(d) {
598          var hch="0123456789ABCDEF";          var hch = '0123456789ABCDEF';
599          var a=d%16;          var a = d % 16;
600          var q=(d-a)/16;          var q = (d - a) / 16;
601          return hch.charAt(q)+hch.charAt(a);          return hch.charAt(q) + hch.charAt(a);
602  }  }
603    
   
604  function pbar_set(amount, max) {  function pbar_set(amount, max) {
605            debug('pbar_set('+amount+', '+max+')');
606    
607          debug('pbar_set( '+amount+' , '+max+' )');          if (_pbar_width == null) {
608                    var _mc = element_id("mContainer");
609          curWidth = parseInt(element_id("mask").offsetWidth);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
610          curLeft = parseInt(element_id("mask").offsetLeft);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
611                    if (_pbar_width == null) _pbar_width = 0;
612            }
613    
614          var pcnt = Math.floor( amount * 100 / max );          var pcnt = Math.floor(amount * 100 / max);
615          var p90 = 100 - _pbar_warn;          var p90 = 100 - _pbar_warn;
616          var pcol = pcnt - p90;          var pcol = pcnt - p90;
617          if (pcol < _pbar_warn) {          if (Math.round(pcnt) <= 100) {
618                  if (pcol < 0) pcol = 0;                  if (pcol < 0) pcol = 0;
619                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
620                  if (e && e.disabled) {                  debug('enable_button');
621                          debug('enable_button');                  e.disabled = false;
622                          var a = e.getAttributeNode('disabled') || null;                  var a = e.getAttributeNode('disabled') || null;
623                          if (a) e.removeAttributeNode(a);                  if (a) e.removeAttributeNode(a);
624                  }          } else {
         } else if (pcol > _pbar_warn) {  
625                  debug('disable button');                  debug('disable button');
626                  pcol = _pbar_warn;                  pcol = _pbar_warn;
627                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
628                  if (! e.disabled) e.disabled = true;                  if (!e.disabled) e.disabled = true;
629          }          }
630          var col_g = Math.floor( ( _pbar_warn - pcol ) * 255 / _pbar_warn );          var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
631          var col = '#ff' + dec2hex( col_g ) + '00';          var col = '#FF' + dec2hex(col_g) + '00';
632    
633          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
634          element_id("gradient").style.backgroundColor = col;          element_id("gradient").style.backgroundColor = col;
635    
         var size = parseInt( _pbar_width * amount / max );  
   
         curWidth = _pbar_width - size;  
         curLeft = size ;  
   
         //debug('size: '+size+' curWidth '+curWidth+' curLeft: '+curLeft);  
   
636          element_id("progressIndicator").innerHTML = pcnt + '%';          element_id("progressIndicator").innerHTML = pcnt + '%';
637          //element_id("progressIndicator").innerHTML = amount;          //element_id("progressIndicator").innerHTML = amount;
638    
639          if (curLeft > _pbar_width) {          element_id("mask").style.clip = 'rect(' + Array(
640                  element_id("mask").style.display = "none";                  '0px',
641                  return;                  element_id("mask").offsetWidth + 'px',
642          } else {                  element_id("mask").offsetHeight + 'px',
643                  element_id("mask").style.display = "";                  Math.round(_pbar_width * amount / max) + 'px'
644          }          ).join(' ') + ')';
   
         //if(parseInt(element_id("mask").offsetWidth)>10)  
         element_id("mask").style.width = curWidth + "px";  
         element_id("mask").style.left = curLeft + "px";  
   
645  }  }
646    
647  if (!self.body) self.body = new Object();  if (!self.body) self.body = new Object();
648  self.onload = self.document.onload = self.body.onload = function() {  self.onload = self.document.onload = self.body.onload = function() {
649          pbar_reset();          //pbar_reset();
650          sumiraj();          sumiraj();
651  }  };
652    
653  //-->  // -->
654  </script>  </script>
655  <div id="fixedBox">  <div id="fixedBox">
656    
657  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>  
658    
659  <div id="mContainer">  <div id="mContainer">
660          <div id="gradient"></div>          <div id="gradient">&nbsp;</div>
661          <div id="mask"></div>          <div id="mask">&nbsp;</div>
662          <div id="progressIndicator">&nbsp;</div>          <div id="progressIndicator">0%</div>
663  </div>  </div>
   
664  <br/>  <br/>
665    
666  Note:  Note:
667  <br/>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
668  <textarea name="note" cols="10" rows="5">  
669  </textarea>  <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
 <br/>  
 <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner">  
670    
671  </div>  </div>
672    <!--
673  <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;">
674  no debug output yet  no debug output yet
675  </div>  </div>
676    -->
677  EOF3  EOF3
678          $retHTML .= q{          $retHTML .= q{
679                          <input type="hidden" value="burn" name="action">                          <input type="hidden" value="burn" name="action">
# Line 626  EOF3 Line 689  EOF3
689                          <td align="center">date</td>                          <td align="center">date</td>
690                          <td align="center">age/days</td>                          <td align="center">age/days</td>
691                          <td align="center">size/MB</td>                          <td align="center">size/MB</td>
692                          <td align="center">gzip size</td>                          <td align="center">gzip size/kB</td>
693                          </tr>                          </tr>
694    
695          };          };
# Line 644  EOF3 Line 707  EOF3
707                  }                  }
708                  my $ftype = "";                  my $ftype = "";
709    
710                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
711    
712                  $retHTML .=                  $retHTML .=
713                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
714                          <td class="fview">';                          <td class="fview">';
715                  # FIXME  
716                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);                  if (($backup->{'inc_size'} || 0) > 0) {
                 if (($backup->{'fs_size'} || 0) > 0) {  
717                          $retHTML .= '                          $retHTML .= '
718                          <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);">';  
719                  }                  }
720    
721                  $retHTML .=                  $retHTML .=
722                          '</td>' .                          '</td>' .
723                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 664  EOF3 Line 726  EOF3
726                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
727                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
728                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
729                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . $backup->{'inc_size'} .
730                          '<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>' .
731    
732                          "</tr>\n";                          "</tr>\n";
733          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26