From 1faf1110d654e9386e4ae102224d9aea2763d389 Mon Sep 17 00:00:00 2001 From: jirislav Date: Tue, 14 Apr 2015 12:21:10 +0200 Subject: [PATCH] Bug 13931 - Added patron's dateofbirth to autocomplete --- circ/ysearch.pl | 71 +++++++++----------- .../prog/en/includes/patron-search-box.inc | 2 +- 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/circ/ysearch.pl b/circ/ysearch.pl index ae4ae42..6403a6c 100755 --- a/circ/ysearch.pl +++ b/circ/ysearch.pl @@ -22,63 +22,54 @@ =head1 ysearch.pl + =cut -use Modern::Perl; +use strict; +#use warnings; FIXME - Bug 2505 use CGI qw ( -utf8 ); use C4::Context; +use C4::Members; use C4::Auth qw/check_cookie_auth/; -use Koha::Borrowers; - -use JSON qw( to_json ); +use JSON qw(to_json); -my $input = new CGI; -my $query = $input->param('term'); +my $input = new CGI; +my $query = $input->param('term'); binmode STDOUT, ":encoding(UTF-8)"; -print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); +print $input->header(-type => 'text/plain', -charset => 'UTF-8'); -my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } ); -if ( $auth_status ne "ok" ) { +my ($auth_status, $sessionID) = check_cookie_auth($input->cookie('CGISESSID'), { circulate => '*' }); +if ($auth_status ne "ok") { exit 0; } -my $limit_on_branch; +my $dbh = C4::Context->dbh; +my $sql = q( + SELECT borrowernumber, surname, firstname, cardnumber, address, city, zipcode, country, dateofbirth + FROM borrowers + WHERE ( surname LIKE ? + OR firstname LIKE ? + OR cardnumber LIKE ? ) +); if ( C4::Context->preference("IndependentBranches") && C4::Context->userenv && !C4::Context->IsSuperLibrarian() - && C4::Context->userenv->{'branch'} ) { - $limit_on_branch = 1; + && C4::Context->userenv->{'branch'} ) +{ + $sql .= " AND borrowers.branchcode =" + . $dbh->quote( C4::Context->userenv->{'branch'} ); } -my $borrowers_rs = Koha::Borrowers->search( - { -or => { - surname => { -like => "$query%" }, - firstname => { -like => "$query%" }, - cardnumber => { -like => "$query%" }, - ( $limit_on_branch ? { branchcode => C4::Context->userenv->{branch} } : () ), - }, - }, - { - # Get the first 10 results - page => 1, - rows => 10, - order_by => [ 'surname', 'firstname' ], - }, -); +$sql .= q( ORDER BY surname, firstname LIMIT 10); +my $sth = $dbh->prepare( $sql ); +$sth->execute("$query%", "$query%", "$query%"); + +my $results = $sth->fetchall_arrayref({}); -my @borrowers; -while ( my $b = $borrowers_rs->next ) { - push @borrowers, - { borrowernumber => $b->borrowernumber, - surname => $b->surname // '', - firstname => $b->firstname // '', - cardnumber => $b->cardnumber // '', - address => $b->address // '', - city => $b->city // '', - zipcode => $b->zipcode // '', - country => $b->country // '', - }; +for(my $i = 0; $i < scalar @{$results}; ++$i) { + # Format all dateofbirths from sql datetime + ${$results}[$i]->{dateofbirth} = Koha::DateUtils::format_sqldatetime(${$results}[$i]->{dateofbirth}, undef, undef, 1); } -print to_json( \@borrowers ); +print to_json($results); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-box.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-box.inc index 87f1969..464b8ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-box.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-box.inc @@ -14,7 +14,7 @@ $(document).ready(function(){ .data( "ui-autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) .data( "ui-autocomplete-item", item ) - .append( "" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) + .append( "" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") " + item.dateofbirth + ", " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) .appendTo( ul ); }; -- 1.7.10.4