# Copyright 2000-2002 Katipo Communications
# 2006 SAN Ouest Provence
-# 2007 BibLibre Paul POULAIN
+# 2007-2010 BibLibre Paul POULAIN
#
# This file is part of Koha.
#
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
my $biblio = GetBiblioData($biblionumber);
my $letter = C4::Letters::getletter( 'reserves', 'HOLDPLACED');
- my $admin_email_address = C4::Context->preference('KohaAdminEmailAddress');
+ my $branchcode = $borrower->{branchcode};
+ my $branch_details = C4::Branch::GetBranchDetail($branchcode);
+ my $admin_email_address =$branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
my %keys = (%$borrower, %$biblio);
foreach my $key (keys %keys) {
sub CanBookBeReserved{
my ($borrowernumber, $biblionumber) = @_;
- my $dbh = C4::Context->dbh;
- my $biblio = GetBiblioData($biblionumber);
- my $borrower = C4::Members::GetMember(borrowernumber=>$borrowernumber);
- my $controlbranch = C4::Context->preference('ReservesControlBranch');
- my $itype = C4::Context->preference('item-level_itypes');
- my $reservesrights= 0;
- my $reservescount = 0;
-
- # we retrieve the user rights
- my @args;
- my $rightsquery = "SELECT categorycode, itemtype, branchcode, reservesallowed
- FROM issuingrules
- WHERE categorycode IN (?, '*')";
- push @args,$borrower->{categorycode};
-
- if($controlbranch eq "ItemHomeLibrary"){
- $rightsquery .= " AND branchcode = '*'";
- }elsif($controlbranch eq "PatronLibrary"){
- $rightsquery .= " AND branchcode IN (?,'*')";
- push @args, $borrower->{branchcode};
- }
-
- if(not $itype){
- $rightsquery .= " AND itemtype IN (?,'*')";
- push @args, $biblio->{itemtype};
- }else{
- $rightsquery .= " AND itemtype = '*'";
- }
-
- $rightsquery .= " ORDER BY categorycode DESC, itemtype DESC, branchcode DESC";
- my $sthrights = $dbh->prepare($rightsquery);
- $sthrights->execute(@args);
-
- if(my $row = $sthrights->fetchrow_hashref()){
- $reservesrights = $row->{reservesallowed};
- }
-
- @args = ();
- # we count how many reserves the borrower have
- my $countquery = "SELECT count(*) as count
- FROM reserves
- LEFT JOIN items USING (itemnumber)
- LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber)
- LEFT JOIN borrowers USING (borrowernumber)
- WHERE borrowernumber = ?
- ";
- push @args, $borrowernumber;
-
- if(not $itype){
- $countquery .= "AND itemtype = ?";
- push @args, $biblio->{itemtype};
- }
-
- if($controlbranch eq "PatronLibrary"){
- $countquery .= " AND borrowers.branchcode = ? ";
- push @args, $borrower->{branchcode};
+ my @items = GetItemsInfo($biblionumber);
+ foreach my $item (@items){
+ return 1 if CanItemBeReserved($borrowernumber, $item->{itemnumber});
}
-
- my $sthcount = $dbh->prepare($countquery);
- $sthcount->execute(@args);
-
- if(my $row = $sthcount->fetchrow_hashref()){
- $reservescount = $row->{count};
- }
- if($reservescount < $reservesrights){
- return 1;
- }else{
- return 0;
- }
-
+ return 0;
}
=head2 CanItemBeReserved
} else {
# See if this item is more important than what we've got so far
if ( $res->{'priority'} && $res->{'priority'} < $priority ) {
+ my $borrowerinfo=C4::Members::GetMemberDetails($res->{'borrowernumber'});
+ my $iteminfo=C4::Items::GetItem($itemnumber);
+ my $branch=C4::Circulation::_GetCircControlBranch($iteminfo,$borrowerinfo);
+ my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
+ next if ($branchitemrule->{'holdallowed'} == 0);
+ next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
$priority = $res->{'priority'};
$highest = $res;
}
SELECT reserves.biblionumber AS biblionumber,
reserves.borrowernumber AS borrowernumber,
reserves.reservedate AS reservedate,
+ reserves.waitingdate AS waitingdate,
reserves.branchcode AS branchcode,
reserves.cancellationdate AS cancellationdate,
reserves.found AS found,
my $dbh = C4::Context->dbh;
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
+
+ # Try to get the borrower's email address
+ my $to_address;
+ my $which_address = C4::Context->preference('AutoEmailPrimaryAddress');
+ # If the system preference is set to 'first valid' (value == OFF), look up email address
+ if ($which_address eq 'OFF') {
+ $to_address = C4::Members::GetFirstValidEmailAddress( $borrowernumber );
+ } else {
+ $to_address = $borrower->{$which_address};
+ }
+
my $letter_code;
my $print_mode = 0;
my $messagingprefs;
- if ( $borrower->{'email'} || $borrower->{'smsalertnumber'} ) {
- $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold Filled' } );
+ if ( $to_address || $borrower->{'smsalertnumber'} ) {
+ $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold_Filled' } );
return if ( !defined( $messagingprefs->{'letter_code'} ) );
$letter_code = $messagingprefs->{'letter_code'};
=head1 AUTHOR
-Koha Development Team <info@koha.org>
+Koha Development Team <http://koha-community.org/>
=cut