4 use CXGN
::DB
::Connection
;
8 use CXGN
::DB
::Connection
;
10 my $page = CXGN
::Page
->new("Make Attributions", "Lukas and John");
11 our $dbh = CXGN
::DB
::Connection
-> new
("sgn_people");
13 my($action, $data_type, $data_id, $attributed_to_id, $attributed_to_type, $role_id)=$page->get_encoded_arguments('action', 'data_type', 'data_id','attributed_to_id', 'attributed_to_type', 'role_id');
15 my $logged_in_person_id=CXGN
::Login
->new($dbh)->verify_session();
16 my $logged_in_user=CXGN
::People
::Person
->new($dbh, $logged_in_person_id);
17 my $logged_in_person_id=$logged_in_user->get_sp_person_id();
18 my $logged_in_username=$logged_in_user->get_first_name()." ".$logged_in_user->get_last_name();
19 my $logged_in_user_type=$logged_in_user->get_user_type();
21 if($logged_in_user_type ne 'curator') {
22 $page->message_page("You don't have the necessary privileges to perform this action! ");
28 if ($action eq "verify") { verify
( $data_type, $data_id, $attributed_to_id, $attributed_to_type, $role_id); }
29 elsif ($action eq "store" ) { store
( $data_type, $data_id, $attributed_to_id, $attributed_to_type, $role_id); }
36 my $schema = $dbh->qualify_schema("metadata");
38 my $q = "SELECT $schema.roles.role_id, $schema.roles.role_name FROM $schema.roles";
39 my $sth = $dbh->prepare($q);
43 while (my ($role_id, $role) = $sth->fetchrow_array()) {
45 push @role_ids, $role_id;
48 my $role_select = "<select name=\"role_id\" >";
49 for (my $i=0; $i<@roles; $i++) {
50 $role_select .= qq { <option value
="$role_ids[$i]">$roles[$i]</option
> };
52 $role_select .= "</select>";
61 <select name="data_type">
62 <option value="bac">BAC</option>
63 <option value="marker">Marker</option>
67 <td> <input name="data_id" /></td>
77 <td>Attribution to</td>
79 <select name="attributed_to_type">
80 <option value="person">Person</option>
81 <option value="organization">Organization</option>
82 <option value="project">Project</option>
86 <td> <input name="attributed_to_id" /></td>
91 <input type="hidden" name="action" value="verify" />
92 <input type="submit" value="Submit" />
103 my ($data_type, $data_id, $attributed_to_id, $attributed_to_type, $role_id) = @_;
106 if (!$attributed_to_type || !$attributed_to_id || !$data_type || !$data_id) {
107 $page->message_page("Need all data filled in!");
110 my $attributed_name = "";
111 if ($attributed_to_type eq "person") {
113 my $p = CXGN
::People
::Person
->new_person($dbh, $attributed_to_id);
114 $attributed_name = $p->get_first_name()." ".$p->get_last_name();
116 elsif ($attributed_to_type eq "organization") {
117 my $p = CXGN
::People
::Organization
->new($dbh, $attributed_to_id);
118 $attributed_name = $p->get_name();
120 elsif ($attributed_to_type eq "project") {
121 my $p = CXGN
::People
::Project
->new($dbh, $attributed_to_id);
122 $attributed_name = $p->get_name();
126 if ($data_type eq "bac") {
127 my $schema = $dbh->qualify_schema("genomic");
128 $q = "SELECT * FROM $schema.clone WHERE $schema.clone.clone_id=?";
130 if ($data_type eq "marker") {
131 my $schema = $dbh->qualify_schema("sgn");
132 $q = "SELECT * FROM $schema.markers WHERE $schema.markers.marker_id=?";
134 my $sth = $dbh->prepare($q);
135 $sth->execute($data_id);
136 my ($hashref) = $sth->fetchrow_hashref();
138 print qq { <div
class="boxbgcolor2"><b
>Database object
</b><br /><br
/> };
139 foreach my $k (keys %$hashref) {
140 print "$k: $$hashref{$k}<br />\n" if (exists $$hashref{$k});
142 print "<br /></div><br />Attribute to : <br />";
143 print "<b>$attributed_name</b><br /><br />";
147 <input type="hidden" name="role_id" value="$role_id" />
148 <input type="hidden" name="attributed_to_id" value="$attributed_to_id" />
149 <input type="hidden" name="attributed_to_type" value="$attributed_to_type" />
150 <input type="hidden" name="data_type" value="$data_type" />
151 <input type="hidden" name="data_id" value="$data_id" />
152 <input type="hidden" name="action" value="store" />
154 <input type="submit" value="Store" />
163 my ($data_type, $data_id, $attributed_to_id, $attributed_to_type, $role_id) = @_;
165 my $database_name="";
168 if ($data_type eq "bac") {
169 $database_name="genomic";
172 elsif ($data_type eq "marker") {
173 $database_name="sgn";
174 $table_name="markers";
177 my $organization_id=undef;
178 my $project_id=undef;
180 if ($attributed_to_type eq "person") {
181 $person_id = $attributed_to_id;
183 elsif ($attributed_to_type eq "organization") {
184 $organization_id = $attributed_to_id;
186 elsif ($attributed_to_type eq "project") {
187 $project_id=$attributed_to_id;
190 my $q = "SELECT attribution_id from metadata.attribution WHERE database_name=? AND table_name=? AND row_id=?";
191 my $sth = $dbh->prepare($q);
192 $sth->execute($database_name,$table_name, $data_id);
193 my $attribution_id="";
194 if ($attribution_id = ($sth->fetchrow_array())[0]) {
195 print "The attribution is already in the database.\n";
199 my $iq = "INSERT INTO metadata.attribution (database_name, table_name, row_id) VALUES (?, ?, ?)";
201 my $sth = $dbh->prepare($iq);
202 $sth->execute($database_name, $table_name, $data_id);
203 $attribution_id = $dbh->last_insert_id("attribution", "metadata");
206 my $q2 = "SELECT attribution_to_id FROM metadata.attribution_to WHERE
207 person_id=? AND organization_id =? AND project_id=?";
209 my $sth2 = $dbh->prepare($q2);
210 $sth2->execute($person_id, $organization_id, $project_id);
212 my ($attributed_to_id) = ($sth2->fetchrow_array())[0];
214 if (!$attributed_to_id) {
215 my $iq2="INSERT INTO metadata.attribution_to (attribution_id, person_id, organiztion_id, project_id, role_id) VALUES (?, ?, ?, ?, ?)";
218 my $isth = $dbh->prepare($iq2);
219 $isth -> execute
($attribution_id, $person_id, $organization_id, $project_id, $role_id);
222 print "The data object was already attributed to that entity in the database.";