X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FMembers.pm;h=76cc36f49840d2c3fed61c4f713c7acd784e8640;hb=aefcbc11c6e53276805130bf4eceace79551a952;hp=8cc32bdc64b87485a24b8207e42a2e57605950fb;hpb=2fb30705142505c86b1929c70fc248be53e13a07;p=koha.git diff --git a/C4/Members.pm b/C4/Members.pm index 8cc32bdc64..76cc36f498 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -148,7 +148,7 @@ name. C<$filter> is assumed to be a list of elements to filter results on -C<$showallbranches> is used in IndependantBranches Context to display all branches results. +C<$showallbranches> is used in IndependentBranchPatron Context to display all branches results. C<&SearchMember> returns a two-element list. C<$borrowers> is a reference-to-array; each element is a reference-to-hash, whose keys @@ -173,8 +173,20 @@ sub SearchMember { $query = "SELECT * FROM borrowers LEFT JOIN categories ON borrowers.categorycode=categories.categorycode "; - my $sth = $dbh->prepare("$query WHERE cardnumber = ?"); - $sth->execute($searchstring); + my (@where_string, @bind_params); + push @where_string, "cardnumber=?"; + push @bind_params, $searchstring; + if (C4::Context->preference("IndependentBranchPatron") && !$showallbranches){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} % 2) !=1 && C4::Context->userenv->{'branch'}){ + unless (C4::Context->userenv->{'branch'} eq "insecure"){ + push @where_string,"borrowers.branchcode =?"; + push @bind_params,C4::Context->userenv->{'branch'}; + } + } + } + my $sth = $dbh->prepare("$query WHERE ".join(" AND ", @where_string)); + + $sth->execute(@bind_params); my $data = $sth->fetchall_arrayref({}); if (@$data){ return ( scalar(@$data), $data ); @@ -185,8 +197,8 @@ sub SearchMember { { $query .= ($category_type ? " AND category_type = ".$dbh->quote($category_type) : ""); $query .= " WHERE (surname LIKE ? OR cardnumber like ?) "; - if (C4::Context->preference("IndependantBranches") && !$showallbranches){ - if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){ + if (C4::Context->preference("IndependentBranchPatron") && !$showallbranches){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} % 2) !=1 && C4::Context->userenv->{'branch'}){ $query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure"); } } @@ -198,8 +210,8 @@ sub SearchMember { @data = split( ' ', $searchstring ); $count = @data; $query .= " WHERE "; - if (C4::Context->preference("IndependantBranches") && !$showallbranches){ - if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){ + if (C4::Context->preference("IndependentBranchPatron") && !$showallbranches){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} %2 )!=1 && C4::Context->userenv->{'branch'}){ $query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure"); } } @@ -222,7 +234,7 @@ sub SearchMember { # FIXME - .= <preference('ExtendedPatronAttributes')) { $query .= "OR borrowernumber IN ( @@ -268,81 +280,11 @@ about the patron. Its keys act as flags : # Patron's card was reported lost } -Each flag has a C key, giving a human-readable explanation of -the flag. If the state of a flag means that the patron should not be +If the state of a flag means that the patron should not be allowed to borrow any more books, then it will have a C key with a true value. -The possible flags are: - -=head3 CHARGES - -=over 4 - -=item Shows the patron's credit or debt, if any. - -=back - -=head3 GNA - -=over 4 - -=item (Gone, no address.) Set if the patron has left without giving a -forwarding address. - -=back - -=head3 LOST - -=over 4 - -=item Set if the patron's card has been reported as lost. - -=back - -=head3 DBARRED - -=over 4 - -=item Set if the patron has been debarred. - -=back - -=head3 NOTES - -=over 4 - -=item Any additional notes about the patron. - -=back - -=head3 ODUES - -=over 4 - -=item Set if the patron has overdue items. This flag has several keys: - -C<$flags-E{ODUES}{itemlist}> is a reference-to-array listing the -overdue items. Its elements are references-to-hash, each describing an -overdue item. The keys are selected fields from the issues, biblio, -biblioitems, and items tables of the Koha database. - -C<$flags-E{ODUES}{itemlist}> is a string giving a text listing of -the overdue items, one per line. - -=back - -=head3 WAITING - -=over 4 - -=item Set if any items that the patron has reserved are available. - -C<$flags-E{WAITING}{itemlist}> is a reference-to-array listing the -available items. Each element is a reference-to-hash whose keys are -fields from the reserves table of the Koha database. - -=back +See patronflags for more details. C<$borrower-E{authflags}> is a hash giving more detailed information about the top-level permissions flags set for the borrower. For example, @@ -398,37 +340,66 @@ sub GetMemberDetails { =head2 patronflags - Not exported + $flags = &patronflags($patron); - NOTE!: If you change this function, be sure to update the POD for - &GetMemberDetails. + This function is not exported. - $flags = &patronflags($patron); + The following will be set where applicable: + $flags->{CHARGES}->{amount} Amount of debt + $flags->{CHARGES}->{noissues} Set if debt amount >$5.00 (or syspref noissuescharge) + $flags->{CHARGES}->{message} Message -- deprecated + + $flags->{CREDITS}->{amount} Amount of credit + $flags->{CREDITS}->{message} Message -- deprecated + + $flags->{ GNA } Patron has no valid address + $flags->{ GNA }->{noissues} Set for each GNA + $flags->{ GNA }->{message} "Borrower has no valid address" -- deprecated + + $flags->{ LOST } Patron's card reported lost + $flags->{ LOST }->{noissues} Set for each LOST + $flags->{ LOST }->{message} Message -- deprecated + + $flags->{DBARRED} Set if patron debarred, no access + $flags->{DBARRED}->{noissues} Set for each DBARRED + $flags->{DBARRED}->{message} Message -- deprecated - $flags->{CHARGES} - {message} Message showing patron's credit or debt - {noissues} Set if patron owes >$5.00 - {GNA} Set if patron gone w/o address - {message} "Borrower has no valid address" - {noissues} Set. - {LOST} Set if patron's card reported lost - {message} Message to this effect - {noissues} Set. - {DBARRED} Set is patron is debarred - {message} Message to this effect - {noissues} Set. - {NOTES} Set if patron has notes - {message} Notes about patron - {ODUES} Set if patron has overdue books - {message} "Yes" - {itemlist} ref-to-array: list of overdue books - {itemlisttext} Text list of overdue items - {WAITING} Set if there are items available that the - patron reserved - {message} Message to this effect - {itemlist} ref-to-array: list of available items + $flags->{ NOTES } + $flags->{ NOTES }->{message} The note itself. NOT deprecated + + $flags->{ ODUES } Set if patron has overdue books. + $flags->{ ODUES }->{message} "Yes" -- deprecated + $flags->{ ODUES }->{itemlist} ref-to-array: list of overdue books + $flags->{ ODUES }->{itemlisttext} Text list of overdue items -- deprecated + + $flags->{WAITING} Set if any of patron's reserves are available + $flags->{WAITING}->{message} Message -- deprecated + $flags->{WAITING}->{itemlist} ref-to-array: list of available items + +=over 4 + +C<$flags-E{ODUES}-E{itemlist}> is a reference-to-array listing the +overdue items. Its elements are references-to-hash, each describing an +overdue item. The keys are selected fields from the issues, biblio, +biblioitems, and items tables of the Koha database. + +C<$flags-E{ODUES}-E{itemlisttext}> is a string giving a text listing of +the overdue items, one per line. Deprecated. + +C<$flags-E{WAITING}-E{itemlist}> is a reference-to-array listing the +available items. Each element is a reference-to-hash whose keys are +fields from the reserves table of the Koha database. + +=back + +All the "message" fields that include language generated in this function are deprecated, +because such strings belong properly in the display layer. + +The "message" field that comes from the DB is OK. =cut + +# TODO: use {anonymous => hashes} instead of a dozen %flaginfo # FIXME rename this function. sub patronflags { my %flags; @@ -437,9 +408,9 @@ sub patronflags { my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'}); if ( $amount > 0 ) { my %flaginfo; - my $noissuescharge = C4::Context->preference("noissuescharge"); + my $noissuescharge = C4::Context->preference("noissuescharge") || 5; $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount; - $flaginfo{'amount'} = sprintf "%.02f",$amount; + $flaginfo{'amount'} = sprintf "%.02f", $amount; if ( $amount > $noissuescharge ) { $flaginfo{'noissues'} = 1; } @@ -448,6 +419,7 @@ sub patronflags { elsif ( $amount < 0 ) { my %flaginfo; $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount; + $flaginfo{'amount'} = sprintf "%.02f", $amount; $flags{'CREDITS'} = \%flaginfo; } if ( $patroninformation->{'gonenoaddress'} @@ -476,11 +448,10 @@ sub patronflags { && $patroninformation->{'borrowernotes'} ) { my %flaginfo; - $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}"; + $flaginfo{'message'} = $patroninformation->{'borrowernotes'}; $flags{'NOTES'} = \%flaginfo; } - my ( $odues, $itemsoverdue ) = - checkoverdues( $patroninformation->{'borrowernumber'}, $dbh ); + my ( $odues, $itemsoverdue ) = checkoverdues($patroninformation->{'borrowernumber'}); if ( $odues > 0 ) { my %flaginfo; $flaginfo{'message'} = "Yes"; @@ -489,7 +460,7 @@ sub patronflags { @$itemsoverdue ) { $flaginfo{'itemlisttext'} .= - "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n"; + "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n"; # newline is display layer } $flags{'ODUES'} = \%flaginfo; } @@ -696,8 +667,9 @@ Returns the borrowernumber sub AddMember { my (%data) = @_; my $dbh = C4::Context->dbh; - $data{'userid'} = '' unless $data{'password'}; + $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'}; + $data{'password'} = '!' if (not $data{'password'} and $data{'userid'}); # WE SHOULD NEVER PASS THIS SUBROUTINE ANYTHING OTHER THAN ISO DATES # IF YOU UNCOMMENT THESE LINES YOU BETTER HAVE A DARN COMPELLING REASON @@ -1107,8 +1079,8 @@ sub GetAllIssues { # apparently specific to HLT. Not sure if the ReadingHistory # syspref is still required, as old_issues by design # is no longer checked with each loan. - my $query2 = "SELECT * FROM oldissues - LEFT JOIN items ON items.itemnumber=oldissues.itemnumber + my $query2 = "SELECT * FROM old_issues + LEFT JOIN items ON items.itemnumber=old_issues.itemnumber LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber WHERE borrowernumber=? @@ -1172,9 +1144,9 @@ sub GetMemberAccountRecords { $data->{title} = $biblio->{title}; $acctlines[$numlines] = $data; $numlines++; - $total += int(100 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors + $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors } - $total /= 100; + $total /= 1000; $sth->finish; return ( $total, \@acctlines,$numlines); } @@ -1648,32 +1620,32 @@ sub GetSortDetails { return ($sortvalue) unless ($lib); } -=head2 DeleteBorrower +=head2 MoveMemberToDeleted - () = &DeleteBorrower($member); + $result = &MoveMemberToDeleted($borrowernumber); -delete all data fo borrowers and add record to deletedborrowers table -C<&$member>this is the borrowernumber +Copy the record from borrowers to deletedborrowers table. =cut +# FIXME: should do it in one SQL statement w/ subquery +# Otherwise, we should return the @data on success + sub MoveMemberToDeleted { - my ($member) = @_; + my ($member) = shift or return; my $dbh = C4::Context->dbh; - my $query; - $query = qq|SELECT * + my $query = qq|SELECT * FROM borrowers WHERE borrowernumber=?|; my $sth = $dbh->prepare($query); $sth->execute($member); my @data = $sth->fetchrow_array; - $sth->finish; + (@data) or return; # if we got a bad borrowernumber, there's nothing to insert $sth = $dbh->prepare( "INSERT INTO deletedborrowers VALUES (" . ( "?," x ( scalar(@data) - 1 ) ) . "?)" ); $sth->execute(@data); - $sth->finish; } =head2 DelMember @@ -1796,7 +1768,7 @@ Looks up the different title . Returns array with all borrowers title =cut sub GetTitles { - my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles'); + my @borrowerTitle = split (/,|\|/,C4::Context->preference('BorrowersTitles')); unshift( @borrowerTitle, "" ); my $count=@borrowerTitle; if ($count == 1){ @@ -1823,10 +1795,8 @@ sub GetPatronImage { my $sth = $dbh->prepare($query); $sth->execute($cardnumber); my $imagedata = $sth->fetchrow_hashref; - my $dberror = $sth->errstr; warn "Database error!" if $sth->errstr; - $sth->finish; - return $imagedata, $dberror; + return $imagedata, $sth->errstr; } =head2 PutPatronImage @@ -1846,9 +1816,7 @@ sub PutPatronImage { my $sth = $dbh->prepare($query); $sth->execute($cardnumber,$mimetype,$imgfile,$imgfile); warn "Error returned inserting $cardnumber.$mimetype." if $sth->errstr; - my $dberror = $sth->errstr; - $sth->finish; - return $dberror; + return $sth->errstr; } =head2 RmPatronImage @@ -1868,7 +1836,6 @@ sub RmPatronImage { $sth->execute($cardnumber); my $dberror = $sth->errstr; warn "Database error!" if $sth->errstr; - $sth->finish; return $dberror; } @@ -1904,9 +1871,8 @@ this function get all borrowers who haven't borrowed since the date given on inp =cut sub GetBorrowersWhoHaveNotBorrowedSince { -### TODO : It could be dangerous to delete Borrowers who have just been entered and who have not yet borrowed any book. May be good to add a dateexpiry or dateenrolled filter. - - my $filterdate = shift||POSIX::strftime("%Y-%m-%d",localtime()); + my $filterdate = shift||POSIX::strftime("%Y-%m-%d",localtime()); + my $filterexpiry = shift; my $filterbranch = shift || ((C4::Context->preference('IndependantBranches') && C4::Context->userenv @@ -1916,20 +1882,29 @@ sub GetBorrowersWhoHaveNotBorrowedSince { : ""); my $dbh = C4::Context->dbh; my $query = " - SELECT borrowers.borrowernumber,max(issues.timestamp) as latestissue + SELECT borrowers.borrowernumber, + max(old_issues.timestamp) as latestissue, + max(issues.timestamp) as currentissue FROM borrowers JOIN categories USING (categorycode) - LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber + LEFT JOIN old_issues USING (borrowernumber) + LEFT JOIN issues USING (borrowernumber) WHERE category_type <> 'S' + AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0) "; my @query_params; if ($filterbranch && $filterbranch ne ""){ $query.=" AND borrowers.branchcode= ?"; push @query_params,$filterbranch; - } + } + if($filterexpiry){ + $query .= " AND dateexpiry < ? "; + push @query_params,$filterdate; + } $query.=" GROUP BY borrowers.borrowernumber"; if ($filterdate){ - $query.=" HAVING latestissue