bug fix. Now it tests correctly if either of the tests evaluate to false or not
[sgn.git] / cgi-bin / scraps / set_user_prefs.pl
blob05c05ef71cc67f573ed9d15f1e0f9dbb9c620e7b
1 #!/usr/bin/perl
2 use strict;
4 use CXGN::DB::Connection;
5 use CXGN::Scrap::AjaxPage;
6 use CXGN::UserPrefs;
7 use CXGN::Login;
9 my $page = CXGN::Scrap::AjaxPage->new();
10 my $dbh = CXGN::DB::Connection->new();
12 my %args = $page->get_all_encoded_arguments();
13 $page->caller("UserPrefs");
14 $page->send_http_header();
15 print $page->header();
17 my $updated = 0;
18 my $errmsg = "";
19 my $fatalmsg = "";
21 eval {
23 my $user_prefs = $args{user_prefs};
24 my $sgn_session_id = $args{sgn_session_id};
26 my $sp_person_id = undef;
27 if($sgn_session_id){
28 $sp_person_id = CXGN::Login->new($dbh)->query_from_cookie($sgn_session_id);
30 else {
31 $sp_person_id = CXGN::Login->new($dbh)->has_session();
35 if($sp_person_id && $user_prefs){
36 my $up = CXGN::UserPrefs->new($dbh,$sp_person_id);
37 $up->set_user_pref_string($user_prefs);
38 $up->store();
39 $updated = 1;
41 else {
42 if(!$sp_person_id){
43 $errmsg .= "sp_person_id could not be resolved\n";
45 if(!$user_prefs){
46 $errmsg .= "user_prefs was found in arguments list\n";
51 if($@){
52 $fatalmsg = $@;
55 print "<updated>$updated</updated>\n";
56 if($errmsg){
57 print "<errmsg>$errmsg</errmsg>\n";
59 if($fatalmsg) {
60 print "<fatalmsg>$fatalmsg</fatalmsg>\n";
63 print $page->footer();