Bug 19287: Do not display buttons for biblio level holds
[koha.git] / offline_circ / service.pl
blobb36162f98eb11cb5e04fa4ec6d71bfcc7522446e
1 #!/usr/bin/perl
3 # 2009 BibLibre <jeanandre.santoni@biblibre.com>
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Auth;
25 use C4::Circulation;
26 use Koha::DateUtils;
27 use DateTime::TimeZone;
29 my $cgi = CGI->new;
31 # get the status of the user, this will check his credentials and rights
32 my ($status, $cookie, $sessionId) = C4::Auth::check_api_auth($cgi, undef);
33 ($status, $sessionId) = C4::Auth::check_cookie_auth($cgi, undef) if ($status ne 'ok');
35 my $result;
37 if ($status eq 'ok') { # if authentication is ok
39 my $userid = $cgi->param('userid') || '';
40 my $branchcode = $cgi->param('branchcode') || '';
41 my $timestamp = $cgi->param('timestamp') || '';
42 my $action = $cgi->param('action') || '';
43 my $barcode = $cgi->param('barcode') || '';
44 my $amount = $cgi->param('amount') || 0;
45 $barcode =~ s/^\s+//;
46 $barcode =~ s/\s+$//;
47 my $cardnumber = $cgi->param('cardnumber') || '';
48 $cardnumber =~ s/^\s+//;
49 $cardnumber =~ s/\s+$//;
51 # KOCT send UTC timestamp, it should be converted to local timezone
52 my $dt = dt_from_string($timestamp, 'iso', DateTime::TimeZone->new(name => 'UTC'));
53 $dt->set_time_zone(C4::Context->tz);
54 $timestamp = $dt->ymd('-') . ' ' . $dt->hms(':');
56 if ( $cgi->param('pending') eq 'true' ) { # if the 'pending' flag is true, we store the operation in the db instead of directly processing them
57 $result = AddOfflineOperation(
58 $userid,
59 $branchcode,
60 $timestamp,
61 $action,
62 $barcode,
63 $cardnumber,
64 $amount
66 } else {
67 $result = ProcessOfflineOperation(
69 'userid' => $userid,
70 'branchcode' => $branchcode,
71 'timestamp' => $timestamp,
72 'action' => $action,
73 'barcode' => $barcode,
74 'cardnumber' => $cardnumber,
75 'amount' => $amount
79 } else {
80 $result = "Authentication failed."
83 print CGI::header('-type'=>'text/plain', '-charset'=>'utf-8');
84 print $result;