From ebba2e6ed2b0ca0340dfbaf5c8fa58cdf444b71d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 10 Nov 2017 15:32:43 -0300 Subject: [PATCH] Bug 15492: Add SCI module This patch adds the SCI module, and adapts C4::Auth to know about it. The current behaviour is: - Requires admin user initialization/login - Uses the logged users' library - A form allows to scan multiple barcodes - A button sends the barcode list to the controller to batch perform the checkins - Successful and failed checkins are sent to the template - Results are displayed - Logout link To test: - Apply this patches - Make sure you upgrade: $ kshell k$ perl installer/data/mysql/updatedatabase.pl - Have 'SelfCheckInModule' disabled - Go to http://kohadev.myDNSname.org:8080/cgi-bin/koha/sci/sci-main.pl [1] => SUCCESS: You are rejected because the feature is disabled - Enable 'SelfCheckInModule' - Go to the previous URL => SUCCESS: You are required to login - Login with a user WITHOUT self_checkout permissions => SUCCESS: You are not allowed to log into the Self check-in module. - Login with a user WITH self_checkour permissions => SUCCESS: You gain access, and are presented the UI - Go through the several options => SUCCESS: All works as it should - Click the 'Help' link => SUCCESS: A help text is displayed on a modal - Sign off :-D - Bonus points: $ kshell k$ qa -c 2 -v 2 => SUCCESS: All tests green [1] Adjust to your dev's OPAC setup Signed-off-by: David Bourgault Signed-off-by: Kyle M Hall --- C4/Auth.pm | 29 +++ koha-tmpl/opac-tmpl/bootstrap/css/sco.css | 12 + .../opac-tmpl/bootstrap/en/modules/opac-auth.tt | 4 + .../opac-tmpl/bootstrap/en/modules/sci/sci-main.tt | 248 +++++++++++++++++++++ opac/sci/sci-main.pl | 96 ++++++++ 5 files changed, 389 insertions(+) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt create mode 100755 opac/sci/sci-main.pl diff --git a/C4/Auth.pm b/C4/Auth.pm index 67bdd7e751..23cf87c16a 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -207,6 +207,34 @@ sub get_template_and_user { } } + # If the user logged in is the SCI user and they try to go out of the SCI module, + # log the user out removing the CGISESSID cookie + if ( $in->{type} eq 'opac' and $in->{template_name} !~ m|sci/| ) { + if ( $user && C4::Context->preference('AutoSelfCheckID') && $user eq C4::Context->preference('AutoSelfCheckID') ) { + $template = C4::Templates::gettemplate( 'opac-auth.tt', 'opac', $in->{query} ); + my $cookie = $in->{query}->cookie( + -name => 'CGISESSID', + -value => '', + -expires => '', + -HttpOnly => 1, + ); + + $template->param( + loginprompt => 1, + script_name => get_script_name(), + ); + print $in->{query}->header( + { type => 'text/html', + charset => 'utf-8', + cookie => $cookie, + 'X-Frame-Options' => 'SAMEORIGIN' + } + ), + $template->output; + safe_exit; + } + } + my $borrowernumber; if ($user) { @@ -1266,6 +1294,7 @@ sub checkauth { ); $template->param( SCO_login => 1 ) if ( $query->param('sco_user_login') ); + $template->param( SCI_login => 1 ) if ( $query->param('sci_user_login') ); $template->param( OpacPublic => C4::Context->preference("OpacPublic") ); $template->param( loginprompt => 1 ) unless $info{'nopermission'}; diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/sco.css b/koha-tmpl/opac-tmpl/bootstrap/css/sco.css index ad50406085..38fe8777da 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/css/sco.css +++ b/koha-tmpl/opac-tmpl/bootstrap/css/sco.css @@ -193,4 +193,16 @@ i.help { .table .nosort.sorting { padding-right: 19px; background: #EEEEEE none; +} + +#sci_logout { + color: #E8583C; +} + +#sci_checkin_button, #sci_refresh_button, #sci_append_button { + margin-bottom: 10px; +} + +#sci_refresh_button { + color: rgb(51, 51, 51); } \ No newline at end of file diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt index 31cfbc63c5..2a38e505ce 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt @@ -31,6 +31,8 @@

Sorry, the system doesn't think you have permission to access this page.

[% IF SCO_login %]

Log out and try again with a different user.

+ [% ELSIF SCI_login %] +

Log out and try again with a different user.

[% END %] [% END %] @@ -158,6 +160,8 @@ [% IF SCO_login %]
+ [% ELSIF SCI_login %] + [% ELSE %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt new file mode 100644 index 0000000000..c33d6f4338 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt @@ -0,0 +1,248 @@ +[%# Includes %] +[% USE Koha %] +[% USE KohaDates %] +[%# Helper template functions %] +[% BLOCK error_message %] + [% IF messages.BadBarcode %] + (Barcode not found on the database) + [% ELSIF messages.DataCorrupted %] + (Data corruption detected. Contact your librarian) + [% ELSIF messages.Wrongbranch %] + (The item cannot be returned at this library) + [% ELSIF messages.withdrawn %] + (Item is withdrawn and check-in blocked by policy. Contact your librarian) + [% ELSIF messages.NotIssued %] + (The book is not currently on loan. Contact your librarian) + [% END %] +[% END %] + +[% INCLUDE 'doc-head-open.inc' %] + +[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha [% END %] › Self check-in + + + + +[% IF ( Koha.Preference('OpacFavicon') ) %] + +[% ELSE %] + +[% END %] + + + + +[% IF ( Koha.Preference('OPACUserCSS') ) %][% END %] +[% IF ( Koha.Preference('SCOUserCSS') ) %][% END %] + + + + + + +[% SET OpacLangSelectorMode = Koha.Preference('OpacLangSelectorMode') %] +
+ + +[% IF Koha.Preference( 'opacheader' ) %] +
+
+
+ [% Koha.Preference( 'opacheader' ) %] +
+
+
+[% END %] + +
+
+
+
+

[% LibraryName %] Self check-in

+ [% IF ( nopermission ) %] + [%# This is what is displayed if user doesn't have permission %] +
+

Access denied

+

Sorry, this self check-in station has lost authentication. Please contact the administrator to resolve this problem.

+
+ [% ELSIF ( different_ip ) %] + [%# This is what is displayed if user doesn't have permission %] +
+

Session lost

+

You are accessing self check-in from a different IP address! Please log in again.

+
+ [% ELSIF ( checkins ) %] + [%# We have results from a check-in attempt %] +
+ [% IF ( success && success.size > 0 || errors && errors.size > 0 ) %] +

Results

+ + + + + + + [% FOREACH success_line IN success %] + + [% END %] + [% FOREACH error IN errors %] + + + + + [% END %] + + +
+ + + +
+ [% ELSE %] +
+

Your request included no check-ins.

+
+ [% END %] +
+ [% ELSE %] + [%# Prompt for barcodes %] +
+
+
+
+ + + +
+
+ + + + + + + +
+ +
+ + +
+
+
+
+ [% END %] +
+
+
+ + [% IF ( Koha.Preference('SCOMainUserBlock' ) ) %] +
[% Koha.Preference('SCOMainUserBlock' ) %]
+ [% END %] +
+ + + + +[% INCLUDE 'opac-bottom.inc' %] +[% BLOCK jsinclude %] + [% INCLUDE 'datatables.inc' %] + + + [% IF ( Koha.Preference('SCOUserJS') ) %][% END %] +[% END %] diff --git a/opac/sci/sci-main.pl b/opac/sci/sci-main.pl new file mode 100755 index 0000000000..a6cb4fef75 --- /dev/null +++ b/opac/sci/sci-main.pl @@ -0,0 +1,96 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use CGI qw ( -utf8 ); + +use C4::Auth qw(get_template_and_user checkpw); +use C4::Circulation; +use C4::Output; + +use List::MoreUtils qw( uniq ); +use Try::Tiny; + +my $cgi = new CGI; + +# 404 if feature is disabled +unless ( C4::Context->preference('SelfCheckInModule') ) { + print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + +# Let Auth know this is a SCI context +$cgi->param( -name => 'sci_user_login', -values => [1] ); + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "sci/sci-main.tt", + authnotrequired => 0, + flagsrequired => { circulate => "self_checkout" }, + query => $cgi, + type => "opac" + } +); + +my $op = $cgi->param('op') // ''; + +if ( $op eq 'check_in' ) { + ## Get the barcodes, perform some basic validation + # Remove empty ones + my @barcodes = grep { $_ ne '' } $cgi->multi_param('barcode'); + + # Remove duplicates + @barcodes = uniq @barcodes; + + # Read the library we are logged in from userenv + my $library = C4::Context->userenv->{'branch'}; + my @success; + my @errors; + + # Return items + foreach my $barcode (@barcodes) { + try { + my ( $success, $messages, $checkout, $patron ) = + AddReturn( $barcode, $library ); + if ($success) { + push @success, + { + barcode => $barcode, + messages => $messages, + checkout => $checkout, + patron => $patron + }; + } + else { + push @errors, + { + barcode => $barcode, + messages => $messages, + checkout => $checkout, + patron => $patron + }; + } + } + catch { + push @errors, { barcode => $barcode, messages => 'unknown_error' }; + }; + } + $template->param( success => \@success, errors => \@errors, checkins => 1 ); +} + +output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.14.1