/[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 79 by dpavlin, Fri Aug 26 23:37:10 2005 UTC revision 84 by dpavlin, Sun Aug 28 10:20:31 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 $dbh;
19    
20    sub get_dbh {
21            $dbh ||= DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
22            return $dbh;
23    }
24    
25  sub getUnits() {  sub getUnits() {
26          my @ret;          my @ret;
27    
28          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
29          my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares ORDER BY share} );          my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares ORDER BY share} );
30          $sth->execute();          $sth->execute();
31          push @ret, { 'id' => '', 'share' => '-'};       # dummy any          push @ret, { 'id' => '', 'share' => '-'};       # dummy any
# Line 26  sub getUnits() { Line 33  sub getUnits() {
33          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
34                  push @ret, $row;                  push @ret, $row;
35          }          }
         $dbh->disconnect();  
36          return @ret;          return @ret;
37  }  }
38    
# Line 37  sub epoch_to_iso { Line 43  sub epoch_to_iso {
43          return $iso;          return $iso;
44  }  }
45    
46  sub getWhere($) {  sub dates_from_form($) {
47          my ($param)    = @_;          my $param = shift || return;
         my @conditions;  
48    
49          sub mk_epoch_date($$) {          sub mk_epoch_date($$) {
50                  my ($name,$suffix) = @_;                  my ($name,$suffix) = @_;
# Line 57  sub getWhere($) { Line 62  sub getWhere($) {
62                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
63          }          }
64    
65          my $backup_from = mk_epoch_date('search_backup', 'from');          return (
66                    mk_epoch_date('search_backup', 'from'),
67                    mk_epoch_date('search_backup', 'to'),
68                    mk_epoch_date('search', 'from'),
69                    mk_epoch_date('search', 'to'),
70            );
71    }
72    
73    
74    sub getWhere($) {
75            my $param = shift || return;
76    
77            my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
78    
79            my @conditions;
80          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');  
81          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');  
82          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');  
83          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
84    
85          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'});  
86    
87            push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
88          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'});
89    
90          return (          return join(" and ", @conditions);
                 join(" and ", @conditions),  
                 $files_from, $files_to,  
                 $backup_from, $backup_to  
         );  
91  }  }
92    
93    
94  sub getFiles($$) {  sub getFiles($$) {
95          my ($where, $offset) = @_;          my ($param, $offset) = @_;
96    
97          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
98    
99          my $sql_cols = qq{          my $sql_cols = qq{
100                  files.id                        AS fid,                  files.id                        AS fid,
# Line 113  sub getFiles($$) { Line 123  sub getFiles($$) {
123          };          };
124    
125          my $sql_where;          my $sql_where;
126            my $where = getWhere($param);
127          $sql_where = " WHERE ". $where if ($where);          $sql_where = " WHERE ". $where if ($where);
128    
129          my $sql_order = qq{          my $sql_order = qq{
# Line 160  sub getFiles($$) { Line 171  sub getFiles($$) {
171          }          }
172            
173          $sth->finish();          $sth->finish();
         $dbh->disconnect();  
174          return ($results, \@ret);          return ($results, \@ret);
175  }  }
176    
177  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
178    
179          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = get_dbh();
180          my $sql = q{          my $sql = q{
181          SELECT          SELECT
182                  backups.hostID          AS hostid,                  backups.hostID          AS hostid,
# Line 231  EOF3 Line 241  EOF3
241                $retHTML .= q{<input type="hidden" value="results" name="search_results">};                $retHTML .= q{<input type="hidden" value="results" name="search_results">};
242          }          }
243          $retHTML .= qq{          $retHTML .= qq{
244                  <table style="fview" border="1" cellspacing="1" cellpadding="3">                  <table style="fview" border="1" cellspacing="0" cellpadding="3">
245                  <tr class="tableheader">                  <tr class="tableheader">
246          };          };
247    
# Line 289  EOF3 Line 299  EOF3
299          return $retHTML;          return $retHTML;
300  }        }      
301    
302  sub displayGrid($$$$) {  sub displayGrid($$) {
303          my ($where, $addForm, $offset, $hilite) = @_;          my ($param, $addForm) = @_;
304    
305            my $offset = $param->{'offset'};
306            my $hilite = $param->{'search_filename'};
307    
308          my $retHTML = "";          my $retHTML = "";
309    
310          my $start_t = time();          my $start_t = time();
311    
312          my ($results, $files) = getFiles($where, $offset);          my ($results, $files) = getFiles($param, $offset);
313    
314          my $dur_t = time() - $start_t;          my $dur_t = time() - $start_t;
315          my $dur = sprintf("%0.4fs", $dur_t);          my $dur = sprintf("%0.4fs", $dur_t);
# Line 357  sub displayGrid($$$$) { Line 371  sub displayGrid($$$$) {
371    
372                  $retHTML .=                  $retHTML .=
373                          qq{<td class="fviewborder" align="right">} . $file->{'sharename'} . qq{</td>} .                          qq{<td class="fviewborder" align="right">} . $file->{'sharename'} . qq{</td>} .
374                          qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr">&nbsp;} . hilite_html( $file->{'fpath'}, $hilite ) . qq{</td>} .                          qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle">&nbsp;} . hilite_html( $file->{'fpath'}, $hilite ) . qq{</td>} .
375                          qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupno'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'fpath'} )}, $file->{'backupno'} ) . qq{</td>} .                          qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupno'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'fpath'} )}, $file->{'backupno'} ) . qq{</td>} .
376                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .                          qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
377                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .                          qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .

Legend:
Removed from v.79  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26