From 0b2aeb3b2d57f98ac7a5564e11a193649c0a6e0a Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 23 Jan 2008 21:16:18 -0600 Subject: [PATCH] Backend for "Session" Shelves in toolbar. Affects Auth and Context, so please test. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Auth.pm | 28 +++++++--- C4/Context.pm | 17 ++++++ C4/VirtualShelves.pm | 55 ++++++++++++++----- .../opac-tmpl/prog/en/includes/masthead.inc | 20 ++++++- 4 files changed, 98 insertions(+), 22 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 43ded3ea7d..d5b14d7e0d 100755 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -31,12 +31,13 @@ use C4::Output; # to get the template use C4::Members; use C4::Koha; use C4::Branch; # GetBranches +use C4::VirtualShelves 3.02 qw(GetShelvesSummary); # use utf8; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap); BEGIN { - $VERSION = 3.01; # set version for version checking + $VERSION = 3.02; # set version for version checking $debug = $ENV{DEBUG} || 0 ; @ISA = qw(Exporter); @EXPORT = qw(&checkauth &get_template_and_user); @@ -145,6 +146,11 @@ 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); + } $borrowernumber = getborrowernumber($user); my ( $borr, $alternativeflags ) = @@ -316,6 +322,7 @@ sub get_template_and_user { 'item-level_itypes' => C4::Context->preference('item-level_itypes'), ); } + $template->param(listloop=>[{shelfname=>"Freelist", shelfnumber=>110}]); return ( $template, $borrowernumber, $cookie, $flags); } @@ -427,7 +434,7 @@ sub _session_log { sub checkauth { my $query = shift; - # warn "Checking Auth"; + $debug and warn "Checking Auth"; # $authnotrequired will be set for scripts which will run without authentication my $authnotrequired = shift; my $flagsrequired = shift; @@ -446,7 +453,7 @@ sub checkauth { # state variables my $loggedin = 0; my %info; - my ( $userid, $cookie, $sessionID, $flags ); + my ( $userid, $cookie, $sessionID, $flags, $shelves ); my $logout = $query->param('logout.x'); if ( $userid = $ENV{'REMOTE_USER'} ) { # Using Basic Authentication, no cookies required @@ -469,6 +476,7 @@ sub checkauth { $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter') ); + C4::Context::set_shelves_userenv($session->param('shelves')); $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'); @@ -532,11 +540,11 @@ sub checkauth { $info{'nopermission'} = 1; C4::Context->_unset_userenv($sessionID); } + + my ($borrowernumber, $firstname, $surname, $userflags, + $branchcode, $branchname, $branchprinter, $emailaddress); + if ( $return == 1 ) { - my ( - $borrowernumber, $firstname, $surname, $userflags, - $branchcode, $branchname, $branchprinter, $emailaddress - ); my $select = " SELECT borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname, @@ -610,10 +618,11 @@ sub checkauth { $session->param('emailaddress',$emailaddress); $session->param('ip',$session->remote_addr()); $session->param('lasttime',time()); - $debug and printf STDERR "AUTH_3: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; + $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; } elsif ( $return == 2 ) { #We suppose the user is the superlibrarian + $borrowernumber = 0; $session->param('number',0); $session->param('id',C4::Context->config('user')); $session->param('cardnumber',C4::Context->config('user')); @@ -633,6 +642,9 @@ 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); } else { if ($userid) { diff --git a/C4/Context.pm b/C4/Context.pm index ca7316b07d..361b6dc0bb 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -295,6 +295,7 @@ sub new { $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield $self->{"userenv"} = undef; # User env $self->{"activeuser"} = undef; # current active user + $self->{"shelves"} = undef; bless $self, $class; return $self; @@ -874,6 +875,22 @@ sub set_userenv{ return $cell; } +sub set_shelves_userenv ($) { + my $lists = shift or return undef; + my $activeuser = $context->{activeuser} or return undef; + $context->{userenv}->{$activeuser}->{shelves} = $lists; + # die "set_shelves_userenv: $lists"; +} +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; +} + =item _new_userenv C4::Context->_new_userenv($session); diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 1af3603d9c..f075c6fdb9 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -25,11 +25,11 @@ use strict; use Carp; use C4::Context; use C4::Circulation; -use vars qw($VERSION @ISA @EXPORT); +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); BEGIN { # set the version for version checking - $VERSION = 3.01; + $VERSION = 3.02; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( @@ -41,6 +41,7 @@ BEGIN { &ShelfPossibleAction &DelFromShelf &DelShelf ); + @EXPORT_OK = qw(&GetShelvesSummary); } my $dbh = C4::Context->dbh; @@ -65,7 +66,9 @@ items to and from virtualshelves. =item GetShelves + $shelflist = &GetShelves($owner); $shelflist = &GetShelves($owner, $mincategory); + $shelflist = &GetShelves($owner, $mincategory, $limit); ($shelfnumber, $shelfhash) = each %{$shelflist}; Looks up the virtual virtualshelves, and returns a summary. C<$shelflist> @@ -73,7 +76,7 @@ is a reference-to-hash. The keys are the virtualshelves numbers (C<$shelfnumber>, above), and the values (C<$shelfhash>, above) are themselves references-to-hash, with the following keys: -C : 2 if the list is for "look". 3 if the list is for "Select virtualshelves for adding a virtual". +C : 2 if the list is for "Public", 3 for "Open". virtualshelves of the owner are always selected, whatever the category =over 4 @@ -90,14 +93,10 @@ The number of virtuals on that virtualshelves. =cut -#' -# FIXME - Wouldn't it be more intuitive to return a list, rather than -# a reference-to-hash? The shelf number can be just another key in the -# hash. - sub GetShelves { - my ( $owner, $mincategory ) = @_; - + my ($owner, $mincategory, $limit) = @_; + ($mincategory and $mincategory =~ /^\d+$/) or $mincategory = 2; + ( $limit and $limit =~ /^\d+$/) or $limit = undef; my $query = qq( SELECT virtualshelves.shelfnumber, virtualshelves.shelfname,owner,surname,firstname,virtualshelves.category,virtualshelves.sortfield, count(virtualshelfcontents.biblionumber) as count @@ -108,6 +107,7 @@ sub GetShelves { GROUP BY virtualshelves.shelfnumber ORDER BY virtualshelves.category, virtualshelves.shelfname, borrowers.firstname, borrowers.surname ); + $limit and $query .= " LIMIT $limit "; my $sth = $dbh->prepare($query); $sth->execute( $owner, $mincategory ); my %shelflist; @@ -121,15 +121,44 @@ sub GetShelves { { $shelflist{$shelfnumber}->{'shelfname'} = $shelfname; $shelflist{$shelfnumber}->{'count'} = $count; - $shelflist{$shelfnumber}->{'sortfield'} = $sortfield; + $shelflist{$shelfnumber}->{'sortfield'} = $sortfield; $shelflist{$shelfnumber}->{'category'} = $category; $shelflist{$shelfnumber}->{'owner'} = $owner; - $shelflist{$shelfnumber}->{'surname'} = $surname; - $shelflist{$shelfnumber}->{'firstname'} = $firstname; + $shelflist{$shelfnumber}->{'surname'} = $surname; + $shelflist{$shelfnumber}->{'firstname'} = $firstname; } return ( \%shelflist ); } +sub GetShelvesSummary { + my ($owner, $mincategory, $limit) = @_; + ($mincategory and $mincategory =~ /^\d+$/) or $mincategory = 2; + ( $limit and $limit =~ /^\d+$/) or $limit = 10; + my $query = qq( + SELECT + virtualshelves.shelfnumber, + virtualshelves.shelfname, + owner, + CONCAT(firstname, ' ', surname) AS name, + virtualshelves.category, + count(virtualshelfcontents.biblionumber) AS count + FROM virtualshelves + LEFT JOIN virtualshelfcontents ON virtualshelves.shelfnumber = virtualshelfcontents.shelfnumber + LEFT JOIN borrowers ON virtualshelves.owner = borrowers.borrowernumber + WHERE owner=? OR category>=? + GROUP BY virtualshelves.shelfnumber + ORDER BY virtualshelves.category, borrowers.surname, borrowers.firstname, virtualshelves.shelfname + LIMIT ? + ); + my $sth = $dbh->prepare($query); + $sth->execute($owner,$mincategory,$limit); + return $sth->fetchall_arrayref({}); + # Probably NOT the final implementation since it is still bulky (repeated hash keys). + # might like an array of rows of delimited values: + # 1|2||0|blacklist|112 + # 2|6|Josh Ferraro|51|en_fuego|106 +} + =item GetShelf (shelfnumber,shelfname,owner,category) = &GetShelf($shelfnumber); diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc index f6365b877a..d8432a9b8b 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc @@ -9,7 +9,25 @@
-- 2.39.5