From c0ad1303a823eb739fd4d0fb4883a3ed966ff074 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Nu=C3=B1o=20L=C3=B3pez=20Ans=C3=B3tegui?= Date: Thu, 6 Jun 2013 12:04:07 +0200 Subject: [PATCH] Bug 9921 - Make it possible to force 001 = biblionumber --- C4/Biblio.pm | 21 +++++ cataloguing/value_builder/marc21_field_001.pl | 90 ++++++++++++++++++++ installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 16 ++++ .../en/modules/admin/preferences/cataloguing.pref | 12 +++ 5 files changed, 141 insertions(+), 0 deletions(-) create mode 100755 cataloguing/value_builder/marc21_field_001.pl diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 7af8619..7bb0be7 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -271,6 +271,27 @@ sub AddBiblio { # update MARC subfield that stores biblioitems.cn_sort _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); + # update the control number (001) in MARC + if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){ + unless($record->field('001')){ + $record->insert_fields_ordered(MARC::Field->new('001', $biblionumber)); + }elsif($record->field('001')->data() eq 'biblionumber'){ + $record->field('001')->update($biblionumber); + } + }elsif(C4::Context->preference('autoControlNumber') eq 'incremental'){ + my $incrementalCN=C4::Context->preference('incrementalControlNumber'); + unless($record->field('001')){ + $record->insert_fields_ordered(MARC::Field->new('001', $incrementalCN)); + }elsif($record->field('001')->data() eq 'incremental'){ + $record->field('001')->update($incrementalCN); + } + if($record->field('001')->data() eq $incrementalCN){ + my $sth = $dbh->prepare(q{UPDATE systempreferences SET value = ? WHERE variable = 'incrementalControlNumber'}); + $sth->execute(int($record->field('001')->data())+1); + $sth->finish(); + } + } + # now add the record ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save; diff --git a/cataloguing/value_builder/marc21_field_001.pl b/cataloguing/value_builder/marc21_field_001.pl new file mode 100755 index 0000000..244e3a2 --- /dev/null +++ b/cataloguing/value_builder/marc21_field_001.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl + + +# Copyright 2013 MASmedios for information management +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +#use warnings; FIXME - Bug 2505 +use C4::Context; + +=head1 + +plugin_parameters : other parameters added when the plugin is called by the dopop function + +=cut + +sub plugin_parameters { + # my ($dbh,$record,$tagslib,$i,$tabloop) = @_; + return ""; +} + +=head1 + +plugin_javascript : the javascript function called when the user enters the subfield. +contain 3 javascript functions : +* one called when the field is entered (OnFocus). Named FocusXXX +* one called when the field is leaved (onBlur). Named BlurXXX +* one called when the ... link is clicked () named ClicXXX + +returns : +* XXX +* a variable containing the 3 scripts. +the 3 scripts are inserted after the in the html code + +=cut + +sub plugin_javascript { + my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; + my $function_name= $field_number; + my $res; + my $autoControlNumber = C4::Context->preference('autoControlNumber'); + unless($autoControlNumber eq 'OFF'){ + my $control_number = $autoControlNumber; + $res = " + +"; + } + return ($function_name,$res); +} + +=head1 + +plugin : the true value_builded. The screen that is open in the popup window. + +=cut + +sub plugin { + return ""; +} + +1; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 31485bc..93ce358 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -427,3 +427,5 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo'); INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowHoldNotes',0,'Show hold notes on OPAC','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo'); +INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('autoControlNumber','OFF','incremental|biblionumber|OFF','Used to autogenerate a Control Number: incremental will be of the form 1, 2, 3; biblionumber will be as biblionumber;','Choice'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('incrementalControlNumber', '1', 'Set the number (controlnumber) of the next bibliographic record.',NULL,''); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f3a90d8..a137e83 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6983,6 +6983,22 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ( SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do( + q{ +INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('autoControlNumber','OFF','incremental|biblionumber|OFF','Used to autogenerate a Control Number: incremental will be of the form 1, 2, 3; biblionumber will be as biblionumber;','Choice'); +} + ); + $dbh->do( + q{ +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('incrementalControlNumber', '1', 'Set the number (controlnumber) of the next bibliographic record.',NULL,''); +} + ); + print +"Upgrade to $DBversion done (Bug 9921 - Make it possible to force 001 = biblionumber)\n"; + SetVersion($DBversion); +} =head1 FUNCTIONS diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index 96f3603..9da274c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -109,6 +109,18 @@ Cataloging: - pref: UNIMARCField100Language class: short - as default language in the UNIMARC field 100 when creating a new record or in the field plugin. + - + - Control Number (001) is + - pref: autoControlNumber + choices: + biblionumber: generated as biblionumber. + incremental: generated in the form 1, 2, 3. + "OFF": not generated automatically. + - + - Use Control Number (001) + - pref: incrementalControlNumber + class: integer + - as incremental number. This requires incremental option on autoControlNumber. Display: - - 'Separate multiple displayed authors, series or subjects with ' -- 1.5.6.5