bug fix. Now it tests correctly if either of the tests evaluate to false or not
[sgn.git] / cgi-bin / search / route-order.pl
blob90f715afef0d4327f55ddbfa2d8416c0a07b7761
1 #!/usr/bin/perl -w
2 use strict;
3 use CXGN::Page;
4 use CXGN::DB::Connection;
5 use CXGN::Cookie;
6 # The purpose of this script is an intermediate between our final order page
7 # and the supplier's page. This is necessary so that if the user clicks send
8 # order on clone-order.pl, we can delete the items from the cookie before we
9 # send over to receiving site.
11 # Because we need to use POST, we can't accomplish this transparently with an
12 # HTML REDIRECT in the <HEAD> section.
14 # Instead we use javascript to automatically click the submit button and
15 # POST to the receiving site. Users without javascript enabled will see the
16 # intermediate page and have to click the submit button manually.
17 our ($dbh, $check_q);
18 our $page = CXGN::Page->new("Clone Shopping Cart","Koni");#cleaned up by john 23Dec2005
19 $dbh = CXGN::DB::Connection->new();
20 $check_q = $dbh->prepare("SELECT order_routing_id from clone LEFT JOIN library USING (library_id) where clone_name=?");
21 my $cart_contents = CXGN::Cookie::get_cookie("CloneCart");
22 if (!$cart_contents)
24 $page->error_page('Cannot route order because shopping cart is empty.');
25 #$cart_contents = "";
27 my %cookie_clones;
28 foreach ( split /,/,$cart_contents )
30 $cookie_clones{$_} = 1;
32 # Since we can, we always check to make sure we are doing what we are supposed
33 # to be doing. The script which POSTs to this page should specify what we are
34 # ordering, and where to route it to, so we verify that what is being ordered
35 # is supposed to be routed the given way. We don't care whether or not they
36 # are in the cookie. If they are in the cookie, they will be removed.
37 my %order_clones;
38 my ($posted_clones, $routing_id, $action) = $page->get_arguments("order_clones","route_to","route_order");
39 foreach ( split /,/,$posted_clones )
41 $check_q->execute($_);
42 my ($clone_routing_id) = $check_q->fetchrow_array();
43 if ($clone_routing_id == $routing_id)
45 $order_clones{$_} = 1;
48 # Later, we will reset the cookie to the list formed from the cookie_clones
49 # hash keys.
50 foreach ( keys %order_clones )
52 if ($cookie_clones{$_})
54 delete $cookie_clones{$_};
57 my $new_cookie = join(",",keys(%cookie_clones));
58 #i have no idea what a new cookie could be for if we are sending these cookies away to be processed,
59 #but i'm leaving this in since i don't understand it. i THINK what this MIGHT be doing is rescuing
60 #cookie clones that fail the above tests by reinserting them into the cookie. but why do we want to
61 #rescue them if they are invalid? lukas says this is because in the future we may need to add code
62 #to order these other clones that failed the above tests. --john
63 if($new_cookie)
65 CXGN::Cookie::set_cookie("CloneCart",$new_cookie);
67 else
69 CXGN::Cookie::set_cookie("CloneCart","");
71 if ($action eq "Delete Order")
73 $page->header();
74 print <<END_HTML;
75 Order deleted.
76 <script type="text/javascript">
77 <!--
78 window.opener.document.location.replace("/search/clone-order.pl");
79 window.close();
80 -->
81 </script>
82 END_HTML
83 $page->footer();
85 else
87 if ($routing_id == 1)
89 my $order_clones = join(" ",keys(%order_clones));
90 # Fei hates the "-" seperators in clone names that we use at SGN
91 $order_clones =~ s/-//g;
92 $page->header();
93 print <<END_HTML;
94 <p />
95 <table summary="" cellpadding="2" cellspacing="2" align="center" width="80%" border="0">
96 <tr><td>This page should automatically route your order to the ordering facility. If you are seeing this page, your browser may not support the javascript commands which automate the order submission. Simply click the button below in that case.</td></tr>
97 <tr><td>
98 <form name="auto-routing-form" method="post" action="http://ted.bti.cornell.edu/cgi-bin/TFGD/order/order.cgi?order_clones=$order_clones&item=clone">
99 <input type="hidden" name="clone" value="$order_clones">
100 <input type="submit" value="Submit Order">
101 </td></tr>
102 </table>
103 <script language="javascript" type="text/javascript">
104 <!--
105 // Its the second form because of the quick search form in the header
106 document.forms[1].submit();
107 window.opener.document.location.replace("/search/clone-order.pl");
109 </script>
110 END_HTML
111 $page->footer();
113 else
115 $page->error_page("Clone order sent to unknown routing id \"$routing_id\" ($!)");