Bug 18309: UNIMARC update from IFLA - authority (fr) (TU)
[koha.git] / opac / sci / sci-main.pl
blob84d2a6cb67c4fa177b165c9fcc3bd204fcd0a776
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use CGI qw ( -utf8 );
22 use C4::Auth qw(get_template_and_user checkpw);
23 use C4::Circulation;
24 use C4::Output;
26 use List::MoreUtils qw( uniq );
27 use Try::Tiny;
29 my $cgi = new CGI;
31 # 404 if feature is disabled
32 unless ( C4::Context->preference('SelfCheckInModule') ) {
33 print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
34 exit;
37 # Let Auth know this is a SCI context
38 $cgi->param( -name => 'sci_user_login', -values => [1] );
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42 template_name => "sci/sci-main.tt",
43 authnotrequired => 0,
44 flagsrequired => { self_check => 'self_checkin_module' },
45 query => $cgi,
46 type => "opac"
50 my $op = $cgi->param('op') // '';
52 if ( $op eq 'check_in' ) {
53 ## Get the barcodes, perform some basic validation
54 # Remove empty ones
55 my @barcodes = grep { $_ ne '' } $cgi->multi_param('barcode');
57 # Remove duplicates
58 @barcodes = uniq @barcodes;
60 # Read the library we are logged in from userenv
61 my $library = C4::Context->userenv->{'branch'};
62 my @success;
63 my @errors;
65 # Return items
66 foreach my $barcode (@barcodes) {
67 try {
68 my ( $success, $messages, $checkout, $patron ) =
69 AddReturn( $barcode, $library );
70 if ($success) {
71 push @success,
73 barcode => $barcode,
74 messages => $messages,
75 checkout => $checkout,
76 patron => $patron
79 else {
80 push @errors,
82 barcode => $barcode,
83 messages => $messages,
84 checkout => $checkout,
85 patron => $patron
89 catch {
90 push @errors, { barcode => $barcode, messages => 'unknown_error' };
93 $template->param( success => \@success, errors => \@errors, checkins => 1 );
96 # Make sure timeout has a reasonable value
97 my $timeout = C4::Context->preference('SelfCheckInTimeout') || 120;
98 $template->param( refresh_timeout => $timeout );
100 output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };