/[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 31 by dpavlin, Sun Jul 31 16:16:55 2005 UTC revision 109 by dpavlin, Thu Sep 1 18:30:51 2005 UTC
# Line 5  use strict; Line 5  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);
7  use DBI;  use DBI;
8    use DateTime;
9  use vars qw(%In $MyURL);  use vars qw(%In $MyURL);
10    use Time::HiRes qw/time/;
11    
12  my $on_page = 100;  my $on_page = 100;
13  my $pager_pages = 10;  my $pager_pages = 10;
14    
15    my $dsn = $Conf{SearchDSN};
16    my $db_user = $Conf{SearchUser} || '';
17    
18    my $index_path = $Conf{HyperEstraierIndex};
19    if ($index_path) {
20            $index_path = $TopDir . '/' . $index_path;
21            $index_path =~ s#//#/#g;
22    }
23    
24    my $dbh;
25    
26    sub get_dbh {
27            $dbh ||= DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
28            return $dbh;
29    }
30    
31  sub getUnits() {  sub getUnits() {
32      my @ret = ();          my @ret;
33      my $tmp;  
34      my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          my $dbh = get_dbh();
35          "", "", { RaiseError => 1, AutoCommit => 1 } );          my $sth = $dbh->prepare(qq{
36      my $st =                  SELECT
37        $dbh->prepare(                          shares.id       as id,
38          " SELECT shares.ID AS ID, shares.share AS name FROM shares;");                          hosts.name || ':' || shares.name as share
39      $st->execute();                  FROM shares
40      push (@ret, { 'ID' => '', 'name' => '-'});                  JOIN hosts on hostid = hosts.id
41      while ( $tmp = $st->fetchrow_hashref() ) {                  ORDER BY share
42          push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } );          } );
43      }          $sth->execute();
44      $dbh->disconnect();          push @ret, { 'id' => '', 'share' => '-'};       # dummy any
45      return @ret;  
46            while ( my $row = $sth->fetchrow_hashref() ) {
47                    push @ret, $row;
48            }
49            return @ret;
50  }  }
51    
52  sub getWhere($) {  sub epoch_to_iso {
53          my ($param)    = @_;          my $t = shift || return;
54          my @conditions;          my $iso = BackupPC::Lib::timeStamp(undef, $t);
55            $iso =~ s/\s/ /g;
56            return $iso;
57    }
58    
59          sub mk_iso_date($$) {  sub dates_from_form($) {
60            my $param = shift || return;
61    
62            sub mk_epoch_date($$) {
63                  my ($name,$suffix) = @_;                  my ($name,$suffix) = @_;
64    
65                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef;
66                  my $mm .= $param->{ $name . '_month_' . $suffix} ||                  my $mm .= $param->{ $name . '_month_' . $suffix} ||
67                          ( $suffix eq 'from' ? 1 : 12);                          ( $suffix eq 'from' ? 1 : 12);
68                  my $dd .= $param->{ $name . '_day_' . $suffix} ||                  my $dd .= $param->{ $name . '_day_' . $suffix} ||
69                          ( $suffix eq 'from' ? 1 : 31);                          ( $suffix eq 'from' ? 1 : 31);
                 return sprintf("%04d-%02d-%02d", $yyyy, $mm, $dd);  
         }  
70    
71          my $backup_from = mk_iso_date('search_backup', 'from');                  $yyyy =~ s/\D//g;
72          push @conditions, qq{ date(backups.date, 'unixepoch','localtime') >= '$backup_from' } if ($backup_from);                  $mm =~ s/\D//g;
73          my $backup_to = mk_iso_date('search_backup', 'to');                  $dd =~ s/\D//g;
74          push @conditions, qq{ date(backups.date, 'unixepoch','localtime') <= '$backup_to' } if ($backup_to);  
75                    my $dt = new DateTime(
76                            year => $yyyy,
77                            month => $mm,
78                            day => $dd
79                    );
80                    print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
81                    return $dt->epoch || 'NULL';
82            }
83    
84            my @ret = (
85                    mk_epoch_date('search_backup', 'from'),
86                    mk_epoch_date('search_backup', 'to'),
87                    mk_epoch_date('search', 'from'),
88                    mk_epoch_date('search', 'to'),
89            );
90    
91          my $files_from = mk_iso_date('search', 'from');          return @ret;
         push @conditions, qq{ date(files.date, 'unixepoch','localtime') >= '$files_from' } if ($files_from);  
         my $files_to = mk_iso_date('search', 'to');  
         push @conditions, qq{ date(files.date, 'unixepoch','localtime') <= '$files_to' } if ($files_to);  
92    
93          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:",join(" | ",@conditions);  }
       
         push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'});  
94    
         push (@conditions, " upper(files.name) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});  
95    
96          return (  sub getWhere($) {
97                  join(" and ", @conditions),          my $param = shift || return;
98                  $files_from, $files_to,  
99                  $backup_from, $backup_to          my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
100          );  
101            my @conditions;
102            push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
103            push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
104            push @conditions, qq{ files.date >= $files_from } if ($files_from);
105            push @conditions, qq{ files.date <= $files_to } if ($files_to);
106    
107            print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);
108    
109            push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
110            push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
111    
112            return join(" and ", @conditions);
113  }  }
114    
115    
116  sub getFiles($$) {  sub getFiles($) {
117          my ($where, $offset) = @_;          my ($param) = @_;
118    
119            my $offset = $param->{'offset'} || 0;
120            $offset *= $on_page;
121    
122          my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          my $dbh = get_dbh();
                 "", "", { RaiseError => 1, AutoCommit => 1 } );  
123    
124          my $sql_cols = qq{          my $sql_cols = qq{
125                  files.id                        AS fid,                  files.id                        AS fid,
126                  hosts.name                      AS hname,                  hosts.name                      AS hname,
127                  shares.name                     AS sname,                  shares.name                     AS sname,
128                  shares.share                    AS sharename,                  files.backupnum                 AS backupnum,
                 files.backupNum                 AS backupNum,  
                 files.name                      AS filename,  
129                  files.path                      AS filepath,                  files.path                      AS filepath,
130                  shares.share||files.fullpath    AS networkPath,                  files.date                      AS date,
131                  date(files.date, 'unixepoch', 'localtime') AS date,                  files.type                      AS type,
132                  files.type                      AS filetype,                  files.size                      AS size
                 files.size                      AS size,  
                 dvds.name                       AS dvd  
133          };          };
134    
135          my $sql_from = qq{          my $sql_from = qq{
136                  FROM files                  FROM files
137                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
138                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
139                          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
                         LEFT  JOIN dvds         ON dvds.ID = files.dvdid  
140          };          };
141    
142          my $sql_where;          my $sql_where;
143            my $where = getWhere($param);
144          $sql_where = " WHERE ". $where if ($where);          $sql_where = " WHERE ". $where if ($where);
145    
146          my $sql_order = qq{          my $sql_order = qq{
147                  ORDER BY files.id                  ORDER BY files.date
148                          LIMIT $on_page                  LIMIT $on_page
149                          OFFSET ?                  OFFSET ?
150          };          };
151    
152          $offset ||= 0;          my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
153          $offset = ($offset * $on_page) + 1;          my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
154    
155          my $sth = $dbh->prepare(qq{ select count(files.id) $sql_from $sql_where });          my $sth = $dbh->prepare($sql_count);
156          $sth->execute();          $sth->execute();
   
157          my ($results) = $sth->fetchrow_array();          my ($results) = $sth->fetchrow_array();
158    
159          $sth = $dbh->prepare(qq{ select $sql_cols $sql_from $sql_where $sql_order });          $sth = $dbh->prepare($sql_results);
160          $sth->execute( $offset );          $sth->execute( $offset );
161    
162            if ($sth->rows != $results) {
163                    my $bug = "$0 BUG: [[ $sql_count ]] = $results while [[ $sql_results ]] = " . $sth->rows;
164                    $bug =~ s/\s+/ /gs;
165                    print STDERR "$bug\n";
166            }
167    
168          my @ret;          my @ret;
169                
170          while (my $row = $sth->fetchrow_hashref()) {          while (my $row = $sth->fetchrow_hashref()) {
171                  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'}  
                 });  
172          }          }
173              
174          $sth->finish();          $sth->finish();
         $dbh->disconnect();  
175          return ($results, \@ret);          return ($results, \@ret);
176  }  }
177    
178  sub getBackupsNotBurned()  sub getFilesHyperEstraier($) {
179    {          my ($param) = @_;
180        my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",  
181          "", "", { RaiseError => 1, AutoCommit => 1 } );                my $offset = $param->{'offset'} || 0;
182        my $sql = q{          $offset *= $on_page;
183            SELECT  
184              hosts.ID         AS hostID,          die "no index_path?" unless ($index_path);
185              hosts.name       AS host,  
186              backups.num      AS backupno,          use HyperEstraier;
187              backups.type     AS type,  
188              backups.date     AS date          # open the database
189            FROM backups, shares, files, hosts          my $db = HyperEstraier::Database->new();
190            WHERE          $db->open($index_path, $HyperEstraier::ESTDBREADER);
191              backups.num    = files.backupNum  AND  
192              shares.ID      = files.shareID    AND                    # create a search condition object
193              backups.hostID = shares.hostID    AND          my $cond = HyperEstraier::Condition->new();
194              hosts.ID       = backups.hostID   AND  
195              files.dvdid    IS NULL          my $q = $param->{'search_filename'};
196            GROUP BY          my $shareid = $param->{'search_share'};
197              backups.hostID, backups.num  
198        };          if (length($q) > 0) {
199        my $st = $dbh -> prepare( $sql );                  # exact match
200        my @ret = ();                  $cond->add_attr("filepath ISTRINC $q");
201        $st -> execute();  
202                    $q =~ s/(.)/$1 /g;
203        while ( my $row = $st -> fetchrow_hashref() )                  # set the search phrase to the search condition object
204          {                            $cond->set_phrase($q);
205              push(@ret, {          }
206                           'host'     => $row->{'host'},  
207                           'hostid'   => $row->{'hostID'},          my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
208                           'backupno' => $row->{'backupno'},  
209                           'type'     => $row->{'type'},          $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
210                           'date'     => $row->{'date'}          $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
211                         }  
212              );          $cond->add_attr("date NUMGE $files_from") if ($files_from);
213            $cond->add_attr("date NUMLE $files_to") if ($files_to);
214    
215            $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
216    
217    #       $cond->set_max( $offset + $on_page );
218            $cond->set_options( $HyperEstraier::Condition::SURE );
219            $cond->set_order( 'date NUMA' );
220    
221            # get the result of search
222            my $result = $db->search($cond, 0);
223    
224            my @res;
225            my $hits = $result->size;
226    
227            # for each document in result
228            for my $i ($offset .. ($offset + $on_page - 1)) {
229                    last if ($i >= $hits);
230    
231                    my $id = $result->get($i);
232                    my $doc = $db->get_doc($id, 0);
233    
234                    my $row;
235                    foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) {
236                            $row->{$c} = $doc->attr($c);
237                    }
238                    push @res, $row;
239            }
240    
241            return ($hits, \@res);
242    }
243    
244    sub getGzipName($$$)
245    {
246            my ($host, $share, $backupnum) = @_;
247            my $ret = $Conf{GzipSchema};
248            
249            $share =~ s/\//_/g;
250            $ret =~ s/\\h/$host/ge;
251            $ret =~ s/\\s/$share/ge;
252            $ret =~ s/\\n/$backupnum/ge;
253            
254            return $ret;
255            
256    }
257    
258    sub getBackupsNotBurned() {
259    
260            my $dbh = get_dbh();
261            my $sql = q{
262            SELECT
263                    backups.hostID          AS hostid,
264                    min(hosts.name)         AS host,
265                    min(shares.name)        AS share,
266                    backups.num             AS backupnum,
267                    min(backups.type)       AS type,
268                    min(backups.date)       AS date,
269                    min(backups.size)       AS size
270            FROM files
271                    INNER JOIN shares       ON files.shareID=shares.ID
272                    INNER JOIN hosts        ON hosts.ID = shares.hostID
273                    INNER JOIN backups      ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID
274            GROUP BY
275                    backups.hostID, backups.num, backups.shareid
276            ORDER BY min(backups.date)
277            };
278            my $sth = $dbh->prepare( $sql );
279            my @ret;
280            $sth->execute();
281    
282            while ( my $row = $sth->fetchrow_hashref() ) {
283                    $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
284                    $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
285                    my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =
286                            stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
287                                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
288                    $row->{'fs_size'} = $fs_size;
289                    push @ret, $row;
290          }          }
291                
292        return @ret;                return @ret;      
293    }  }
294    
295  sub displayBackupsGrid()  sub displayBackupsGrid()
296    {    {
297        my $retHTML = "";        my $retHTML = "";
       my $addForm = 1;  
298                
299        if ($addForm) {          $retHTML .= <<EOF3;
   
             $retHTML .= <<EOF3;  
300  <script language="javascript" type="text/javascript">  <script language="javascript" type="text/javascript">
301  <!--  <!--
302    
# Line 207  sub displayBackupsGrid() Line 317  sub displayBackupsGrid()
317  //-->  //-->
318  </script>        </script>      
319  EOF3  EOF3
320                $retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\"";          $retHTML .= q{
321                $retHTML.= q{<input type="hidden" value="burn" name="action">};                  <form name="forma" method="GET" action="$MyURL?action=burn">
322                $retHTML .= q{<input type="hidden" value="results" name="search_results">};                  <input type="hidden" value="burn" name="action">
323          }                  <input type="hidden" value="results" name="search_results">
324          $retHTML .= qq{<table style="fview"><tr>};                  <table style="fview" border="0" cellspacing="0" cellpadding="2">
325                    <tr class="tableheader">
326                    <td class="tableheader">
327                            <input type="checkbox" name="allFiles" onClick="checkAll('allFiles');">
328                    </td>
329                    <td align="center">Share</td>
330                    <td align="center">Backup no</td>
331                    <td align="center">Type</td>
332                    <td align="center">date</td>
333                    <td align="center">age/days</td>
334                    <td align="center">size/MB</td>
335                    <td align="center">gzip size</td>
336                    </tr>
337    
338          if ($addForm) {                  <tr><td colspan=7 style="tableheader">
339              $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";                  <input type="submit" value="Burn selected backups on medium" name="submitBurner">
340          }                  </td></tr>
341          $retHTML .=  qq{<td class="tableheader">Host</td><td class="tableheader">Backup no</td><td class="tableheader">Type</td><td class="tableheader">date</td></tr>};          };
342    
343          my @backups = getBackupsNotBurned();          my @color = (' bgcolor="#e0e0e0"', '');
         my $backup;  
344    
345          if ($addForm) {          my $i = 0;
346                  $retHTML .= qq{<tr><td colspan=7 style="tableheader">          my $host = '';
                         <input type="submit" value="Burn selected backups on medium" name="submitBurner">  
                         </td></tr>};  
         }  
347    
348          foreach $backup(@backups) {          foreach my $backup ( getBackupsNotBurned() ) {
349    
350                    if ($host ne $backup->{'host'}) {
351                            $i++;
352                            $host = $backup->{'host'};
353                    }
354                  my $ftype = "";                  my $ftype = "";
355                            
356                  $retHTML .= "<tr>";                  $retHTML .= "<tr" . $color[$i %2 ] . ">";
357                  if ($addForm) {                  $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .
358                          $retHTML .= qq{<td class="fview"><input type="checkbox" name="fcb} .                                  $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
359                                  $backup->{'hostid'}."_".$backup->{'backupno'} .                                  '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
360                                  qq{" value="} . $backup->{'hostid'}."_".$backup->{'backupno'} .                                  '"></td>';
                                 qq{"></td>};  
                 }            
361                            
362                  $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .                  $retHTML .=
363                          '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
364                          '<td class="fviewborder">' . $backup->{'type'} . '</td>' .                          '<td align="center">' . $backup->{'backupnum'} . '</td>' .
365                          '<td class="fviewborder">' . $backup->{'date'} . '<td>' .                          '<td align="center">' . $backup->{'type'} . '</td>' .
366                          '</tr>';                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
367          }                          '<td align="center">' . $backup->{'age'} . '</td>' .
368                            '<td align="right">' . $backup->{'size'} . '</td>' .
369                            '<td align="right">' . $backup->{'fs_size'} .'</td>' .
370                            "</tr>\n";
371    
         $retHTML .= "</table>";  
372    
         if ($addForm) {  
                 $retHTML .= "</form>";  
373          }          }
374    
375            $retHTML .= "</table>";
376            $retHTML .= "</form>";
377                
378          return $retHTML;          return $retHTML;
379  }        }      
380    
381  sub displayGrid($$$$) {  sub displayGrid($) {
382          my ($where, $addForm, $offset, $hilite) = @_;          my ($param) = @_;
383    
384            my $offset = $param->{'offset'};
385            my $hilite = $param->{'search_filename'};
386    
387          my $retHTML = "";          my $retHTML = "";
388    
389          if ($addForm) {          my $start_t = time();
390                  $retHTML .= qq{<form name="forma" method="GET" action="$MyURL">};  
391                  $retHTML.= qq{<input type="hidden" value="search" name="action">};          my ($results, $files);
392                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};          if ($param->{'use_hest'} && length($hilite) > 0) {
393                    ($results, $files) = getFilesHyperEstraier($param);
394            } else {
395                    ($results, $files) = getFiles($param);
396          }          }
397    
398          my ($results, $files) = getFiles($where, $offset);          my $dur_t = time() - $start_t;
399            my $dur = sprintf("%0.4fs", $dur_t);
400    
401          my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);          my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);
402    
403            if ($results <= 0) {
404                    $retHTML .= qq{
405                            <p style="color: red;">No results found...</p>
406                    };
407                    return $retHTML;
408            } else {
409                    # DEBUG
410                    #use Data::Dumper;
411                    #$retHTML .= '<pre>' . Dumper($files) . '</pre>';
412            }
413    
414    
415          $retHTML .= qq{          $retHTML .= qq{
416          <br/>Found $results files, showing $from - $to          <div>
417          <table style="fview" width="100%">          Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
418                  <tr>          </div>
419                  <td class="tableheader">Share</td>          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
420                  <td class="tableheader">Name</td>                  <tr class="fviewheader">
421                  <td class="tableheader">Type</td>                  <td></td>
422                  <td class="tableheader">#</td>                  <td align="center">Share</td>
423                  <td class="tableheader">Size</td>                  <td align="center">Type and Name</td>
424                  <td class="tableheader">Date</td>                  <td align="center">#</td>
425                  <td class="tableheader">Media</td>                  <td align="center">Size</td>
426                    <td align="center">Date</td>
427                    <td align="center">Media</td>
428                  </tr>                  </tr>
429          };          };
430    
# Line 298  sub displayGrid($$$$) { Line 443  sub displayGrid($$$$) {
443                  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, @_);
444          }          }
445    
446            my $i = $offset * $on_page;
447    
448          foreach $file (@{ $files }) {          foreach $file (@{ $files }) {
449                    $i++;
450    
451                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
452                  $retHTML .= "<tr>";                  $retHTML .= qq{<tr class="fviewborder">};
453    
454                  foreach my $v ((                  $retHTML .= qq{<td class="fviewborder">$i</td>};
455                          $file->{'sharename'},  
456                          qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center">&nbsp;} . hilite_html( $file->{'fpath'}, $hilite ),                  $retHTML .=
457                          $typeStr,                          qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} .
458                          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>} .
459                          $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>} .
460                          $file->{'date'},                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
461                          $file->{'dvd'}                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
462                  )) {                          qq{<td class="fviewborder">} . '?' . qq{</td>};
                         $retHTML .= qq{<td class="fviewborder">$v</td>};  
                 }  
463    
464                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
465          }          }
# Line 327  sub displayGrid($$$$) { Line 474  sub displayGrid($$$$) {
474          my $max_page = int( $results / $on_page );          my $max_page = int( $results / $on_page );
475          my $page = 0;          my $page = 0;
476    
477          my $link_fmt = '<a href = "#" onclick="document.forma.offset.value=%d;document.forma.submit();">%s</a>';          sub page_link($$$) {
478                    my ($param,$page,$display) = @_;
479    
480                    $param->{'offset'} = $page;
481    
482                    my $html = '<a href = "' . $MyURL;
483                    my $del = '?';
484                    foreach my $k (keys %{ $param }) {
485                            if ($param->{$k}) {
486                                    $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};
487                                    $del = '&';
488                            }
489                    }
490                    $html .= '">' . $display . '</a>';
491            }
492    
493          $retHTML .= '<div style="text-align: center;">';          $retHTML .= '<div style="text-align: center;">';
494    
495          if ($offset > 0) {          if ($offset > 0) {
496                  $retHTML .= sprintf($link_fmt, $offset - 1, '&lt;&lt;') . ' ';                  $retHTML .= page_link($param, $offset - 1, '&lt;&lt;') . ' ';
497          }          }
498    
499          while ($page <= $max_page) {          while ($page <= $max_page) {
500                  if ($page == $offset) {                  if ($page == $offset) {
501                          $retHTML .= $del . '<b>' . ($page + 1) . '</b>';                          $retHTML .= $del . '<b>' . ($page + 1) . '</b>';
502                  } else {                  } else {
503                          $retHTML .= $del . sprintf($link_fmt, $page, $page + 1);                          $retHTML .= $del . page_link($param, $page, $page + 1);
504                  }                  }
505    
506                  if ($page < $offset - $pager_pages && $page != 0) {                  if ($page < $offset - $pager_pages && $page != 0) {
# Line 357  sub displayGrid($$$$) { Line 518  sub displayGrid($$$$) {
518          }          }
519    
520          if ($offset < $max_page) {          if ($offset < $max_page) {
521                  $retHTML .= ' ' . sprintf($link_fmt, $offset + 1, '&gt;&gt;');                  $retHTML .= ' ' . page_link($param, $offset + 1, '&gt;&gt;');
522          }          }
523    
524          $retHTML .= "</div>";          $retHTML .= "</div>";
525    
         $retHTML .= "</form>" if ($addForm);  
   
526          return $retHTML;          return $retHTML;
527  }  }
528    

Legend:
Removed from v.31  
changed lines
  Added in v.109

  ViewVC Help
Powered by ViewVC 1.1.26