partial work for repetable fields.
Near each field is a + If you click on it, it's duplicated. TODO : * cc the + to each tab (for instance, only in tab 0) * doing the french template * fixing an annoying bug : everything is stored in the same field : 200$a$b$c$a$b$c and not 200$a$b$c 200$a$b$c as expected.
This commit is contained in:
parent
94ac73b0d3
commit
28b099f89e
2 changed files with 155 additions and 82 deletions
|
@ -31,6 +31,7 @@ use HTML::Template;
|
||||||
use MARC::File::USMARC;
|
use MARC::File::USMARC;
|
||||||
|
|
||||||
use vars qw( $tagslib);
|
use vars qw( $tagslib);
|
||||||
|
use vars qw( $authorised_values_sth);
|
||||||
use vars qw( $is_a_modif );
|
use vars qw( $is_a_modif );
|
||||||
|
|
||||||
=item find_value
|
=item find_value
|
||||||
|
@ -154,66 +155,12 @@ sub build_authorized_values_list ($$$$$) {
|
||||||
-multiple => 0 );
|
-multiple => 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub build_tabs ($$$$) {
|
=item create_input
|
||||||
my($template, $record, $dbh,$encoding) = @_;
|
builds the <input ...> entry for a subfield.
|
||||||
|
=cut
|
||||||
# fill arrays
|
sub create_input () {
|
||||||
my @loop_data =();
|
my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth) = @_;
|
||||||
my $tag;
|
my $dbh = C4::Context->dbh;
|
||||||
my $i=0;
|
|
||||||
my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
|
|
||||||
from authorised_values
|
|
||||||
where category=? order by authorised_value");
|
|
||||||
|
|
||||||
# loop through each tab 0 through 9
|
|
||||||
for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
|
|
||||||
# my @fields = $record->fields();
|
|
||||||
my @loop_data = ();
|
|
||||||
foreach my $tag (sort(keys (%{$tagslib}))) {
|
|
||||||
my $previous_tag = '';
|
|
||||||
my @subfields_data;
|
|
||||||
my $indicator;
|
|
||||||
|
|
||||||
# loop through each subfield
|
|
||||||
foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
|
|
||||||
next if subfield_is_koha_internal_p($subfield);
|
|
||||||
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
|
|
||||||
# if breeding is not empty
|
|
||||||
if ($record ne -1) {
|
|
||||||
my ($x,@value) = find_value($tag,$subfield,$record,$encoding);
|
|
||||||
push (@value,"") if ($#value eq -1);
|
|
||||||
foreach my $value (@value) {
|
|
||||||
my %subfield_data;
|
|
||||||
$subfield_data{tag}=$tag;
|
|
||||||
$subfield_data{subfield}=$subfield;
|
|
||||||
$subfield_data{marc_lib}="<DIV id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</div>";
|
|
||||||
$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};
|
|
||||||
$value=char_decode($value) unless ($is_a_modif);
|
|
||||||
$indicator = $x if $x; #XXX
|
|
||||||
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
|
|
||||||
$subfield_data{marc_value}= build_authorized_values_list($tag, $subfield, $value, $dbh, $authorised_values_sth);
|
|
||||||
} elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
|
|
||||||
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=47 maxlength=255> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>"; #"
|
|
||||||
} elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
|
|
||||||
my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
|
|
||||||
require $plugin;
|
|
||||||
my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,$tabloop);
|
|
||||||
my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,$tabloop);
|
|
||||||
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=47 maxlength=255 OnFocus=\"javascript:Focus$function_name($i)\" OnBlur=\"javascript:Blur$function_name($i)\"> <a href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
|
|
||||||
} else {
|
|
||||||
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
|
|
||||||
}
|
|
||||||
push(@subfields_data, \%subfield_data);
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
# if breeding is empty
|
|
||||||
} else {
|
|
||||||
my ($x,$value);
|
|
||||||
($x,$value) = find_value($tag,$subfield,$record,$encoding) if ($record ne -1);
|
|
||||||
# $value=char_decode($value) unless ($is_a_modif);
|
|
||||||
my %subfield_data;
|
my %subfield_data;
|
||||||
$subfield_data{tag}=$tag;
|
$subfield_data{tag}=$tag;
|
||||||
$subfield_data{subfield}=$subfield;
|
$subfield_data{subfield}=$subfield;
|
||||||
|
@ -229,16 +176,62 @@ sub build_tabs ($$$$) {
|
||||||
} elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
|
} elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
|
||||||
my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
|
my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
|
||||||
require $plugin;
|
require $plugin;
|
||||||
my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,$tabloop);
|
my $extended_param = plugin_parameters($dbh,$rec,$tagslib,$i,$tabloop);
|
||||||
my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,$tabloop);
|
my ($function_name,$javascript) = plugin_javascript($dbh,$rec,$tagslib,$i,$tabloop);
|
||||||
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY size=47 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 type=\"text\" name=\"field_value\" value=\"$value\" DISABLE READONLY size=47 maxlength=255 OnFocus=\"javascript:Focus$function_name($i)\" OnBlur=\"javascript:Blur$function_name($i)\"> <a href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
|
||||||
} else {
|
} else {
|
||||||
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" size=50 maxlength=255>";
|
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>"; #"
|
||||||
}
|
}
|
||||||
push(@subfields_data, \%subfield_data);
|
return \%subfield_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub build_tabs ($$$$) {
|
||||||
|
my($template, $record, $dbh,$encoding) = @_;
|
||||||
|
|
||||||
|
# fill arrays
|
||||||
|
my @loop_data =();
|
||||||
|
my $tag;
|
||||||
|
my $i=0;
|
||||||
|
my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
|
||||||
|
from authorised_values
|
||||||
|
where category=? order by authorised_value");
|
||||||
|
|
||||||
|
# loop through each tab 0 through 9
|
||||||
|
for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
|
||||||
|
my @loop_data = ();
|
||||||
|
foreach my $tag (sort(keys (%{$tagslib}))) {
|
||||||
|
my $previous_tag = '';
|
||||||
|
my $indicator;
|
||||||
|
# if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab.
|
||||||
|
# if MARC::Record is empty => use tab as master loop.
|
||||||
|
if ($record ne -1) {
|
||||||
|
my @fields = $record->field($tag);
|
||||||
|
foreach my $field (@fields) {
|
||||||
|
my @subfields_data;
|
||||||
|
if ($tag<10) {
|
||||||
|
my $value=$field->data();
|
||||||
|
my $subfield="@";
|
||||||
|
push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
|
||||||
|
$i++;
|
||||||
|
} else {
|
||||||
|
my @subfields=$field->subfields();
|
||||||
|
foreach my $subfieldcount (0..$#subfields) {
|
||||||
|
my $subfield=$subfields[$subfieldcount][0];
|
||||||
|
my $value=$subfields[$subfieldcount][1];
|
||||||
|
next if subfield_is_koha_internal_p($subfield);
|
||||||
|
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
|
||||||
|
push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# now, loop again to add parameter subfield that are not in the MARC::Record
|
||||||
|
foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
|
||||||
|
next if subfield_is_koha_internal_p($subfield);
|
||||||
|
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
|
||||||
|
next if (defined($record->field($tag)->subfield($subfield)));
|
||||||
|
push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
if ($#subfields_data >= 0) {
|
if ($#subfields_data >= 0) {
|
||||||
my %tag_data;
|
my %tag_data;
|
||||||
$tag_data{tag} = $tag;
|
$tag_data{tag} = $tag;
|
||||||
|
@ -248,6 +241,25 @@ sub build_tabs ($$$$) {
|
||||||
push (@loop_data, \%tag_data);
|
push (@loop_data, \%tag_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# if breeding is empty
|
||||||
|
} else {
|
||||||
|
my @subfields_data;
|
||||||
|
foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
|
||||||
|
next if subfield_is_koha_internal_p($subfield);
|
||||||
|
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
|
||||||
|
push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
if ($#subfields_data >= 0) {
|
||||||
|
my %tag_data;
|
||||||
|
$tag_data{tag} = $tag;
|
||||||
|
$tag_data{tag_lib} = $tagslib->{$tag}->{lib};
|
||||||
|
$tag_data{indicator} = $indicator;
|
||||||
|
$tag_data{subfield_loop} = \@subfields_data;
|
||||||
|
push (@loop_data, \%tag_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$template->param($tabloop."XX" =>\@loop_data);
|
$template->param($tabloop."XX" =>\@loop_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,6 +359,61 @@ if ($op eq "addbiblio") {
|
||||||
print $input->redirect("additem.pl?bibid=$bibid");
|
print $input->redirect("additem.pl?bibid=$bibid");
|
||||||
exit;
|
exit;
|
||||||
#------------------------------------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
} elsif ($op eq "addfield") {
|
||||||
|
#------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
my $addedfield = $input->param('addfield_field');
|
||||||
|
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');
|
||||||
|
splice(@tags,$addedfield,0,$tags[$addedfield]);
|
||||||
|
splice(@subfields,$addedfield,0,$subfields[$addedfield]);
|
||||||
|
splice(@values,$addedfield,0,$values[$addedfield]);
|
||||||
|
splice(@ind_tag,$addedfield,0,$ind_tag[$addedfield]);
|
||||||
|
my %indicators;
|
||||||
|
for (my $i=0;$i<=$#ind_tag;$i++) {
|
||||||
|
$indicators{$ind_tag[$i]} = $indicator[$i];
|
||||||
|
}
|
||||||
|
# search the part of the array to duplicate.
|
||||||
|
my $start=0;
|
||||||
|
my $end=0;
|
||||||
|
my $started;
|
||||||
|
for (my $i=0;$i<=$#tags;$i++) {
|
||||||
|
$start=$i if ($start eq 0 && $tags[$i] == $addedfield);
|
||||||
|
$end=$i if ($start>0 && $tags[$i] eq $addedfield);
|
||||||
|
last if ($start>0 && $tags[$i] ne $addedfield);
|
||||||
|
}
|
||||||
|
# add an empty line in all arrays. This forces a new field in MARC::Record.
|
||||||
|
splice(@tags,$end+1,0,'');
|
||||||
|
splice(@subfields,$end+1,0,'');
|
||||||
|
splice(@values,$end+1,0,'');
|
||||||
|
splice(@ind_tag,$end+1,0,'');
|
||||||
|
splice(@indicator,$end+1,0,'');
|
||||||
|
# then duplicate the field.
|
||||||
|
splice(@tags,$end+2,0,@tags[$start..$end]);
|
||||||
|
splice(@subfields,$end+2,0,@subfields[$start..$end]);
|
||||||
|
splice(@values,$end+2,0,@values[$start..$end]);
|
||||||
|
splice(@ind_tag,$end+2,0,@ind_tag[$start..$end]);
|
||||||
|
splice(@indicator,$end+2,0,@indicator[$start..$end]);
|
||||||
|
|
||||||
|
my %indicators;
|
||||||
|
for (my $i=0;$i<=$#ind_tag;$i++) {
|
||||||
|
$indicators{$ind_tag[$i]} = $indicator[$i];
|
||||||
|
}
|
||||||
|
my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
|
||||||
|
build_tabs ($template, $record, $dbh,$encoding);
|
||||||
|
build_hidden_data;
|
||||||
|
$template->param(
|
||||||
|
oldbiblionumber => $oldbiblionumber,
|
||||||
|
bibid => $bibid,
|
||||||
|
oldbiblionumtagfield => $oldbiblionumtagfield,
|
||||||
|
oldbiblionumtagsubfield => $oldbiblionumtagsubfield,
|
||||||
|
oldbiblioitemnumtagfield => $oldbiblioitemnumtagfield,
|
||||||
|
oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield,
|
||||||
|
oldbiblioitemnumber => $oldbiblioitemnumber );
|
||||||
|
#------------------------------------------------------------------------------------------------------------------------------
|
||||||
} else {
|
} else {
|
||||||
#------------------------------------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------------------------------------
|
||||||
build_tabs ($template, $record, $dbh,$encoding);
|
build_tabs ($template, $record, $dbh,$encoding);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
font-size:10pt;}
|
font-size:10pt;}
|
||||||
</STYLE-->
|
</STYLE-->
|
||||||
|
|
||||||
<form method="post" name="f">
|
<form method="post" name="f_add">
|
||||||
<table width=100% cellspacing=0 cellpadding=5 border=1>
|
<table width=100% cellspacing=0 cellpadding=5 border=1>
|
||||||
<tr background="<TMPL_VAR name="themelang">/images/background-mem.gif">
|
<tr background="<TMPL_VAR name="themelang">/images/background-mem.gif">
|
||||||
<th>MARC biblio : <TMPL_VAR name="bibid"></th>
|
<th>MARC biblio : <TMPL_VAR name="bibid"></th>
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
<td width=9% align="center"><a href="javascript:active(8)"><div id="link8">8</div></a></td>
|
<td width=9% align="center"><a href="javascript:active(8)"><div id="link8">8</div></a></td>
|
||||||
<td width=9% align="center"><a href="javascript:active(9)"><div id="link9">9</div></a></td>
|
<td width=9% align="center"><a href="javascript:active(9)"><div id="link9">9</div></a></td>
|
||||||
<td width=10% align="center"><input type="hidden" name="op" value="addbiblio">
|
<td width=10% align="center"><input type="hidden" name="op" value="addbiblio">
|
||||||
|
<input type="hidden" name="addfield_field">
|
||||||
<input type="hidden" name="oldbiblionumber" value="<TMPL_VAR name="oldbiblionumber">">
|
<input type="hidden" name="oldbiblionumber" value="<TMPL_VAR name="oldbiblionumber">">
|
||||||
<input type="button" value="Add biblio" onClick='Check(this.form)' accesskey="w">
|
<input type="button" value="Add biblio" onClick='Check(this.form)' accesskey="w">
|
||||||
<a href="javascript:PopupZ3950()">z3950 search</a>
|
<a href="javascript:PopupZ3950()">z3950 search</a>
|
||||||
|
@ -39,7 +40,7 @@
|
||||||
<DIV name="0XX" id="0XX" style="position:absolute;visibility:visible;width:90%">
|
<DIV name="0XX" id="0XX" style="position:absolute;visibility:visible;width:90%">
|
||||||
<table width=100% cellspacing=0 cellpadding=2 border=0>
|
<table width=100% cellspacing=0 cellpadding=2 border=0>
|
||||||
<TMPL_LOOP name="0XX">
|
<TMPL_LOOP name="0XX">
|
||||||
<tr background="<TMPL_VAR name="themelang">/images/background-mem.gif"><td colspan=4><b><TMPL_VAR name="tag"> <input type="hidden" name="ind_tag" value="<TMPL_VAR name="tag">"><input type="text" name="indicator" size=3 maxlength=2 value="<TMPL_VAR name="indicator">"> - <tmpl_var name="tag_lib"></td></tr>
|
<tr background="<TMPL_VAR name="themelang">/images/background-mem.gif"><td colspan=4><b><TMPL_VAR name="tag"> <input type="hidden" name="ind_tag" value="<TMPL_VAR name="tag">"><input type="text" name="indicator" size=3 maxlength=2 value="<TMPL_VAR name="indicator">"> - <tmpl_var name="tag_lib"> <a href="javascript:AddField(<TMPL_VAR name="tag">)">+</a></td></tr>
|
||||||
<TMPL_LOOP name="subfield_loop">
|
<TMPL_LOOP name="subfield_loop">
|
||||||
<tr>
|
<tr>
|
||||||
<td width="3%"> </td>
|
<td width="3%"> </td>
|
||||||
|
@ -369,7 +370,7 @@ function Check(f) {
|
||||||
alertString2 += "- "+ total_missing_mandatory_subfields +" mandatory fields empty (see bold subfields)";
|
alertString2 += "- "+ total_missing_mandatory_subfields +" mandatory fields empty (see bold subfields)";
|
||||||
alert(alertString2);
|
alert(alertString2);
|
||||||
} else {
|
} else {
|
||||||
document.f.submit();
|
document.forms[0].submit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function Dopop(link,i) {
|
function Dopop(link,i) {
|
||||||
|
@ -396,6 +397,11 @@ function PopupZ3950(link,i) {
|
||||||
newin=window.open("../z3950/search.pl?bibid=<TMPL_VAR name="bibid">"+strQuery,"z3950 search",'width=500,height=400,toolbar=false,scrollbars=yes');
|
newin=window.open("../z3950/search.pl?bibid=<TMPL_VAR name="bibid">"+strQuery,"z3950 search",'width=500,height=400,toolbar=false,scrollbars=yes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AddField(field) {
|
||||||
|
document.forms[0].op.value = "addfield";
|
||||||
|
document.forms[0].addfield_field.value=field;
|
||||||
|
document.f_add.submit();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue