From 8daca4918eb59d15ac71f6185d3005dec61099f8 Mon Sep 17 00:00:00 2001
From: David Roberts <david.roberts@ptfs-europe.com>
Date: Thu, 6 Jul 2017 20:49:44 +0100
Subject: [PATCH] Bug 7374: Can't upload icon for auth values

This patch allows the upload of a remote image to the authorised values policies.
---
 admin/authorised_values.pl                         |  9 ++++++++-
 .../prog/en/modules/admin/authorised_values.tt     | 22 +++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl
index 272ed00..87a729f 100755
--- a/admin/authorised_values.pl
+++ b/admin/authorised_values.pl
@@ -28,6 +28,7 @@ use C4::Output;
 use Koha::AuthorisedValues;
 use Koha::AuthorisedValueCategories;
 use Koha::Libraries;
+use Koha::Localizations;
 
 my $input = new CGI;
 my $id          = $input->param('id');
@@ -98,8 +99,14 @@ if ($op eq 'add_form') {
 } elsif ($op eq 'add') {
     my $new_authorised_value = $input->param('authorised_value');
     my $new_category = $input->param('category');
+    my $image = $input->param('image') || q||;
     my $imageurl     = $input->param( 'imageurl' ) || '';
-    $imageurl = '' if $imageurl =~ /removeImage/;
+    my $imageurl =
+      $image eq 'removeImage' ? ''
+      : (
+          $image eq 'remoteImage' ? $input->param('remoteImage')
+        : $image
+      );
     my $duplicate_entry = 0;
     my @branches = grep { $_ ne q{} } $input->multi_param('branches');
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt
index 5aee840..c105f4e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt
@@ -126,6 +126,7 @@ $(document).ready(function() {
 				  [% FOREACH imageset IN imagesets %]
                         [% IF ( imageset.imagesetactive ) %]<li class="ui-tabs-active">[% ELSE %]<li>[% END %]<a href="#[% imageset.imagesetname %]">[% imageset.imagesetname %]</a></li>
 				  [% END %]
+      [% IF itemtype.image_location('intranet').match('^http') %]<li class="ui-tabs-active">[% ELSE %]<li>[% END %]<a href="#remote">Remote image</a></li>
 			</ul>
   <div id="none"><ul>
   <li><label for="noimage">No image: </label><input type="radio" name="imageurl" id="noimage" value="removeImage" /></li>
@@ -152,7 +153,26 @@ $(document).ready(function() {
   <br class="clear" />
   </div>
   [% END %]
-  </div>
+
+<div id="remote">
+                        <ul>
+                            <li>
+                                <label for="remote_image_check"> Remote image:</label>
+                                [% IF remote_image %]
+                                    <input type="radio" id="remote_image_check" name="image" value="remoteImage" checked="checked" />
+                                [% ELSE %]
+                                    <input type="radio" id="remote_image_check" name="image" value="remoteImage" />
+                                [% END %]
+                                <input type="text" name="remoteImage" size="48" maxlength="200" value="[% remote_image %]" onmousedown="document.getElementById('remote_image_check').checked = true;" />
+                                [% IF ( remote_image ) %]
+                                    <img src="[% remote_image %]" alt="" />
+                                [% END %]
+                            </li>
+                        </ul>
+                        <br class="clear" />
+                    </div>
+                </div>
+
         [% END %]
         </fieldset>
        <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
-- 
2.1.4