upload fieldbook from manage phenotyping
[sgn.git] / cgi-bin / search / clone-order.pl
blob2b39f47bd210a055cc8a2dae05bf90ea9c8413a7
1 #!/usr/bin/perl -w
2 use strict;
3 use CXGN::Page;
4 use CXGN::DB::Connection;
5 use CXGN::Cookie;
6 my $dbh = CXGN::DB::Connection->new();
7 my $check_q = $dbh->prepare("SELECT order_routing_id from clone LEFT JOIN library USING (library_id) where clone_name=?");
9 our $page = CXGN::Page->new("Clone Shopping Cart", "Koni");
11 my ($clone_add) = $page->get_arguments("add_clone");
13 my $cart_contents = CXGN::Cookie::get_cookie("CloneCart");
15 if (!$cart_contents) {
16 $cart_contents = "";
19 my @clones = split /,/,$cart_contents;
20 if ($clone_add) {
21 push @clones, $clone_add;
24 # Note: An advantage of server-side statefulness here is not repeating this
25 # everytime. This is typical of stateful/stateless tradeoff -- storing
26 # state provides performance gains but at the expense of correctness and
27 # increased complexity.
29 # Future versions of this ordering thing may require server side state
30 # due to the limitations of cookie size at the client.
31 my %ok_clones = ();
32 my %orders = ();
33 foreach my $clone_id ( @clones )
35 $check_q->execute($clone_id);
36 if ($check_q->rows()>0) {
37 my ($order_routing_id) = $check_q->fetchrow_array();
38 if (!$ok_clones{$clone_id}) {
39 push @{$orders{$order_routing_id}}, $clone_id;
40 $ok_clones{$clone_id} = 1;
45 # If we have valid clones, set the cookie.
46 if (keys(%ok_clones) > 0) {
47 CXGN::Cookie::set_cookie("CloneCart",join(",",keys(%ok_clones)));
48 } else {
49 CXGN::Cookie::set_cookie("CloneCart","");
50 empty_cart();
53 if ($clone_add) {
54 $page->client_redirect("/search/clone-order.pl");
55 exit(0);
58 my @order_text = ();
59 foreach my $routing_id ( keys %orders ) {
60 if ($routing_id == 1) { # TED
61 push @order_text, ted_order_routing($orders{$routing_id});
63 elsif ($routing_id == 2) { # Kazusa
64 push @order_text, kazusa_order_routing($orders{$routing_id});
65 } else {
66 $page->error_page("Clone ordered but order routing function for \"$routing_id\" is not available");
71 sub ted_order_routing {
72 my ($clone_listref) = @_;
73 my $clone_order = join(",",@{$clone_listref});
74 my $text = <<EOF;
75 <form method="post" action="/search/route-order.pl" target="_BLANK">
76 <input type="hidden" name="route_to" value="1" />
77 <input type="hidden" name="order_clones" value="$clone_order" />
78 <table summary="" cellpadding="2" cellspacing="2" border="0" align="center" width="100%">
79 <tr><td style="background-color: CCCCFF;" align="center">The following selected clones are available through <b>TED</b></td></tr>
80 EOF
81 foreach (@{$clone_listref}) {
82 $text .= "<tr><td>$_</td></tr>";
85 $text .= <<EOF;
86 <tr><td style="background-color: CCCCFF;" align="center">
87 <input type="submit" name="route_order" value="Route Order" />&nbsp;&nbsp;<input type="submit" name="route_order" value="Delete Order" />
88 </td></tr></table></form>
89 EOF
91 return $text;
94 sub kazusa_order_routing {
95 my ($clone_listref) = @_;
96 my $clone_order = join(",", @{$clone_listref});
97 my $clone_order_text = "Dear Kazusa, %0AI would like to order the following clones:%0A$clone_order%0A";
98 my $text = <<EOF;
99 <form method="post" action="/search/route-order.pl" target="_BLANK">
100 <input type="hidden" name="route_to" value="1" />
101 <input type="hidden" name="order_clones" value="$clone_order" />
102 <table summary="" cellpadding="2" cellspacing="2" border="0" align="center" width="100%">
103 <tr><td style="background-color: CCCCFF;" align="center">The following selected clones are available through <b>Kazusa</b></td></tr>
105 foreach (@{$clone_listref}) {
106 $text .= "<tr><td>$_</td></tr>";
109 $text .= <<EOF;
110 <tr><td style="background-color: CCCCFF;" align="center">
111 <a href="mailto:plantinfo\@kazusa.or.jp?subject=clone order&amp;body=$clone_order_text"><b>ORDER CLONES (email)</b></a>&nbsp;&nbsp;<input type="submit" name="route_order" value="Delete Order" /><br /><br />
112 <a href="http://www.kazusa.or.jp/clonereq/">Kazusa Clone request page</a> | <a href="http://www.kazusa.or.jp/clonereq/agreement.html">Kazusa Material Transfer Agreement</a>
113 </td></tr></table></form>
116 return $text;
119 $page->header();
121 print <<EOF;
123 <table summary="" width="80%" align="center" cellspacing="2" cellpadding="2" border="0">
124 <tr><td>
125 <p>SGN can compile a list of clones to order and then route the orders to appropriate people or facilities for you when you are finished selecting clones. To continue selecting clones, use your browser's back button or start a <a href="/search/direct_search.pl">new search</a></p>
126 </td></tr>
127 <tr><td align="center"><b>Shopping Cart Contents</b></td></tr>
128 <tr><td>
129 <p />
130 @order_text
131 </td></tr>
132 <tr><td>
134 <b>Please Note:</b> SGN does not handle clone orders directly. Selected clones will be routed online to the appropriate parties using the submit buttons above. Your browser <b>must support cookies</b> for this to work properly. Please use your browser's back button to select additional clones, or start a new search using the links above.
135 </p>
136 </td></tr>
137 </table>
140 $page->footer();
142 sub empty_cart {
144 $page->header();
146 print <<EOF;
148 <table summary="" border="0" width="80%" align="center">
149 <tr><td align="center"><p>There are no cDNA clones in your shopping cart.</td></tr>
150 <tr><td align="center"><p>Please note that your browser must accept cookies to order clones through SGN.</p>
151 <br /></td></tr>
152 </table>
156 $page->footer();
158 exit 0;