/[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 66 by dpavlin, Mon Aug 22 00:09:59 2005 UTC revision 121 by iklaric, Thu Sep 15 13:54:29 2005 UTC
# Line 15  my $pager_pages = 10; Line 15  my $pager_pages = 10;
15  my $dsn = $Conf{SearchDSN};  my $dsn = $Conf{SearchDSN};
16  my $db_user = $Conf{SearchUser} || '';  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    
34          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
35          my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares} );          my $sth = $dbh->prepare(qq{
36                    SELECT
37                            shares.id       as id,
38                            hosts.name || ':' || shares.name as share
39                    FROM shares
40                    JOIN hosts on hostid = hosts.id
41                    ORDER BY share
42            } );
43          $sth->execute();          $sth->execute();
44          push @ret, { 'id' => '', 'share' => '-'};       # dummy any          push @ret, { 'id' => '', 'share' => '-'};       # dummy any
45    
46          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
47                  push @ret, $row;                  push @ret, $row;
48          }          }
         $dbh->disconnect();  
49          return @ret;          return @ret;
50  }  }
51    
52  sub epoch_to_iso {  sub epoch_to_iso {
53          my $t = shift || return;          my $t = shift || return;
54          $t += 60 * 60 * +2;     # FIXME add TZ          my $iso = BackupPC::Lib::timeStamp(undef, $t);
55          my $dt = DateTime->from_epoch( epoch => $t ) || return;          $iso =~ s/\s/ /g;
56          print STDERR "BUG: $t != " . $dt->epoch . "\n" unless ($t == $dt->epoch);          return $iso;
         return $dt->ymd . ' ' . $dt->hms;  
57  }  }
58    
59  sub getWhere($) {  sub dates_from_form($) {
60          my ($param)    = @_;          my $param = shift || return;
         my @conditions;  
61    
62          sub mk_epoch_date($$) {          sub mk_epoch_date($$) {
63                  my ($name,$suffix) = @_;                  my ($name,$suffix) = @_;
64    
65                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef;
66                  my $mm .= $param->{ $name . '_month_' . $suffix} ||                  my $mm .= $param->{ $name . '_month_' . $suffix} ||
67                          ( $suffix eq 'from' ? 1 : 12);                          ( $suffix eq 'from' ? 1 : 12);
68                  my $dd .= $param->{ $name . '_day_' . $suffix} ||                  my $dd .= $param->{ $name . '_day_' . $suffix} ||
69                          ( $suffix eq 'from' ? 1 : 31);                          ( $suffix eq 'from' ? 1 : 31);
70    
71                    $yyyy =~ s/\D//g;
72                    $mm =~ s/\D//g;
73                    $dd =~ s/\D//g;
74    
75                  my $dt = new DateTime(                  my $dt = new DateTime(
76                          year => $yyyy,                          year => $yyyy,
77                          month => $mm,                          month => $mm,
78                          day => $dd                          day => $dd
79                  );                  );
80                    print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
81                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
82          }          }
83    
84          my $backup_from = mk_epoch_date('search_backup', 'from');          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($) {
97            my $param = shift || return;
98    
99            my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
100    
101            my @conditions;
102          push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);          push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
         my $backup_to = mk_epoch_date('search_backup', 'to');  
103          push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);          push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
   
         my $files_from = mk_epoch_date('search', 'from');  
104          push @conditions, qq{ files.date >= $files_from } if ($files_from);          push @conditions, qq{ files.date >= $files_from } if ($files_from);
         my $files_to = mk_epoch_date('search', 'to');  
105          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
106    
107          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);
       
         push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});  
108    
109            push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
110          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
111    
112          return (          return join(" and ", @conditions);
                 join(" and ", @conditions),  
                 $files_from, $files_to,  
                 $backup_from, $backup_to  
         );  
113  }  }
114    
115    
116  sub getFiles($$) {  sub getFiles($) {
117          my ($where, $offset) = @_;          my ($param) = @_;
118    
119            my $offset = $param->{'offset'} || 0;
120            $offset *= $on_page;
121    
122          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
123    
124          my $sql_cols = qq{          my $sql_cols = qq{
125                  files.id                        AS fid,                  files.id                        AS fid,
126                  hosts.name                      AS hname,                  hosts.name                      AS hname,
127                  shares.name                     AS sname,                  shares.name                     AS sname,
128                  shares.share                    AS sharename,                  files.backupnum                 AS backupnum,
                 files.backupNum                 AS backupNum,  
                 files.name                      AS filename,  
129                  files.path                      AS filepath,                  files.path                      AS filepath,
130                  files.date                      AS date,                  files.date                      AS date,
131                  files.type                      AS filetype,                  files.type                      AS type,
132                  files.size                      AS size,                  files.size                      AS size
                 dvds.name                       AS dvd  
133          };          };
134    
135          my $sql_from = qq{          my $sql_from = qq{
136                  FROM files                  FROM files
137                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
138                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
139                          INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID AND backups.shareID = shares.ID                          INNER JOIN backups      ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = files.shareID
         };  
   
         my $sql_dvd_from = qq{  
                         LEFT  JOIN dvds         ON dvds.ID = files.dvdid  
140          };          };
141    
142          my $sql_where;          my $sql_where;
143            my $where = getWhere($param);
144          $sql_where = " WHERE ". $where if ($where);          $sql_where = " WHERE ". $where if ($where);
145    
146          my $sql_order = qq{          my $sql_order = qq{
# Line 122  sub getFiles($$) { Line 150  sub getFiles($$) {
150          };          };
151    
152          my $sql_count = qq{ select count(files.id) $sql_from $sql_where };          my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
153          my $sql_results = qq{ select $sql_cols $sql_from $sql_dvd_from $sql_where $sql_order };          my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
   
         $offset ||= 0;  
         $offset = ($offset * $on_page);  
154    
155          my $sth = $dbh->prepare($sql_count);          my $sth = $dbh->prepare($sql_count);
156          $sth->execute();          $sth->execute();
# Line 143  sub getFiles($$) { Line 168  sub getFiles($$) {
168          my @ret;          my @ret;
169                
170          while (my $row = $sth->fetchrow_hashref()) {          while (my $row = $sth->fetchrow_hashref()) {
171                  push(@ret, {                  push @ret, $row;
                         'hname'         => $row->{'hname'},  
                         'sname'         => $row->{'sname'},  
                         'sharename'     => $row->{'sharename'},  
                         'backupno'      => $row->{'backupnum'},  
                         'fname'         => $row->{'filename'},  
                         'fpath'         => $row->{'filepath'},  
                         'networkpath'   => $row->{'networkpath'},  
                         'date'          => $row->{'date'},  
                         'type'          => $row->{'filetype'},  
                         'size'          => $row->{'size'},  
                         'id'            => $row->{'fid'},  
                         'dvd'           => $row->{'dvd'}  
                 });  
172          }          }
173            
174          $sth->finish();          $sth->finish();
         $dbh->disconnect();  
175          return ($results, \@ret);          return ($results, \@ret);
176  }  }
177    
178    sub getHyperEstraier_url($) {
179            my ($use_hest) = @_;
180    
181            return unless $use_hest;
182    
183            use HyperEstraier;
184            my ($index_path, $index_node_url);
185    
186            if ($use_hest =~ m#^http://#) {
187                    $index_node_url = $use_hest;
188            } else {
189                    $index_path = $TopDir . '/' . $index_path;
190                    $index_path =~ s#//#/#g;
191            }
192            return ($index_path, $index_node_url);
193    }
194    
195    sub getFilesHyperEstraier($) {
196            my ($param) = @_;
197    
198            my $offset = $param->{'offset'} || 0;
199            $offset *= $on_page;
200    
201            die "no index_path?" unless ($index_path);
202    
203            use HyperEstraier;
204    
205            my ($index_path, $index_node_url) = getHyperEstraier_url($index_path);
206    
207            # open the database
208            my $db;
209            if ($index_path) {
210                    $db = HyperEstraier::Database->new();
211                    $db->open($index_path, $HyperEstraier::ESTDBREADER);
212            } elsif ($index_node_url) {
213                    $db ||= HyperEstraier::Node->new($index_node_url);
214                    $db->set_auth('admin', 'admin');
215            } else {
216                    die "BUG: unimplemented";
217            }
218    
219            # create a search condition object
220            my $cond = HyperEstraier::Condition->new();
221    
222            my $q = $param->{'search_filename'};
223            my $shareid = $param->{'search_share'};
224    
225            if (length($q) > 0) {
226                    # exact match
227                    $cond->add_attr("filepath ISTRINC $q");
228    
229                    $q =~ s/(.)/$1 /g;
230                    # set the search phrase to the search condition object
231                    $cond->set_phrase($q);
232            }
233    
234            my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
235    
236            $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
237            $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
238    
239            $cond->add_attr("date NUMGE $files_from") if ($files_from);
240            $cond->add_attr("date NUMLE $files_to") if ($files_to);
241    
242            $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
243    
244    #       $cond->set_max( $offset + $on_page );
245            $cond->set_options( $HyperEstraier::Condition::SURE );
246            $cond->set_order( 'date NUMA' );
247    
248            # get the result of search
249            my @res;
250            my ($result, $hits);
251    
252            if ($index_path) {
253                    $result = $db->search($cond, 0);
254                    $hits = $result->size;
255            } elsif ($index_node_url) {
256                    $result = $db->search($cond, 0);
257                    $hits = $result->doc_num;
258            } else {
259                    die "BUG: unimplemented";
260            }
261    
262            # for each document in result
263            for my $i ($offset .. ($offset + $on_page - 1)) {
264                    last if ($i >= $hits);
265    
266                    my $doc;
267                    if ($index_path) {
268                            my $id = $result->get($i);
269                            $doc = $db->get_doc($id, 0);
270                    } elsif ($index_node_url) {
271                            $doc = $result->get_doc($i);
272                    } else {
273                            die "BUG: unimplemented";
274                    }
275    
276                    my $row;
277                    foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) {
278                            $row->{$c} = $doc->attr($c);
279                    }
280                    push @res, $row;
281            }
282    
283            return ($hits, \@res);
284    }
285    
286    sub getGzipName($$$)
287    {
288            my ($host, $share, $backupnum) = @_;
289            my $ret = $Conf{GzipSchema};
290            
291            $share =~ s/\//_/g;
292            $ret =~ s/\\h/$host/ge;
293            $ret =~ s/\\s/$share/ge;
294            $ret =~ s/\\n/$backupnum/ge;
295            
296            return $ret;
297            
298    }
299    
300  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
301    
302          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
303    
304          my $sql = q{          my $sql = q{
305          SELECT                  SELECT
306                  backups.hostID          AS hostid,                          backups.hostID AS hostID,
307                  min(hosts.name)         AS host,                          hosts.name AS host,
308                  backups.num             AS backupno,                          shares.name AS share,
309                  min(backups.type)       AS type,                          backups.id AS backupnum,
310                  min(backups.date)       AS date,                          backups.type AS type,
311                  min(backups.size)       AS size                          backups.date AS date,
312          FROM backups                          backups.size AS size
313                  INNER JOIN hosts        ON hosts.ID = backups.hostID                  FROM backups
314          WHERE                  WHERE id not in( select id from backups,archive_backup where archive_backup.backup_id=backups.id)
315                  files.dvdid     IS NULL                  ORDER BY backups.date
         GROUP BY  
                 backups.hostID, backups.num  
         ORDER BY min(backups.date)  
316          };          };
317          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
318          my @ret;          my @ret;
# Line 190  sub getBackupsNotBurned() { Line 321  sub getBackupsNotBurned() {
321          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
322                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
323                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
324                    my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =
325                            stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
326                                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
327                    $row->{'fs_size'} = $fs_size;
328                  push @ret, $row;                  push @ret, $row;
329          }          }
330                
# Line 199  sub getBackupsNotBurned() { Line 334  sub getBackupsNotBurned() {
334  sub displayBackupsGrid()  sub displayBackupsGrid()
335    {    {
336        my $retHTML = "";        my $retHTML = "";
       my $addForm = 1;  
337                
338        if ($addForm) {          $retHTML .= <<EOF3;
   
             $retHTML .= <<EOF3;  
339  <script language="javascript" type="text/javascript">  <script language="javascript" type="text/javascript">
340  <!--  <!--
341    
# Line 221  sub displayBackupsGrid() Line 353  sub displayBackupsGrid()
353          }          }
354        }        }
355      }      }
356        
357        function sumiraj()
358        {
359            var suma = 0;
360            for (var i = 0; i < document.forma.elements.length; i++)    
361                    {
362                            var e = document.forma.elements[i];
363                            if ((e.checked || !e.checked) && e.name != \'all\')
364                            {
365                                    if (e.checked)
366                                    {
367                                            var ret = e.name.match("fcb(.*)");
368                                            suma += parseInt(eval("document.forma.fss"+ret[1]+".value"));
369                                            
370                                    }
371                            }
372            }
373            document.forma.totalsize.value = suma;
374            return suma;
375        }
376  //-->  //-->
377  </script>        </script>      
378  EOF3  EOF3
379                $retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\"";          $retHTML .= q{
380                $retHTML.= q{<input type="hidden" value="burn" name="action">};                  <form name="forma" method="GET" action=};
381                $retHTML .= q{<input type="hidden" value="results" name="search_results">};                  $retHTML .= "\"".$MyURL."\"";
382          }                  $retHTML .= q{?action=burn>
383          $retHTML .= qq{<table style="fview"><tr>};                          <input type="hidden" value="burn" name="action">
384                            <input type="hidden" value="results" name="search_results">
385          if ($addForm) {                          <table style="fview" border="0" cellspacing="0" cellpadding="2">
386              $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";                          <tr class="tableheader">
387          }                          <td class="tableheader">
388          $retHTML .=  qq{                                  <input type="checkbox" name="allFiles" onClick="checkAll('allFiles');">
389                  <td class="tableheader">Host</td>                          </td>
390                  <td class="tableheader">Backup no</td>                          <td align="center">Share</td>
391                  <td class="tableheader">Type</td>                          <td align="center">Backup no</td>
392                  <td class="tableheader">date</td>                          <td align="center">Type</td>
393                  <td class="tableheader">age/days</td>                          <td align="center">date</td>
394                  <td class="tableheader">size/MB</td>                          <td align="center">age/days</td>
395                  </tr>                          <td align="center">size/MB</td>
396          };                          <td align="center">gzip size</td>
397                            </tr>
398    
         my @backups = getBackupsNotBurned();  
         my $backup;  
   
         if ($addForm) {  
                 $retHTML .= qq{  
399                          <tr><td colspan=7 style="tableheader">                          <tr><td colspan=7 style="tableheader">
400                          <input type="submit" value="Burn selected backups on medium" name="submitBurner">                          <input type="submit" value="Burn selected backups on medium" name="submitBurner">
401                          </td></tr>                          </td></tr>
402                  };          };
403          }  
404            my @color = (' bgcolor="#e0e0e0"', '');
405    
406            my $i = 0;
407            my $host = '';
408    
409          foreach $backup(@backups) {          foreach my $backup ( getBackupsNotBurned() ) {
410    
411                    if ($host ne $backup->{'host'}) {
412                            $i++;
413                            $host = $backup->{'host'};
414                    }
415                  my $ftype = "";                  my $ftype = "";
416                            
417                  $retHTML .= "<tr>";                  $retHTML .= "<tr" . $color[$i %2 ] . ">";
418                  if ($addForm) {                  $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .
419                          $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .                                                                                          $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
420                                  $backup->{'hostid'}.'_'.$backup->{'backupno'} .                                                                                          '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
421                                  '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupno'} .                                                                                          '" onClick="sumiraj();"></td>';
                                 '"></td>';  
                 }            
422                            
423                  $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .                  $retHTML .=
424                          '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
425                          '<td class="fviewborder">' . $backup->{'type'} . '</td>' .                          '<td align="center">' . $backup->{'backupnum'} . '</td>' .
426                          '<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . $backup->{'type'} . '</td>' .
427                          '<td class="fviewborder">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
428                          '<td class="fviewborder">' . $backup->{'size'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
429                          '</tr>';                          '<td align="right">' . $backup->{'size'} . '</td>' .
430          }                          '<td align="right">' . $backup->{'fs_size'} .
431                            '<input type="hidden" name="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '"'.
432                            'value="'. $backup->{'fs_size'} .'"'.'</td>' .
433                            "</tr>\n";
434    
         $retHTML .= "</table>";  
435    
         if ($addForm) {  
                 $retHTML .= "</form>";  
436          }          }
437    
438            $retHTML .= "</table>";
439            $retHTML .= "total gzip size:<input type=\"text\" name=\"totalsize\"><br>";
440            $retHTML .= "Note:<input type=\"text\" name=\"note\">";
441            $retHTML .= "</form>";
442                
443          return $retHTML;          return $retHTML;
444  }        }      
445    
446  sub displayGrid($$$$) {  sub displayGrid($) {
447          my ($where, $addForm, $offset, $hilite) = @_;          my ($param) = @_;
448    
449            my $offset = $param->{'offset'};
450            my $hilite = $param->{'search_filename'};
451    
452          my $retHTML = "";          my $retHTML = "";
453    
454          my $start_t = time();          my $start_t = time();
455    
456          my ($results, $files) = getFiles($where, $offset);          my ($results, $files);
457            if ($param->{'use_hest'} && length($hilite) > 0) {
458                    ($results, $files) = getFilesHyperEstraier($param);
459            } else {
460                    ($results, $files) = getFiles($param);
461            }
462    
463          my $dur_t = time() - $start_t;          my $dur_t = time() - $start_t;
464          my $dur = sprintf("%0.4fs", $dur_t);          my $dur = sprintf("%0.4fs", $dur_t);
# Line 309  sub displayGrid($$$$) { Line 477  sub displayGrid($$$$) {
477          }          }
478    
479    
         if ($addForm) {  
                 $retHTML .= qq{<form name="forma" method="GET" action="$MyURL">};  
                 $retHTML.= qq{<input type="hidden" value="search" name="action">};  
                 $retHTML .= qq{<input type="hidden" value="results" name="search_results">};  
         }  
   
   
480          $retHTML .= qq{          $retHTML .= qq{
481          <br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)          <div>
482          <table style="fview" width="100%">          Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
483                  <tr>          </div>
484                  <td class="tableheader">Share</td>          <table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
485                  <td class="tableheader">Name</td>                  <tr class="fviewheader">
486                  <td class="tableheader">Type</td>                  <td></td>
487                  <td class="tableheader">#</td>                  <td align="center">Share</td>
488                  <td class="tableheader">Size</td>                  <td align="center">Type and Name</td>
489                  <td class="tableheader">Date</td>                  <td align="center">#</td>
490                  <td class="tableheader">Media</td>                  <td align="center">Size</td>
491                    <td align="center">Date</td>
492                    <td align="center">Media</td>
493                  </tr>                  </tr>
494          };          };
495    
# Line 345  sub displayGrid($$$$) { Line 508  sub displayGrid($$$$) {
508                  return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);                  return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);
509          }          }
510    
511            my $i = $offset * $on_page;
512    
513          foreach $file (@{ $files }) {          foreach $file (@{ $files }) {
514                    $i++;
515    
516                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});                  my $typeStr  = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
517                  $retHTML .= "<tr>";                  $retHTML .= qq{<tr class="fviewborder">};
518    
519                  foreach my $v ((                  $retHTML .= qq{<td class="fviewborder">$i</td>};
520                          $file->{'sharename'},  
521                          qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center">&nbsp;} . hilite_html( $file->{'fpath'}, $hilite ),                  $retHTML .=
522                          $typeStr,                          qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} .
523                          restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ),                          qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle">&nbsp;} . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} .
524                          $file->{'size'},                          qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .
525                          epoch_to_iso( $file->{'date'} ),                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
526                          $file->{'dvd'}                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
527                  )) {                          qq{<td class="fviewborder">} . '?' . qq{</td>};
                         $retHTML .= qq{<td class="fviewborder">$v</td>};  
                 }  
528    
529                  $retHTML .= "</tr>";                  $retHTML .= "</tr>";
530          }          }
# Line 374  sub displayGrid($$$$) { Line 539  sub displayGrid($$$$) {
539          my $max_page = int( $results / $on_page );          my $max_page = int( $results / $on_page );
540          my $page = 0;          my $page = 0;
541    
542          my $link_fmt = '<a href = "#" onclick="document.forma.offset.value=%d;document.forma.submit();">%s</a>';          sub page_link($$$) {
543                    my ($param,$page,$display) = @_;
544    
545                    $param->{'offset'} = $page;
546    
547                    my $html = '<a href = "' . $MyURL;
548                    my $del = '?';
549                    foreach my $k (keys %{ $param }) {
550                            if ($param->{$k}) {
551                                    $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};
552                                    $del = '&';
553                            }
554                    }
555                    $html .= '">' . $display . '</a>';
556            }
557    
558          $retHTML .= '<div style="text-align: center;">';          $retHTML .= '<div style="text-align: center;">';
559    
560          if ($offset > 0) {          if ($offset > 0) {
561                  $retHTML .= sprintf($link_fmt, $offset - 1, '&lt;&lt;') . ' ';                  $retHTML .= page_link($param, $offset - 1, '&lt;&lt;') . ' ';
562          }          }
563    
564          while ($page <= $max_page) {          while ($page <= $max_page) {
565                  if ($page == $offset) {                  if ($page == $offset) {
566                          $retHTML .= $del . '<b>' . ($page + 1) . '</b>';                          $retHTML .= $del . '<b>' . ($page + 1) . '</b>';
567                  } else {                  } else {
568                          $retHTML .= $del . sprintf($link_fmt, $page, $page + 1);                          $retHTML .= $del . page_link($param, $page, $page + 1);
569                  }                  }
570    
571                  if ($page < $offset - $pager_pages && $page != 0) {                  if ($page < $offset - $pager_pages && $page != 0) {
# Line 404  sub displayGrid($$$$) { Line 583  sub displayGrid($$$$) {
583          }          }
584    
585          if ($offset < $max_page) {          if ($offset < $max_page) {
586                  $retHTML .= ' ' . sprintf($link_fmt, $offset + 1, '&gt;&gt;');                  $retHTML .= ' ' . page_link($param, $offset + 1, '&gt;&gt;');
587          }          }
588    
589          $retHTML .= "</div>";          $retHTML .= "</div>";
590    
         $retHTML .= "</form>" if ($addForm);  
   
591          return $retHTML;          return $retHTML;
592  }  }
593    

Legend:
Removed from v.66  
changed lines
  Added in v.121

  ViewVC Help
Powered by ViewVC 1.1.26