bug 2505: enable strict and warnings in ILS-DI code
[koha_ffzg] / cataloguing / additem.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use CGI;
22 use strict;
23 use C4::Auth;
24 use C4::Output;
25 use C4::Biblio;
26 use C4::Items;
27 use C4::Context;
28 use C4::Koha; # XXX subfield_is_koha_internal_p
29 use C4::Branch; # XXX subfield_is_koha_internal_p
30 use C4::ClassSource;
31 use C4::Dates;
32
33 use MARC::File::XML;
34
35 sub find_value {
36     my ($tagfield,$insubfield,$record) = @_;
37     my $result;
38     my $indicator;
39     foreach my $field ($record->field($tagfield)) {
40         my @subfields = $field->subfields();
41         foreach my $subfield (@subfields) {
42             if (@$subfield[0] eq $insubfield) {
43                 $result .= @$subfield[1];
44                 $indicator = $field->indicator(1).$field->indicator(2);
45             }
46         }
47     }
48     return($indicator,$result);
49 }
50
51 sub get_item_from_barcode {
52     my ($barcode)=@_;
53     my $dbh=C4::Context->dbh;
54     my $result;
55     my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?");
56     $rq->execute($barcode);
57     ($result)=$rq->fetchrow;
58     return($result);
59 }
60
61 sub set_item_default_location {
62     my $itemnumber = shift;
63     if ( C4::Context->preference('NewItemsDefaultLocation') ) {
64         my $item = GetItem( $itemnumber );
65         $item->{'permanent_location'} = $item->{'location'};
66         $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation');
67         ModItem( $item, undef, $itemnumber);
68     }
69 }
70
71 my $input = new CGI;
72 my $dbh = C4::Context->dbh;
73 my $error        = $input->param('error');
74 my $biblionumber = $input->param('biblionumber');
75 my $itemnumber   = $input->param('itemnumber');
76 my $op           = $input->param('op');
77
78 my ($template, $loggedinuser, $cookie)
79     = get_template_and_user({template_name => "cataloguing/additem.tmpl",
80                  query => $input,
81                  type => "intranet",
82                  authnotrequired => 0,
83                  flagsrequired => {editcatalogue => 1},
84                  debug => 1,
85                  });
86
87 my $frameworkcode = &GetFrameworkCode($biblionumber);
88
89 my $today_iso = C4::Dates->today('iso');
90 $template->param(today_iso => $today_iso);
91
92 my $tagslib = &GetMarcStructure(1,$frameworkcode);
93 my $record = GetMarcBiblio($biblionumber);
94 my $oldrecord = TransformMarcToKoha($dbh,$record);
95 my $itemrecord;
96 my $nextop="additem";
97 my @errors; # store errors found while checking data BEFORE saving item.
98 #-------------------------------------------------------------------------------
99 if ($op eq "additem") {
100 #-------------------------------------------------------------------------------
101     # rebuild
102     my @tags      = $input->param('tag');
103     my @subfields = $input->param('subfield');
104     my @values    = $input->param('field_value');
105     # build indicator hash.
106     my @ind_tag   = $input->param('ind_tag');
107     my @indicator = $input->param('indicator');
108     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
109     my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
110
111     # type of add
112     my $add_submit                 = $input->param('add_submit');
113     my $add_duplicate_submit       = $input->param('add_duplicate_submit');
114     my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
115     my $number_of_copies           = $input->param('number_of_copies');
116
117     # if autoBarcode is set to 'incremental', calculate barcode...
118         # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
119         # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
120     if (C4::Context->preference('autoBarcode') eq 'incremental') {
121         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
122         unless ($record->field($tagfield)->subfield($tagsubfield)) {
123             my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
124             $sth_barcode->execute;
125             my ($newbarcode) = $sth_barcode->fetchrow;
126             $newbarcode++;
127             # OK, we have the new barcode, now create the entry in MARC record
128             my $fieldItem = $record->field($tagfield);
129             $record->delete_field($fieldItem);
130             $fieldItem->add_subfields($tagsubfield => $newbarcode);
131             $record->insert_fields_ordered($fieldItem);
132         }
133     }
134
135     my $addedolditem = TransformMarcToKoha($dbh,$record);
136
137     # If we have to add or add & duplicate, we add the item
138     if ($add_submit || $add_duplicate_submit) {
139         # check for item barcode # being unique
140         my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
141         push @errors,"barcode_not_unique" if($exist_itemnumber);
142         # if barcode exists, don't create, but report The problem.
143     unless ($exist_itemnumber) {
144             my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
145         set_item_default_location($oldbibitemnum);
146     }
147         $nextop = "additem";
148         if ($exist_itemnumber) {
149             $itemrecord = $record;
150         }
151     }
152
153     # If we have to add & duplicate
154     if ($add_duplicate_submit) {
155
156         # We try to get the next barcode
157         use C4::Barcodes;
158         my $barcodeobj = C4::Barcodes->new;
159         my $barcodevalue = $barcodeobj->next_value($addedolditem->{'barcode'}) if $barcodeobj;
160         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
161         if ($record->field($tagfield)->subfield($tagsubfield)) {
162             # If we got the next codebar value, we put it in the record
163             if ($barcodevalue) {
164                 $record->field($tagfield)->update($tagsubfield => $barcodevalue);
165             # If not, we delete the recently inserted barcode from the record (so the user can input a barcode himself)
166             } else {
167                 $record->field($tagfield)->update($tagsubfield => '');
168             }
169         }
170         $itemrecord = $record;
171     }
172
173     # If we have to add multiple copies
174     if ($add_multiple_copies_submit) {
175
176         use C4::Barcodes;
177         my $barcodeobj = C4::Barcodes->new;
178         my $oldbarcode = $addedolditem->{'barcode'};
179         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
180
181         # If there is a barcode and we can't find him new values, we can't add multiple copies
182         my $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
183         if ($oldbarcode && !$testbarcode) {
184
185             push @errors, "no_next_barcode";
186             $itemrecord = $record;
187
188         } else {
189         # We add each item
190
191             # For the first iteration
192             my $barcodevalue = $oldbarcode;
193             my $exist_itemnumber;
194
195
196             for (my $i = 0; $i < $number_of_copies;) {
197
198                 # If there is a barcode
199                 if ($barcodevalue) {
200
201                     # Getting a new barcode (if it is not the first iteration or the barcode we tried already exists)
202                     $barcodevalue = $barcodeobj->next_value($oldbarcode) if ($i > 0 || $exist_itemnumber);
203
204                     # Putting it into the record
205                     if ($barcodevalue) {
206                         $record->field($tagfield)->update($tagsubfield => $barcodevalue);
207                     }
208
209                     # Checking if the barcode already exists
210                     $exist_itemnumber = get_item_from_barcode($barcodevalue);
211                 }
212
213                 # Adding the item
214         if (!$exist_itemnumber) {
215             my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
216             set_item_default_location($oldbibitemnum);
217
218             # We count the item only if it was really added
219             # That way, all items are added, even if there was some already existing barcodes
220             # FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode
221             $i++;
222         }
223
224                 # Preparing the next iteration
225                 $oldbarcode = $barcodevalue;
226             }
227             undef($itemrecord);
228         }
229     }
230
231
232 #-------------------------------------------------------------------------------
233 } elsif ($op eq "edititem") {
234 #-------------------------------------------------------------------------------
235 # retrieve item if exist => then, it's a modif
236     $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
237     $nextop = "saveitem";
238 #-------------------------------------------------------------------------------
239 } elsif ($op eq "delitem") {
240 #-------------------------------------------------------------------------------
241     # check that there is no issue on this item before deletion.
242     my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?");
243     $sth->execute($itemnumber);
244     my $onloan=$sth->fetchrow;
245         $sth->finish();
246     $nextop="additem";
247     if ($onloan){
248         push @errors,"book_on_loan";
249     } else {
250                 # check it doesnt have a waiting reserve
251                 $sth=$dbh->prepare("SELECT * FROM reserves WHERE found = 'W' AND itemnumber = ?");
252                 $sth->execute($itemnumber);
253                 my $reserve=$sth->fetchrow;
254                 unless ($reserve){
255                         &DelItem($dbh,$biblionumber,$itemnumber);
256                         print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
257             exit;
258                 }
259         push @errors,"book_reserved";
260     }
261 #-------------------------------------------------------------------------------
262 } elsif ($op eq "saveitem") {
263 #-------------------------------------------------------------------------------
264     # rebuild
265     my @tags      = $input->param('tag');
266     my @subfields = $input->param('subfield');
267     my @values    = $input->param('field_value');
268     # build indicator hash.
269     my @ind_tag   = $input->param('ind_tag');
270     my @indicator = $input->param('indicator');
271     # my $itemnumber = $input->param('itemnumber');
272     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM');
273     my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
274     # MARC::Record builded => now, record in DB
275     # warn "R: ".$record->as_formatted;
276     # check that the barcode don't exist already
277     my $addedolditem = TransformMarcToKoha($dbh,$itemtosave);
278     my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
279     if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
280         push @errors,"barcode_not_unique";
281     } else {
282         my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
283         $itemnumber="";
284     }
285     $nextop="additem";
286 }
287
288 #
289 #-------------------------------------------------------------------------------
290 # build screen with existing items. and "new" one
291 #-------------------------------------------------------------------------------
292
293 # now, build existiing item list
294 my $temp = GetMarcBiblio( $biblionumber );
295 my @fields = $temp->fields();
296 #my @fields = $record->fields();
297 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
298 my @big_array;
299 #---- finds where items.itemnumber is stored
300 my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
301 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
302
303 foreach my $field (@fields) {
304     next if ($field->tag()<10);
305     my @subf = $field->subfields or (); # don't use ||, as that forces $field->subfelds to be interpreted in scalar context
306     my %this_row;
307 # loop through each subfield
308     for my $i (0..$#subf) {
309         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10 
310                 && ($field->tag() ne $itemtagfield 
311                 && $subf[$i][0]   ne $itemtagsubfield));
312
313         $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10);
314                 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10) {
315                 $this_row{$subf[$i][0]}=GetAuthorisedValueDesc( $field->tag(),
316                         $subf[$i][0], $subf[$i][1], '', $tagslib) 
317                                                 || $subf[$i][1];
318                 }
319
320         if (($field->tag eq $branchtagfield) && ($subf[$i][$0] eq $branchtagsubfield) && C4::Context->preference("IndependantBranches")) {
321             #verifying rights
322             my $userenv = C4::Context->userenv();
323             unless (($userenv->{'flags'} == 1) or (($userenv->{'branch'} eq $subf[$i][1]))){
324                     $this_row{'nomod'}=1;
325             }
326         }
327         $this_row{itemnumber} = $subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield);
328     }
329     if (%this_row) {
330         push(@big_array, \%this_row);
331     }
332 }
333
334 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
335 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
336
337 # now, construct template !
338 # First, the existing items for display
339 my @item_value_loop;
340 my @header_value_loop;
341 for my $row ( @big_array ) {
342     my %row_data;
343     my @item_fields = map +{ field => $_ || '' }, @$row{ sort keys(%witness) };
344     $row_data{item_value} = [ @item_fields ];
345     $row_data{itemnumber} = $row->{itemnumber};
346     #reporting this_row values
347     $row_data{'nomod'} = $row->{'nomod'};
348     push(@item_value_loop,\%row_data);
349 }
350 foreach my $subfield_code (sort keys(%witness)) {
351     my %header_value;
352     $header_value{header_value} = $witness{$subfield_code};
353     push(@header_value_loop, \%header_value);
354 }
355
356 # now, build the item form for entering a new item
357 my @loop_data =();
358 my $i=0;
359 my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
360
361 my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
362 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
363
364 foreach my $tag (sort keys %{$tagslib}) {
365 # loop through each subfield
366   foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
367     next if subfield_is_koha_internal_p($subfield);
368     next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
369     my %subfield_data;
370  
371     my $index_subfield = int(rand(1000000)); 
372     if ($subfield eq '@'){
373         $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
374     } else {
375         $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
376     }
377     $subfield_data{tag}        = $tag;
378     $subfield_data{subfield}   = $subfield;
379     $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
380 #   $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
381     $subfield_data{marc_lib}   ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
382     $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
383     $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
384     my ($x,$value);
385     ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord);
386     $value =~ s/"/&quot;/g;
387     unless ($value) {
388         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
389         # get today date & replace YYYY, MM, DD if provided in the default value
390         my ( $year, $month, $day ) = split ',', $today_iso;     # FIXME: iso dates don't have commas!
391         $value =~ s/YYYY/$year/g;
392         $value =~ s/MM/$month/g;
393         $value =~ s/DD/$day/g;
394     }
395     $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
396     # testing branch value if IndependantBranches.
397     if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
398         my $CNtag       = substr($pref_itemcallnumber, 0, 3);
399         my $CNsubfield  = substr($pref_itemcallnumber, 3, 1);
400         my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
401         my $temp2 = $temp->field($CNtag);
402         if ($temp2) {
403             $value = ($temp2->subfield($CNsubfield)).' '.($temp2->subfield($CNsubfield2));
404             #remove any trailing space incase one subfield is used
405             $value =~ s/^\s+|\s+$//g;
406         }
407     }
408
409     my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
410     my $attributes          = qq($attributes_no_value value="$value" );
411     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
412       my @authorised_values;
413       my %authorised_lib;
414       # builds list, depending on authorised value...
415   
416       if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
417           foreach my $thisbranch (@$branches) {
418               push @authorised_values, $thisbranch->{value};
419               $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
420               $value = $thisbranch->{value} if $thisbranch->{selected};
421           }
422       }
423       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
424           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
425           my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
426           $sth->execute;
427           while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
428               push @authorised_values, $itemtype;
429               $authorised_lib{$itemtype} = $description;
430           }
431
432           unless ( $value ) {
433               my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
434               $itype_sth->execute( $biblionumber );
435               ( $value ) = $itype_sth->fetchrow_array;
436           }
437   
438           #---- class_sources
439       }
440       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
441           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
442             
443           my $class_sources = GetClassSources();
444           my $default_source = C4::Context->preference("DefaultClassificationSource");
445           
446           foreach my $class_source (sort keys %$class_sources) {
447               next unless $class_sources->{$class_source}->{'used'} or
448                           ($value and $class_source eq $value)      or
449                           ($class_source eq $default_source);
450               push @authorised_values, $class_source;
451               $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
452           }
453                   $value = $default_source unless ($value);
454
455           #---- "true" authorised value
456       }
457       else {
458           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
459           $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
460           while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
461               push @authorised_values, $value;
462               $authorised_lib{$value} = $lib;
463           }
464       }
465       $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
466           -name     => "field_value",
467           -values   => \@authorised_values,
468           -default  => $value,
469           -labels   => \%authorised_lib,
470           -override => 1,
471           -size     => 1,
472           -multiple => 0,
473           -tabindex => 1,
474           -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
475           -class    => "input_marceditor",
476       );
477     # it's a thesaurus / authority field
478     }
479     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
480         $subfield_data{marc_value} = "<input type=\"text\" $attributes />
481             <a href=\"#\" class=\"buttonDot\"
482                 onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
483     ";
484     # it's a plugin field
485     }
486     elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
487         # opening plugin
488         my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
489         if (do $plugin) {
490             my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
491             my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
492             $subfield_data{marc_value} = qq[<input $attributes
493                 onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
494                  onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
495                 <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
496                 $javascript];
497         } else {
498             warn "Plugin Failed: $plugin";
499             $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
500         }
501     }
502     elsif ( $tag eq '' ) {       # it's an hidden field
503         $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
504     }
505     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
506         $subfield_data{marc_value} = qq(<input type="text" $attributes />);
507     }
508     elsif ( length($value) > 100
509             or (C4::Context->preference("marcflavour") eq "UNIMARC" and
510                   300 <= $tag && $tag < 400 && $subfield eq 'a' )
511             or (C4::Context->preference("marcflavour") eq "MARC21"  and
512                   500 <= $tag && $tag < 600                     )
513           ) {
514         # oversize field (textarea)
515         $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
516     } else {
517         # it's a standard field
518          $subfield_data{marc_value} = "<input $attributes />";
519     }
520 #   $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
521     push (@loop_data, \%subfield_data);
522     $i++
523   }
524 }
525
526 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
527 $template->param( title => $record->title() ) if ($record ne "-1");
528 $template->param(
529     biblionumber => $biblionumber,
530     title        => $oldrecord->{title},
531     author       => $oldrecord->{author},
532     item_loop        => \@item_value_loop,
533     item_header_loop => \@header_value_loop,
534     item             => \@loop_data,
535     itemnumber       => $itemnumber,
536     itemtagfield     => $itemtagfield,
537     itemtagsubfield  => $itemtagsubfield,
538     op      => $nextop,
539     opisadd => ($nextop eq "saveitem") ? 0 : 1,
540 );
541 foreach my $error (@errors) {
542     $template->param($error => 1);
543 }
544 output_html_with_http_headers $input, $cookie, $template->output;