(bug #2914) delete all items of a notice
[koha.git] / 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
32 use Date::Calc qw(Today);
33
34 use MARC::File::XML;
35
36 sub find_value {
37     my ($tagfield,$insubfield,$record) = @_;
38     my $result;
39     my $indicator;
40     foreach my $field ($record->field($tagfield)) {
41         my @subfields = $field->subfields();
42         foreach my $subfield (@subfields) {
43             if (@$subfield[0] eq $insubfield) {
44                 $result .= @$subfield[1];
45                 $indicator = $field->indicator(1).$field->indicator(2);
46             }
47         }
48     }
49     return($indicator,$result);
50 }
51
52 sub get_item_from_barcode {
53     my ($barcode)=@_;
54     my $dbh=C4::Context->dbh;
55     my $result;
56     my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?");
57     $rq->execute($barcode);
58     ($result)=$rq->fetchrow;
59     return($result);
60 }
61
62 my $input = new CGI;
63 my $dbh = C4::Context->dbh;
64 my $error = $input->param('error');
65 my $biblionumber = $input->param('biblionumber');
66 my $itemnumber = $input->param('itemnumber');
67 my $op = $input->param('op');
68
69 my ($template, $loggedinuser, $cookie)
70     = get_template_and_user({template_name => "cataloguing/additem.tmpl",
71                  query => $input,
72                  type => "intranet",
73                  authnotrequired => 0,
74                  flagsrequired => {editcatalogue => 1},
75                  debug => 1,
76                  });
77
78 # find itemtype
79 my $frameworkcode = &GetFrameworkCode($biblionumber);
80
81 my $tagslib = &GetMarcStructure(1,$frameworkcode);
82 my $record = GetMarcBiblio($biblionumber);
83 my $oldrecord = TransformMarcToKoha($dbh,$record);
84 my $itemrecord;
85 my $nextop="additem";
86 my @errors; # store errors found while checking data BEFORE saving item.
87 #-------------------------------------------------------------------------------
88 if ($op eq "additem") {
89 #-------------------------------------------------------------------------------
90     # rebuild
91     my @tags = $input->param('tag');
92     my @subfields = $input->param('subfield');
93     my @values = $input->param('field_value');
94     # build indicator hash.
95     my @ind_tag = $input->param('ind_tag');
96     my @indicator = $input->param('indicator');
97     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
98         my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
99     # if autoBarcode is set to 'incremental', calculate barcode...
100         # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
101         # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
102     if (C4::Context->preference('autoBarcode') eq 'incremental') {
103         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
104         unless ($record->field($tagfield)->subfield($tagsubfield)) {
105             my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
106             $sth_barcode->execute;
107             my ($newbarcode) = $sth_barcode->fetchrow;
108             $newbarcode++;
109             # OK, we have the new barcode, now create the entry in MARC record
110             my $fieldItem = $record->field($tagfield);
111             $record->delete_field($fieldItem);
112             $fieldItem->add_subfields($tagsubfield => $newbarcode);
113             $record->insert_fields_ordered($fieldItem);
114         }
115     }
116 # check for item barcode # being unique
117     my $addedolditem = TransformMarcToKoha($dbh,$record);
118     my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
119     push @errors,"barcode_not_unique" if($exist_itemnumber);
120     # if barcode exists, don't create, but report The problem.
121     my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber);
122     if ($exist_itemnumber) {
123         $nextop = "additem";
124         $itemrecord = $record;
125     } else {
126         $nextop = "additem";
127     }
128 #-------------------------------------------------------------------------------
129 } elsif ($op eq "edititem") {
130 #-------------------------------------------------------------------------------
131 # retrieve item if exist => then, it's a modif
132     $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
133     $nextop="saveitem";
134 #-------------------------------------------------------------------------------
135 } elsif ($op eq "delitem") {
136 #-------------------------------------------------------------------------------
137     # check that there is no issue on this item before deletion.
138     my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?");
139     $sth->execute($itemnumber);
140     my $onloan=$sth->fetchrow;
141         $sth->finish();
142     push @errors,"book_on_loan" if ($onloan); ##error book_on_loan added to template as well
143     if ($onloan){
144                 $nextop="additem";
145     } else {
146                 # check it doesnt have a waiting reserve
147                 $sth=$dbh->prepare("SELECT * FROM reserves WHERE found = 'W' AND itemnumber = ?");
148                 $sth->execute($itemnumber);
149                 my $reserve=$sth->fetchrow;
150                 if ($reserve){
151                         push @errors,"book_reserved";
152                         $nextop="additem";
153                 }
154                 else {
155                         &DelItem($dbh,$biblionumber,$itemnumber);
156                         print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
157                 }
158     }
159 #-------------------------------------------------------------------------------
160 } elsif ($op eq "delallitems") {
161 #-------------------------------------------------------------------------------
162     my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber);
163     foreach my $biblioitem (@biblioitems){
164         my $items = &GetItemsByBiblioitemnumber($biblioitem->{biblioitemnumber});
165
166         foreach my $item (@$items){
167             &DelItem($dbh,$biblionumber,$item->{itemnumber});
168         }
169     }
170     print $input->redirect("/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=$biblionumber");
171 #-------------------------------------------------------------------------------
172 } elsif ($op eq "saveitem") {
173 #-------------------------------------------------------------------------------
174     # rebuild
175     my @tags = $input->param('tag');
176     my @subfields = $input->param('subfield');
177     my @values = $input->param('field_value');
178     # build indicator hash.
179     my @ind_tag = $input->param('ind_tag');
180     my @indicator = $input->param('indicator');
181     #    my $itemnumber = $input->param('itemnumber');
182     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM');
183     my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
184     # MARC::Record builded => now, record in DB
185     # warn "R: ".$record->as_formatted;
186     # check that the barcode don't exist already
187     my $addedolditem = TransformMarcToKoha($dbh,$itemtosave);
188     my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
189     if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
190         push @errors,"barcode_not_unique";
191     } else {
192         my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
193     $itemnumber="";
194     }
195     $nextop="additem";
196 }
197
198 #
199 #-------------------------------------------------------------------------------
200 # build screen with existing items. and "new" one
201 #-------------------------------------------------------------------------------
202
203 # now, build existiing item list
204 my $temp = GetMarcBiblio( $biblionumber );
205 my @fields = $temp->fields();
206 #my @fields = $record->fields();
207 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
208 my @big_array;
209 #---- finds where items.itemnumber is stored
210 my ($itemtagfield,$itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber",$frameworkcode);
211 my ($branchtagfield,$branchtagsubfield) = &GetMarcFromKohaField("items.homebranch",$frameworkcode);
212
213 foreach my $field (@fields) {
214     next if ($field->tag()<10);
215     my @subf=$field->subfields;
216     my %this_row;
217 # loop through each subfield
218     for my $i (0..$#subf) {
219         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10 
220                 && ($field->tag() ne $itemtagfield 
221                 && $subf[$i][0] ne $itemtagsubfield));
222
223         $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10);
224                 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10) {
225                 $this_row{$subf[$i][0]}=GetAuthorisedValueDesc( $field->tag(),
226                         $subf[$i][0], $subf[$i][1], '', $tagslib) 
227                                                 || $subf[$i][1];
228                 }
229
230         if (($field->tag eq $branchtagfield) && ($subf[$i][$0] eq $branchtagsubfield) && C4::Context->preference("IndependantBranches")) {
231             #verifying rights
232             my $userenv = C4::Context->userenv();
233             unless (($userenv->{'flags'} == 1) or (($userenv->{'branch'} eq $subf[$i][1]))){
234                     $this_row{'nomod'}=1;
235             }
236         }
237         $this_row{itemnumber} = $subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield);
238     }
239     if (%this_row) {
240         push(@big_array, \%this_row);
241     }
242 }
243 #fill big_row with missing data
244 foreach my $subfield_code  (keys(%witness)) {
245     for (my $i=0;$i<=$#big_array;$i++) {
246         $big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
247     }
248 }
249 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
250 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
251
252 # now, construct template !
253 # First, the existing items for display
254 my @item_value_loop;
255 my @header_value_loop;
256 for (my $i=0;$i<=$#big_array; $i++) {
257     my $items_data;
258     foreach my $subfield_code (sort keys(%witness)) {
259         $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
260     }
261     my %row_data;
262     $items_data =~ s/"/&quot;/g;
263     $row_data{item_value} = $items_data;
264     $row_data{itemnumber} = $big_array[$i]->{itemnumber};
265     #reporting this_row values
266     $row_data{'nomod'} = $big_array[$i]{'nomod'};
267     push(@item_value_loop,\%row_data);
268 }
269 foreach my $subfield_code (sort keys(%witness)) {
270     my %header_value;
271     $header_value{header_value} = $witness{$subfield_code};
272     push(@header_value_loop, \%header_value);
273 }
274
275 # now, build the item form for entering a new item
276 my @loop_data =();
277 my $i=0;
278 my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
279
280 foreach my $tag (sort keys %{$tagslib}) {
281   my $previous_tag = '';
282 # loop through each subfield
283   foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
284     next if subfield_is_koha_internal_p($subfield);
285     next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "10");
286     my %subfield_data;
287  
288     my $index_subfield= int(rand(1000000)); 
289     if($subfield eq '@'){
290         $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
291     } else {
292          $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
293     }
294     $subfield_data{tag}=$tag;
295     $subfield_data{subfield}=$subfield;
296     $subfield_data{random}=int(rand(1000000)); 
297 #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
298     $subfield_data{marc_lib}="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
299     $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
300     $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
301     my ($x,$value);
302     ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord);
303     $value =~ s/"/&quot;/g;
304     unless ($value) {
305         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
306
307         # get today date & replace YYYY, MM, DD if provided in the default value
308         my ( $year, $month, $day ) = Today();
309         $month = sprintf( "%02d", $month );
310         $day   = sprintf( "%02d", $day );
311         $value =~ s/YYYY/$year/g;
312         $value =~ s/MM/$month/g;
313         $value =~ s/DD/$day/g;
314     }
315     $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
316     #testing branch value if IndependantBranches.
317     my $test = (C4::Context->preference("IndependantBranches")) &&
318               ($tag eq $branchtagfield) && ($subfield eq $branchtagsubfield) &&
319               (C4::Context->userenv->{flags} != 1) && ($value) && ($value ne C4::Context->userenv->{branch}) ;
320 #         print $input->redirect(".pl?biblionumber=$biblionumber") if ($test);
321         # search for itemcallnumber if applicable
322     if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && C4::Context->preference('itemcallnumber')) {
323         my $CNtag = substr(C4::Context->preference('itemcallnumber'),0,3);
324         my $CNsubfield = substr(C4::Context->preference('itemcallnumber'),3,1);
325         my $CNsubfield2 = substr(C4::Context->preference('itemcallnumber'),4,1);
326         my $temp2 = $temp->field($CNtag);
327         if ($temp2) {
328                 $value = ($temp2->subfield($CNsubfield)).' '.($temp2->subfield($CNsubfield2));
329 #remove any trailing space incase one subfield is used
330         $value=~s/^\s+|\s+$//g;
331       }
332     }
333     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
334       my @authorised_values;
335       my %authorised_lib;
336       my $dbh=C4::Context->dbh;   
337   
338       # builds list, depending on authorised value...
339   
340       #---- branch
341       if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
342           #Use GetBranches($onlymine)
343           my $onlymine=C4::Context->preference('IndependantBranches') && 
344                   C4::Context->userenv && 
345                   C4::Context->userenv->{flags}!=1 && 
346                   C4::Context->userenv->{branch};
347           my $branches = GetBranches($onlymine);
348           my @branchloop;
349           foreach my $thisbranch ( sort keys %$branches ) {
350               push @authorised_values, $thisbranch;
351               $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
352           }
353           
354           #----- itemtypes
355       }
356       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
357           my $sth =
358             $dbh->prepare(
359               "select itemtype,description from itemtypes order by description");
360           $sth->execute;
361           push @authorised_values, ""
362             unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
363                       
364           while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
365               push @authorised_values, $itemtype;
366               $authorised_lib{$itemtype} = $description;
367           }
368
369           unless ( $value ) {
370               my $default_itemtype;
371               my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
372               $itype_sth->execute( $biblionumber );
373               ( $default_itemtype ) = $itype_sth->fetchrow_array;
374               $value = $default_itemtype;
375           }
376   
377           #---- class_sources
378       }
379       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
380           push @authorised_values, ""
381             unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
382             
383           my $class_sources = GetClassSources();
384
385           my $default_source = C4::Context->preference("DefaultClassificationSource");
386           
387           foreach my $class_source (sort keys %$class_sources) {
388               next unless $class_sources->{$class_source}->{'used'} or
389                           ($value and $class_source eq $value) or
390                           ($class_source eq $default_source);
391               push @authorised_values, $class_source;
392               $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
393           }
394                   $value = $default_source unless ($value);
395
396           #---- "true" authorised value
397       }
398       else {
399           $authorised_values_sth->execute(
400               $tagslib->{$tag}->{$subfield}->{authorised_value} );
401   
402           push @authorised_values, ""
403             unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
404   
405           while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
406               push @authorised_values, $value;
407               $authorised_lib{$value} = $lib;
408           }
409       }
410       $subfield_data{marc_value} =CGI::scrolling_list(
411           -name     => "field_value",
412           -values   => \@authorised_values,
413           -default  => $value,
414           -labels   => \%authorised_lib,
415           -override => 1,
416           -size     => 1,
417           -multiple => 0,
418           -tabindex => 1,
419           -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
420           -class    => "input_marceditor",
421       );
422     # it's a thesaurus / authority field
423     }
424     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
425         $subfield_data{marc_value} =
426             "<input type=\"text\"
427                     id=\"".$subfield_data{id}."\"
428                     name=\"field_value\"
429                     value=\"$value\"
430                     class=\"input_marceditor\"
431                     tabindex=\"1\"
432                     size=\"67\"
433                     maxlength=\"255\" 
434                     \/>
435                     <a href=\"#\" class=\"buttonDot\"
436                         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>
437     ";
438     # it's a plugin field
439     }
440     elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
441
442         # opening plugin. Just check wether we are on a developper computer on a production one
443         # (the cgidir differs)
444         my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
445         unless ( opendir( DIR, "$cgidir" ) ) {
446             $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
447             closedir( DIR );
448         }
449         my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
450         if (do $plugin) {
451             my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
452             my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
453         
454             $subfield_data{marc_value} =
455                     "<input tabindex=\"1\"
456                             type=\"text\"
457                             id=\"".$subfield_data{id}."\"
458                             name=\"field_value\"
459                             value=\"$value\"
460                             class=\"input_marceditor\"
461                             onfocus=\"Focus$function_name(".$subfield_data{random}.")\"
462                             size=\"67\"
463                             maxlength=\"255\" 
464                             onblur=\"Blur$function_name(".$subfield_data{random}."); \" \/>
465                             <a href=\"#\" class=\"buttonDot\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
466                     $javascript";
467         } else {
468             warn "Plugin Failed: $plugin";
469             # supply default input form
470             $subfield_data{marc_value} =
471                 "<input type=\"text\"
472                         id=\"".$subfield_data{id}."\"
473                         name=\"field_value\"
474                         value=\"$value\"
475                         tabindex=\"1\"
476                         size=\"67\"
477                         maxlength=\"255\" 
478                         class=\"input_marceditor\"
479                 \/>
480                 ";
481         }
482         # it's an hidden field
483     }
484     elsif ( $tag eq '' ) {
485         $subfield_data{marc_value} =
486             "<input tabindex=\"1\"
487                     type=\"hidden\"
488                     id=\"".$subfield_data{id}."\"
489                     name=\"field_value\"
490                     size=\"67\"
491                     maxlength=\"255\" 
492                     value=\"$value\" \/>
493             ";
494     }
495     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
496         $subfield_data{marc_value} =
497             "<input type=\"text\"
498                     id=\"".$subfield_data{id}."\"
499                     name=\"field_value\"
500                     class=\"input_marceditor\"
501                     tabindex=\"1\"
502                     size=\"67\"
503                     maxlength=\"255\" 
504                     value=\"$value\"
505             \/>";
506
507         # it's a standard field
508     }
509     else {
510         if (
511             length($value) > 100
512             or
513             ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
514                 and $tag < 400 && $subfield eq 'a' )
515             or (    $tag >= 500
516                 and $tag < 600
517                 && C4::Context->preference("marcflavour") eq "MARC21" )
518           )
519         {
520             $subfield_data{marc_value} =
521                 "<textarea cols=\"70\"
522                            rows=\"4\"
523                            id=\"".$subfield_data{id}."\"
524                            name=\"field_value\"
525                            class=\"input_marceditor\"
526                            tabindex=\"1\"
527                             size=\"67\"
528                             maxlength=\"255\" 
529                            >$value</textarea>
530                 ";
531         }
532         else {
533             $subfield_data{marc_value} =
534                 "<input type=\"text\"
535                         id=\"".$subfield_data{id}."\"
536                         name=\"field_value\"
537                         value=\"$value\"
538                         tabindex=\"1\"
539                         size=\"67\"
540                         maxlength=\"255\" 
541                         class=\"input_marceditor\"
542                 \/>
543                 ";
544         }
545     }
546 #        $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
547         push(@loop_data, \%subfield_data);
548         $i++
549     }
550 }
551
552 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
553 $template->param( title => $record->title() ) if ($record ne "-1");
554 $template->param(item_loop => \@item_value_loop,
555                         item_header_loop => \@header_value_loop,
556                         biblionumber => $biblionumber,
557                         title => $oldrecord->{title},
558                         author => $oldrecord->{author},
559                         item => \@loop_data,
560                         itemnumber => $itemnumber,
561                         itemtagfield => $itemtagfield,
562                         itemtagsubfield =>$itemtagsubfield,
563                         op => $nextop,
564                         opisadd => ($nextop eq "saveitem")?0:1);
565 foreach my $error (@errors) {
566     $template->param($error => 1);
567 }
568 output_html_with_http_headers $input, $cookie, $template->output;