/[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 155 by dpavlin, Mon Oct 10 13:04:48 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                  FROM backups                  FROM backups
342                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
343                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
344                  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
345                  WHERE backups.size > 0                  WHERE backups.size > 0 AND archive_backup.backup_id IS NULL
346                  GROUP BY                  GROUP BY
347                          backups.hostID,                          backups.hostID,
348                          hosts.name,                          hosts.name,
# Line 343  sub getBackupsNotBurned() { Line 375  sub getBackupsNotBurned() {
375  sub displayBackupsGrid() {  sub displayBackupsGrid() {
376    
377          my $retHTML .= q{          my $retHTML .= q{
378                  <form id="forma" method="POST" action=};                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
                 $retHTML .= "\"".$MyURL."\"";  
                 $retHTML .= q{?action=burn>  
379          };          };
380    
381          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
382  <style>  <style type="text/css">
383  <!--  <!--
384    DIV#fixedBox {
 div#fixedBox {  
385          position: absolute;          position: absolute;
386          bottom: 1em;          top: 50em;
387          left: 0.5em;          left: -24%;
388          padding: 0.5em;          padding: 0.5em;
389          width: 10em;          width: 20%;
390          background: #e0f0e0;          background-color: #E0F0E0;
391          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. */  
392  }  }
393    
394  #mContainer {  DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
395          position: relative;          font-size: 10pt;
         width: 100%;  
         height: 1.1em;  
         padding: 0px;  
         border: 1px solid #000000;  
396  }  }
397    
398  #gradient {  FORM>DIV#fixedBox {
399          position: absolute;          position: fixed !important;
400          top: 0px;          left: 0.5em !important;
401          left: 0px;          top: auto !important;
402          width: 100%;          bottom: 1em !important;
403          height: 100%;          width: 15% !important;
404    }
405    
406    DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
407            border: 1px solid #00C000;
408    }
409    
410    DIV#fixedBox #note {
411          display: block;          display: block;
412          background-color: #ffff00;          width: 100%;
413  }  }
414    
415  #mask {  DIV#fixedBox #submitBurner {
416          position: absolute;          display: block;
         top: 0px;  
         left: 0px;  
417          width: 100%;          width: 100%;
418            margin-top: 0.5em;
419            cursor: pointer;
420    }
421    
422    * HTML {
423            overflow-y: hidden;
424    }
425    
426    * HTML BODY {
427            overflow-y: auto;
428          height: 100%;          height: 100%;
429          display: block;          font-size: 100%;
         font-size: 1px;  
         background-color: #FFFFFF;  
         overflow: hidden;  
430  }  }
431    
432  #progressIndicator {  * HTML DIV#fixedBox {
433          position: absolute;          position: absolute;
434          top: 0px;  }
435          left: 0px;  
436          width: 100%;  #mContainer, #gradient, #mask, #progressIndicator {
         height: 100%;  
437          display: block;          display: block;
438          font-weight: bold;          width: 100%;
         color: #404040;  
439          font-size: 10pt;          font-size: 10pt;
440            font-weight: bold;
441          text-align: center;          text-align: center;
442            vertical-align: middle;
443            padding: 1px;
444    }
445    
446    #gradient, #mask, #progressIndicator {
447            left: 0;
448            border-width: 1px;
449            border-style: solid;
450            border-color: #000000;
451            color: #404040;
452            margin: 0.4em;
453            position: absolute;
454            margin-left: -1px;
455            margin-top: -1px;
456            margin-bottom: -1px;
457            overflow: hidden;
458  }  }
459    
460    #mContainer {
461            display: block;
462            position: relative;
463            padding: 0px;
464            margin-top: 0.4em;
465            margin-bottom: 0.5em;
466    }
467    
468    #gradient {
469            z-index: 1;
470            background-color: #FFFF00;
471    }
472    
473    #mask {
474            z-index: 2;
475            background-color: #FFFFFF;
476    }
477    
478    #progressIndicator {
479            z-index: 3;
480            background-color: transparent;
481    }
482  -->  -->
483  </style>  </style>
484  <script language="javascript" type="text/javascript">  <script type="text/javascript">
485  <!--  <!--
486    
487  var debug_div = null;  var debug_div = null;
488  var media_size = 4400 * 1024;  EOF3
489    
490            # take maximum archive size from configuration
491            $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';
492    
493            $retHTML .= <<'EOF3';
494    
495  function debug(msg) {  function debug(msg) {
496  //      return; // Disable debugging  //      return; // Disable debugging
# Line 460  function element_id(name,element) { Line 520  function element_id(name,element) {
520  }  }
521    
522  function checkAll(location) {  function checkAll(location) {
523          var len = element_id('forma').elements.length;          var f = element_id('forma') || null;
524            if (!f) return false;
525    
526            var len = f.elements.length;
527          var check_all = element_id('allFiles');          var check_all = element_id('allFiles');
528            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
529    
530          for (var i = 0; i < len; i++) {          for (var i = 0; i < len; i++) {
531                    var e = f.elements[i];
532                  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') {  
533                          if (check_all.checked) {                          if (check_all.checked) {
534                                  e.checked = true;                                  if (e.checked) continue;
535                                    var el = element_id("fss" + e.name.substr(3));
536                                    var size = parseInt(el.value) || 0;
537                                    debug('suma: '+suma+' size: '+size);
538                                    if ((suma + size) < media_size) {
539                                            suma += size;
540                                            e.checked = true;
541                                    } else {
542                                            break;
543                                    }
544                          } else {                          } else {
545                                  e.checked = false;                                  e.checked = false;
546                          }                          }
547                  }                  }
548          }          }
549            update_sum(suma);
550    }
551    
552          sumiraj();  function update_sum(suma) {
553            element_id('forma').elements['totalsize'].value = suma;
554            pbar_set(suma, media_size);
555            debug('total size: ' + suma);
556  }  }
557        
558  function sumiraj(e) {  function sumiraj(e) {
559          var suma = parseInt(element_id('forma').totalsize.value) || 0;          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
560          var len = element_id('forma').elements.length;          var len = element_id('forma').elements.length;
561          if (e) {          if (e) {
562                  var size = parseInt( element_id("fss" + e.name.substr(3)).value );                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);
563                  if (e.checked) {                  if (e.checked) {
564                          suma += size;                          suma += size;
565                  } else {                  } else {
# Line 498  function sumiraj(e) { Line 575  function sumiraj(e) {
575                          }                          }
576                  }                  }
577          }          }
578          element_id('forma').totalsize.value = suma;          update_sum(suma);
         pbar_set(suma, media_size);  
         debug('total size: '+suma);  
579          return suma;          return suma;
580  }  }
581    
582  /* progress bar */  /* progress bar */
583    
584  var _pbar_width = 0;  var _pbar_width = null;
585  var _pbar_warn = 10;    // change color in last 10%  var _pbar_warn = 10;    // change color in last 10%
586    
587  function pbar_reset() {  function pbar_reset() {
588          element_id("mask").style.left = "0px";          element_id("mask").style.left = "0px";
589          _pbar_width = element_id("mContainer").offsetWidth - 2;          _pbar_width = element_id("mContainer").offsetWidth - 2;
590          element_id("mask").style.width = _pbar_width + "px";          element_id("mask").style.width = _pbar_width + "px";
         element_id("progressIndicator").style.zIndex  = 10;  
591          element_id("mask").style.display = "block";          element_id("mask").style.display = "block";
592            element_id("progressIndicator").style.zIndex  = 10;
593          element_id("progressIndicator").innerHTML = "0";          element_id("progressIndicator").innerHTML = "0";
594  }  }
595    
596  function dec2hex(d) {  function dec2hex(d) {
597          var hch="0123456789ABCDEF";          var hch = '0123456789ABCDEF';
598          var a=d%16;          var a = d % 16;
599          var q=(d-a)/16;          var q = (d - a) / 16;
600          return hch.charAt(q)+hch.charAt(a);          return hch.charAt(q) + hch.charAt(a);
601  }  }
602    
   
603  function pbar_set(amount, max) {  function pbar_set(amount, max) {
604            debug('pbar_set('+amount+', '+max+')');
605    
606          debug('pbar_set( '+amount+' , '+max+' )');          if (_pbar_width == null) {
607                    var _mc = element_id("mContainer");
608          curWidth = parseInt(element_id("mask").offsetWidth);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
609          curLeft = parseInt(element_id("mask").offsetLeft);                  if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
610                    if (_pbar_width == null) _pbar_width = 0;
611            }
612    
613          var pcnt = Math.floor( amount * 100 / max );          var pcnt = Math.floor(amount * 100 / max);
614          var p90 = 100 - _pbar_warn;          var p90 = 100 - _pbar_warn;
615          var pcol = pcnt - p90;          var pcol = pcnt - p90;
616          if (pcol < _pbar_warn) {          if (Math.round(pcnt) <= 100) {
617                  if (pcol < 0) pcol = 0;                  if (pcol < 0) pcol = 0;
618                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
619                  if (e && e.disabled) {                  debug('enable_button');
620                          debug('enable_button');                  e.disabled = false;
621                          var a = e.getAttributeNode('disabled') || null;                  var a = e.getAttributeNode('disabled') || null;
622                          if (a) e.removeAttributeNode(a);                  if (a) e.removeAttributeNode(a);
623                  }          } else {
         } else if (pcol > _pbar_warn) {  
624                  debug('disable button');                  debug('disable button');
625                  pcol = _pbar_warn;                  pcol = _pbar_warn;
626                  var e = element_id("submitBurner");                  var e = element_id("submitBurner");
627                  if (! e.disabled) e.disabled = true;                  if (!e.disabled) e.disabled = true;
628          }          }
629          var col_g = Math.floor( ( _pbar_warn - pcol ) * 255 / _pbar_warn );          var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
630          var col = '#ff' + dec2hex( col_g ) + '00';          var col = '#FF' + dec2hex(col_g) + '00';
631    
632          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);          //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
633          element_id("gradient").style.backgroundColor = col;          element_id("gradient").style.backgroundColor = col;
634    
         var size = parseInt( _pbar_width * amount / max );  
   
         curWidth = _pbar_width - size;  
         curLeft = size ;  
   
         //debug('size: '+size+' curWidth '+curWidth+' curLeft: '+curLeft);  
   
635          element_id("progressIndicator").innerHTML = pcnt + '%';          element_id("progressIndicator").innerHTML = pcnt + '%';
636          //element_id("progressIndicator").innerHTML = amount;          //element_id("progressIndicator").innerHTML = amount;
637    
638          if (curLeft > _pbar_width) {          element_id("mask").style.clip = 'rect(' + Array(
639                  element_id("mask").style.display = "none";                  '0px',
640                  return;                  element_id("mask").offsetWidth + 'px',
641          } else {                  element_id("mask").offsetHeight + 'px',
642                  element_id("mask").style.display = "";                  Math.round(_pbar_width * amount / max) + 'px'
643          }          ).join(' ') + ')';
   
         //if(parseInt(element_id("mask").offsetWidth)>10)  
         element_id("mask").style.width = curWidth + "px";  
         element_id("mask").style.left = curLeft + "px";  
   
644  }  }
645    
646  if (!self.body) self.body = new Object();  if (!self.body) self.body = new Object();
647  self.onload = self.document.onload = self.body.onload = function() {  self.onload = self.document.onload = self.body.onload = function() {
648          pbar_reset();          //pbar_reset();
649          sumiraj();          sumiraj();
650  }  };
651    
652  //-->  // -->
653  </script>  </script>
654  <div id="fixedBox">  <div id="fixedBox">
655    
656  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>  
657    
658  <div id="mContainer">  <div id="mContainer">
659          <div id="gradient"></div>          <div id="gradient">&nbsp;</div>
660          <div id="mask"></div>          <div id="mask">&nbsp;</div>
661          <div id="progressIndicator">&nbsp;</div>          <div id="progressIndicator">0%</div>
662  </div>  </div>
   
663  <br/>  <br/>
664    
665  Note:  Note:
666  <br/>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
667  <textarea name="note" cols="10" rows="5">  
668  </textarea>  <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
 <br/>  
 <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner">  
669    
670  </div>  </div>
671    <!--
672  <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;">
673  no debug output yet  no debug output yet
674  </div>  </div>
675    -->
676  EOF3  EOF3
677          $retHTML .= q{          $retHTML .= q{
678                          <input type="hidden" value="burn" name="action">                          <input type="hidden" value="burn" name="action">
# Line 644  EOF3 Line 706  EOF3
706                  }                  }
707                  my $ftype = "";                  my $ftype = "";
708    
709                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
710    
711                  $retHTML .=                  $retHTML .=
712                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
713                          <td class="fview">';                          <td class="fview">';
714    
715                  # FIXME                  # FIXME
716                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);                  $backup->{'fs_size'} = int($backup->{'size'} * 1024);
717    
718                  if (($backup->{'fs_size'} || 0) > 0) {                  if (($backup->{'fs_size'} || 0) > 0) {
719                          $retHTML .= '                          $retHTML .= '
720                          <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);">';  
721                  }                  }
722    
723                  $retHTML .=                  $retHTML .=
724                          '</td>' .                          '</td>' .
725                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 665  EOF3 Line 729  EOF3
729                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
730                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
731                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . $backup->{'fs_size'} .
732                          '<input type="hidden" iD="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '" value="'. $backup->{'fs_size'} .'"></td>' .                          '<input type="hidden" iD="fss'.$checkbox_key .'" value="'. $backup->{'fs_size'} .'"></td>' .
733    
734                          "</tr>\n";                          "</tr>\n";
735          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26