/[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 117 by dpavlin, Sun Sep 11 13:05:06 2005 UTC revision 171 by dpavlin, Mon Oct 10 14:32:31 2005 UTC
# Line 15  my $pager_pages = 10; Line 15  my $pager_pages = 10;
15  my $dsn = $Conf{SearchDSN};  my $dsn = $Conf{SearchDSN};
16  my $db_user = $Conf{SearchUser} || '';  my $db_user = $Conf{SearchUser} || '';
17    
18  my $index_path = $Conf{HyperEstraierIndex};  my $hest_index_path = $Conf{HyperEstraierIndex};
 if ($index_path) {  
         $index_path = $TopDir . '/' . $index_path;  
         $index_path =~ s#//#/#g;  
 }  
19    
20  my $dbh;  my $dbh;
21    
# Line 198  sub getFilesHyperEstraier($) { Line 194  sub getFilesHyperEstraier($) {
194          my $offset = $param->{'offset'} || 0;          my $offset = $param->{'offset'} || 0;
195          $offset *= $on_page;          $offset *= $on_page;
196    
197          die "no index_path?" unless ($index_path);          die "no index_path?" unless ($hest_index_path);
198    
199          use HyperEstraier;          use HyperEstraier;
200    
201          my ($index_path, $index_node_url) = getHyperEstraier_url($index_path);          my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path);
202    
203          # open the database          # open the database
204          my $db;          my $db;
# Line 292  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();
330          my $sql = q{  
331          SELECT          my $sql = q{
332                  backups.hostID          AS hostid,                  SELECT
333                  min(hosts.name)         AS host,                          backups.hostID AS hostID,
334                  min(shares.name)        AS share,                          hosts.name AS host,
335                  backups.num             AS backupnum,                          shares.name AS share,
336                  min(backups.type)       AS type,                          backups.num AS backupnum,
337                  min(backups.date)       AS date,                          backups.type AS type,
338                  min(backups.size)       AS size                          backups.date AS date,
339          FROM files                          backups.size AS size,
340                  INNER JOIN shares       ON files.shareID=shares.ID                          backups.id AS id,
341                  INNER JOIN hosts        ON hosts.ID = shares.hostID                          backups.inc_size AS inc_size
342                  INNER JOIN backups      ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID                  FROM backups
343          GROUP BY                  INNER JOIN shares       ON backups.shareID=shares.ID
344                  backups.hostID, backups.num, backups.shareid                  INNER JOIN hosts        ON backups.hostID = hosts.ID
345          ORDER BY min(backups.date)                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
346                    WHERE backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL
347                    GROUP BY
348                            backups.hostID,
349                            hosts.name,
350                            shares.name,
351                            backups.num,
352                            backups.shareid,
353                            backups.id,
354                            backups.type,
355                            backups.date,
356                            backups.size,
357                            backups.inc_size
358                    ORDER BY backups.date
359          };          };
360          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
361          my @ret;          my @ret;
# Line 324  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'} + 1023 ) / ( 2 * 1024 ) * 2);
                 $row->{'fs_size'} = $fs_size;  
370                  push @ret, $row;                  push @ret, $row;
371          }          }
372                
373          return @ret;                return @ret;      
374  }  }
375    
376  sub displayBackupsGrid()  sub displayBackupsGrid() {
377    {  
378        my $retHTML = "";          my $retHTML .= q{
379                          <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
380          $retHTML .= <<EOF3;          };
381  <script language="javascript" type="text/javascript">  
382            $retHTML .= <<'EOF3';
383    <style type="text/css">
384  <!--  <!--
385    DIV#fixedBox {
386            position: absolute;
387            top: 50em;
388            left: -24%;
389            padding: 0.5em;
390            width: 20%;
391            background-color: #E0F0E0;
392            border: 1px solid #00C000;
393    }
394    
395    DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
396            font-size: 10pt;
397    }
398    
399    FORM>DIV#fixedBox {
400            position: fixed !important;
401            left: 0.5em !important;
402            top: auto !important;
403            bottom: 1em !important;
404            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;
413            width: 100%;
414    }
415    
416    DIV#fixedBox #submitBurner {
417            display: block;
418            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%;
430            font-size: 100%;
431    }
432    
433    * HTML DIV#fixedBox {
434            position: absolute;
435    }
436    
437    #mContainer, #gradient, #mask, #progressIndicator {
438            display: block;
439            width: 100%;
440            font-size: 10pt;
441            font-weight: bold;
442            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>
485    <script type="text/javascript">
486    <!--
487    
488    var debug_div = null;
489    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) {
497    //      return; // Disable debugging
498    
499            if (! debug_div) debug_div = document.getElementById('debug');
500    
501            // this will create debug div if it doesn't exist.
502            if (! debug_div) {
503                    debug_div = document.createElement('div');
504                    if (document.body) document.body.appendChild(debug_div);
505                    else debug_div = null;
506            }
507            if (debug_div) {
508                    debug_div.appendChild(document.createTextNode(msg));
509                    debug_div.appendChild(document.createElement("br"));
510            }
511    }
512    
513    
514    var element_id_cache = Array();
515    
516    function element_id(name,element) {
517            if (! element_id_cache[name]) {
518                    element_id_cache[name] = self.document.getElementById(name);
519            }
520            return element_id_cache[name];
521    }
522    
523    function checkAll(location) {
524            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');
529            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
530    
531            for (var i = 0; i < len; i++) {
532                    var e = f.elements[i];
533                    if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
534                            if (check_all.checked) {
535                                    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 {
546                                    e.checked = false;
547                            }
548                    }
549            }
550            update_sum(suma);
551    }
552    
553    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) {
560            var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
561            var len = element_id('forma').elements.length;
562            if (e) {
563                    var size = parseInt( element_id("fss" + e.name.substr(3)).value);
564                    if (e.checked) {
565                            suma += size;
566                    } else {
567                            suma -= size;
568                    }
569            } else {
570                    suma = 0;
571                    for (var i = 0; i < len; i++) {
572                            var e = element_id('forma').elements[i];
573                            if (e.name != 'all' && e.checked && e.name.substr(0,3) == 'fcb') {
574                                    var el = element_id("fss" + e.name.substr(3));
575                                    if (el && el.value) suma += parseInt(el.value) || 0;
576                            }
577                    }
578            }
579            update_sum(suma);
580            return suma;
581    }
582    
583      function checkAll(location)  /* progress bar */
584      {  
585        for (var i=0;i<document.forma.elements.length;i++)  var _pbar_width = null;
586        {  var _pbar_warn = 10;    // change color in last 10%
587          var e = document.forma.elements[i];  
588          if ((e.checked || !e.checked) && e.name != \'all\') {  function pbar_reset() {
589              if (eval("document.forma."+location+".checked")) {          element_id("mask").style.left = "0px";
590                  e.checked = true;          _pbar_width = element_id("mContainer").offsetWidth - 2;
591              } else {          element_id("mask").style.width = _pbar_width + "px";
592                  e.checked = false;          element_id("mask").style.display = "block";
593              }          element_id("progressIndicator").style.zIndex  = 10;
594          }          element_id("progressIndicator").innerHTML = "0";
595        }  }
596      }  
597  //-->  function dec2hex(d) {
598  </script>                var hch = '0123456789ABCDEF';
599            var a = d % 16;
600            var q = (d - a) / 16;
601            return hch.charAt(q) + hch.charAt(a);
602    }
603    
604    function pbar_set(amount, max) {
605            debug('pbar_set('+amount+', '+max+')');
606    
607            if (_pbar_width == null) {
608                    var _mc = element_id("mContainer");
609                    if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
610                    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);
615            var p90 = 100 - _pbar_warn;
616            var pcol = pcnt - p90;
617            if (Math.round(pcnt) <= 100) {
618                    if (pcol < 0) pcol = 0;
619                    var e = element_id("submitBurner");
620                    debug('enable_button');
621                    e.disabled = false;
622                    var a = e.getAttributeNode('disabled') || null;
623                    if (a) e.removeAttributeNode(a);
624            } else {
625                    debug('disable button');
626                    pcol = _pbar_warn;
627                    var e = element_id("submitBurner");
628                    if (!e.disabled) e.disabled = true;
629            }
630            var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
631            var col = '#FF' + dec2hex(col_g) + '00';
632    
633            //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
634            element_id("gradient").style.backgroundColor = col;
635    
636            element_id("progressIndicator").innerHTML = pcnt + '%';
637            //element_id("progressIndicator").innerHTML = amount;
638    
639            element_id("mask").style.clip = 'rect(' + Array(
640                    '0px',
641                    element_id("mask").offsetWidth + 'px',
642                    element_id("mask").offsetHeight + 'px',
643                    Math.round(_pbar_width * amount / max) + 'px'
644            ).join(' ') + ')';
645    }
646    
647    if (!self.body) self.body = new Object();
648    self.onload = self.document.onload = self.body.onload = function() {
649            //pbar_reset();
650            sumiraj();
651    };
652    
653    // -->
654    </script>
655    <div id="fixedBox">
656    
657    Size: <input type="text" name="totalsize" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
658    
659    <div id="mContainer">
660            <div id="gradient">&nbsp;</div>
661            <div id="mask">&nbsp;</div>
662            <div id="progressIndicator">0%</div>
663    </div>
664    <br/>
665    
666    Note:
667    <textarea name="note" cols="10" rows="5" id="note"></textarea>
668    
669    <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
670    
671    </div>
672    <!--
673    <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">
674    no debug output yet
675    </div>
676    -->
677  EOF3  EOF3
678          $retHTML .= q{          $retHTML .= q{
679                  <form name="forma" method="GET" action="$MyURL?action=burn">                          <input type="hidden" value="burn" name="action">
680                  <input type="hidden" value="burn" name="action">                          <input type="hidden" value="results" name="search_results">
681                  <input type="hidden" value="results" name="search_results">                          <table style="fview" border="0" cellspacing="0" cellpadding="2">
682                  <table style="fview" border="0" cellspacing="0" cellpadding="2">                          <tr class="tableheader">
683                  <tr class="tableheader">                          <td class="tableheader">
684                  <td class="tableheader">                                  <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
685                          <input type="checkbox" name="allFiles" onClick="checkAll('allFiles');">                          </td>
686                  </td>                          <td align="center">Share</td>
687                  <td align="center">Share</td>                          <td align="center">Backup no</td>
688                  <td align="center">Backup no</td>                          <td align="center">Type</td>
689                  <td align="center">Type</td>                          <td align="center">date</td>
690                  <td align="center">date</td>                          <td align="center">age/days</td>
691                  <td align="center">age/days</td>                          <td align="center">size/MB</td>
692                  <td align="center">size/MB</td>                          <td align="center">gzip size/kB</td>
693                  <td align="center">gzip size</td>                          </tr>
694                  </tr>  
   
                 <tr><td colspan=7 style="tableheader">  
                 <input type="submit" value="Burn selected backups on medium" name="submitBurner">  
                 </td></tr>  
695          };          };
696    
697          my @color = (' bgcolor="#e0e0e0"', '');          my @color = (' bgcolor="#e0e0e0"', '');
# Line 394  EOF3 Line 706  EOF3
706                          $host = $backup->{'host'};                          $host = $backup->{'host'};
707                  }                  }
708                  my $ftype = "";                  my $ftype = "";
709                
710                  $retHTML .= "<tr" . $color[$i %2 ] . ">";                  my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
711                  $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .  
                                 $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                                 '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                                 '"></td>';  
               
712                  $retHTML .=                  $retHTML .=
713                            '<tr' . $color[$i %2 ] . '>
714                            <td class="fview">';
715    
716                    if (($backup->{'inc_size'} || 0) > 0) {
717                            $retHTML .= '
718                            <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
719                    }
720    
721                    $retHTML .=
722                            '</td>' .
723                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
724                          '<td align="center">' . $backup->{'backupnum'} . '</td>' .                          '<td align="center">' . $backup->{'backupnum'} . '</td>' .
725                          '<td align="center">' . $backup->{'type'} . '</td>' .                          '<td align="center">' . $backup->{'type'} . '</td>' .
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>' .                          '<td align="right">' . $backup->{'inc_size'} .
730                          "</tr>\n";                          '<input type="hidden" iD="fss'.$checkbox_key .'" value="'. $backup->{'inc_size'} .'"></td>' .
   
731    
732                            "</tr>\n";
733          }          }
734    
735          $retHTML .= "</table>";          $retHTML .= "</table>";

Legend:
Removed from v.117  
changed lines
  Added in v.171

  ViewVC Help
Powered by ViewVC 1.1.26