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

Legend:
Removed from v.127  
changed lines
  Added in v.149

  ViewVC Help
Powered by ViewVC 1.1.26