diff --git a/cgi-bin/DW/Controller/Support/History.pm b/cgi-bin/DW/Controller/Support/History.pm index 9e4c1d169d..c441c1475f 100644 --- a/cgi-bin/DW/Controller/Support/History.pm +++ b/cgi-bin/DW/Controller/Support/History.pm @@ -29,43 +29,44 @@ DW::Routing->register_string( '/support/history', \&history_handler, app => 1 ); sub history_handler { my $r = DW::Request->get; - my $get = $r->get_args; + my $args = $r->get_args; + $args = $r->post_args if $r->did_post; my ( $ok, $rv ) = controller( anonymous => 0, form_auth => 1 ); return $rv unless $ok; - - my $vars = {}; + + my $vars = {}; my $remote = $rv->{remote}; my $fullsearch = $remote->has_priv( 'supporthelp' ); $vars->{fullsearch} = $fullsearch; - - if ( $get->{user} || $get->{email} || $get->{userid} ) { + + if ( $args->{user} || $args->{email} || $args->{userid} ) { my $dbr = LJ::get_db_reader(); return error_ml( '/support/history.tt.error.nodatabase' ) unless $dbr; - - $vars->{get_user} = ( $get->{user} ) ? 1 : 0; - $vars->{get_userid} = ( $get->{userid} ) ? 1 : 0; - $vars->{get_email} = ( $get->{email} ) ? 1 : 0; + + $vars->{get_user} = ( $args->{user} ) ? 1 : 0; + $vars->{get_userid} = ( $args->{userid} ) ? 1 : 0; + $vars->{get_email} = ( $args->{email} ) ? 1 : 0; $vars->{user} = $remote->user; - + my $reqlist; - if ( $get->{user} || $get->{userid} ) { + if ( $args->{user} || $args->{userid} ) { # get requests by a user, regardless of email (only gets user requests) - my $userid = $get->{userid} ? $get->{userid}+0 : LJ::get_userid( LJ::trim( $get->{user} ) ); + my $userid = $args->{userid} ? $args->{userid}+0 : LJ::get_userid( LJ::trim( $args->{user} ) ); return error_ml( '/support/history.tt.error.invaliduser' ) unless $userid && ( $fullsearch || $remote->id == $userid ); $vars->{username} = LJ::ljuser( LJ::get_username( $userid ) ); - $reqlist = $dbr->selectall_arrayref( + $reqlist = $dbr->selectall_arrayref( 'SELECT spid, subject, state, spcatid, requserid, ' . 'timecreate, timetouched, timelasthelp, reqemail ' . 'FROM support WHERE reqtype = \'user\' AND requserid = ?', undef, $userid ); - } elsif ( $get->{email} ) { + } elsif ( $args->{email} ) { # try by email, note that this gets requests opened by users and anonymous # requests, so we can view them all - my $email = LJ::trim( $get->{email} ); + my $email = LJ::trim( $args->{email} ); $vars->{email} = LJ::ehtml( $email ); my %user_emails; @@ -80,13 +81,13 @@ sub history_handler { return error_ml( '/support/history.tt.error.invalidemail' ) unless $email =~ /^.+\@.+$/ && ( $fullsearch || $user_emails{$email} ); - $reqlist = $dbr->selectall_arrayref( + $reqlist = $dbr->selectall_arrayref( 'SELECT spid, subject, state, spcatid, requserid, ' . 'timecreate, timetouched, timelasthelp, reqemail ' . 'FROM support WHERE reqemail = ?', undef, $email ); - } - + } + if ( @{$reqlist || []} ) { # construct a list of people who have answered these requests my @ids; @@ -154,14 +155,19 @@ sub history_handler { } else { $vars->{noresults} = 1; } + } elsif ( $args->{fulltext} ) { + $rv = DW::Controller::Support::Search::do_search( + remoteid => $remote->id, query => $args->{fulltext} ); + return DW::Template->render_template( 'support/search.tt', $rv ); + } elsif ( ! $fullsearch ) { my $redirect_user = $remote->user; $r->header_out( Location => "$LJ::SITEROOT/support/history?user=$redirect_user" ); return $r->REDIRECT; } - + return DW::Template->render_template( 'support/history.tt', $vars ); - + } - + 1; diff --git a/cgi-bin/DW/Controller/Support/Search.pm b/cgi-bin/DW/Controller/Support/Search.pm index c14d0cf7e5..ecb756bde9 100644 --- a/cgi-bin/DW/Controller/Support/Search.pm +++ b/cgi-bin/DW/Controller/Support/Search.pm @@ -27,16 +27,7 @@ DW::Routing->register_string( "/support/search", \&search_handler, app => 1 ); sub search_handler { my ( $ok, $rv ) = controller( authas => 1, form_auth => 0 ); return $rv unless $ok; - - my $q = ''; - my $error = sub { - return DW::Template->render_template( 'support/search.tt', - { error => $_[0], query => $q } ); - }; - - my $gc = LJ::gearman_client(); - die "Sorry, content searching is not configured on this server.\n" - unless $gc && @LJ::SPHINX_SEARCHD; + my $remote = $rv->{remote}; my $r = DW::Request->get; return DW::Template->render_template( 'support/search.tt' ) @@ -47,18 +38,40 @@ sub search_handler { die "Invalid form auth.\n" unless LJ::check_form_auth( $args->{lj_form_auth} ); - $q = LJ::strip_html( LJ::trim( $args->{query} ) ); + $rv = do_search( remoteid => $remote->id, + query => $args->{query}, + offset => $args->{offset} ); + + return DW::Template->render_template( 'support/search.tt', $rv ); +} + +# helper subroutine that can be called from other contexts + +sub do_search { + my %args = @_; + + my $remoteid = delete $args{remoteid} or die "No remoteid"; + my $q = LJ::strip_html( LJ::trim( delete $args{query} ) ); + my $offset = ( delete $args{offset} // 0 ) + 0; + die "Unknown opts to do_search" if %args; + + my $gc = LJ::gearman_client(); + die "Sorry, content searching is not configured on this server.\n" + unless $gc && @LJ::SPHINX_SEARCHD; + + my $error = sub { return { query => $q, error => $_[0] } }; + my $ok = sub { return { query => $q, offset => $offset, + result => $_[0] } }; + return $error->( "Please specify a shorter search string." ) if length $q > 255; return $error->( "Please specify a search string." ) unless length $q > 0; - - my $offset = ( $args->{offset} // 0 ) + 0; return $error->( "Offset must be between 0 and 1000." ) unless $offset >= 0 && $offset <= 1000; # Gearman worker takes a blob, we send it a frozen hash. - my $search_args = { remoteid => $rv->{remote}->id, query => $q, + my $search_args = { remoteid => $remoteid, query => $q, offset => $offset, support => 1 }; my $arg = Storable::nfreeze( $search_args ); @@ -85,11 +98,7 @@ sub search_handler { return $error->( "Sorry, there were no results found for that search." ) if $result->{total} <= 0; - use Data::Dumper; - - # Okay, render the results with the matches. - return DW::Template->render_template( 'support/search.tt', - { query => $q, result => $result, offset => $offset, tmp => Dumper( $result ) } ); + return $ok->( $result ); } 1; diff --git a/views/support/history.tt b/views/support/history.tt index 645e37ae7a..553a2304a0 100644 --- a/views/support/history.tt +++ b/views/support/history.tt @@ -48,7 +48,7 @@ the same terms as Perl itself. For a copy of the license, please reference [% END %] [% IF fullsearch %] -
+
[% '.search.text' | ml %]
@@ -87,6 +87,18 @@ the same terms as Perl itself. For a copy of the license, please reference
+
+
+
+
+ +
+
+ +
+
+
+
@@ -96,6 +108,7 @@ the same terms as Perl itself. For a copy of the license, please reference
[% '.search.onefield' | ml %]
+ [% dw.form_auth %]
[% ELSE %] [% IF get_user %] diff --git a/views/support/history.tt.text b/views/support/history.tt.text index 9d7905abda..5c46869dd8 100644 --- a/views/support/history.tt.text +++ b/views/support/history.tt.text @@ -16,6 +16,10 @@ .search.email.text=Email Address +.search.fulltext=Containing Text: + +.search.fulltext.text=Search Text + .search.onefield=Please fill out only one of the search fields. .search.otheremails=You may also search for requests from email addresses associated with your account.