@@ -, +, @@ 1) Apply patch 2) Run updatedatabase.pl 3) Map a nonrepeatable field/subfield to biblio.branchcode ( e.g. 951$o ) Pro-tip: Use the authorised value 'branches_optional' to get a pulldown of libraries instead of entering the branchcode manually. 4) Edit a record, and add a branchcode. 5) Log in as a non-superlibrarian with cataloging priveleges 6) Change the logged in branch to a branch other than the one you entered in the record. 7) You should note the 'edit' pulldown for the record is missing the "Edit record" and "Delete record" options. 8) Switch the logged in branch to match the branchcode of the record. 9) You should now see the edit and delete options for that record. able to. --- C4/Auth.pm | 1 + C4/Biblio.pm | 21 ++++++++--- Koha/Template/Plugin/Koha.pm | 8 ++++- admin/marc_subfields_structure.pl | 1 + catalogue/detail.pl | 2 + cataloguing/addbiblio.pl | 23 +++++++++++- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 36 ++++++++++++++++++- .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 21 +++++++++--- .../prog/en/modules/admin/preferences/admin.pref | 9 ++++- .../prog/en/modules/catalogue/results.tt | 3 +- 11 files changed, 109 insertions(+), 18 deletions(-) --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -186,6 +186,7 @@ sub get_template_and_user { # to create the template's parameters that will indicate # which menus the user can access. if ( $flags && $flags->{superlibrarian}==1 ) { + $template->param( CAN_user_superlibrarian => 1 ); $template->param( CAN_user_circulate => 1 ); $template->param( CAN_user_catalogue => 1 ); $template->param( CAN_user_parameters => 1 ); --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -2955,12 +2955,16 @@ sub _koha_add_biblio { seriestitle = ?, copyrightdate = ?, datecreated=NOW(), - abstract = ? + abstract = ?, + branchcode = ? "; my $sth = $dbh->prepare($query); $sth->execute( - $frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, - $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'} + $frameworkcode, $biblio->{'author'}, + $biblio->{'title'}, $biblio->{'unititle'}, + $biblio->{'notes'}, $biblio->{'serial'}, + $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, + $biblio->{'abstract'}, $biblio->{'branchcode'}, ); my $biblionumber = $dbh->{'mysql_insertid'}; @@ -2997,15 +3001,20 @@ sub _koha_modify_biblio { serial = ?, seriestitle = ?, copyrightdate = ?, - abstract = ? + abstract = ?, + branchcode = ? WHERE biblionumber = ? " ; my $sth = $dbh->prepare($query); $sth->execute( - $frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, - $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}, $biblio->{'biblionumber'} + $frameworkcode, $biblio->{'author'}, + $biblio->{'title'}, $biblio->{'unititle'}, + $biblio->{'notes'}, $biblio->{'serial'}, + $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, + $biblio->{'abstract'}, $biblio->{'branchcode'}, + $biblio->{'biblionumber'} ) if $biblio->{'biblionumber'}; if ( $dbh->errstr || !$biblio->{'biblionumber'} ) { --- a/Koha/Template/Plugin/Koha.pm +++ a/Koha/Template/Plugin/Koha.pm @@ -22,7 +22,7 @@ use Modern::Perl; use base qw( Template::Plugin ); use C4::Context; - +use C4::Branch qw( GetIndependentGroupModificationRights ); =pod This plugin contains various Koha replated Template Toolkit functions @@ -44,4 +44,10 @@ sub Preference { return C4::Context->preference( $pref ); } +sub HasIndependentGroupModificationRightsFor { + my ( $self, $branchcode ) = @_; + my $value = GetIndependentGroupModificationRights( { for => $branchcode } ); + return $value; +} + 1; --- a/admin/marc_subfields_structure.pl +++ a/admin/marc_subfields_structure.pl @@ -133,6 +133,7 @@ if ( $op eq 'add_form' ) { push @authorised_values, $category; } push( @authorised_values, "branches" ); + push( @authorised_values, "branches_optional" ); push( @authorised_values, "itemtypes" ); push( @authorised_values, "cn_source" ); --- a/catalogue/detail.pl +++ a/catalogue/detail.pl @@ -62,6 +62,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $biblionumber = $query->param('biblionumber'); my $record = GetMarcBiblio($biblionumber); +$template->param( biblio => GetBiblio( $biblionumber ) ); + if ( not defined $record ) { # biblionumber invalid -> report and exit $template->param( unknownbiblionumber => 1, --- a/cataloguing/addbiblio.pl +++ a/cataloguing/addbiblio.pl @@ -170,7 +170,7 @@ sub build_authorized_values_list { # builds list, depending on authorised value... #---- branch - if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { + if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} =~ /branches|branches_optional/ ) { #Use GetBranches($onlymine) my $onlymine = C4::Context->preference('IndependentBranches') @@ -183,7 +183,7 @@ sub build_authorized_values_list { push @authorised_values, $thisbranch; $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'}; } - + push( @authorised_values, q{} ) if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq 'branches_optional' ); #----- itemtypes } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { @@ -806,6 +806,25 @@ if ($breedingid) { ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ; } +if ( $record != -1 + && C4::Context->preference('IndependentBranchesMarcEditing') ) +{ + my ( $field, $subfield ) = + GetMarcFromKohaField( 'biblio.branchcode', $frameworkcode ); + if ( + defined( $record->field($field) ) + && defined( $record->subfield( $field, $subfield ) ) + && !GetIndependentGroupModificationRights( + { for => $record->subfield( $field, $subfield ) } + ) + ) + { + print $input->redirect( + "/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber"); + exit; + } +} + #populate hostfield if hostbiblionumber is available if ($hostbiblionumber) { my $marcflavour = C4::Context->preference("marcflavour"); --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -126,6 +126,7 @@ CREATE TABLE `biblio` ( -- table that stores bibliographic information `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched `datecreated` DATE NOT NULL, -- the date this record was added to Koha `abstract` mediumtext, -- summary from the MARC record (520$a in MARC21) + `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- branchcode for the opationl 'owner' of this record. PRIMARY KEY (`biblionumber`), KEY `blbnoidx` (`biblionumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -715,6 +716,7 @@ CREATE TABLE `deletedbiblio` ( -- stores information about bibliographic records `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched `datecreated` DATE NOT NULL, -- the date this record was added to Koha `abstract` mediumtext, -- summary from the MARC record (520$a in MARC21) + `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- branchcode for the opationl 'owner' of this record. PRIMARY KEY (`biblionumber`), KEY `blbnoidx` (`biblionumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -6800,6 +6800,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { ADD KEY `branchcode_idx` (`branchcode`), ADD KEY `issuingbranch_idx` (`issuingbranch`) }); + #items $dbh->do(q{ ALTER TABLE `items` ADD KEY `itype_idx` (`itype`) @@ -6832,6 +6833,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion($DBversion); } +<<<<<<< HEAD $DBversion = "3.12.00.000"; if ( CheckVersion($DBversion) ) { print "Upgrade to $DBversion done (3.12.0 release)\n"; @@ -7004,7 +7006,7 @@ if ( CheckVersion($DBversion) ) { $DBversion = "3.13.00.XXX"; if ( CheckVersion($DBversion) ) { - $dbh->do(" + $dbh->do(q{ INSERT INTO systempreferences ( variable, value, @@ -7018,11 +7020,41 @@ if ( CheckVersion($DBversion) ) { 'If on, the staff interface search will hide all records that do not contain an item owned by the logged in branch, and hide the items themselves.', 'YesNo' ) - "); + }); print "Upgrade to $DBversion done (Bug 10278 - Add ability to hide items and records from search results for Independent Branches)\n"; SetVersion ($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + INSERT INTO systempreferences ( + variable, + value, + options, + explanation, + type + ) VALUES ( + 'IndependentBranchesMarcEditing', + '0', + '', + "If on, this preference disallows the editing of a bibliographic record unless the logged in library's branchcode matchs the branchcode stored in biblio.branchcode.", + 'YesNo' + ) + }); + + $dbh->do(q{ + ALTER TABLE biblio ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL + }); + + $dbh->do(q{ + ALTER TABLE deletedbiblio ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL + }); + + print "Upgrade to $DBversion done (Bug 10263 - Add ability to limit which branch can edit a bibliographic record)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -1,3 +1,5 @@ +[% USE Koha %] +