/[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 50 by dpavlin, Sun Jul 31 16:16:55 2005 UTC revision 51 by dpavlin, Sat Aug 20 16:40:11 2005 UTC
# Line 5  use strict; Line 5  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);
7  use DBI;  use DBI;
8    use DateTime;
9  use vars qw(%In $MyURL);  use vars qw(%In $MyURL);
10    
11  my $on_page = 100;  my $on_page = 100;
12  my $pager_pages = 10;  my $pager_pages = 10;
13    
14    my $dsn = $Conf{SearchDSN};
15    my $db_user = $Conf{SearchUser} || '';
16    
17  sub getUnits() {  sub getUnits() {
18      my @ret = ();      my @ret = ();
19      my $tmp;      my $tmp;
20      my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",      my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
         "", "", { RaiseError => 1, AutoCommit => 1 } );  
21      my $st =      my $st =
22        $dbh->prepare(        $dbh->prepare(
23          " SELECT shares.ID AS ID, shares.share AS name FROM shares;");          " SELECT shares.ID AS ID, shares.share AS name FROM shares;");
# Line 27  sub getUnits() { Line 30  sub getUnits() {
30      return @ret;      return @ret;
31  }  }
32    
33    sub epoch_to_iso {
34            my $t = shift || return;
35            my $dt = DateTime->from_epoch( epoch => $t ) || return;
36    print STDERR "$t == ",$dt->epoch,"\n";
37            return $dt->ymd . ' ' . $dt->hms;
38    }
39    
40  sub getWhere($) {  sub getWhere($) {
41          my ($param)    = @_;          my ($param)    = @_;
42          my @conditions;          my @conditions;
43    
44          sub mk_iso_date($$) {          sub mk_epoch_date($$) {
45                  my ($name,$suffix) = @_;                  my ($name,$suffix) = @_;
46    
47                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;
# Line 39  sub getWhere($) { Line 49  sub getWhere($) {
49                          ( $suffix eq 'from' ? 1 : 12);                          ( $suffix eq 'from' ? 1 : 12);
50                  my $dd .= $param->{ $name . '_day_' . $suffix} ||                  my $dd .= $param->{ $name . '_day_' . $suffix} ||
51                          ( $suffix eq 'from' ? 1 : 31);                          ( $suffix eq 'from' ? 1 : 31);
52                  return sprintf("%04d-%02d-%02d", $yyyy, $mm, $dd);                  my $dt = new DateTime(
53          }                          year => $yyyy,
54                            month => $mm,
55          my $backup_from = mk_iso_date('search_backup', 'from');                          day => $dd
56          push @conditions, qq{ date(backups.date, 'unixepoch','localtime') >= '$backup_from' } if ($backup_from);                  );
57          my $backup_to = mk_iso_date('search_backup', 'to');                  return $dt->epoch || 'NULL';
58          push @conditions, qq{ date(backups.date, 'unixepoch','localtime') <= '$backup_to' } if ($backup_to);          }
59    
60          my $files_from = mk_iso_date('search', 'from');          my $backup_from = mk_epoch_date('search_backup', 'from');
61          push @conditions, qq{ date(files.date, 'unixepoch','localtime') >= '$files_from' } if ($files_from);          push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
62          my $files_to = mk_iso_date('search', 'to');          my $backup_to = mk_epoch_date('search_backup', 'to');
63          push @conditions, qq{ date(files.date, 'unixepoch','localtime') <= '$files_to' } if ($files_to);          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          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);
71            
# Line 69  sub getWhere($) { Line 84  sub getWhere($) {
84  sub getFiles($$) {  sub getFiles($$) {
85          my ($where, $offset) = @_;          my ($where, $offset) = @_;
86    
87          my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
                 "", "", { RaiseError => 1, AutoCommit => 1 } );  
88    
89          my $sql_cols = qq{          my $sql_cols = qq{
90                  files.id                        AS fid,                  files.id                        AS fid,
# Line 81  sub getFiles($$) { Line 95  sub getFiles($$) {
95                  files.name                      AS filename,                  files.name                      AS filename,
96                  files.path                      AS filepath,                  files.path                      AS filepath,
97                  shares.share||files.fullpath    AS networkPath,                  shares.share||files.fullpath    AS networkPath,
98                  date(files.date, 'unixepoch', 'localtime') AS date,                  files.date                      AS date,
99                  files.type                      AS filetype,                  files.type                      AS filetype,
100                  files.size                      AS size,                  files.size                      AS size,
101                  dvds.name                       AS dvd                  dvds.name                       AS dvd
# Line 122  sub getFiles($$) { Line 136  sub getFiles($$) {
136                          'hname'         => $row->{'hname'},                          'hname'         => $row->{'hname'},
137                          'sname'         => $row->{'sname'},                          'sname'         => $row->{'sname'},
138                          'sharename'     => $row->{'sharename'},                          'sharename'     => $row->{'sharename'},
139                          'backupno'      => $row->{'backupNum'},                          'backupno'      => $row->{'backupnum'},
140                          'fname'         => $row->{'filename'},                          'fname'         => $row->{'filename'},
141                          'fpath'         => $row->{'filepath'},                          'fpath'         => $row->{'filepath'},
142                          'networkpath'   => $row->{'networkPath'},                          'networkpath'   => $row->{'networkpath'},
143                          'date'          => $row->{'date'},                          'date'          => $row->{'date'},
144                          'type'          => $row->{'filetype'},                          'type'          => $row->{'filetype'},
145                          'size'          => $row->{'size'},                          'size'          => $row->{'size'},
# Line 139  sub getFiles($$) { Line 153  sub getFiles($$) {
153          return ($results, \@ret);          return ($results, \@ret);
154  }  }
155    
156  sub getBackupsNotBurned()  sub getBackupsNotBurned() {
157    {  
158        my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
         "", "", { RaiseError => 1, AutoCommit => 1 } );        
159        my $sql = q{        my $sql = q{
160            SELECT            SELECT
161              hosts.ID         AS hostID,              hosts.ID         AS hostID,
# Line 242  EOF3 Line 255  EOF3
255                  $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .                  $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .
256                          '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .                          '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .
257                          '<td class="fviewborder">' . $backup->{'type'} . '</td>' .                          '<td class="fviewborder">' . $backup->{'type'} . '</td>' .
258                          '<td class="fviewborder">' . $backup->{'date'} . '<td>' .                          '<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '<td>' .
259                          '</tr>';                          '</tr>';
260          }          }
261    
# Line 308  sub displayGrid($$$$) { Line 321  sub displayGrid($$$$) {
321                          $typeStr,                          $typeStr,
322                          restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ),                          restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ),
323                          $file->{'size'},                          $file->{'size'},
324                          $file->{'date'},                          epoch_to_iso( $file->{'date'} ),
325                          $file->{'dvd'}                          $file->{'dvd'}
326                  )) {                  )) {
327                          $retHTML .= qq{<td class="fviewborder">$v</td>};                          $retHTML .= qq{<td class="fviewborder">$v</td>};

Legend:
Removed from v.50  
changed lines
  Added in v.51

  ViewVC Help
Powered by ViewVC 1.1.26