BrAPI study POST call
[sgn.git] / cgi-bin / search / pub_search.pl
blob36d1040f8b535eacbba82b2eb74b865309b320e6
1 use strict;
2 use warnings;
4 use CXGN::Publication;
5 use CXGN::Page;
6 use CXGN::Page::FormattingHelpers qw/
7 blue_section_html
8 info_section_html
9 page_title_html
10 columnar_table_html
12 use CXGN::Search::CannedForms;
13 use CXGN::DB::Connection;
14 use CXGN::Login;
15 use CXGN::People::Person;
16 use CXGN::Chado::Publication;
18 #################################################
20 # Start a new SGN page.
22 my $page = CXGN::Page->new( "SGN publcation search results", "Naama" );
24 $page->jsan_use("jquery");
25 $page->jsan_use("CXGN.Phenome.Publication");
27 $page->header();
29 print page_title_html('SGN Publication search');
30 my $dbh = CXGN::DB::Connection->new;
32 #create the search and query objects
33 my $search = CXGN::Publication->new;
34 my $query = $search->new_query;
36 $search->page_size(10); #set 10 phenetypes per page
38 my ( $login_person_id, $login_user_type ) =
39 CXGN::Login->new($dbh)->has_session();
41 #get the parameters
42 my %params = $page->get_all_encoded_arguments;
44 #my $allele_keyword = $page->get_encoded_arguments("allele_keyword");
45 $query->from_request( \%params );
47 if (%params) {
48 $query->order_by( date_stored => 'desc', pyear => 'desc', title => '' );
49 my $result = $search->do_search($query); #execute the search
50 my @results;
52 ###check if the the user has permission to alter pub_curator status
54 my $has_permission = 0;
55 if ( $login_user_type eq 'curator'
56 || $login_user_type eq 'submitter'
57 || $login_user_type eq 'sequencer' )
59 $has_permission = 1;
61 #####
63 while ( my $r = $result->next_result ) {
64 my $pub_id = $r->[0];
65 my $publication = CXGN::Chado::Publication->new( $dbh, $pub_id );
66 my $pub_ref = $publication->print_mini_ref();
68 #my $title= $r->[1];
69 #my $series = $r->[2];
70 #my $pyear= $r->[3];
71 my $assigned_to_id = $r->[4];
72 my $assigned_to =
73 CXGN::People::Person->new( $dbh, $assigned_to_id )->get_first_name();
74 my $curation_date = $r->[5];
75 my $curated_by_id = $r->[6];
76 my $stat = $r->[7];
77 my $stored_on = $r->[8];
78 $stored_on =~ s/(\d{4}-\d{2}-\d{2})(.*)/$1/;
80 my @stat_options = ( "curated", "pending", "irrelevant", "no gene" );
81 my $stat_options = qq|<option value=""></option>|;
82 foreach my $s (@stat_options) {
83 my $selected = qq|selected="selected"| if $s eq $stat || '';
84 $stat_options .= qq|<option value="$s" $selected >$s</option>|;
86 my $stats = $stat;
87 $stats =
88 qq|<select id="pub_stat" onchange="Publication.updatePubCuratorStat(this.value, $pub_id)">
89 $stat_options
90 </select>
91 | if $has_permission;
93 my @curators = CXGN::People::Person::get_curators($dbh);
94 my %names =
95 map { $_ => CXGN::People::Person->new( $dbh, $_ )->get_first_name() }
96 @curators;
97 my $curator_options = qq|<option value=""></option>|;
98 for my $curator_id ( keys %names ) {
99 my $curator = $names{$curator_id};
100 my $selected = qq|selected="selected"| if $curator_id == $assigned_to_id || '';
101 $curator_options .=
102 qq|<option value="$curator_id" $selected>$curator</option>|;
104 my $curators = $assigned_to;
105 $curators =
106 qq|<select id="pub_curator_select" onchange="Publication.updatePubCuratorAssigned(this.value, $pub_id)">
107 $curator_options
108 </select>
109 | if $has_permission;
111 my $pub = CXGN::Chado::Publication->new( $dbh, $pub_id );
112 push @results,
114 map { $_ } (
115 qq|<a href="/publication/$pub_id/view">$pub_ref</a>|,
116 $stats, $curators, $stored_on
121 #build the HTML to output
122 my $pagination_html = $search->pagination_buttons_html( $query, $result );
124 my $results_html = <<EOH;
125 <div id="searchresults">
128 $results_html .= columnar_table_html(
129 headings => [ 'Title', 'Status', 'Assigned to', 'Stored' ],
130 data => \@results,
131 __alt_freq => 2,
132 __align => 'llll'
134 # __alt_width => 2,
137 $results_html .= <<EOH;
138 </div>
139 $pagination_html
142 if (@results) {
143 print blue_section_html(
144 'Publication search results',
146 sprintf(
147 '<span class="paginate_summary">%s matches </span>',
148 $result->total_results, $result->time
150 $results_html
153 else {
154 print '<h4>No matches found</h4>';
157 print info_section_html(
158 title => 'Search again',
159 contents =>
160 CXGN::Search::CannedForms::publication_search_form( $page, $query )
164 else {
165 print CXGN::Search::CannedForms::publication_search_form($page);
168 $page->footer();
170 #############