/[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 17 by dpavlin, Mon Jul 11 13:22:38 2005 UTC revision 124 by dpavlin, Tue Sep 20 16:23:04 2005 UTC
# Line 4  package BackupPC::SearchLib; Line 4  package BackupPC::SearchLib;
4  use strict;  use strict;
5  use BackupPC::CGI::Lib qw(:all);  use BackupPC::CGI::Lib qw(:all);
6  use BackupPC::Attrib qw(:all);  use BackupPC::Attrib qw(:all);
 use Data::Dumper;  
7  use DBI;  use DBI;
8    use DateTime;
9    use vars qw(%In $MyURL);
10    use Time::HiRes qw/time/;
11    
12    my $on_page = 100;
13    my $pager_pages = 10;
14    
15    my $dsn = $Conf{SearchDSN};
16    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( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          my $dbh = get_dbh();
31          "", "", { RaiseError => 1, AutoCommit => 1 } );          my $sth = $dbh->prepare(qq{
32      my $st =                  SELECT
33        $dbh->prepare(                          shares.id       as id,
34          " SELECT shares.ID AS ID, shares.share AS name FROM shares;");                          hosts.name || ':' || shares.name as share
35      $st->execute();                  FROM shares
36      push (@ret, { 'ID' => '', 'name' => '-'});                  JOIN hosts on hostid = hosts.id
37      while ( $tmp = $st->fetchrow_hashref() ) {                  ORDER BY share
38          push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } );          } );
39      }          $sth->execute();
40      $dbh->disconnect();          push @ret, { 'id' => '', 'share' => '-'};       # dummy any
41      return @ret;  
42            while ( my $row = $sth->fetchrow_hashref() ) {
43                    push @ret, $row;
44            }
45            return @ret;
46    }
47    
48    sub epoch_to_iso {
49            my $t = shift || return;
50            my $iso = BackupPC::Lib::timeStamp(undef, $t);
51            $iso =~ s/\s/ /g;
52            return $iso;
53    }
54    
55    sub dates_from_form($) {
56            my $param = shift || return;
57    
58            sub mk_epoch_date($$) {
59                    my ($name,$suffix) = @_;
60    
61                    my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef;
62                    my $mm .= $param->{ $name . '_month_' . $suffix} ||
63                            ( $suffix eq 'from' ? 1 : 12);
64                    my $dd .= $param->{ $name . '_day_' . $suffix} ||
65                            ( $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(
72                            year => $yyyy,
73                            month => $mm,
74                            day => $dd
75                    );
76                    print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
77                    return $dt->epoch || 'NULL';
78            }
79    
80            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($) {  sub getWhere($) {
93      my ($param)    = @_;          my $param = shift || return;
     my $retSQL     = "";  
     my @conditions = ();  
     my $cond;  
94    
95                my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
     
       
     if ( defined( $param->{'search_backup_day_from'} ) && $param->{'search_backup_day_from'} ne "") {  
         push( @conditions,  
             ' strftime("%d", datetime(backups.date, "unixepoch","localtime")) >= "'  
               . $param->{'search_backup_day_from'} ."\"");  
     }  
     if ( defined( $param->{'search_backup_day_to'} ) && $param->{'search_backup_day_to'} ne "") {  
         push( @conditions,  
             ' strftime("%d", datetime(backups.date, "unixepoch","localtime")) <= "'  
               . $param->{'search_backup_day_from'}  ."\"");  
     }  
     if ( defined( $param->{'search_backup_month_from'} ) && $param->{'search_backup_month_from'} ne "") {  
         push( @conditions,  
             ' strftime("%m", datetime(backups.date, "unixepoch","localtime")) >= "'  
               . $param->{'search_backup_month_from'}  ."\"");  
     }  
     if ( defined( $param->{'search_backup_month_to'} ) && $param->{'search_backup_month_to'} ne "") {  
         push( @conditions,  
             ' strftime("%m", datetime(backups.date, "unixepoch","localtime")) <= "'  
               . $param->{'search_backup_month_to'}  ."\"");  
     }  
     if ( defined( $param->{'search_backup_year_from'} ) && $param->{'search_backup_year_from'} ne "") {  
         push( @conditions,  
             ' strftime("%Y", datetime(backups.date, "unixepoch","localtime")) >= "'  
               . $param->{'search_backup_year_from'}  ."\"");  
     }  
     if ( defined( $param->{'search_backup_year_to'} ) && $param->{'search_backup_year_to'} ne "") {  
         push( @conditions,  
             ' strftime("%Y", datetime(backups.date, "unixepoch","localtime")) <= "'  
               . $param->{'search_backup_year_to'}  ."\"");  
     }  
96    
97      if ( defined( $param->{'search_day_from'} )   && $param->{'search_day_from'} ne "" ) {          my @conditions;
98          push( @conditions,          push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
99              ' strftime("%d", datetime(files.date, "unixepoch","localtime")) >= "'          push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
100                . $param->{'search_day_from'}  ."\"");          push @conditions, qq{ files.date >= $files_from } if ($files_from);
101      }          push @conditions, qq{ files.date <= $files_to } if ($files_to);
     if ( defined( $param->{'search_month_from'} ) && $param->{'search_month_from'} ne "") {  
         push( @conditions,  
             ' strftime("%m", datetime(files.date, "unixepoch","localtime")) >= "'  
               . $param->{'search_month_from'}  ."\"");  
     }  
     if ( defined( $param->{'search_year_from'} ) && $param->{'search_year_from'} ne "") {  
         push( @conditions,  
             ' strftime("%Y", datetime(files.date, "unixepoch","localtime")) >= "'  
               . $param->{'search_year_from'}  ."\"");  
     }  
     if ( defined( $param->{'search_day_to'} )   && $param->{'search_day_to'} ne "" ) {  
         push( @conditions,  
             ' strftime("%d", datetime(files.date, "unixepoch","localtime")) <= "'  
               . $param->{'search_day_to'}  ."\"");  
     }  
     if ( defined( $param->{'search_month_to'} ) && $param->{'search_month_to'} ne "" ) {  
         push( @conditions,  
             ' strftime("%m", datetime(files.date, "unixepoch","localtime")) <= "'  
               . $param->{'search_month_to'} ."\"" );  
     }  
     if ( defined( $param->{'search_year_to'} )&& $param->{'search_year_to'} ne "" )  {  
         push( @conditions,  
             ' strftime("%Y", datetime(files.date, "unixepoch","localtime")) <= "'  
               . $param->{'search_year_to'} ."\"");  
     }  
102    
103      if ( defined( $param->{'search_host'} ) && $param->{'search_host'} ne "") {          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);
       push( @conditions, ' backups.hostID = ' . $param->{'search_host'} );  
     }  
104    
105      if ( defined ($param->{'search_filename'}) && $param->{'search_filename'} ne "") {          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
106          push (@conditions, " files.name LIKE '".$param->{'search_filename'}."%'");          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
         }  
       
     $retSQL = "";  
     foreach $cond(@conditions)  
       {  
           if ($retSQL ne "")  
             {  
                 $retSQL .= " AND ";  
             }  
           $retSQL .= $cond;  
       }        
107    
108                return join(" and ", @conditions);
     return $retSQL;  
109  }  }
110    
111  sub getFiles($$)  
112    {  sub getFiles($) {
113        my ($where, $offset) = @_;          my ($param) = @_;
114          
115                  my $offset = $param->{'offset'} || 0;
116        my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          $offset *= $on_page;
117          "", "", { RaiseError => 1, AutoCommit => 1 } );  
118        my $sql =                    my $dbh = get_dbh();
119          q{    
120                  SELECT  files.id                        AS fid,          my $sql_cols = qq{
121                          hosts.name                      AS hname,                  files.id                        AS fid,
122                          shares.name                     AS sname,                  hosts.name                      AS hname,
123                          shares.share                    AS sharename,                  shares.name                     AS sname,
124                          files.backupNum                 AS backupNum,                  files.backupnum                 AS backupnum,
125                          files.name                      AS filename,                  files.path                      AS filepath,
126                          files.path                      AS filepath,                  files.date                      AS date,
127                          shares.share||files.fullpath    AS networkPath,                  files.type                      AS type,
128                          date(files.date, 'unixepoch', 'localtime') AS date,                  files.size                      AS size
129                          files.type                      AS filetype,          };
130                          files.size                      AS size,  
131                          dvds.name                       AS dvd          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                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid                          INNER JOIN backups      ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = files.shareID
136            };          };
137    
138            my $sql_where;
139            my $where = getWhere($param);
140            $sql_where = " WHERE ". $where if ($where);
141    
142            my $sql_order = qq{
143                    ORDER BY files.date
144                    LIMIT $on_page
145                    OFFSET ?
146            };
147    
148        if (defined($where) && $where ne "")          my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
149          {          my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
150              $sql .= " WHERE ". $where;        
151            my $sth = $dbh->prepare($sql_count);
152            $sth->execute();
153            my ($results) = $sth->fetchrow_array();
154    
155            $sth = $dbh->prepare($sql_results);
156            $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        $sql .=          my @ret;
         q{            
             ORDER BY files.id  
               LIMIT 100  
               OFFSET ? * 100 + 1  
         };  
165                
166                  while (my $row = $sth->fetchrow_hashref()) {
167                          push @ret, $row;
       my $st = $dbh->prepare(  
           $sql  
           );      
       if (!defined($offset) && $offset ne "")  
       {  
         $st->bind_param(1, $offset);  
       }  
       else  
       {  
         $st->bind_param(1,0);  
       }  
       $st->execute;  
         
       my @ret = ();  
       my $tmp;  
         
       while ($tmp = $st->fetchrow_hashref())  
         {  
             push(@ret, {  
                            'hname'       => $tmp->{'hname'},  
                            'sname'       => $tmp->{'sname'},  
                            'sharename'   => $tmp->{'sharename'},  
                            'backupno'    => $tmp->{'backupNum'},  
                            'fname'       => $tmp->{'filename'},  
                            'fpath'       => $tmp->{'filepath'},  
                            'networkpath' => $tmp->{'networkPath'},  
                            'date'        => $tmp->{'date'},  
                            'type'        => $tmp->{'filetype'},  
                            'size'        => $tmp->{'size'},  
                            'id'          => $tmp->{'fid'},  
                            'dvd'         => $tmp->{'dvd'}  
                        }  
             );  
                                   
168          }          }
169              
170        $st->finish();          $sth->finish();
171        $dbh->disconnect();          return ($results, \@ret);
172        return @ret;  }
   }  
173    
174  sub getBackupsNotBurned()  sub getHyperEstraier_url($) {
175    {          my ($use_hest) = @_;
176        my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",  
177          "", "", { RaiseError => 1, AutoCommit => 1 } );                return unless $use_hest;
178        my $sql = q{  
179            SELECT          use HyperEstraier;
180              hosts.ID         AS hostID,          my ($index_path, $index_node_url);
181              hosts.name       AS host,  
182              backups.num      AS backupno,          if ($use_hest =~ m#^http://#) {
183              backups.type     AS type,                  $index_node_url = $use_hest;
184              backups.date     AS date          } else {
185            FROM backups, shares, files, hosts                  $index_path = $TopDir . '/' . $index_path;
186            WHERE                  $index_path =~ s#//#/#g;
187              backups.num    = files.backupNum  AND          }
188              shares.ID      = files.shareID    AND                    return ($index_path, $index_node_url);
189              backups.hostID = shares.hostID    AND  }
190              hosts.ID       = backups.hostID   AND  
191              files.dvdid    IS NULL  sub getFilesHyperEstraier($) {
192            GROUP BY          my ($param) = @_;
193              backups.hostID, backups.num  
194        };          my $offset = $param->{'offset'} || 0;
195        my $st = $dbh -> prepare( $sql );          $offset *= $on_page;
196        my @ret = ();  
197        $st -> execute();          die "no index_path?" unless ($hest_index_path);
198    
199        while ( my $tmp = $st -> fetchrow_hashref() )          use HyperEstraier;
200          {            
201              push(@ret, {          my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path);
202                           'host'     => $tmp->{'host'},  
203                           'hostid'   => $tmp->{'hostID'},          # open the database
204                           'backupno' => $tmp->{'backupno'},          my $db;
205                           'type'     => $tmp->{'type'},          if ($index_path) {
206                           'date'     => $tmp->{'date'}                  $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            return $ret;
293            
294    }
295    
296    sub getBackupsNotBurned() {
297    
298            my $dbh = get_dbh();
299    
300            my $sql = q{
301                    SELECT
302                            backups.hostID AS hostID,
303                            hosts.name AS host,
304                            shares.name AS share,
305                            backups.id AS backupnum,
306                            backups.type AS type,
307                            backups.date AS date,
308                            backups.size AS size
309                    FROM backups
310                    INNER JOIN shares       ON backups.shareID=shares.ID
311                    INNER JOIN hosts        ON backups.hostID = hosts.ID
312                    LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id AND archive_backup.backup_id IS NULL
313                    WHERE backups.size > 0
314                    GROUP BY
315                            backups.hostID,
316                            hosts.name,
317                            shares.name,
318                            backups.num,
319                            backups.shareid,
320                            backups.id,
321                            backups.type,
322                            backups.date,
323                            backups.size
324                    ORDER BY backups.date
325            };
326            my $sth = $dbh->prepare( $sql );
327            my @ret;
328            $sth->execute();
329    
330            while ( my $row = $sth->fetchrow_hashref() ) {
331                    $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
332                    $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
333                    my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =
334                            stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
335                                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
336                    $row->{'fs_size'} = $fs_size;
337                    push @ret, $row;
338          }          }
339                
340        return @ret;                return @ret;      
341    }  }
342    
343  sub displayBackupsGrid()  sub displayBackupsGrid()
344    {    {
345        my $retHTML = "";        my $retHTML = "";
       my $addForm = 1;  
346                
347        if ($addForm)          $retHTML .= <<EOF3;
         {  
   
             $retHTML .= <<EOF3;  
348  <script language="javascript" type="text/javascript">  <script language="javascript" type="text/javascript">
349  <!--  <!--
350    
# Line 265  sub displayBackupsGrid() Line 362  sub displayBackupsGrid()
362          }          }
363        }        }
364      }      }
365        
366        function sumiraj()
367        {
368            var suma = 0;
369            for (var i = 0; i < document.forma.elements.length; i++)    
370                    {
371                            var e = document.forma.elements[i];
372                            if ((e.checked || !e.checked) && e.name != \'all\')
373                            {
374                                    if (e.checked)
375                                    {
376                                            var ret = e.name.match("fcb(.*)");
377                                            suma += parseInt(eval("document.forma.fss"+ret[1]+".value") || 0);
378                                            
379                                    }
380                            }
381            }
382            document.forma.totalsize.value = suma;
383            return suma;
384        }
385  //-->  //-->
386  </script>        </script>      
387  EOF3  EOF3
388                $retHTML .= q{<form name="forma" method="POST" action="}."$MyURL"."?action=burn\"";          $retHTML .= q{
389                $retHTML.= q{<input type="hidden" value="burn" name="action">};                  <form name="forma" method="GET" action=};
390                $retHTML .= q{<input type="hidden" value="results" name="search_results">};                  $retHTML .= "\"".$MyURL."\"";
391          }                  $retHTML .= q{?action=burn>
392        $retHTML .= "<table style=\"fview\">";                          <input type="hidden" value="burn" name="action">
393        $retHTML .= "<tr> ";                          <input type="hidden" value="results" name="search_results">
394        if ($addForm)                          <table style="fview" border="0" cellspacing="0" cellpadding="2">
395          {                          <tr class="tableheader">
396              $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";                          <td class="tableheader">
397          }                                  <input type="checkbox" name="allFiles" onClick="checkAll('allFiles');">
398        $retHTML .=  "<td class=\"tableheader\">Host</td> <td class=\"tableheader\">Backup no</td> <td class=\"tableheader\">Type</td> <td class=\"tableheader\">date</td></tr>";                          </td>
399        my @backups = getBackupsNotBurned();                          <td align="center">Share</td>
400        my $backup;                          <td align="center">Backup no</td>
401                            <td align="center">Type</td>
402        if ($addForm)                          <td align="center">date</td>
403          {                          <td align="center">age/days</td>
404              $retHTML .= "<tr>";                          <td align="center">size/MB</td>
405              $retHTML .= "<td colspan=7 style=\"tableheader\">";                          <td align="center">gzip size</td>
406              $retHTML .= "<input type=\"submit\" value=\"Burn selected backups on medium\" name=\"submitBurner\">";                          </tr>
407              $retHTML .= "</td>";  
408              $retHTML .= "</tr>";                          <tr><td colspan=7 style="tableheader">
409                                        <input type="submit" value="Burn selected backups on medium" name="submitBurner">
410          }                          </td></tr>
411        foreach $backup(@backups)          };
412          {  
413              my $ftype = "";          my @color = (' bgcolor="#e0e0e0"', '');
414    
415            my $i = 0;
416            my $host = '';
417    
418            foreach my $backup ( getBackupsNotBurned() ) {
419    
420                    if ($host ne $backup->{'host'}) {
421                            $i++;
422                            $host = $backup->{'host'};
423                    }
424                    my $ftype = "";
425                            
426              $retHTML .= "<tr>";                  $retHTML .= "<tr" . $color[$i %2 ] . ">";
427              if ($addForm)                  $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .
428                {                                                                                          $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
429                    $retHTML .= "<td class=\"fview\"> <input type=\"checkbox\" name=\"fcb"                                                                                          '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
430                      .$backup->{'hostid'}."_".$backup->{'backupno'}                                                                                          '" onClick="sumiraj();"></td>';
                   ."\" value=\"".$backup->{'hostid'}."_".$backup->{'backupno'}."\"> </td>";  
               }      
431                            
432              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'host'} . "</td>";                  $retHTML .=
433              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'backupno'} . "</td>";                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
434              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'type'} . "</td>";                          '<td align="center">' . $backup->{'backupnum'} . '</td>' .
435              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'date'} . "<td>";                          '<td align="center">' . $backup->{'type'} . '</td>' .
436              $retHTML .= "</tr>";                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
437          }                          '<td align="center">' . $backup->{'age'} . '</td>' .
438        $retHTML .= "</table>";                          '<td align="right">' . $backup->{'size'} . '</td>' .
439        if ($addForm)                          '<td align="right">' . $backup->{'fs_size'} .
440         {                          '<input type="hidden" name="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '"'.
441             $retHTML .= "</form>";                          'value="'. $backup->{'fs_size'} .'"'.'</td>' .
442         }                          "</tr>\n";
443    
444    
445            }
446    
447            $retHTML .= "</table>";
448            $retHTML .= "total gzip size:<input type=\"text\" name=\"totalsize\"><br>";
449            $retHTML .= "Note:<input type=\"text\" name=\"note\">";
450            $retHTML .= "</form>";
451                
452        return $retHTML;          return $retHTML;
453      }      
454      
455    }        sub displayGrid($) {
456            my ($param) = @_;
457    
458            my $offset = $param->{'offset'};
459            my $hilite = $param->{'search_filename'};
460    
 sub displayGrid($$$$) {  
         my ($where, $addForm, $offset, $hilite) = @_;  
461          my $retHTML = "";          my $retHTML = "";
462    
463          if ($addForm) {          my $start_t = time();
464                  $retHTML .= qq{<form name="forma" method="POST" action="}.$MyURL.qq{?action=search">};  
465                  $retHTML.= qq{<input type="hidden" value="search" name="action">};          my ($results, $files);
466                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};          if ($param->{'use_hest'} && length($hilite) > 0) {
467                    ($results, $files) = getFilesHyperEstraier($param);
468            } else {
469                    ($results, $files) = getFiles($param);
470            }
471    
472            my $dur_t = time() - $start_t;
473            my $dur = sprintf("%0.4fs", $dur_t);
474    
475            my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);
476    
477            if ($results <= 0) {
478                    $retHTML .= qq{
479                            <p style="color: red;">No results found...</p>
480                    };
481                    return $retHTML;
482            } else {
483                    # DEBUG
484                    #use Data::Dumper;
485                    #$retHTML .= '<pre>' . Dumper($files) . '</pre>';
486          }          }
487    
488    
489          $retHTML .= qq{          $retHTML .= qq{
490          <table style="fview" width="100%">          <div>
491                  <tr>          Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
492                  <td class="tableheader">Host</td>          </div>
493                  <td class="tableheader">Type</td>          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
494                  <td class="tableheader">Name</td>                  <tr class="fviewheader">
495                  <td class="tableheader">backup no.</td>                  <td></td>
496                  <td class="tableheader">size</td>                  <td align="center">Share</td>
497                  <td class="tableheader">date</td>                  <td align="center">Type and Name</td>
498                  <td class="tableheader">Media</td>                  <td align="center">#</td>
499                    <td align="center">Size</td>
500                    <td align="center">Date</td>
501                    <td align="center">Media</td>
502                  </tr>                  </tr>
503          };          };
504          my @files = getFiles($where, $offset);  
505          my $file;          my $file;
506    
507          sub hilite_html($$) {          sub hilite_html($$) {
# Line 350  sub displayGrid($$$$) { Line 510  sub displayGrid($$$$) {
510                  return $html;                  return $html;
511          }          }
512    
513          foreach $file (@files) {          sub restore_link($$$$$$) {
514                  my $ftype = "file";                  my $type = shift;
515                  $ftype = "dir" if ($file->{'type'} == BPC_FTYPE_DIR);                  my $action = 'RestoreFile';
516                    $action = 'browse' if (lc($type) eq 'dir');
517                  $retHTML .= "<tr>";                  return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);
518            }
519                  foreach my $v ((  
520                          $file->{'hname'},          my $i = $offset * $on_page;
521                          $ftype,  
522                          hilite_html( $file->{'fpath'}, $hilite ),          foreach $file (@{ $files }) {
523                          $file->{'backupno'},                  $i++;
524                          $file->{'size'},  
525                          $file->{'date'},                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
526                          $file->{'dvd'}                  $retHTML .= qq{<tr class="fviewborder">};
527                  )) {  
528                          $retHTML .= qq{<td class="fviewborder">$v</td>};                  $retHTML .= qq{<td class="fviewborder">$i</td>};
529                  }  
530                    $retHTML .=
531                            qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} .
532                            qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle">&nbsp;} . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} .
533                            qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .
534                            qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
535                            qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
536                            qq{<td class="fviewborder">} . '?' . qq{</td>};
537    
538                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
539          }          }
540          $retHTML .= "</table>";          $retHTML .= "</table>";
541    
542          # skip pager          # all variables which has to be transfered
543          return $retHTML;          foreach my $n (qw/search_day_from search_month_from search_year_from search_day_to search_month_to search_year_to search_backup_day_from search_backup_month_from search_backup_year_from search_backup_day_to search_backup_month_to search_backup_year_to search_filename offset/) {
544                    $retHTML .= qq{<INPUT TYPE="hidden" NAME="$n" VALUE="$In{$n}">\n};
545            }
546    
547            my $del = '';
548            my $max_page = int( $results / $on_page );
549            my $page = 0;
550    
551            sub page_link($$$) {
552                    my ($param,$page,$display) = @_;
553    
554                    $param->{'offset'} = $page;
555    
556                    my $html = '<a href = "' . $MyURL;
557                    my $del = '?';
558                    foreach my $k (keys %{ $param }) {
559                            if ($param->{$k}) {
560                                    $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};
561                                    $del = '&';
562                            }
563                    }
564                    $html .= '">' . $display . '</a>';
565            }
566    
567            $retHTML .= '<div style="text-align: center;">';
568    
569          $retHTML .= "<INPUT TYPE=\"hidden\" VALUE=\"\" NAME=\"offset\">";          if ($offset > 0) {
570          for (my $ii = 1; $ii <= $#files; $ii++) {                  $retHTML .= page_link($param, $offset - 1, '&lt;&lt;') . ' ';
571                  $retHTML .= "<a href = \"#\" onclick=\"document.forma.offset.value=$ii;document.forma.submit();\">$ii</a>";          }
572                  if ($ii < $#files) {  
573                          $retHTML .= " | ";          while ($page <= $max_page) {
574                    if ($page == $offset) {
575                            $retHTML .= $del . '<b>' . ($page + 1) . '</b>';
576                    } else {
577                            $retHTML .= $del . page_link($param, $page, $page + 1);
578                    }
579    
580                    if ($page < $offset - $pager_pages && $page != 0) {
581                            $retHTML .= " ... ";
582                            $page = $offset - $pager_pages;
583                            $del = '';
584                    } elsif ($page > $offset + $pager_pages && $page != $max_page) {
585                            $retHTML .= " ... ";
586                            $page = $max_page;
587                            $del = '';
588                    } else {
589                            $del = ' | ';
590                            $page++;
591                  }                  }
592          }          }
593    
594          $retHTML .= "</form>" if ($addForm);          if ($offset < $max_page) {
595                          $retHTML .= ' ' . page_link($param, $offset + 1, '&gt;&gt;');
596            }
597    
598            $retHTML .= "</div>";
599    
600          return $retHTML;          return $retHTML;
601  }  }
602    

Legend:
Removed from v.17  
changed lines
  Added in v.124

  ViewVC Help
Powered by ViewVC 1.1.26