Merge branch 'master' of https://github.com/solgenomics/sgn
[sgn.git] / cgi-bin / scraps / hotlist.pl
blob30bc6de4df01f85773539f3c4d53137878eb9830
1 use strict;
2 use warnings;
4 use CXGN::Scrap::AjaxPage;
5 use CXGN::DB::Connection;
6 use CXGN::UserList::Hotlist;
7 use CXGN::Login;
8 use Carp;
10 my $page = CXGN::Scrap::AjaxPage->new();
11 my $dbh = CXGN::DB::Connection->new("sgn_people");
13 my %args = $page->get_all_encoded_arguments();
15 $page->send_http_header;
16 print $page->header();
18 print "<caller>Hotlist</caller>\n";
20 # Test high-latency conditions for AJAX:
21 # system("sleep 3");
23 my $action = $args{action} or $page->throw("Action must be specified");
24 my $content_list = $args{content} or $page->throw("Content must be sent");
25 my $button_id = $args{button_id};
27 print "<content>$content_list</content>\n";
28 print "<buttonId>$button_id</buttonId>\n";
31 # if($id_check != $session_id) { die "Session ID is not valid" }
33 my $loginh = CXGN::Login->new($dbh, {NO_REDIRECT=>1});
34 my $owner = $loginh->has_session();
36 $page->throw("No session") unless ($owner);
39 my @content_list = split /::/, $content_list;
42 my $hotlist = CXGN::UserList::Hotlist->new($dbh, $owner);
44 my $old_hotlist_size = $hotlist->get_list_size();
45 print "<oldsize>$old_hotlist_size</oldsize>\n";
47 if($action eq "add"){
48 print "<action>add</action>\n";
49 $hotlist->add_items(@content_list);
51 elsif($action eq "remove"){
52 print "<action>remove</action>\n";
53 $hotlist->remove_items(@content_list);
55 else {
56 $page->throw("Invalid action sent");
59 my $new_hotlist_size = $hotlist->get_list_size();
61 print "<newsize>$new_hotlist_size</newsize>\n";
63 print $page->footer();