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

Legend:
Removed from v.9  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26