From 9971756a24e70101b2fb92833afab974d57ac4b9 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Wed, 25 Jun 2008 23:18:07 -0500 Subject: [PATCH] kohabug 2159 Improving "Lists" button list refreshes after adding/changing lists/shelves Adding code to refresh "Lists" button lists display in OPAC masthead.inc Adding javascript to force refresh of parent window to update "Lists" button menu Adding query limits and ability to specify row count and offset in queries related to Virtualshelves. Also added the ability to return total record counts for specified virtualshelves. Adding C4::VirtualShelves::GetRecentShelves which returns a list of the most recently modified shelves for a given set of parameters. This allows the user to be offered active private and open lists to add books to in drop down menus while also allowing drop down menus to be limited to a reasonable length. This also limits the shelves stored in the user's session to a fixed number. A further enhancement might be to add a syspref to enable a staff member to define the limit. Currently it is hardcoded at 10 per list type (private/public-open). Adding pagination to list/shelf related screens Moving refresh shelves code into C4::VirtualShelves::RefreshShelvesSummary and tidying up a bit Correcting several inconsistancies in the shelves templates as well as handling shelf management on the intranet side correctly. Correcting "Add To:" drop-down list to show only lists the patron has permission to add to Correcting a few C4::VirtualShelves::GetShelvesSummary API calls Modifications for template consistancy Breaking up a 1367 char line of javascript in opac-results.tmpl Signed-off-by: Galen Charlton Signed-off-by: Joshua Ferraro --- C4/Auth.pm | 61 +++-- C4/Context.pm | 6 +- C4/VirtualShelves.pm | 245 +++++++++++++----- C4/VirtualShelves/Page.pm | 95 +++++-- .../en/includes/virtualshelves-toolbar.inc | 2 +- .../en/modules/virtualshelves/shelves.tmpl | 163 +++++++++--- .../opac-tmpl/prog/en/includes/masthead.inc | 17 +- .../en/modules/opac-addbybiblionumber.tmpl | 103 ++++---- .../prog/en/modules/opac-results.tmpl | 4 +- .../prog/en/modules/opac-shelves.tmpl | 17 +- opac/opac-addbybiblionumber.pl | 47 ++-- opac/opac-search.pl | 23 +- virtualshelves/addbybiblionumber.pl | 75 ++---- 13 files changed, 566 insertions(+), 292 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 8ccaf61781..98c151e256 100755 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -31,7 +31,7 @@ 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 C4::VirtualShelves; # use utf8; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap); @@ -145,14 +145,18 @@ sub get_template_and_user { $template->param( loggedinusername => $user ); $template->param( sessionID => $sessionID ); - my ($pubshelves, $barshelves) = C4::Context->get_shelves_userenv(); + my ($total, $pubshelves, $barshelves) = C4::Context->get_shelves_userenv(); if (defined($pubshelves)) { - $template->param( pubshelves => scalar (@$pubshelves)); - $template->param( pubshelvesloop => $pubshelves); + $template->param( pubshelves => scalar (@$pubshelves), + pubshelvesloop => $pubshelves, + ); + $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar (@$pubshelves)); } if (defined($barshelves)) { - $template->param( barshelves => scalar (@$barshelves)); - $template->param( barshelvesloop => $barshelves); + $template->param( barshelves => scalar (@$barshelves), + barshelvesloop => $barshelves, + ); + $template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar (@$barshelves)); } $borrowernumber = getborrowernumber($user); @@ -240,10 +244,12 @@ sub get_template_and_user { $template->param( sessionID => $sessionID ); - my ($pubshelves) = C4::Context->get_shelves_userenv(); # an anonymous user has no 'barshelves'... + my ($total, $pubshelves) = C4::Context->get_shelves_userenv(); # an anonymous user has no 'barshelves'... if (defined(($pubshelves))) { - $template->param( pubshelves => scalar (@$pubshelves)); - $template->param( pubshelvesloop => $pubshelves); + $template->param( pubshelves => scalar (@$pubshelves), + pubshelvesloop => $pubshelves, + ); + $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar (@$pubshelves)); } } @@ -519,6 +525,7 @@ sub checkauth { ); C4::Context::set_shelves_userenv('bar',$session->param('barshelves')); C4::Context::set_shelves_userenv('pub',$session->param('pubshelves')); + C4::Context::set_shelves_userenv('tot',$session->param('totshelves')); $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'); @@ -699,15 +706,22 @@ sub checkauth { $session->param('emailaddress'), $session->param('branchprinter') ); - # 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); + # Grab borrower's shelves and public shelves and add them to the session + # $row_count determines how many records are returned from the db query + # and the number of lists to be displayed of each type in the 'Lists' button drop down + my $row_count = 10; # FIXME:This probably should be a syspref + my ($total, $totshelves, $barshelves, $pubshelves); + ($barshelves, $totshelves) = GetRecentShelves(1, $row_count, $borrowernumber); + $total->{'bartotal'} = $totshelves; + ($pubshelves, $totshelves) = GetRecentShelves(2, $row_count, undef); + $total->{'pubtotal'} = $totshelves; + $session->param('barshelves', ${@$barshelves}[0]); + $session->param('pubshelves', ${@$pubshelves}[0]); + $session->param('totshelves', $total); + + C4::Context::set_shelves_userenv('bar',${@$barshelves}[0]); + C4::Context::set_shelves_userenv('pub',${@$pubshelves}[0]); + C4::Context::set_shelves_userenv('tot',$total); } else { if ($userid) { @@ -722,9 +736,14 @@ sub checkauth { $debug and warn "Initiating an anonymous session..."; # 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); + my $row_count = 20; # FIXME:This probably should be a syspref + my ($total, $totshelves, $pubshelves); + ($pubshelves, $totshelves) = GetRecentShelves(2, $row_count, undef); + $total->{'pubtotal'} = $totshelves; + $session->param('pubshelves', ${@$pubshelves}[0]); + $session->param('pubtotal', $total->{'pubtotal'}); + C4::Context::set_shelves_userenv('pub',${@$pubshelves}[0]); + C4::Context::set_shelves_userenv('tot',$total); # setting a couple of other session vars... $session->param('ip',$session->remote_addr()); diff --git a/C4/Context.pm b/C4/Context.pm index 20e5794bcc..efd344ff07 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -913,6 +913,7 @@ sub set_shelves_userenv ($$) { my $activeuser = $context->{activeuser} or return undef; $context->{userenv}->{$activeuser}->{barshelves} = $shelves if $type eq 'bar'; $context->{userenv}->{$activeuser}->{pubshelves} = $shelves if $type eq 'pub'; + $context->{userenv}->{$activeuser}->{totshelves} = $shelves if $type eq 'tot'; } sub get_shelves_userenv () { @@ -921,9 +922,10 @@ sub get_shelves_userenv () { $debug and warn "get_shelves_userenv cannot retrieve context->{userenv}->{context->{activeuser}}"; return undef; } + my $totshelves = $active->{totshelves} or undef; my $pubshelves = $active->{pubshelves} or undef; - my $barshelves = $active->{barshelves} or undef;# die "get_shelves_userenv: activeenv has no ->{shelves}"; - return $pubshelves, $barshelves; + my $barshelves = $active->{barshelves} or undef; + return ($totshelves, $pubshelves, $barshelves); } =item _new_userenv diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index e5c8adc93f..fbb100df53 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -37,16 +37,21 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &GetShelves &GetShelfContents &GetShelf + &GetRecentShelves &GetShelvesSummary &AddToShelf &AddToShelfFromBiblio &AddShelf + &SetShelvesLimit + &RefreshShelvesSummary + &ModShelf &ShelfPossibleAction &DelFromShelf &DelShelf ); - @EXPORT_OK = qw(&GetShelvesSummary); } +use C4::Auth qw(get_session); + my $dbh = C4::Context->dbh; =head1 NAME @@ -69,18 +74,15 @@ items to and from virtualshelves. =item GetShelves - $shelflist = &GetShelves($owner); - $shelflist = &GetShelves($owner, $mincategory); - $shelflist = &GetShelves($owner, $mincategory, $limit); + ($shelflist, $totshelves) = &GetShelves($mincategory, $row_count, $offset, $owner); ($shelfnumber, $shelfhash) = each %{$shelflist}; -Looks up the virtual virtualshelves, and returns a summary. C<$shelflist> -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 "Public", 3 for "Open". -virtualshelves of the owner are always selected, whatever the category +Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total +number of shelves that meet the C<$owner> and C<$mincategory> criteria. C<$mincategory>, +C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$mincategory> == 1. +When C<$mincategory> is 2 or 3, supply undef as argument for C<$owner>. +C<$shelflist>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: =over 4 @@ -96,32 +98,33 @@ The number of virtuals on that virtualshelves. =cut -sub GetShelves { - my ($owner, $mincategory, $limit) = @_; - ($mincategory and $mincategory =~ /^\d+$/) or $mincategory = 2; - ( $limit and $limit =~ /^\d+$/) or $limit = undef; +sub GetShelves ($$$$) { + my ($mincategory, $row_count, $offset, $owner) = @_; + my @params = ($owner, $mincategory, ($offset ? $offset : 0), $row_count); + my @params1 = ($owner, $mincategory); + if ($mincategory > 1) { + shift @params; + shift @params1; + } + my $total = _shelf_count($owner, $mincategory); + # grab only the shelves meeting the row_count/offset spec... my $query = qq( SELECT virtualshelves.shelfnumber, virtualshelves.shelfname,owner,surname,firstname,virtualshelves.category,virtualshelves.sortfield, 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>=? + LEFT JOIN borrowers ON virtualshelves.owner = borrowers.borrowernumber ); + $query .= ($mincategory == 1) ? "WHERE owner=? AND category=?" : "WHERE category>=?"; + $query .= qq( 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 ); + ORDER BY virtualshelves.category + DESC + LIMIT ?, ?); + my $sth2 = $dbh->prepare($query); + $sth2->execute(@params); my %shelflist; - while ( - my ( - $shelfnumber, $shelfname, $owner, $surname, - $firstname, $category, $sortfield, $count - ) - = $sth->fetchrow - ) - { + while ( my ( $shelfnumber, $shelfname, $owner, $surname, + $firstname, $category, $sortfield, $count ) = $sth2->fetchrow ) { $shelflist{$shelfnumber}->{'shelfname'} = $shelfname; $shelflist{$shelfnumber}->{'count'} = $count; $shelflist{$shelfnumber}->{'sortfield'} = $sortfield; @@ -130,14 +133,31 @@ sub GetShelves { $shelflist{$shelfnumber}->{'surname'} = $surname; $shelflist{$shelfnumber}->{'firstname'} = $firstname; } - return ( \%shelflist ); + return ( \%shelflist, $total ); } -sub GetShelvesSummary { - my ($owner, $mincategory, $limit) = @_; - ($mincategory and $mincategory =~ /^\d+$/) or $mincategory = 2; - ( $limit and $limit =~ /^\d+$/) or $limit = 10; - my $query = qq( +=item GetShelvesSummary + + ($shelves, $total) = GetShelvesSummary($mincategory, $row_count, $offset, $owner) + +Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total +number of shelves that meet the C<$owner> and/or C<$mincategory> criteria. C<$mincategory>, +C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$mincategory> == 1. +When C<$mincategory> is 2 or 3, supply undef as argument for C<$owner>. + +=cut + +sub GetShelvesSummary ($$$$) { + my ($mincategory, $row_count, $offset, $owner) = @_; + my @params = ($owner, $mincategory, ($offset ? $offset : 0), $row_count); + my @params1 = ($owner, $mincategory); + if ($mincategory > 1) { + shift @params; + shift @params1; + } + my $total = _shelf_count($owner, $mincategory); + # grab only the shelves meeting the row_count/offset spec... + my $query = qq( SELECT virtualshelves.shelfnumber, virtualshelves.shelfname, @@ -147,25 +167,17 @@ sub GetShelvesSummary { 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>=? + LEFT JOIN borrowers ON virtualshelves.owner = borrowers.borrowernumber ); + $query .= ($mincategory == 1) ? "WHERE owner=? AND category=?" : "WHERE category>=?"; + $query .= qq( 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); - - my $shelves = $sth->fetchall_arrayref({}); - # add private flag to each shelf entry -- - # need to do this because HTML::Template::Pro's EXPR - # support complains about a non-initialized 'category' - # if the user has no shelves -- the offending line in - # masthead.inc was <-- TMPL_IF EXPR="category == 1"... - foreach my $shelf (@{ $shelves }) { - $shelf->{'private'} = ($shelf->{'category'} == 1); - } - return $shelves; + ORDER BY virtualshelves.category + DESC + LIMIT ?, ?); + my $sth2 = $dbh->prepare($query); + $sth2->execute(@params); + my $shelves = $sth2->fetchall_arrayref({}); + return ($shelves, $total); # Probably NOT the final implementation since it is still bulky (repeated hash keys). # might like an array of rows of delimited values: @@ -173,6 +185,34 @@ sub GetShelvesSummary { # 2|6|Josh Ferraro|51|en_fuego|106 } +=item GetRecentShelves + + ($shelflist) = GetRecentShelves(1, $limit, $owner) + +This function returns a references to an array of hashrefs containing specified shelves sorted +by the date the shelf was last modified in descending order limited to the number of records +specified by C<$row_count>. If calling with C<$mincategory> other than 1, use undef as C<$owner>. + +This function is intended to return a dataset reflecting the most recently active shelves for +the submitted parameters. + +=cut + +sub GetRecentShelves ($$$) { + my ($mincategory, $row_count, $owner) = @_; + my (@shelflist); + my $total = _shelf_count($owner, $mincategory); + my @params = ($owner, $mincategory, 0, $row_count); #FIXME: offset is hardcoded here, but could be passed in for enhancements + shift @params if !$owner; + my $query = "SELECT * FROM virtualshelves"; + $query .= ($owner ? " WHERE owner = ? AND category = ?" : " WHERE category >= ? "); + $query .= " ORDER BY lastmodified DESC LIMIT ?, ?"; + my $sth = $dbh->prepare($query); + $sth->execute(@params); + @shelflist = $sth->fetchall_arrayref({}); + return ( \@shelflist, $total ); +} + =item GetShelf (shelfnumber,shelfname,owner,category,sortfield) = &GetShelf($shelfnumber); @@ -184,7 +224,7 @@ Returns the database's information on 'virtualshelves' table. =cut -sub GetShelf { +sub GetShelf ($) { my ($shelfnumber) = @_; my $query = qq( SELECT shelfnumber, shelfname, owner, category, sortfield @@ -214,13 +254,16 @@ from C4::Circulation. =cut -sub GetShelfContents { - my ( $shelfnumber ,$sortfield) = @_; +sub GetShelfContents ($$;$$) { + my ($shelfnumber, $row_count, $offset, $sortfield) = @_; my $dbh=C4::Context->dbh(); + my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?"); + $sth1->execute($shelfnumber); + my $total = $sth1->fetchrow; if(!$sortfield) { - my $sthsort = $dbh->prepare('SELECT sortfield FROM virtualshelves WHERE shelfnumber=?'); - $sthsort->execute($shelfnumber); - ($sortfield) = $sthsort->fetchrow_array; + my $sth2 = $dbh->prepare('SELECT sortfield FROM virtualshelves WHERE shelfnumber=?'); + $sth2->execute($shelfnumber); + ($sortfield) = $sth2->fetchrow_array; } my $query = " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, @@ -230,13 +273,18 @@ sub GetShelfContents { LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype WHERE vc.shelfnumber=? "; + my @params = ($shelfnumber); if($sortfield) { - $query .= " ORDER BY `$sortfield` "; + $query .= " ORDER BY ? "; $query .= " DESC " if ($sortfield eq 'copyrightdate'); + push (@params, $sortfield); } - my $sth = $dbh->prepare($query); - $sth->execute($shelfnumber); - return $sth->fetchall_arrayref({}); + $query .= " LIMIT ?, ? "; + push (@params, ($offset ? $offset : 0)); + push (@params, $row_count); + my $sth3 = $dbh->prepare($query); + $sth3->execute(@params); + return ($sth3->fetchall_arrayref({}), $total); # Like the perldoc says, # returns reference-to-array, where each element is reference-to-hash of the row: # like [ $sth->fetchrow_hashref(), $sth->fetchrow_hashref() ... ] @@ -259,7 +307,7 @@ Returns a code to know what's happen. =cut sub AddShelf { - my ( $shelfname, $owner, $category ) = @_; + my ( $shelfname, $owner, $category, $sortfield ) = @_; my $query = qq( SELECT * FROM virtualshelves @@ -270,11 +318,11 @@ sub AddShelf { ( $sth->rows ) and return (-1); $query = qq( INSERT INTO virtualshelves - (shelfname,owner,category) - VALUES (?,?,?) + (shelfname,owner,category,sortfield) + VALUES (?,?,?,?) ); $sth = $dbh->prepare($query); - $sth->execute( $shelfname, $owner, $category ); + $sth->execute( $shelfname, $owner, $category, $sortfield ); my $shelfnumber = $dbh->{'mysql_insertid'}; return ($shelfnumber); } @@ -309,6 +357,11 @@ sub AddToShelf { ); $sth = $dbh->prepare($query); $sth->execute( $shelfnumber, $biblionumber ); + $query = qq(UPDATE virtualshelves + SET lastmodified = CURRENT_TIMESTAMP + WHERE shelfnumber = ?); + $sth = $dbh->prepare($query); + $sth->execute( $shelfnumber ); } =item AddToShelfFromBiblio @@ -339,6 +392,11 @@ sub AddToShelfFromBiblio { ); $sth = $dbh->prepare($query); $sth->execute( $shelfnumber, $biblionumber ); + $query = qq(UPDATE virtualshelves + SET lastmodified = CURRENT_TIMESTAMP + WHERE shelfnumber = ?); + $sth = $dbh->prepare($query); + $sth->execute( $shelfnumber ); } } @@ -472,6 +530,57 @@ sub DelShelf { return $sth->execute(shift); } +=item RefreshShelvesSummary + + ($total, $pubshelves, $barshelves) = RefreshShelvesSummary($sessionID, $loggedinuser, $row_count); + +Updates the current session and userenv with the most recent shelves + +Returns the total number of shelves stored in the session/userenv along with two references each to an +array of hashes, one containing the C<$loggedinuser>'s private shelves and one containing all public/open shelves. + +This function is used in conjunction with the 'Lists' button in masthead.inc. + +=cut + +sub RefreshShelvesSummary ($$$) { + + my ($sessionID, $loggedinuser, $row_count) = @_; + my $session = get_session($sessionID); + my ($total, $totshelves, $barshelves, $pubshelves); + + ($barshelves, $totshelves) = GetRecentShelves(1, $row_count, $loggedinuser); + $total->{'bartotal'} = $totshelves; + ($pubshelves, $totshelves) = GetRecentShelves(2, $row_count, undef); + $total->{'pubtotal'} = $totshelves; + + # Update the current session with the latest shelves... + $session->param('barshelves', ${@$barshelves}[0]); + $session->param('pubshelves', ${@$pubshelves}[0]); + $session->param('totshelves', $total); + + # likewise the userenv... + C4::Context->set_shelves_userenv('bar',${@$barshelves}[0]); + C4::Context->set_shelves_userenv('pub',${@$pubshelves}[0]); + C4::Context::set_shelves_userenv('tot',$total); + + return ($total, $pubshelves, $barshelves); +} + +# internal subs + +sub _shelf_count ($$) { + my (@params) = @_; + # Find out how many shelves total meet the submitted criteria... + my $query = "SELECT count(*) FROM virtualshelves"; + $query .= ($params[1] > 1) ? " WHERE category >= ?" : " WHERE owner=? AND category=?"; + shift @params if $params[1] > 1; + my $sth = $dbh->prepare($query); + $sth->execute(@params); + my $total = $sth->fetchrow; + return $total; +} + 1; __END__ diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index af85ed5774..7c28918aa1 100755 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -23,7 +23,7 @@ package C4::VirtualShelves::Page; use strict; use warnings; use CGI; -use C4::VirtualShelves qw/:DEFAULT GetShelvesSummary/; +use C4::VirtualShelves; use C4::Biblio; use C4::Items; use C4::Koha; @@ -32,6 +32,7 @@ use C4::Members; use C4::Output; use C4::Dates qw/format_date/; use Exporter; +use Data::Dumper; use vars qw($debug @EXPORT @ISA $VERSION); @@ -58,11 +59,22 @@ sub shelfpage ($$$$$) { $template or die "No template"; $template->param( { loggedinuser => $loggedinuser } ); my @paramsloop; + my $totitems; + my $shelfoff = ($query->param('shelfoff') ? $query->param('shelfoff') : 1); + my $itemoff = ($query->param('itemoff') ? $query->param('itemoff') : 1); + my $displaymode = ($query->param('display') ? $query->param('display') : 'publicshelves'); + my ($shelflimit, $shelfoffset, $shelveslimit, $shelvesoffset); + # FIXME: These limits should not be hardcoded... + $shelflimit = 20; # Limits number of items returned for a given query + $shelfoffset = (($itemoff == 1) ? 0 : ($itemoff * 10)); # Sets the offset to begin retrieving items at + $shelveslimit = 20; # Limits number of shelves returned for a given query (row_count) + $shelvesoffset = (($shelfoff == 1) ? 0 : ($shelfoff * 10)); # Sets the offset to begin retrieving shelves at (offset) # getting the Shelves list - my $shelflist = GetShelves( $loggedinuser, 2 ); + my $category = (($displaymode eq 'privateshelves') ? 1 : 2); + my ($shelflist, $totshelves) = GetShelves( $category, $shelveslimit, $shelvesoffset, $loggedinuser ); my $op = $query->param('op'); - my $imgdir = getitemtypeimagesrc(); - my $itemtypes = GetItemTypes(); +# my $imgdir = getitemtypeimagesrc(); +# my $itemtypes = GetItemTypes(); # the format of this is unindented for ease of diff comparison to the old script # Note: do not mistake the assignment statements below for comparisons! @@ -92,7 +104,7 @@ if ( $query->param('modifyshelfcontents') ) { my $showadd = 1; # set the default tab, etc. (for OPAC) -my $shelf_type = $query->param('display'); +my $shelf_type = ($query->param('display') ? $query->param('display') : 'publicshelves'); if (defined $shelf_type) { if ($shelf_type eq 'privateshelves') { $template->param(showprivateshelves => 1); @@ -102,6 +114,8 @@ if (defined $shelf_type) { } else { $debug and warn "Invalid 'display' param ($shelf_type)"; } +} elsif ($loggedinuser == -1) { + $template->param(showpublicshelves => 1); } else { $template->param(showprivateshelves => 1); } @@ -109,10 +123,12 @@ if (defined $shelf_type) { my($okmanage, $okview); my $shelfnumber = $query->param('shelfnumber') || $query->param('viewshelf'); if ($shelfnumber) { - $okmanage = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ); - $okview = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ); + $okmanage = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ); + $okview = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ); } +my $delflag = 0; + SWITCH: { if ( $op ) { unless ($okmanage) { @@ -127,8 +143,7 @@ SWITCH: { }; ModShelf( $shelfnumber, $shelf ); - $shelflist = GetShelves( $loggedinuser, 2 ); # refresh after mods; this also retrieves all public shelves - + } elsif ( $op eq 'modif' ) { my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) =GetShelf( $shelfnumber ); my $member = GetMember($owner,'borrowernumber'); @@ -149,10 +164,13 @@ SWITCH: { if ($shelfnumber = $query->param('viewshelf') ) { #check that the user can view the shelf if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) { - my $items = GetShelfContents($shelfnumber); + my $items; + ($items, $totitems) = GetShelfContents($shelfnumber, $shelflimit, $shelfoffset); for my $this_item (@$items) { - $this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype} }->{'imageurl'}; - $this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'}; + # the virtualshelfcontents table does not store these columns nor are they retrieved from the items + # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn + #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype} }->{'imageurl'}; + #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'}; $this_item->{'dateadded'} = format_date($this_item->{'dateadded'}); } $showadd = 1; @@ -160,13 +178,12 @@ SWITCH: { foreach (grep {$i++ % 2} @$items) { # every other item $_->{toggle} = 1; } - # my $manageshelf = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ); - # ($manageshelf) and $showadd = 1; + my $manageshelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ); $template->param( shelfname => $shelflist->{$shelfnumber}->{'shelfname'}, shelfnumber => $shelfnumber, viewshelf => $shelfnumber, - manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ), + manageshelf => $manageshelf, itemsloop => $items, ); } else { push @paramsloop, {nopermission=>$shelfnumber} }; @@ -179,7 +196,8 @@ SWITCH: { my $shelfnumber = AddShelf( $newshelf, $query->param('owner'), - $query->param('category') + $query->param('category'), + $query->param('sortfield') ); $stay = 1; if ( $shelfnumber == -1 ) { #shelf already exists. @@ -193,6 +211,7 @@ SWITCH: { } foreach ($query->param()) { /DEL-(\d+)/ or next; + $delflag = 1; my $number = $1; unless (defined $shelflist->{$number}) { push(@paramsloop, {unrecognized=>$number}); last; @@ -200,7 +219,8 @@ SWITCH: { unless (ShelfPossibleAction($loggedinuser, $number, 'manage')) { push(@paramsloop, {nopermission=>$shelfnumber}); last; } - my $contents = GetShelfContents($number); + my $contents; + ($contents, $totshelves) = GetShelfContents($number, $shelveslimit, $shelvesoffset); if (my $count = scalar @$contents){ unless (scalar grep {/^CONFIRM-$number$/} $query->param()) { push(@paramsloop, {need_confirm=>$shelflist->{$number}->{shelfname}, count=>$count}); @@ -225,13 +245,13 @@ SWITCH: { } (@paramsloop) and $template->param(paramsloop => \@paramsloop); -# rebuild shelflist in case a shelf has been added -# $shelflist = GetShelves( $loggedinuser, 2 ); $showadd and $template->param(showadd => 1); my @shelvesloop; my @shelveslooppriv; my $numberCanManage = 0; +# rebuild shelflist in case a shelf has been added +($shelflist, $totshelves) = GetShelves( $category, $shelveslimit, $shelvesoffset, $loggedinuser ) unless $delflag; foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) { my %line; $shelflist->{$element}->{shelf} = $element; @@ -239,7 +259,7 @@ foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflis my $owner = $shelflist->{$element}->{ 'owner' }; my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' ); $shelflist->{$element}->{"viewcategory$category"} = 1; - $shelflist->{$element}->{canmanage} = $canmanage; + $shelflist->{$element}->{manageshelf} = $canmanage; if ($owner eq $loggedinuser or $canmanage) { $shelflist->{$element}->{'mine'} = 1; } @@ -254,7 +274,14 @@ foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflis push (@shelvesloop, $shelflist->{$element}); } } - +my $url = $type eq 'opac' ? "/cgi-bin/koha/opac-shelves.pl" : "/cgi-bin/koha/virtualshelves/shelves.pl"; +$url .= "?display=" . $query->param('display') if $query->param('display'); +$url .= "?viewshelf=" . $query->param('viewshelf') if $query->param('viewshelf'); +if ($query->param('viewshelf')) { + $template->param( {pagination_bar => pagination_bar($url, (int($totitems/$shelflimit)) + (($totitems % $shelflimit) > 0 ? 1 : 0), $itemoff, "itemoff")} ); +} else { + $template->param( {pagination_bar => pagination_bar($url, (int($totshelves/$shelveslimit)) + (($totshelves % $shelveslimit) > 0 ? 1 : 0), $shelfoff, "shelfoff")} ); +} $template->param( shelveslooppriv => \@shelveslooppriv, shelvesloop => \@shelvesloop, @@ -272,13 +299,25 @@ if ($template->param( 'shelves' ) or $template->param( seflag => 1); } -my $sessionID = $query->cookie("CGISESSID") ; -my $session = get_session($sessionID); -my $barshelves = GetShelvesSummary($loggedinuser, 2, 10); -if (defined($barshelves)) { - $session->param('barshelves', $barshelves); - $template->param( barshelves => scalar (@$barshelves)); - $template->param( barshelvesloop => $barshelves); +#FIXME: This refresh really only needs to happen when there is a modification of some sort +# to the shelves, but the above code is so convoluted in its handling of the various +# options, it is easier to do this refresh every time C4::VirtualShelves::Page.pm is +# called + +my ($total, $pubshelves, $barshelves) = RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10)); + +if (defined $barshelves) { + $template->param( barshelves => scalar (@{${@$barshelves}[0]}), + barshelvesloop => ${@$barshelves}[0], + ); + $template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar (@{${@$barshelves}[0]})); +} + +if (defined $pubshelves) { + $template->param( pubshelves => scalar (@{${@$pubshelves}[0]}), + pubshelvesloop => ${@$pubshelves}[0], + ); + $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar (@{${@$pubshelves}[0]})); } output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc index 803db7fc65..32b2de5624 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc @@ -29,7 +29,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl index 03180cc081..e24fffa479 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl @@ -76,7 +76,6 @@ $(document).ready(function(){
-
@@ -114,10 +113,11 @@ $(document).ready(function(){
Contents of -

+

+ - + @@ -130,6 +130,7 @@ $(document).ready(function(){ + + @@ -210,11 +212,17 @@ $(document).ready(function(){
  1. Owner: " />
  2. +
  3. +
@@ -225,6 +233,12 @@ $(document).ready(function(){
  1. " />
  2. +
  3. +
   Item Type Title Author
" /> @@ -138,6 +139,7 @@ $(document).ready(function(){ " /> " alt="" title="" />
- - - - - - - - - - -
NameOwnerCategoryItems 
">Koha Admin - - Private - Public - Open - -
- " /> - - -
-
- - " value="1" /> - - " value="1" /> - +

Lists

+ + +
- +
- + + + + + + + + + + + + + + + + +
List NameContentsSort byTypeOptions
"> item(s)Private + Public + Open + + +
+ " /> + + +
+
+ + " value="1" /> + + " value="1" /> + + + + +
+ + None + +
No Private Lists.
+ New List +
+ + +
+ +
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc index 1eafec5ea7..ddc002700c 100755 --- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc @@ -90,27 +90,36 @@ No Public Lists + + +

Your Lists

No Private Lists - + + + diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl index 5b5a003082..adbcf92818 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl @@ -9,58 +9,61 @@
- -

Add items to : a list:

- -

Add to a list:

- -
    -
  • - -
  • + + +

    Add items to : a list:

    + +

    Add to a list:

    + +
      + +
    • + +
    • -
    - -
    -
    Select a List -
    - " /> -
    -
    Cancel
    -
    -

    ...or...

    - - -
    - "> - " /> - -
    Cancel
    -
    - - - -
    -
    Add to a New List: -
    1. - - -
    2. -
    3. -
    - " /> -
    Cancel
    -
    +
+ +
+
Select a List +
+ " /> +
+
Cancel
+
+

...or...

+ + +
+ "> + " /> + +
Cancel
+
+ + + +
+
Add to a New List: +
  1. + + +
  2. +
  3. +
+ " /> +
Cancel
+
+ -

- This is not an open list. - Items cannot be added to it. -

+

+ This is not an open list. + Items cannot be added to it. +

Close this window. diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl index 196f11582f..0ec9d0076c 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl @@ -13,13 +13,15 @@