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

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

  ViewVC Help
Powered by ViewVC 1.1.26