push @EXPORT, qw(
&checkuniquemember
&checkuserpassword
+ &Check_Userid
&fixEthnicity
ðnicitycategories
&fixup_cardnumber
=item SearchMember
- ($count, $borrowers) = &SearchMember($searchstring, $type,$category_type);
+ ($count, $borrowers) = &SearchMember($searchstring, $type,$category_type,$filter,$showallbranches);
Looks up patrons (borrowers) by name.
must match the beginning a borrower's surname, first name, or other
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<&SearchMember> returns a two-element list. C<$borrowers> is a
reference-to-array; each element is a reference-to-hash, whose keys
are the fields of the C<borrowers> table in the Koha database.
#used by member enquiries from the intranet
#called by member.pl
sub SearchMember {
- my ($searchstring, $orderby, $type,$category_type ) = @_;
+ my ($searchstring, $orderby, $type,$category_type,$filter,$showallbranches ) = @_;
my $dbh = C4::Context->dbh;
my $query = "";
my $count;
if ( $type eq "simple" ) # simple search for one letter only
{
$query =
- "SELECT * FROM borrowers
- LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
- ($category_type?" AND category_type = ".$dbh->quote($category_type):"").
- " WHERE surname LIKE ? OR cardnumber like ? ORDER BY $orderby";
+ "SELECT *
+ FROM borrowers
+ LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
+ ($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'}){
+ $query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure");
+ }
+ }
+ $query.=" ORDER BY $orderby";
@bind = ("$searchstring%","$searchstring");
}
else # advanced search looking in surname, firstname and othernames
$count = @data;
$query = "SELECT * FROM borrowers
LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
- WHERE ((surname LIKE ? OR surname LIKE ?
- OR firstname LIKE ? OR firstname LIKE ?
- OR othernames LIKE ? OR othernames LIKE ?)
+ WHERE ";
+ if (C4::Context->preference("IndependantBranches") && !$showallbranches){
+ if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
+ $query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
+ }
+ }
+ $query.="((surname LIKE ? OR surname LIKE ?
+ OR firstname LIKE ? OR firstname LIKE ?
+ OR othernames LIKE ? OR othernames LIKE ?)
".
($category_type?" AND category_type = ".$dbh->quote($category_type):"");
@bind = (
my $sth = $dbh->prepare($query);
- # warn "Q $orderby : $query";
+# warn "Q $orderby : $query";
$sth->execute(@bind);
my @results;
my $data = $sth->fetchall_arrayref({});
}
$flags{'ODUES'} = \%flaginfo;
}
- my @itemswaiting = GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
+ my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
my $nowaiting = scalar @itemswaiting;
if ( $nowaiting > 0 ) {
my %flaginfo;
if ( $data{'password'} eq '****' ) {
delete $data{'password'};
foreach (keys %data)
- {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $hashborrowerfields{$_} and $data{$_})} ;
+ {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $hashborrowerfields{$_}) } ;
$query = "UPDATE borrowers SET ".join (",",@parameters)
." WHERE borrowernumber=$data{'borrowernumber'}";
# warn "$query";
$sth->execute;
}
else {
- ( $data{'password'} = md5_base64( $data{'password'} ) )
+ $data{'password'} = md5_base64( $data{'password'} ) if ( $data{'password'} ne '' );
+ delete $data{'password'} if ($data{password} eq "");
foreach (keys %data)
- {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $hashborrowerfields{$_} and $data{$_})} ;
- if ( $data{'password'} ne '' );
+ {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $hashborrowerfields{$_})} ;
+
$query = "UPDATE borrowers SET ".join (",",@parameters)." WHERE borrowernumber=$data{'borrowernumber'}";
# warn "$query";
$sth = $dbh->prepare($query);
return $data{'borrowernumber'};
}
+sub Check_Userid {
+ my ($uid,$member) = @_;
+ my $dbh = C4::Context->dbh;
+ # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
+ # Then we need to tell the user and have them create a new one.
+ my $sth =
+ $dbh->prepare(
+ "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
+ $sth->execute( $uid, $member );
+ if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
+ return 0;
+ }
+ else {
+ return 1;
+ }
+}
+
+
sub changepassword {
my ( $uid, $member, $digest ) = @_;
my $dbh = C4::Context->dbh;
#Then we need to tell the user and have them create a new one.
my $sth =
$dbh->prepare(
- "select * from borrowers where userid=? and borrowernumber != ?");
+ "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
$sth->execute( $uid, $member );
- if ( ( $uid ne '' ) && ( $sth->fetchrow ) ) {
+ if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
return 0;
}
else {
WHERE
borrowernumber=?
AND returndate IS NULL
- ORDER BY issues.date_due"
+ ORDER BY issues.issuedate"
);
$sth->execute($borrowernumber);
my $data = $sth->fetchall_arrayref({});
my $dbh = C4::Context->dbh;
my $count = 0;
my $query =
-"Select *,items.timestamp AS itemstimestamp from issues,biblio,items,biblioitems
- where borrowernumber=? and
- items.biblioitemnumber=biblioitems.biblioitemnumber and
- items.itemnumber=issues.itemnumber and
- items.biblionumber=biblio.biblionumber order by $order";
+ "Select *,items.timestamp AS itemstimestamp from
+ issues
+ LEFT JOIN items on items.itemnumber=issues.itemnumber
+ LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
+ LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
+ where borrowernumber=?
+ order by $order";
if ( $limit != 0 ) {
$query .= " limit $limit";
}
# large chunk of older issues data put into table oldissues
# to speed up db calls for issuing items
if ( C4::Context->preference("ReadingHistory") ) {
- my $query2 = "SELECT * FROM oldissues,biblio,items,biblioitems
+ my $query2 = "SELECT * FROM oldissues
+ LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
+ LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
+ LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
WHERE borrowernumber=?
- AND items.biblioitemnumber=biblioitems.biblioitemnumber
- AND items.itemnumber=oldissues.itemnumber
- AND items.biblionumber=biblio.biblionumber
ORDER BY $order";
if ( $limit != 0 ) {
$limit = $limit - $count;