Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / cgi-bin / solpeople / admin / create_organization.pl
blob92a7d16f9a76490fa2fcff3b788cbfae1d6b1ae9
1 #!/usr/bin/perl -w
2 use strict;
3 use warnings;
5 use CXGN::Page;
6 use CXGN::Login;
7 use CXGN::People;
8 use CXGN::DB::Connection;
9 use HTML::Entities;
11 my $page=CXGN::Page->new("Create organization","john");
12 my $dbh=CXGN::DB::Connection->new("sgn_people");
14 my $logged_in_person_id=CXGN::Login->new($dbh)->verify_session();
15 my $logged_in_user=CXGN::People::Person->new($dbh, $logged_in_person_id);
16 my $logged_in_username=$logged_in_user->get_first_name()." ".$logged_in_user->get_last_name();
17 my $logged_in_user_type=$logged_in_user->get_user_type();
18 if($logged_in_user_type eq 'curator')
20 my($name,$short_name)=$page->get_encoded_arguments("organization_name", "short_name");
21 if($name)
23 $short_name ||= $name;
24 my $org_query=$dbh->prepare("select sp_organization_id from sgn_people.sp_organization where name=?");
25 $org_query->execute($name);
26 my($existing_org_id)=$org_query->fetchrow_array();
27 if($existing_org_id){$page->message_page("Organization \"$name\" exists, id $existing_org_id.");}
28 else
30 my $org_insert=$dbh->prepare("insert into sgn_people.sp_organization (name, shortname) values (?,?)");
31 $org_insert->execute($name, $short_name);
32 $page->header("Create organization","Organization created: $name");
33 $page->footer();
36 else
38 $page->header("Create organization");
39 print <<END_HTML;
40 <form method="post" action="">
41 <table cellpadding="2" cellspacing="2" width="100%" align="center">
42 <tr><td colspan="2"><b>Curators may use this form to create organizations.<br />&nbsp;</b></td></tr>
43 <tr><td>Organization name</td><td><input type="text" name="organization_name" size="30" value=""></td></tr>
44 <tr><td>Short name</td><td><input type="text" name="short_name" size="30" value=""></td></tr>
45 <tr><td>&nbsp;</td></tr>
46 <tr><td colspan="2" align="center"><input type="submit" name="create_organization" value="Create organization"></td></tr>
47 <tr><td colspan="2" align="center"><input type="reset" name="Clear" value="Clear form"></td></tr>
48 </table>
49 <br />
50 END_HTML
53 else
55 $page->client_redirect('/solpeople/login.pl');