From 288c3f2278d41aa1e355066e579c5abec7576dea Mon Sep 17 00:00:00 2001
From: Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
Date: Thu, 25 May 2017 18:28:41 +0200
Subject: [PATCH] Bug 7317: Add generic Copyright Clearance functionality.

* Koha/Illrequest.pm (backend_create): Consider Copyright Clearance
  syspref.
* koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt: Display
  Copyright Clearance information.
---
 Koha/Illrequest.pm                                      | 17 +++++++++++++++++
 .../intranet-tmpl/prog/en/modules/ill/ill-requests.tt   | 15 ++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm
index 145c55ac9a..6677fcde03 100644
--- a/Koha/Illrequest.pm
+++ b/Koha/Illrequest.pm
@@ -467,6 +467,23 @@ pass it $params, as it does not yet have any other data associated with it.
 sub backend_create {
     my ( $self, $params ) = @_;
 
+    # Establish whether we need to do a generic copyright clearance.
+    if ( ( !$params->{stage} || $params->{stage} eq 'init' )
+             && C4::Context->preference("ILLModuleCopyrightClearance") ) {
+        return {
+            error   => 0,
+            status  => '',
+            message => '',
+            method  => 'create',
+            stage   => 'copyrightclearance',
+            value   => {
+                backend => $self->_backend->name
+            }
+        };
+    } elsif ( $params->{stage} eq 'copyrightclearance' ) {
+        $params->{stage} = 'init';
+    }
+
     # First perform API action, then...
     my $args = {
         request => $self,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt
index 5c2f3fb556..c0137270f4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt
@@ -1,4 +1,5 @@
 [% USE Branches %]
+[% USE Koha %]
 
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; ILL requests  &rsaquo;</title>
@@ -396,7 +397,19 @@
 
                 [% IF query_type == 'create' %]
                     <h1>New ILL request</h1>
-                    [% PROCESS $whole.template %]
+                    [% IF whole.stage == 'copyrightclearance' %]
+                        <div>
+                            <p>
+                                [% Koha.Preference('ILLModuleCopyrightClearance') %]
+                            </p>
+                            <a href="?method=create&stage=copyrightclearance&backend=[% whole.value.backend %]"
+                               class="btn btn-sm btn-default btn-group"><i class="fa fa-check">Yes</i></a>
+                            <a href="/cgi-bin/koha/ill/ill-requests.pl"
+                               class="btn btn-sm btn-default btn-group"><i class="fa fa-times">No</i></a>
+                        </div>
+                    [% ELSE %]
+                        [% PROCESS $whole.template %]
+                    [% END %]
 
                 [% ELSIF query_type == 'confirm' %]
                     <h1>Confirm ILL request</h1>
-- 
2.11.0