[Koha-patches] [PATCH] [followup] (bug #3819) still fixing holds policies

Nahuel ANGELINETTI nahuel.angelinetti at biblibre.com
Wed Dec 2 17:30:58 CET 2009


This patch backports more code from 3.2 to make hold policies working.
---
 circ/circulation.pl                                |    4 +-
 .../prog/en/modules/reserve/request.tmpl           |   60 ++++++++++++++--
 .../prog/img/famfamfam/silk/cross.png              |  Bin 0 -> 655 bytes
 .../prog/img/famfamfam/silk/error.png              |  Bin 0 -> 666 bytes
 .../opac-tmpl/prog/en/modules/opac-reserve.tmpl    |   16 ++++-
 opac/opac-reserve.pl                               |   14 +++-
 reserve/request.pl                                 |   76 +++++++++++++-------
 7 files changed, 133 insertions(+), 37 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/img/famfamfam/silk/cross.png
 create mode 100644 koha-tmpl/intranet-tmpl/prog/img/famfamfam/silk/error.png

diff --git a/circ/circulation.pl b/circ/circulation.pl
index d117092..27436a0 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -235,8 +235,8 @@ if ($borrowernumber) {
 
     # Warningdate is the date that the warning starts appearing
     my (  $today_year,   $today_month,   $today_day) = Today();
-    my ($warning_year, $warning_month, $warning_day) = split /-/, $borrower->{'dateexpiry'};
-    my (  $enrol_year,   $enrol_month,   $enrol_day) = split /-/, $borrower->{'dateenrolled'};
+    my ($warning_year, $warning_month, $warning_day) = split (/-/, $borrower->{'dateexpiry'});
+    my (  $enrol_year,   $enrol_month,   $enrol_day) = split (/-/, $borrower->{'dateenrolled'});
     # Renew day is calculated by adding the enrolment period to today
     my (  $renew_year,   $renew_month,   $renew_day) =
       Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tmpl
index 6b72b88..64e3d6a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tmpl
@@ -2,7 +2,16 @@
 <title>Koha &rsaquo; Circulation &rsaquo; Holds &rsaquo; Place a hold on <!-- TMPL_VAR NAME="title" escape="html" --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 <script type="text/javascript">
-// <![CDATA[ 
+    // <![CDATA[
+var patron_homebranch = "<!-- TMPL_VAR NAME="borrower_branchname" ESCAPE="JS" -->";
+var override_items = {<!-- TMPL_LOOP NAME="bibitemloop" --><!-- TMPL_LOOP NAME="itemloop" --><!-- TMPL_IF NAME="override" -->
+    <!-- TMPL_VAR NAME="itemnumber" -->: {
+        homebranch: "<!-- TMPL_VAR NAME="homebranchname" ESCAPE="JS" -->",
+        holdallowed: <!-- TMPL_VAR NAME="holdallowed" -->
+    },
+<!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP -->
+};
+
 function check() {
 	var msg = "";
 	var count_reserv = 0;
@@ -50,6 +59,22 @@ if (alreadyreserved > "0"){
 }
 
  $(document).ready(function() {
+    $("input.needsoverride").click(function() { // This must be before the radio button/checkbox switch logic
+        var itemnumber = this.value;
+        var msg;
+
+        switch (override_items[itemnumber].holdallowed) {
+            case 0: msg = _( 'This item normally cannot be put on hold.' ); break;
+            case 1: msg = _( 'This item normally cannot be put on hold except for patrons from ' ) + override_items[itemnumber].homebranch + '.'; break;
+        }
+
+        msg += "\n\n" + _( 'Place hold on this item?' );
+
+        return confirm(msg);
+    });
+    $("input.warning").click(function() {
+        return confirm( _( 'None of these items can normally be put on hold for this patron.' ) + "\n\n" + _( 'Place hold?' ) );
+    });
  	$("#requestany").click(function() {
 		if(this.checked){
 		$("input[name=checkitem]").each(function() {
@@ -136,6 +161,11 @@ if (alreadyreserved > "0"){
     <!-- TMPL_IF NAME="alreadyreserved" -->
      <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->"><!-- TMPL_VAR NAME="borrowerfirstname" --> <!-- TMPL_VAR NAME="borrowersurname" --></a> <strong>already has a hold</strong> on this item </li>
     <!-- /TMPL_IF -->
+
+    <!-- TMPL_IF NAME="none_available" -->
+    <li> <strong>No copies are available</strong> to be placed on hold</li>
+    <!-- /TMPL_IF -->
+
 	</ul></div>
 <!-- /TMPL_IF -->	
 
@@ -192,9 +222,15 @@ if (alreadyreserved > "0"){
 
 </ol>
         <fieldset class="action">
-        <!-- TMPL_IF NAME="cardnumber"-->
-        <input type="submit" value="Place Hold" />
-        <!-- /TMPL_IF -->
+            <!-- TMPL_IF NAME="cardnumber"-->
+                <!-- TMPL_IF NAME="override_required" -->
+                    <input type="submit" class="warning" value="Place Hold" />
+                <!-- TMPL_ELSIF NAME="none_available" -->
+                    <input type="submit" disabled="disabled" value="Place Hold" />
+                <!-- TMPL_ELSE -->
+                    <input type="submit" value="Place Hold" />
+                <!-- /TMPL_IF -->
+            <!-- /TMPL_IF -->
         </fieldset>
         <!-- TMPL_LOOP name="bibitemloop" -->
 <ol>
@@ -223,8 +259,12 @@ if (alreadyreserved > "0"){
             <td>
             <!-- TMPL_IF NAME="available" -->
                 <input type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+            <!-- TMPL_ELSIF NAME="override" -->
+                <input type="radio" name="checkitem" class="needsoverride" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+                <img src="/intranet-tmpl/<!-- TMPL_VAR NAME="theme" -->/img/famfamfam/silk/error.png" alt="Requires override of hold policy" />
             <!-- TMPL_ELSE -->
                 <input disabled="disabled" type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" /> 
+                <img src="/intranet-tmpl/<!-- TMPL_VAR NAME="theme" -->/img/famfamfam/silk/cross.png" alt="Cannot be put on hold" />
             <!-- /TMPL_IF -->
             </td>
             <!-- TMPL_IF NAME="item-level_itypes" -->
@@ -284,9 +324,15 @@ if (alreadyreserved > "0"){
     <!-- /TMPL_LOOP --> <!-- bibitemloop -->
     
     <fieldset class="action">
-    <!-- TMPL_IF NAME="cardnumber"-->
-        <input type="submit" value="Place Hold" />
-    <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="cardnumber"-->
+            <!-- TMPL_IF NAME="override_required" -->
+                <input type="submit" class="warning" value="Place Hold" />
+            <!-- TMPL_ELSIF NAME="none_available" -->
+                <input type="submit" disabled="disabled" value="Place Hold" />
+            <!-- TMPL_ELSE -->
+                <input type="submit" value="Place Hold" />
+            <!-- /TMPL_IF -->
+        <!-- /TMPL_IF -->
     </fieldset>
 	</fieldset>
     </form>
diff --git a/koha-tmpl/intranet-tmpl/prog/img/famfamfam/silk/cross.png b/koha-tmpl/intranet-tmpl/prog/img/famfamfam/silk/cross.png
new file mode 100644
index 0000000000000000000000000000000000000000..1514d51a3cf1b67e1c5b9ada36f1fd474e2d214a
GIT binary patch
literal 655
zcmV;A0&x9_P)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004XF*Lt006JZ
zHwB960000PbVXQnQ*UN;cVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU!AxT6*R5;6(
zlj}|sQ51!ViOGr2pjL^7$dQ1=8$w$KD6I_$CeZtZUZjAurR}6mp*HFdO?(oc3q-}<
zu+o`!I at 9H@m`W`r;m1zSWX}5bthM(H02sJT)z?DT&OUcv5HmU|-dF4oa at p;T*KAHh
zFQ6^X?4p&<LW?JRAa!4W*8^cRHn#BV<;v&k;?li;fWKno-=RgNB}6ngw>uEoyT++I
zn$b9r%cFfhHe2K68Pk<hKq}2z2~lh9z5zadf|kv-0cZq5T=w`mb%(MY1L(c%58!zI
zxmp(Hu69|_VhN_cj;WfM0p5Rrno6S{41>Bu*@^<$y+7xQ$wJ~;c5aBx$R=xq*41Wo
zhwQus_VOgm0hughj}MhOvs#{>Vg09Y8WxjWUJY5Y<Msg#Hz1}_nVr{4MuGi*zXu>W
zJ?&8eG!59Cz=|E%Ns at 013KLWOLV)CObIIj_5{>{#k%TEAMs_GbdDV`x-iYsG<NRDe
z&F<oo(+wrG4$v4ShYJ*zTAVUyCyUEKWCOJq%P2g2jKiT}-UXn|;?x~V at D+7UK%!5l
zu+-wDffb%iu%q!uYSm;0f+3t(tT-AO#lfvX-T}~N2{oGoN+1Mj)d31iEk4tC0{b>H
z#=Z{USAQA>NY(}X7=3{K8#<xO0&SL1U06cNFs)HoJ!v1_9b#Vw at 2F?RJt3C#MxpR@
plJ)zU4s^HK{`H%}g=4&I{RVQoq{rLsz7zle002ovPDHLkV1j2<C=vhw

literal 0
HcmV?d00001

diff --git a/koha-tmpl/intranet-tmpl/prog/img/famfamfam/silk/error.png b/koha-tmpl/intranet-tmpl/prog/img/famfamfam/silk/error.png
new file mode 100644
index 0000000000000000000000000000000000000000..628cf2dae3d419ae220c8928ac71393b480745a3
GIT binary patch
literal 666
zcmV;L0%iS)P)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004XF*Lt006JZ
zHwB960000PbVXQnQ*UN;cVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU!EJ;K`R5;6}
zQ%gvc0TBNFhpVpZYs*vuLt9diOv=bL4R1XR>eOSYYtbpBV}~vsBnU!_?2tr-P=|^T
zED<b;h)xArC`LwRuDi0BivEw8uY($aYXuI>%wc9ezHgW at NMb!^uT_|SvCpFLJylbx
zY%bpaTGI8IYXMN$9w<3j9VkA~NYOKEQXsj?6a9_hcwfU$acAhJhB)zb_w at MVUEy@S
zX&I>K-R!bhu3?(6bHWIg$HEl7{9g>>&l_qdd+UYb(1~BCo9LptNq&8>!yoJ3Ui(i5
zRJ|XnYBklL!{@$-7=3mJ>P at 1c=7Oc79e-V7yf+%lD2!I;Y&nXBZ>=B!5?CB>LvEx6
znI%n)qqi$#X#wKB(U7XP2P=+4{b at j#r%9-K(8UqtSDk>0UKzf*HM9yqMZ1D!$2MdZ
zR=`U>0zhOH1XqN?nY at AQqB7)Fp4{v&dKXvb43hZKvnN8;Po;+jY*}~*Z|W9Q0W%{D
z^T}Cc<|r(Su=1K=<sQLMN1ZE<U%m5Ea at 1Tp8to2kJ7-hpAhT}(Dgffk;4r2>P5>Z4
zg`et&Va}tdzBS-G-ZcO)zCWpJvGQwrHZ`@wpM420ac at bI5~KkTFfGEM3sPWO8<ADs
zh7X-F%!~{kwpFCFAaZKyF+vTnL(ye%#)|yqz~B3T5kTqQvq%jMT(v1Wka%_eG)1AJ
z_%n+q5XXb>co4^fI6lPnA)Y{ef%@{+SnoUk0+dW+*{8WvF8}}l07*qoM6N<$g7cXs
A&j0`b

literal 0
HcmV?d00001

diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl
index 18832d6..51ed128 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tmpl
@@ -87,6 +87,11 @@
     <!-- TMPL_IF NAME="bad_biblionumber" -->
     <div class="dialog alert">ERROR: No biblio record found for biblionumber <!-- TMPL_VAR NAME="bad_biblionumber" -->.</div>
     <!-- /TMPL_IF -->
+    <!-- TMPL_IF NAME="none_available" -->
+    <div class="dialog alert">
+        <strong>Sorry</strong>, none of these items can be placed on hold.
+    </div>
+    <!-- /TMPL_IF -->
 </div>
 <!-- /TMPL_IF -->
 
@@ -135,7 +140,11 @@
 
 
 <fieldset class="action">            <input type="hidden" name="biblioitem" value="<!-- TMPL_VAR NAME="biblioitemnumber" -->" />
+			<!-- TMPL_IF NAME="none_available" -->
+            <input type="submit" disabled="disabled" value="Place Hold" />
+            <!-- TMPL_ELSE -->
             <input type="submit" value="Place Hold" />
+            <!-- /TMPL_IF -->
             <input type="hidden" name="all" value="1" />
             <input type="hidden" name="place_reserve" value="1" /></fieldset>
 			<!-- /TMPL_IF -->  
@@ -164,6 +173,7 @@
             <input type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
             <!-- TMPL_ELSE -->
             <input disabled="disabled" type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+            <img src="/intranet-tmpl/<!-- TMPL_VAR NAME="theme" -->/img/famfamfam/silk/cross.png" alt="Cannot be put on hold" />
             <!-- /TMPL_IF -->
             </td>
             <!-- TMPL_IF NAME="item-level_itypes" -->
@@ -206,7 +216,11 @@
         <!-- /TMPL_LOOP --> <!-- itemloop -->
         </table>
         <!-- /TMPL_LOOP --> <!-- bibitemloop -->
-        <input type="submit" value="Place Hold" />
+        <!-- TMPL_IF NAME="none_available" -->
+            <input type="submit" disabled="disabled" value="Place Hold" />
+        <!-- TMPL_ELSE -->
+            <input type="submit" value="Place Hold" />
+        <!-- /TMPL_IF -->
         </form><!-- /TMPL_IF -->
     <!-- end of the first form -->
 <!-- /TMPL_IF -->
diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index ad895f6..9842e71 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -250,6 +250,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
 }
 
 my @bibitemloop;
+my $num_available = 0;
 
 foreach my $biblioitemnumber (@biblioitemnumbers) {
     my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
@@ -330,12 +331,17 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
         # If there is no loan, return and transfer, we show a checkbox.
         $item->{notforloan} = $item->{notforloan} || 0;
 
-        my $branchitemrule = C4::Context->preference("RequestOnOpac");
+        my $branchitemrule = GetBranchItemRule( $borr->{'branchcode'}, $itemInfo->{'itype'} );
         my $policy_holdallowed = 1;
-
+        
+        if ( $branchitemrule->{'holdallowed'} == 0 ||
+                ( $branchitemrule->{'holdallowed'} == 1 && $borr->{'branchcode'} ne $itemInfo->{'homebranch'} ) ) {
+            $policy_holdallowed = 0;
+        }
 
         if (IsAvailableForItemLevelRequest($itemnumber) and $policy_holdallowed) {
             $item->{available} = 1;
+            $num_available++;
         }
 
 	# FIXME: move this to a pm
@@ -352,6 +358,10 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
     push @bibitemloop, $biblioitem;
 }
 
+if ( $num_available == 0 ) {
+        $template->param( none_available => 1, message => 1 );
+}
+
 # display infos
 $template->param(
 	forloan           => $forloan,
diff --git a/reserve/request.pl b/reserve/request.pl
index 58b42b3..67ef180 100755
--- a/reserve/request.pl
+++ b/reserve/request.pl
@@ -115,7 +115,7 @@ if ($cardnumber) {
     my $expiry_date = $borrowerinfo->{dateexpiry};
     my $expiry = 0; # flag set if patron account has expired
     if ($expiry_date and $expiry_date ne '0000-00-00' and
-            Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
+            Date_to_Days(split (/-/,$date)) > Date_to_Days(split (/-/,$expiry_date))) {
 		$messages = $expiry = 1;
     }else{
         $expiry = 0;
@@ -251,12 +251,13 @@ my @bibitemloop;
 foreach my $biblioitemnumber (@biblioitemnumbers) {
     my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
 
+    my $num_available;
+    my $num_override;
+
     $biblioitem->{description} =
       $itemtypes->{ $biblioitem->{itemtype} }{description};
 
-    foreach
-      my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )
-    {
+    foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ){
         my $item = $iteminfos_of->{$itemnumber};
         unless (C4::Context->preference('item-level_itypes')) {
             $item->{itype} = $biblioitem->{itemtype};
@@ -273,8 +274,8 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
               $branches->{ $item->{holdingbranch} }{branchname};
         }
         
-#   add information
-    $item->{itemcallnumber} = $item->{itemcallnumber};
+        #   add information
+        $item->{itemcallnumber} = $item->{itemcallnumber};
     
         # if the item is currently on loan, we display its return date and
         # change the background color
@@ -331,31 +332,56 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
         # If there is no loan, return and transfer, we show a checkbox.
         $item->{notforloan} = $item->{notforloan} || 0;
     
-    # if independent branches is on we need to check if the person can reserve
-    # for branches they arent logged in to
-    if ( C4::Context->preference("IndependantBranches") ) { 
-        if (! C4::Context->preference("canreservefromotherbranches")){
-        # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
-        my $userenv = C4::Context->userenv; 
-        if ( ($userenv) && ( $userenv->{flags} %2 != 1 ) ) {
-            $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
-        } 
+        # if independent branches is on we need to check if the person can reserve
+        # for branches they arent logged in to
+        if ( C4::Context->preference("IndependantBranches") ) { 
+            if (! C4::Context->preference("canreservefromotherbranches")){
+                # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
+                my $userenv = C4::Context->userenv; 
+                if ( ($userenv) && ( $userenv->{flags} %2 != 1 ) ) {
+                    $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
+                } 
+            }
         }
-    }
 
-    if (IsAvailableForItemLevelRequest($itemnumber) and not $item->{cantreserve}) {
-        $item->{available} = 1;
-    }
 
-    # FIXME: move this to a pm
-    my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
-    $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
-    while (my $wait_hashref = $sth2->fetchrow_hashref) {
-        $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
-    }
+        my $branchitemrule = GetBranchItemRule( $item->{'homebranch'}, $item->{'itype'} );
+        my $policy_holdallowed = 1;
+
+        $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
+
+        if ( $branchitemrule->{'holdallowed'} == 0 ||
+                ( $branchitemrule->{'holdallowed'} == 1 && $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
+            $policy_holdallowed = 0;
+        }
+
+        if (IsAvailableForItemLevelRequest($itemnumber) and not $item->{cantreserve}) {
+            if ( not $policy_holdallowed and C4::Context->preference( 'AllowHoldPolicyOverride' ) ) {
+                $item->{override} = 1;
+                $num_override++;
+            } elsif ( $policy_holdallowed ) {
+                $item->{available} = 1;
+                $num_available++;
+            }
+        }
+        # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
+
+        # FIXME: move this to a pm
+        my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
+        $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
+        while (my $wait_hashref = $sth2->fetchrow_hashref) {
+            $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
+        }
         push @{ $biblioitem->{itemloop} }, $item;
     }
 
+    if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
+        $template->param( override_required => 1 );
+    } elsif ( $num_available == 0 ) {
+        $template->param( none_available => 1 );
+        $template->param( warnings => 1 );
+    }
+
     push @bibitemloop, $biblioitem;
 }
 
-- 
1.6.3.3




More information about the Koha-patches mailing list