From b29af58306b436755d9a0a3394e29eb549549c60 Mon Sep 17 00:00:00 2001
From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Date: Tue, 29 Oct 2013 19:13:10 +0200
Subject: [PATCH] Bug 11157 - Placing a simple item-level hold for serials in
 staff client.

For biblios marked as a serial or if the syspref:
-ShowPlaceItemLevelHold
is enabled.
Adds a "Place hold"-link after each item in the detailed biblio view.

Added a new parameter itemnumber to reserve.pl/.tt.
This causes the reserving module to display only the desired item, preselect it
and hide unnecessary buttons.
---
 catalogue/detail.pl                                |  6 ++++++
 installer/data/mysql/sysprefs.sql                  |  1 +
 .../en/modules/admin/preferences/cataloguing.pref  |  7 +++++++
 .../prog/en/modules/catalogue/detail.tt            |  8 ++++++++
 .../prog/en/modules/reserve/request.tt             | 17 ++++++++++++++---
 reserve/request.pl                                 | 22 +++++++++++++++++++++-
 6 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index 955dbf5..9a8d339 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -144,6 +144,10 @@ my $dat = &GetBiblioData($biblionumber);
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, undef, $biblionumber );
 my @subs;
+if (scalar(@subscriptions)) {
+	$template->param('isSerial',1);
+}
+
 
 foreach my $subscription (@subscriptions) {
     my %cell;
@@ -462,4 +466,6 @@ $template->param (countdeletedorders => $count_deletedorders_using_biblio);
 $template->param (basketsorders => \@baskets_orders);
 $template->param (basketsdeletedorders => \@baskets_deletedorders);
 
+$template->param('ShowPlaceItemLevelHold',  C4::Context->preference('ShowPlaceItemLevelHold'));
+
 output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index df2b999..0d871de 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -345,6 +345,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('ShowPatronImageInWebBasedSelfCheck','0','','If ON, displays patron image when a patron uses web-based self-checkout','YesNo'),
 ('ShowReviewer','full','none|full|first|surname|firstandinitial|username','Choose how a commenter\'s identity is presented alongside comments in the OPAC','Choice'),
 ('ShowReviewerPhoto','1','','If ON, photo of reviewer will be shown beside comments in OPAC','YesNo'),
+('ShowPlaceItemLevelHold','0',NULL,'Allow placing a item-level hold from the detailed biblio view.','YesNo'),
 ('singleBranchMode','0',NULL,'Operate in Single-branch mode, hide branch selection in the OPAC','YesNo'),
 ('SlipCSS','',NULL,'Slips CSS url.','free'),
 ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
index 9d15296..86075a9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
@@ -18,6 +18,13 @@ Cataloging:
                   yes: Display
                   no: "Don't Display"
             - easy ways to create analytical record relationships
+        -
+            - pref: ShowPlaceItemLevelHold
+              default: 0
+              choices:
+                  yes: "Allow"
+                  no : "Don't allow"
+            - placing a item-level hold from the detailed biblio view. This is always enabled for serials because serials need only item-level holds.
     Spine Labels:
         -
             - When using the quick spine label printer,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
index 26f945c..dafaefe 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
@@ -524,6 +524,7 @@ function verify_images() {
                 [% IF ( hostrecords ) %]<th>Host records</th>[% END %]
                 [% IF ( analyze ) %]<th>Used in</th><th></th>[% END %]
                 [% IF ( ShowCourseReserves ) %]<th>Course Reserves</th>[% END %]
+                [% IF ( ShowPlaceItemLevelHold || isSerial ) %]<th id="placeItemLevelHoldTh">Reserve</th>[% END %]
             </tr>
         </thead>
         <tbody>
@@ -697,6 +698,13 @@ function verify_images() {
                        [% END %]
                     </td>
                 [% END %]
+                [% IF ( ShowPlaceItemLevelHold || isSerial ) %]
+                    <td>
+                        <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblionumber %]&itemnumber=[% item.itemnumber %]">
+                            Place hold
+                        </a>
+                    </td>
+                [% END %]
                 </tr>
             [% END %]
         </tbody>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
index 7f7d05f..b0eb339 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
@@ -191,7 +191,9 @@ function checkMultiHold() {
   [% END %]
 
   [% UNLESS ( multi_hold ) %]
-    <h1>Place a hold on [% INCLUDE 'biblio-default-view.inc' %][% title |html %]</a></h1>
+    <h1>Place a hold on [% INCLUDE 'biblio-default-view.inc' %][% title |html %]</a>
+        [% IF targetItemTitle %] - <a href="/cgi-bin/koha/catalogue/moredetail.pl?type=&itemnumber=[% targetItemnumber %]&biblionumber=[% biblionumber %]&bi=[% biblioitemnumber %]#item[% targetItemnumber %]">[% targetItemTitle %]</a>[% END %]
+    </h1>
   [% ELSE %]
     <h1>Confirm Holds</h1>
   [% END %]
@@ -208,6 +210,7 @@ function checkMultiHold() {
                 <input type="text" size="40" id="patron" class="focus" name="findborrower" />
                 <input type="submit" value="Search" />
                 <input type="hidden" name="biblionumber" value="[% biblionumber %]" />
+                [% IF targetItemnumber %]<input type="hidden" name="itemnumber" value="[% targetItemnumber %]" />[% END %]
             </fieldset>
         [% ELSE %]
           <fieldset>
@@ -221,6 +224,7 @@ function checkMultiHold() {
             [% END %]
             </select>
             <input type="hidden" name="biblionumber" value="[% biblionumber %]" /><fieldset class="action"><input type="submit" value="Select" /></fieldset></fieldset>
+            [% IF targetItemnumber %]<input type="hidden" name="itemnumber" value="[% targetItemnumber %]" />[% END %]
 
         [% END %]
         [% IF ( multi_hold ) %]
@@ -344,8 +348,11 @@ function checkMultiHold() {
 	</li>
 
         [% UNLESS ( multi_hold ) %]
-          <li> <label for="requestany">Place a hold on the next available copy </label>
+          <li>
+            [% UNLESS targetItemnumber %]
+               <label for="requestany">Place a hold on the next available copy </label>
                <input type="checkbox" id="requestany" name="request" checked="checked" value="Any" />
+            [% END %]
                <input type="hidden" name="biblioitem" value="[% biblioitemnumber %]" />
                <input type="hidden" name="alreadyreserved" value="[% alreadyreserved %]" />
           </li>
@@ -395,7 +402,11 @@ function checkMultiHold() {
         <tr class="[% itemloo.backgroundcolor %]">
             <td>
             [% IF ( itemloo.available ) %]
-                <input type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
+                [% IF targetItemnumber %]
+                    <input type="radio" name="checkitem" checked="checked" value="[% itemloo.itemnumber %]" />
+                [% ELSE %]
+                    <input type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
+                [% END %]
             [% ELSIF ( itemloo.override ) %]
                 <input type="radio" name="checkitem" class="needsoverride" value="[% itemloo.itemnumber %]" />
                 <img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/error.png" alt="Requires override of hold policy" />
diff --git a/reserve/request.pl b/reserve/request.pl
index c411ce9..4151f54 100755
--- a/reserve/request.pl
+++ b/reserve/request.pl
@@ -57,10 +57,27 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
     }
 );
 
+my $targetItemnumber = $input->param('itemnumber') ? $input->param('itemnumber') : undef;
+if ($targetItemnumber) {
+    $template->param('targetItemnumber', $targetItemnumber);
+    my $targetItem = C4::Items::GetItem($targetItemnumber);
+    if ($targetItem->{enumchron}) {
+        $template->param('targetItemTitle', $targetItem->{enumchron});
+    }
+    elsif ($targetItem->{barcode}) {
+        $template->param('targetItemTitle', $targetItem->{barcode});
+    }
+    else {
+        $template->param('targetItemTitle', $targetItem->{itemnumber});
+    }
+}
+
+
 my $multihold = $input->param('multi_hold');
 $template->param(multi_hold => $multihold);
 my $showallitems = $input->param('showallitems');
 
+
 # get Branches and Itemtypes
 my $branches = GetBranches();
 my $itemtypes = GetItemTypes();
@@ -243,7 +260,10 @@ foreach my $biblionumber (@biblionumbers) {
     my @itemnumbers;
 
     ## $items is array of 'item' table numbers
-    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
+    if ($targetItemnumber) { #If we just want to place a hold on one item
+        push @itemnumbers, $targetItemnumber;
+    }
+    elsif (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
         @itemnumbers  = @$items;
     }
     my @hostitems = get_hostitemnumbers_of($biblionumber);
-- 
1.8.1.2