Lines 1-9
Link Here
|
1 |
# -*- tab-width: 8 -*- |
|
|
2 |
# Please use 8-character tabs for this file (indents are every 4 characters) |
3 |
|
4 |
package C4::VirtualShelves; |
1 |
package C4::VirtualShelves; |
5 |
|
2 |
|
6 |
|
|
|
7 |
# Copyright 2000-2002 Katipo Communications |
3 |
# Copyright 2000-2002 Katipo Communications |
8 |
# |
4 |
# |
9 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
Lines 198-217
sub GetSomeShelfNames {
Link Here
|
198 |
$qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit"; |
194 |
$qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit"; |
199 |
|
195 |
|
200 |
unless($adding_allowed && (!defined($owner) || $owner<=0)) { |
196 |
unless($adding_allowed && (!defined($owner) || $owner<=0)) { |
201 |
#if adding items, user should be known |
197 |
#if adding items, user should be known |
202 |
$pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params); |
198 |
$pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params); |
203 |
} |
199 |
} |
204 |
|
200 |
|
205 |
if($owner) { |
201 |
if($owner) { |
206 |
my $qry2= $bquery. qq{ |
202 |
my $qry2= $bquery. qq{ |
207 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=? |
203 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=? |
208 |
WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
204 |
WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; |
209 |
@params=($owner,$owner,$owner); |
205 |
@params=($owner,$owner,$owner); |
210 |
$qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed; |
206 |
$qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed; |
211 |
push @params, $owner if $adding_allowed; |
207 |
push @params, $owner if $adding_allowed; |
212 |
$qry2.= "ORDER BY vs.lastmodified DESC "; |
208 |
$qry2.= "ORDER BY vs.lastmodified DESC "; |
213 |
$qry2.= "LIMIT $limit"; |
209 |
$qry2.= "LIMIT $limit"; |
214 |
$bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params); |
210 |
$bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params); |
215 |
} |
211 |
} |
216 |
|
212 |
|
217 |
return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar); |
213 |
return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar); |
Lines 326-338
sub AddShelf {
Link Here
|
326 |
|
322 |
|
327 |
my $sth = $dbh->prepare($query); |
323 |
my $sth = $dbh->prepare($query); |
328 |
$sth->execute( |
324 |
$sth->execute( |
329 |
$hashref->{shelfname}, |
325 |
$hashref->{shelfname}, |
330 |
$owner, |
326 |
$owner, |
331 |
$hashref->{category}, |
327 |
$hashref->{category}, |
332 |
$hashref->{sortfield}, |
328 |
$hashref->{sortfield}, |
333 |
$hashref->{allow_add}||0, |
329 |
$hashref->{allow_add}||0, |
334 |
$hashref->{allow_delete_own}||1, |
330 |
$hashref->{allow_delete_own}||1, |
335 |
$hashref->{allow_delete_other}||0 ); |
331 |
$hashref->{allow_delete_other}||0 ); |
336 |
my $shelfnumber = $dbh->{'mysql_insertid'}; |
332 |
my $shelfnumber = $dbh->{'mysql_insertid'}; |
337 |
return $shelfnumber; |
333 |
return $shelfnumber; |
338 |
} |
334 |
} |
Lines 357-363
sub AddToShelf {
Link Here
|
357 |
my $sth = $dbh->prepare($query); |
353 |
my $sth = $dbh->prepare($query); |
358 |
|
354 |
|
359 |
$sth->execute( $shelfnumber, $biblionumber ); |
355 |
$sth->execute( $shelfnumber, $biblionumber ); |
360 |
($sth->rows) and return undef; # already on shelf |
356 |
($sth->rows) and return undef; # already on shelf |
361 |
$query = qq( |
357 |
$query = qq( |
362 |
INSERT INTO virtualshelfcontents |
358 |
INSERT INTO virtualshelfcontents |
363 |
(shelfnumber, biblionumber, flags, borrowernumber) |
359 |
(shelfnumber, biblionumber, flags, borrowernumber) |
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=?"; |
410 |
$query= "UPDATE virtualshelves SET shelfname=?, category=?, sortfield=?, allow_add=?, allow_delete_own=?, allow_delete_other=? WHERE shelfnumber=?"; |
415 |
$sth = $dbh->prepare($query); |
411 |
$sth = $dbh->prepare($query); |
416 |
$sth->execute( |
412 |
$sth->execute( |
417 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
413 |
$hashref->{shelfname}||$oldrecord->{shelfname}, |
418 |
$hashref->{category}||$oldrecord->{category}, |
414 |
$hashref->{category}||$oldrecord->{category}, |
419 |
$hashref->{sortfield}||$oldrecord->{sortfield}, |
415 |
$hashref->{sortfield}||$oldrecord->{sortfield}, |
420 |
$hashref->{allow_add}||$oldrecord->{allow_add}, |
416 |
$hashref->{allow_add}||$oldrecord->{allow_add}, |
421 |
$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own}, |
417 |
$hashref->{allow_delete_own}||$oldrecord->{allow_delete_own}, |
422 |
$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other}, |
418 |
$hashref->{allow_delete_other}||$oldrecord->{allow_delete_other}, |
423 |
$shelfnumber ); |
419 |
$shelfnumber ); |
424 |
return $@? 0: 1; |
420 |
return $@? 0: 1; |
425 |
} |
421 |
} |
426 |
|
422 |
|
Lines 471-493
sub ShelfPossibleAction {
Link Here
|
471 |
|
467 |
|
472 |
return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || $shelf->{borrowernumber}==$user); |
468 |
return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || $shelf->{borrowernumber}==$user); |
473 |
if($action eq 'view') { |
469 |
if($action eq 'view') { |
474 |
#already handled in the above condition |
470 |
#already handled in the above condition |
475 |
return 1; |
471 |
return 1; |
476 |
} |
472 |
} |
477 |
elsif($action eq 'add') { |
473 |
elsif($action eq 'add') { |
478 |
return 0 if $user<=0; #should be logged in |
474 |
return 0 if $user<=0; #should be logged in |
479 |
return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user; |
475 |
return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user; |
480 |
#owner may always add |
476 |
#owner may always add |
481 |
} |
477 |
} |
482 |
elsif($action eq 'delete') { |
478 |
elsif($action eq 'delete') { |
483 |
#this answer is just diplomatic: it says that you may be able to delete |
479 |
#this answer is just diplomatic: it says that you may be able to delete |
484 |
#some items from that shelf |
480 |
#some items from that shelf |
485 |
#it does not answer the question about a specific biblio |
481 |
#it does not answer the question about a specific biblio |
486 |
#DelFromShelf checks the situation per biblio |
482 |
#DelFromShelf checks the situation per biblio |
487 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
483 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
488 |
} |
484 |
} |
489 |
elsif($action eq 'manage') { |
485 |
elsif($action eq 'manage') { |
490 |
return 1 if $user && $shelf->{owner}==$user; |
486 |
return 1 if $user && $shelf->{owner}==$user; |
491 |
} |
487 |
} |
492 |
return 0; |
488 |
return 0; |
493 |
} |
489 |
} |
Lines 515-525
sub DelFromShelf {
Link Here
|
515 |
$query = qq(DELETE FROM virtualshelfcontents |
511 |
$query = qq(DELETE FROM virtualshelfcontents |
516 |
WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?); |
512 |
WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?); |
517 |
$sth= $dbh->prepare($query); |
513 |
$sth= $dbh->prepare($query); |
518 |
foreach my $biblionumber (@$bibref) { |
514 |
foreach my $biblionumber (@$bibref) { |
519 |
$sth->execute($shelfnumber, $biblionumber, $user); |
515 |
$sth->execute($shelfnumber, $biblionumber, $user); |
520 |
$r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1) |
516 |
$r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1) |
521 |
$t+= ($r==-1)? 1: $r; |
517 |
$t+= ($r==-1)? 1: $r; |
522 |
} |
518 |
} |
523 |
} |
519 |
} |
524 |
if($del_oth) { |
520 |
if($del_oth) { |
525 |
#includes a check if borrowernumber is null (deleted patron) |
521 |
#includes a check if borrowernumber is null (deleted patron) |
Lines 527-537
sub DelFromShelf {
Link Here
|
527 |
WHERE shelfnumber=? AND biblionumber=? AND |
523 |
WHERE shelfnumber=? AND biblionumber=? AND |
528 |
(borrowernumber IS NULL OR borrowernumber<>?)/; |
524 |
(borrowernumber IS NULL OR borrowernumber<>?)/; |
529 |
$sth= $dbh->prepare($query); |
525 |
$sth= $dbh->prepare($query); |
530 |
foreach my $biblionumber (@$bibref) { |
526 |
foreach my $biblionumber (@$bibref) { |
531 |
$sth->execute($shelfnumber, $biblionumber, $user); |
527 |
$sth->execute($shelfnumber, $biblionumber, $user); |
532 |
$r= $sth->rows; |
528 |
$r= $sth->rows; |
533 |
$t+= ($r==-1)? 1: $r; |
529 |
$t+= ($r==-1)? 1: $r; |
534 |
} |
530 |
} |
535 |
} |
531 |
} |
536 |
return $t; |
532 |
return $t; |
537 |
} |
533 |
} |
Lines 585-596
main Koha toolbar with Lists button.
Link Here
|
585 |
=cut |
581 |
=cut |
586 |
|
582 |
|
587 |
sub ShelvesMax { |
583 |
sub ShelvesMax { |
588 |
my $which= shift; |
584 |
my $which= shift; |
589 |
return SHELVES_POPUP_MAX if $which eq 'POPUP'; |
585 |
return SHELVES_POPUP_MAX if $which eq 'POPUP'; |
590 |
return SHELVES_MGRPAGE_MAX if $which eq 'MGRPAGE'; |
586 |
return SHELVES_MGRPAGE_MAX if $which eq 'MGRPAGE'; |
591 |
return SHELVES_COMBO_MAX if $which eq 'COMBO'; |
587 |
return SHELVES_COMBO_MAX if $which eq 'COMBO'; |
592 |
return SHELVES_MASTHEAD_MAX if $which eq 'MASTHEAD'; |
588 |
return SHELVES_MASTHEAD_MAX if $which eq 'MASTHEAD'; |
593 |
return SHELVES_MASTHEAD_MAX; |
589 |
return SHELVES_MASTHEAD_MAX; |
594 |
} |
590 |
} |
595 |
|
591 |
|
596 |
sub HandleDelBorrower { |
592 |
sub HandleDelBorrower { |
Lines 643-649
sub _shelf_count {
Link Here
|
643 |
@params= ($owner, $owner, $owner); |
639 |
@params= ($owner, $owner, $owner); |
644 |
} |
640 |
} |
645 |
else { |
641 |
else { |
646 |
$query.='WHERE category=2'; |
642 |
$query.='WHERE category=2'; |
647 |
@params= (); |
643 |
@params= (); |
648 |
} |
644 |
} |
649 |
my $sth = $dbh->prepare($query); |
645 |
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 = ?'; |
653 |
my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?'; |
658 |
my $dbh = C4::Context->dbh; |
654 |
my $dbh = C4::Context->dbh; |
659 |
my $sth = $dbh->prepare($query) |
655 |
my $sth = $dbh->prepare($query) |
660 |
or die $dbh->errstr; |
656 |
or die $dbh->errstr; |
661 |
$sth->execute( $shelf ) |
657 |
$sth->execute( $shelf ) |
662 |
or die $sth->errstr; |
658 |
or die $sth->errstr; |
663 |
$sth; |
659 |
$sth; |
664 |
} |
660 |
} |
665 |
|
661 |
|
Lines 667-675
sub each_biblionumbers (&$) { #OBSOLETE
Link Here
|
667 |
my ($code,$shelf) = @_; |
663 |
my ($code,$shelf) = @_; |
668 |
my $ref = _biblionumber_sth($shelf)->fetchall_arrayref; |
664 |
my $ref = _biblionumber_sth($shelf)->fetchall_arrayref; |
669 |
map { |
665 |
map { |
670 |
$_=$$_[0]; |
666 |
$_=$$_[0]; |
671 |
$code->(); |
667 |
$code->(); |
672 |
} @$ref; |
668 |
} @$ref; |
673 |
} |
669 |
} |
674 |
|
670 |
|
675 |
sub _CheckShelfName { |
671 |
sub _CheckShelfName { |
Lines 678-684
sub _CheckShelfName {
Link Here
|
678 |
my $query = qq( |
674 |
my $query = qq( |
679 |
SELECT DISTINCT shelfnumber |
675 |
SELECT DISTINCT shelfnumber |
680 |
FROM virtualshelves |
676 |
FROM virtualshelves |
681 |
LEFT JOIN virtualshelfshares sh USING (shelfnumber) |
677 |
LEFT JOIN virtualshelfshares sh USING (shelfnumber) |
682 |
WHERE shelfname=? AND shelfnumber<>?); |
678 |
WHERE shelfname=? AND shelfnumber<>?); |
683 |
if($cat==1) { |
679 |
if($cat==1) { |
684 |
$query.= ' AND (sh.borrowernumber=? OR owner=?) AND category=1'; |
680 |
$query.= ' AND (sh.borrowernumber=? OR owner=?) AND category=1'; |
685 |
- |
|
|