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

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

  ViewVC Help
Powered by ViewVC 1.1.26