Lines 36-53
use constant SHELVES_POPUP_MAX => 40; #addbybiblio popup
Link Here
|
36 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
36 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
37 |
|
37 |
|
38 |
BEGIN { |
38 |
BEGIN { |
39 |
# set the version for version checking |
39 |
# set the version for version checking |
40 |
$VERSION = 3.02; |
40 |
$VERSION = 3.02; |
41 |
require Exporter; |
41 |
require Exporter; |
42 |
@ISA = qw(Exporter); |
42 |
@ISA = qw(Exporter); |
43 |
@EXPORT = qw( |
43 |
@EXPORT = qw( |
44 |
&GetShelves &GetShelfContents &GetShelf |
44 |
&GetShelves &GetShelfContents &GetShelf |
45 |
&AddToShelf &AddShelf |
45 |
&AddToShelf &AddShelf |
46 |
&ModShelf |
46 |
&ModShelf |
47 |
&ShelfPossibleAction |
47 |
&ShelfPossibleAction |
48 |
&DelFromShelf &DelShelf |
48 |
&DelFromShelf &DelShelf |
49 |
&GetBibliosShelves |
49 |
&GetBibliosShelves |
50 |
); |
50 |
); |
51 |
@EXPORT_OK = qw( |
51 |
@EXPORT_OK = qw( |
52 |
&GetAllShelves &ShelvesMax |
52 |
&GetAllShelves &ShelvesMax |
53 |
); |
53 |
); |
Lines 116-122
sub GetShelves {
Link Here
|
116 |
$query.= qq{ |
116 |
$query.= qq{ |
117 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
117 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
118 |
AND sh.borrowernumber=? |
118 |
AND sh.borrowernumber=? |
119 |
WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
119 |
WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
120 |
@params= ($owner, $owner, $owner, $offset||0, $row_count); |
120 |
@params= ($owner, $owner, $owner, $offset||0, $row_count); |
121 |
} |
121 |
} |
122 |
else { |
122 |
else { |
Lines 164-174
sub GetAllShelves {
Link Here
|
164 |
$query.= qq{ |
164 |
$query.= qq{ |
165 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
165 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
166 |
AND sh.borrowernumber=? |
166 |
AND sh.borrowernumber=? |
167 |
WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
167 |
WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
168 |
@params = ($owner, $owner, $owner); |
168 |
@params = ($owner, $owner, $owner); |
169 |
} |
169 |
} |
170 |
else { |
170 |
else { |
171 |
$query.='WHERE category=2 '; |
171 |
$query.='WHERE category=2 '; |
172 |
@params = (); |
172 |
@params = (); |
173 |
} |
173 |
} |
174 |
$query.='AND (allow_add=1 OR owner=?) ' if $adding_allowed; |
174 |
$query.='AND (allow_add=1 OR owner=?) ' if $adding_allowed; |
Lines 261-301
from C4::Circulation.
Link Here
|
261 |
sub GetShelfContents ($;$$$) { |
261 |
sub GetShelfContents ($;$$$) { |
262 |
my ($shelfnumber, $row_count, $offset, $sortfield) = @_; |
262 |
my ($shelfnumber, $row_count, $offset, $sortfield) = @_; |
263 |
my $dbh=C4::Context->dbh(); |
263 |
my $dbh=C4::Context->dbh(); |
264 |
my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?"); |
264 |
my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?"); |
265 |
$sth1->execute($shelfnumber); |
265 |
$sth1->execute($shelfnumber); |
266 |
my $total = $sth1->fetchrow; |
266 |
my $total = $sth1->fetchrow; |
267 |
if(!$sortfield) { |
267 |
if(!$sortfield) { |
268 |
my $sth2 = $dbh->prepare('SELECT sortfield FROM virtualshelves WHERE shelfnumber=?'); |
268 |
my $sth2 = $dbh->prepare('SELECT sortfield FROM virtualshelves WHERE shelfnumber=?'); |
269 |
$sth2->execute($shelfnumber); |
269 |
$sth2->execute($shelfnumber); |
270 |
($sortfield) = $sth2->fetchrow_array; |
270 |
($sortfield) = $sth2->fetchrow_array; |
271 |
} |
271 |
} |
272 |
my $query = |
272 |
my $query = |
273 |
" SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*, |
273 |
" SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*, |
274 |
biblio.*, biblioitems.itemtype, biblioitems.publicationyear as year, biblioitems.publishercode, biblioitems.place, biblioitems.size, biblioitems.pages |
274 |
biblio.*, biblioitems.itemtype, biblioitems.publicationyear as year, biblioitems.publishercode, biblioitems.place, biblioitems.size, biblioitems.pages |
275 |
FROM virtualshelfcontents vc |
275 |
FROM virtualshelfcontents vc |
276 |
LEFT JOIN biblio ON vc.biblionumber = biblio.biblionumber |
276 |
LEFT JOIN biblio ON vc.biblionumber = biblio.biblionumber |
277 |
LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber |
277 |
LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber |
278 |
LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype |
278 |
LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype |
279 |
WHERE vc.shelfnumber=? "; |
279 |
WHERE vc.shelfnumber=? "; |
280 |
my @params = ($shelfnumber); |
280 |
my @params = ($shelfnumber); |
281 |
if($sortfield) { |
281 |
if($sortfield) { |
282 |
$query .= " ORDER BY " . $sortfield; |
282 |
$query .= " ORDER BY " . $sortfield; |
283 |
$query .= " DESC " if ($sortfield eq 'copyrightdate'); |
283 |
$query .= " DESC " if ($sortfield eq 'copyrightdate'); |
284 |
} |
284 |
} |
285 |
if($row_count){ |
285 |
if($row_count){ |
286 |
$query .= " LIMIT ?, ? "; |
286 |
$query .= " LIMIT ?, ? "; |
287 |
push (@params, ($offset ? $offset : 0)); |
287 |
push (@params, ($offset ? $offset : 0)); |
288 |
push (@params, $row_count); |
288 |
push (@params, $row_count); |
289 |
} |
289 |
} |
290 |
my $sth3 = $dbh->prepare($query); |
290 |
my $sth3 = $dbh->prepare($query); |
291 |
$sth3->execute(@params); |
291 |
$sth3->execute(@params); |
292 |
return ($sth3->fetchall_arrayref({}), $total); |
292 |
return ($sth3->fetchall_arrayref({}), $total); |
293 |
# Like the perldoc says, |
293 |
# Like the perldoc says, |
294 |
# returns reference-to-array, where each element is reference-to-hash of the row: |
294 |
# returns reference-to-array, where each element is reference-to-hash of the row: |
295 |
# like [ $sth->fetchrow_hashref(), $sth->fetchrow_hashref() ... ] |
295 |
# like [ $sth->fetchrow_hashref(), $sth->fetchrow_hashref() ... ] |
296 |
# Suitable for use in TMPL_LOOP. |
296 |
# Suitable for use in TMPL_LOOP. |
297 |
# See http://search.cpan.org/~timb/DBI-1.601/DBI.pm#fetchall_arrayref |
297 |
# See http://search.cpan.org/~timb/DBI-1.601/DBI.pm#fetchall_arrayref |
298 |
# or newer, for your version of DBI. |
298 |
# or newer, for your version of DBI. |
299 |
} |
299 |
} |
300 |
|
300 |
|
301 |
=head2 AddShelf |
301 |
=head2 AddShelf |
Lines 326-338
sub AddShelf {
Link Here
|
326 |
|
326 |
|
327 |
my $sth = $dbh->prepare($query); |
327 |
my $sth = $dbh->prepare($query); |
328 |
$sth->execute( |
328 |
$sth->execute( |
329 |
$hashref->{shelfname}, |
329 |
$hashref->{shelfname}, |
330 |
$owner, |
330 |
$owner, |
331 |
$hashref->{category}, |
331 |
$hashref->{category}, |
332 |
$hashref->{sortfield}, |
332 |
$hashref->{sortfield}, |
333 |
$hashref->{allow_add}||0, |
333 |
$hashref->{allow_add}||0, |
334 |
$hashref->{allow_delete_own}||1, |
334 |
$hashref->{allow_delete_own}||1, |
335 |
$hashref->{allow_delete_other}||0 ); |
335 |
$hashref->{allow_delete_other}||0 ); |
336 |
my $shelfnumber = $dbh->{'mysql_insertid'}; |
336 |
my $shelfnumber = $dbh->{'mysql_insertid'}; |
337 |
return $shelfnumber; |
337 |
return $shelfnumber; |
338 |
} |
338 |
} |
Lines 358-374
sub AddToShelf {
Link Here
|
358 |
|
358 |
|
359 |
$sth->execute( $shelfnumber, $biblionumber ); |
359 |
$sth->execute( $shelfnumber, $biblionumber ); |
360 |
($sth->rows) and return undef; # already on shelf |
360 |
($sth->rows) and return undef; # already on shelf |
361 |
$query = qq( |
361 |
$query = qq( |
362 |
INSERT INTO virtualshelfcontents |
362 |
INSERT INTO virtualshelfcontents |
363 |
(shelfnumber, biblionumber, flags, borrowernumber) |
363 |
(shelfnumber, biblionumber, flags, borrowernumber) |
364 |
VALUES (?, ?, 0, ?)); |
364 |
VALUES (?, ?, 0, ?)); |
365 |
$sth = $dbh->prepare($query); |
365 |
$sth = $dbh->prepare($query); |
366 |
$sth->execute( $shelfnumber, $biblionumber, $borrowernumber); |
366 |
$sth->execute( $shelfnumber, $biblionumber, $borrowernumber); |
367 |
$query = qq(UPDATE virtualshelves |
367 |
$query = qq(UPDATE virtualshelves |
368 |
SET lastmodified = CURRENT_TIMESTAMP |
368 |
SET lastmodified = CURRENT_TIMESTAMP |
369 |
WHERE shelfnumber = ?); |
369 |
WHERE shelfnumber = ?); |
370 |
$sth = $dbh->prepare($query); |
370 |
$sth = $dbh->prepare($query); |
371 |
$sth->execute( $shelfnumber ); |
371 |
$sth->execute( $shelfnumber ); |
372 |
} |
372 |
} |
373 |
|
373 |
|
374 |
=head2 ModShelf |
374 |
=head2 ModShelf |
Lines 403-412
sub ModShelf {
Link Here
|
403 |
#if name or category changes, the name should be tested |
403 |
#if name or category changes, the name should be tested |
404 |
if($hashref->{shelfname} || $hashref->{category}) { |
404 |
if($hashref->{shelfname} || $hashref->{category}) { |
405 |
unless(_CheckShelfName( |
405 |
unless(_CheckShelfName( |
406 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
406 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
407 |
$hashref->{category}||$oldrecord->{category}, |
407 |
$hashref->{category}||$oldrecord->{category}, |
408 |
$oldrecord->{owner}, $shelfnumber )) { |
408 |
$oldrecord->{owner}, $shelfnumber )) { |
409 |
return 0; #name check failed |
409 |
return 0; #name check failed |
410 |
} |
410 |
} |
411 |
} |
411 |
} |
412 |
|
412 |
|
Lines 414-426
sub ModShelf {
Link Here
|
414 |
$query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; |
414 |
$query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; |
415 |
$sth = $dbh->prepare($query); |
415 |
$sth = $dbh->prepare($query); |
416 |
$sth->execute( |
416 |
$sth->execute( |
417 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
417 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
418 |
$hashref->{category}||$oldrecord->{category}, |
418 |
$hashref->{category}||$oldrecord->{category}, |
419 |
$hashref->{sortfield}||$oldrecord->{sortfield}, |
419 |
$hashref->{sortfield}||$oldrecord->{sortfield}, |
420 |
$hashref->{allow_add}||$oldrecord->{allow_add}, |
420 |
$hashref->{allow_add}||$oldrecord->{allow_add}, |
421 |
$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own}, |
421 |
$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own}, |
422 |
$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other}, |
422 |
$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other}, |
423 |
$shelfnumber ); |
423 |
$shelfnumber ); |
424 |
return $@? 0: 1; |
424 |
return $@? 0: 1; |
425 |
} |
425 |
} |
426 |
|
426 |
|
Lines 471-493
sub ShelfPossibleAction {
Link Here
|
471 |
|
471 |
|
472 |
return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || $shelf->{borrowernumber}==$user); |
472 |
return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || $shelf->{borrowernumber}==$user); |
473 |
if($action eq 'view') { |
473 |
if($action eq 'view') { |
474 |
#already handled in the above condition |
474 |
#already handled in the above condition |
475 |
return 1; |
475 |
return 1; |
476 |
} |
476 |
} |
477 |
elsif($action eq 'add') { |
477 |
elsif($action eq 'add') { |
478 |
return 0 if $user<=0; #should be logged in |
478 |
return 0 if $user<=0; #should be logged in |
479 |
return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user; |
479 |
return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user; |
480 |
#owner may always add |
480 |
#owner may always add |
481 |
} |
481 |
} |
482 |
elsif($action eq 'delete') { |
482 |
elsif($action eq 'delete') { |
483 |
#this answer is just diplomatic: it says that you may be able to delete |
483 |
#this answer is just diplomatic: it says that you may be able to delete |
484 |
#some items from that shelf |
484 |
#some items from that shelf |
485 |
#it does not answer the question about a specific biblio |
485 |
#it does not answer the question about a specific biblio |
486 |
#DelFromShelf checks the situation per biblio |
486 |
#DelFromShelf checks the situation per biblio |
487 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
487 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
488 |
} |
488 |
} |
489 |
elsif($action eq 'manage') { |
489 |
elsif($action eq 'manage') { |
490 |
return 1 if $user && $shelf->{owner}==$user; |
490 |
return 1 if $user && $shelf->{owner}==$user; |
491 |
} |
491 |
} |
492 |
return 0; |
492 |
return 0; |
493 |
} |
493 |
} |
Lines 515-525
sub DelFromShelf {
Link Here
|
515 |
$query = qq(DELETE FROM virtualshelfcontents |
515 |
$query = qq(DELETE FROM virtualshelfcontents |
516 |
WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?); |
516 |
WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?); |
517 |
$sth= $dbh->prepare($query); |
517 |
$sth= $dbh->prepare($query); |
518 |
foreach my $biblionumber (@$bibref) { |
518 |
foreach my $biblionumber (@$bibref) { |
519 |
$sth->execute($shelfnumber, $biblionumber, $user); |
519 |
$sth->execute($shelfnumber, $biblionumber, $user); |
520 |
$r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1) |
520 |
$r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1) |
521 |
$t+= ($r==-1)? 1: $r; |
521 |
$t+= ($r==-1)? 1: $r; |
522 |
} |
522 |
} |
523 |
} |
523 |
} |
524 |
if($del_oth) { |
524 |
if($del_oth) { |
525 |
#includes a check if borrowernumber is null (deleted patron) |
525 |
#includes a check if borrowernumber is null (deleted patron) |
Lines 527-537
sub DelFromShelf {
Link Here
|
527 |
WHERE shelfnumber=? AND biblionumber=? AND |
527 |
WHERE shelfnumber=? AND biblionumber=? AND |
528 |
(borrowernumber IS NULL OR borrowernumber<>?)/; |
528 |
(borrowernumber IS NULL OR borrowernumber<>?)/; |
529 |
$sth= $dbh->prepare($query); |
529 |
$sth= $dbh->prepare($query); |
530 |
foreach my $biblionumber (@$bibref) { |
530 |
foreach my $biblionumber (@$bibref) { |
531 |
$sth->execute($shelfnumber, $biblionumber, $user); |
531 |
$sth->execute($shelfnumber, $biblionumber, $user); |
532 |
$r= $sth->rows; |
532 |
$r= $sth->rows; |
533 |
$t+= ($r==-1)? 1: $r; |
533 |
$t+= ($r==-1)? 1: $r; |
534 |
} |
534 |
} |
535 |
} |
535 |
} |
536 |
return $t; |
536 |
return $t; |
537 |
} |
537 |
} |
Lines 639-649
sub _shelf_count {
Link Here
|
639 |
$query.= qq{ |
639 |
$query.= qq{ |
640 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
640 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
641 |
AND sh.borrowernumber=? |
641 |
AND sh.borrowernumber=? |
642 |
WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
642 |
WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
643 |
@params= ($owner, $owner, $owner); |
643 |
@params= ($owner, $owner, $owner); |
644 |
} |
644 |
} |
645 |
else { |
645 |
else { |
646 |
$query.='WHERE category=2'; |
646 |
$query.='WHERE category=2'; |
647 |
@params= (); |
647 |
@params= (); |
648 |
} |
648 |
} |
649 |
my $sth = $dbh->prepare($query); |
649 |
my $sth = $dbh->prepare($query); |
Lines 657-665
sub _biblionumber_sth { #only used in obsolete sub below
Link Here
|
657 |
my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?'; |
657 |
my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?'; |
658 |
my $dbh = C4::Context->dbh; |
658 |
my $dbh = C4::Context->dbh; |
659 |
my $sth = $dbh->prepare($query) |
659 |
my $sth = $dbh->prepare($query) |
660 |
or die $dbh->errstr; |
660 |
or die $dbh->errstr; |
661 |
$sth->execute( $shelf ) |
661 |
$sth->execute( $shelf ) |
662 |
or die $sth->errstr; |
662 |
or die $sth->errstr; |
663 |
$sth; |
663 |
$sth; |
664 |
} |
664 |
} |
665 |
|
665 |
|
Lines 667-674
sub each_biblionumbers (&$) { #OBSOLETE
Link Here
|
667 |
my ($code,$shelf) = @_; |
667 |
my ($code,$shelf) = @_; |
668 |
my $ref = _biblionumber_sth($shelf)->fetchall_arrayref; |
668 |
my $ref = _biblionumber_sth($shelf)->fetchall_arrayref; |
669 |
map { |
669 |
map { |
670 |
$_=$$_[0]; |
670 |
$_=$$_[0]; |
671 |
$code->(); |
671 |
$code->(); |
672 |
} @$ref; |
672 |
} @$ref; |
673 |
} |
673 |
} |
674 |
|
674 |
|
Lines 678-684
sub _CheckShelfName {
Link Here
|
678 |
my $query = qq( |
678 |
my $query = qq( |
679 |
SELECT DISTINCT shelfnumber |
679 |
SELECT DISTINCT shelfnumber |
680 |
FROM virtualshelves |
680 |
FROM virtualshelves |
681 |
LEFT JOIN virtualshelfshares sh USING (shelfnumber) |
681 |
LEFT JOIN virtualshelfshares sh USING (shelfnumber) |
682 |
WHERE shelfname=? AND shelfnumber<>?); |
682 |
WHERE shelfname=? AND shelfnumber<>?); |
683 |
if($cat==1) { |
683 |
if($cat==1) { |
684 |
$query.= ' AND (sh.borrowernumber=? OR owner=?) AND category=1'; |
684 |
$query.= ' AND (sh.borrowernumber=? OR owner=?) AND category=1'; |