bug fix: require search string to be in filepath to produce same
[BackupPC.git] / lib / BackupPC / CGI / SearchArchives.pm
1 ####################################################################
2 #  SearchArchives.pm - module for searching through archived files #
3 #                      via a sqlite database                       #
4 ####################################################################
5 package BackupPC::CGI::SearchArchives;
6
7
8 use strict;
9 use BackupPC::CGI::Lib qw(:all);
10 use BackupPC::SearchLib;
11 use Data::Dumper;
12 use HTML::FillInForm;
13 use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
14
15 sub action() {
16         my $hosts_html = "";
17
18     
19         BackupPC::CGI::Lib::NewRequest();
20         my @hosts = BackupPC::SearchLib::getUnits();
21
22         foreach my $host (@hosts) {
23                 $hosts_html .= "<option value=" . $host->{'id'} . "> " . $host->{'share'} . " </option>\n";
24         }
25
26         sub date_from_to_html {
27                 my $name = shift || return;
28                 return qq{
29                         <input type="text" name="${name}_year_from" size="4">
30                         <input type="text" name="${name}_month_from" size="2">
31                         <input type="text" name="${name}_day_from" size="2">
32                         -
33                         <input type="text" name="${name}_year_to" size="4">
34                         <input type="text" name="${name}_month_to" size="2">
35                         <input type="text" name="${name}_day_to" size="2">
36                 };
37         }
38
39         my $form .= qq{
40 <form name="searchForm" method="GET" action="$MyURL">
41 <p>
42         Filename:
43         <input type="text" name="search_filename" size="50">
44         &nbsp;
45         on share
46         &nbsp;
47         <select name="search_share">$hosts_html</select>
48         &nbsp;&nbsp;&nbsp;
49         <input type="submit" value="Search">
50 </p>
51
52 <p style="color:gray;">
53         file(s) between:
54         } . date_from_to_html('search') . qq{
55         &nbsp;&nbsp;
56         backups between:
57         } . date_from_to_html('search_backup') . qq{
58         (yyyy-mm-dd)
59 </p>
60
61 <p style="color: gray;">
62         <input type="checkbox" name="use_hest"> use faster full-text search engine
63 </p>
64
65 <input type="hidden" value="search" name="action">
66 <input type="hidden" value="results" name="search_results">
67 </form>
68         };
69
70         my $html = eval(q{ ${h1("Search")}});
71
72         if ( !defined($In{search_results}) ) {
73                 $html .= eval(q{ ${h2("Search criteria")}});
74
75                 $html .= $form;
76         } else {
77                 $html .= eval(q{ ${h2("Search results")}});
78
79                 my $fif = new HTML::FillInForm;
80                 $html .= $fif->fill(scalarref => \$form, fdat => \%In);
81
82                 $html .= BackupPC::SearchLib::displayGrid( \%In );
83         }
84
85         Header( eval("qq{$Lang->{Search_archive}}"), "", 1, "", $html );
86         Trailer();
87 }
88
89 1;