6 use CXGN
::Page
::FormattingHelpers qw
/ blue_section_html page_title_html /;
7 use CXGN
::Insitu
::Image
;
8 use CXGN
::Insitu
::Experiment
;
11 # legal parameters are:
13 # image_id: a valid image_id
14 # experiment_id: a valid experiment_id
15 # upload_file: the file to be uploaded, if action=upload.
19 # here we need to use the Apache2::Request methods for getting
20 # the parameters because uploading a file will cause the
21 # page object not to receive any of the parameters.
24 $args{image_id
} = $cgi->param("image_id");
25 $args{experiment_id
} = $cgi->param("experiment_id");
26 $args{action
}=$cgi->param("action");
27 $args{upload_file
}=$cgi->param("upload_file");
29 # now that we got everthing safely, let's initiate the page object
31 my $page = CXGN
::Page
->new();
35 my $dbh = CXGN
::DB
::Connection
->new("insitu");
37 # set the default action if none was supplied
39 if (!exists($args{action
}) || !defined($args{action
})) {
43 # get the user_id if user is logged in for actions add and upload.
47 if ($args{action
} =~/new|upload/i ) {
48 $user = CXGN
::People
::Person
->new(CXGN
::Login
->new()->verify_session());
49 $user_id= $user->get_sp_person_id();
50 if ($user->get_user_type() !~ /curator|submitter/) {
51 $page->message_page("You do not have sufficient privileges to upload images. You need an account of type 'submitter'. Please contact SGN to change your account type. Sorry.");
55 if (!exists($args{experiment_id
}) || !defined($args{experiment_id
})) {
56 my $page = CXGN
::Page
->new();
58 $page->error_page("Need an experiment_id to add image.");
61 # create an new image object and go through the different
62 # possible actions. Emit error pages if needed.
64 my $image = CXGN
::Insitu
::Image
->new($dbh);
65 $image -> set_experiment_id
($args{experiment_id
});
66 $image -> set_user_id
($user_id);
68 if ($args{action
} eq "new") {
69 add_dialog
($image, %args);
72 elsif ($args{action
} eq "upload") {
73 upload
($dbh, $cgi, $image, %args);
76 my $page = CXGN
::Page
->new();
77 $page->error_page("No recognized action defined.");
86 # deal with the upload options
88 # TODO fix this upload
89 my $upload = $cgi->upload();
92 my $experiment = CXGN
::Insitu
::Experiment
->new($dbh, $image->get_experiment_id());
93 #print STDERR "Uploading file $args{upload_file}...\n";
94 if (defined $upload) {
95 $upload_fh = $upload->fh();
96 $image->upload_image($experiment, $args{upload_file
}, $upload_fh);
97 $image->process_image($args{upload_file
}, $experiment);
98 my $experiment_id = $image->get_experiment_id();
99 my $page = CXGN
::Page
->new();
101 print "The following file was uploaded: <br />";
103 print $image->get_img_src_tag();
105 print qq { <br
/><br />Return to
<a href
="experiment.pl?experiment_id=$experiment_id">experiment
</a
> };
115 my $page = CXGN
::Page
->new();
116 $page->error_page("A freakin error occurred!");
126 my $page = CXGN
::Page
->new();
127 my $experiment_id = $image->get_experiment_id();
128 my $experiment = CXGN
::Insitu
::Experiment
->new($image->get_dbh(),$experiment_id);
129 my $experiment_name = $experiment->get_name();
133 page_title_html
("<a href=\"/insitu\">Insitu</a> Add Image" );
135 foreach my $k (keys %args) {
136 #print "$k, $args{$k}<br />\n";
140 <form action
="add_image.pl" method
="post" enctype
="multipart/form-data" >
141 Upload an image
for experiment
"$experiment_name":
142 [<a href
="experiment.pl?experiment_id=$experiment_id&action=edit">Cancel
</a>]<br /><br
/>
144 <input type
="file" name
="upload_file" value
="Choose image file" />
145 <input type
="hidden" name
="action" value
="upload" />
146 <input type
="hidden" name
="experiment_id" value
="$experiment_id" />
147 <input type
="submit" value
="Upload" />