/[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 58 by dpavlin, Sun Aug 21 14:26:23 2005 UTC revision 155 by dpavlin, Mon Oct 10 13:04:48 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 $hest_index_path = $Conf{HyperEstraierIndex};
19    
20    my $dbh;
21    
22    sub get_dbh {
23            $dbh ||= DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
24            return $dbh;
25    }
26    
27  sub getUnits() {  sub getUnits() {
28      my @ret = ();          my @ret;
29      my $tmp;  
30      my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
31      my $st =          my $sth = $dbh->prepare(qq{
32        $dbh->prepare(                  SELECT
33          " SELECT shares.ID AS ID, shares.share AS name FROM shares;");                          shares.id       as id,
34      $st->execute();                          hosts.name || ':' || shares.name as share
35      push (@ret, { 'ID' => '', 'name' => '-'});                  FROM shares
36      while ( $tmp = $st->fetchrow_hashref() ) {                  JOIN hosts on hostid = hosts.id
37          push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } );                  ORDER BY share
38      }          } );
39      $dbh->disconnect();          $sth->execute();
40      return @ret;          push @ret, { 'id' => '', 'share' => '-'};       # dummy any
41    
42            while ( my $row = $sth->fetchrow_hashref() ) {
43                    push @ret, $row;
44            }
45            return @ret;
46  }  }
47    
48  sub epoch_to_iso {  sub epoch_to_iso {
49          my $t = shift || return;          my $t = shift || return;
50          my $dt = DateTime->from_epoch( epoch => $t ) || return;          my $iso = BackupPC::Lib::timeStamp(undef, $t);
51  print STDERR "$t == ",$dt->epoch,"\n";          $iso =~ s/\s/ /g;
52          return $dt->ymd . ' ' . $dt->hms;          return $iso;
53  }  }
54    
55  sub getWhere($) {  sub dates_from_form($) {
56          my ($param)    = @_;          my $param = shift || return;
         my @conditions;  
57    
58          sub mk_epoch_date($$) {          sub mk_epoch_date($$) {
59                  my ($name,$suffix) = @_;                  my ($name,$suffix) = @_;
60    
61                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef;
62                  my $mm .= $param->{ $name . '_month_' . $suffix} ||                  my $mm .= $param->{ $name . '_month_' . $suffix} ||
63                          ( $suffix eq 'from' ? 1 : 12);                          ( $suffix eq 'from' ? 1 : 12);
64                  my $dd .= $param->{ $name . '_day_' . $suffix} ||                  my $dd .= $param->{ $name . '_day_' . $suffix} ||
65                          ( $suffix eq 'from' ? 1 : 31);                          ( $suffix eq 'from' ? 1 : 31);
66    
67                    $yyyy =~ s/\D//g;
68                    $mm =~ s/\D//g;
69                    $dd =~ s/\D//g;
70    
71                  my $dt = new DateTime(                  my $dt = new DateTime(
72                          year => $yyyy,                          year => $yyyy,
73                          month => $mm,                          month => $mm,
74                          day => $dd                          day => $dd
75                  );                  );
76                    print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
77                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
78          }          }
79    
80          my $backup_from = mk_epoch_date('search_backup', 'from');          my @ret = (
81                    mk_epoch_date('search_backup', 'from'),
82                    mk_epoch_date('search_backup', 'to'),
83                    mk_epoch_date('search', 'from'),
84                    mk_epoch_date('search', 'to'),
85            );
86    
87            return @ret;
88    
89    }
90    
91    
92    sub getWhere($) {
93            my $param = shift || return;
94    
95            my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
96    
97            my @conditions;
98          push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);          push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
         my $backup_to = mk_epoch_date('search_backup', 'to');  
99          push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);          push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
   
         my $files_from = mk_epoch_date('search', 'from');  
100          push @conditions, qq{ files.date >= $files_from } if ($files_from);          push @conditions, qq{ files.date >= $files_from } if ($files_from);
         my $files_to = mk_epoch_date('search', 'to');  
101          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
102    
103          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(" | ",@conditions);
104        
105          push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'});          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
106            push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
107          push (@conditions, " upper(files.name) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});  
108            return join(" and ", @conditions);
         return (  
                 join(" and ", @conditions),  
                 $files_from, $files_to,  
                 $backup_from, $backup_to  
         );  
109  }  }
110    
111    
112  sub getFiles($$) {  sub getFiles($) {
113          my ($where, $offset) = @_;          my ($param) = @_;
114    
115            my $offset = $param->{'offset'} || 0;
116            $offset *= $on_page;
117    
118          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
119    
120          my $sql_cols = qq{          my $sql_cols = qq{
121                  files.id                        AS fid,                  files.id                        AS fid,
122                  hosts.name                      AS hname,                  hosts.name                      AS hname,
123                  shares.name                     AS sname,                  shares.name                     AS sname,
124                  shares.share                    AS sharename,                  files.backupnum                 AS backupnum,
                 files.backupNum                 AS backupNum,  
                 files.name                      AS filename,  
125                  files.path                      AS filepath,                  files.path                      AS filepath,
                 shares.share||files.fullpath    AS networkPath,  
126                  files.date                      AS date,                  files.date                      AS date,
127                  files.type                      AS filetype,                  files.type                      AS type,
128                  files.size                      AS size,                  files.size                      AS size
         };  
   
         my $sql_dvd_cols = qq{  
                 dvds.name                       AS dvd  
129          };          };
130    
131          my $sql_from = qq{          my $sql_from = qq{
132                  FROM files                  FROM files
133                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
134                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
135                          INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID                          INNER JOIN backups      ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = files.shareID
         };  
   
         my $sql_dvd_from = qq{  
                         LEFT  JOIN dvds         ON dvds.ID = files.dvdid  
136          };          };
137    
138          my $sql_where;          my $sql_where;
139            my $where = getWhere($param);
140          $sql_where = " WHERE ". $where if ($where);          $sql_where = " WHERE ". $where if ($where);
141    
142          my $sql_order = qq{          my $sql_order = qq{
143                  ORDER BY files.id                  ORDER BY files.date
144                          LIMIT $on_page                  LIMIT $on_page
145                          OFFSET ?                  OFFSET ?
146          };          };
147    
148          $offset ||= 0;          my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
149          $offset = ($offset * $on_page) + 1;          my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
150    
151          my $sth = $dbh->prepare(qq{ select count(files.id) $sql_from $sql_where });          my $sth = $dbh->prepare($sql_count);
152          $sth->execute();          $sth->execute();
   
153          my ($results) = $sth->fetchrow_array();          my ($results) = $sth->fetchrow_array();
154    
155          $sth = $dbh->prepare(qq{ select $sql_cols $sql_dvd_cols $sql_from $sql_dvd_from $sql_where $sql_order });          $sth = $dbh->prepare($sql_results);
156          $sth->execute( $offset );          $sth->execute( $offset );
157    
158            if ($sth->rows != $results) {
159                    my $bug = "$0 BUG: [[ $sql_count ]] = $results while [[ $sql_results ]] = " . $sth->rows;
160                    $bug =~ s/\s+/ /gs;
161                    print STDERR "$bug\n";
162            }
163    
164          my @ret;          my @ret;
165                
166          while (my $row = $sth->fetchrow_hashref()) {          while (my $row = $sth->fetchrow_hashref()) {
167                  push(@ret, {                  push @ret, $row;
                         'hname'         => $row->{'hname'},  
                         'sname'         => $row->{'sname'},  
                         'sharename'     => $row->{'sharename'},  
                         'backupno'      => $row->{'backupnum'},  
                         'fname'         => $row->{'filename'},  
                         'fpath'         => $row->{'filepath'},  
                         'networkpath'   => $row->{'networkpath'},  
                         'date'          => $row->{'date'},  
                         'type'          => $row->{'filetype'},  
                         'size'          => $row->{'size'},  
                         'id'            => $row->{'fid'},  
                         'dvd'           => $row->{'dvd'}  
                 });  
168          }          }
169              
170          $sth->finish();          $sth->finish();
         $dbh->disconnect();  
171          return ($results, \@ret);          return ($results, \@ret);
172  }  }
173    
174    sub getHyperEstraier_url($) {
175            my ($use_hest) = @_;
176    
177            return unless $use_hest;
178    
179            use HyperEstraier;
180            my ($index_path, $index_node_url);
181    
182            if ($use_hest =~ m#^http://#) {
183                    $index_node_url = $use_hest;
184            } else {
185                    $index_path = $TopDir . '/' . $index_path;
186                    $index_path =~ s#//#/#g;
187            }
188            return ($index_path, $index_node_url);
189    }
190    
191    sub getFilesHyperEstraier($) {
192            my ($param) = @_;
193    
194            my $offset = $param->{'offset'} || 0;
195            $offset *= $on_page;
196    
197            die "no index_path?" unless ($hest_index_path);
198    
199            use HyperEstraier;
200    
201            my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path);
202    
203            # open the database
204            my $db;
205            if ($index_path) {
206                    $db = HyperEstraier::Database->new();
207                    $db->open($index_path, $HyperEstraier::ESTDBREADER);
208            } elsif ($index_node_url) {
209                    $db ||= HyperEstraier::Node->new($index_node_url);
210                    $db->set_auth('admin', 'admin');
211            } else {
212                    die "BUG: unimplemented";
213            }
214    
215            # create a search condition object
216            my $cond = HyperEstraier::Condition->new();
217    
218            my $q = $param->{'search_filename'};
219            my $shareid = $param->{'search_share'};
220    
221            if (length($q) > 0) {
222                    # exact match
223                    $cond->add_attr("filepath ISTRINC $q");
224    
225                    $q =~ s/(.)/$1 /g;
226                    # set the search phrase to the search condition object
227                    $cond->set_phrase($q);
228            }
229    
230            my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
231    
232            $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
233            $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
234    
235            $cond->add_attr("date NUMGE $files_from") if ($files_from);
236            $cond->add_attr("date NUMLE $files_to") if ($files_to);
237    
238            $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
239    
240    #       $cond->set_max( $offset + $on_page );
241            $cond->set_options( $HyperEstraier::Condition::SURE );
242            $cond->set_order( 'date NUMA' );
243    
244            # get the result of search
245            my @res;
246            my ($result, $hits);
247    
248            if ($index_path) {
249                    $result = $db->search($cond, 0);
250                    $hits = $result->size;
251            } elsif ($index_node_url) {
252                    $result = $db->search($cond, 0);
253                    $hits = $result->doc_num;
254            } else {
255                    die "BUG: unimplemented";
256            }
257    
258            # for each document in result
259            for my $i ($offset .. ($offset + $on_page - 1)) {
260                    last if ($i >= $hits);
261    
262                    my $doc;
263                    if ($index_path) {
264                            my $id = $result->get($i);
265                            $doc = $db->get_doc($id, 0);
266                    } elsif ($index_node_url) {
267                            $doc = $result->get_doc($i);
268                    } else {
269                            die "BUG: unimplemented";
270                    }
271    
272                    my $row;
273                    foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) {
274                            $row->{$c} = $doc->attr($c);
275                    }
276                    push @res, $row;
277            }
278    
279            return ($hits, \@res);
280    }
281    
282    sub getGzipName($$$)
283    {
284            my ($host, $share, $backupnum) = @_;
285            my $ret = $Conf{GzipSchema};
286            
287            $share =~ s/\//_/g;
288            $ret =~ s/\\h/$host/ge;
289            $ret =~ s/\\s/$share/ge;
290            $ret =~ s/\\n/$backupnum/ge;
291    
292            $ret =~ s/__+/_/g;
293    
294            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 = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
330          my $sql = q{  
331          SELECT          my $sql = q{
332                  hosts.ID                AS hostid,                  SELECT
333                  min(hosts.name)         AS host,                          backups.hostID AS hostID,
334                  backups.num             AS backupno,                          hosts.name AS host,
335                  min(backups.type)       AS type,                          shares.name AS share,
336                  min(backups.date)       AS date                          backups.num AS backupnum,
337          FROM backups, shares, files, hosts                          backups.type AS type,
338          WHERE                          backups.date AS date,
339                  backups.num     = files.backupNum       AND                          backups.size AS size,
340                  shares.ID       = files.shareID         AND                                  backups.id AS id
341                  backups.hostID  = shares.hostID         AND                  FROM backups
342                  hosts.ID        = backups.hostID        AND                  INNER JOIN shares       ON backups.shareID=shares.ID
343                  files.dvdid     IS NULL                  INNER JOIN hosts        ON backups.hostID = hosts.ID
344          GROUP BY                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
345                  backups.hostID, backups.num, hosts.id                  WHERE backups.size > 0 AND archive_backup.backup_id IS NULL
346          ORDER BY min(backups.date)                  GROUP BY
347                            backups.hostID,
348                            hosts.name,
349                            shares.name,
350                            backups.num,
351                            backups.shareid,
352                            backups.id,
353                            backups.type,
354                            backups.date,
355                            backups.size
356                    ORDER BY backups.date
357          };          };
358          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
359          my @ret;          my @ret;
360          $sth->execute();          $sth->execute();
361    
362          while ( my $row = $sth->fetchrow_hashref() ) {                while ( my $row = $sth->fetchrow_hashref() ) {
363                  push(@ret, {                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
364                           'host'         => $row->{'host'},                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
365                           'hostid'       => $row->{'hostid'},                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =
366                           'backupno'     => $row->{'backupno'},                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
367                           'type'         => $row->{'type'},                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
368                           'date'         => $row->{'date'},                  $row->{'fs_size'} = $fs_size;
369                           'age'          => sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ),                  push @ret, $row;
                        }  
                 );  
370          }          }
371                
372          return @ret;                return @ret;      
373  }  }
374    
375  sub displayBackupsGrid()  sub displayBackupsGrid() {
376    {  
377        my $retHTML = "";          my $retHTML .= q{
378        my $addForm = 1;                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
379                  };
380        if ($addForm) {  
381            $retHTML .= <<'EOF3';
382    <style type="text/css">
383    <!--
384    DIV#fixedBox {
385            position: absolute;
386            top: 50em;
387            left: -24%;
388            padding: 0.5em;
389            width: 20%;
390            background-color: #E0F0E0;
391            border: 1px solid #00C000;
392    }
393    
394    DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
395            font-size: 10pt;
396    }
397    
398    FORM>DIV#fixedBox {
399            position: fixed !important;
400            left: 0.5em !important;
401            top: auto !important;
402            bottom: 1em !important;
403            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;
412            width: 100%;
413    }
414    
415    DIV#fixedBox #submitBurner {
416            display: block;
417            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%;
429            font-size: 100%;
430    }
431    
432    * HTML DIV#fixedBox {
433            position: absolute;
434    }
435    
436              $retHTML .= <<EOF3;  #mContainer, #gradient, #mask, #progressIndicator {
437  <script language="javascript" type="text/javascript">          display: block;
438            width: 100%;
439            font-size: 10pt;
440            font-weight: bold;
441            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>
484    <script type="text/javascript">
485  <!--  <!--
486    
487      function checkAll(location)  var debug_div = null;
     {  
       for (var i=0;i<document.forma.elements.length;i++)  
       {  
         var e = document.forma.elements[i];  
         if ((e.checked || !e.checked) && e.name != \'all\') {  
             if (eval("document.forma."+location+".checked")) {  
                 e.checked = true;  
             } else {  
                 e.checked = false;  
             }  
         }  
       }  
     }  
 //-->  
 </script>        
488  EOF3  EOF3
               $retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\"";  
               $retHTML.= q{<input type="hidden" value="burn" name="action">};  
               $retHTML .= q{<input type="hidden" value="results" name="search_results">};  
         }  
         $retHTML .= qq{<table style="fview"><tr>};  
   
         if ($addForm) {  
             $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";  
         }  
         $retHTML .=  qq{  
                 <td class="tableheader">Host</td>  
                 <td class="tableheader">Backup no</td>  
                 <td class="tableheader">Type</td>  
                 <td class="tableheader">date</td>  
                 <td class="tableheader">age/days</td>  
                 </tr>  
         };  
489    
490          my @backups = getBackupsNotBurned();          # take maximum archive size from configuration
491          my $backup;          $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';
492    
493          if ($addForm) {          $retHTML .= <<'EOF3';
494                  $retHTML .= qq{  
495                          <tr><td colspan=7 style="tableheader">  function debug(msg) {
496                          <input type="submit" value="Burn selected backups on medium" name="submitBurner">  //      return; // Disable debugging
497                          </td></tr>  
498                  };          if (! debug_div) debug_div = document.getElementById('debug');
499    
500            // this will create debug div if it doesn't exist.
501            if (! debug_div) {
502                    debug_div = document.createElement('div');
503                    if (document.body) document.body.appendChild(debug_div);
504                    else debug_div = null;
505            }
506            if (debug_div) {
507                    debug_div.appendChild(document.createTextNode(msg));
508                    debug_div.appendChild(document.createElement("br"));
509          }          }
510    }
511    
         foreach $backup(@backups) {  
512    
513                  my $ftype = "";  var element_id_cache = Array();
514                
515                  $retHTML .= "<tr>";  function element_id(name,element) {
516                  if ($addForm) {          if (! element_id_cache[name]) {
517                          $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .                  element_id_cache[name] = self.document.getElementById(name);
                                 $backup->{'hostid'}.'_'.$backup->{'backupno'} .  
                                 '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupno'} .  
                                 '"></td>';  
                 }            
               
                 $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .  
                         '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .  
                         '<td class="fviewborder">' . $backup->{'type'} . '</td>' .  
                         '<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .  
                         '<td class="fviewborder">' . $backup->{'age'} . '</td>' .  
                         '</tr>';  
518          }          }
519            return element_id_cache[name];
520    }
521    
522          $retHTML .= "</table>";  function checkAll(location) {
523            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');
528            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
529    
530            for (var i = 0; i < len; i++) {
531                    var e = f.elements[i];
532                    if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
533                            if (check_all.checked) {
534                                    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 {
545                                    e.checked = false;
546                            }
547                    }
548            }
549            update_sum(suma);
550    }
551    
552    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) {
559            var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
560            var len = element_id('forma').elements.length;
561            if (e) {
562                    var size = parseInt( element_id("fss" + e.name.substr(3)).value);
563                    if (e.checked) {
564                            suma += size;
565                    } else {
566                            suma -= size;
567                    }
568            } else {
569                    suma = 0;
570                    for (var i = 0; i < len; i++) {
571                            var e = element_id('forma').elements[i];
572                            if (e.name != 'all' && e.checked && e.name.substr(0,3) == 'fcb') {
573                                    var el = element_id("fss" + e.name.substr(3));
574                                    if (el && el.value) suma += parseInt(el.value) || 0;
575                            }
576                    }
577            }
578            update_sum(suma);
579            return suma;
580    }
581    
582    /* progress bar */
583    
584    var _pbar_width = null;
585    var _pbar_warn = 10;    // change color in last 10%
586    
587          if ($addForm) {  function pbar_reset() {
588                  $retHTML .= "</form>";          element_id("mask").style.left = "0px";
589            _pbar_width = element_id("mContainer").offsetWidth - 2;
590            element_id("mask").style.width = _pbar_width + "px";
591            element_id("mask").style.display = "block";
592            element_id("progressIndicator").style.zIndex  = 10;
593            element_id("progressIndicator").innerHTML = "0";
594    }
595    
596    function dec2hex(d) {
597            var hch = '0123456789ABCDEF';
598            var a = d % 16;
599            var q = (d - a) / 16;
600            return hch.charAt(q) + hch.charAt(a);
601    }
602    
603    function pbar_set(amount, max) {
604            debug('pbar_set('+amount+', '+max+')');
605    
606            if (_pbar_width == null) {
607                    var _mc = element_id("mContainer");
608                    if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
609                    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);
614            var p90 = 100 - _pbar_warn;
615            var pcol = pcnt - p90;
616            if (Math.round(pcnt) <= 100) {
617                    if (pcol < 0) pcol = 0;
618                    var e = element_id("submitBurner");
619                    debug('enable_button');
620                    e.disabled = false;
621                    var a = e.getAttributeNode('disabled') || null;
622                    if (a) e.removeAttributeNode(a);
623            } else {
624                    debug('disable button');
625                    pcol = _pbar_warn;
626                    var e = element_id("submitBurner");
627                    if (!e.disabled) e.disabled = true;
628            }
629            var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
630            var col = '#FF' + dec2hex(col_g) + '00';
631    
632            //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
633            element_id("gradient").style.backgroundColor = col;
634    
635            element_id("progressIndicator").innerHTML = pcnt + '%';
636            //element_id("progressIndicator").innerHTML = amount;
637    
638            element_id("mask").style.clip = 'rect(' + Array(
639                    '0px',
640                    element_id("mask").offsetWidth + 'px',
641                    element_id("mask").offsetHeight + 'px',
642                    Math.round(_pbar_width * amount / max) + 'px'
643            ).join(' ') + ')';
644    }
645    
646    if (!self.body) self.body = new Object();
647    self.onload = self.document.onload = self.body.onload = function() {
648            //pbar_reset();
649            sumiraj();
650    };
651    
652    // -->
653    </script>
654    <div id="fixedBox">
655    
656    Size: <input type="text" name="totalsize" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
657    
658    <div id="mContainer">
659            <div id="gradient">&nbsp;</div>
660            <div id="mask">&nbsp;</div>
661            <div id="progressIndicator">0%</div>
662    </div>
663    <br/>
664    
665    Note:
666    <textarea name="note" cols="10" rows="5" id="note"></textarea>
667    
668    <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
669    
670    </div>
671    <!--
672    <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">
673    no debug output yet
674    </div>
675    -->
676    EOF3
677            $retHTML .= q{
678                            <input type="hidden" value="burn" name="action">
679                            <input type="hidden" value="results" name="search_results">
680                            <table style="fview" border="0" cellspacing="0" cellpadding="2">
681                            <tr class="tableheader">
682                            <td class="tableheader">
683                                    <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
684                            </td>
685                            <td align="center">Share</td>
686                            <td align="center">Backup no</td>
687                            <td align="center">Type</td>
688                            <td align="center">date</td>
689                            <td align="center">age/days</td>
690                            <td align="center">size/MB</td>
691                            <td align="center">gzip size</td>
692                            </tr>
693    
694            };
695    
696            my @color = (' bgcolor="#e0e0e0"', '');
697    
698            my $i = 0;
699            my $host = '';
700    
701            foreach my $backup ( getBackupsNotBurned() ) {
702    
703                    if ($host ne $backup->{'host'}) {
704                            $i++;
705                            $host = $backup->{'host'};
706                    }
707                    my $ftype = "";
708    
709                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
710    
711                    $retHTML .=
712                            '<tr' . $color[$i %2 ] . '>
713                            <td class="fview">';
714    
715                    # FIXME
716                    $backup->{'fs_size'} = int($backup->{'size'} * 1024);
717    
718                    if (($backup->{'fs_size'} || 0) > 0) {
719                            $retHTML .= '
720                            <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
721                    }
722    
723                    $retHTML .=
724                            '</td>' .
725                            '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
726                            '<td align="center">' . $backup->{'backupnum'} . '</td>' .
727                            '<td align="center">' . $backup->{'type'} . '</td>' .
728                            '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
729                            '<td align="center">' . $backup->{'age'} . '</td>' .
730                            '<td align="right">' . $backup->{'size'} . '</td>' .
731                            '<td align="right">' . $backup->{'fs_size'} .
732                            '<input type="hidden" iD="fss'.$checkbox_key .'" value="'. $backup->{'fs_size'} .'"></td>' .
733    
734                            "</tr>\n";
735          }          }
736    
737            $retHTML .= "</table>";
738            $retHTML .= "</form>";
739                
740          return $retHTML;          return $retHTML;
741  }        }      
742    
743  sub displayGrid($$$$) {  sub displayGrid($) {
744          my ($where, $addForm, $offset, $hilite) = @_;          my ($param) = @_;
745    
746            my $offset = $param->{'offset'};
747            my $hilite = $param->{'search_filename'};
748    
749          my $retHTML = "";          my $retHTML = "";
750    
         if ($addForm) {  
                 $retHTML .= qq{<form name="forma" method="GET" action="$MyURL">};  
                 $retHTML.= qq{<input type="hidden" value="search" name="action">};  
                 $retHTML .= qq{<input type="hidden" value="results" name="search_results">};  
         }  
   
751          my $start_t = time();          my $start_t = time();
752    
753          my ($results, $files) = getFiles($where, $offset);          my ($results, $files);
754            if ($param->{'use_hest'} && length($hilite) > 0) {
755                    ($results, $files) = getFilesHyperEstraier($param);
756            } else {
757                    ($results, $files) = getFiles($param);
758            }
759    
760          my $dur_t = time() - $start_t;          my $dur_t = time() - $start_t;
761          my $dur = sprintf("%0.4fs", $dur_t);          my $dur = sprintf("%0.4fs", $dur_t);
762    
763          my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);          my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);
764    
765            if ($results <= 0) {
766                    $retHTML .= qq{
767                            <p style="color: red;">No results found...</p>
768                    };
769                    return $retHTML;
770            } else {
771                    # DEBUG
772                    #use Data::Dumper;
773                    #$retHTML .= '<pre>' . Dumper($files) . '</pre>';
774            }
775    
776    
777          $retHTML .= qq{          $retHTML .= qq{
778          <br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)          <div>
779          <table style="fview" width="100%">          Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
780                  <tr>          </div>
781                  <td class="tableheader">Share</td>          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
782                  <td class="tableheader">Name</td>                  <tr class="fviewheader">
783                  <td class="tableheader">Type</td>                  <td></td>
784                  <td class="tableheader">#</td>                  <td align="center">Share</td>
785                  <td class="tableheader">Size</td>                  <td align="center">Type and Name</td>
786                  <td class="tableheader">Date</td>                  <td align="center">#</td>
787                  <td class="tableheader">Media</td>                  <td align="center">Size</td>
788                    <td align="center">Date</td>
789                    <td align="center">Media</td>
790                  </tr>                  </tr>
791          };          };
792    
# Line 334  sub displayGrid($$$$) { Line 805  sub displayGrid($$$$) {
805                  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, @_);
806          }          }
807    
808            my $i = $offset * $on_page;
809    
810          foreach $file (@{ $files }) {          foreach $file (@{ $files }) {
811                    $i++;
812    
813                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
814                  $retHTML .= "<tr>";                  $retHTML .= qq{<tr class="fviewborder">};
815    
816                  foreach my $v ((                  $retHTML .= qq{<td class="fviewborder">$i</td>};
817                          $file->{'sharename'},  
818                          qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center">&nbsp;} . hilite_html( $file->{'fpath'}, $hilite ),                  $retHTML .=
819                          $typeStr,                          qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} .
820                          restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ),                          qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle">&nbsp;} . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} .
821                          $file->{'size'},                          qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .
822                          epoch_to_iso( $file->{'date'} ),                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
823                          $file->{'dvd'}                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
824                  )) {                          qq{<td class="fviewborder">} . '?' . qq{</td>};
                         $retHTML .= qq{<td class="fviewborder">$v</td>};  
                 }  
825    
826                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
827          }          }
# Line 363  sub displayGrid($$$$) { Line 836  sub displayGrid($$$$) {
836          my $max_page = int( $results / $on_page );          my $max_page = int( $results / $on_page );
837          my $page = 0;          my $page = 0;
838    
839          my $link_fmt = '<a href = "#" onclick="document.forma.offset.value=%d;document.forma.submit();">%s</a>';          sub page_link($$$) {
840                    my ($param,$page,$display) = @_;
841    
842                    $param->{'offset'} = $page;
843    
844                    my $html = '<a href = "' . $MyURL;
845                    my $del = '?';
846                    foreach my $k (keys %{ $param }) {
847                            if ($param->{$k}) {
848                                    $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};
849                                    $del = '&';
850                            }
851                    }
852                    $html .= '">' . $display . '</a>';
853            }
854    
855          $retHTML .= '<div style="text-align: center;">';          $retHTML .= '<div style="text-align: center;">';
856    
857          if ($offset > 0) {          if ($offset > 0) {
858                  $retHTML .= sprintf($link_fmt, $offset - 1, '&lt;&lt;') . ' ';                  $retHTML .= page_link($param, $offset - 1, '&lt;&lt;') . ' ';
859          }          }
860    
861          while ($page <= $max_page) {          while ($page <= $max_page) {
862                  if ($page == $offset) {                  if ($page == $offset) {
863                          $retHTML .= $del . '<b>' . ($page + 1) . '</b>';                          $retHTML .= $del . '<b>' . ($page + 1) . '</b>';
864                  } else {                  } else {
865                          $retHTML .= $del . sprintf($link_fmt, $page, $page + 1);                          $retHTML .= $del . page_link($param, $page, $page + 1);
866                  }                  }
867    
868                  if ($page < $offset - $pager_pages && $page != 0) {                  if ($page < $offset - $pager_pages && $page != 0) {
# Line 393  sub displayGrid($$$$) { Line 880  sub displayGrid($$$$) {
880          }          }
881    
882          if ($offset < $max_page) {          if ($offset < $max_page) {
883                  $retHTML .= ' ' . sprintf($link_fmt, $offset + 1, '&gt;&gt;');                  $retHTML .= ' ' . page_link($param, $offset + 1, '&gt;&gt;');
884          }          }
885    
886          $retHTML .= "</div>";          $retHTML .= "</div>";
887    
         $retHTML .= "</form>" if ($addForm);  
   
888          return $retHTML;          return $retHTML;
889  }  }
890    

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

  ViewVC Help
Powered by ViewVC 1.1.26