- my $privateshelves = GetAllShelves(1,$loggedinuser);
- if(@{$privateshelves}){
- $template->param (
- privatevirtualshelves => $privateshelves,
- existingshelves => 1
- );
- }
- my $publicshelves = GetAllShelves(2,$loggedinuser);
- if(@{$publicshelves}){
- $template->param (
- publicvirtualshelves => $publicshelves,
- existingshelves => 1
- );
+ #Close this page and return
+ print $query->header;
+ print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
+ exit;
+ } else {
+ $authorized = 0;
+ }
+} elsif ($selectedshelf) {
+ my $shelfnumber = $query->param('selectedshelf');
+ my $shelf = Koha::Virtualshelves->find($shelfnumber);
+ if ( $shelf->can_biblios_be_added($loggedinuser) ) {
+ $template->param(
+ singleshelf => 1,
+ shelfnumber => $shelf->shelfnumber,
+ shelfname => $shelf->shelfname,
+ );
+ } else {
+ $authorized = 0;
+ }
+} else {
+ if ( $loggedinuser > 0 ) {
+ my $private_shelves = Koha::Virtualshelves->search(
+ { public => 0,
+ owner => $loggedinuser,
+ allow_change_from_owner => 1,
+ },
+ { order_by => 'shelfname' }
+ );
+ my $shelves_shared_with_me = Koha::Virtualshelves->search(
+ { public => 0,
+ 'virtualshelfshares.borrowernumber' => $loggedinuser,
+ allow_change_from_others => 1,
+ },
+ { join => 'virtualshelfshares', }
+ );
+ my $public_shelves;
+ if ( $loggedinuser ) {
+ if ( Koha::Patrons->find( $loggedinuser )->can_patron_change_staff_only_lists ) {
+ $public_shelves = Koha::Virtualshelves->search(
+ { public => 1,
+ -or => [
+ -and => {
+ allow_change_from_owner => 1,
+ owner => $loggedinuser,
+ },
+ allow_change_from_others => 1,
+ allow_change_from_staff => 1
+ ],
+ },
+ { order_by => 'shelfname' }
+ );
+ } else {
+ $public_shelves = Koha::Virtualshelves->search(
+ { public => 1,
+ -or => [
+ -and => {
+ allow_change_from_owner => 1,
+ owner => $loggedinuser,
+ },
+ allow_change_from_others => 1,
+ ],
+ },
+ {order_by => 'shelfname' }
+ );
+ }
+ } else {
+ $public_shelves = Koha::Virtualshelves->search(
+ { public => 1,
+ -or => [
+ -and => {
+ allow_change_from_owner => 1,
+ owner => $loggedinuser,
+ },
+ allow_change_from_others => 1,
+ ],
+ },
+ {order_by => 'shelfname' }
+ );