View | Details | Raw Unified | Return to bug 7310
Collapse All | Expand All

(-)a/C4/Auth.pm (-47 / +12 lines)
Lines 164-182 sub get_template_and_user { Link Here
164
        $template->param( loggedinusername => $user );
164
        $template->param( loggedinusername => $user );
165
        $template->param( sessionID        => $sessionID );
165
        $template->param( sessionID        => $sessionID );
166
166
167
        my ($total, $pubshelves, $barshelves) = C4::Context->get_shelves_userenv();
167
        my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($borrowernumber, 'MASTHEAD');
168
        if (defined($pubshelves)) {
168
        $template->param(
169
            $template->param( pubshelves     => scalar @{$pubshelves},
169
            pubshelves     => $total->{pubtotal},
170
                              pubshelvesloop => $pubshelves,
170
            pubshelvesloop => $pubshelves,
171
            );
171
            barshelves      => $total->{bartotal},
172
            $template->param( pubtotal   => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
172
            barshelvesloop  => $barshelves,
173
        }
173
        );
174
        if (defined($barshelves)) {
175
            $template->param( barshelves      => scalar @{$barshelves},
176
                              barshelvesloop  => $barshelves,
177
            );
178
            $template->param( bartotal  => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar @{$barshelves});
179
        }
180
174
181
        require C4::Members;
175
        require C4::Members;
182
        my ( $borr ) = C4::Members::GetMemberDetails( $borrowernumber );
176
        my ( $borr ) = C4::Members::GetMemberDetails( $borrowernumber );
Lines 284-297 sub get_template_and_user { Link Here
284
278
285
        $template->param( sessionID        => $sessionID );
279
        $template->param( sessionID        => $sessionID );
286
        
280
        
287
        my ($total, $pubshelves) = C4::Context->get_shelves_userenv();  # an anonymous user has no 'barshelves'...
281
        my ($total, $pubshelves) = C4::VirtualShelves::GetSomeShelfNames(undef, 'MASTHEAD');
288
        if (defined $pubshelves) {
282
	$template->param(
289
            $template->param(   pubshelves      => scalar @{$pubshelves},
283
	    pubshelves     => $total->{pubtotal},
290
                                pubshelvesloop  => $pubshelves,
284
	    pubshelvesloop => $pubshelves,
291
                            );
285
	);
292
            $template->param(   pubtotal        => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
293
        }
294
295
    }
286
    }
296
 	# Anonymous opac search history
287
 	# Anonymous opac search history
297
 	# If opac search history is enabled and at least one search has already been performed
288
 	# If opac search history is enabled and at least one search has already been performed
Lines 900-921 sub checkauth { Link Here
900
                    $session->param('emailaddress'), $session->param('branchprinter')
891
                    $session->param('emailaddress'), $session->param('branchprinter')
901
                );
892
                );
902
893
903
                # Grab borrower's shelves and public shelves and add them to the session
904
                # $row_count determines how many records are returned from the db query
905
                # and the number of lists to be displayed of each type in the 'Lists' button drop down
906
                my $row_count = 10; # FIXME:This probably should be a syspref
907
                my ($total, $totshelves, $barshelves, $pubshelves);
908
                ($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber);
909
                $total->{'bartotal'} = $totshelves;
910
                ($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
911
                $total->{'pubtotal'} = $totshelves;
912
                $session->param('barshelves', $barshelves);
913
                $session->param('pubshelves', $pubshelves);
914
                $session->param('totshelves', $total);
915
916
                C4::Context::set_shelves_userenv('bar',$barshelves);
917
                C4::Context::set_shelves_userenv('pub',$pubshelves);
918
                C4::Context::set_shelves_userenv('tot',$total);
919
            }
894
            }
920
        	else {
895
        	else {
921
            	if ($userid) {
896
            	if ($userid) {
Lines 929-944 sub checkauth { Link Here
929
            # anonymous sessions are created only for the OPAC
904
            # anonymous sessions are created only for the OPAC
930
			$debug and warn "Initiating an anonymous session...";
905
			$debug and warn "Initiating an anonymous session...";
931
906
932
			# Grab the public shelves and add to the session...
933
			my $row_count = 20; # FIXME:This probably should be a syspref
934
			my ($total, $totshelves, $pubshelves);
935
			($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
936
			$total->{'pubtotal'} = $totshelves;
937
			$session->param('pubshelves', $pubshelves);
938
			$session->param('totshelves', $total);
939
			C4::Context::set_shelves_userenv('pub',$pubshelves);
940
			C4::Context::set_shelves_userenv('tot',$total);
941
942
			# setting a couple of other session vars...
907
			# setting a couple of other session vars...
943
			$session->param('ip',$session->remote_addr());
908
			$session->param('ip',$session->remote_addr());
944
			$session->param('lasttime',time());
909
			$session->param('lasttime',time());
(-)a/C4/VirtualShelves.pm (-268 / +309 lines)
Lines 28-33 use Carp; Link Here
28
use C4::Context;
28
use C4::Context;
29
use C4::Debug;
29
use C4::Debug;
30
30
31
use constant SHELVES_MASTHEAD_MAX => 10; #number under Lists button in masthead
32
use constant SHELVES_COMBO_MAX => 10; #add to combo in search
33
use constant SHELVES_MGRPAGE_MAX => 20; #managing page
34
use constant SHELVES_POPUP_MAX => 40; #addbybiblio popup
35
31
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
36
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
32
37
33
BEGIN {
38
BEGIN {
Lines 44-51 BEGIN { Link Here
44
            &GetBibliosShelves
49
            &GetBibliosShelves
45
	);
50
	);
46
        @EXPORT_OK = qw(
51
        @EXPORT_OK = qw(
47
            &GetShelvesSummary &GetRecentShelves &GetAllShelves
52
            &GetAllShelves &ShelvesMax
48
            &RefreshShelvesSummary &SetShelvesLimit
49
        );
53
        );
50
}
54
}
51
55
Lines 54-60 my $dbh = C4::Context->dbh; Link Here
54
58
55
=head1 NAME
59
=head1 NAME
56
60
57
C4::VirtualShelves - Functions for manipulating Koha virtual virtualshelves
61
C4::VirtualShelves - Functions for manipulating Koha virtual shelves
58
62
59
=head1 SYNOPSIS
63
=head1 SYNOPSIS
60
64
Lines 62-82 C4::VirtualShelves - Functions for manipulating Koha virtual virtualshelves Link Here
62
66
63
=head1 DESCRIPTION
67
=head1 DESCRIPTION
64
68
65
This module provides functions for manipulating virtual virtualshelves,
69
This module provides functions for manipulating virtual shelves,
66
including creating and deleting virtualshelves, and adding and removing
70
including creating and deleting virtual shelves, and adding and removing
67
bibs to and from virtualshelves.
71
bibs to and from virtual shelves.
68
72
69
=head1 FUNCTIONS
73
=head1 FUNCTIONS
70
74
71
=head2 GetShelves
75
=head2 GetShelves
72
76
73
  ($shelflist, $totshelves) = &GetShelves($mincategory, $row_count, $offset, $owner);
77
  ($shelflist, $totshelves) = &GetShelves($category, $row_count, $offset, $owner);
74
  ($shelfnumber, $shelfhash) = each %{$shelflist};
78
  ($shelfnumber, $shelfhash) = each %{$shelflist};
75
79
76
Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total
80
Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total
77
number of shelves that meet the C<$owner> and C<$mincategory> criteria.  C<$mincategory>,
81
number of shelves that meet the C<$owner> and C<$category> criteria.  C<$category>,
78
C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$mincategory> == 1.
82
C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$category> == 1.
79
When C<$mincategory> is 2 or 3, supply undef as argument for C<$owner>.
83
When C<$category> is 2, supply undef as argument for C<$owner>.
84
85
This function is used by shelfpage in VirtualShelves/Page.pm when listing all shelves for lists management in opac or staff client. Order is by shelfname.
86
80
C<$shelflist>is a reference-to-hash. The keys are the virtualshelves numbers (C<$shelfnumber>, above),
87
C<$shelflist>is a reference-to-hash. The keys are the virtualshelves numbers (C<$shelfnumber>, above),
81
and the values (C<$shelfhash>, above) are themselves references-to-hash, with the following keys:
88
and the values (C<$shelfhash>, above) are themselves references-to-hash, with the following keys:
82
89
Lines 94-128 The number of virtuals on that virtualshelves. Link Here
94
101
95
=cut
102
=cut
96
103
97
sub GetShelves ($$$$) {
104
sub GetShelves {
98
    my ($mincategory, $row_count, $offset, $owner) = @_;
105
    my ($category, $row_count, $offset, $owner) = @_;
99
	my @params = ($owner, $mincategory, ($offset ? $offset : 0), $row_count);
106
    my @params;
100
	my @params1 = ($owner, $mincategory);
107
    my $total = _shelf_count($owner, $category);
101
	if ($mincategory > 1) {
108
    my $query = qq{
102
		shift @params;
109
        SELECT vs.shelfnumber, vs.shelfname,vs.owner,
103
		shift @params1;
110
        bo.surname,bo.firstname,vs.category,vs.sortfield,
104
	}
111
        count(vc.biblionumber) as count
105
	my $total = _shelf_count($owner, $mincategory);
112
        FROM virtualshelves vs
106
    # grab only the shelves meeting the row_count/offset spec...
113
        LEFT JOIN borrowers bo ON vs.owner=bo.borrowernumber
107
    my $query = qq(
114
        LEFT JOIN virtualshelfcontents vc USING (shelfnumber) };
108
        SELECT virtualshelves.shelfnumber, virtualshelves.shelfname,owner,surname,firstname,virtualshelves.category,virtualshelves.sortfield,
115
    if($category==1) {
109
               count(virtualshelfcontents.biblionumber) as count
116
        $query.= qq{
110
        FROM   virtualshelves
117
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
111
            LEFT JOIN   virtualshelfcontents ON virtualshelves.shelfnumber = virtualshelfcontents.shelfnumber
118
            AND sh.borrowernumber=?
112
            LEFT JOIN   borrowers ON virtualshelves.owner = borrowers.borrowernumber );
119
	    WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
113
    $query .= ($mincategory == 1) ? "WHERE  owner=? AND category=?" : "WHERE category>=?";
120
        @params= ($owner, $owner, $owner, $offset||0, $row_count);
114
	$query .= qq(
121
    }
115
        GROUP BY virtualshelves.shelfnumber
122
    else {
116
        ORDER BY virtualshelves.shelfname
123
        $query.= 'WHERE category=2 ';
117
		LIMIT ?, ?);
124
        @params= ($offset||0, $row_count);
125
    }
126
    $query.= qq{
127
        GROUP BY vs.shelfnumber
128
        ORDER BY vs.shelfname
129
        LIMIT ?, ?};
130
118
    my $sth2 = $dbh->prepare($query);
131
    my $sth2 = $dbh->prepare($query);
119
    $sth2->execute(@params);
132
    $sth2->execute(@params);
120
    my %shelflist;
133
    my %shelflist;
121
    while ( my ( $shelfnumber, $shelfname, $owner, $surname,
134
    while( my ($shelfnumber, $shelfname, $owner, $surname, $firstname, $category, $sortfield, $count)= $sth2->fetchrow) {
122
           	$firstname,   $category,  $sortfield, $count ) = $sth2->fetchrow ) {
123
        $shelflist{$shelfnumber}->{'shelfname'} = $shelfname;
135
        $shelflist{$shelfnumber}->{'shelfname'} = $shelfname;
124
        $shelflist{$shelfnumber}->{'count'}     = $count;
136
        $shelflist{$shelfnumber}->{'count'}     = $count;
125
        if($count eq 1){ $shelflist{$shelfnumber}->{'single'} = 1; }
137
        $shelflist{$shelfnumber}->{'single'}    = $count==1;
126
        $shelflist{$shelfnumber}->{'sortfield'} = $sortfield;
138
        $shelflist{$shelfnumber}->{'sortfield'} = $sortfield;
127
        $shelflist{$shelfnumber}->{'category'}  = $category;
139
        $shelflist{$shelfnumber}->{'category'}  = $category;
128
        $shelflist{$shelfnumber}->{'owner'}     = $owner;
140
        $shelflist{$shelfnumber}->{'owner'}     = $owner;
Lines 132-242 sub GetShelves ($$$$) { Link Here
132
    return ( \%shelflist, $total );
144
    return ( \%shelflist, $total );
133
}
145
}
134
146
135
=head2 GetShelvesSummary
147
=head2 GetAllShelves
136
137
	($shelves, $total) = GetShelvesSummary($mincategory, $row_count, $offset, $owner)
138
139
Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total
140
number of shelves that meet the C<$owner> and/or C<$mincategory> criteria. C<$mincategory>,
141
C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$mincategory> == 1.
142
When C<$mincategory> is 2 or 3, supply undef as argument for C<$owner>.
143
144
=cut
145
146
sub GetShelvesSummary ($$$$) {
147
    my ($mincategory, $row_count, $offset, $owner) = @_;
148
	my @params = ($owner, $mincategory, ($offset ? $offset : 0), $row_count);
149
	my @params1 = ($owner, $mincategory);
150
	if ($mincategory > 1) {
151
		shift @params;
152
		shift @params1;
153
	}
154
	my $total = _shelf_count($owner, $mincategory);
155
    # grab only the shelves meeting the row_count/offset spec...
156
	my $query = qq(
157
		SELECT
158
			virtualshelves.shelfnumber,
159
			virtualshelves.shelfname,
160
			owner,
161
			CONCAT(firstname, ' ', surname) AS name,
162
			virtualshelves.category,
163
			count(virtualshelfcontents.biblionumber) AS count
164
		FROM   virtualshelves
165
			LEFT JOIN  virtualshelfcontents ON virtualshelves.shelfnumber = virtualshelfcontents.shelfnumber
166
			LEFT JOIN             borrowers ON virtualshelves.owner = borrowers.borrowernumber );
167
    $query .= ($mincategory == 1) ? "WHERE  owner=? AND category=?" : "WHERE category>=?";
168
	$query .= qq(
169
		GROUP BY virtualshelves.shelfnumber
170
		ORDER BY virtualshelves.category
171
		DESC 
172
		LIMIT ?, ?);
173
	my $sth2 = $dbh->prepare($query);
174
	$sth2->execute(@params);
175
    my $shelves = $sth2->fetchall_arrayref({});
176
    return ($shelves, $total);
177
178
	# Probably NOT the final implementation since it is still bulky (repeated hash keys).
179
	# might like an array of rows of delimited values:
180
	# 1|2||0|blacklist|112
181
	# 2|6|Josh Ferraro|51|en_fuego|106
182
}
183
184
=head2 GetRecentShelves
185
148
186
	($shelflist, $total) = GetRecentShelves(1, $limit, $owner)
149
    $shelflist = GetAllShelves($category, $owner)
187
150
188
This function returns a reference to an array of hashrefs containing specified shelves sorted
151
This function returns a reference to an array of hashrefs containing all shelves
189
by the date the shelf was last modified in descending order limited to the number of records
152
sorted by the shelf name.
190
specified by C<$row_count>. If calling with C<$mincategory> other than 1, use undef as C<$owner>.
191
153
192
This function is intended to return a dataset reflecting the most recently active shelves for
154
This function is intended to return a dataset reflecting all the shelves for
193
the submitted parameters.
155
the submitted parameters.
194
156
195
=cut
157
=cut
196
158
197
sub GetRecentShelves {
159
sub GetAllShelves {
198
    my ($mincategory, $row_count, $owner) = @_;
160
    my ($category,$owner,$adding_allowed) = @_;
199
    my $total = _shelf_count($owner, $mincategory);
200
    my @params;
161
    my @params;
201
    my $selection;
162
    my $query = 'SELECT vs.* FROM virtualshelves vs ';
202
    if (defined $owner) {
163
    if($category==1) {
203
        @params = ($owner, $mincategory);
164
        $query.= qq{
204
        $selection = ' WHERE owner = ? AND category = ?';
165
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
205
    } else {
166
            AND sh.borrowernumber=?
206
        @params = ( $mincategory);
167
	    WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
207
        $selection = ' WHERE category >= ? ';
168
        @params = ($owner, $owner, $owner);
208
    }
169
    }
209
    my $query = 'SELECT * FROM virtualshelves';
170
    else {
210
    $query .= $selection;
171
	$query.='WHERE category=2 ';
211
    $query .= ' ORDER BY lastmodified DESC';
172
        @params = ();
212
    if ($row_count){
213
	$query .= ' LIMIT ?';
214
	push @params,$row_count;
215
    }
173
    }
216
    my $sth = $dbh->prepare($query);
174
    $query.='AND (allow_add=1 OR owner=?) ' if $adding_allowed;
175
    push @params, $owner if $adding_allowed;
176
    $query.= 'ORDER BY shelfname ASC';
177
    my $sth = $dbh->prepare( $query );
217
    $sth->execute(@params);
178
    $sth->execute(@params);
218
    my $shelflist = $sth->fetchall_arrayref({});
179
    return $sth->fetchall_arrayref({});
219
    return ( $shelflist, $total );
220
}
180
}
221
181
222
=head2 GetAllShelves
182
=head2 GetSomeShelfNames
223
183
224
    $shelflist = GetAllShelves($owner)
184
Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header.
225
185
226
This function returns a reference to an array of hashrefs containing all shelves sorted
186
=cut
227
by the shelf name.
228
187
229
This function is intended to return a dataset reflecting all the shelves for
188
sub GetSomeShelfNames {
230
the submitted parameters.
189
    my ($owner, $purpose, $adding_allowed)= @_;
190
    my ($bar, $pub, @params);
231
191
232
=cut
192
    my $bquery = 'SELECT vs.shelfnumber, vs.shelfname FROM virtualshelves vs ';
193
    my $limit= ShelvesMax($purpose);
233
194
234
sub GetAllShelves {
195
    my $qry1= $bquery."WHERE vs.category=2 ";
235
    my ($category,$owner) = @_;
196
    $qry1.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
236
    my $query = 'SELECT * FROM virtualshelves WHERE category = ? AND owner = ? ORDER BY shelfname ASC';
197
    push @params, $owner||0 if $adding_allowed;
237
    my $sth = $dbh->prepare( $query );
198
    $qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit";
238
    $sth->execute( $category, $owner );
199
239
    return $sth->fetchall_arrayref({});
200
    unless($adding_allowed && (!defined($owner) || $owner<=0)) {
201
      #if adding items, user should be known
202
      $pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params);
203
    }
204
205
    if($owner) {
206
      my $qry2= $bquery. qq{
207
        LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=?
208
        WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
209
      @params=($owner,$owner,$owner);
210
      $qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
211
      push @params, $owner if $adding_allowed;
212
      $qry2.= "ORDER BY vs.lastmodified DESC ";
213
      $qry2.= "LIMIT $limit";
214
      $bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params);
215
    }
216
217
    return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
240
}
218
}
241
219
242
=head2 GetShelf
220
=head2 GetShelf
Lines 322-371 sub GetShelfContents ($;$$$) { Link Here
322
300
323
=head2 AddShelf
301
=head2 AddShelf
324
302
325
  $shelfnumber = &AddShelf( $shelfname, $owner, $category);
303
  $shelfnumber = &AddShelf($hashref, $owner);
326
304
327
Creates a new virtual virtualshelves with name C<$shelfname>, owner C<$owner> and category
305
Creates a new virtual shelf. Params passed in a hash like ModShelf.
328
C<$category>.
329
306
330
Returns a code to know what's happen.
307
Returns a code to know what's happen.
331
    * -1 : if this virtualshelves already exist.
308
    * -1 : if this virtualshelves already exists.
332
    * $shelfnumber : if success.
309
    * $shelfnumber : if success.
333
310
334
=cut
311
=cut
335
312
336
sub AddShelf {
313
sub AddShelf {
337
    my ( $shelfname, $owner, $category, $sortfield ) = @_;
314
    my ($hashref, $owner)= @_;
338
    my $query = qq(
315
339
        SELECT *
316
    #initialize missing hash values to silence warnings
340
        FROM   virtualshelves
317
    foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) {
341
        WHERE  shelfname=? AND owner=?
318
        $hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': '';
342
    );
319
    }
320
321
    return -1 unless _CheckShelfName($hashref->{shelfname}, $hashref->{category}, $owner, 0);
322
323
    my $query = qq(INSERT INTO virtualshelves
324
        (shelfname,owner,category,sortfield,allow_add,allow_delete_own,allow_delete_other)
325
        VALUES (?,?,?,?,?,?,?));
326
343
    my $sth = $dbh->prepare($query);
327
    my $sth = $dbh->prepare($query);
344
    $sth->execute($shelfname,$owner);
328
    $sth->execute(
345
    ( $sth->rows ) and return (-1);
329
	$hashref->{shelfname},
346
    $query = qq(
330
	$owner,
347
        INSERT INTO virtualshelves
331
	$hashref->{category},
348
            (shelfname,owner,category,sortfield)
332
	$hashref->{sortfield},
349
        VALUES (?,?,?,?)
333
	$hashref->{allow_add}||0,
350
    );
334
	$hashref->{allow_delete_own}||1,
351
    $sth = $dbh->prepare($query);
335
	$hashref->{allow_delete_other}||0 );
352
    $sth->execute( $shelfname, $owner, $category, $sortfield );
353
    my $shelfnumber = $dbh->{'mysql_insertid'};
336
    my $shelfnumber = $dbh->{'mysql_insertid'};
354
    return ($shelfnumber);
337
    return $shelfnumber;
355
}
338
}
356
339
357
=head2 AddToShelf
340
=head2 AddToShelf
358
341
359
  &AddToShelf($biblionumber, $shelfnumber);
342
  &AddToShelf($biblionumber, $shelfnumber, $borrower);
360
343
361
Adds bib number C<$biblionumber> to virtual virtualshelves number
344
Adds bib number C<$biblionumber> to virtual virtualshelves number
362
C<$shelfnumber>, unless that bib is already on that shelf.
345
C<$shelfnumber>, unless that bib is already on that shelf.
363
346
364
=cut
347
=cut
365
348
366
#'
367
sub AddToShelf {
349
sub AddToShelf {
368
    my ( $biblionumber, $shelfnumber ) = @_;
350
    my ($biblionumber, $shelfnumber, $borrowernumber) = @_;
369
    return unless $biblionumber;
351
    return unless $biblionumber;
370
    my $query = qq(
352
    my $query = qq(
371
        SELECT *
353
        SELECT *
Lines 378-389 sub AddToShelf { Link Here
378
    ($sth->rows) and return undef;	# already on shelf
360
    ($sth->rows) and return undef;	# already on shelf
379
	$query = qq(
361
	$query = qq(
380
		INSERT INTO virtualshelfcontents
362
		INSERT INTO virtualshelfcontents
381
			(shelfnumber, biblionumber, flags)
363
			(shelfnumber, biblionumber, flags, borrowernumber)
382
		VALUES
364
		VALUES (?, ?, 0, ?));
383
			(?, ?, 0)
384
	);
385
	$sth = $dbh->prepare($query);
365
	$sth = $dbh->prepare($query);
386
	$sth->execute( $shelfnumber, $biblionumber );
366
	$sth->execute( $shelfnumber, $biblionumber, $borrowernumber);
387
	$query = qq(UPDATE virtualshelves
367
	$query = qq(UPDATE virtualshelves
388
				SET lastmodified = CURRENT_TIMESTAMP
368
				SET lastmodified = CURRENT_TIMESTAMP
389
				WHERE shelfnumber = ?);
369
				WHERE shelfnumber = ?);
Lines 393-443 sub AddToShelf { Link Here
393
373
394
=head2 ModShelf
374
=head2 ModShelf
395
375
396
ModShelf($shelfnumber, $hashref)
376
my $result= ModShelf($shelfnumber, $hashref)
397
377
398
Where $hashref->{column} = param
378
Where $hashref->{column} = param
399
379
400
Modify the value into virtualshelves table with values given 
380
Modify the value into virtualshelves table with values given 
401
from hashref, which each key of the hashref should be
381
from hashref, which each key of the hashref should be
402
the name of a column of virtualshelves.
382
the name of a column of virtualshelves.
383
Fields like shelfnumber or owner cannot be changed.
384
385
Returns 1 if the action seemed to be successful.
403
386
404
=cut
387
=cut
405
388
406
sub ModShelf {
389
sub ModShelf {
407
    my $shelfnumber = shift;
390
    my ($shelfnumber,$hashref) = @_;
408
    my $shelf = shift;
409
410
    if (exists $shelf->{shelfnumber}) {
411
        carp "Should not use ModShelf to change shelfnumber";
412
        return;
413
    }
414
    unless (defined $shelfnumber and $shelfnumber =~ /^\d+$/) {
415
        carp "Invalid shelfnumber passed to ModShelf: $shelfnumber";
416
        return;
417
    }
418
391
419
	my $query = "UPDATE virtualshelves SET ";
392
    my $query= "SELECT * FROM virtualshelves WHERE shelfnumber=?";
420
    my @bind_params = ();
393
    my $sth = $dbh->prepare($query);
421
    my @set_clauses = ();
394
    $sth->execute($shelfnumber);
395
    my $oldrecord= $sth->fetchrow_hashref;
396
    return 0 unless $oldrecord; #not found?
422
397
423
	foreach my $column (keys %$shelf) {
398
    #initialize missing hash values to silence warnings
424
        push @set_clauses, "$column = ?";
399
    foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) {
425
        push @bind_params, $shelf->{$column};
400
        $hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': '';
426
    }
401
    }
427
402
428
    if ($#set_clauses == -1) {
403
    #if name or category changes, the name should be tested
429
        carp "No columns to update passed to ModShelf";
404
    if($hashref->{shelfname} || $hashref->{category}) {
430
        return;
405
        unless(_CheckShelfName(
406
	    $hashref->{shelfname}||$oldrecord->{shelfname},
407
	    $hashref->{category}||$oldrecord->{category},
408
	    $oldrecord->{owner}, $shelfnumber )) {
409
		return 0; #name check failed
410
        }
431
    }
411
    }
432
    $query .= join(", ", @set_clauses);
433
434
    $query .= " WHERE shelfnumber = ? ";
435
    push @bind_params, $shelfnumber;
436
412
437
    $debug and warn "ModShelf query:\n $query\n",
413
    #only the following fields from the hash may be changed
438
	                "ModShelf query args: ", join(',', @bind_params), "\n";
414
    $query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?";
439
	my $sth = $dbh->prepare($query);
415
    $sth = $dbh->prepare($query);
440
   	$sth->execute( @bind_params );
416
    $sth->execute(
417
	$hashref->{shelfname}||$oldrecord->{shelfname},
418
	$hashref->{category}||$oldrecord->{category},
419
	$hashref->{sortfield}||$oldrecord->{sortfield},
420
	$hashref->{allow_add}||$oldrecord->{allow_add},
421
	$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own},
422
	$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other},
423
	$shelfnumber );
424
    return $@? 0: 1;
441
}
425
}
442
426
443
=head2 ShelfPossibleAction
427
=head2 ShelfPossibleAction
Lines 446-452 ShelfPossibleAction($loggedinuser, $shelfnumber, $action); Link Here
446
430
447
C<$loggedinuser,$shelfnumber,$action>
431
C<$loggedinuser,$shelfnumber,$action>
448
432
449
$action can be "view" or "manage".
433
$action can be "view", "add", "delete", "manage", "new_public", "new_private".
434
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage.
435
new_public and new_private refers to creating a new public or private list.
436
The distinction between deleting your own entries from the list or entries from
437
others is made in DelFromShelf.
450
438
451
Returns 1 if the user can do the $action in the $shelfnumber shelf.
439
Returns 1 if the user can do the $action in the $shelfnumber shelf.
452
Returns 0 otherwise.
440
Returns 0 otherwise.
Lines 455-529 Returns 0 otherwise. Link Here
455
443
456
sub ShelfPossibleAction {
444
sub ShelfPossibleAction {
457
    my ( $user, $shelfnumber, $action ) = @_;
445
    my ( $user, $shelfnumber, $action ) = @_;
458
    my $query = qq(
446
    $action= 'view' unless $action;
459
        SELECT owner,category
447
    $user=0 unless $user;
460
        FROM   virtualshelves
448
461
        WHERE  shelfnumber=?
449
    if($action =~ /^new/) { #no shelfnumber needed
462
    );
450
        if($action eq 'new_private') {
451
            return $user>0;
452
        }
453
        elsif($action eq 'new_public') {
454
            return $user>0 && C4::Context->preference('OpacAllowPublicListCreation');
455
        }
456
        return 0;
457
    }
458
459
    return 0 unless defined($shelfnumber);
460
461
    my $query = qq/
462
        SELECT IFNULL(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, IFNULL(sh.borrowernumber,0) AS borrowernumber
463
        FROM virtualshelves vs
464
        LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
465
        AND sh.borrowernumber=?
466
        WHERE vs.shelfnumber=?
467
    /;
463
    my $sth = $dbh->prepare($query);
468
    my $sth = $dbh->prepare($query);
464
    $sth->execute($shelfnumber);
469
    $sth->execute($user, $shelfnumber);
465
    my ( $owner, $category ) = $sth->fetchrow;
470
    my $shelf= $sth->fetchrow_hashref;
466
    require C4::Members;
471
467
	my $borrower = C4::Members::GetMemberDetails($user);
472
    return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || $shelf->{borrowernumber}==$user);
468
	return 0 if not defined($user);
473
    if($action eq 'view') {
469
	return 1 if ( $category >= 3);							# open list
474
	#already handled in the above condition
470
    return 1 if (($category >= 2) and
475
	return 1;
471
				defined($action) and $action eq 'view');	# public list, anybody can view
476
    }
472
    return 1 if (($category >= 2) and defined($user) and ($borrower->{authflags}->{superlibrarian} || $user == 0));	# public list, superlibrarian can edit/delete
477
    elsif($action eq 'add') {
473
    return 1 if (defined($user)  and $owner  eq $user );	# user owns this list.  Check last.
478
	return 0 if $user<=0; #should be logged in
479
	return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user;
480
	#owner may always add
481
    }
482
    elsif($action eq 'delete') {
483
        #this answer is just diplomatic: it says that you may be able to delete
484
        #some items from that shelf
485
        #it does not answer the question about a specific biblio
486
        #DelFromShelf checks the situation per biblio
487
	return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1);
488
    }
489
    elsif($action eq 'manage') {
490
	return 1 if $user && $shelf->{owner}==$user;
491
    }
474
    return 0;
492
    return 0;
475
}
493
}
476
494
477
=head2 DelFromShelf
495
=head2 DelFromShelf
478
496
479
  &DelFromShelf( $biblionumber, $shelfnumber);
497
    $result= &DelFromShelf( $bibref, $shelfnumber, $user);
480
498
481
Removes bib number C<$biblionumber> from virtual virtualshelves number
499
Removes biblionumbers in passed arrayref from shelf C<$shelfnumber>.
482
C<$shelfnumber>. If the bib wasn't on that virtualshelves to begin with,
500
If the bib wasn't on that virtualshelves to begin with, nothing happens.
483
nothing happens.
501
502
Returns 0 if no items have been deleted.
484
503
485
=cut
504
=cut
486
505
487
#'
488
sub DelFromShelf {
506
sub DelFromShelf {
489
    my ( $biblionumber, $shelfnumber ) = @_;
507
    my ($bibref, $shelfnumber, $user) = @_;
490
    my $query = qq(
508
    my $query = qq(SELECT allow_delete_own, allow_delete_other FROM virtualshelves WHERE shelfnumber=?);
491
        DELETE FROM virtualshelfcontents
509
    my $sth= $dbh->prepare($query);
492
        WHERE  shelfnumber=? AND biblionumber=?
510
    $sth->execute($shelfnumber);
493
    );
511
    my ($del_own, $del_oth)= $sth->fetchrow;
494
    my $sth = $dbh->prepare($query);
512
    my $r; my $t=0;
495
    $sth->execute( $shelfnumber, $biblionumber );
513
514
    if($del_own) {
515
        $query = qq(DELETE FROM virtualshelfcontents
516
            WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?);
517
        $sth= $dbh->prepare($query);
518
	foreach my $biblionumber (@$bibref) {
519
            $sth->execute($shelfnumber, $biblionumber, $user);
520
	    $r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1)
521
	    $t+= ($r==-1)? 1: $r;
522
	}
523
    }
524
    if($del_oth) {
525
        $query = qq(DELETE FROM virtualshelfcontents
526
            WHERE shelfnumber=? AND biblionumber=? AND borrowernumber<>?);
527
        $sth= $dbh->prepare($query);
528
	foreach my $biblionumber (@$bibref) {
529
            $sth->execute($shelfnumber, $biblionumber, $user);
530
	    $r= $sth->rows;
531
	    $t+= ($r==-1)? 1: $r;
532
	}
533
    }
534
    return $t;
496
}
535
}
497
536
498
=head2 DelShelf (old version)
537
=head2 DelShelf
499
500
  ($status, $msg) = &DelShelf($shelfnumber);
501
502
Deletes virtual virtualshelves number C<$shelfnumber>. The virtualshelves must
503
be empty.
504
505
Returns a two-element array, where C<$status> is 0 if the operation
506
was successful, or non-zero otherwise. C<$msg> is "Done" in case of
507
success, or an error message giving the reason for failure.
508
509
=head2 DelShelf (current version)
510
538
511
  $Number = DelShelf($shelfnumber);
539
  $Number = DelShelf($shelfnumber);
512
540
513
This function deletes the shelf number, and all of it's content.
541
This function deletes the shelf number, and all of it's content.
542
Authorization to do so MUST have been checked before calling, while using
543
ShelfPossibleAction with manage parameter.
514
544
515
=cut
545
=cut
516
546
517
sub DelShelf {
547
sub DelShelf {
518
	unless (@_) {
548
    my ($shelfnumber)= @_;
519
		carp "DelShelf called without valid argument (shelfnumber)";
549
    return unless $shelfnumber && $shelfnumber =~ /^\d+$/;
520
		return undef;
550
    my $sth = $dbh->prepare("DELETE FROM virtualshelves WHERE shelfnumber=?");
521
	}
551
    return $sth->execute($shelfnumber);
522
	my $sth = $dbh->prepare("DELETE FROM virtualshelves WHERE shelfnumber=?");
523
	return $sth->execute(shift);
524
}
552
}
525
553
526
=head2 GetBibShelves
554
=head2 GetBibliosShelves
527
555
528
This finds all the public lists that this bib record is in.
556
This finds all the public lists that this bib record is in.
529
557
Lines 536-600 sub GetBibliosShelves { Link Here
536
        SELECT vs.shelfname, vs.shelfnumber 
564
        SELECT vs.shelfname, vs.shelfnumber 
537
        FROM virtualshelves vs 
565
        FROM virtualshelves vs 
538
        JOIN virtualshelfcontents vc ON (vs.shelfnumber= vc.shelfnumber) 
566
        JOIN virtualshelfcontents vc ON (vs.shelfnumber= vc.shelfnumber) 
539
        WHERE vs.category != 1 
567
        WHERE vs.category=2
540
        AND vc.biblionumber= ?
568
        AND vc.biblionumber= ?
541
    ');
569
    ');
542
    $sth->execute( $biblionumber );
570
    $sth->execute( $biblionumber );
543
    return $sth->fetchall_arrayref({});
571
    return $sth->fetchall_arrayref({});
544
}
572
}
545
573
546
=head2 RefreshShelvesSummary
574
=head2 ShelvesMax
547
575
548
	($total, $pubshelves, $barshelves) = RefreshShelvesSummary($sessionID, $loggedinuser, $row_count);
576
    $howmany= ShelvesMax($context);
549
577
550
Updates the current session and userenv with the most recent shelves
578
Tells how much shelves are shown in which context.
551
579
POPUP refers to addbybiblionumber popup, MGRPAGE is managing page (in opac or
552
Returns the total number of shelves stored in the session/userenv along with two references each to an
580
staff), COMBO refers to the Add to-combo of search results. MASTHEAD is the
553
array of hashes, one containing the C<$loggedinuser>'s private shelves and one containing all public/open shelves.
581
main Koha toolbar with Lists button.
554
555
This function is used in conjunction with the 'Lists' button in masthead.inc.
556
582
557
=cut
583
=cut
558
584
559
sub RefreshShelvesSummary ($$$) {
585
sub ShelvesMax {
560
	require C4::Auth;
586
  my $which= shift;
561
	my ($sessionID, $loggedinuser, $row_count) = @_;
587
  return SHELVES_POPUP_MAX if $which eq 'POPUP';
562
	my $session = C4::Auth::get_session($sessionID);
588
  return SHELVES_MGRPAGE_MAX if $which eq 'MGRPAGE';
563
	my ($total, $totshelves, $barshelves, $pubshelves);
589
  return SHELVES_COMBO_MAX if $which eq 'COMBO';
564
590
  return SHELVES_MASTHEAD_MAX if $which eq 'MASTHEAD';
565
	($barshelves, $totshelves) = GetRecentShelves(1, $row_count, $loggedinuser);
591
  return SHELVES_MASTHEAD_MAX;
566
	$total->{'bartotal'} = $totshelves;
567
	($pubshelves, $totshelves) = GetRecentShelves(2, $row_count, undef);
568
	$total->{'pubtotal'} = $totshelves;
569
570
	# Update the current session with the latest shelves...
571
	$session->param('barshelves', $barshelves);
572
	$session->param('pubshelves', $pubshelves);
573
	$session->param('totshelves', $total);
574
575
	# likewise the userenv...
576
	C4::Context->set_shelves_userenv('bar',$barshelves);
577
	C4::Context->set_shelves_userenv('pub',$pubshelves);
578
	C4::Context::set_shelves_userenv('tot',$total);
579
580
	return ($total, $pubshelves, $barshelves);
581
}
592
}
582
593
583
# internal subs
594
# internal subs
584
595
585
sub _shelf_count ($$) {
596
sub _shelf_count {
586
	my (@params) = @_;
597
    my ($owner, $category) = @_;
587
	# Find out how many shelves total meet the submitted criteria...
598
    my @params;
588
	my $query = "SELECT count(*) FROM virtualshelves";
599
    # Find out how many shelves total meet the submitted criteria...
589
	$query .= ($params[1] > 1) ? " WHERE category >= ?" : " WHERE  owner=? AND category=?";
600
590
	shift @params if $params[1] > 1;
601
    my $query = "SELECT count(*) FROM virtualshelves vs ";
591
	my $sth = $dbh->prepare($query);
602
    if($category==1) {
592
	$sth->execute(@params);
603
        $query.= qq{
593
	my $total = $sth->fetchrow;
604
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
594
	return $total;
605
            AND sh.borrowernumber=?
606
	    WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
607
        @params= ($owner, $owner, $owner);
608
    }
609
    else {
610
	$query.='WHERE category=2';
611
        @params= ();
612
    }
613
    my $sth = $dbh->prepare($query);
614
    $sth->execute(@params);
615
    my ($total)= $sth->fetchrow;
616
    return $total;
595
}
617
}
596
618
597
sub _biblionumber_sth {
619
sub _biblionumber_sth { #only used in obsolete sub below
598
    my ($shelf) = @_;
620
    my ($shelf) = @_;
599
    my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?';
621
    my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?';
600
    my $dbh = C4::Context->dbh;
622
    my $dbh = C4::Context->dbh;
Lines 605-611 sub _biblionumber_sth { Link Here
605
    $sth;
627
    $sth;
606
}
628
}
607
629
608
sub each_biblionumbers (&$) {
630
sub each_biblionumbers (&$) { #OBSOLETE
609
    my ($code,$shelf) = @_;
631
    my ($code,$shelf) = @_;
610
    my $ref =  _biblionumber_sth($shelf)->fetchall_arrayref;
632
    my $ref =  _biblionumber_sth($shelf)->fetchall_arrayref;
611
    map {
633
    map {
Lines 614-619 sub each_biblionumbers (&$) { Link Here
614
    } @$ref;
636
    } @$ref;
615
}
637
}
616
638
639
sub _CheckShelfName {
640
    my ($name, $cat, $owner, $number)= @_;
641
642
    my $query = qq(
643
        SELECT DISTINCT shelfnumber
644
        FROM   virtualshelves
645
	LEFT JOIN virtualshelfshares sh USING (shelfnumber)
646
        WHERE  shelfname=? AND shelfnumber<>?);
647
    if($cat==1) {
648
        $query.= ' AND (sh.borrowernumber=? OR owner=?) AND category=1';
649
    }
650
    else {
651
        $query.= ' AND category=2';
652
    }
653
    my $sth = $dbh->prepare($query);
654
    $sth->execute($cat==1? ($name, $number, $owner, $owner): ($name, $number));
655
    return $sth->rows>0? 0: 1;
656
}
657
617
1;
658
1;
618
659
619
__END__
660
__END__
(-)a/C4/VirtualShelves/Page.pm (-56 / +86 lines)
Lines 22-29 package C4::VirtualShelves::Page; Link Here
22
22
23
use strict;
23
use strict;
24
use warnings;
24
use warnings;
25
25
use CGI;
26
use CGI;
26
use C4::VirtualShelves qw/:DEFAULT RefreshShelvesSummary/;
27
use Exporter;
28
use Data::Dumper;
29
30
use C4::VirtualShelves qw/:DEFAULT ShelvesMax/;
27
use C4::Biblio;
31
use C4::Biblio;
28
use C4::Items;
32
use C4::Items;
29
use C4::Koha;
33
use C4::Koha;
Lines 32-42 use C4::Members; Link Here
32
use C4::Output;
36
use C4::Output;
33
use C4::Dates qw/format_date/;
37
use C4::Dates qw/format_date/;
34
use C4::Tags qw(get_tags);
38
use C4::Tags qw(get_tags);
35
use Exporter;
36
use Data::Dumper;
37
use C4::Csv;
39
use C4::Csv;
38
use C4::XSLT;
40
use C4::XSLT;
39
41
42
use constant VIRTUALSHELVES_COUNT => 20;
43
40
use vars qw($debug @EXPORT @ISA $VERSION);
44
use vars qw($debug @EXPORT @ISA $VERSION);
41
45
42
BEGIN {
46
BEGIN {
Lines 51-62 our %pages = ( Link Here
51
    opac     => { redirect => '/cgi-bin/koha/opac-shelves.pl', },
55
    opac     => { redirect => '/cgi-bin/koha/opac-shelves.pl', },
52
);
56
);
53
57
54
sub shelfpage ($$$$$) {
58
sub shelfpage {
55
    my ( $type, $query, $template, $loggedinuser, $cookie ) = @_;
59
    my ( $type, $query, $template, $loggedinuser, $cookie ) = @_;
56
    ( $pages{$type} ) or $type = 'opac';
60
    ( $pages{$type} ) or $type = 'opac';
57
    $query            or die "No query";
61
    $query            or die "No query";
58
    $template         or die "No template";
62
    $template         or die "No template";
59
    $template->param(  loggedinuser => $loggedinuser  );
63
    $template->param(
64
	loggedinuser => $loggedinuser,
65
	OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
66
    );
60
    my $edit;
67
    my $edit;
61
    my $shelves;
68
    my $shelves;
62
    my @paramsloop;
69
    my @paramsloop;
Lines 77-83 sub shelfpage ($$$$$) { Link Here
77
    }
84
    }
78
85
79
    $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') );
86
    $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') );
80
    $shelflimit = $shelflimit || 20;
87
    $shelflimit = $shelflimit || ShelvesMax('MGRPAGE');
81
    $shelfoffset   = ( $itemoff - 1 ) * $shelflimit;     # Sets the offset to begin retrieving items at
88
    $shelfoffset   = ( $itemoff - 1 ) * $shelflimit;     # Sets the offset to begin retrieving items at
82
    $shelveslimit  = $shelflimit;                        # Limits number of shelves returned for a given query (row_count)
89
    $shelveslimit  = $shelflimit;                        # Limits number of shelves returned for a given query (row_count)
83
    $shelvesoffset = ( $shelfoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving shelves at (offset)
90
    $shelvesoffset = ( $shelfoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving shelves at (offset)
Lines 92-127 sub shelfpage ($$$$$) { Link Here
92
    }
99
    }
93
    my $op = $query->param('op');
100
    my $op = $query->param('op');
94
101
95
    #    my $imgdir = getitemtypeimagesrc();
96
    #    my $itemtypes = GetItemTypes();
97
98
    # the format of this is unindented for ease of diff comparison to the old script
102
    # the format of this is unindented for ease of diff comparison to the old script
99
    # Note: do not mistake the assignment statements below for comparisons!
103
    # Note: do not mistake the assignment statements below for comparisons!
100
    if ( $query->param('modifyshelfcontents') ) {
104
    if ( $query->param('modifyshelfcontents') ) {
101
        my ( $shelfnumber, $barcode, $item, $biblio );
105
        my ( $shelfnumber, $barcode, $item, $biblio );
102
        if ( $shelfnumber = $query->param('viewshelf') ) {
106
        if ( $shelfnumber = $query->param('viewshelf') ) {
103
            if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
107
            #add to shelf
104
                if ( $barcode = $query->param('addbarcode') ) {
108
            if($barcode = $query->param('addbarcode') ) {
105
                    $item = GetItem( 0, $barcode );
109
                if(ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')) {
106
                    if (defined $item && $item->{'itemnumber'}){
110
                    $item = GetItem( 0, $barcode);
111
                    if (defined $item && $item->{'itemnumber'}) {
107
                        $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'} );
112
                        $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'} );
108
                        AddToShelf( $biblio->{'biblionumber'}, $shelfnumber )
113
                        AddToShelf( $biblio->{'biblionumber'}, $shelfnumber, $loggedinuser)
109
                          or push @paramsloop, { duplicatebiblio => $barcode };
114
                          or push @paramsloop, { duplicatebiblio => $barcode };
110
                    } else {
115
                    }
116
                    else {
111
                        push @paramsloop, { failgetitem => $barcode };
117
                        push @paramsloop, { failgetitem => $barcode };
112
                    }
118
                    }
113
                } else {
119
                }
114
                    ( grep { /REM-(\d+)/ } $query->param ) or push @paramsloop, { nobarcode => 1 };
120
                else {
115
                    foreach ( $query->param ) {
121
                    push @paramsloop, { nopermission => $shelfnumber };
122
                }
123
            }
124
            elsif(grep { /REM-(\d+)/ } $query->param) {
125
            #remove item(s) from shelf
126
                if(ShelfPossibleAction($loggedinuser, $shelfnumber, 'delete')) {
127
                #This is just a general okay; DelFromShelf checks further
128
                    my @bib;
129
                    foreach($query->param) {
116
                        /REM-(\d+)/ or next;
130
                        /REM-(\d+)/ or next;
117
                        $debug and warn "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber";
131
                        push @bib, $1; #$1 is biblionumber
118
                        DelFromShelf( $1, $shelfnumber );    # $1 is biblionumber
132
                    }
133
                    my $t= DelFromShelf(\@bib, $shelfnumber, $loggedinuser);
134
                    if($t==0) {
135
                        push @paramsloop, {nothingdeleted => $shelfnumber};
136
                    }
137
                    elsif($t<@bib) {
138
                        push @paramsloop, {somedeleted => $shelfnumber};
119
                    }
139
                    }
120
                }
140
                }
121
            } else {
141
                else {
122
                push @paramsloop, { nopermission => $shelfnumber };
142
                    push @paramsloop, { nopermission => $shelfnumber };
143
                }
123
            }
144
            }
124
        } else {
145
        }
146
        else {
125
            push @paramsloop, { noshelfnumber => 1 };
147
            push @paramsloop, { noshelfnumber => 1 };
126
        }
148
        }
127
    }
149
    }
Lines 156-173 sub shelfpage ($$$$$) { Link Here
156
178
157
  SWITCH: {
179
  SWITCH: {
158
        if ($op) {
180
        if ($op) {
159
            unless ($okmanage) {
181
	    #Saving modified shelf
160
                push @paramsloop, { nopermission => $shelfnumber };
161
                last SWITCH;
162
            }
163
            if ( $op eq 'modifsave' ) {
182
            if ( $op eq 'modifsave' ) {
183
                unless ($okmanage) {
184
                        push @paramsloop, { nopermission => $shelfnumber };
185
                        last SWITCH;
186
                }
164
                my $shelf = {
187
                my $shelf = {
165
                    'shelfname' => $query->param('shelfname'),
188
                    'shelfname' => $query->param('shelfname'),
166
                    'category'  => $query->param('category'),
167
                    'sortfield' => $query->param('sortfield'),
189
                    'sortfield' => $query->param('sortfield'),
168
                };
190
                };
191
                if($query->param('category')) { #optional
192
                    $shelf->{category}= $query->param('category');
193
                }
194
                unless(ModShelf($shelfnumber, $shelf )) {
195
                  push @paramsloop, {modifyfailure => $shelf->{shelfname}};
196
                  last SWITCH;
197
                }
169
198
170
                ModShelf( $shelfnumber, $shelf );
171
                if($displaymode eq "viewshelf"){
199
                if($displaymode eq "viewshelf"){
172
                    print $query->redirect( $pages{$type}->{redirect} . "?viewshelf=$shelfnumber" );
200
                    print $query->redirect( $pages{$type}->{redirect} . "?viewshelf=$shelfnumber" );
173
                } elsif($displaymode eq "publicshelves"){
201
                } elsif($displaymode eq "publicshelves"){
Lines 176-187 sub shelfpage ($$$$$) { Link Here
176
                    print $query->redirect( $pages{$type}->{redirect} . "?display=privateshelves" );
204
                    print $query->redirect( $pages{$type}->{redirect} . "?display=privateshelves" );
177
                }
205
                }
178
                exit;
206
                exit;
179
207
            }
180
            } elsif ( $op eq 'modif' ) {
208
	    #Editing a shelf
209
            elsif ( $op eq 'modif' ) {
181
                my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) = GetShelf($shelfnumber);
210
                my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) = GetShelf($shelfnumber);
182
                my $member = GetMember( 'borrowernumber' => $owner );
211
                my $member = GetMember( 'borrowernumber' => $owner );
183
                my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
212
                my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
184
                $edit = 1;
213
                $edit = 1;
214
                $sortfield='' unless $sortfield;
185
                $template->param(
215
                $template->param(
186
                    edit                => 1,
216
                    edit                => 1,
187
                    display             => $displaymode,
217
                    display             => $displaymode,
Lines 196-201 sub shelfpage ($$$$$) { Link Here
196
            }
226
            }
197
            last SWITCH;
227
            last SWITCH;
198
        }
228
        }
229
230
        #View a shelf
199
        if ( $shelfnumber = $query->param('viewshelf') ) {
231
        if ( $shelfnumber = $query->param('viewshelf') ) {
200
            # explicitly fetch this shelf
232
            # explicitly fetch this shelf
201
            my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber);
233
            my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber);
Lines 267-287 sub shelfpage ($$$$$) { Link Here
267
                    authorsort          => $authorsort,
299
                    authorsort          => $authorsort,
268
                    yearsort            => $yearsort,
300
                    yearsort            => $yearsort,
269
                    manageshelf         => $manageshelf,
301
                    manageshelf         => $manageshelf,
302
                    allowremovingitems  => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete'),
303
                    allowaddingitem     => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add'),
270
                    "category$category" => 1,
304
                    "category$category" => 1,
271
                    category            => $category,
305
                    category            => $category,
272
                    itemsloop           => $items,
306
                    itemsloop           => $items,
307
                    showprivateshelves  => $category==1,
273
                );
308
                );
274
            } else {
309
            } else {
275
                push @paramsloop, { nopermission => $shelfnumber };
310
                push @paramsloop, { nopermission => $shelfnumber };
276
            }
311
            }
277
            last SWITCH;
312
            last SWITCH;
278
        }
313
        }
314
279
        if ( $query->param('shelves') ) {
315
        if ( $query->param('shelves') ) {
280
            my $stay = 1;
316
            my $stay = 1;
317
318
	    #Add a shelf
281
            if ( my $newshelf = $query->param('addshelf') ) {
319
            if ( my $newshelf = $query->param('addshelf') ) {
282
320
283
                # note: a user can always add a new shelf
321
                # note: a user can always add a new shelf
284
                my $shelfnumber = AddShelf( $newshelf, $query->param('owner'), $query->param('category'), $query->param('sortfield') );
322
                my $shelfnumber = AddShelf( {
323
                    shelfname => $newshelf,
324
                    sortfield => $query->param('sortfield'),
325
                    category => $query->param('category') },
326
                    $query->param('owner') );
285
                $stay = 1;
327
                $stay = 1;
286
                if ( $shelfnumber == -1 ) {    #shelf already exists.
328
                if ( $shelfnumber == -1 ) {    #shelf already exists.
287
                    $showadd = 1;
329
                    $showadd = 1;
Lines 292-297 sub shelfpage ($$$$$) { Link Here
292
                    exit;
334
                    exit;
293
                }
335
                }
294
            }
336
            }
337
338
	    #Deleting a shelf (asking for confirmation if it has entries)
295
            foreach ( $query->param() ) {
339
            foreach ( $query->param() ) {
296
                /DEL-(\d+)/ or next;
340
                /DEL-(\d+)/ or next;
297
                $delflag = 1;
341
                $delflag = 1;
Lines 333-339 sub shelfpage ($$$$$) { Link Here
333
                }
377
                }
334
                push( @paramsloop, { delete_ok => $name } );
378
                push( @paramsloop, { delete_ok => $name } );
335
379
336
                # print $query->redirect($pages{$type}->{redirect}); exit;
337
                $stay = 0;
380
                $stay = 0;
338
            }
381
            }
339
            $showadd = 1;
382
            $showadd = 1;
Lines 343-349 sub shelfpage ($$$$$) { Link Here
343
            }
386
            }
344
            last SWITCH;
387
            last SWITCH;
345
        }
388
        }
346
    }
389
    } # end of SWITCH block
347
390
348
    (@paramsloop) and $template->param( paramsloop => \@paramsloop );
391
    (@paramsloop) and $template->param( paramsloop => \@paramsloop );
349
    $showadd      and $template->param( showadd    => 1 );
392
    $showadd      and $template->param( showadd    => 1 );
Lines 357-363 sub shelfpage ($$$$$) { Link Here
357
        my %line;
400
        my %line;
358
        $shelflist->{$element}->{shelf} = $element;
401
        $shelflist->{$element}->{shelf} = $element;
359
        my $category  = $shelflist->{$element}->{'category'};
402
        my $category  = $shelflist->{$element}->{'category'};
360
        my $owner     = $shelflist->{$element}->{'owner'};
403
        my $owner     = $shelflist->{$element}->{'owner'}||0;
361
        my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
404
        my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
362
        my $sortfield = $shelflist->{$element}->{'sortfield'};
405
        my $sortfield = $shelflist->{$element}->{'sortfield'};
363
        if ( $sortfield ){
406
        if ( $sortfield ){
Lines 369-375 sub shelfpage ($$$$$) { Link Here
369
        }
412
        }
370
        $shelflist->{$element}->{"viewcategory$category"} = 1;
413
        $shelflist->{$element}->{"viewcategory$category"} = 1;
371
        $shelflist->{$element}->{manageshelf} = $canmanage;
414
        $shelflist->{$element}->{manageshelf} = $canmanage;
372
        if ( $owner eq $loggedinuser or $canmanage ) {
415
        if($canmanage || ($loggedinuser && $owner==$loggedinuser)) {
373
            $shelflist->{$element}->{'mine'} = 1;
416
            $shelflist->{$element}->{'mine'} = 1;
374
        }
417
        }
375
        my $member = GetMember( 'borrowernumber' => $owner );
418
        my $member = GetMember( 'borrowernumber' => $owner );
Lines 413-440 sub shelfpage ($$$$$) { Link Here
413
        $template->param( seflag => 1 );
456
        $template->param( seflag => 1 );
414
    }
457
    }
415
458
416
    #FIXME: This refresh really only needs to happen when there is a modification of some sort
459
#Next call updates the shelves for the Lists button.
417
    #       to the shelves, but the above code is so convoluted in its handling of the various
460
#May not always be needed (when nothing changed), but doesn't take much.
418
    #       options, it is easier to do this refresh every time C4::VirtualShelves::Page.pm is
461
    my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($loggedinuser, 'MASTHEAD');
419
    #       called
462
    $template->param(
420
463
            barshelves     => $total->{bartotal},
421
    my ( $total, $pubshelves, $barshelves ) = RefreshShelvesSummary( $query->cookie("CGISESSID"), $loggedinuser, ( $loggedinuser == -1 ? 20 : 10 ) );
422
423
    if ( defined $barshelves ) {
424
        $template->param(
425
            barshelves     => scalar( @{ $barshelves } ),
426
            barshelvesloop => $barshelves,
464
            barshelvesloop => $barshelves,
427
        );
465
            pubshelves     => $total->{pubtotal},
428
        $template->param( bartotal => $total->{'bartotal'}, ) if ( $total->{'bartotal'} > scalar( @{ $barshelves } ) );
429
    }
430
431
    if ( defined $pubshelves ) {
432
        $template->param(
433
            pubshelves     => scalar( @{ $pubshelves } ),
434
            pubshelvesloop => $pubshelves,
466
            pubshelvesloop => $pubshelves,
435
        );
467
    );
436
        $template->param( pubtotal => $total->{'pubtotal'}, ) if ( $total->{'pubtotal'} > scalar( @{ $pubshelves } ) );
437
    }
438
468
439
    output_html_with_http_headers $query, $cookie, $template->output;
469
    output_html_with_http_headers $query, $cookie, $template->output;
440
}
470
}
(-)a/catalogue/search.pl (-17 / +9 lines)
Lines 147-153 use C4::Search; Link Here
147
use C4::Languages qw(getAllLanguages);
147
use C4::Languages qw(getAllLanguages);
148
use C4::Koha;
148
use C4::Koha;
149
use C4::Members qw(GetMember);
149
use C4::Members qw(GetMember);
150
use C4::VirtualShelves qw(GetRecentShelves);
150
use C4::VirtualShelves;
151
use POSIX qw(ceil floor);
151
use POSIX qw(ceil floor);
152
use C4::Branch; # GetBranches
152
use C4::Branch; # GetBranches
153
153
Lines 701-721 if ($query_desc || $limit_desc) { Link Here
701
# VI. BUILD THE TEMPLATE
701
# VI. BUILD THE TEMPLATE
702
702
703
# Build drop-down list for 'Add To:' menu...
703
# Build drop-down list for 'Add To:' menu...
704
704
my ($totalref, $pubshelves, $barshelves)=
705
my $row_count = 10; # FIXME:This probably should be a syspref
705
	C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1);
706
my ($pubshelves, $total) = GetRecentShelves(2, $row_count, undef);
706
$template->param(
707
my ($barshelves, $total) = GetRecentShelves(1, $row_count, $borrowernumber);
707
        addbarshelves     => $totalref->{bartotal},
708
708
        addbarshelvesloop => $barshelves,
709
if (@{$pubshelves}) {
709
	addpubshelves     => $totalref->{pubtotal},
710
        $template->param( addpubshelves     => scalar @{$pubshelves});
710
	addpubshelvesloop => $pubshelves,
711
        $template->param( addpubshelvesloop => $pubshelves);
711
	);
712
}
713
714
if (@{$barshelves}) {
715
        $template->param( addbarshelves     => scalar @{$barshelves});
716
        $template->param( addbarshelvesloop => $barshelves);
717
}
718
719
720
712
721
output_html_with_http_headers $cgi, $cookie, $template->output;
713
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt (-6 / +30 lines)
Lines 7-12 Link Here
7
</head>
7
</head>
8
<body>
8
<body>
9
9
10
[% UNLESS (authorized) %]
11
    <p align="center">
12
        [% IF (errcode==1) %]Could not make new shelf. Please check the name.<br/>[% END %]
13
        [% IF (errcode==2) %]Sorry, you do not have permission to add items to this list.<br/>[% END %]
14
        <a href="javascript:self.close();">Close this window.</a>
15
    </p>
16
[% ELSE %]
10
<div id="custom-doc" class="yui-t7">
17
<div id="custom-doc" class="yui-t7">
11
   <div id="bd">
18
   <div id="bd">
12
                [% IF ( multiple ) %]
19
                [% IF ( multiple ) %]
Lines 29-39 Link Here
29
36
30
[% UNLESS ( shelfnumber ) %]
37
[% UNLESS ( shelfnumber ) %]
31
38
32
[% IF ( CGIvirtualshelves ) %]    [% UNLESS ( newshelf ) %]
39
[% UNLESS ( newshelf ) %]
33
     <fieldset class="rows">
40
     <fieldset class="rows">
34
	<legend>Select an existing list</legend>
41
	<legend>Select an existing list</legend>
35
	<ol>
42
	<ol>
36
	    <li><label>Choose list</label>[% CGIvirtualshelves %]</li>
43
	    <li>
44
		<label>Choose list</label>
45
		<select name="shelfnumber" id="shelfnumber">
46
		[% IF ( privatevirtualshelves ) %]
47
		<optgroup label="Private Lists">
48
		[% FOREACH privatevirtualshelve IN privatevirtualshelves %]
49
		<option value="[% privatevirtualshelve.shelfnumber %]">[% privatevirtualshelve.shelfname %]</option>
50
		[% END %]
51
		</optgroup>
52
		[% END %]
53
		[% IF ( publicvirtualshelves ) %]
54
		<optgroup label="Public Lists">
55
		[% FOREACH publicvirtualshelve IN publicvirtualshelves %]
56
		<option value="[% publicvirtualshelve.shelfnumber %]">[% publicvirtualshelve.shelfname %]</option>
57
		[% END %]
58
		</optgroup>
59
		[% END %]
60
		</select>
61
	    </li>
37
	</ol>
62
	</ol>
38
	[% FOREACH biblio IN biblios %]<input type="hidden" name="biblionumber" value="[% biblio.biblionumber %]" />[% END %]
63
	[% FOREACH biblio IN biblios %]<input type="hidden" name="biblionumber" value="[% biblio.biblionumber %]" />[% END %]
39
	[% UNLESS ( biblionumbers ) %]
64
	[% UNLESS ( biblionumbers ) %]
Lines 43-51 Link Here
43
	[% END %]
68
	[% END %]
44
	</fieldset>
69
	</fieldset>
45
70
46
	<p>... or...</p> [% END %]
71
	<p>... or...</p>
47
72
[% END %]
48
    [% END %]
49
73
50
    <fieldset class="rows"><legend>Add to a new list:</legend>
74
    <fieldset class="rows"><legend>Add to a new list:</legend>
51
	<ol><li>
75
	<ol><li>
Lines 66-72 Link Here
66
	    <select name="category" id="category">
90
	    <select name="category" id="category">
67
		<option value="1">Private</option>
91
		<option value="1">Private</option>
68
		<option value="2">Public</option>
92
		<option value="2">Public</option>
69
		<option value="3">Open</option>
70
	    </select>
93
	    </select>
71
	</li></ol>
94
	</li></ol>
72
    </fieldset>
95
    </fieldset>
Lines 85-87 Link Here
85
</div>
108
</div>
86
109
87
[% INCLUDE 'intranet-bottom.inc' %]
110
[% INCLUDE 'intranet-bottom.inc' %]
111
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-18 / +10 lines)
Lines 24-30 $(document).ready(function(){ Link Here
24
24
25
	function confirmDelete(message){
25
	function confirmDelete(message){
26
		if (window.confirm(message)) {
26
		if (window.confirm(message)) {
27
		    location.href="/cgi-bin/koha/virtualshelves/shelves.pl?[% IF ( showprivateshelves ) %] display=privateshelves&[% END %]shelves=1&DEL-[% shelfnumber %]=1&shelfoff=[% shelfoff %]";
27
		    location.href="/cgi-bin/koha/virtualshelves/shelves.pl?[% IF ( showprivateshelves ) %]display=privateshelves&[% END %]shelves=1&DEL-[% shelfnumber %]=1&shelfoff=[% shelfoff %]";
28
		} else { 
28
		} else { 
29
			return false;
29
			return false;
30
		}
30
		}
Lines 162-168 function placeHold () { Link Here
162
 <fieldset>
162
 <fieldset>
163
  <legend>Contents of <i>[% shelfname | html %]</i></legend>
163
  <legend>Contents of <i>[% shelfname | html %]</i></legend>
164
   
164
   
165
 [% IF ( manageshelf ) %]
165
 [% IF ( itemsloop ) %]
166
     <p><span class="checkall"></span> |
166
     <p><span class="checkall"></span> |
167
     <span class="clearall"></span></p>
167
     <span class="clearall"></span></p>
168
 [% END %]
168
 [% END %]
Lines 170-176 function placeHold () { Link Here
170
 <div class="pages">[% pagination_bar %]</div>
170
 <div class="pages">[% pagination_bar %]</div>
171
    <table>
171
    <table>
172
            <tr>
172
            <tr>
173
                [% IF ( manageshelf ) %]<th class="checkall">&nbsp;</th>[% END %]
173
                [% IF ( itemsloop ) %]<th class="checkall">&nbsp;</th>[% END %]
174
                [% UNLESS ( item_level_itypes ) %]<th>Item Type</th>[% END %]
174
                [% UNLESS ( item_level_itypes ) %]<th>Item Type</th>[% END %]
175
                <th>Title</th>
175
                <th>Title</th>
176
                <th>Author</th>
176
                <th>Author</th>
Lines 183-189 function placeHold () { Link Here
183
			[% ELSE %]
183
			[% ELSE %]
184
			<tr>
184
			<tr>
185
			[% END %]
185
			[% END %]
186
			[% IF ( manageshelf ) %]
186
			[% IF ( itemsloop ) %]
187
			<td>
187
			<td>
188
				[% IF ( itemsloo.confirm ) %]
188
				[% IF ( itemsloo.confirm ) %]
189
				<input type="hidden"   name="CONFIRM-[% itemsloo.confirm %]" />
189
				<input type="hidden"   name="CONFIRM-[% itemsloo.confirm %]" />
Lines 210-218 function placeHold () { Link Here
210
			</tr>
210
			</tr>
211
		[% END %]<!-- /itemsloop -->
211
		[% END %]<!-- /itemsloop -->
212
    </table><fieldset class="action">
212
    </table><fieldset class="action">
213
        [% IF ( manageshelf ) %]
213
        [% IF ( itemsloop ) %]
214
            <input type="button" id="placehold" style="display:none" onclick="placeHold(); return false;" value="Place Holds" />
214
            <input type="button" id="placehold" style="display:none" onclick="placeHold(); return false;" value="Place Holds" />
215
            <input type="submit" value="Remove selected records" onclick="return confirm(_('Are you sure you want to remove these records from the shelf?'));" />
215
            [% IF ( allowremovingitems ) %]<input type="submit" value="Remove selected records" onclick="return confirm(_('Are you sure you want to remove these records from the shelf?'));" />[% END %]
216
            <input type="submit" value="Merge selected records" onclick="return MergeItems();" />
216
            <input type="submit" value="Merge selected records" onclick="return MergeItems();" />
217
        [% END %]
217
        [% END %]
218
 </fieldset>
218
 </fieldset>
Lines 223-229 function placeHold () { Link Here
223
   </div>
223
   </div>
224
[% END %]<!-- /viewshelf -->
224
[% END %]<!-- /viewshelf -->
225
225
226
[% IF ( manageshelf ) %]
226
[% IF ( allowaddingitem ) %]
227
<div class="yui-g">
227
<div class="yui-g">
228
<form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="post">
228
<form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="post">
229
 <fieldset class="brief">
229
 <fieldset class="brief">
Lines 240-246 function placeHold () { Link Here
240
 </fieldset>
240
 </fieldset>
241
</form>
241
</form>
242
</div>
242
</div>
243
[% END %]<!-- /manageshelf -->
243
[% END %]<!-- /allowaddingitem -->
244
244
245
[% IF ( debug ) %]
245
[% IF ( debug ) %]
246
  [% IF ( edit ) %]<div>Edit is on ([% shelfname | html %])</div>[% END %]
246
  [% IF ( edit ) %]<div>Edit is on ([% shelfname | html %])</div>[% END %]
Lines 269-275 function placeHold () { Link Here
269
			<select name="category" id="category">
269
			<select name="category" id="category">
270
                  <option value="1">Private</option>
270
                  <option value="1">Private</option>
271
                  <option value="2">Public</option>
271
                  <option value="2">Public</option>
272
                  <option value="3">Open</option>
273
			</select></li></ol>
272
			</select></li></ol>
274
    [% END %]
273
    [% END %]
275
274
Lines 299-309 function placeHold () { Link Here
299
			[% ELSE %]
298
			[% ELSE %]
300
				<option value="2">Public</option>
299
				<option value="2">Public</option>
301
			[% END %]
300
			[% END %]
302
			[% IF ( category3 ) %]
303
				<option value="3" selected="selected">Open</option>
304
			[% ELSE %]
305
				<option value="3">Open</option>
306
			[% END %]
307
			</select></li></ol>
301
			</select></li></ol>
308
	[% END %]
302
	[% END %]
309
303
Lines 317-324 function placeHold () { Link Here
317
        <div class="help"><ul>
311
        <div class="help"><ul>
318
            <li>A <b>Private</b> List is managed by you and can be seen only by you.</li>
312
            <li>A <b>Private</b> List is managed by you and can be seen only by you.</li>
319
            <li> A <b>Public</b> List can be seen by everybody, but managed only by you.</li>
313
            <li> A <b>Public</b> List can be seen by everybody, but managed only by you.</li>
320
            <li> A <b>Open</b> List can be seen and managed by everybody.</li>
314
        </ul>
321
        </ul></div>
315
        </div>
322
    </div>
316
    </div>
323
</div>
317
</div>
324
[% END %]<!-- /seflag -->
318
[% END %]<!-- /seflag -->
Lines 354-360 function placeHold () { Link Here
354
        <td>[% IF ( shelveslooppri.authorsort ) %]Author[% ELSIF ( shelveslooppri.yearsort ) %]Year[% ELSE %]Title[% END %]</td>
348
        <td>[% IF ( shelveslooppri.authorsort ) %]Author[% ELSIF ( shelveslooppri.yearsort ) %]Year[% ELSE %]Title[% END %]</td>
355
        <td>[% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
349
        <td>[% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
356
			[% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
350
			[% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
357
			[% IF ( shelveslooppri.viewcategory3 ) %]Open[% END %]
358
		</td>
351
		</td>
359
        <td>
352
        <td>
360
            [% IF ( shelveslooppri.mine ) %]
353
            [% IF ( shelveslooppri.mine ) %]
Lines 408-414 function placeHold () { Link Here
408
        <td>[% IF ( shelvesloo.authorsort ) %]Author[% ELSIF ( shelvesloo.yearsort ) %]Year[% ELSE %]Title[% END %]</td>
401
        <td>[% IF ( shelvesloo.authorsort ) %]Author[% ELSIF ( shelvesloo.yearsort ) %]Year[% ELSE %]Title[% END %]</td>
409
        <td>[% IF ( shelvesloo.viewcategory1 ) %]Private[% END %]
402
        <td>[% IF ( shelvesloo.viewcategory1 ) %]Private[% END %]
410
			[% IF ( shelvesloo.viewcategory2 ) %]Public[% END %]
403
			[% IF ( shelvesloo.viewcategory2 ) %]Public[% END %]
411
			[% IF ( shelvesloo.viewcategory3 ) %]Open[% END %]
412
		</td>
404
		</td>
413
        <td>
405
        <td>
414
            [% IF ( shelvesloo.manageshelf ) %]
406
            [% IF ( shelvesloo.manageshelf ) %]
(-)a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc (-18 / +10 lines)
Lines 138-174 Link Here
138
			[% FOREACH pubshelvesloo IN pubshelvesloop %]
138
			[% FOREACH pubshelvesloo IN pubshelvesloop %]
139
			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=[% pubshelvesloo.shelfnumber %]&amp;sortfield=[% pubshelvesloo.sortfield %]">[% pubshelvesloo.shelfname |html %]</a></li>
139
			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=[% pubshelvesloo.shelfnumber %]&amp;sortfield=[% pubshelvesloo.sortfield %]">[% pubshelvesloo.shelfname |html %]</a></li>
140
			[% END %]
140
			[% END %]
141
			<li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl?display=publicshelves">[View All]</a></li>
141
			</ul>   
142
			</ul>   
142
		[% ELSE %]
143
		[% ELSE %]
143
			No Public Lists
144
			No Public Lists
144
		[% END %]
145
		[% END %]
145
		[% IF ( pubtotal ) %]
146
			<ul class="second-of-type">
147
            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl?display=publicshelves">View all [% pubtotal %] public lists</a></li>
148
			</ul>
149
		[% END %]
150
  [% IF ( opacuserlogin ) %]
146
  [% IF ( opacuserlogin ) %]
151
    [% IF ( loggedinusername ) %]
147
	<h4>Your Lists</h4>
152
<h4>Your Lists</h4>
148
	[% IF ( loggedinusername ) %]
153
		[% IF ( barshelves ) %]
149
		[% IF ( barshelves ) %]
154
			<ul class="first-of-type">
150
			<ul class="first-of-type">
155
			[% FOREACH barshelvesloo IN barshelvesloop %]
151
			[% FOREACH barshelvesloo IN barshelvesloop %]
156
			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=[% barshelvesloo.shelfnumber %]&amp;sortfield=[% barshelvesloo.sortfield %]">[% barshelvesloo.shelfname |html %]</a></li>
152
			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=[% barshelvesloo.shelfnumber %]&amp;sortfield=[% barshelvesloo.sortfield %]">[% barshelvesloo.shelfname |html %]</a></li>
157
			[% END %]
153
			[% END %]
154
			<li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">[View All]</a></li>
158
			</ul>   
155
			</ul>   
159
		[% ELSE %]
156
		[% ELSE %]
160
			No Private Lists
157
			<ul class="first-of-type">
161
		[% END %]
158
			<li>No Private Lists</li>
162
		[% IF ( bartotal ) %]
159
			<li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">[New List]</a></li></ul>
163
			<ul class="second-of-type">
164
            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">View all [% bartotal %] of your private lists</a></li>
165
			</ul>
166
		[% END %]
160
		[% END %]
167
		<ul class="second-of-type">
161
	[% ELSE %]
168
        <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl">Manage Lists</a></li>
162
		<ul class="first-of-type"><li><a href="/cgi-bin/koha/opac-user.pl">Log in to Create Your Own Lists</a></li></ul>
169
        </ul>
163
	[% END %]
170
    [% ELSE %]<ul class="first-of-type"><li><a href="/cgi-bin/koha/opac-user.pl">Log in to Create Your Own Lists</a></li></ul>
171
    [% END %]
172
  [% END %]
164
  [% END %]
173
	  </div>
165
	  </div>
174
</div><!-- /listmenu /virtualshelves -->
166
</div><!-- /listmenu /virtualshelves -->
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tt (-3 / +8 lines)
Lines 64-70 Link Here
64
		<li><label for="category">Category:</label>
64
		<li><label for="category">Category:</label>
65
		<select name="category" id="category">
65
		<select name="category" id="category">
66
		<option value="1">Private</option>
66
		<option value="1">Private</option>
67
		<option value="2">Public</option>
67
		[% IF (OpacAllowPublicListCreation) %]
68
			<option value="2">Public</option>
69
		[% END %]
68
		</select></li></ol></fieldset>
70
		</select></li></ol></fieldset>
69
		[% FOREACH biblio IN biblios %] <input type="hidden" name="biblionumber" value="[% biblio.biblionumber | html%]" />[% END %]
71
		[% FOREACH biblio IN biblios %] <input type="hidden" name="biblionumber" value="[% biblio.biblionumber | html%]" />[% END %]
70
		<fieldset class="action"><input type="submit" value="Save" class="submit" /> <a class="close cancel" href="#">Cancel</a></fieldset>
72
		<fieldset class="action"><input type="submit" value="Save" class="submit" /> <a class="close cancel" href="#">Cancel</a></fieldset>
Lines 72-79 Link Here
72
	[% END %]
74
	[% END %]
73
[% ELSE %]
75
[% ELSE %]
74
	<p align="center">
76
	<p align="center">
75
		This is not an open list.
77
	[% IF (errcode==1) %]
76
		Items cannot be added to it.
78
	Could not create new list. Please check if the name is unique.
79
	[% ELSE %]
80
	Sorry, you cannot add items to this list.
81
	[% END %]
77
	</p>
82
	</p>
78
[% END %]
83
[% END %]
79
<p align="center">
84
<p align="center">
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt (-11 / +21 lines)
Lines 131-137 $(function() { Link Here
131
            });
131
            });
132
        [% END %]
132
        [% END %]
133
        [% END %][% END %][% END %]
133
        [% END %][% END %][% END %]
134
  [% IF ( loggedinusername && manageshelf ) %]
134
  [% IF ( loggedinusername && allowremovingitems ) %]
135
  $("#myform").submit(function(){
135
  $("#myform").submit(function(){
136
    var checkedBoxes = $(".checkboxed input:checkbox:checked");
136
    var checkedBoxes = $(".checkboxed input:checkbox:checked");
137
    if ($(checkedBoxes).size()) {
137
    if ($(checkedBoxes).size()) {
Lines 210-215 $(function() { Link Here
210
                    [% IF ( paramsloo.unrecognized ) %]
210
                    [% IF ( paramsloo.unrecognized ) %]
211
                      <div class="dialog message">ERROR: List number [% paramsloo.unrecognized %] unrecognized.</div>
211
                      <div class="dialog message">ERROR: List number [% paramsloo.unrecognized %] unrecognized.</div>
212
                    [% END %]
212
                    [% END %]
213
                    [% IF ( paramsloo.modifyfailure) %]
214
                      <div class="dialog message">ERROR: Shelf could not be renamed to [% paramsloo.modifyfailure %]. This name may not be unique for this type of list. Please check.</div>
215
                    [% END %]
216
                    [% IF ( paramsloo.nothingdeleted) %]
217
                      <div class="dialog message">Warning: You could not delete any selected items from this shelf.</div>
218
                    [% END %]
219
                    [% IF ( paramsloo.somedeleted) %]
220
                      <div class="dialog message">Warning: You could not delete all selected items from this shelf.</div>
221
                    [% END %]
213
                  </div>
222
                  </div>
214
                </div>
223
                </div>
215
              [% END %]<!-- /paramsloop -->
224
              [% END %]<!-- /paramsloop -->
Lines 257-263 $(function() { Link Here
257
                                          </span>
266
                                          </span>
258
                                        [% END %]
267
                                        [% END %]
259
                                      [% END %]
268
                                      [% END %]
260
                    [% IF ( loggedinusername && manageshelf ) %]<span id="removeitems"></span>[% END %]</span>
269
                    [% IF ( loggedinusername && allowremovingitems ) %]<span id="removeitems"></span>[% END %]</span>
261
                  </div>
270
                  </div>
262
                  <form action="/cgi-bin/koha/opac-shelves.pl" method="post" id="myform" name="myform" class="checkboxed">
271
                  <form action="/cgi-bin/koha/opac-shelves.pl" method="post" id="myform" name="myform" class="checkboxed">
263
                [% IF ( manageshelf ) %]
272
                [% IF ( manageshelf ) %]
Lines 394-414 $(function() { Link Here
394
            [% END %]<!-- /viewshelf -->
403
            [% END %]<!-- /viewshelf -->
395
404
396
405
397
            [% IF ( manageshelf ) %]
406
            [% IF ( itemsloop && allowremovingitems ) %]
398
              <!-- Editing shelf -->
407
                <form method="post" action="opac-shelves.pl">
399
              [% IF ( itemsloop ) %]
400
                <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
408
                <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
401
                <input type="hidden" name="modifyshelfcontents" value="1" />
409
                <input type="hidden" name="modifyshelfcontents" value="1" />
402
                <input type="hidden" name="viewshelf" value="[% shelfnumber %]" /><input type="submit" value="Remove Selected Items" class="icon delete" />
410
                <input type="hidden" name="viewshelf" value="[% shelfnumber %]" /><input type="submit" value="Remove Selected Items" class="icon delete"/>
403
              [% ELSE %]
411
                </form>
412
            [% ELSIF ( !itemsloop && manageshelf ) %]
404
                <form method="post" action="opac-shelves.pl">
413
                <form method="post" action="opac-shelves.pl">
405
                  <input type="hidden" name="DEL-[% shelfnumber %]" value="1" />
414
                  <input type="hidden" name="DEL-[% shelfnumber %]" value="1" />
406
                  <input type="hidden" name="shelves" value="1" />
415
                  <input type="hidden" name="shelves" value="1" />
407
		  <input type="hidden" name="shelfoff" value="[% shelfoff %]" />
416
		  <input type="hidden" name="shelfoff" value="[% shelfoff %]" />
408
                  <input type="submit" class="icon delete" value="Delete this List" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST)" />
417
                  <input type="submit" class="icon delete" value="Delete this List" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST)" />
409
              [% END %]
410
            [% END %]
411
                </form>
418
                </form>
419
            [% END %]
412
420
413
            
421
            
414
            [% IF ( edit ) %]
422
            [% IF ( edit ) %]
Lines 429-439 $(function() { Link Here
429
                        </select>
437
                        </select>
430
                      </li>
438
                      </li>
431
                      <li>
439
                      <li>
440
			[% IF (OpacAllowPublicListCreation) %]
432
                        <label for="category">Category:</label>
441
                        <label for="category">Category:</label>
433
                        <select name="category" id="category">
442
                        <select name="category" id="category">
434
                          [% IF ( category1 ) %]<option value="1" selected="selected">Private</option>[% ELSE %]<option value="1">Private</option>[% END %]
443
                          [% IF ( category1 ) %]<option value="1" selected="selected">Private</option>[% ELSE %]<option value="1">Private</option>[% END %]
435
                          [% IF ( category2 ) %]<option value="2" selected="selected">Public</option>[% ELSE %]<option value="2">Public</option>[% END %]
444
                          [% IF ( category2 ) %]<option value="2" selected="selected">Public</option>[% ELSE %]<option value="2">Public</option>[% END %]
436
                        </select>
445
                        </select>
446
			[% END %]
437
                      </li>
447
                      </li>
438
                    </ol>
448
                    </ol>
439
                  </fieldset>
449
                  </fieldset>
Lines 489-495 $(function() { Link Here
489
                              <td>
499
                              <td>
490
                                [% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
500
                                [% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
491
                                [% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
501
                                [% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
492
                                [% IF ( shelveslooppri.viewcategory3 ) %]Open[% END %]
493
                              </td>
502
                              </td>
494
                              <td>
503
                              <td>
495
                              [% IF ( shelveslooppri.mine ) %]
504
                              [% IF ( shelveslooppri.mine ) %]
Lines 556-562 $(function() { Link Here
556
                          <td>
565
                          <td>
557
                            [% IF ( shelvesloo.viewcategory1 ) %]Private[% END %]
566
                            [% IF ( shelvesloo.viewcategory1 ) %]Private[% END %]
558
                            [% IF ( shelvesloo.viewcategory2 ) %]Public[% END %]
567
                            [% IF ( shelvesloo.viewcategory2 ) %]Public[% END %]
559
                            [% IF ( shelvesloo.viewcategory3 ) %]Open[% END %]
560
	                      </td>
568
	                      </td>
561
                          <td>
569
                          <td>
562
							[% IF ( shelvesloo.mine ) %]
570
							[% IF ( shelvesloo.mine ) %]
Lines 620-626 $(function() { Link Here
620
                        <label for="category">Category:</label>
628
                        <label for="category">Category:</label>
621
                        <select name="category" id="category">
629
                        <select name="category" id="category">
622
                          <option value="1">Private</option>
630
                          <option value="1">Private</option>
631
			  [% IF (OpacAllowPublicListCreation) %]
623
                          <option value="2">Public</option>
632
                          <option value="2">Public</option>
633
			  [% END %]
624
                        </select>
634
                        </select>
625
                      </li>
635
                      </li>
626
                    </ol>
636
                    </ol>
(-)a/opac/opac-addbybiblionumber.pl (-75 / +111 lines)
Lines 25-50 Link Here
25
use strict;
25
use strict;
26
use warnings;
26
use warnings;
27
27
28
use C4::Biblio;
29
use CGI;
28
use CGI;
30
use C4::VirtualShelves qw/:DEFAULT GetAllShelves RefreshShelvesSummary/;
29
use C4::Biblio;
31
use C4::Auth;
30
use C4::VirtualShelves qw/:DEFAULT GetAllShelves/;
32
use C4::Output;
31
use C4::Output;
33
use C4::Auth qw/get_session/;
32
use C4::Auth;
34
use C4::Debug;
35
36
#splits incoming biblionumber(s) to array and adds each to shelf.
37
sub AddBibliosToShelf {
38
    my ($shelfnumber,@biblionumber)=@_;
39
40
    # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
41
    if (scalar(@biblionumber) == 1) {
42
        @biblionumber = (split /\//,$biblionumber[0]);
43
    }
44
    for my $bib (@biblionumber){
45
        AddToShelf($bib, $shelfnumber);
46
    }
47
}
48
33
49
my $query        	= new CGI;
34
my $query        	= new CGI;
50
my @biblionumber 	= $query->param('biblionumber');
35
my @biblionumber 	= $query->param('biblionumber');
Lines 53-58 my $newshelf = $query->param('newshelf'); Link Here
53
my $shelfnumber  	= $query->param('shelfnumber');
38
my $shelfnumber  	= $query->param('shelfnumber');
54
my $newvirtualshelf	= $query->param('newvirtualshelf');
39
my $newvirtualshelf	= $query->param('newvirtualshelf');
55
my $category     	= $query->param('category');
40
my $category     	= $query->param('category');
41
my $authorized          = 1;
42
my $errcode		= 0;
43
my @biblios;
56
44
57
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
58
    {
46
    {
Lines 63-134 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
63
    }
51
    }
64
);
52
);
65
53
66
if ($newvirtualshelf) {
54
if( $newvirtualshelf) {
67
	$shelfnumber = AddShelf(  $newvirtualshelf, $loggedinuser, $category );
55
    HandleNewVirtualShelf();
68
	AddBibliosToShelf($shelfnumber, @biblionumber);
56
    exit if $authorized;
69
	RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10));
57
    ShowTemplate(); #error message
70
	print $query->header;
71
	print "<html><meta http-equiv=\"refresh\" content=\"0;url=opac-shelves.pl?display=privateshelves\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
72
	exit;
73
}
58
}
59
elsif($shelfnumber) {
60
    HandleShelfNumber();
61
    exit if $authorized;
62
    ShowTemplate(); #error message
63
}
64
elsif($selectedshelf) {
65
    HandleSelectedShelf();
66
    LoadBib() if $authorized;
67
    ShowTemplate();
68
}
69
else {
70
    HandleSelect();
71
    LoadBib() if $authorized;
72
    ShowTemplate();
73
}
74
#end
74
75
75
# verify user is authorized to perform the action on the shelf...
76
sub AddBibliosToShelf {
76
my $authorized = 1;
77
    #splits incoming biblionumber(s) to array and adds each to shelf.
77
if ($selectedshelf) {
78
    my ($shelfnumber,@biblionumber)=@_;
78
	$authorized = 0 unless ShelfPossibleAction( $loggedinuser, $selectedshelf );
79
80
    #multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
81
    if (scalar(@biblionumber) == 1) {
82
        @biblionumber = (split /\//,$biblionumber[0]);
83
    }
84
    for my $bib (@biblionumber) {
85
        AddToShelf($bib, $shelfnumber, $loggedinuser);
86
    }
79
}
87
}
80
88
81
if ($shelfnumber && ($shelfnumber != -1)) {
89
sub HandleNewVirtualShelf {
82
	AddBibliosToShelf($shelfnumber,@biblionumber);
90
    if($authorized= ShelfPossibleAction($loggedinuser, undef, $category==1? 'new_private': 'new_public')) {
83
	RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10));
91
	$shelfnumber = AddShelf( {
92
            shelfname => $newvirtualshelf,
93
            category => $category }, $loggedinuser);
94
	if($shelfnumber == -1) {
95
	    $authorized=0;
96
	    $errcode=1;
97
	    return;
98
	}
99
	AddBibliosToShelf($shelfnumber, @biblionumber);
100
	#Reload the page where you came from
84
	print $query->header;
101
	print $query->header;
85
	print "<html><meta http-equiv=\"refresh\" content=\"0;url=opac-shelves.pl?display=privateshelves\" /><body onload=\"self.close();\"></body></html>";
102
	print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
86
	exit;
103
    }
87
}
104
}
88
else {
89
	if($selectedshelf){
90
	# adding to specific shelf
91
	my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('selectedshelf') );
92
				$template->param(
93
				singleshelf 		=> 1,
94
				shelfnumber         => $singleshelf,
95
				shelfname           => $singleshelfname,
96
				"category$singlecategory" => 1
97
			);
98
	} else {
99
105
100
        my $privateshelves = GetAllShelves(1,$loggedinuser);
106
sub HandleShelfNumber {
101
        if(@{$privateshelves}){
107
    if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
102
			$template->param (
108
	AddBibliosToShelf($shelfnumber,@biblionumber);
103
				privatevirtualshelves          => $privateshelves,
109
	#Close this page and return
104
				existingshelves => 1
110
	print $query->header;
105
			);
111
	print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
106
		}
112
    }
107
        my $publicshelves = GetAllShelves(2,$loggedinuser);
113
}
108
        if(@{$publicshelves}){
109
			$template->param (
110
				publicvirtualshelves          => $publicshelves,
111
				existingshelves => 1
112
			);
113
        }
114
114
115
sub HandleSelectedShelf {
116
    if($authorized= ShelfPossibleAction( $loggedinuser, $selectedshelf, 'add')){
117
        #adding to specific shelf
118
        my ($singleshelf, $singleshelfname, $singlecategory)= GetShelf($query->param('selectedshelf'));
119
        $template->param(
120
	    singleshelf               => 1,
121
	    shelfnumber               => $singleshelf,
122
	    shelfname                 => $singleshelfname,
123
	    "category$singlecategory" => 1
124
        );
125
    }
115
}
126
}
116
	my @biblios;
127
117
	for my $bib (@biblionumber) {
128
sub HandleSelect {
118
		my $data = GetBiblioData( $bib );
129
    return unless $authorized= $loggedinuser>0;
119
		push(@biblios, 
130
    my $privateshelves = GetAllShelves(1,$loggedinuser,1);
120
			{ biblionumber => $bib,
131
    if(@{$privateshelves}){
121
			  title        => $data->{'title'},
132
        $template->param (
122
			  author       => $data->{'author'},
133
	    privatevirtualshelves          => $privateshelves,
123
			} );
134
	    existingshelves => 1
124
	}
135
	);
125
	$template->param (
136
    }
126
		newshelf => $newshelf,
137
    my $publicshelves = GetAllShelves(2,$loggedinuser,1);
127
		multiple => (scalar(@biblios) > 1),
138
    if(@{$publicshelves}){
128
		total    => scalar @biblios,
139
        $template->param (
129
		biblios  => \@biblios,
140
	    publicvirtualshelves          => $publicshelves,
130
		authorized	=> $authorized,
141
	    existingshelves => 1
131
	);
142
	);
143
    }
144
}
145
146
sub LoadBib {
147
    for my $bib (@biblionumber) {
148
        my $data = GetBiblioData( $bib );
149
	push(@biblios,
150
		{ biblionumber => $bib,
151
		  title        => $data->{'title'},
152
		  author       => $data->{'author'},
153
	} );
154
    }
155
    $template->param(
156
        multiple => (scalar(@biblios) > 1),
157
	total    => scalar @biblios,
158
	biblios  => \@biblios,
159
    );
160
}
132
161
133
	output_html_with_http_headers $query, $cookie, $template->output;
162
sub ShowTemplate {
163
    $template->param (
164
	newshelf => $newshelf||0,
165
	authorized	=> $authorized,
166
	errcode		=> $errcode,
167
	OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
168
    );
169
    output_html_with_http_headers $query, $cookie, $template->output;
134
}
170
}
(-)a/opac/opac-search.pl (-18 / +9 lines)
Lines 41-46 use URI::Escape; Link Here
41
use Storable qw(thaw freeze);
41
use Storable qw(thaw freeze);
42
42
43
43
44
44
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
45
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
45
# create a new CGI object
46
# create a new CGI object
46
# FIXME: no_undef_params needs to be tested
47
# FIXME: no_undef_params needs to be tested
Lines 741-764 if ($query_desc || $limit_desc) { Link Here
741
742
742
# VI. BUILD THE TEMPLATE
743
# VI. BUILD THE TEMPLATE
743
# Build drop-down list for 'Add To:' menu...
744
# Build drop-down list for 'Add To:' menu...
744
my $session = get_session($cgi->cookie("CGISESSID"));
745
my ($totalref, $pubshelves, $barshelves)=
745
my @addpubshelves;
746
	C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1);
746
my $pubshelves = $session->param('pubshelves');
747
$template->param(
747
my $barshelves = $session->param('barshelves');
748
	addbarshelves     => $totalref->{bartotal},
748
foreach my $shelf (@$pubshelves) {
749
	addbarshelvesloop => $barshelves,
749
    next if ( ($shelf->{'owner'} != ($borrowernumber ? $borrowernumber : -1)) && ($shelf->{'category'} < 3) );
750
	addpubshelves     => $totalref->{pubtotal},
750
    push (@addpubshelves, $shelf);
751
	addpubshelvesloop => $pubshelves,
751
}
752
	);
752
753
if (@addpubshelves) {
754
    $template->param( addpubshelves     => scalar (@addpubshelves));
755
    $template->param( addpubshelvesloop => \@addpubshelves);
756
}
757
758
if (defined $barshelves) {
759
    $template->param( addbarshelves     => scalar (@$barshelves));
760
    $template->param( addbarshelvesloop => $barshelves);
761
}
762
753
763
my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
754
my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
764
755
(-)a/opac/opac-shelves.pl (-6 / +2 lines)
Lines 32-40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ Link Here
32
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
32
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
33
    });
33
    });
34
$template->param(listsview => 1);
34
$template->param(listsview => 1);
35
# if $loggedinuser is not defined, set it to -1, which should
35
36
# not correspond to any real borrowernumber.  
36
shelfpage('opac', $query, $template, $loggedinuser, $cookie);
37
# FIXME: this is a hack to temporarily avoid changing several
38
#        routines in C4::VirtualShelves and C4::VirtualShelves::page
39
#        to deal with lists accessed during an anonymous OPAC session
40
shelfpage('opac', $query, $template, (defined($loggedinuser) ? $loggedinuser : -1), $cookie);
(-)a/virtualshelves/addbybiblionumber.pl (-131 / +113 lines)
Lines 59-102 Link Here
59
=cut
59
=cut
60
60
61
use strict;
61
use strict;
62
#use warnings; FIXME - Bug 2505
62
use warnings;
63
use C4::Biblio;
63
64
use CGI;
64
use CGI;
65
use C4::Biblio;
65
use C4::Output;
66
use C4::Output;
66
use C4::VirtualShelves qw/:DEFAULT GetRecentShelves/;
67
use C4::VirtualShelves qw/:DEFAULT GetAllShelves/;
67
use C4::Circulation;
68
use C4::Auth;
68
use C4::Auth;
69
69
70
# splits incoming biblionumber(s) to array and adds each to shelf.
71
sub AddBibliosToShelf {
72
    my ($shelfnumber,@biblionumber)=@_;
73
74
    # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
75
    # (Note : they come in as '/' when added from the cart)
76
    if (scalar(@biblionumber) == 1) {
77
        @biblionumber = (split /\//,$biblionumber[0]);
78
    }
79
    for my $bib (@biblionumber){
80
        AddToShelf($bib, $shelfnumber);
81
    }
82
}
83
70
84
my $query           = new CGI;
71
my $query           = new CGI;
85
72
my @biblionumber    = HandleBiblioPars();
86
# If set, then single item case.
87
my $biblionumber    = $query->param('biblionumber');
88
89
# If set, then multiple item case.
90
my @biblionumber   = $query->param('biblionumber');
91
my $biblionumbers   = $query->param('biblionumbers');
92
93
my $shelfnumber     = $query->param('shelfnumber');
73
my $shelfnumber     = $query->param('shelfnumber');
94
my $newvirtualshelf = $query->param('newvirtualshelf');
74
my $newvirtualshelf = $query->param('newvirtualshelf');
95
my $newshelf        = $query->param('newshelf');
75
my $newshelf        = $query->param('newshelf');
96
my $category        = $query->param('category');
76
my $category        = $query->param('category');
97
my $sortfield	    = $query->param('sortfield');
77
my $sortfield	    = $query->param('sortfield');
98
my $confirmed       = $query->param('confirmed') || 0;
78
my $confirmed       = $query->param('confirmed') || 0;
99
79
my $authorized      = 1;
80
my $errcode	    = 0;
100
81
101
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
82
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
102
    {
83
    {
Lines 108-227 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
108
    }
89
    }
109
);
90
);
110
91
111
my @biblionumbers;
92
if( $newvirtualshelf) {
112
if ($biblionumbers) {
93
    HandleNewVirtualShelf();
113
    @biblionumbers = split '/', $biblionumbers;
94
    exit if $authorized;
114
} else {
95
    ShowTemplate(); #error message
115
    @biblionumbers = (@biblionumber);
96
}
97
elsif($shelfnumber && $confirmed) {
98
    HandleShelfNumber();
99
    exit if $authorized;
100
    ShowTemplate(); #error message
101
}
102
elsif($shelfnumber) { #still needs confirmation
103
    HandleSelectedShelf();
104
    LoadBib() if $authorized;
105
    ShowTemplate();
116
}
106
}
117
if (scalar(@biblionumber) == 1) {
107
else {
118
        @biblionumber = (split /\//,$biblionumber[0]);
108
    HandleSelect();
109
    LoadBib();
110
    ShowTemplate();
119
}
111
}
112
#end
120
113
121
$shelfnumber = AddShelf( $newvirtualshelf, $loggedinuser, $category, $sortfield ) if $newvirtualshelf;
114
sub HandleBiblioPars {
122
if ( $shelfnumber || ( $shelfnumber == -1 ) ) {    # the shelf already exist.
115
    my @bib= $query->param('biblionumber');
123
116
    if(@bib==0 && $query->param('biblionumbers')) {
124
    if ($confirmed == 1) {
117
        my $str= $query->param('biblionumbers');
125
	AddBibliosToShelf($shelfnumber,@biblionumber);
118
        @bib= split '/', $str;
126
	print
119
    }
127
    "Content-Type: text/html\n\n<html><body onload=\"window.opener.location.reload(true);window.close()\"></body></html>";
120
    elsif(@bib==1 && $bib[0]=~/\//) {
128
	exit;
121
        @bib= split '/', $bib[0];
129
    } else {
122
    }
130
	my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('shelfnumber') );
123
    return @bib;
131
	my @biblios;
124
}
132
        for my $bib (@biblionumber) {
125
133
	    my $data = GetBiblioData( $bib );
126
sub AddBibliosToShelf {
134
            push(@biblios,
127
    my ($shelfnumber, @biblionumber)=@_;
135
                        { biblionumber => $bib,
128
    for my $bib (@biblionumber){
136
                          title        => $data->{'title'},
129
        AddToShelf($bib, $shelfnumber, $loggedinuser);
137
                          author       => $data->{'author'},
130
    }
138
                        } );
131
}
139
        }
132
140
133
sub HandleNewVirtualShelf {
141
       	$template->param
134
    $shelfnumber = AddShelf( {
142
        (
135
        shelfname => $newvirtualshelf,
143
         biblionumber => \@biblionumber,
136
        sortfield => $sortfield,
144
         biblios      => \@biblios,
137
        category => $category }, $loggedinuser);
145
         multiple     => (scalar(@biblionumber) > 1),
138
    if($shelfnumber == -1) {
146
         singleshelf  => 1,
139
	    $authorized=0;
147
         shelfname    => $singleshelfname,
140
	    $errcode=1; #add failed
148
         shelfnumber  => $singleshelf,
141
	    return;
149
         total        => scalar(@biblionumber),
150
         confirm      => 1,
151
        );
152
    }
142
    }
143
    AddBibliosToShelf($shelfnumber, @biblionumber);
144
    #Reload the page where you came from
145
    print $query->header;
146
    print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
153
}
147
}
154
else {    # this shelf doesn't already exist.
148
155
#    my $limit = 10;
149
sub HandleShelfNumber {
156
    my ($shelflist);
150
    if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
157
    my @shelvesloop;
151
	AddBibliosToShelf($shelfnumber, @biblionumber);
158
    my %shelvesloop;
152
	#Close this page and return
159
153
	print $query->header;
160
    #grab each type of shelf, open (type 3) should not be limited by user.
154
	print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
161
    foreach my $shelftype (1,2,3) {
155
    }
162
	    my ($shelflist) = GetRecentShelves($shelftype, undef, $shelftype == 3 ? undef : $loggedinuser);
156
    else {
163
	    for my $shelf (@{ $shelflist }) {
157
	$errcode=2; #no perm
164
		    push(@shelvesloop, $shelf->{shelfnumber});
165
		    $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
166
	    }
167
    }
158
    }
159
}
168
160
169
    if( @shelvesloop ){
161
sub HandleSelectedShelf {
170
        my $CGIvirtualshelves = CGI::scrolling_list
162
    if($authorized= ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')){
171
          (
163
        #confirm adding to specific shelf
172
           -name     => 'shelfnumber',
164
        my ($singleshelf, $singleshelfname, $singlecategory)= GetShelf($shelfnumber);
173
           -values   => \@shelvesloop,
165
        $template->param(
174
           -labels   => \%shelvesloop,
166
	    singleshelf               => 1,
175
           -size     => 1,
167
	    shelfnumber               => $singleshelf,
176
           -tabindex => '',
168
	    shelfname                 => $singleshelfname,
177
           -multiple => 0
169
	    "category$singlecategory" => 1
178
          );
170
        );
179
        $template->param
180
          (
181
           CGIvirtualshelves => $CGIvirtualshelves,
182
          );
183
    }
171
    }
184
   	my @biblios;
172
    else {
185
        for my $bib (@biblionumber) {
173
	$errcode=2; #no perm
186
	    my $data = GetBiblioData( $bib );
174
    }
187
            push(@biblios,
175
}
188
                        { biblionumber => $bib,
176
189
                          title        => $data->{'title'},
177
sub HandleSelect {
190
                          author       => $data->{'author'},
178
    my $privateshelves = GetAllShelves(1,$loggedinuser,1);
191
                        } );
179
    my $publicshelves = GetAllShelves(2,$loggedinuser,1);
192
        }
193
    $template->param(
180
    $template->param(
194
           newshelf     => $newshelf,
181
	privatevirtualshelves => $privateshelves,
195
	   biblios=>\@biblios,
182
	publicvirtualshelves  => $publicshelves,
196
           multiple     => (scalar(@biblionumber) > 1),
197
           total        => scalar(@biblionumber),
198
    );
183
    );
184
}
199
185
200
    unless (@biblionumbers) {
186
sub LoadBib {
201
        my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
187
    my @biblios;
202
    
188
    for my $bib (@biblionumber) {
203
        $template->param
189
        my $data = GetBiblioData($bib);
204
          (
190
	push(@biblios,
205
           biblionumber      => $biblionumber,
191
		{ biblionumber => $bib,
206
           title             => $biblios[0]->{'title'},
192
		  title        => $data->{'title'},
207
           author            => $biblios[0]->{'author'},
193
		  author       => $data->{'author'},
208
          );
194
	} );
209
    } else {
210
        my @biblioloop = ();
211
        foreach my $biblionumber (@biblionumbers) {
212
            my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
213
            my %biblioiter = (
214
                              title=>$biblios[0]->{'title'},
215
                              author=>$biblios[0]->{'author'}
216
                             );
217
            push @biblioloop, \%biblioiter;
218
        }
219
        $template->param
220
          (
221
           biblioloop => \@biblioloop,
222
           biblionumbers => $biblionumbers
223
          );
224
    }
195
    }
225
    
196
    $template->param(
197
        multiple => (scalar(@biblios) > 1),
198
	total    => scalar @biblios,
199
	biblios  => \@biblios,
200
    );
201
}
202
203
sub ShowTemplate {
204
    $template->param (
205
	newshelf => $newshelf||0,
206
	authorized	=> $authorized,
207
	errcode		=> $errcode,
208
    );
209
    output_html_with_http_headers $query, $cookie, $template->output;
226
}
210
}
227
output_html_with_http_headers $query, $cookie, $template->output;
228
- 

Return to bug 7310