/[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 16 by dpavlin, Mon Jul 11 11:51:09 2005 UTC revision 19 by dpavlin, Mon Jul 11 14:32:40 2005 UTC
# Line 25  sub getUnits() { Line 25  sub getUnits() {
25  }  }
26    
27  sub getWhere($) {  sub getWhere($) {
28      my ($param)    = @_;          my ($param)    = @_;
29      my $retSQL     = "";          my @conditions;
     my @conditions = ();  
     my $cond;  
30    
31                sub mk_iso_date($$) {
32                      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'}  ."\"");  
     }  
33    
34      if ( defined( $param->{'search_day_from'} )   && $param->{'search_day_from'} ne "" ) {                  my $yyyy = $param->{ $name . '_year_' . $suffix} || return;
35          push( @conditions,                  my $mm .= $param->{ $name . '_month_' . $suffix} ||
36              ' strftime("%d", datetime(files.date, "unixepoch","localtime")) >= "'                          ( $suffix eq 'from' ? 1 : 12);
37                . $param->{'search_day_from'}  ."\"");                  my $dd .= $param->{ $name . '_day_' . $suffix} ||
38      }                          ( $suffix eq 'from' ? 1 : 31);
39      if ( defined( $param->{'search_month_from'} ) && $param->{'search_month_from'} ne "") {                  return sprintf("%04d-%02d-%02d", $yyyy, $mm, $dd);
40          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'} ."\"");  
     }  
41    
42      if ( defined( $param->{'search_host'} ) && $param->{'search_host'} ne "") {          my $backup_from = mk_iso_date('search_backup', 'from');
43        push( @conditions, ' backups.hostID = ' . $param->{'search_host'} );          push @conditions, qq{ date(backups.date, 'unixepoch','localtime') >= '$backup_from' } if ($backup_from);
44      }          my $backup_to = mk_iso_date('search_backup', 'to');
45            push @conditions, qq{ date(backups.date, 'unixepoch','localtime') <= '$backup_to' } if ($backup_to);
46    
47            my $files_from = mk_iso_date('search', 'from');
48            push @conditions, qq{ date(files.date, 'unixepoch','localtime') >= '$files_from' } if ($files_from);
49            my $files_to = mk_iso_date('search', 'to');
50            push @conditions, qq{ date(files.date, 'unixepoch','localtime') <= '$files_to' } if ($files_to);
51    
52      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'}."%'");  
         }  
53            
54      $retSQL = "";          push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'});
     foreach $cond(@conditions)  
       {  
           if ($retSQL ne "")  
             {  
                 $retSQL .= " AND ";  
             }  
           $retSQL .= $cond;  
       }        
55    
56                push (@conditions, " files.name LIKE '".$param->{'search_filename'}."%'") if ($param->{'search_filename'});
57      return $retSQL;  
58            return (
59                    join(" and ", @conditions),
60                    $files_from, $files_to,
61                    $backup_from, $backup_to
62            );
63  }  }
64    
65    
66  sub getFiles($$)  sub getFiles($$)
67    {    {
68        my ($where, $offset) = @_;        my ($where, $offset) = @_;
# Line 141  sub getFiles($$) Line 87  sub getFiles($$)
87                  FROM files                  FROM files
88                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
89                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
90                            INNER JOIN backups      ON backups.num = files.backupNum
91                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid
92            };            };
93    
# Line 320  EOF3 Line 267  EOF3
267        
268    }          }      
269    
270  sub displayGrid($$$)  sub displayGrid($$$$) {
271    {          my ($where, $addForm, $offset, $hilite) = @_;
272        my ($where, $addForm, $offset) = @_;          my $retHTML = "";
273        my $retHTML = "";  
274                  if ($addForm) {
275        if ($addForm)                  $retHTML .= qq{<form name="forma" method="POST" action="}.$MyURL.qq{?action=search">};
276          {                  $retHTML.= qq{<input type="hidden" value="search" name="action">};
277                $retHTML .= q{<form name="forma" method="POST" action="}."$MyURL"."?action=search\"";                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};
               $retHTML.= q{<input type="hidden" value="search" name="action">};  
               $retHTML .= q{<input type="hidden" value="results" name="search_results">};  
278          }          }
279        $retHTML .= "<table style=\"fview\">";          $retHTML .= qq{
280        $retHTML .= "<tr> ";          <table style="fview" width="100%">
281        $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>";                  <tr>
282        my @files = getFiles($where, $offset);                  <td class="tableheader">Host</td>
283        my $file;                  <td class="tableheader">Type</td>
284                    <td class="tableheader">Name</td>
285                    <td class="tableheader">backup no.</td>
286                    <td class="tableheader">size</td>
287                    <td class="tableheader">date</td>
288                    <td class="tableheader">Media</td>
289                    </tr>
290            };
291            my @files = getFiles($where, $offset);
292            my $file;
293    
294        foreach $file(@files)          sub hilite_html($$) {
295          {                  my ($html, $search) = @_;
296              my $ftype = "";                  $html =~ s#($search)#<b>$1</b>#gis;
297                                return $html;
             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>";  
298          }          }
       $retHTML .= "</table>";  
299    
300                  foreach $file (@files) {
301                    my $ftype = "file";
302                    $ftype = "dir" if ($file->{'type'} == BPC_FTYPE_DIR);
303    
304                    $retHTML .= "<tr>";
305    
306                    foreach my $v ((
307                            $file->{'hname'},
308                            $ftype,
309                            hilite_html( $file->{'fpath'}, $hilite ),
310                            $file->{'backupno'},
311                            $file->{'size'},
312                            $file->{'date'},
313                            $file->{'dvd'}
314                    )) {
315                            $retHTML .= qq{<td class="fviewborder">$v</td>};
316                    }
317    
318        $retHTML .= "<INPUT TYPE=\"hidden\" VALUE=\"\" NAME=\"offset\">";                  $retHTML .= "</tr>";
319        for (my $ii = 1; $ii <= $#files; $ii++)          }
320        {          $retHTML .= "</table>";
           $retHTML .= "<a href = \"#\" onclick=\"document.forma.offset.value=$ii;document.forma.submit();\">$ii</a>";  
           if ($ii < $#files)  
             {  
                 $retHTML .= " | ";  
             }  
       }  
321    
322            # skip pager
323            return $retHTML;
324    
325         if ($addForm)          $retHTML .= "<INPUT TYPE=\"hidden\" VALUE=\"\" NAME=\"offset\">";
326         {          for (my $ii = 1; $ii <= $#files; $ii++) {
327             $retHTML .= "</form>";                  $retHTML .= "<a href = \"#\" onclick=\"document.forma.offset.value=$ii;document.forma.submit();\">$ii</a>";
328         }                  if ($ii < $#files) {
329                            $retHTML .= " | ";
330                    }
331            }
332    
333            $retHTML .= "</form>" if ($addForm);
334                
335        return $retHTML;          return $retHTML;
336    }  }
337    
338  1;  1;

Legend:
Removed from v.16  
changed lines
  Added in v.19

  ViewVC Help
Powered by ViewVC 1.1.26