/[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 60 by dpavlin, Sun Aug 21 15:38:18 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  sub getUnits() {  sub getUnits() {
19      my @ret = ();          my @ret;
20      my $tmp;  
21      my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
22          "", "", { RaiseError => 1, AutoCommit => 1 } );          my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares} );
23      my $st =          $sth->execute();
24        $dbh->prepare(          push @ret, { 'id' => '', 'share' => '-'};       # dummy any
25          " SELECT shares.ID AS ID, shares.share AS name FROM shares;");  
26      $st->execute();          while ( my $row = $sth->fetchrow_hashref() ) {
27      push (@ret, { 'ID' => '', 'name' => '-'});                  push @ret, $row;
28      while ( $tmp = $st->fetchrow_hashref() ) {          }
29          push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } );          $dbh->disconnect();
30      }          return @ret;
     $dbh->disconnect();  
     return @ret;  
31  }  }
32    
33  sub getWhere($) {  sub epoch_to_iso {
34      my ($param)    = @_;          my $t = shift || return;
35      my $retSQL     = "";          my $dt = DateTime->from_epoch( epoch => $t ) || return;
36      my @conditions = ();          print STDERR "BUG: $t != " . $dt->epoch . "\n" unless ($t == $dt->epoch);
37      my $cond;          return $dt->ymd . ' ' . $dt->hms;
38    }
39    
40        sub getWhere($) {
41              my ($param)    = @_;
42                my @conditions;
     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'}  ."\"");  
     }  
43    
44      if ( defined( $param->{'search_day_from'} )   && $param->{'search_day_from'} ne "" ) {          sub mk_epoch_date($$) {
45          push( @conditions,                  my ($name,$suffix) = @_;
             ' strftime("%d", datetime(files.date, "unixepoch","localtime")) >= "'  
               . $param->{'search_day_from'}  ."\"");  
     }  
     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'} ."\"");  
     }  
46    
47      if ( defined( $param->{'search_host'} ) && $param->{'search_host'} ne "") {                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;
48        push( @conditions, ' backups.hostID = ' . $param->{'search_host'} );                  my $mm .= $param->{ $name . '_month_' . $suffix} ||
49      }                          ( $suffix eq 'from' ? 1 : 12);
50                    my $dd .= $param->{ $name . '_day_' . $suffix} ||
51                            ( $suffix eq 'from' ? 1 : 31);
52                    my $dt = new DateTime(
53                            year => $yyyy,
54                            month => $mm,
55                            day => $dd
56                    );
57                    return $dt->epoch || 'NULL';
58            }
59    
60            my $backup_from = mk_epoch_date('search_backup', 'from');
61            push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
62            my $backup_to = mk_epoch_date('search_backup', 'to');
63            push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
64    
65            my $files_from = mk_epoch_date('search', 'from');
66            push @conditions, qq{ files.date >= $files_from } if ($files_from);
67            my $files_to = mk_epoch_date('search', 'to');
68            push @conditions, qq{ files.date <= $files_to } if ($files_to);
69    
70      if ( defined ($param->{'search_filename'}) && $param->{'search_filename'} ne "") {          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);
         push (@conditions, " files.name LIKE '".$param->{'search_filename'}."%'");  
         }  
71            
72      $retSQL = "";          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
     foreach $cond(@conditions)  
       {  
           if ($retSQL ne "")  
             {  
                 $retSQL .= " AND ";  
             }  
           $retSQL .= $cond;  
       }        
73    
74                push (@conditions, " upper(files.name) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
75      return $retSQL;  
76            return (
77                    join(" and ", @conditions),
78                    $files_from, $files_to,
79                    $backup_from, $backup_to
80            );
81  }  }
82    
83  sub getFiles($$)  
84    {  sub getFiles($$) {
85        my ($where, $offset) = @_;          my ($where, $offset) = @_;
86          
87                  my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
88        my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",  
89          "", "", { RaiseError => 1, AutoCommit => 1 } );          my $sql_cols = qq{
90        my $sql =                            files.id                        AS fid,
91          q{                    hosts.name                      AS hname,
92                  SELECT  files.id                        AS fid,                  shares.name                     AS sname,
93                          hosts.name                      AS hname,                  shares.share                    AS sharename,
94                          shares.name                     AS sname,                  files.backupNum                 AS backupNum,
95                          shares.share                    AS sharename,                  files.name                      AS filename,
96                          files.backupNum                 AS backupNum,                  files.path                      AS filepath,
97                          files.name                      AS filename,                  shares.share||files.fullpath    AS networkPath,
98                          files.path                      AS filepath,                  files.date                      AS date,
99                          shares.share||files.fullpath    AS networkPath,                  files.type                      AS filetype,
100                          date(files.date, 'unixepoch', 'localtime') AS date,                  files.size                      AS size,
101                          files.type                      AS filetype,                  dvds.name                       AS dvd
102                          files.size                      AS size,          };
103                          dvds.name                       AS dvd  
104            my $sql_from = qq{
105                  FROM files                  FROM files
106                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
107                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
108                            INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID
109            };
110    
111            my $sql_dvd_from = qq{
112                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid
113            };          };
114    
115        if (defined($where) && $where ne "")          my $sql_where;
116          {          $sql_where = " WHERE ". $where if ($where);
             $sql .= " WHERE ". $where;        
         }  
117    
118        $sql .=          my $sql_order = qq{
119          q{                            ORDER BY files.id
120              ORDER BY files.id                  LIMIT $on_page
121                LIMIT 100                  OFFSET ?
               OFFSET ? * 100 + 1  
122          };          };
         
         
         
       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'}  
                        }  
             );  
                                   
         }  
         
       $st->finish();  
       $dbh->disconnect();  
       return @ret;  
   }  
123    
124  sub getBackupsNotBurned()          my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
125    {          my $sql_results = qq{ select $sql_cols $sql_from $sql_dvd_from $sql_where $sql_order };
126        my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",  
127          "", "", { RaiseError => 1, AutoCommit => 1 } );                $offset ||= 0;
128        my $sql = q{          $offset = ($offset * $on_page);
129            SELECT  
130              hosts.ID         AS hostID,          my $sth = $dbh->prepare($sql_count);
131              hosts.name       AS host,          $sth->execute();
132              backups.num      AS backupno,          my ($results) = $sth->fetchrow_array();
133              backups.type     AS type,  
134              backups.date     AS date          $sth = $dbh->prepare($sql_results);
135            FROM backups, shares, files, hosts          $sth->execute( $offset );
136            WHERE  
137              backups.num    = files.backupNum  AND          if ($sth->rows != $results) {
138              shares.ID      = files.shareID    AND                            my $bug = "$0 BUG: [[ $sql_count ]] = $results while [[ $sql_results ]] = " . $sth->rows;
139              backups.hostID = shares.hostID    AND                  $bug =~ s/\s+/ /gs;
140              hosts.ID       = backups.hostID   AND                  print STDERR "$bug\n";
141              files.dvdid    IS NULL          }
142            GROUP BY  
143              backups.hostID, backups.num          my @ret;
144        };        
145        my $st = $dbh -> prepare( $sql );          while (my $row = $sth->fetchrow_hashref()) {
146        my @ret = ();                  push(@ret, {
147        $st -> execute();                          'hname'         => $row->{'hname'},
148                            'sname'         => $row->{'sname'},
149        while ( my $tmp = $st -> fetchrow_hashref() )                          'sharename'     => $row->{'sharename'},
150          {                                    'backupno'      => $row->{'backupnum'},
151              push(@ret, {                          'fname'         => $row->{'filename'},
152                           'host'     => $tmp->{'host'},                          'fpath'         => $row->{'filepath'},
153                           'hostid'   => $tmp->{'hostID'},                          'networkpath'   => $row->{'networkpath'},
154                           'backupno' => $tmp->{'backupno'},                          'date'          => $row->{'date'},
155                           'type'     => $tmp->{'type'},                          'type'          => $row->{'filetype'},
156                           'date'     => $tmp->{'date'}                          'size'          => $row->{'size'},
157                            'id'            => $row->{'fid'},
158                            'dvd'           => $row->{'dvd'}
159                    });
160            }
161        
162            $sth->finish();
163            $dbh->disconnect();
164            return ($results, \@ret);
165    }
166    
167    sub getBackupsNotBurned() {
168    
169            my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
170            my $sql = q{
171            SELECT
172                    hosts.ID                AS hostid,
173                    min(hosts.name)         AS host,
174                    backups.num             AS backupno,
175                    min(backups.type)       AS type,
176                    min(backups.date)       AS date
177            FROM backups, shares, files, hosts
178            WHERE
179                    backups.num     = files.backupNum       AND
180                    shares.ID       = files.shareID         AND        
181                    backups.hostID  = shares.hostID         AND
182                    hosts.ID        = backups.hostID        AND
183                    files.dvdid     IS NULL
184            GROUP BY
185                    backups.hostID, backups.num, hosts.id
186            ORDER BY min(backups.date)
187            };
188            my $sth = $dbh->prepare( $sql );
189            my @ret;
190            $sth->execute();
191    
192            while ( my $row = $sth->fetchrow_hashref() ) {      
193                    push(@ret, {
194                             'host'         => $row->{'host'},
195                             'hostid'       => $row->{'hostid'},
196                             'backupno'     => $row->{'backupno'},
197                             'type'         => $row->{'type'},
198                             'date'         => $row->{'date'},
199                             'age'          => sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ),
200                         }                         }
201              );                  );
202          }          }
203                
204        return @ret;                return @ret;      
205    }  }
206    
207  sub displayBackupsGrid()  sub displayBackupsGrid()
208    {    {
209        my $retHTML = "";        my $retHTML = "";
210        my $addForm = 1;        my $addForm = 1;
211                
212        if ($addForm)        if ($addForm) {
         {  
213    
214              $retHTML .= <<EOF3;              $retHTML .= <<EOF3;
215  <script language="javascript" type="text/javascript">  <script language="javascript" type="text/javascript">
# Line 268  sub displayBackupsGrid() Line 232  sub displayBackupsGrid()
232  //-->  //-->
233  </script>        </script>      
234  EOF3  EOF3
235                $retHTML .= q{<form name="forma" method="POST" action="}."$MyURL"."?action=burn\"";                $retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\"";
236                $retHTML.= q{<input type="hidden" value="burn" name="action">};                $retHTML.= q{<input type="hidden" value="burn" name="action">};
237                $retHTML .= q{<input type="hidden" value="results" name="search_results">};                $retHTML .= q{<input type="hidden" value="results" name="search_results">};
238          }          }
239        $retHTML .= "<table style=\"fview\">";          $retHTML .= qq{<table style="fview"><tr>};
240        $retHTML .= "<tr> ";  
241        if ($addForm)          if ($addForm) {
         {  
242              $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";              $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";
243          }          }
244        $retHTML .=  "<td class=\"tableheader\">Host</td> <td class=\"tableheader\">Backup no</td> <td class=\"tableheader\">Type</td> <td class=\"tableheader\">date</td></tr>";          $retHTML .=  qq{
245        my @backups = getBackupsNotBurned();                  <td class="tableheader">Host</td>
246        my $backup;                  <td class="tableheader">Backup no</td>
247                    <td class="tableheader">Type</td>
248        if ($addForm)                  <td class="tableheader">date</td>
249          {                  <td class="tableheader">age/days</td>
250              $retHTML .= "<tr>";                  </tr>
251              $retHTML .= "<td colspan=7 style=\"tableheader\">";          };
252              $retHTML .= "<input type=\"submit\" value=\"Burn selected backups on medium\" name=\"submitBurner\">";  
253              $retHTML .= "</td>";          my @backups = getBackupsNotBurned();
254              $retHTML .= "</tr>";          my $backup;
255                
256            if ($addForm) {
257                    $retHTML .= qq{
258                            <tr><td colspan=7 style="tableheader">
259                            <input type="submit" value="Burn selected backups on medium" name="submitBurner">
260                            </td></tr>
261                    };
262          }          }
263        foreach $backup(@backups)  
264          {          foreach $backup(@backups) {
265              my $ftype = "";  
266                    my $ftype = "";
267                            
268              $retHTML .= "<tr>";                  $retHTML .= "<tr>";
269              if ($addForm)                  if ($addForm) {
270                {                          $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .
271                    $retHTML .= "<td class=\"fview\"> <input type=\"checkbox\" name=\"fcb"                                  $backup->{'hostid'}.'_'.$backup->{'backupno'} .
272                      .$backup->{'hostid'}."_".$backup->{'backupno'}                                  '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupno'} .
273                    ."\" value=\"".$backup->{'hostid'}."_".$backup->{'backupno'}."\"> </td>";                                  '"></td>';
274                }                      }          
275                            
276              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'host'} . "</td>";                  $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .
277              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'backupno'} . "</td>";                          '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .
278              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'type'} . "</td>";                          '<td class="fviewborder">' . $backup->{'type'} . '</td>' .
279              $retHTML .= "<td class=\"fviewborder\">" . $backup->{'date'} . "<td>";                          '<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
280              $retHTML .= "</tr>";                          '<td class="fviewborder">' . $backup->{'age'} . '</td>' .
281          }                          '</tr>';
282        $retHTML .= "</table>";          }
283        if ($addForm)  
284         {          $retHTML .= "</table>";
285             $retHTML .= "</form>";  
286         }          if ($addForm) {
287                    $retHTML .= "</form>";
288            }
289                
290        return $retHTML;          return $retHTML;
291      }      
     
   }        
292    
293  sub displayGrid($$$$) {  sub displayGrid($$$$) {
294          my ($where, $addForm, $offset, $hilite) = @_;          my ($where, $addForm, $offset, $hilite) = @_;
295          my $retHTML = "";          my $retHTML = "";
296    
297            my $start_t = time();
298    
299            my ($results, $files) = getFiles($where, $offset);
300    
301            my $dur_t = time() - $start_t;
302            my $dur = sprintf("%0.4fs", $dur_t);
303    
304            my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);
305    
306            if ($results <= 0) {
307                    $retHTML .= qq{
308                            <p style="color: red;">No results found...</p>
309                    };
310                    return $retHTML;
311            } else {
312                    # DEBUG
313                    #use Data::Dumper;
314                    #$retHTML .= '<pre>' . Dumper($files) . '</pre>';
315            }
316    
317    
318          if ($addForm) {          if ($addForm) {
319                  $retHTML .= qq{<form name="forma" method="POST" action="}.$MyURL.qq{?action=search">};                  $retHTML .= qq{<form name="forma" method="GET" action="$MyURL">};
320                  $retHTML.= qq{<input type="hidden" value="search" name="action">};                  $retHTML.= qq{<input type="hidden" value="search" name="action">};
321                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};
322          }          }
323    
324    
325          $retHTML .= qq{          $retHTML .= qq{
326            <br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
327          <table style="fview" width="100%">          <table style="fview" width="100%">
328                  <tr>                  <tr>
329                  <td class="tableheader">Host</td>                  <td class="tableheader">Share</td>
                 <td class="tableheader">Type</td>  
330                  <td class="tableheader">Name</td>                  <td class="tableheader">Name</td>
331                  <td class="tableheader">backup no.</td>                  <td class="tableheader">Type</td>
332                  <td class="tableheader">size</td>                  <td class="tableheader">#</td>
333                  <td class="tableheader">date</td>                  <td class="tableheader">Size</td>
334                    <td class="tableheader">Date</td>
335                  <td class="tableheader">Media</td>                  <td class="tableheader">Media</td>
336                  </tr>                  </tr>
337          };          };
338          my @files = getFiles($where, $offset);  
339          my $file;          my $file;
340    
341          sub hilite_html($$) {          sub hilite_html($$) {
# Line 350  sub displayGrid($$$$) { Line 344  sub displayGrid($$$$) {
344                  return $html;                  return $html;
345          }          }
346    
347          foreach $file (@files) {          sub restore_link($$$$$$) {
348                  my $ftype = "file";                  my $type = shift;
349                  $ftype = "dir" if ($file->{'type'} == BPC_FTYPE_DIR);                  my $action = 'RestoreFile';
350                    $action = 'browse' if (lc($type) eq 'dir');
351                    return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);
352            }
353    
354            foreach $file (@{ $files }) {
355                    my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
356                  $retHTML .= "<tr>";                  $retHTML .= "<tr>";
357    
358                  foreach my $v ((                  foreach my $v ((
359                          $file->{'hname'},                          $file->{'sharename'},
360                          $ftype,                          qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center">&nbsp;} . hilite_html( $file->{'fpath'}, $hilite ),
361                          hilite_html( $file->{'fpath'}, $hilite ),                          $typeStr,
362                          $file->{'backupno'},                          restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ),
363                          $file->{'size'},                          $file->{'size'},
364                          $file->{'date'},                          epoch_to_iso( $file->{'date'} ),
365                          $file->{'dvd'}                          $file->{'dvd'}
366                  )) {                  )) {
367                          $retHTML .= qq{<td class="fviewborder">$v</td>};                          $retHTML .= qq{<td class="fviewborder">$v</td>};
# Line 372  sub displayGrid($$$$) { Line 371  sub displayGrid($$$$) {
371          }          }
372          $retHTML .= "</table>";          $retHTML .= "</table>";
373    
374          # skip pager          # all variables which has to be transfered
375          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/) {
376                    $retHTML .= qq{<INPUT TYPE="hidden" NAME="$n" VALUE="$In{$n}">\n};
377            }
378    
379            my $del = '';
380            my $max_page = int( $results / $on_page );
381            my $page = 0;
382    
383            my $link_fmt = '<a href = "#" onclick="document.forma.offset.value=%d;document.forma.submit();">%s</a>';
384    
385            $retHTML .= '<div style="text-align: center;">';
386    
387          $retHTML .= "<INPUT TYPE=\"hidden\" VALUE=\"\" NAME=\"offset\">";          if ($offset > 0) {
388          for (my $ii = 1; $ii <= $#files; $ii++) {                  $retHTML .= sprintf($link_fmt, $offset - 1, '&lt;&lt;') . ' ';
389                  $retHTML .= "<a href = \"#\" onclick=\"document.forma.offset.value=$ii;document.forma.submit();\">$ii</a>";          }
390                  if ($ii < $#files) {  
391                          $retHTML .= " | ";          while ($page <= $max_page) {
392                    if ($page == $offset) {
393                            $retHTML .= $del . '<b>' . ($page + 1) . '</b>';
394                    } else {
395                            $retHTML .= $del . sprintf($link_fmt, $page, $page + 1);
396                  }                  }
397    
398                    if ($page < $offset - $pager_pages && $page != 0) {
399                            $retHTML .= " ... ";
400                            $page = $offset - $pager_pages;
401                            $del = '';
402                    } elsif ($page > $offset + $pager_pages && $page != $max_page) {
403                            $retHTML .= " ... ";
404                            $page = $max_page;
405                            $del = '';
406                    } else {
407                            $del = ' | ';
408                            $page++;
409                    }
410            }
411    
412            if ($offset < $max_page) {
413                    $retHTML .= ' ' . sprintf($link_fmt, $offset + 1, '&gt;&gt;');
414          }          }
415    
416            $retHTML .= "</div>";
417    
418          $retHTML .= "</form>" if ($addForm);          $retHTML .= "</form>" if ($addForm);
419          
420          return $retHTML;          return $retHTML;
421  }  }
422    

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

  ViewVC Help
Powered by ViewVC 1.1.26