Merge remote-tracking branch 'origin/new/bug_6875'
[koha.git] / offline_circ / service.pl
1 #!/usr/bin/perl
2
3 # 2009 BibLibre <jeanandre.santoni@biblibre.com>
4
5 # This file is part of Koha.
6 #
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 2 of the License, or (at your option) any later
10 # version.
11 #
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.
15 #
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.
19 #
20
21 use strict;
22 use warnings;
23
24 use CGI;
25 use C4::Auth;
26 use C4::Circulation;
27
28 my $cgi = CGI->new;
29
30 # get the status of the user, this will check his credentials and rights
31 my ($status, $cookie, $sessionId) = C4::Auth::check_api_auth($cgi, undef);
32
33 my $result;
34
35 if ($status eq 'ok') { # if authentication is ok
36     if ( $cgi->param('pending') eq 'true' ) { # if the 'pending' flag is true, we store the operation in the db instead of directly processing them
37         $result = AddOfflineOperation(
38             $cgi->param('userid')     || '',
39             $cgi->param('branchcode') || '',
40             $cgi->param('timestamp')  || '',
41             $cgi->param('action')     || '',
42             $cgi->param('barcode')    || '',
43             $cgi->param('cardnumber') || '',
44         );
45     } else {
46         $result = ProcessOfflineOperation(
47             {
48                 'userid'      => $cgi->param('userid'),
49                 'branchcode'  => $cgi->param('branchcode'),
50                 'timestamp'   => $cgi->param('timestamp'),
51                 'action'      => $cgi->param('action'),
52                 'barcode'     => $cgi->param('barcode'),
53                 'cardnumber'  => $cgi->param('cardnumber'),
54             }
55         );
56     }
57 } else {
58     $result = "Authentication failed."
59 }
60
61 print CGI::header('-type'=>'text/plain', '-charset'=>'utf-8');
62 print $result;