From 3cb7a9ac281d33fcc643e09db00bc6efca8e6490 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Fri, 20 Jun 2008 00:36:10 -0500 Subject: [PATCH] kohabug 2238 This patch allows patrons to add books to public open/free lists whether they are logged in or not. Signed-off-by: Joshua Ferraro --- C4/Auth.pm | 48 ++++++++++++------- C4/Context.pm | 14 +++--- .../opac-tmpl/prog/en/includes/masthead.inc | 4 +- .../en/modules/opac-addbybiblionumber.tmpl | 10 +++- .../prog/en/modules/opac-results.tmpl | 6 +-- .../prog/en/modules/opac-shelves.tmpl | 2 +- opac/opac-addbybiblionumber.pl | 7 ++- opac/opac-search.pl | 1 + 8 files changed, 60 insertions(+), 32 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 9311c88945..9a3480968a 100755 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -144,10 +144,13 @@ sub get_template_and_user { # user info $template->param( loggedinusername => $user ); $template->param( sessionID => $sessionID ); - my $shelves; - if ($shelves = C4::Context->get_shelves_userenv()) { - $template->param( barshelves => scalar (@$shelves)); - $template->param( barshelvesloop => $shelves); + + my ($pubshelves, $barshelves); + if (($pubshelves, $barshelves) = C4::Context->get_shelves_userenv()) { + $template->param( barshelves => scalar (@$barshelves)); + $template->param( pubshelves => scalar (@$pubshelves)); + $template->param( barshelvesloop => $barshelves); + $template->param( pubshelvesloop => $pubshelves); } $borrowernumber = getborrowernumber($user); @@ -235,11 +238,13 @@ sub get_template_and_user { $template->param( js_widgets => $in->{'js_widgets'} ); $template->param( sessionID => $sessionID ); - my $shelves; - if ($shelves = C4::Context->get_shelves_userenv()) { - $template->param( barshelves => scalar (@$shelves)); - $template->param( barshelvesloop => $shelves); + + my ($pubshelves); # an anonymous user has no 'barshelves'... + if (($pubshelves) = C4::Context->get_shelves_userenv()) { + $template->param( pubshelves => scalar (@$pubshelves)); + $template->param( pubshelvesloop => $pubshelves); } + } if ( $in->{'type'} eq "intranet" ) { @@ -491,7 +496,7 @@ sub checkauth { # state variables my $loggedin = 0; my %info; - my ( $userid, $cookie, $sessionID, $flags, $shelves ); + my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); my $logout = $query->param('logout.x'); if ( $userid = $ENV{'REMOTE_USER'} ) { @@ -515,7 +520,8 @@ sub checkauth { $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter') ); - C4::Context::set_shelves_userenv($session->param('shelves')); + C4::Context::set_shelves_userenv('bar',$session->param('barshelves')); + C4::Context::set_shelves_userenv('pub',$session->param('pubshelves')); $debug and printf STDERR "AUTH_SESSION: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; $ip = $session->param('ip'); $lasttime = $session->param('lasttime'); @@ -695,9 +701,16 @@ sub checkauth { $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter') ); - $shelves = GetShelvesSummary($borrowernumber,2,10); - $session->param('shelves', $shelves); - C4::Context::set_shelves_userenv($shelves); + + # Grab borrower's shelves and add to the session... + $barshelves = GetShelvesSummary($borrowernumber,2,10); + $session->param('barshelves', $barshelves); + C4::Context::set_shelves_userenv('bar',$barshelves); + + # Grab the public shelves and add to the session... + $pubshelves = GetShelvesSummary(0,2,10); + $session->param('pubshelves', $pubshelves); + C4::Context::set_shelves_userenv('pub',$pubshelves); } else { if ($userid) { @@ -710,9 +723,12 @@ sub checkauth { # if we are here this is an anonymous session; add public lists to it and a few other items... # anonymous sessions are created only for the OPAC $debug and warn "Initiating an anonymous session..."; - $shelves = GetShelvesSummary(0,2,10); - $session->param('shelves', $shelves); - C4::Context::set_shelves_userenv($shelves); + + # Grab the public shelves and add to the session... + $pubshelves = GetShelvesSummary(0,2,10); + $session->param('pubshelves', $pubshelves); + C4::Context::set_shelves_userenv('pub',$pubshelves); + # setting a couple of other session vars... $session->param('ip',$session->remote_addr()); $session->param('lasttime',time()); diff --git a/C4/Context.pm b/C4/Context.pm index e81fd953ed..88bd1ad61d 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -901,20 +901,22 @@ sub set_userenv{ return $cell; } -sub set_shelves_userenv ($) { - my $lists = shift or return undef; +sub set_shelves_userenv ($$) { + my ($type, $shelves) = @_ or return undef; my $activeuser = $context->{activeuser} or return undef; - $context->{userenv}->{$activeuser}->{shelves} = $lists; - # die "set_shelves_userenv: $lists"; + $context->{userenv}->{$activeuser}->{barshelves} = $shelves if $type eq 'bar'; + $context->{userenv}->{$activeuser}->{pubshelves} = $shelves if $type eq 'pub'; } + sub get_shelves_userenv () { my $active; unless ($active = $context->{userenv}->{$context->{activeuser}}) { warn "get_shelves_userenv cannot retrieve context->{userenv}->{context->{activeuser}}"; return undef; } - my $lists = $active->{shelves} or return undef;# die "get_shelves_userenv: activeenv has no ->{shelves}"; - return $lists; + my $pubshelves = $active->{pubshelves} or undef; + my $barshelves = $active->{barshelves} or undef;# die "get_shelves_userenv: activeenv has no ->{shelves}"; + return $pubshelves, $barshelves; } =item _new_userenv diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc index bc384f5801..d9d5f64378 100755 --- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc @@ -88,9 +88,9 @@