[Patches] [PATCH] Bug 7263 - Determine maximum length of some fields or subfields when cataloguing a biblio or an item.
koha-patchbot at kohaaloha.com
koha-patchbot at kohaaloha.com
Wed Dec 21 03:12:45 NZDT 2011
From: Juan Romay Sieira <juan.sieira at xercode.es>
Date: Mon, 19 Dec 2011 10:32:08 +0100
Subject: [PATCH] Bug 7263 - Determine maximum length of some fields or subfields when cataloguing a biblio or an item.
Content-Type: text/plain; charset="utf-8"
---
C4/Biblio.pm | 7 ++++-
admin/marc_subfields_structure.pl | 11 ++++++--
cataloguing/addbiblio.pl | 25 +++++++------------
cataloguing/additem.pl | 3 +-
installer/data/mysql/kohastructure.sql | 1 +
installer/data/mysql/updatedatabase.pl | 16 ++++++++++++
.../en/modules/admin/marc_subfields_structure.tt | 3 +-
.../modules/help/admin/marc_subfields_structure.tt | 10 ++++++++
8 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index ac78ae3..d213584 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -958,7 +958,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
@@ -977,10 +977,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
) {
@@ -997,6 +999,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 2c69733..f837644 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 71d43d7..26fa98c 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}."\"
\/>
<span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot\"
onclick=\"openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'".$tagslib->{$tag}->{$subfield}->{authtypecode}."'); return false;\" tabindex=\"1\" title=\"Tag Editor\"><img src=\"/intranet-tmpl/prog/img/edit-tag.png\" alt=\"Tag Editor\" /></a></span>
@@ -404,7 +397,7 @@ sub create_input {
class=\"input_marceditor readonly\"
tabindex=\"1\"
size=\"67\"
- maxlength=\"$max_length\"
+ maxlength=\"".$subfield_data{maxlength}."\"
readonly=\"readonly\"
\/><span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot\"
onclick=\"openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'".$tagslib->{$tag}->{$subfield}->{authtypecode}."'); return false;\" tabindex=\"1\" title=\"Tag Editor\"><img src=\"/intranet-tmpl/prog/img/edit-tag.png\" alt=\"Tag Editor\" /></a></span>
@@ -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); \" \/>
<span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" tabindex=\"1\" title=\"Tag Editor\"><img src=\"/intranet-tmpl/prog/img/edit-tag.png\" alt=\"Tag Editor\" /></a></span>
$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\" \/>
";
}
@@ -475,7 +468,7 @@ sub create_input {
class=\"input_marceditor\"
tabindex=\"1\"
size=\"67\"
- maxlength=\"$max_length\"
+ maxlength=\"".$subfield_data{maxlength}."\"
value=\"$value\"
\/>";
@@ -510,7 +503,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 70ca4a9..16803b1 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -119,6 +119,7 @@ sub generate_subfield_form {
$subfield_data{marc_lib} ="<span id=\"error$i\" title=\"".$subfieldlib->{lib}."\">".$subfieldlib->{lib}."</span>";
$subfield_data{mandatory} = $subfieldlib->{mandatory};
$subfield_data{repeatable} = $subfieldlib->{repeatable};
+ $subfield_data{maxlength} = $subfieldlib->{maxlength};
$value =~ s/"/"/g;
if ( ! defined( $value ) || $value eq '') {
@@ -149,7 +150,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 a03bd23..9323e05 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1197,6 +1197,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 0063a75..55772ea 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4578,6 +4578,22 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
SetVersion($DBversion);
}
+$DBversion = "3.06.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=40 WHERE tagfield='008';
+ ");
+ 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 18c1db3..8ea6640 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
@@ -108,7 +108,8 @@
<legend>Advanced constraints:</legend>
<ol><li><label for="defaultvalue[% loo.row %]">Default value:</label>
<input type="text" name="defaultvalue" id="defaultvalue[% loo.row %]" value="[% loo.defaultvalue %]" /></li>
- <li><label for="hidden[% loo.row %]">hidden</label><input type="text" id="hidden[% loo.row %]" name="hidden" value="[% loo.hidden %]" size="2" /> (see online help)</li>
+ <li><label for="maxlength[% loo.row %]">Max length:</label><input type="text" id="maxlength[% loo.row %]" name="maxlength" value="[% loo.maxlength %]" size="4" /> (see online help)</li>
+ <li><label for="hidden[% loo.row %]">hidden</label><input type="text" id="hidden[% loo.row %]" name="hidden" value="[% loo.hidden %]" size="2" /> (see online help)</li>
<li><label for="isurl[% loo.row %]">Is a url:</label>[% loo.isurl %] (if checked, it means that the subfield is a url and can be clicked)</li>
<li><label for="link[% loo.row %]">Link:</label><input type="text" id="link[% loo.row %]" name="link" value="[% loo.link %]" size="10" maxlength="80" /> (e.g., Title or Local-Number) <span class="error"><em>NOTE: If you change this value you must ask your administrator to run misc/batchRebuildBiblioTables.pl.</em></span></li>
<li><label for="kohafield[% loo.row %]">Koha link:</label>[% loo.kohafield %]</li>
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 2a8801c..c9b6567 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,15 @@ To edit the subfields associated with the tag, click 'Subfields' to the right of
</ul>
</li>
</ul>
+
+<ul>
+ <li>Max length
+<ul>
+ <li>Define the max characters to fill.</li>
+</ul>
+</li>
+</ul>
+
<ul>
<li>Is a url
<ul>
@@ -90,6 +99,7 @@ To edit the subfields associated with the tag, click 'Subfields' to the right of
</ul>
</li>
</ul>
+
<ul>
<li>Link
<ul>
--
1.7.1
More information about the Patches
mailing list