From 65abb5124e7fe00bac13f79dfaa785fc78821300 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 30 Nov 2009 16:37:01 +0100 Subject: [PATCH] (bug #3819) hold policies implementation This still backports updatedatabase from head, update kohastructure, and fix smart-rules.tmpl/.pl. --- admin/smart-rules.pl | 31 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 16 ++++++++++ installer/data/mysql/updatedatabase30.pl | 28 ++++++++++++++++- .../prog/en/modules/admin/smart-rules.tmpl | 1 + 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 2dd1878168..2be5364eb9 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -365,7 +365,38 @@ foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); } +my $sth_branch_item; +if ($branch eq "*") { + $sth_branch_item = $dbh->prepare(" + SELECT default_branch_item_rules.*, itemtypes.description AS humanitemtype + FROM default_branch_item_rules + JOIN itemtypes USING (itemtype) + "); + $sth_branch_item->execute(); +} else { + $sth_branch_item = $dbh->prepare(" + SELECT branch_item_rules.*, itemtypes.description AS humanitemtype + FROM branch_item_rules + JOIN itemtypes USING (itemtype) + WHERE branch_item_rules.branchcode = ? + "); + $sth_branch_item->execute($branch); +} + +my @branch_item_rules = (); +while (my $row = $sth_branch_item->fetchrow_hashref) { + push @branch_item_rules, $row; +} +my @sorted_branch_item_rules = sort { $a->{'humanitemtype'} cmp $b->{'humanitemtype'} } @branch_item_rules; + +# note undef holdallowed so that template can deal with them +foreach my $entry (@sorted_branch_item_rules) { + $entry->{holdallowed_any} = 1 if($entry->{holdallowed} == 2); + $entry->{holdallowed_same} = 1 if($entry->{holdallowed} == 1); +} + $template->param(show_branch_cat_rule_form => 1); +$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); $template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); $template->param(categoryloop => \@category_loop, diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 8e45a96c88..c2826e10c8 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -672,6 +672,7 @@ DROP TABLE IF EXISTS `default_branch_circ_rules`; CREATE TABLE `default_branch_circ_rules` ( `branchcode` VARCHAR(10) NOT NULL, `maxissueqty` int(4) default NULL, + `holdallowed` int(1) default NULL, PRIMARY KEY (`branchcode`), CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE @@ -689,6 +690,20 @@ CREATE TABLE `default_branch_item_rules` ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- +-- Table structure for table `branch_item_rules` +-- + +CREATE TABLE `branch_item_rules` ( + `branchcode` varchar(10) NOT NULL, + `itemtype` varchar(10) NOT NULL, + `holdallowed` tinyint(1) default NULL, + PRIMARY KEY (`itemtype`,`branchcode`), + KEY `branch_item_rules_ibfk_2` (`branchcode`), + CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + -- -- Table structure for table `default_circ_rules` -- @@ -697,6 +712,7 @@ DROP TABLE IF EXISTS `default_circ_rules`; CREATE TABLE `default_circ_rules` ( `singleton` enum('singleton') NOT NULL default 'singleton', `maxissueqty` int(4) default NULL, + `holdallowed` int(1) default NULL, PRIMARY KEY (`singleton`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase30.pl b/installer/data/mysql/updatedatabase30.pl index 83d3062fbe..941153ec4a 100644 --- a/installer/data/mysql/updatedatabase30.pl +++ b/installer/data/mysql/updatedatabase30.pl @@ -632,7 +632,7 @@ OPACISBDEN SetVersion ($DBversion); } -$DBversion = "3.00.04.021"; +$DBversion = "3.00.05.001"; if (C4::Context->preference("Version") < TransformToNum($DBversion)) { $dbh->do(<preference("Version") < TransformToNum($DBversion)) { DEFAULTBRANCHRULES } +$DBversion = "3.00.05.001"; +#$DBversion = "3.01.00.012"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')"); + $dbh->do(" + CREATE TABLE `branch_item_rules` ( + `branchcode` varchar(10) NOT NULL, + `itemtype` varchar(10) NOT NULL, + `holdallowed` tinyint(1) default NULL, + PRIMARY KEY (`itemtype`,`branchcode`), + KEY `branch_item_rules_ibfk_2` (`branchcode`), + CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + "); + $dbh->do(" + ALTER TABLE default_branch_circ_rules + ADD COLUMN holdallowed tinyint(1) NULL + "); + $dbh->do(" + ALTER TABLE default_circ_rules + ADD COLUMN holdallowed tinyint(1) NULL + "); + print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n"; + SetVersion ($DBversion); +} =item DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl index 0badb0c3ed..c5e6edc35b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl @@ -255,6 +255,7 @@ $(document).ready(function() {