View | Details | Raw Unified | Return to bug 13931
Collapse All | Expand All

(-)a/circ/ysearch.pl (-40 / +31 lines)
Lines 22-84 Link Here
22
22
23
=head1 ysearch.pl
23
=head1 ysearch.pl
24
24
25
25
=cut
26
=cut
26
27
27
use Modern::Perl;
28
use strict;
29
#use warnings; FIXME - Bug 2505
28
use CGI qw ( -utf8 );
30
use CGI qw ( -utf8 );
29
use C4::Context;
31
use C4::Context;
32
use C4::Members;
30
use C4::Auth qw/check_cookie_auth/;
33
use C4::Auth qw/check_cookie_auth/;
31
use Koha::Borrowers;
34
use JSON qw(to_json);
32
33
use JSON qw( to_json );
34
35
35
my $input = new CGI;
36
my $input   = new CGI;
36
my $query = $input->param('term');
37
my $query   = $input->param('term');
37
38
38
binmode STDOUT, ":encoding(UTF-8)";
39
binmode STDOUT, ":encoding(UTF-8)";
39
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
40
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
40
41
41
my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } );
42
my ($auth_status, $sessionID) = check_cookie_auth($input->cookie('CGISESSID'), { circulate => '*' });
42
if ( $auth_status ne "ok" ) {
43
if ($auth_status ne "ok") {
43
    exit 0;
44
    exit 0;
44
}
45
}
45
46
46
my $limit_on_branch;
47
my $dbh = C4::Context->dbh;
48
my $sql = q(
49
    SELECT borrowernumber, surname, firstname, cardnumber, address, city, zipcode, country, dateofbirth
50
    FROM borrowers
51
    WHERE ( surname LIKE ?
52
        OR firstname LIKE ?
53
        OR cardnumber LIKE ? )
54
);
47
if (   C4::Context->preference("IndependentBranches")
55
if (   C4::Context->preference("IndependentBranches")
48
    && C4::Context->userenv
56
    && C4::Context->userenv
49
    && !C4::Context->IsSuperLibrarian()
57
    && !C4::Context->IsSuperLibrarian()
50
    && C4::Context->userenv->{'branch'} ) {
58
    && C4::Context->userenv->{'branch'} )
51
    $limit_on_branch = 1;
59
{
60
    $sql .= " AND borrowers.branchcode ="
61
      . $dbh->quote( C4::Context->userenv->{'branch'} );
52
}
62
}
53
63
54
my $borrowers_rs = Koha::Borrowers->search(
64
$sql    .= q( ORDER BY surname, firstname LIMIT 10);
55
    {   -or => {
65
my $sth = $dbh->prepare( $sql );
56
            surname    => { -like => "$query%" },
66
$sth->execute("$query%", "$query%", "$query%");
57
            firstname  => { -like => "$query%" },
67
58
            cardnumber => { -like => "$query%" },
68
my $results = $sth->fetchall_arrayref({});
59
            ( $limit_on_branch ? { branchcode => C4::Context->userenv->{branch} } : () ),
60
        },
61
    },
62
    {
63
        # Get the first 10 results
64
        page     => 1,
65
        rows     => 10,
66
        order_by => [ 'surname', 'firstname' ],
67
    },
68
);
69
69
70
my @borrowers;
70
for(my $i = 0; $i < scalar @{$results}; ++$i) {
71
while ( my $b = $borrowers_rs->next ) {
71
    # Format all dateofbirths from sql datetime
72
    push @borrowers,
72
    ${$results}[$i]->{dateofbirth} = Koha::DateUtils::format_sqldatetime(${$results}[$i]->{dateofbirth}, undef, undef, 1);
73
      { borrowernumber => $b->borrowernumber,
74
        surname        => $b->surname    // '',
75
        firstname      => $b->firstname  // '',
76
        cardnumber     => $b->cardnumber // '',
77
        address        => $b->address    // '',
78
        city           => $b->city       // '',
79
        zipcode        => $b->zipcode    // '',
80
        country        => $b->country    // '',
81
      };
82
}
73
}
83
74
84
print to_json( \@borrowers );
75
print to_json($results);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-box.inc (-2 / +1 lines)
Lines 14-20 $(document).ready(function(){ Link Here
14
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
14
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
15
        return $( "<li></li>" )
15
        return $( "<li></li>" )
16
        .data( "ui-autocomplete-item", item )
16
        .data( "ui-autocomplete-item", item )
17
        .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
17
        .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.dateofbirth + ", " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
18
        .appendTo( ul );
18
        .appendTo( ul );
19
    };
19
    };
20
20
21
- 

Return to bug 13931