Lines 33-39
use C4::Members;
Link Here
|
33 |
use C4::Auth qw/check_cookie_auth/; |
33 |
use C4::Auth qw/check_cookie_auth/; |
34 |
|
34 |
|
35 |
my $input = new CGI; |
35 |
my $input = new CGI; |
36 |
my $query = $input->param('term'); |
36 |
my $term = $input->param('term'); |
37 |
|
37 |
|
38 |
binmode STDOUT, ":encoding(UTF-8)"; |
38 |
binmode STDOUT, ":encoding(UTF-8)"; |
39 |
print $input->header(-type => 'text/plain', -charset => 'UTF-8'); |
39 |
print $input->header(-type => 'text/plain', -charset => 'UTF-8'); |
Lines 43-72
if ($auth_status ne "ok") {
Link Here
|
43 |
exit 0; |
43 |
exit 0; |
44 |
} |
44 |
} |
45 |
|
45 |
|
46 |
my $dbh = C4::Context->dbh; |
46 |
$term =~ s/,//g; #remove any commas from search string |
47 |
my $sql = q( |
47 |
my $order_by = 'surname, firstname'; |
48 |
SELECT borrowernumber, surname, firstname, cardnumber, address, city, zipcode, country |
48 |
my ($results) = Search( $term, $order_by, [ 10 ] ); |
49 |
FROM borrowers |
|
|
50 |
WHERE ( surname LIKE ? |
51 |
OR firstname LIKE ? |
52 |
OR cardnumber LIKE ? ) |
53 |
); |
54 |
if ( C4::Context->preference("IndependentBranches") |
55 |
&& C4::Context->userenv |
56 |
&& !C4::Context->IsSuperLibrarian() |
57 |
&& C4::Context->userenv->{'branch'} ) |
58 |
{ |
59 |
$sql .= " AND borrowers.branchcode =" |
60 |
. $dbh->quote( C4::Context->userenv->{'branch'} ); |
61 |
} |
62 |
|
63 |
$sql .= q( ORDER BY surname, firstname LIMIT 10); |
64 |
my $sth = $dbh->prepare( $sql ); |
65 |
$sth->execute("$query%", "$query%", "$query%"); |
66 |
|
49 |
|
67 |
print "["; |
50 |
print "["; |
68 |
my $i = 0; |
51 |
my $i = 0; |
69 |
while ( my $rec = $sth->fetchrow_hashref ) { |
52 |
foreach my $rec ( @$results ) { |
70 |
if($i > 0){ print ","; } |
53 |
if($i > 0){ print ","; } |
71 |
print "{\"borrowernumber\":\"" . $rec->{borrowernumber} . "\",\"" . |
54 |
print "{\"borrowernumber\":\"" . $rec->{borrowernumber} . "\",\"" . |
72 |
"surname\":\"".$rec->{surname} . "\",\"" . |
55 |
"surname\":\"".$rec->{surname} . "\",\"" . |
73 |
- |
|
|