Bug 18689: calendar error with double quotes in title or description of holiday
[koha.git] / svc / holds
blobc1a5a9a83c812e4258cd6afb034bee306a431e5c
1 #!/usr/bin/perl
3 # Copyright 2014 ByWater Solutions
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
10 # version.
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use CGI;
23 use JSON qw(to_json);
25 use C4::Auth qw(check_cookie_auth);
26 use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
27 use C4::Charset;
28 use C4::Circulation qw(GetTransfers);
29 use C4::Context;
31 use Koha::DateUtils;
32 use Koha::Holds;
33 use Koha::Libraries;
35 my $input = new CGI;
37 my ( $auth_status, $sessionID ) =
38 check_cookie_auth( $input->cookie('CGISESSID'),
39 { circulate => 'circulate_remaining_permissions' } );
41 if ( $auth_status ne "ok" ) {
42 exit 0;
45 my $branch = C4::Context->userenv->{'branch'};
47 my $schema = Koha::Database->new()->schema();
49 my @sort_columns =
50 qw/reservedate title itemcallnumber barcode expirationdate priority/;
52 my $borrowernumber = $input->param('borrowernumber');
53 my $offset = $input->param('iDisplayStart');
54 my $results_per_page = $input->param('iDisplayLength');
55 my $sorting_direction = $input->param('sSortDir_0') || 'desc';
56 my $sorting_column = $sort_columns[ $input->param('iSortCol_0') ]
57 || 'reservedate';
59 binmode STDOUT, ":encoding(UTF-8)";
60 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
62 my $holds_rs = Koha::Holds->search(
63 { borrowernumber => $borrowernumber },
65 order_by => { "-$sorting_direction" => $sorting_column }
69 my $borrower;
70 my @holds;
71 while ( my $h = $holds_rs->next() ) {
72 my $item = $h->item();
74 my $biblionumber = $h->biblio()->biblionumber();
76 my $itemtype_limit;
77 if ( $h->itemtype ) {
78 my $itemtype = C4::Koha::getitemtypeinfo( $h->itemtype );
79 $itemtype_limit = $itemtype->{translated_description};
82 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
83 for my $library ( @$libraries ) {
84 $library->{selected} = 1 if $library->{branchcode} eq $h->branchcode();
86 my $hold = {
87 DT_RowId => $h->reserve_id(),
88 biblionumber => $biblionumber,
89 title => $h->biblio()->title(),
90 author => $h->biblio()->author(),
91 reserve_id => $h->reserve_id(),
92 branchcode => $h->branch()->branchname(),
93 branches => $libraries,
94 reservedate => $h->reservedate(),
95 expirationdate => $h->expirationdate(),
96 suspend => $h->suspend(),
97 suspend_until => $h->suspend_until(),
98 found => $h->found(),
99 waiting => $h->is_waiting(),
100 waiting_at => $h->branch()->branchname(),
101 waiting_here => $h->branch()->branchcode() eq $branch,
102 priority => $h->priority(),
103 itemtype_limit => $itemtype_limit,
104 subtitle => GetRecordValue(
105 'subtitle', GetMarcBiblio($biblionumber),
106 GetFrameworkCode($biblionumber)
108 reservedate_formatted => $h->reservedate() ? output_pref(
109 { dt => dt_from_string( $h->reservedate() ), dateonly => 1 }
111 : q{},
112 suspend_until_formatted => $h->suspend_until() ? output_pref(
113 { dt => dt_from_string( $h->suspend_until() ), dateonly => 1 }
115 : q{},
116 expirationdate_formatted => $h->expirationdate() ? output_pref(
117 { dt => dt_from_string( $h->expirationdate() ), dateonly => 1 }
119 : q{},
122 $hold->{transfered} = 0;
123 $hold->{not_transfered} = 0;
125 if ($item) {
126 $hold->{itemnumber} = $item->itemnumber();
127 $hold->{barcode} = $item->barcode();
128 $hold->{itemtype} = $item->effective_itemtype();
129 $hold->{itemcallnumber} = $item->itemcallnumber() || q{};
131 my ( $transferred_when, $transferred_from, $transferred_to ) =
132 GetTransfers( $item->itemnumber() );
133 if ($transferred_when) {
134 $hold->{color} = 'transferred';
135 $hold->{transferred} = 1;
136 $hold->{date_sent} = output_pref( dt_from_string($transferred_when) );
137 $hold->{from_branch} = Koha::Libraries->find($transferred_from)->branchname;
139 elsif ( $item->holding_branch() && $item->holding_branch()->branchcode() ne
140 $h->branch()->branchcode() )
142 $hold->{not_transferred} = 1;
143 $hold->{not_transferred_by} = $h->item()->holding_branch()->branchname();
147 push( @holds, $hold );
150 my $data;
151 $data->{'iTotalRecords'} = scalar @holds;
152 $data->{'iTotalDisplayRecords'} = scalar @holds;
153 $data->{'sEcho'} = $input->param('sEcho') || undef;
154 $data->{'aaData'} = \@holds;
156 print to_json($data);