From 020c095377971fe70550ef07383bb9092f967946 Mon Sep 17 00:00:00 2001 From: Juan Romay Sieira Date: Tue, 20 Mar 2012 16:17:27 +0100 Subject: [PATCH] Bug 7263 - Determine maximum length of some fields or subfields when cataloguing a biblio or an item. Signed-off-by: Henri-Damien LAURENT Signed-off-by: Paul Poulain --- C4/Biblio.pm | 7 ++++-- admin/marc_subfields_structure.pl | 11 ++++++--- cataloguing/addbiblio.pl | 23 +++++++------------ cataloguing/additem.pl | 3 ++- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 18 +++++++++++++++ .../modules/admin/marc_subfields_structure.tt | 1 + .../help/admin/marc_subfields_structure.tt | 7 ++++++ 8 files changed, 50 insertions(+), 21 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 54db228e94..579ebcf3c3 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1081,7 +1081,7 @@ sub GetMarcStructure { } $sth = $dbh->prepare( - "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue + "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue,maxlength FROM marc_subfield_structure WHERE frameworkcode=? ORDER BY tagfield,tagsubfield @@ -1100,10 +1100,12 @@ sub GetMarcStructure { my $isurl; my $link; my $defaultvalue; + my $maxlength; while ( ( $tag, $subfield, $liblibrarian, $libopac, $tab, $mandatory, $repeatable, $authorised_value, - $authtypecode, $value_builder, $kohafield, $seealso, $hidden, $isurl, $link, $defaultvalue + $authtypecode, $value_builder, $kohafield, $seealso, $hidden, $isurl, $link, $defaultvalue, + $maxlength ) = $sth->fetchrow ) { @@ -1120,6 +1122,7 @@ sub GetMarcStructure { $res->{$tag}->{$subfield}->{isurl} = $isurl; $res->{$tag}->{$subfield}->{'link'} = $link; $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue; + $res->{$tag}->{$subfield}->{maxlength} = $maxlength; } $marc_structure_cache->{$forlibrarian}->{$frameworkcode} = $res; diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index 2c69733318..f8376441bf 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -179,6 +179,7 @@ if ( $op eq 'add_form' ) { while ( $data = $sth->fetchrow_hashref ) { my %row_data; # get a fresh hash for the row data $row_data{defaultvalue} = $data->{defaultvalue}; + $row_data{maxlength} = $data->{maxlength}; $row_data{tab} = CGI::scrolling_list( -name => 'tab', -id => "tab$i", @@ -386,11 +387,11 @@ elsif ( $op eq 'add_validate' ) { # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" # ); my $sth_insert = $dbh->prepare(qq{ - insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue) - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue,maxlength) + values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) }); my $sth_update = $dbh->prepare(qq{ - update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=? + update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?, maxlength=? where tagfield=? and tagsubfield=? and frameworkcode=? }); my @tagsubfield = $input->param('tagsubfield'); @@ -405,6 +406,7 @@ elsif ( $op eq 'add_validate' ) { my @value_builder = $input->param('value_builder'); my @link = $input->param('link'); my @defaultvalue = $input->param('defaultvalue'); + my @maxlength = $input->param('maxlength'); for ( my $i = 0 ; $i <= $#tagsubfield ; $i++ ) { my $tagfield = $input->param('tagfield'); @@ -425,6 +427,7 @@ elsif ( $op eq 'add_validate' ) { my $isurl = $input->param("isurl$i") ? 1 : 0; my $link = $link[$i]; my $defaultvalue = $defaultvalue[$i]; + my $maxlength = $maxlength[$i]; if (defined($liblibrarian) && $liblibrarian ne "") { unless ( C4::Context->config('demo') eq 1 ) { @@ -447,6 +450,7 @@ elsif ( $op eq 'add_validate' ) { $frameworkcode, $link, $defaultvalue, + $maxlength, ( $tagfield, $tagsubfield, @@ -472,6 +476,7 @@ elsif ( $op eq 'add_validate' ) { $frameworkcode, $link, $defaultvalue, + $maxlength, ); } } diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 8e4defd9ba..d5778a4a59 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -293,14 +293,6 @@ sub create_input { $value =~ s/"/"/g; - # determine maximum length; 9999 bytes per ISO 2709 except for leader and MARC21 008 - my $max_length = 9999; - if ($tag eq '000') { - $max_length = 24; - } elsif ($tag eq '008' and C4::Context->preference('marcflavour') eq 'MARC21') { - $max_length = 40; - } - # if there is no value provided but a default value in parameters, get it if ( $value eq '' ) { $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; @@ -335,6 +327,7 @@ sub create_input { index => $index_tag, id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield, value => $value, + maxlength => $tagslib->{$tag}->{$subfield}->{maxlength}, random => CreateKey(), ); @@ -374,7 +367,7 @@ sub create_input { class=\"input_marceditor readonly\" tabindex=\"1\" size=\"5\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" readonly=\"readonly\" \/>"; @@ -390,7 +383,7 @@ sub create_input { class=\"input_marceditor readonly\" tabindex=\"1\" size=\"67\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" \/> {$tag}->{$subfield}->{authtypecode}."'); return false;\" tabindex=\"1\" title=\"Tag Editor\">\"Tag @@ -404,7 +397,7 @@ sub create_input { class=\"input_marceditor readonly\" tabindex=\"1\" size=\"67\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" readonly=\"readonly\" \/>{$tag}->{$subfield}->{authtypecode}."'); return false;\" tabindex=\"1\" title=\"Tag Editor\">\"Tag @@ -435,7 +428,7 @@ sub create_input { class=\"input_marceditor\" onfocus=\"Focus$function_name($index_tag)\" size=\"67\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" onblur=\"Blur$function_name($index_tag); \" \/> \"Tag $javascript"; @@ -449,7 +442,7 @@ sub create_input { value=\"$value\" tabindex=\"1\" size=\"67\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" class=\"input_marceditor\" \/> "; @@ -463,7 +456,7 @@ sub create_input { id=\"".$subfield_data{id}."\" name=\"".$subfield_data{id}."\" size=\"67\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" value=\"$value\" \/> "; } @@ -497,7 +490,7 @@ sub create_input { value=\"$value\" tabindex=\"1\" size=\"67\" - maxlength=\"$max_length\" + maxlength=\"".$subfield_data{maxlength}."\" class=\"input_marceditor\" \/> "; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 695181be26..91dc9e7781 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -120,6 +120,7 @@ sub generate_subfield_form { $subfield_data{marc_lib} ="{lib}."\">".$subfieldlib->{lib}.""; $subfield_data{mandatory} = $subfieldlib->{mandatory}; $subfield_data{repeatable} = $subfieldlib->{repeatable}; + $subfield_data{maxlength} = $subfieldlib->{maxlength}; $value =~ s/"/"/g; if ( ! defined( $value ) || $value eq '') { @@ -150,7 +151,7 @@ sub generate_subfield_form { my $input = new CGI; $value = $input->param('barcode'); } - my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" ); + my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="$subfield_data{maxlength}" ); my $attributes = qq($attributes_no_value value="$value" ); if ( $subfieldlib->{authorised_value} ) { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 77423d17a2..a3535766b4 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1207,6 +1207,7 @@ CREATE TABLE `marc_subfield_structure` ( `seealso` varchar(1100) default NULL, `link` varchar(80) default NULL, `defaultvalue` text default NULL, + `maxlength` int(4) NOT NULL DEFAULT '9999', PRIMARY KEY (`frameworkcode`,`tagfield`,`tagsubfield`), KEY `kohafield_2` (`kohafield`), KEY `tab` (`frameworkcode`,`tab`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index d7532720b9..76d7016521 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5036,6 +5036,24 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(" + ALTER TABLE `marc_subfield_structure` ADD `maxlength` INT( 4 ) NOT NULL DEFAULT '9999'; + "); + $dbh->do(" + UPDATE `marc_subfield_structure` SET maxlength=24 WHERE tagfield='000'; + "); + $dbh->do(" + UPDATE marc_subfield_structure SET maxlength = IF ((SELECT value FROM systempreferences WHERE variable = 'marcflavour')='MARC21','40','9999') WHERE tagfield='008'; + "); + $dbh->do(" + UPDATE marc_subfield_structure SET maxlength = IF ((SELECT value FROM systempreferences WHERE variable = 'marcflavour')='UNIMARC','36','9999') WHERE tagfield='100'; + "); + print "Upgrade to $DBversion done (Add new field maxlength to marc_subfield_structure)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt index f85a5bdb86..71c83b9981 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt @@ -110,6 +110,7 @@ $(document).ready(function() { Advanced constraints:
  1. +
  2. (see online help)
  3. (see online help)
  4. [% loo.isurl %] (if checked, it means that the subfield is a url and can be clicked)
  5. (e.g., Title or Local-Number) NOTE: If you change this value you must ask your administrator to run misc/batchRebuildBiblioTables.pl.
  6. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/marc_subfields_structure.tt index 2a8801c105..0fba909290 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/marc_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/marc_subfields_structure.tt @@ -83,6 +83,13 @@ To edit the subfields associated with the tag, click 'Subfields' to the right of +
      +
    • Max length +
        +
      • Define the max characters to fill.
      • +
      +
    • +
    • Is a url
        -- 2.39.5