add extra newline after headings in error emails, easier to read.
[sgn.git] / cgi-bin / solpeople / people_search.pl
bloba74c80d74b774d064de6c7fa81d09ad9928f1b74
1 use CatalystX::GlobalContext qw( $c );
2 ######################################################################
4 # Search the people database and display the results.
6 # Adapted from locus_search.pl by Evan Herbst, 1 / 3 / 07
8 ######################################################################
10 use strict;
12 use CXGN::Page;
13 use CXGN::Page::FormattingHelpers
14 qw/blue_section_html info_section_html page_title_html columnar_table_html/;
15 use CXGN::Search::CannedForms;
16 use CXGN::Searches::People;
18 #################################################
20 # Start a new SGN page.
21 my $page = CXGN::Page->new( "SGN directory search results", "Evan" );
22 $page->header();
24 print page_title_html('Directory search results');
26 #create the search and query objects
27 my $search = CXGN::Searches::People->new();
28 my $query = $search->new_query();
29 $search->page_size(20); #results shown per page
31 #get the parameters
32 my %params = CGI->new->Vars
33 or $c->throw( message => 'No query parameters provided', is_error => 0 );
34 $query->from_request( \%params );
36 my $search_again_html = info_section_html(
37 title => 'Search again',
38 contents => CXGN::Search::CannedForms::people_search_form( $page, $query )
42 _add_to_param( $query, $_, '&t NOT LIKE ? AND &t IS NOT NULL', '%contact-info.pl%')
43 for 'last_name', 'first_name';
45 my $result = $search->do_search($query); #execute the search
46 my @results;
47 while ( my $r = $result->next_result() ) {
48 #fields in result objs appear in the order in which they're registered with has_parameter() in the query class
49 push @results,
51 qq|<a href="/solpeople/personal-info.pl?sp_person_id=$r->[7]&amp;action=view">$r->[1], $r->[0]</a>|,
52 $r->[2],
53 $r->[3],
54 $r->[4],
58 #build the HTML to output
59 my $pagination_html = $search->pagination_buttons_html( $query, $result );
61 my $results_html = <<EOH;
62 <div id="searchresults">
63 EOH
65 $results_html .= columnar_table_html(
66 headings => [ 'Name', 'E-mail', 'Organization', 'Country' ],
67 data => \@results,
68 __alt_freq => 2
71 $results_html .= <<EOH;
72 </div>
73 $pagination_html
74 EOH
76 if (@results) {
77 print info_section_html(
78 title => 'Results',
79 contents =>
80 sprintf(
81 '<span class="paginate_summary">%s matches </span>',
82 $result->total_results()
84 .$results_html,
87 else {
88 print '<h4>No matches found</h4>';
91 print $search_again_html;
93 $page->footer();
95 #### helper subs ######
97 # set additional criteria to not return people that have not set their
98 # first name or last name
99 sub _add_to_param {
100 my ($query,$param,$cond,@bind) = @_;
101 my $curr = $query->param_val($param) || ['true'];
102 my $curr_exp = shift @$curr;
103 $curr_exp = "&t $curr_exp" unless $curr_exp =~ /(&t|^true$)/;
104 $query->param_set($param => ["$curr_exp AND $cond",@$curr,@bind]);