minor fixes
[sgn.git] / cgi-bin / phenome / associate_allele.pl
blob8590c41b3a2a7a6be73da98684aec32edf8dcf9a
1 use strict;
2 use warnings;
4 use CXGN::Scrap::AjaxPage;
5 use CXGN::Login;
6 use CXGN::Chado::Stock;
7 use CXGN::People::Person;
8 use CXGN::Feed;
9 use JSON;
10 use CatalystX::GlobalContext '$c';
12 my $doc = CXGN::Scrap::AjaxPage->new();
13 $doc->send_http_header();
15 my $dbh = $c->dbc->dbh;
16 my $schema = $c->dbic_schema('Bio::Chado::Schema' , 'sgn_chado');
17 my($login_person_id,$login_user_type)=CXGN::Login->new($dbh)->verify_session();
19 if ($login_user_type eq 'curator' || $login_user_type eq 'submitter' || $login_user_type eq 'sequencer') {
21 my $doc = CXGN::Scrap::AjaxPage->new();
22 my ($stock_id, $allele_id, $sp_person_id) = $doc->get_encoded_arguments("stock_id", "allele_id", "sp_person_id");
24 my %error = ();
25 my $json = JSON->new();
27 eval {
28 my $stock = CXGN::Chado::Stock->new($schema, $stock_id);
29 $stock->associate_allele($allele_id, $sp_person_id);
30 $error{"response"} = "Associated allele $allele_id with stock $stock_id!";
32 if ($@) {
33 $error{"error"} = "Associate allele failed! " . $@;
34 CXGN::Contact::send_email('associate_allele.pl died',$error{"error"}, 'sgn-bugs@sgn.cornell.edu');
35 } else {
36 my $subject="[New stock associated] allele $allele_id";
37 my $person= CXGN::People::Person->new($dbh, $login_person_id);
38 my $user=$person->get_first_name()." ".$person->get_last_name();
39 my $user_link = qq |http://www.sgn.cornell.edu/solpeople/personal-info.pl?sp_person_id=$sp_person_id|;
41 my $fdbk_body="$user ($user_link has associated stock $stock_id with allele $allele_id \n
42 http://www.sgn.cornell.edu/stock/$stock_id/view";
43 CXGN::Contact::send_email($subject,$fdbk_body, 'sgn-db-curation@sgn.cornell.edu');
44 CXGN::Feed::update_feed($subject,$fdbk_body);
46 my $jobj = $json->objToJson(\%error);
47 print $jobj;