$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 ?)
+ $query.="((surname LIKE ? OR (surname LIKE ? AND surname REGEXP ?)
+ OR firstname LIKE ? OR (firstname LIKE ? AND firstname REGEXP ?)
+ OR othernames LIKE ? OR (othernames LIKE ? AND othernames REGEXP ?))
" .
($category_type?" AND category_type = ".$dbh->quote($category_type):"");
+ my $regex = '[[:punct:][:space:]]'.$data[0];
@bind = (
- "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
- "$data[0]%", "% $data[0]%"
+ "$data[0]%", "%$data[0]%", $regex,
+ "$data[0]%", "%$data[0]%", $regex,
+ "$data[0]%", "%$data[0]%", $regex
);
for ( my $i = 1 ; $i < $count ; $i++ ) {
- $query = $query . " AND (" . " surname LIKE ? OR surname LIKE ?
- OR firstname LIKE ? OR firstname LIKE ?
- OR othernames LIKE ? OR othernames LIKE ?)";
+ $query = $query . " AND (" . " surname LIKE ? OR (surname LIKE ? AND surname REGEXP ?)
+ OR firstname LIKE ? OR (firstname LIKE ? AND firstname REGEXP ?)
+ OR othernames LIKE ? OR (othernames LIKE ? AND othernames REGEXP ?))";
+ $regex = '[[:punct:][:space:]]'.$data[$i];
push( @bind,
- "$data[$i]%", "% $data[$i]%", "$data[$i]%",
- "% $data[$i]%", "$data[$i]%", "% $data[$i]%" );
+ "$data[$i]%", "%$data[$i]%", $regex,
+ "$data[$i]%", "%$data[$i]%", $regex,
+ "$data[$i]%", "%$data[$i]%", $regex
+ );
+
# FIXME - .= <<EOT;
}
}
}
my $execute_success=UpdateInTable("borrowers",\%data);
-# ok if its an adult (type) it may have borrowers that depend on it as a guarantor
-# so when we update information for an adult we should check for guarantees and update the relevant part
-# of their records, ie addresses and phone numbers
- my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
- if ( exists $borrowercategory->{'category_type'} && $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
- # is adult check guarantees;
- UpdateGuarantees(%data);
+ if ($execute_success) { # only proceed if the update was a success
+ # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
+ # so when we update information for an adult we should check for guarantees and update the relevant part
+ # of their records, ie addresses and phone numbers
+ my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
+ if ( exists $borrowercategory->{'category_type'} && $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
+ # is adult check guarantees;
+ UpdateGuarantees(%data);
+ }
+ logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
}
- logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})")
- if C4::Context->preference("BorrowersLog");
-
return $execute_success;
}
$borrowernumber = &AddMember(%borrower);
insert new borrower into table
-Returns the borrowernumber
+Returns the borrowernumber upon success
+
+Returns as undef upon any db error without further processing
=cut
sub AddMember {
my (%data) = @_;
my $dbh = C4::Context->dbh;
- $data{'password'} = '!' if (not $data{'password'} and $data{'userid'});
- $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
+ # generate a proper login if none provided
+ $data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq '';
+ # create a disabled account if no password provided
+ $data{'password'} = ($data{'password'})? md5_base64($data{'password'}) : '!';
$data{'borrowernumber'}=InsertInTable("borrowers",\%data);
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best.
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
$sth->execute($data{'categorycode'});
my ($enrolmentfee) = $sth->fetchrow;
+ if ($sth->err) {
+ warn sprintf('Database returned the following error: %s', $sth->errstr);
+ return;
+ }
if ($enrolmentfee && $enrolmentfee > 0) {
# insert fee in patron debts
manualinvoice($data{'borrowernumber'}, '', '', 'A', $enrolmentfee);
}
+
return $data{'borrowernumber'};
}
do {
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
- $newuid = lc("$firstname.$surname");
+ $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
$newuid .= $offset unless $offset == 0;
$offset++;
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=?
+ WHERE borrowernumber=? AND old_issues.itemnumber IS NOT NULL
order by $order";
if ( $limit != 0 ) {
$query .= " limit $limit";
$sth->execute( @bind );
my $total = 0;
while ( my $data = $sth->fetchrow_hashref ) {
- my $biblio = GetBiblioFromItemNumber($data->{itemnumber}) if $data->{itemnumber};
- $data->{biblionumber} = $biblio->{biblionumber};
- $data->{title} = $biblio->{title};
+ if ( $data->{itemnumber} ) {
+ my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
+ $data->{biblionumber} = $biblio->{biblionumber};
+ $data->{title} = $biblio->{title};
+ }
$acctlines[$numlines] = $data;
$numlines++;
$total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
sub checkcardnumber {
my ($cardnumber,$borrowernumber) = @_;
+ # If cardnumber is null, we assume they're allowed.
+ return 0 if !defined($cardnumber);
my $dbh = C4::Context->dbh;
my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
$query .= " AND borrowernumber <> ?" if ($borrowernumber);
my $dbh = C4::Context->dbh;
my $sth =
$dbh->prepare(
- "select city_name,city_zipcode from cities where cityid=? ");
+ "select city_name,city_state,city_zipcode,city_country from cities where cityid=? ");
$sth->execute($cityid);
my @data = $sth->fetchrow;
- return $data[0], $data[1];
+ return $data[0], $data[1], $data[2], $data[3];
}
my $dbh = C4::Context->dbh;
my $city_arr = $dbh->selectall_arrayref(
- q|SELECT cityid,city_zipcode,city_name FROM cities ORDER BY city_name|,
+ q|SELECT cityid,city_zipcode,city_name,city_state,city_country FROM cities ORDER BY city_name|,
{ Slice => {} });
if ( @{$city_arr} ) {
unshift @{$city_arr}, {
city_zipcode => q{},
city_name => q{},
cityid => q{},
+ city_state => q{},
+ city_country => q{},
};
}