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

(-)a/C4/Auth.pm (-48 / +13 lines)
Lines 162-182 sub get_template_and_user { Link Here
162
        $template->param( loggedinusername => $user );
162
        $template->param( loggedinusername => $user );
163
        $template->param( sessionID        => $sessionID );
163
        $template->param( sessionID        => $sessionID );
164
164
165
        my ($total, $pubshelves, $barshelves) = C4::Context->get_shelves_userenv();
166
        if (defined($pubshelves)) {
167
            $template->param( pubshelves     => scalar @{$pubshelves},
168
                              pubshelvesloop => $pubshelves,
169
            );
170
            $template->param( pubtotal   => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
171
        }
172
        if (defined($barshelves)) {
173
            $template->param( barshelves      => scalar @{$barshelves},
174
                              barshelvesloop  => $barshelves,
175
            );
176
            $template->param( bartotal  => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar @{$barshelves});
177
        }
178
179
        $borrowernumber = getborrowernumber($user) if defined($user);
165
        $borrowernumber = getborrowernumber($user) if defined($user);
166
        my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($borrowernumber, 'MASTHEAD');
167
	$template->param(
168
	    pubshelves     => $total->{pubtotal},
169
	    pubshelvesloop => $pubshelves,
170
	    barshelves      => $total->{bartotal},
171
	    barshelvesloop  => $barshelves,
172
	);
173
180
        require C4::Members;
174
        require C4::Members;
181
        my ( $borr ) = C4::Members::GetMemberDetails( $borrowernumber );
175
        my ( $borr ) = C4::Members::GetMemberDetails( $borrowernumber );
182
        my @bordat;
176
        my @bordat;
Lines 294-307 sub get_template_and_user { Link Here
294
288
295
        $template->param( sessionID        => $sessionID );
289
        $template->param( sessionID        => $sessionID );
296
        
290
        
297
        my ($total, $pubshelves) = C4::Context->get_shelves_userenv();  # an anonymous user has no 'barshelves'...
291
        my ($total, $pubshelves) = C4::VirtualShelves::GetSomeShelfNames(undef, 'MASTHEAD');
298
        if (defined $pubshelves) {
292
	$template->param(
299
            $template->param(   pubshelves      => scalar @{$pubshelves},
293
	    pubshelves     => $total->{pubtotal},
300
                                pubshelvesloop  => $pubshelves,
294
	    pubshelvesloop => $pubshelves,
301
                            );
295
	);
302
            $template->param(   pubtotal        => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
303
        }
304
305
    }
296
    }
306
 	# Anonymous opac search history
297
 	# Anonymous opac search history
307
 	# If opac search history is enabled and at least one search has already been performed
298
 	# If opac search history is enabled and at least one search has already been performed
Lines 870-891 sub checkauth { Link Here
870
					$session->param('emailaddress'), $session->param('branchprinter')
861
					$session->param('emailaddress'), $session->param('branchprinter')
871
				);
862
				);
872
863
873
				# Grab borrower's shelves and public shelves and add them to the session
874
				# $row_count determines how many records are returned from the db query
875
				# and the number of lists to be displayed of each type in the 'Lists' button drop down
876
				my $row_count = 10; # FIXME:This probably should be a syspref
877
				my ($total, $totshelves, $barshelves, $pubshelves);
878
				($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber);
879
				$total->{'bartotal'} = $totshelves;
880
				($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
881
				$total->{'pubtotal'} = $totshelves;
882
				$session->param('barshelves', $barshelves);
883
				$session->param('pubshelves', $pubshelves);
884
				$session->param('totshelves', $total);
885
886
				C4::Context::set_shelves_userenv('bar',$barshelves);
887
				C4::Context::set_shelves_userenv('pub',$pubshelves);
888
				C4::Context::set_shelves_userenv('tot',$total);
889
			}
864
			}
890
        	else {
865
        	else {
891
            	if ($userid) {
866
            	if ($userid) {
Lines 899-914 sub checkauth { Link Here
899
            # anonymous sessions are created only for the OPAC
874
            # anonymous sessions are created only for the OPAC
900
			$debug and warn "Initiating an anonymous session...";
875
			$debug and warn "Initiating an anonymous session...";
901
876
902
			# Grab the public shelves and add to the session...
903
			my $row_count = 20; # FIXME:This probably should be a syspref
904
			my ($total, $totshelves, $pubshelves);
905
			($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
906
			$total->{'pubtotal'} = $totshelves;
907
			$session->param('pubshelves', $pubshelves);
908
			$session->param('totshelves', $total);
909
			C4::Context::set_shelves_userenv('pub',$pubshelves);
910
			C4::Context::set_shelves_userenv('tot',$total);
911
912
			# setting a couple of other session vars...
877
			# setting a couple of other session vars...
913
			$session->param('ip',$session->remote_addr());
878
			$session->param('ip',$session->remote_addr());
914
			$session->param('lasttime',time());
879
			$session->param('lasttime',time());
(-)a/C4/VirtualShelves.pm (-255 / +345 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
            &GetRecentShelves &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-218 sub GetShelves ($$$$) { Link Here
132
    return ( \%shelflist, $total );
144
    return ( \%shelflist, $total );
133
}
145
}
134
146
135
=head2 GetShelvesSummary
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
147
=head2 GetRecentShelves
185
148
186
	($shelflist, $total) = GetRecentShelves(1, $limit, $owner)
149
	($shelflist, $total) = GetRecentShelves($category, $row_count, $owner, $adding_allowed)
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 specified shelves sorted by the date the shelf was last modified in descending order limited to the number of records specified by C<$row_count>.
189
by the date the shelf was last modified in descending order limited to the number of records
152
If row_count is undef, a default maximum of 100 lists is used.
190
specified by C<$row_count>. If calling with C<$mincategory> other than 1, use undef as C<$owner>.
153
If calling with C<$category> other than 1, owner is ignored.
154
If C<$adding_allowed> is 1, return only lists where user has permission to add entries.
191
155
192
This function is intended to return a dataset reflecting the most recently active shelves for
156
This function is intended to return a dataset reflecting the most recently active shelves for the submitted parameters.
193
the submitted parameters.
194
157
195
=cut
158
=cut
196
159
197
sub GetRecentShelves {
160
sub GetRecentShelves {
198
    my ($mincategory, $row_count, $owner) = @_;
161
    my ($category, $row_count, $owner, $adding_allowed) = @_;
199
    my $total = _shelf_count($owner, $mincategory);
162
    my $total = _shelf_count($owner, $category);
200
    my @params;
163
    my @params;
201
    my $selection;
164
202
    if (defined $owner) {
165
    my $query = 'SELECT vs.* FROM virtualshelves vs ';
203
        @params = ($owner, $mincategory);
166
    if($category==1) {
204
        $selection = ' WHERE owner = ? AND category = ?';
167
        $query.= qq{
205
    } else {
168
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
206
        @params = ( $mincategory);
169
            AND sh.borrowernumber=?
207
        $selection = ' WHERE category >= ? ';
170
	    WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
171
        @params = ($owner, $owner, $owner);
208
    }
172
    }
209
    my $query = 'SELECT * FROM virtualshelves';
173
    else {
210
    $query .= $selection;
174
	$query.='WHERE category=2 ';
211
    $query .= ' ORDER BY lastmodified DESC';
175
        @params = ();
176
    }
177
    if($adding_allowed) {
178
	$query.= 'AND (allow_add=1 OR owner=?) ';
179
	push @params,$owner;
180
    }
181
    $query .= 'ORDER BY lastmodified DESC ';
212
    if ($row_count){
182
    if ($row_count){
213
	$query .= ' LIMIT ?';
183
	$query .= 'LIMIT ?';
214
	push @params,$row_count;
184
	push @params,$row_count;
215
    }
185
    }
186
    elsif($total>SHELVES_COMBO_MAX) {
187
	$query .= 'LIMIT '.SHELVES_COMBO_MAX;
188
    }
189
216
    my $sth = $dbh->prepare($query);
190
    my $sth = $dbh->prepare($query);
217
    $sth->execute(@params);
191
    $sth->execute(@params);
218
    my $shelflist = $sth->fetchall_arrayref({});
192
    my $shelflist = $sth->fetchall_arrayref({});
Lines 221-230 sub GetRecentShelves { Link Here
221
195
222
=head2 GetAllShelves
196
=head2 GetAllShelves
223
197
224
    $shelflist = GetAllShelves($owner)
198
    $shelflist = GetAllShelves($category, $owner)
225
199
226
This function returns a reference to an array of hashrefs containing all shelves sorted
200
This function returns a reference to an array of hashrefs containing all shelves
227
by the shelf name.
201
sorted by the shelf name.
228
202
229
This function is intended to return a dataset reflecting all the shelves for
203
This function is intended to return a dataset reflecting all the shelves for
230
the submitted parameters.
204
the submitted parameters.
Lines 232-244 the submitted parameters. Link Here
232
=cut
206
=cut
233
207
234
sub GetAllShelves {
208
sub GetAllShelves {
235
    my ($category,$owner) = @_;
209
    my ($category,$owner,$adding_allowed) = @_;
236
    my $query = 'SELECT * FROM virtualshelves WHERE category = ? AND owner = ? ORDER BY shelfname ASC';
210
    my @params;
211
    my $query = 'SELECT vs.* FROM virtualshelves vs ';
212
    if($category==1) {
213
        $query.= qq{
214
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
215
            AND sh.borrowernumber=?
216
	    WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
217
        @params = ($owner, $owner, $owner);
218
    }
219
    else {
220
	$query.='WHERE category=2 ';
221
        @params = ();
222
    }
223
    $query.='AND (allow_add=1 OR owner=?) ' if $adding_allowed;
224
    push @params, $owner if $adding_allowed;
225
    $query.= 'ORDER BY shelfname ASC';
237
    my $sth = $dbh->prepare( $query );
226
    my $sth = $dbh->prepare( $query );
238
    $sth->execute( $category, $owner );
227
    $sth->execute(@params);
239
    return $sth->fetchall_arrayref({});
228
    return $sth->fetchall_arrayref({});
240
}
229
}
241
230
231
=head2 GetSomeShelfNames
232
233
Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header.
234
235
=cut
236
237
sub GetSomeShelfNames {
238
    my ($owner, $purpose, $adding_allowed)= @_;
239
    my ($bar, $pub, @params);
240
241
    my $bquery = 'SELECT vs.shelfnumber, vs.shelfname FROM virtualshelves vs ';
242
    my $limit= ShelvesMax($purpose);
243
244
    my $qry1= $bquery."WHERE vs.category=2 ";
245
    $qry1.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
246
    push @params, $owner||0 if $adding_allowed;
247
    $qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit";
248
249
    unless($adding_allowed && (!defined($owner) || $owner<=0)) {
250
      #if adding items, user should be known
251
      $pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params);
252
    }
253
254
    if($owner) {
255
      my $qry2= $bquery. qq{
256
        LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=?
257
        WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
258
      @params=($owner,$owner,$owner);
259
      $qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
260
      push @params, $owner if $adding_allowed;
261
      $qry2.= "ORDER BY vs.lastmodified DESC ";
262
      $qry2.= "LIMIT $limit";
263
      $bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params);
264
    }
265
266
    return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
267
}
268
242
=head2 GetShelf
269
=head2 GetShelf
243
270
244
  (shelfnumber,shelfname,owner,category,sortfield) = &GetShelf($shelfnumber);
271
  (shelfnumber,shelfname,owner,category,sortfield) = &GetShelf($shelfnumber);
Lines 322-371 sub GetShelfContents ($;$$$) { Link Here
322
349
323
=head2 AddShelf
350
=head2 AddShelf
324
351
325
  $shelfnumber = &AddShelf( $shelfname, $owner, $category);
352
  $shelfnumber = &AddShelf($hashref, $owner);
326
353
327
Creates a new virtual virtualshelves with name C<$shelfname>, owner C<$owner> and category
354
Creates a new virtual shelf. Params passed in a hash like ModShelf.
328
C<$category>.
329
355
330
Returns a code to know what's happen.
356
Returns a code to know what's happen.
331
    * -1 : if this virtualshelves already exist.
357
    * -1 : if this virtualshelves already exists.
332
    * $shelfnumber : if success.
358
    * $shelfnumber : if success.
333
359
334
=cut
360
=cut
335
361
336
sub AddShelf {
362
sub AddShelf {
337
    my ( $shelfname, $owner, $category, $sortfield ) = @_;
363
    my ($hashref, $owner)= @_;
338
    my $query = qq(
364
339
        SELECT *
365
    #initialize missing hash values to silence warnings
340
        FROM   virtualshelves
366
    foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) {
341
        WHERE  shelfname=? AND owner=?
367
        $hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': '';
342
    );
368
    }
369
370
    return -1 unless _CheckShelfName($hashref->{shelfname}, $hashref->{category}, $owner, 0);
371
372
    my $query = qq(INSERT INTO virtualshelves
373
        (shelfname,owner,category,sortfield,allow_add,allow_delete_own,allow_delete_other)
374
        VALUES (?,?,?,?,?,?,?));
375
343
    my $sth = $dbh->prepare($query);
376
    my $sth = $dbh->prepare($query);
344
    $sth->execute($shelfname,$owner);
377
    $sth->execute(
345
    ( $sth->rows ) and return (-1);
378
	$hashref->{shelfname},
346
    $query = qq(
379
	$owner,
347
        INSERT INTO virtualshelves
380
	$hashref->{category},
348
            (shelfname,owner,category,sortfield)
381
	$hashref->{sortfield},
349
        VALUES (?,?,?,?)
382
	$hashref->{allow_add}||0,
350
    );
383
	$hashref->{allow_delete_own}||1,
351
    $sth = $dbh->prepare($query);
384
	$hashref->{allow_delete_other}||0 );
352
    $sth->execute( $shelfname, $owner, $category, $sortfield );
353
    my $shelfnumber = $dbh->{'mysql_insertid'};
385
    my $shelfnumber = $dbh->{'mysql_insertid'};
354
    return ($shelfnumber);
386
    return $shelfnumber;
355
}
387
}
356
388
357
=head2 AddToShelf
389
=head2 AddToShelf
358
390
359
  &AddToShelf($biblionumber, $shelfnumber);
391
  &AddToShelf($biblionumber, $shelfnumber, $borrower);
360
392
361
Adds bib number C<$biblionumber> to virtual virtualshelves number
393
Adds bib number C<$biblionumber> to virtual virtualshelves number
362
C<$shelfnumber>, unless that bib is already on that shelf.
394
C<$shelfnumber>, unless that bib is already on that shelf.
363
395
364
=cut
396
=cut
365
397
366
#'
367
sub AddToShelf {
398
sub AddToShelf {
368
    my ( $biblionumber, $shelfnumber ) = @_;
399
    my ($biblionumber, $shelfnumber, $borrowernumber) = @_;
369
    return unless $biblionumber;
400
    return unless $biblionumber;
370
    my $query = qq(
401
    my $query = qq(
371
        SELECT *
402
        SELECT *
Lines 378-389 sub AddToShelf { Link Here
378
    ($sth->rows) and return undef;	# already on shelf
409
    ($sth->rows) and return undef;	# already on shelf
379
	$query = qq(
410
	$query = qq(
380
		INSERT INTO virtualshelfcontents
411
		INSERT INTO virtualshelfcontents
381
			(shelfnumber, biblionumber, flags)
412
			(shelfnumber, biblionumber, flags, borrowernumber)
382
		VALUES
413
		VALUES (?, ?, 0, ?));
383
			(?, ?, 0)
384
	);
385
	$sth = $dbh->prepare($query);
414
	$sth = $dbh->prepare($query);
386
	$sth->execute( $shelfnumber, $biblionumber );
415
	$sth->execute( $shelfnumber, $biblionumber, $borrowernumber);
387
	$query = qq(UPDATE virtualshelves
416
	$query = qq(UPDATE virtualshelves
388
				SET lastmodified = CURRENT_TIMESTAMP
417
				SET lastmodified = CURRENT_TIMESTAMP
389
				WHERE shelfnumber = ?);
418
				WHERE shelfnumber = ?);
Lines 393-443 sub AddToShelf { Link Here
393
422
394
=head2 ModShelf
423
=head2 ModShelf
395
424
396
ModShelf($shelfnumber, $hashref)
425
my $result= ModShelf($shelfnumber, $hashref)
397
426
398
Where $hashref->{column} = param
427
Where $hashref->{column} = param
399
428
400
Modify the value into virtualshelves table with values given 
429
Modify the value into virtualshelves table with values given 
401
from hashref, which each key of the hashref should be
430
from hashref, which each key of the hashref should be
402
the name of a column of virtualshelves.
431
the name of a column of virtualshelves.
432
Fields like shelfnumber or owner cannot be changed.
433
434
Returns 1 if the action seemed to be successful.
403
435
404
=cut
436
=cut
405
437
406
sub ModShelf {
438
sub ModShelf {
407
    my $shelfnumber = shift;
439
    my ($shelfnumber,$hashref) = @_;
408
    my $shelf = shift;
409
440
410
    if (exists $shelf->{shelfnumber}) {
441
    my $query= "SELECT * FROM virtualshelves WHERE shelfnumber=?";
411
        carp "Should not use ModShelf to change shelfnumber";
442
    my $sth = $dbh->prepare($query);
412
        return;
443
    $sth->execute($shelfnumber);
413
    }
444
    my $oldrecord= $sth->fetchrow_hashref;
414
    unless (defined $shelfnumber and $shelfnumber =~ /^\d+$/) {
445
    return 0 unless $oldrecord; #not found?
415
        carp "Invalid shelfnumber passed to ModShelf: $shelfnumber";
416
        return;
417
    }
418
419
	my $query = "UPDATE virtualshelves SET ";
420
    my @bind_params = ();
421
    my @set_clauses = ();
422
446
423
	foreach my $column (keys %$shelf) {
447
    #initialize missing hash values to silence warnings
424
        push @set_clauses, "$column = ?";
448
    foreach('shelfname','category', 'sortfield', 'allow_add', 'allow_delete_own', 'allow_delete_other' ) {
425
        push @bind_params, $shelf->{$column};
449
        $hashref->{$_}= exists $hashref->{$_}? $hashref->{$_}||'': '';
426
    }
450
    }
427
451
428
    if ($#set_clauses == -1) {
452
    #if name or category changes, the name should be tested
429
        carp "No columns to update passed to ModShelf";
453
    if($hashref->{shelfname} || $hashref->{category}) {
430
        return;
454
        unless(_CheckShelfName(
455
	    $hashref->{shelfname}||$oldrecord->{shelfname},
456
	    $hashref->{category}||$oldrecord->{category},
457
	    $oldrecord->{owner}, $shelfnumber )) {
458
		return 0; #name check failed
459
        }
431
    }
460
    }
432
    $query .= join(", ", @set_clauses);
433
434
    $query .= " WHERE shelfnumber = ? ";
435
    push @bind_params, $shelfnumber;
436
461
437
    $debug and warn "ModShelf query:\n $query\n",
462
    #only the following fields from the hash may be changed
438
	                "ModShelf query args: ", join(',', @bind_params), "\n";
463
    $query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?";
439
	my $sth = $dbh->prepare($query);
464
    $sth = $dbh->prepare($query);
440
   	$sth->execute( @bind_params );
465
    $sth->execute(
466
	$hashref->{shelfname}||$oldrecord->{shelfname},
467
	$hashref->{category}||$oldrecord->{category},
468
	$hashref->{sortfield}||$oldrecord->{sortfield},
469
	$hashref->{allow_add}||$oldrecord->{allow_add},
470
	$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own},
471
	$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other},
472
	$shelfnumber );
473
    return $@? 0: 1;
441
}
474
}
442
475
443
=head2 ShelfPossibleAction
476
=head2 ShelfPossibleAction
Lines 446-452 ShelfPossibleAction($loggedinuser, $shelfnumber, $action); Link Here
446
479
447
C<$loggedinuser,$shelfnumber,$action>
480
C<$loggedinuser,$shelfnumber,$action>
448
481
449
$action can be "view" or "manage".
482
$action can be "view", "add", "delete", "manage", "new_public", "new_private".
483
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage.
484
new_public and new_private refers to creating a new public or private list.
485
The distinction between deleting your own entries from the list or entries from
486
others is made in DelFromShelf.
450
487
451
Returns 1 if the user can do the $action in the $shelfnumber shelf.
488
Returns 1 if the user can do the $action in the $shelfnumber shelf.
452
Returns 0 otherwise.
489
Returns 0 otherwise.
Lines 455-529 Returns 0 otherwise. Link Here
455
492
456
sub ShelfPossibleAction {
493
sub ShelfPossibleAction {
457
    my ( $user, $shelfnumber, $action ) = @_;
494
    my ( $user, $shelfnumber, $action ) = @_;
458
    my $query = qq(
495
    $action= 'view' unless $action;
459
        SELECT owner,category
496
    $user=0 unless $user;
460
        FROM   virtualshelves
497
461
        WHERE  shelfnumber=?
498
    if($action =~ /^new/) { #no shelfnumber needed
462
    );
499
        if($action eq 'new_private') {
500
            return $user>0;
501
        }
502
        elsif($action eq 'new_public') {
503
            return $user>0 && C4::Context->preference('OpacAllowPublicListCreation');
504
        }
505
        return 0;
506
    }
507
508
    return 0 unless defined($shelfnumber);
509
510
    my $query = qq/
511
        SELECT IFNULL(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, IFNULL(sh.borrowernumber,0) AS borrowernumber
512
        FROM virtualshelves vs
513
        LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
514
        AND sh.borrowernumber=?
515
        WHERE vs.shelfnumber=?
516
    /;
463
    my $sth = $dbh->prepare($query);
517
    my $sth = $dbh->prepare($query);
464
    $sth->execute($shelfnumber);
518
    $sth->execute($user, $shelfnumber);
465
    my ( $owner, $category ) = $sth->fetchrow;
519
    my $shelf= $sth->fetchrow_hashref;
466
    require C4::Members;
520
467
	my $borrower = C4::Members::GetMemberDetails($user);
521
    return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || $shelf->{borrowernumber}==$user);
468
	return 0 if not defined($user);
522
    if($action eq 'view') {
469
	return 1 if ( $category >= 3);							# open list
523
	#already handled in the above condition
470
    return 1 if (($category >= 2) and
524
	return 1;
471
				defined($action) and $action eq 'view');	# public list, anybody can view
525
    }
472
    return 1 if (($category >= 2) and defined($user) and ($borrower->{authflags}->{superlibrarian} || $user == 0));	# public list, superlibrarian can edit/delete
526
    elsif($action eq 'add') {
473
    return 1 if (defined($user)  and $owner  eq $user );	# user owns this list.  Check last.
527
	return 0 if $user<=0; #should be logged in
528
	return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user;
529
	#owner may always add
530
    }
531
    elsif($action eq 'delete') {
532
        #this answer is just diplomatic: it says that you may be able to delete
533
        #some items from that shelf
534
        #it does not answer the question about a specific biblio
535
        #DelFromShelf checks the situation per biblio
536
	return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1);
537
    }
538
    elsif($action eq 'manage') {
539
	return 1 if $user && $shelf->{owner}==$user;
540
    }
474
    return 0;
541
    return 0;
475
}
542
}
476
543
477
=head2 DelFromShelf
544
=head2 DelFromShelf
478
545
479
  &DelFromShelf( $biblionumber, $shelfnumber);
546
    $result= &DelFromShelf( $bibref, $shelfnumber, $user);
547
548
Removes biblionumbers in passed arrayref from shelf C<$shelfnumber>.
549
If the bib wasn't on that virtualshelves to begin with, nothing happens.
480
550
481
Removes bib number C<$biblionumber> from virtual virtualshelves number
551
Returns 0 if no items have been deleted.
482
C<$shelfnumber>. If the bib wasn't on that virtualshelves to begin with,
483
nothing happens.
484
552
485
=cut
553
=cut
486
554
487
#'
488
sub DelFromShelf {
555
sub DelFromShelf {
489
    my ( $biblionumber, $shelfnumber ) = @_;
556
    my ($bibref, $shelfnumber, $user) = @_;
490
    my $query = qq(
557
    my $query = qq(SELECT allow_delete_own, allow_delete_other FROM virtualshelves WHERE shelfnumber=?);
491
        DELETE FROM virtualshelfcontents
558
    my $sth= $dbh->prepare($query);
492
        WHERE  shelfnumber=? AND biblionumber=?
559
    $sth->execute($shelfnumber);
493
    );
560
    my ($del_own, $del_oth)= $sth->fetchrow;
494
    my $sth = $dbh->prepare($query);
561
    my $r; my $t=0;
495
    $sth->execute( $shelfnumber, $biblionumber );
562
563
    if($del_own) {
564
        $query = qq(DELETE FROM virtualshelfcontents
565
            WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?);
566
        $sth= $dbh->prepare($query);
567
	foreach my $biblionumber (@$bibref) {
568
            $sth->execute($shelfnumber, $biblionumber, $user);
569
	    $r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1)
570
	    $t+= ($r==-1)? 1: $r;
571
	}
572
    }
573
    if($del_oth) {
574
        $query = qq(DELETE FROM virtualshelfcontents
575
            WHERE shelfnumber=? AND biblionumber=? AND borrowernumber<>?);
576
        $sth= $dbh->prepare($query);
577
	foreach my $biblionumber (@$bibref) {
578
            $sth->execute($shelfnumber, $biblionumber, $user);
579
	    $r= $sth->rows;
580
	    $t+= ($r==-1)? 1: $r;
581
	}
582
    }
583
    return $t;
496
}
584
}
497
585
498
=head2 DelShelf (old version)
586
=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
587
511
  $Number = DelShelf($shelfnumber);
588
  $Number = DelShelf($shelfnumber);
512
589
513
This function deletes the shelf number, and all of it's content.
590
This function deletes the shelf number, and all of it's content.
591
Authorization to do so MUST have been checked before calling, while using
592
ShelfPossibleAction with manage parameter.
514
593
515
=cut
594
=cut
516
595
517
sub DelShelf {
596
sub DelShelf {
518
	unless (@_) {
597
    my ($shelfnumber)= @_;
519
		carp "DelShelf called without valid argument (shelfnumber)";
598
    return unless $shelfnumber && $shelfnumber =~ /^\d+$/;
520
		return undef;
599
    my $sth = $dbh->prepare("DELETE FROM virtualshelves WHERE shelfnumber=?");
521
	}
600
    return $sth->execute($shelfnumber);
522
	my $sth = $dbh->prepare("DELETE FROM virtualshelves WHERE shelfnumber=?");
523
	return $sth->execute(shift);
524
}
601
}
525
602
526
=head2 GetBibShelves
603
=head2 GetBibliosShelves
527
604
528
This finds all the public lists that this bib record is in.
605
This finds all the public lists that this bib record is in.
529
606
Lines 536-600 sub GetBibliosShelves { Link Here
536
        SELECT vs.shelfname, vs.shelfnumber 
613
        SELECT vs.shelfname, vs.shelfnumber 
537
        FROM virtualshelves vs 
614
        FROM virtualshelves vs 
538
        JOIN virtualshelfcontents vc ON (vs.shelfnumber= vc.shelfnumber) 
615
        JOIN virtualshelfcontents vc ON (vs.shelfnumber= vc.shelfnumber) 
539
        WHERE vs.category != 1 
616
        WHERE vs.category=2
540
        AND vc.biblionumber= ?
617
        AND vc.biblionumber= ?
541
    ');
618
    ');
542
    $sth->execute( $biblionumber );
619
    $sth->execute( $biblionumber );
543
    return $sth->fetchall_arrayref({});
620
    return $sth->fetchall_arrayref({});
544
}
621
}
545
622
546
=head2 RefreshShelvesSummary
623
=head2 ShelvesMax
547
548
	($total, $pubshelves, $barshelves) = RefreshShelvesSummary($sessionID, $loggedinuser, $row_count);
549
624
550
Updates the current session and userenv with the most recent shelves
625
    $howmany= ShelvesMax($context);
551
626
552
Returns the total number of shelves stored in the session/userenv along with two references each to an
627
Tells how much shelves are shown in which context.
553
array of hashes, one containing the C<$loggedinuser>'s private shelves and one containing all public/open shelves.
628
POPUP refers to addbybiblionumber popup, MGRPAGE is managing page (in opac or
554
629
staff), COMBO refers to the Add to-combo of search results. MASTHEAD is the
555
This function is used in conjunction with the 'Lists' button in masthead.inc.
630
main Koha toolbar with Lists button.
556
631
557
=cut
632
=cut
558
633
559
sub RefreshShelvesSummary ($$$) {
634
sub ShelvesMax {
560
	require C4::Auth;
635
  my $which= shift;
561
	my ($sessionID, $loggedinuser, $row_count) = @_;
636
  return SHELVES_POPUP_MAX if $which eq 'POPUP';
562
	my $session = C4::Auth::get_session($sessionID);
637
  return SHELVES_MGRPAGE_MAX if $which eq 'MGRPAGE';
563
	my ($total, $totshelves, $barshelves, $pubshelves);
638
  return SHELVES_COMBO_MAX if $which eq 'COMBO';
564
639
  return SHELVES_MASTHEAD_MAX if $which eq 'MASTHEAD';
565
	($barshelves, $totshelves) = GetRecentShelves(1, $row_count, $loggedinuser);
640
  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
}
641
}
582
642
583
# internal subs
643
# internal subs
584
644
585
sub _shelf_count ($$) {
645
sub _shelf_count {
586
	my (@params) = @_;
646
    my ($owner, $category) = @_;
587
	# Find out how many shelves total meet the submitted criteria...
647
    my @params;
588
	my $query = "SELECT count(*) FROM virtualshelves";
648
    # Find out how many shelves total meet the submitted criteria...
589
	$query .= ($params[1] > 1) ? " WHERE category >= ?" : " WHERE  owner=? AND category=?";
649
590
	shift @params if $params[1] > 1;
650
    my $query = "SELECT count(*) FROM virtualshelves vs ";
591
	my $sth = $dbh->prepare($query);
651
    if($category==1) {
592
	$sth->execute(@params);
652
        $query.= qq{
593
	my $total = $sth->fetchrow;
653
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
594
	return $total;
654
            AND sh.borrowernumber=?
655
	    WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
656
        @params= ($owner, $owner, $owner);
657
    }
658
    else {
659
	$query.='WHERE category=2';
660
        @params= ();
661
    }
662
    my $sth = $dbh->prepare($query);
663
    $sth->execute(@params);
664
    my ($total)= $sth->fetchrow;
665
    return $total;
595
}
666
}
596
667
597
sub _biblionumber_sth {
668
sub _biblionumber_sth { #only used in obsolete sub below
598
    my ($shelf) = @_;
669
    my ($shelf) = @_;
599
    my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?';
670
    my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?';
600
    my $dbh = C4::Context->dbh;
671
    my $dbh = C4::Context->dbh;
Lines 605-611 sub _biblionumber_sth { Link Here
605
    $sth;
676
    $sth;
606
}
677
}
607
678
608
sub each_biblionumbers (&$) {
679
sub each_biblionumbers (&$) { #OBSOLETE
609
    my ($code,$shelf) = @_;
680
    my ($code,$shelf) = @_;
610
    my $ref =  _biblionumber_sth($shelf)->fetchall_arrayref;
681
    my $ref =  _biblionumber_sth($shelf)->fetchall_arrayref;
611
    map {
682
    map {
Lines 614-619 sub each_biblionumbers (&$) { Link Here
614
    } @$ref;
685
    } @$ref;
615
}
686
}
616
687
688
sub _CheckShelfName {
689
    my ($name, $cat, $owner, $number)= @_;
690
691
    my $query = qq(
692
        SELECT DISTINCT shelfnumber
693
        FROM   virtualshelves
694
	LEFT JOIN virtualshelfshares sh USING (shelfnumber)
695
        WHERE  shelfname=? AND shelfnumber<>?);
696
    if($cat==1) {
697
        $query.= ' AND (sh.borrowernumber=? OR owner=?) AND category=1';
698
    }
699
    else {
700
        $query.= ' AND category=2';
701
    }
702
    my $sth = $dbh->prepare($query);
703
    $sth->execute($cat==1? ($name, $number, $owner, $owner): ($name, $number));
704
    return $sth->rows>0? 0: 1;
705
}
706
617
1;
707
1;
618
708
619
__END__
709
__END__
(-)a/C4/VirtualShelves/Page.pm (-57 / +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 69-75 sub shelfpage ($$$$$) { Link Here
69
    my $marcflavour = C4::Context->preference("marcflavour");
76
    my $marcflavour = C4::Context->preference("marcflavour");
70
77
71
    $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') );
78
    $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') );
72
    $shelflimit = $shelflimit || 20;
79
    $shelflimit = $shelflimit || ShelvesMax('MGRPAGE');
73
    $shelfoffset   = ( $itemoff - 1 ) * $shelflimit;     # Sets the offset to begin retrieving items at
80
    $shelfoffset   = ( $itemoff - 1 ) * $shelflimit;     # Sets the offset to begin retrieving items at
74
    $shelveslimit  = $shelflimit;                        # Limits number of shelves returned for a given query (row_count)
81
    $shelveslimit  = $shelflimit;                        # Limits number of shelves returned for a given query (row_count)
75
    $shelvesoffset = ( $shelfoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving shelves at (offset)
82
    $shelvesoffset = ( $shelfoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving shelves at (offset)
Lines 84-119 sub shelfpage ($$$$$) { Link Here
84
    }
91
    }
85
    my $op = $query->param('op');
92
    my $op = $query->param('op');
86
93
87
    #    my $imgdir = getitemtypeimagesrc();
88
    #    my $itemtypes = GetItemTypes();
89
90
    # the format of this is unindented for ease of diff comparison to the old script
94
    # the format of this is unindented for ease of diff comparison to the old script
91
    # Note: do not mistake the assignment statements below for comparisons!
95
    # Note: do not mistake the assignment statements below for comparisons!
92
    if ( $query->param('modifyshelfcontents') ) {
96
    if ( $query->param('modifyshelfcontents') ) {
93
        my ( $shelfnumber, $barcode, $item, $biblio );
97
        my ( $shelfnumber, $barcode, $item, $biblio );
94
        if ( $shelfnumber = $query->param('viewshelf') ) {
98
        if ( $shelfnumber = $query->param('viewshelf') ) {
95
            if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
99
            #add to shelf
96
                if ( $barcode = $query->param('addbarcode') ) {
100
            if($barcode = $query->param('addbarcode') ) {
97
                    $item = GetItem( 0, $barcode );
101
                if(ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')) {
98
                    if (defined $item && $item->{'itemnumber'}){
102
                    $item = GetItem( 0, $barcode);
103
                    if (defined $item && $item->{'itemnumber'}) {
99
                        $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'} );
104
                        $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'} );
100
                        AddToShelf( $biblio->{'biblionumber'}, $shelfnumber )
105
                        AddToShelf( $biblio->{'biblionumber'}, $shelfnumber, $loggedinuser)
101
                          or push @paramsloop, { duplicatebiblio => $barcode };
106
                          or push @paramsloop, { duplicatebiblio => $barcode };
102
                    } else {
107
                    }
108
                    else {
103
                        push @paramsloop, { failgetitem => $barcode };
109
                        push @paramsloop, { failgetitem => $barcode };
104
                    }
110
                    }
105
                } else {
111
                }
106
                    ( grep { /REM-(\d+)/ } $query->param ) or push @paramsloop, { nobarcode => 1 };
112
                else {
107
                    foreach ( $query->param ) {
113
                    push @paramsloop, { nopermission => $shelfnumber };
114
                }
115
            }
116
            elsif(grep { /REM-(\d+)/ } $query->param) {
117
            #remove item(s) from shelf
118
                if(ShelfPossibleAction($loggedinuser, $shelfnumber, 'delete')) {
119
                #This is just a general okay; DelFromShelf checks further
120
                    my @bib;
121
                    foreach($query->param) {
108
                        /REM-(\d+)/ or next;
122
                        /REM-(\d+)/ or next;
109
                        $debug and warn "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber";
123
                        push @bib, $1; #$1 is biblionumber
110
                        DelFromShelf( $1, $shelfnumber );    # $1 is biblionumber
124
                    }
125
                    my $t= DelFromShelf(\@bib, $shelfnumber, $loggedinuser);
126
                    if($t==0) {
127
                        push @paramsloop, {nothingdeleted => $shelfnumber};
128
                    }
129
                    elsif($t<@bib) {
130
                        push @paramsloop, {somedeleted => $shelfnumber};
111
                    }
131
                    }
112
                }
132
                }
113
            } else {
133
                else {
114
                push @paramsloop, { nopermission => $shelfnumber };
134
                    push @paramsloop, { nopermission => $shelfnumber };
135
                }
115
            }
136
            }
116
        } else {
137
        }
138
        else {
117
            push @paramsloop, { noshelfnumber => 1 };
139
            push @paramsloop, { noshelfnumber => 1 };
118
        }
140
        }
119
    }
141
    }
Lines 148-171 sub shelfpage ($$$$$) { Link Here
148
170
149
  SWITCH: {
171
  SWITCH: {
150
        if ($op) {
172
        if ($op) {
151
            unless ($okmanage) {
173
	    #Saving modified shelf
152
                push @paramsloop, { nopermission => $shelfnumber };
153
                last SWITCH;
154
            }
155
            if ( $op eq 'modifsave' ) {
174
            if ( $op eq 'modifsave' ) {
175
                unless ($okmanage) {
176
                        push @paramsloop, { nopermission => $shelfnumber };
177
                        last SWITCH;
178
                }
156
                my $shelf = {
179
                my $shelf = {
157
                    'shelfname' => $query->param('shelfname'),
180
                    'shelfname' => $query->param('shelfname'),
158
                    'category'  => $query->param('category'),
159
                    'sortfield' => $query->param('sortfield'),
181
                    'sortfield' => $query->param('sortfield'),
160
                };
182
                };
161
183
                if($query->param('category')) { #optional
162
                ModShelf( $shelfnumber, $shelf );
184
                    $shelf->{category}= $query->param('category');
163
185
                }
164
            } elsif ( $op eq 'modif' ) {
186
                unless(ModShelf($shelfnumber, $shelf )) {
187
                  push @paramsloop, {modifyfailure => $shelf->{shelfname}};
188
                  last SWITCH;
189
                }
190
            }
191
	    #Editing a shelf
192
	    elsif ( $op eq 'modif' ) {
165
                my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) = GetShelf($shelfnumber);
193
                my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) = GetShelf($shelfnumber);
166
                my $member = GetMember( 'borrowernumber' => $owner );
194
                my $member = GetMember( 'borrowernumber' => $owner );
167
                my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
195
                my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
168
                $edit = 1;
196
                $edit = 1;
197
                $sortfield='' unless $sortfield;
169
                $template->param(
198
                $template->param(
170
                    edit                => 1,
199
                    edit                => 1,
171
                    shelfnumber         => $shelfnumber2,
200
                    shelfnumber         => $shelfnumber2,
Lines 179-184 sub shelfpage ($$$$$) { Link Here
179
            }
208
            }
180
            last SWITCH;
209
            last SWITCH;
181
        }
210
        }
211
212
        #View a shelf
182
        if ( $shelfnumber = $query->param('viewshelf') ) {
213
        if ( $shelfnumber = $query->param('viewshelf') ) {
183
            # explicitly fetch this shelf
214
            # explicitly fetch this shelf
184
            my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber);
215
            my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber);
Lines 247-267 sub shelfpage ($$$$$) { Link Here
247
                    authorsort          => $authorsort,
278
                    authorsort          => $authorsort,
248
                    yearsort            => $yearsort,
279
                    yearsort            => $yearsort,
249
                    manageshelf         => $manageshelf,
280
                    manageshelf         => $manageshelf,
281
                    allowremovingitems  => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete'),
282
                    allowaddingitem     => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add'),
250
                    "category$category" => 1,
283
                    "category$category" => 1,
251
                    category            => $category,
284
                    category            => $category,
252
                    itemsloop           => $items,
285
                    itemsloop           => $items,
286
                    showprivateshelves  => $category==1,
253
                );
287
                );
254
            } else {
288
            } else {
255
                push @paramsloop, { nopermission => $shelfnumber };
289
                push @paramsloop, { nopermission => $shelfnumber };
256
            }
290
            }
257
            last SWITCH;
291
            last SWITCH;
258
        }
292
        }
293
259
        if ( $query->param('shelves') ) {
294
        if ( $query->param('shelves') ) {
260
            my $stay = 1;
295
            my $stay = 1;
296
297
	    #Add a shelf
261
            if ( my $newshelf = $query->param('addshelf') ) {
298
            if ( my $newshelf = $query->param('addshelf') ) {
262
299
263
                # note: a user can always add a new shelf
300
                # note: a user can always add a new shelf
264
                my $shelfnumber = AddShelf( $newshelf, $query->param('owner'), $query->param('category'), $query->param('sortfield') );
301
                my $shelfnumber = AddShelf( {
302
                    shelfname => $newshelf,
303
                    sortfield => $query->param('sortfield'),
304
                    category => $query->param('category') },
305
                    $query->param('owner') );
265
                $stay = 1;
306
                $stay = 1;
266
                if ( $shelfnumber == -1 ) {    #shelf already exists.
307
                if ( $shelfnumber == -1 ) {    #shelf already exists.
267
                    $showadd = 1;
308
                    $showadd = 1;
Lines 272-277 sub shelfpage ($$$$$) { Link Here
272
                    exit;
313
                    exit;
273
                }
314
                }
274
            }
315
            }
316
317
	    #Deleting a shelf (asking for confirmation if it has entries)
275
            foreach ( $query->param() ) {
318
            foreach ( $query->param() ) {
276
                /DEL-(\d+)/ or next;
319
                /DEL-(\d+)/ or next;
277
                $delflag = 1;
320
                $delflag = 1;
Lines 313-319 sub shelfpage ($$$$$) { Link Here
313
                }
356
                }
314
                push( @paramsloop, { delete_ok => $name } );
357
                push( @paramsloop, { delete_ok => $name } );
315
358
316
                # print $query->redirect($pages{$type}->{redirect}); exit;
317
                $stay = 0;
359
                $stay = 0;
318
            }
360
            }
319
            $showadd = 1;
361
            $showadd = 1;
Lines 323-329 sub shelfpage ($$$$$) { Link Here
323
            }
365
            }
324
            last SWITCH;
366
            last SWITCH;
325
        }
367
        }
326
    }
368
    } # end of SWITCH block
327
369
328
    (@paramsloop) and $template->param( paramsloop => \@paramsloop );
370
    (@paramsloop) and $template->param( paramsloop => \@paramsloop );
329
    $showadd      and $template->param( showadd    => 1 );
371
    $showadd      and $template->param( showadd    => 1 );
Lines 337-343 sub shelfpage ($$$$$) { Link Here
337
        my %line;
379
        my %line;
338
        $shelflist->{$element}->{shelf} = $element;
380
        $shelflist->{$element}->{shelf} = $element;
339
        my $category  = $shelflist->{$element}->{'category'};
381
        my $category  = $shelflist->{$element}->{'category'};
340
        my $owner     = $shelflist->{$element}->{'owner'};
382
        my $owner     = $shelflist->{$element}->{'owner'}||0;
341
        my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
383
        my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
342
        my $sortfield = $shelflist->{$element}->{'sortfield'};
384
        my $sortfield = $shelflist->{$element}->{'sortfield'};
343
        if ( $sortfield ){
385
        if ( $sortfield ){
Lines 349-355 sub shelfpage ($$$$$) { Link Here
349
        }
391
        }
350
        $shelflist->{$element}->{"viewcategory$category"} = 1;
392
        $shelflist->{$element}->{"viewcategory$category"} = 1;
351
        $shelflist->{$element}->{manageshelf} = $canmanage;
393
        $shelflist->{$element}->{manageshelf} = $canmanage;
352
        if ( $owner eq $loggedinuser or $canmanage ) {
394
        if($canmanage || ($loggedinuser && $owner==$loggedinuser)) {
353
            $shelflist->{$element}->{'mine'} = 1;
395
            $shelflist->{$element}->{'mine'} = 1;
354
        }
396
        }
355
        my $member = GetMember( 'borrowernumber' => $owner );
397
        my $member = GetMember( 'borrowernumber' => $owner );
Lines 393-420 sub shelfpage ($$$$$) { Link Here
393
        $template->param( seflag => 1 );
435
        $template->param( seflag => 1 );
394
    }
436
    }
395
437
396
    #FIXME: This refresh really only needs to happen when there is a modification of some sort
438
#Next call updates the shelves for the Lists button.
397
    #       to the shelves, but the above code is so convoluted in its handling of the various
439
#May not always be needed (when nothing changed), but doesn't take much.
398
    #       options, it is easier to do this refresh every time C4::VirtualShelves::Page.pm is
440
    my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($loggedinuser, 'MASTHEAD');
399
    #       called
441
    $template->param(
400
442
            barshelves     => $total->{bartotal},
401
    my ( $total, $pubshelves, $barshelves ) = RefreshShelvesSummary( $query->cookie("CGISESSID"), $loggedinuser, ( $loggedinuser == -1 ? 20 : 10 ) );
402
403
    if ( defined $barshelves ) {
404
        $template->param(
405
            barshelves     => scalar( @{ $barshelves } ),
406
            barshelvesloop => $barshelves,
443
            barshelvesloop => $barshelves,
407
        );
444
            pubshelves     => $total->{pubtotal},
408
        $template->param( bartotal => $total->{'bartotal'}, ) if ( $total->{'bartotal'} > scalar( @{ $barshelves } ) );
409
    }
410
411
    if ( defined $pubshelves ) {
412
        $template->param(
413
            pubshelves     => scalar( @{ $pubshelves } ),
414
            pubshelvesloop => $pubshelves,
445
            pubshelvesloop => $pubshelves,
415
        );
446
    );
416
        $template->param( pubtotal => $total->{'pubtotal'}, ) if ( $total->{'pubtotal'} > scalar( @{ $pubshelves } ) );
417
    }
418
447
419
    output_html_with_http_headers $query, $cookie, $template->output;
448
    output_html_with_http_headers $query, $cookie, $template->output;
420
}
449
}
(-)a/catalogue/search.pl (-16 / +8 lines)
Lines 695-715 if ($query_desc || $limit_desc) { Link Here
695
# VI. BUILD THE TEMPLATE
695
# VI. BUILD THE TEMPLATE
696
696
697
# Build drop-down list for 'Add To:' menu...
697
# Build drop-down list for 'Add To:' menu...
698
698
my ($barshelves, $totalb) = GetRecentShelves(1, undef, $borrowernumber, 1);
699
my $row_count = 10; # FIXME:This probably should be a syspref
699
my ($pubshelves, $totalp) = GetRecentShelves(2, undef, undef, 1);
700
my ($pubshelves, $total) = GetRecentShelves(2, $row_count, undef);
700
$template->param(
701
my ($barshelves, $total) = GetRecentShelves(1, $row_count, $borrowernumber);
701
        addbarshelves     => $totalb,
702
702
        addbarshelvesloop => $barshelves,
703
if (@{$pubshelves}) {
703
	addpubshelves     => $totalp,
704
        $template->param( addpubshelves     => scalar @{$pubshelves});
704
	addpubshelvesloop => $pubshelves,
705
        $template->param( addpubshelvesloop => $pubshelves);
705
	);
706
}
707
708
if (@{$barshelves}) {
709
        $template->param( addbarshelves     => scalar @{$barshelves});
710
        $template->param( addbarshelvesloop => $barshelves);
711
}
712
713
714
706
715
output_html_with_http_headers $cgi, $cookie, $template->output;
707
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 (-17 / +7 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
			No Private Lists
161
		[% END %]
158
		[% END %]
162
		[% IF ( bartotal ) %]
159
	[% ELSE %]
163
			<ul class="second-of-type">
160
		<ul class="first-of-type"><li><a href="/cgi-bin/koha/opac-user.pl">Log in to Create Your Own Lists</a></li></ul>
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>
161
	[% END %]
165
			</ul>
166
		[% END %]
167
		<ul class="second-of-type">
168
        <li class="yuimenuitem"><a class="yuimenuitemlabel" href="/cgi-bin/koha/opac-shelves.pl">Manage Lists</a></li>
169
        </ul>
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 %]
162
  [% END %]
173
	  </div>
163
	  </div>
174
</div><!-- /listmenu /virtualshelves -->
164
</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 (-8 / +18 lines)
Lines 175-180 $(function() { Link Here
175
                    [% IF ( paramsloo.unrecognized ) %]
175
                    [% IF ( paramsloo.unrecognized ) %]
176
                      <div class="dialog message">ERROR: List number [% paramsloo.unrecognized %] unrecognized.</div>
176
                      <div class="dialog message">ERROR: List number [% paramsloo.unrecognized %] unrecognized.</div>
177
                    [% END %]
177
                    [% END %]
178
                    [% IF ( paramsloo.modifyfailure) %]
179
                      <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>
180
                    [% END %]
181
                    [% IF ( paramsloo.nothingdeleted) %]
182
                      <div class="dialog message">Warning: No items have been deleted from shelf [% paramsloo.nothingdeleted%]. Check your permissions for this list.</div>
183
                    [% END %]
184
                    [% IF ( paramsloo.somedeleted) %]
185
                      <div class="dialog message">Warning: Not all items may have been deleted from shelf [% paramsloo.somedeleted%]. Check your permissions for this list.</div>
186
                    [% END %]
178
                  </div>
187
                  </div>
179
                </div>
188
                </div>
180
              [% END %]<!-- /paramsloop -->
189
              [% END %]<!-- /paramsloop -->
Lines 351-371 $(function() { Link Here
351
            [% END %]<!-- /viewshelf -->
360
            [% END %]<!-- /viewshelf -->
352
361
353
362
354
            [% IF ( manageshelf ) %]
363
            [% IF ( itemsloop && allowremovingitems ) %]
355
              <!-- Editing shelf -->
364
                <form method="post" action="opac-shelves.pl">
356
              [% IF ( itemsloop ) %]
357
                <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
365
                <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
358
                <input type="hidden" name="modifyshelfcontents" value="1" />
366
                <input type="hidden" name="modifyshelfcontents" value="1" />
359
                <input type="hidden" name="viewshelf" value="[% shelfnumber %]" /><input type="submit" value="Remove Selected Items" class="icon delete" onclick="return confirmDelete(MSG_REMOVE_FROM_LIST)" />
367
                <input type="hidden" name="viewshelf" value="[% shelfnumber %]" /><input type="submit" value="Remove Selected Items" class="icon delete" onclick="return confirmDelete(MSG_REMOVE_FROM_LIST)" />
360
              [% ELSE %]
368
                </form>
369
            [% ELSIF ( !itemsloop && manageshelf ) %]
361
                <form method="post" action="opac-shelves.pl">
370
                <form method="post" action="opac-shelves.pl">
362
                  <input type="hidden" name="DEL-[% shelfnumber %]" value="1" />
371
                  <input type="hidden" name="DEL-[% shelfnumber %]" value="1" />
363
                  <input type="hidden" name="shelves" value="1" />
372
                  <input type="hidden" name="shelves" value="1" />
364
		  <input type="hidden" name="shelfoff" value="[% shelfoff %]" />
373
		  <input type="hidden" name="shelfoff" value="[% shelfoff %]" />
365
                  <input type="submit" class="icon delete" value="Delete this List" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST)" />
374
                  <input type="submit" class="icon delete" value="Delete this List" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST)" />
366
              [% END %]
367
            [% END %]
368
                </form>
375
                </form>
376
            [% END %]
369
377
370
            
378
            
371
            [% IF ( edit ) %]
379
            [% IF ( edit ) %]
Lines 386-396 $(function() { Link Here
386
                        </select>
394
                        </select>
387
                      </li>
395
                      </li>
388
                      <li>
396
                      <li>
397
			[% IF (OpacAllowPublicListCreation) %]
389
                        <label for="category">Category:</label>
398
                        <label for="category">Category:</label>
390
                        <select name="category" id="category">
399
                        <select name="category" id="category">
391
                          [% IF ( category1 ) %]<option value="1" selected="selected">Private</option>[% ELSE %]<option value="1">Private</option>[% END %]
400
                          [% IF ( category1 ) %]<option value="1" selected="selected">Private</option>[% ELSE %]<option value="1">Private</option>[% END %]
392
                          [% IF ( category2 ) %]<option value="2" selected="selected">Public</option>[% ELSE %]<option value="2">Public</option>[% END %]
401
                          [% IF ( category2 ) %]<option value="2" selected="selected">Public</option>[% ELSE %]<option value="2">Public</option>[% END %]
393
                        </select>
402
                        </select>
403
			[% END %]
394
                      </li>
404
                      </li>
395
                    </ol>
405
                    </ol>
396
                  </fieldset>
406
                  </fieldset>
Lines 444-450 $(function() { Link Here
444
                              <td>
454
                              <td>
445
                                [% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
455
                                [% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
446
                                [% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
456
                                [% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
447
                                [% IF ( shelveslooppri.viewcategory3 ) %]Open[% END %]
448
                              </td>
457
                              </td>
449
                              <td>
458
                              <td>
450
                              [% IF ( shelveslooppri.mine ) %]
459
                              [% IF ( shelveslooppri.mine ) %]
Lines 511-517 $(function() { Link Here
511
                          <td>
520
                          <td>
512
                            [% IF ( shelvesloo.viewcategory1 ) %]Private[% END %]
521
                            [% IF ( shelvesloo.viewcategory1 ) %]Private[% END %]
513
                            [% IF ( shelvesloo.viewcategory2 ) %]Public[% END %]
522
                            [% IF ( shelvesloo.viewcategory2 ) %]Public[% END %]
514
                            [% IF ( shelvesloo.viewcategory3 ) %]Open[% END %]
515
	                      </td>
523
	                      </td>
516
                          <td>
524
                          <td>
517
							[% IF ( shelvesloo.mine ) %]
525
							[% IF ( shelvesloo.mine ) %]
Lines 574-580 $(function() { Link Here
574
                        <label for="category">Category:</label>
582
                        <label for="category">Category:</label>
575
                        <select name="category" id="category">
583
                        <select name="category" id="category">
576
                          <option value="1">Private</option>
584
                          <option value="1">Private</option>
585
			  [% IF (OpacAllowPublicListCreation) %]
577
                          <option value="2">Public</option>
586
                          <option value="2">Public</option>
587
			  [% END %]
578
                        </select>
588
                        </select>
579
                      </li>
589
                      </li>
580
                    </ol>
590
                    </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);
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);
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 718-741 if ($query_desc || $limit_desc) { Link Here
718
719
719
# VI. BUILD THE TEMPLATE
720
# VI. BUILD THE TEMPLATE
720
# Build drop-down list for 'Add To:' menu...
721
# Build drop-down list for 'Add To:' menu...
721
my $session = get_session($cgi->cookie("CGISESSID"));
722
my ($totalref, $pubshelves, $barshelves)=
722
my @addpubshelves;
723
	C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1);
723
my $pubshelves = $session->param('pubshelves');
724
$template->param(
724
my $barshelves = $session->param('barshelves');
725
	addbarshelves     => $totalref->{bartotal},
725
foreach my $shelf (@$pubshelves) {
726
	addbarshelvesloop => $barshelves,
726
    next if ( ($shelf->{'owner'} != ($borrowernumber ? $borrowernumber : -1)) && ($shelf->{'category'} < 3) );
727
	addpubshelves     => $totalref->{pubtotal},
727
    push (@addpubshelves, $shelf);
728
	addpubshelvesloop => $pubshelves,
728
}
729
	);
729
730
if (@addpubshelves) {
731
    $template->param( addpubshelves     => scalar (@addpubshelves));
732
    $template->param( addpubshelvesloop => \@addpubshelves);
733
}
734
735
if (defined $barshelves) {
736
    $template->param( addbarshelves     => scalar (@$barshelves));
737
    $template->param( addbarshelvesloop => $barshelves);
738
}
739
730
740
my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
731
my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
741
732
(-)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);
191
                        } );
179
    my $publicshelves = GetAllShelves(2,$loggedinuser);
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