1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => loc("Search for articles") &>
51 % unless ( keys %ARGS ) {
52 % my $Classes = RT::Classes->new($session{'CurrentUser'});
53 % $Classes->LimitToEnabled();
54 <table width="100%" border="0">
56 <td valign="top" width="50%">
58 if (not $Classes->First) {
59 $m->comp("/Articles/Elements/NeedsSetup");
61 $Classes->GotoFirstItem; # Reset for loop below
65 % while (my $class = $Classes->Next) {
66 <li><a href="<%RT->Config->Get('WebPath')%>/Articles/Article/Search.html?<% $m->comp('/Elements/QueryString', %filtered, Class => $class->id) %>"><&|/l, $class->Name&>in class [_1]</&></a></li>
70 <td valign="top" width="50%">
71 <form action="Search.html" method="get">
72 <& /Widgets/TitleBoxStart, title => loc('Saved searches') &>
73 <&|/l&>Load saved search:</&><br />
74 <& Elements/SelectSavedSearches, Name => 'LoadSavedSearch', Default => $CurrentSearch &>
75 <input value="<%loc('Load')%>" name="Load" type="submit" />
76 <& /Widgets/TitleBoxEnd &>
84 <& /Elements/ListActions, actions => \@results &>
85 <div style="float:right;margin-top:15px"><a href="#criteria"><&|/l&>Modify this search...</&></a></div>
87 % if ($articles->BuildSelectCountQuery =~ /WHERE/i) {
88 <h2><&|/l&>Search results</&></h2>
89 <& /Elements/CollectionList,
90 Collection => $articles,
95 GenericQueryArgs => { %filtered, Format => $format, },
102 <a name="criteria"></a>
103 <form action="Search.html" method="get">
104 <& Elements/ShowSearchCriteria, dates => \%dates, RefersTo => $RefersTo, customfields => $customfields, ReferredToBy => $ReferredToBy, %ARGS &>
107 <& Elements/ShowSavedSearches, CurrentSearch => $CurrentSearch,
108 Name => ($search ? $search->Name : undef),
109 Privacy => ($search ? $search->Privacy : undef) &>
114 <a href="<%RT->Config->Get('WebPath')%>/Articles/Article/Search.html<%$QueryString%>"><&|/l&>Bookmarkable link for this search</&></a><br />
119 my $articles = RT::Articles->new( $session{'CurrentUser'} );
121 '<a href="__WebPath__/Articles/Article/Display.html?id=__id__">__id__</a>/TITLE:#',
122 '<a href="__WebPath__/Articles/Article/Display.html?id=__id__">__Name__</a>/TITLE:Name',
124 '__CreatedRelative__',
125 '__LastUpdatedRelative__',
129 # {{{ Quicksearch logic
131 # If it is a number, load the article with that ID. Otherwise, search
132 # on name and summary.
133 if ($ARGS{'q'} && $ARGS{'q'} =~ /^(\d+)$/) {
134 return $m->comp("/Articles/Article/Display.html", id => $1);
138 # {{{ Saved search logic
142 # The keys in %ARGS that are not saved and loaded with named searches.
143 # These need to be treated specially.
144 my @metakeys = qw/NewSearchName CurrentSearch SearchPrivacy Save Load
147 if ($CurrentSearch =~ /^(.*-\d+)-SavedSearch-(\d+)$/) {
148 $search = RT::SavedSearch->new($session{'CurrentUser'});
149 $search->Load($1, $2);
152 # Have we been asked to load a search?
155 if ($ARGS{'LoadSavedSearch'} =~ /^(.*-\d+)-SavedSearch-(\d+)$/ ) {
159 $search = RT::SavedSearch->new($session{'CurrentUser'});
160 my ($ret, $msg) = $search->Load($privacy, $search_id);
162 my $searchargs = $search->GetParameter('args');
163 # Clean out ARGS and fill it in with the saved args from the
165 foreach my $key (@metakeys) {
166 $searchargs->{$key} = $ARGS{$key};
168 %ARGS = %{$searchargs};
169 $CurrentSearch = "$privacy-SavedSearch-$search_id";
171 push(@results, loc("Error: could not load saved search [_1]: [_2]",
172 $ARGS{'LoadSavedSearch'}, $msg));
175 push(@results, loc("Invalid [_1] argument", 'LoadSavedSearch'));
179 # ...or have we been asked to save, update, or delete a search?
182 my %searchargs = %ARGS;
183 foreach my $key (@metakeys) {
184 delete $searchargs{$key};
187 $search = RT::SavedSearch->new($session{'CurrentUser'});
188 unless ($ARGS{'SearchPrivacy'} =~ /^(.*)-(\d+)$/) {
189 # This shouldn't really happen, but hey.
190 push(@results, loc("WARNING: Saving search to user-level privacy"));
191 $ARGS{'SearchPrivacy'} = 'RT::User-'.$session{'CurrentUser'}->Id;
193 my ($ret, $msg) = $search->Save(Privacy => $ARGS{'SearchPrivacy'},
195 Name => $ARGS{'NewSearchName'},
196 SearchParams => {'args' => \%searchargs});
198 $CurrentSearch = $ARGS{'SearchPrivacy'} . "-SavedSearch-" .
200 push(@results, loc("Created search [_1]", $search->Name));
202 undef $search; # if we bomb out creating a search
203 # we don't want to have the empty object hang around
204 push(@results, loc("Could not create search: [_1]", $msg));
206 } elsif ($ARGS{'Update'}) {
207 if ($ARGS{'SearchPrivacy'} != $search->Privacy) {
209 loc("Error: cannot change privacy value of existing search"));
211 my %searchargs = %ARGS;
212 foreach my $key (@metakeys) {
213 delete $searchargs{$key};
216 # We already have a search loaded, because CurrentSearch is set,
217 # or else we would not have gotten here.
218 my ($ret, $msg) = $search->Update(Name => $ARGS{'NewSearchName'},
219 SearchParams => \%searchargs);
221 push(@results, loc("Search [_1] updated", $search->Name));
223 push(@results, loc("Error: search [_1] not updated: [_2]",
224 $search->Name, $msg));
227 } elsif ($ARGS{'Delete'}) {
228 # Keep track of this, as we are about to delete the search.
229 my $searchname = $search->Name;
230 my ($ret, $msg) = $search->Delete;
232 $ARGS{'CurrentSearch'} = undef;
233 push(@results, loc("Deleted search [_1]", $searchname));
234 # Get rid of all the state.
235 foreach my $key (keys %ARGS) {
238 $CurrentSearch = 'new';
241 $ReferredToBy = undef;
243 push(@results, loc("Could not delete search [_1]: [_2]",
250 # Don't want to search for a null class when there is no class specced
251 my $customfields = RT::CustomFields->new( $session{'CurrentUser'} );
254 $articles->Search( %ARGS, CustomFields => $customfields, Dates => \%dates,
255 OrderBy => \@OrderBy, Order => \@Order, );
257 $m->callback( %ARGS, _Search => $articles );
259 my %filtered = %ARGS;
260 delete $filtered{$_} for (@metakeys, "EditTopics", "ExpandTopics");
261 delete $filtered{$_} for grep {$filtered{$_} !~ /\S/} keys %filtered;
262 @filtered{qw(OrderBy Order)} = (\@OrderBy, \@Order);
263 my $QueryString = "?".$m->comp('/Elements/QueryString', %filtered);
269 $LastUpdatedBefore => ''
270 $LastUpdatedAfter => ''
272 $ReferredToBy => undef
273 $CurrentSearch => 'new'