3 # Copyright 2013 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
30 my ( $template, $loggedinuser, $cookie, $flags ) =
31 checkauth( $query, undef, { circulate => "circulate_remaining_permissions" },
34 my $page = $query->param('page') || 0;
35 my $startrec = int($page) * 5000;
36 my $req_data = $query->param('data') || '';
38 my $patrons_query = qq{SELECT
39 borrowers.borrowernumber, cardnumber, surname, firstname, title,
40 othernames, initials, streetnumber, streettype, address, address2, city,
41 state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode,
42 categorycode, dateenrolled, dateexpiry, gonenoaddress, lost, debarred,
43 debarredcomment, SUM(accountlines.amountoutstanding) AS fine
45 LEFT JOIN accountlines ON borrowers.borrowernumber=accountlines.borrowernumber
46 GROUP BY borrowers.borrowernumber
47 LIMIT $startrec, 5000;
50 # NOTE: we can't fit very long titles on the interface so there isn't really any point in transferring them
51 my $items_query = qq{SELECT
52 items.barcode AS barcode, items.itemnumber AS itemnumber,
53 items.itemcallnumber AS callnumber, items.homebranch AS homebranch,
54 items.holdingbranch AS holdingbranch, items.itype AS itemtype,
55 items.materials AS materials, LEFT(biblio.title, 60) AS title,
56 biblio.author AS author, biblio.biblionumber AS biblionumber
58 JOIN biblio ON biblio.biblionumber = items.biblionumber
59 LIMIT $startrec, 5000;
62 my $issues_query = qq{SELECT
63 biblio.title AS title,
64 items.barcode AS barcode,
65 items.itemcallnumber AS callnumber,
66 issues.date_due AS date_due,
67 issues.issuedate AS issuedate,
68 issues.renewals AS renewals,
69 borrowers.cardnumber AS cardnumber,
70 CONCAT(borrowers.surname, ', ', borrowers.firstname) AS borrower_name
72 JOIN items ON items.itemnumber = issues.itemnumber
73 JOIN biblio ON biblio.biblionumber = items.biblionumber
74 JOIN borrowers ON borrowers.borrowernumber = issues.borrowernumber
75 LIMIT $startrec, 5000;
78 if ( $req_data eq 'all' ) {
79 print $query->header( -type => 'application/json', -charset => 'utf-8' );
82 'patrons' => get_data( $patrons_query, 'cardnumber' ),
83 'items' => get_data( $items_query, 'barcode' ),
84 'issues' => get_data( $issues_query, 'barcode' ),
88 elsif ( $req_data eq 'patrons' ) {
89 print $query->header( -type => 'application/json', -charset => 'utf-8' );
90 print to_json( { 'patrons' => get_data( $patrons_query, 'cardnumber' ), } );
92 elsif ( $req_data eq 'items' ) {
93 print $query->header( -type => 'application/json', -charset => 'utf-8' );
94 print to_json( { 'items' => get_data( $items_query, 'barcode' ), } );
96 elsif ( $req_data eq 'issues' ) {
97 print $query->header( -type => 'application/json', -charset => 'utf-8' );
98 print to_json( { 'issues' => get_data( $issues_query, 'barcode' ), } );
102 my ( $sql, $key ) = @_;
103 my $dbh = C4::Context->dbh;
104 my $sth = $dbh->prepare($sql);
106 return $sth->fetchall_hashref($key);