From 64231ed8f327b0449cbef7354aa8dc83f81cb661 Mon Sep 17 00:00:00 2001 From: Srdjan Jankovic Date: Thu, 5 Jan 2012 14:42:18 +1300 Subject: [PATCH] bug_5786: moved AllowOnShelfHolds to circ matrix (issuingrules) --- C4/Circulation.pm | 3 +- C4/Items.pm | 2 + C4/Reserves.pm | 72 ++++++++++++++++--- C4/VirtualShelves/Page.pm | 1 - admin/smart-rules.pl | 9 ++- admin/systempreferences.pl | 1 - .../mysql/it-IT/necessari/system_preferences.sql | 1 - installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/sysprefs.sql | 1 - installer/data/mysql/updatedatabase.pl | 20 ++++++ installer/html-template-to-template-toolkit.pl | 2 +- .../en/modules/admin/preferences/circulation.pref | 6 -- .../prog/en/modules/admin/smart-rules.tt | 25 +++++-- .../prog/en/modules/help/reserve/request.tt | 2 +- .../opac-tmpl/prog/en/modules/opac-ISBDdetail.tt | 6 -- .../opac-tmpl/prog/en/modules/opac-MARCdetail.tt | 6 -- koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 12 +--- .../prog/en/modules/opac-results-grouped.tt | 6 -- .../opac-tmpl/prog/en/modules/opac-results.tt | 8 +-- .../opac-tmpl/prog/en/modules/opac-shelves.tt | 6 -- opac/opac-ISBDdetail.pl | 2 - opac/opac-MARCdetail.pl | 1 - opac/opac-detail.pl | 2 - opac/opac-reserve.pl | 2 +- opac/opac-search.pl | 2 +- 25 files changed, 115 insertions(+), 84 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9a6f4f2..df202e1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2200,7 +2200,8 @@ sub CanBookBeRenewed { LEFT JOIN biblioitems USING (biblioitemnumber) WHERE - (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*') + (issuingrules.categorycode = borrowers.categorycode + OR issuingrules.categorycode = '*') AND (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*') AND diff --git a/C4/Items.pm b/C4/Items.pm index 8802a4c..7c3a26f 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -160,6 +160,8 @@ sub GetItem { ($data->{'serialseq'} , $data->{'publisheddate'}) = $ssth->fetchrow_array(); } #if we don't have an items.itype, use biblioitems.itemtype. + # FIXME this should respect the itypes systempreference + # if (C4::Context->preference('item-level_itypes')) { if( ! $data->{'itype'} ) { my $sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); $sth->execute($data->{'biblionumber'}); diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 359bbad..5a2d819 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -479,7 +479,6 @@ sub CanItemBeReserved{ if(my $rowcount = $sthcount->fetchrow_hashref()){ $reservecount = $rowcount->{count}; } - # we check if it's ok or not if( $reservecount < $allowedreserves ){ return 1; @@ -1321,7 +1320,7 @@ sub GetReserveInfo { =head2 IsAvailableForItemLevelRequest - my $is_available = IsAvailableForItemLevelRequest($itemnumber); + my $is_available = IsAvailableForItemLevelRequest($itemnumber,$borrowernumber,$branchcode); Checks whether a given item record is available for an item-level hold request. An item is available if @@ -1331,12 +1330,8 @@ item-level hold request. An item is available if * it is not withdrawn AND * does not have a not for loan value > 0 -Whether or not the item is currently on loan is -also checked - if the AllowOnShelfHolds system preference -is ON, an item can be requested even if it is currently -on loan to somebody else. If the system preference -is OFF, an item that is currently checked out cannot -be the target of an item-level hold request. +Need to check the issuingrules onshelfholds column, +if this is set items on the shelf can be placed on hold Note that IsAvailableForItemLevelRequest() does not check if the staff operator is authorized to place @@ -1348,9 +1343,9 @@ and canreservefromotherbranches. sub IsAvailableForItemLevelRequest { my $itemnumber = shift; - + my $borrowernumber = shift; + my $branchcode = shift; my $item = GetItem($itemnumber); - # must check the notforloan setting of the itemtype # FIXME - a lot of places in the code do this # or something similar - need to be @@ -1383,14 +1378,67 @@ sub IsAvailableForItemLevelRequest { $item->{wthdrawn} or $notforloan_per_itemtype; - - if (C4::Context->preference('AllowOnShelfHolds')) { + # check issuingrules + + if (OnShelfHoldsAllowed($itemnumber,$borrowernumber,$branchcode)) { return $available_per_item; } else { return ($available_per_item and ($item->{onloan} or GetReserveStatus($itemnumber) eq "W")); } } +=head2 OnShelfHoldsAllowed + + OnShelfHoldsAllowed($itemnumber,$borrowernumber,$branchcode); + +Checks issuingrules, using the borrowers categorycode, the itemtype, and branchcode to see if onshelf +holds are allowed, returns true if so. + +=cut + +sub OnShelfHoldsAllowed { + my ($itemnumber,$borrowernumber,$branchcode) = @_; + my $item = GetItem($itemnumber); + my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); + my $itype; + my $dbh = C4::Context->dbh; + if (C4::Context->preference('item-level_itypes')) { + # We cant trust GetItem to honour the syspref, so safest to do it ourselves + # When GetItem is fixed, we can remove this + $itype = $item->{itype}; + } + else { + my $query = "SELECT itemtype FROM biblioitems WHERE biblioitemnumber = ? "; + my $sth = $dbh->prepare($query); + $sth->execute($item->{biblioitemnumber}); + if (my $data = $sth->fetchrow_hashref()){ + $itype = $data->{itemtype}; + } + } + + my $query = "SELECT onshelfholds,categorycode,itemtype,branchcode FROM issuingrules WHERE + (issuingrules.categorycode = ? OR issuingrules.categorycode = '*') + AND + (issuingrules.itemtype = ? OR issuingrules.itemtype = '*') + AND + (issuingrules.branchcode = ? OR issuingrules.branchcode = '*') + ORDER BY + issuingrules.categorycode desc, + issuingrules.itemtype desc, + issuingrules.branchcode desc + LIMIT 1"; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute($borrower->{categorycode},$itype,$branchcode); + my $data = $sth->fetchrow_hashref; + if ($data->{onshelfholds}){ + return 1; + } + else { + return 0; + } +} + =head2 AlterPriority AlterPriority( $where, $borrowernumber, $biblionumber, $reservedate ); diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 523527e..ff55dc0 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -183,7 +183,6 @@ sub shelfpage ($$$$$) { # explicitly fetch this shelf my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber); - $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); if (C4::Context->preference('TagsEnabled')) { $template->param(TagsEnabled => 1); foreach (qw(TagsShowOnList TagsInputOnList)) { diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index f290934..5bfdc7d 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -101,8 +101,8 @@ elsif ($op eq 'delete-branch-item') { # save the values entered elsif ($op eq 'add') { my $sth_search = $dbh->prepare("SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?"); - my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, reservesallowed, issuelength, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, hardduedate=?, hardduedatecompare=?, rentaldiscount=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); + my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, reservesallowed, issuelength, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod, rentaldiscount, onshelfholds) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, onshelfholds=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); my $br = $branch; # branch my $bor = $input->param('categorycode'); # borrower category @@ -114,6 +114,7 @@ elsif ($op eq 'add') { my $maxissueqty = $input->param('maxissueqty'); my $renewalsallowed = $input->param('renewalsallowed'); my $reservesallowed = $input->param('reservesallowed'); + my $onshelfholds = $input->param('onshelfholds'); $maxissueqty =~ s/\s//g; $maxissueqty = undef if $maxissueqty !~ /^\d+/; my $issuelength = $input->param('issuelength'); @@ -126,9 +127,9 @@ elsif ($op eq 'add') { $sth_search->execute($br,$bor,$cat); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$hardduedate,$hardduedatecompare,$rentaldiscount, $br,$bor,$cat); + $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$hardduedate,$hardduedatecompare,$rentaldiscount, $onshelfholds, $br,$bor,$cat); } else { - $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount); + $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount,$onshelfholds); } } elsif ($op eq "set-branch-defaults") { diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl index 78d0768..6bd68ee 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -186,7 +186,6 @@ $tabsysprefs{HomeOrHoldingBranch} = "Circulation"; $tabsysprefs{HomeOrHoldingBranchReturn} = "Circulation"; $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation"; $tabsysprefs{StaticHoldsQueueWeight} = "Circulation"; -$tabsysprefs{AllowOnShelfHolds} = "Circulation"; $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation"; $tabsysprefs{UseBranchTransferLimits} = "Circulation"; $tabsysprefs{AllowHoldPolicyOverride} = "Circulation"; diff --git a/installer/data/mysql/it-IT/necessari/system_preferences.sql b/installer/data/mysql/it-IT/necessari/system_preferences.sql index b4ddfa0..7aaa066 100644 --- a/installer/data/mysql/it-IT/necessari/system_preferences.sql +++ b/installer/data/mysql/it-IT/necessari/system_preferences.sql @@ -17,7 +17,6 @@ -- 51 Franklin Street' WHERE variable = ' Fifth Floor' WHERE variable = ' Boston' WHERE variable = ' MA 02110-1301 USA. UPDATE systempreferences SET value = 'cataloguing' WHERE variable = 'AcqCreateItem'; -UPDATE systempreferences SET value = '1' WHERE variable = 'AllowOnShelfHolds'; UPDATE systempreferences SET value = '1' WHERE variable = 'AllowRenewalLimitOverride'; UPDATE systempreferences SET value = 'annual' WHERE variable = 'autoBarcode'; UPDATE systempreferences SET value = 'email' WHERE variable = 'AutoEmailPrimaryAddress'; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 5287d9f..d608712 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -988,6 +988,7 @@ CREATE TABLE `issuingrules` ( `renewalsallowed` smallint(6) NOT NULL default "0", `reservesallowed` smallint(6) NOT NULL default "0", `branchcode` varchar(10) NOT NULL default '', + `onshelfholds` tinyint(1) NOT NULL default 0, PRIMARY KEY (`branchcode`,`categorycode`,`itemtype`), KEY `categorycode` (`categorycode`), KEY `itemtype` (`itemtype`) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 128c9b2..a1a913a 100755 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -223,7 +223,6 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on intranet','YesNo'), ('XSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on intranet','YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice'); -INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Allow hold requests to be placed on items that are not on loan', 'YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OpacSuppression', '0', '', 'Turn ON the OPAC Suppression feature, requires further setup, ask your system administrator for details', 'YesNo'); -- FIXME: add FrameworksLoaded, noOPACUserLogin? diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 67708fa..84b11d4 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4585,6 +4585,26 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion($DBversion); } +$DBversion = '3.06.03.XXX'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + # First create the column + $dbh->do("ALTER TABLE issuingrules ADD onshelfholds tinyint(1) default 0"); + # Now update the column + if (C4::Context->preference("AllowOnShelfHolds")){ + # Pref is on, set allow for all rules + $dbh->do("UPDATE issuingrules SET onshelfholds=1"); + } else { + # If the preference is not set, leave off + $dbh->do("UPDATE issuingrules SET onshelfholds=0"); + } + $dbh->do("ALTER TABLE issuingrules MODIFY onshelfholds tinyint(1) default 0 NOT NULL"); + # Remove from the systempreferences table + $dbh->do("DELETE FROM systempreferences WHERE variable = 'AllowOnShelfHolds'"); + + print "Upgrade to $DBversion done (Bug 5786 move AllowOnShelfHolds to circulation matrix)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/installer/html-template-to-template-toolkit.pl b/installer/html-template-to-template-toolkit.pl index e99b195..5f0e0ac 100755 --- a/installer/html-template-to-template-toolkit.pl +++ b/installer/html-template-to-template-toolkit.pl @@ -32,7 +32,7 @@ my @globals = ("themelang","JacketImages","OPACAmazonCoverImages","GoogleJackets "SyndeticsEnabled", "OpacRenewalAllowed", "item_level_itypes","noItemTypeImages", "virtualshelves", "RequestOnOpac", "COinSinOPACResults", "OPACXSLTResultsDisplay", "OPACItemsResultsDisplay", "LibraryThingForLibrariesID", "opacuserlogin", "TagsEnabled", -"TagsShowOnList", "TagsInputOnList","loggedinusername","AllowOnShelfHolds","opacbookbag", +"TagsShowOnList", "TagsInputOnList","loggedinusername","opacbookbag", "OPACAmazonEnabled", "SyndeticsCoverImages","using_https"); # Arguments: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index f4946b5..4cb60ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -236,12 +236,6 @@ Circulation: no: "Don't allow" - hold requests to be placed on damaged items. - - - pref: AllowOnShelfHolds - choices: - yes: Allow - no: "Don't allow" - - hold requests to be placed on items that are not checked out. - - - pref: AllowHoldDateInFuture choices: yes: Allow diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index d2f314f..e38e446 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -80,7 +80,8 @@ for="tobranch">Clone these rules to: Clone these rules to: Delete @@ -175,6 +183,7 @@ for="tobranch">Clone these rules to: + Yes No diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/reserve/request.tt index 3d7381b..a5a5cd0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/reserve/request.tt @@ -72,4 +72,4 @@

See the full documentation for Holds in the manual (online).

-[% INCLUDE 'help-bottom.inc' %] \ No newline at end of file +[% INCLUDE 'help-bottom.inc' %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-ISBDdetail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-ISBDdetail.tt index f9984a7..d04e7b1 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-ISBDdetail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-ISBDdetail.tt @@ -51,13 +51,7 @@ [% UNLESS ( norequests ) %] [% IF ( opacuserlogin ) %] [% IF ( RequestOnOpac ) %] - [% IF ( AllowOnShelfHolds ) %]
  • Place Hold
  • - [% ELSE %] - [% IF ( ItemsIssued ) %] -
  • Place Hold
  • - [% END %] - [% END %] [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-MARCdetail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-MARCdetail.tt index 284154e..200c0ed 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-MARCdetail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-MARCdetail.tt @@ -206,13 +206,7 @@ $(document).ready(function(){ [% UNLESS ( norequests ) %] [% IF ( opacuserlogin ) %] [% IF ( RequestOnOpac ) %] - [% IF ( AllowOnShelfHolds ) %]
  • Place Hold
  • - [% ELSE %] - [% IF ( ItemsIssued ) %] -
  • Place Hold
  • - [% END %] - [% END %] [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index d1b6570..fb367ca 100755 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -1016,16 +1016,10 @@ YAHOO.util.Event.onContentReady("furtherm", function () {