@@ -, +, @@ --- C4/Koha.pm | 32 +++++++++++++++++--------------- course_reserves/add_items.pl | 2 +- course_reserves/mod_course.pl | 6 +----- installer/data/mysql/kohastructure.sql | 25 +++++++++++++++++++++++-- installer/data/mysql/updatedatabase.pl | 23 +++++++++++++++++++++-- 5 files changed, 63 insertions(+), 25 deletions(-) --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -41,7 +41,6 @@ BEGIN { &subfield_is_koha_internal_p &GetPrinters &GetPrinter &GetItemTypes &getitemtypeinfo - &GetItemTypesFlat &GetCcodes &GetSupportName &GetSupportList &get_itemtypeinfos_of @@ -205,10 +204,15 @@ sub GetSupportList{ } =head2 GetItemTypes - $itemtypes = &GetItemTypes(); + $itemtypes = &GetItemTypes( style => $style ); Returns information about existing itemtypes. +Params: + style: either 'array' or 'hash', defaults to 'hash'. + 'array' returns an arrayref, + 'hash' return a hashref with the itemtype value as the key + build a HTML select with the following code : =head3 in PERL SCRIPT @@ -241,7 +245,9 @@ build a HTML select with the following code : =cut sub GetItemTypes { - + my ( %params ) = @_; + my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash'; + # returns a reference to a hash of references to itemtypes... my %itemtypes; my $dbh = C4::Context->dbh; @@ -251,19 +257,15 @@ sub GetItemTypes { |; my $sth = $dbh->prepare($query); $sth->execute; - while ( my $IT = $sth->fetchrow_hashref ) { - $itemtypes{ $IT->{'itemtype'} } = $IT; + + if ( $style eq 'hash' ) { + while ( my $IT = $sth->fetchrow_hashref ) { + $itemtypes{ $IT->{'itemtype'} } = $IT; + } + return ( \%itemtypes ); + } else { + return $sth->fetchall_arrayref({}); } - return ( \%itemtypes ); -} - -sub GetItemTypesFlat { - my $dbh = C4::Context->dbh; - my $query = "SELECT * FROM itemtypes ORDER BY description"; - my $sth = $dbh->prepare($query); - $sth->execute; - - return $sth->fetchall_arrayref({}); } sub get_itemtypeinfos_of { --- a/course_reserves/add_items.pl +++ a/course_reserves/add_items.pl @@ -72,7 +72,7 @@ if ( $action eq 'lookup' ) { ccodes => GetAuthorisedValues('CCODE'), locations => GetAuthorisedValues('LOC'), - itypes => GetItemTypesFlat(), + itypes => GetItemTypes( style => 'array' ), branches => GetBranchesLoop(), ); --- a/course_reserves/mod_course.pl +++ a/course_reserves/mod_course.pl @@ -1,10 +1,6 @@ #!/usr/bin/perl -#script to modify reserves/requests -#written 2/1/00 by chris@katipo.oc.nz -#last update 27/1/2000 by chris@katipo.co.nz - -# Copyright 2000-2002 Katipo Communications +# Copyright 2012 ByWater Solutions # # This file is part of Koha. # --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -505,6 +505,13 @@ CREATE TABLE `course_instructors` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- +-- Constraints for table `course_instructors` +-- +ALTER TABLE `course_instructors` + ADD CONSTRAINT `course_instructors_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`), + ADD CONSTRAINT `course_instructors_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- -- Table structure for table `course_items` -- @@ -523,10 +530,18 @@ CREATE TABLE `course_items` ( `enabled` enum('yes','no') NOT NULL DEFAULT 'no', -- If at least one enabled course has this item on reseve, this field will be 'yes', otherwise it will be 'no' `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`ci_id`), - UNIQUE KEY `itemnumber` (`itemnumber`) + UNIQUE KEY `itemnumber` (`itemnumber`), + KEY `holdingbranch` (`holdingbranch`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- +-- Constraints for table `course_items` +-- +ALTER TABLE `course_items` + ADD CONSTRAINT `course_items_ibfk_2` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `course_items_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- -- Table structure for table `course_reserves` -- @@ -542,11 +557,17 @@ CREATE TABLE `course_reserves` ( `public_note` mediumtext, -- Public, OPAC visible note `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`cr_id`), - UNIQUE KEY `psuedo_key` (`course_id`,`ci_id`), + UNIQUE KEY `pseudo_key` (`course_id`,`ci_id`), KEY `course_id` (`course_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- +-- Constraints for table `course_reserves` +-- +ALTER TABLE `course_reserves` + ADD CONSTRAINT `course_reserves_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`); + +-- -- Table structure for table `borrower_branch_circ_rules` -- --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -5728,6 +5728,12 @@ CREATE TABLE `course_instructors` ( "); $dbh->do(" +ALTER TABLE `course_instructors` + ADD CONSTRAINT `course_instructors_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`), + ADD CONSTRAINT `course_instructors_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE; +"); + +$dbh->do(" CREATE TABLE `course_items` ( `ci_id` int(11) NOT NULL AUTO_INCREMENT, `itemnumber` int(11) NOT NULL, @@ -5738,11 +5744,18 @@ CREATE TABLE `course_items` ( `enabled` enum('yes','no') NOT NULL DEFAULT 'no', `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`ci_id`), - UNIQUE KEY `itemnumber` (`itemnumber`) + UNIQUE KEY `itemnumber` (`itemnumber`), + KEY `holdingbranch` (`holdingbranch`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; "); $dbh->do(" +ALTER TABLE `course_items` + ADD CONSTRAINT `course_items_ibfk_2` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `course_items_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE; +"); + +$dbh->do(" CREATE TABLE `course_reserves` ( `cr_id` int(11) NOT NULL AUTO_INCREMENT, `course_id` int(11) NOT NULL, @@ -5751,12 +5764,17 @@ CREATE TABLE `course_reserves` ( `public_note` mediumtext, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`cr_id`), - UNIQUE KEY `psuedo_key` (`course_id`,`ci_id`), + UNIQUE KEY `pseudo_key` (`course_id`,`ci_id`), KEY `course_id` (`course_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; "); $dbh->do(" +ALTER TABLE `course_reserves` + ADD CONSTRAINT `course_reserves_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`); +"); + +$dbh->do(" INSERT INTO permissions (module_bit, code, description) VALUES (18, 'manage_courses', 'Add, edit and delete courses'), (18, 'add_reserves', 'Add course reserves'), @@ -5764,6 +5782,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES ; "); + print "Upgrade to $DBversion done (Add Course Reserves ( system preference UseCourseReserves ))\n"; SetVersion($DBversion); } --