added a comment section..
[sgn.git] / cgi-bin / phenome / add_registry.pl
blob15eeb388d3e966714c25c23cbf66604acf2a8187
1 use strict;
2 use warnings;
4 use CXGN::Scrap::AjaxPage;
5 use CXGN::DB::Connection;
6 use CXGN::Login;
8 my $dbh = CXGN::DB::Connection->new();
9 my($login_person_id,$login_user_type)=CXGN::Login->new($dbh)->verify_session();
11 if ($login_user_type eq 'curator' || $login_user_type eq 'submitter') {
13 my $response = undef;
15 my $doc = CXGN::Scrap::AjaxPage->new();
16 my ($registry_symbol, $registry_name, $registry_description, $sp_person_id, $locus_id) = $doc->get_encoded_arguments("registry_symbol", "registry_name", "registry_description", "sp_person_id", "locus_id");
18 print STDERR "registry symbol: $registry_symbol registry name: $registry_name\n";
20 #query to make sure we can't insert 2 of the same registries. There is a constraint on the database but this is required to give user feedback
21 #I've changed the query to search only for existing registered symbols. There may be multiple symbols in the database, but users shouldn't be allowed to store more duplicates.
22 my $registry_exists = $dbh->prepare("SELECT symbol, name FROM phenome.registry WHERE symbol ilike '$registry_symbol' ");
23 $registry_exists->execute();
25 if(!$registry_exists->fetchrow_array()){
26 print STDERR "got into if block \n";
27 my $registry_query = $dbh->prepare("INSERT INTO phenome.registry (symbol, name, description, sp_person_id, status) VALUES (?, ?, ?, ?, 'registered')");
29 $registry_query->execute($registry_symbol, $registry_name, $registry_description, $sp_person_id);
31 my $registry_id = $dbh->last_insert_id('registry', 'phenome');
33 my $locus_registry_insert = $dbh->prepare("INSERT INTO phenome.locus_registry (locus_id, registry_id, sp_person_id) VALUES (?, ?, ?)");
34 $locus_registry_insert->execute($locus_id, $registry_id, $sp_person_id);
35 $response = "success";
38 else{
39 print STDERR "**GOT into else\n";
40 $response = "already exists";
41 print STDERR "response is \n";
42 print "this is nothing!"
45 print "$response";