syncing with rel_2_2, adding visibility handling

This commit is contained in:
kados 2006-04-02 19:12:01 +00:00
parent ea32a21f7f
commit 6c633aca55

View file

@ -31,6 +31,7 @@ use C4::Log;
use C4::Koha; # XXX subfield_is_koha_internal_p
use HTML::Template;
use MARC::File::USMARC;
use MARC::File::XML;
use vars qw( $tagslib);
use vars qw( $authorised_values_sth);
@ -169,17 +170,19 @@ sub create_input () {
$subfield_data{tag}=$tag;
$subfield_data{subfield}=$subfield;
$subfield_data{marc_lib}="<span id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
$subfield_data{marc_lib_plain}=$tagslib->{$tag}->{$subfield}->{lib};
$subfield_data{tag_mandatory}=$tagslib->{$tag}->{mandatory};
$subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
$subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
$subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{kohafield};
$subfield_data{index} = $i;
$subfield_data{visibility} = "display:none" unless (($tagslib->{$tag}->{$subfield}->{hidden}%2==0) or $value ne ''); #check parity
# it's an authorised field
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
$subfield_data{marc_value}= build_authorized_values_list($tag, $subfield, $value, $dbh,$authorised_values_sth);
# it's a thesaurus / authority field
} elsif ($tagslib->{$tag}->{$subfield}->{authtypecode}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"67\" maxlength=\"255\" DISABLE READONLY /> <a href=\"javascript:Dopop('../authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$i',$i)\">...</a>";
$subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00;'\"\" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" maxlength=\"255\" DISABLE READONLY> <a style=\"cursor: help;\" href=\"javascript:Dopop('../authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$i',$i)\">...</a>";
# it's a plugin field
} elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
# opening plugin. Just check wether we are on a developper computer on a production one
@ -192,18 +195,18 @@ sub create_input () {
require $plugin;
my $extended_param = plugin_parameters($dbh,$rec,$tagslib,$i,$tabloop);
my ($function_name,$javascript) = plugin_javascript($dbh,$rec,$tagslib,$i,$tabloop);
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"67\" maxlength=\"255\" OnFocus=\"javascript:Focus$function_name($i)\" OnBlur=\"javascript:Blur$function_name($i)\" /> <a href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
$subfield_data{marc_value}="<input tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" maxlength=\"255\" OnFocus=\"javascript:Focus$function_name($i)\" OnBlur=\"javascript:Blur$function_name($i); \"> <a style=\"cursor: help;\" href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
# it's an hidden field
} elsif ($tag eq '') {
$subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value\" value=\"$value\" />";
$subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"hidden\" name=\"field_value\" value=\"$value\">";
} elsif ($tagslib->{$tag}->{$subfield}->{'hidden'}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" maxlength=\"255\" DISABLE READONLY />";
$subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" maxlength=\"255\" >";
# it's a standard field
} else {
if (length($value) >100) {
$subfield_data{marc_value}="<textarea name=\"field_value\" cols=\"70\" rows=\"5\" >$value</textarea>";
} else {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" />"; #"
$subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\">"; #"
}
}
return \%subfield_data;
@ -264,6 +267,7 @@ sub build_tabs ($$$$) {
next if (length $subfield !=1);
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
next if ($tag<10);
next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-4) or ($tagslib->{$tag}->{$subfield}->{hidden}>=5) ); #check for visibility flag
next if (defined($field->subfield($subfield)));
push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
$i++;
@ -275,6 +279,10 @@ sub build_tabs ($$$$) {
$tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
$tag_data{indicator} = $record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if ($tag>=10);
$tag_data{subfield_loop} = \@subfields_data;
if ($tag<10) {
$tag_data{fixedfield} = 1;
}
push (@loop_data, \%tag_data);
}
# If there is more than 1 field, add an empty hidden field as separator.
@ -286,6 +294,9 @@ sub build_tabs ($$$$) {
$tag_data{tag_lib} = '';
$tag_data{indicator} = '';
$tag_data{subfield_loop} = \@subfields_data;
if ($tag<10) {
$tag_data{fixedfield} = 1;
}
push (@loop_data, \%tag_data);
$i++;
}
@ -295,6 +306,7 @@ sub build_tabs ($$$$) {
my @subfields_data;
foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
next if (length $subfield !=1);
next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-5) or ($tagslib->{$tag}->{$subfield}->{hidden}>=4) ); #check for visibility flag
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
$i++;
@ -306,6 +318,10 @@ sub build_tabs ($$$$) {
$tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
$tag_data{indicator} = $indicator;
$tag_data{subfield_loop} = \@subfields_data;
$tag_data{tagfirstsubfield} = $tag_data{subfield_loop}[0];
if ($tag<10) {
$tag_data{fixedfield} = 1;
}
push (@loop_data, \%tag_data);
}
}
@ -460,16 +476,16 @@ if ($op eq "addbiblio") {
} elsif ($op eq "addfield") {
#------------------------------------------------------------------------------------------------------------------------------
my $addedfield = $input->param('addfield_field');
my $tagaddfield_subfield = $input->param('addfield_subfield');
my @tags = $input->param('tag');
my @subfields = $input->param('subfield');
my @values = $input->param('field_value');
# build indicator hash.
my @ind_tag = $input->param('ind_tag');
my @indicator = $input->param('indicator');
my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
# adding an empty field
my $field = MARC::Field->new("$addedfield",'','','a'=> "");
my $field = MARC::Field->new("$addedfield",'','','$tagaddfield_subfield' => "");
$record->append_fields($field);
build_tabs ($template, $record, $dbh,$encoding);
build_hidden_data;
@ -499,9 +515,9 @@ if ($op eq "addbiblio") {
}
#FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
eval {
my $uxml = $record->as_xml;
my $urecord = MARC::Record::new_from_xml($uxml, 'UTF-8');
$record = $urecord;
my $uxml = $record->as_xml;
my $urecord = MARC::Record::new_from_xml($uxml, 'UTF-8');
$record = $urecord;
};
build_tabs ($template, $record, $dbh,$encoding);
build_hidden_data;