Bug 27526: Remove ModItemFromMarc from additem
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
075c8a96b3
commit
96826fd2d0
3 changed files with 65 additions and 38 deletions
|
@ -2086,7 +2086,7 @@ sub TransformHtmlToXml {
|
|||
|
||||
my $xml = MARC::File::XML::header('UTF-8');
|
||||
$xml .= "<record>\n";
|
||||
$auth_type = C4::Context->preference('marcflavour') unless $auth_type;
|
||||
$auth_type = C4::Context->preference('marcflavour') unless $auth_type; # FIXME auth_type must be removed
|
||||
MARC::File::XML->default_record_format($auth_type);
|
||||
|
||||
# in UNIMARC, field 100 contains the encoding
|
||||
|
|
|
@ -127,6 +127,7 @@ sub generate_subfield_form {
|
|||
$subfield_data{repeatable} = $subfieldlib->{repeatable};
|
||||
$subfield_data{maxlength} = $subfieldlib->{maxlength};
|
||||
$subfield_data{display_order} = $subfieldlib->{display_order};
|
||||
$subfield_data{kohafield} = $subfieldlib->{kohafield} || 'items.more_subfields_xml';
|
||||
|
||||
if ( ! defined( $value ) || $value eq '') {
|
||||
$value = $subfieldlib->{defaultvalue};
|
||||
|
@ -741,33 +742,49 @@ if ($op eq "additem") {
|
|||
#-------------------------------------------------------------------------------
|
||||
} elsif ($op eq "saveitem") {
|
||||
#-------------------------------------------------------------------------------
|
||||
# rebuild
|
||||
my @tags = $input->multi_param('tag');
|
||||
my @subfields = $input->multi_param('subfield');
|
||||
my @values = $input->multi_param('field_value');
|
||||
# build indicator hash.
|
||||
my @ind_tag = $input->multi_param('ind_tag');
|
||||
my @indicator = $input->multi_param('indicator');
|
||||
# my $itemnumber = $input->param('itemnumber');
|
||||
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM');
|
||||
my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
|
||||
# MARC::Record builded => now, record in DB
|
||||
# warn "R: ".$record->as_formatted;
|
||||
# check that the barcode don't exist already
|
||||
my $addedolditem = TransformMarcToKoha($itemtosave);
|
||||
my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
|
||||
if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
|
||||
push @errors,"barcode_not_unique";
|
||||
} else {
|
||||
my $item = Koha::Items->find($itemnumber );
|
||||
my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber);
|
||||
$itemnumber = q{};
|
||||
my $olditemlost = $item->itemlost;
|
||||
my $newitemlost = $newitem->{itemlost};
|
||||
if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
|
||||
LostItem( $item->itemnumber, 'additem' )
|
||||
|
||||
my $itemnumber = $input->param('itemnumber');
|
||||
my $item = Koha::Items->find($itemnumber);
|
||||
# FIXME Handle non existent item
|
||||
my $olditemlost = $item->itemlost;
|
||||
my @columns = Koha::Items->columns;
|
||||
for my $c ( @columns ) {
|
||||
if ( $c eq 'more_subfields_xml' ) {
|
||||
my @more_subfields_xml = $input->multi_param("items.more_subfields_xml");
|
||||
my @unlinked_item_subfields;
|
||||
for my $subfield ( @more_subfields_xml ) {
|
||||
my $v = $input->param('items.more_subfields_xml_' . $subfield);
|
||||
push @unlinked_item_subfields, $subfield, $v;
|
||||
}
|
||||
if ( @unlinked_item_subfields ) {
|
||||
my $marc = MARC::Record->new();
|
||||
# use of tag 999 is arbitrary, and doesn't need to match the item tag
|
||||
# used in the framework
|
||||
$marc->append_fields(MARC::Field->new('999', ' ', ' ', @unlinked_item_subfields));
|
||||
$marc->encoding("UTF-8");
|
||||
$item->more_subfields_xml($marc->as_xml("USMARC"));
|
||||
next;
|
||||
}
|
||||
$item->more_subfields_xml(undef);
|
||||
} else {
|
||||
my $v = $input->param("items.".$c);
|
||||
next unless defined $v;
|
||||
$item->$c($v);
|
||||
}
|
||||
}
|
||||
|
||||
# check that the barcode don't exist already
|
||||
if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) {
|
||||
# FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
|
||||
push @errors,"barcode_not_unique";
|
||||
} else {
|
||||
my $newitemlost = $item->itemlost;
|
||||
if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
|
||||
LostItem( $item->itemnumber, 'additem' );
|
||||
}
|
||||
$item->store;
|
||||
}
|
||||
|
||||
$nextop="additem";
|
||||
} elsif ($op eq "delinkitem"){
|
||||
|
||||
|
|
|
@ -160,6 +160,13 @@
|
|||
<fieldset class="rows">
|
||||
<ol>
|
||||
[% FOREACH ite IN item %]
|
||||
|
||||
[% IF ite.kohafield == 'items.more_subfields_xml' %]
|
||||
[% SET kohafield = 'items.more_subfields_xml_' _ ite.subfield %]
|
||||
[% ELSE %]
|
||||
[% SET kohafield = ite.kohafield %]
|
||||
[% END %]
|
||||
|
||||
<li><div class="subfield_line" style="[% ite.visibility | html %]" id="subfield[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]">
|
||||
[% IF ( ite.mandatory ) %]
|
||||
<label class="required">[% ite.subfield | html %] - [% ite.marc_lib | $raw %]</label>
|
||||
|
@ -169,12 +176,12 @@
|
|||
|
||||
[% SET mv = ite.marc_value %]
|
||||
[% IF ( mv.type == 'hidden' ) %]
|
||||
<input type="hidden" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
|
||||
<input type="hidden" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
|
||||
[% ELSIF ( mv.type == 'select' ) %]
|
||||
[% IF ( mv.readonly || ite.IS_RETURN_CLAIM ) %]
|
||||
<select name="field_value" id="[%- mv.id | html -%]" class="input_marceditor" readonly="readonly" disabled="disabled" data-width="50%">
|
||||
<select name="[% kohafield %]" id="[%- mv.id | html -%]" class="input_marceditor" readonly="readonly" disabled="disabled" data-width="50%">
|
||||
[% ELSE %]
|
||||
<select name="field_value" id="[%- mv.id | html -%]" class="input_marceditor" data-category="[% mv.category | html %]" data-width="50%">
|
||||
<select name="[% kohafield %]" id="[%- mv.id | html -%]" class="input_marceditor" data-category="[% mv.category | html %]" data-width="50%">
|
||||
[% END %]
|
||||
[% FOREACH aval IN mv.values %]
|
||||
[% IF aval == mv.default %]
|
||||
|
@ -190,17 +197,17 @@
|
|||
</select>
|
||||
[% ELSIF ( mv.type == 'text_auth' ) %]
|
||||
[% IF mv.readonly %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
|
||||
[% ELSE %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
[% SET dopop = "Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=\"${mv.authtypecode}\"&index=${mv.id}','${mv.id}')" %]
|
||||
<a href="#" class="buttonDot" onclick="[%- dopop | html -%]; return false;" title="Tag editor">...</a>
|
||||
[% END %]
|
||||
[% ELSIF ( mv.type == 'text_plugin' ) %]
|
||||
[% IF mv.readonly %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
|
||||
[% ELSE %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
[% IF ( mv.nopopup ) %]
|
||||
<a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="No popup">...</a>
|
||||
[% ELSE %]
|
||||
|
@ -210,18 +217,21 @@
|
|||
[% END %]
|
||||
[% ELSIF ( mv.type == 'text' ) %]
|
||||
[% IF mv.readonly %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
|
||||
[% ELSE %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
[% END %]
|
||||
[% ELSIF ( mv.type == 'textarea' ) %]
|
||||
[% IF mv.readonly %]
|
||||
<textarea id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" rows="5" cols="64" readonly="readonly" >[% mv.value | html %]</textarea>
|
||||
<textarea id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" rows="5" cols="64" readonly="readonly" >[% mv.value | html %]</textarea>
|
||||
[% ELSE %]
|
||||
<textarea id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" rows="5" cols="64" >[% mv.value | html %]</textarea>
|
||||
<textarea id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" rows="5" cols="64" >[% mv.value | html %]</textarea>
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
||||
[% IF ite.kohafield == 'items.more_subfields_xml' %]
|
||||
<input type="hidden" name="items.more_subfields_xml" value="[% ite.subfield %]" />
|
||||
[% END %]
|
||||
<input type="hidden" name="tag" value="[% ite.tag | html %]" />
|
||||
<input type="hidden" name="subfield" value="[% ite.subfield | html %]" />
|
||||
<input type="hidden" name="mandatory" value="[% ite.mandatory | html %]" />
|
||||
|
@ -265,7 +275,7 @@
|
|||
[% ELSE %]
|
||||
<input type="hidden" name="tag" value="[% itemtagfield | html %]" />
|
||||
<input type="hidden" name="subfield" value="[% itemtagsubfield | html %]" />
|
||||
<input type="hidden" name="field_value" value="[% itemnumber | html %]" />
|
||||
<input type="hidden" name="itemnumber" value="[% itemnumber | html %]" />
|
||||
<input type="submit" value="Save changes" onclick="return Check(this.form)">
|
||||
<input type="button" id="addnewitem" value="Add a new item">
|
||||
<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">Cancel</a>
|
||||
|
|
Loading…
Reference in a new issue