Subscription add Updating Online Help file
[koha-ffzg.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 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     $error = &DelItemCheck($dbh,$biblionumber,$itemnumber);
243     if($error == 1){
244         print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
245     }else{
246         push @errors,$error;
247         $nextop="additem";
248     }
249 #-------------------------------------------------------------------------------
250 } elsif ($op eq "delallitems") {
251 #-------------------------------------------------------------------------------
252     my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber);
253     foreach my $biblioitem (@biblioitems){
254         my $items = &GetItemsByBiblioitemnumber($biblioitem->{biblioitemnumber});
255
256         foreach my $item (@$items){
257             &DelItem($dbh,$biblionumber,$item->{itemnumber});
258         }
259         }
260 #-------------------------------------------------------------------------------
261 } elsif ($op eq "saveitem") {
262 #-------------------------------------------------------------------------------
263     # rebuild
264     my @tags      = $input->param('tag');
265     my @subfields = $input->param('subfield');
266     my @values    = $input->param('field_value');
267     # build indicator hash.
268     my @ind_tag   = $input->param('ind_tag');
269     my @indicator = $input->param('indicator');
270     # my $itemnumber = $input->param('itemnumber');
271     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM');
272     my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
273     # MARC::Record builded => now, record in DB
274     # warn "R: ".$record->as_formatted;
275     # check that the barcode don't exist already
276     my $addedolditem = TransformMarcToKoha($dbh,$itemtosave);
277     my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
278     if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
279         push @errors,"barcode_not_unique";
280     } else {
281         my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
282         $itemnumber="";
283     }
284     $nextop="additem";
285 }
286
287 #
288 #-------------------------------------------------------------------------------
289 # build screen with existing items. and "new" one
290 #-------------------------------------------------------------------------------
291
292 # now, build existiing item list
293 my $temp = GetMarcBiblio( $biblionumber );
294 my @fields = $temp->fields();
295 #my @fields = $record->fields();
296 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
297 my @big_array;
298 #---- finds where items.itemnumber is stored
299 my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
300 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
301
302 foreach my $field (@fields) {
303     next if ($field->tag()<10);
304     my @subf = $field->subfields or (); # don't use ||, as that forces $field->subfelds to be interpreted in scalar context
305     my %this_row;
306 # loop through each subfield
307     for my $i (0..$#subf) {
308         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10 
309                 && ($field->tag() ne $itemtagfield 
310                 && $subf[$i][0]   ne $itemtagsubfield));
311
312         $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10);
313                 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10) {
314                 $this_row{$subf[$i][0]}=GetAuthorisedValueDesc( $field->tag(),
315                         $subf[$i][0], $subf[$i][1], '', $tagslib) 
316                                                 || $subf[$i][1];
317                 }
318
319         if (($field->tag eq $branchtagfield) && ($subf[$i][$0] eq $branchtagsubfield) && C4::Context->preference("IndependantBranches")) {
320             #verifying rights
321             my $userenv = C4::Context->userenv();
322             unless (($userenv->{'flags'} == 1) or (($userenv->{'branch'} eq $subf[$i][1]))){
323                     $this_row{'nomod'}=1;
324             }
325         }
326         $this_row{itemnumber} = $subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield);
327     }
328     if (%this_row) {
329         push(@big_array, \%this_row);
330     }
331 }
332
333 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
334 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
335
336 # now, construct template !
337 # First, the existing items for display
338 my @item_value_loop;
339 my @header_value_loop;
340 for my $row ( @big_array ) {
341     my %row_data;
342     my @item_fields = map +{ field => $_ || '' }, @$row{ sort keys(%witness) };
343     $row_data{item_value} = [ @item_fields ];
344     $row_data{itemnumber} = $row->{itemnumber};
345     #reporting this_row values
346     $row_data{'nomod'} = $row->{'nomod'};
347     push(@item_value_loop,\%row_data);
348 }
349 foreach my $subfield_code (sort keys(%witness)) {
350     my %header_value;
351     $header_value{header_value} = $witness{$subfield_code};
352     push(@header_value_loop, \%header_value);
353 }
354
355 # now, build the item form for entering a new item
356 my @loop_data =();
357 my $i=0;
358 my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
359
360 my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
361 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
362
363 # Getting the fields where the item location is
364 my ($location_field, $location_subfield) = GetMarcFromKohaField('items.location', $frameworkcode);
365
366 # Getting the name of the authorised values' category for item location
367 my $item_location_category = $tagslib->{$location_field}->{$location_subfield}->{'authorised_value'};
368
369 foreach my $tag (sort keys %{$tagslib}) {
370 # loop through each subfield
371   foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
372     next if subfield_is_koha_internal_p($subfield);
373     next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
374     my %subfield_data;
375  
376     my $index_subfield = int(rand(1000000)); 
377     if ($subfield eq '@'){
378         $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
379     } else {
380         $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
381     }
382     $subfield_data{tag}        = $tag;
383     $subfield_data{subfield}   = $subfield;
384     $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
385 #   $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
386     $subfield_data{marc_lib}   ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
387     $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
388     $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
389     my ($x,$value);
390     ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord);
391     $value =~ s/"/&quot;/g;
392     unless ($value) {
393         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
394         # get today date & replace YYYY, MM, DD if provided in the default value
395         my ( $year, $month, $day ) = split ',', $today_iso;     # FIXME: iso dates don't have commas!
396         $value =~ s/YYYY/$year/g;
397         $value =~ s/MM/$month/g;
398         $value =~ s/DD/$day/g;
399     }
400     $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
401     # testing branch value if IndependantBranches.
402     if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
403         my $CNtag       = substr($pref_itemcallnumber, 0, 3);
404         my $CNsubfield  = substr($pref_itemcallnumber, 3, 1);
405         my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
406         my $temp2 = $temp->field($CNtag);
407         if ($temp2) {
408             $value = ($temp2->subfield($CNsubfield)).' '.($temp2->subfield($CNsubfield2));
409             #remove any trailing space incase one subfield is used
410             $value =~ s/^\s+|\s+$//g;
411         }
412     }
413
414     my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
415     my $attributes          = qq($attributes_no_value value="$value" );
416     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
417       my @authorised_values;
418       my %authorised_lib;
419       # builds list, depending on authorised value...
420   
421       if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
422           foreach my $thisbranch (@$branches) {
423               push @authorised_values, $thisbranch->{value};
424               $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
425               $value = $thisbranch->{value} if $thisbranch->{selected};
426           }
427       }
428       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
429           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
430           my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
431           $sth->execute;
432           while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
433               push @authorised_values, $itemtype;
434               $authorised_lib{$itemtype} = $description;
435           }
436
437           unless ( $value ) {
438               my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
439               $itype_sth->execute( $biblionumber );
440               ( $value ) = $itype_sth->fetchrow_array;
441           }
442   
443           #---- class_sources
444       }
445       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
446           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
447             
448           my $class_sources = GetClassSources();
449           my $default_source = C4::Context->preference("DefaultClassificationSource");
450           
451           foreach my $class_source (sort keys %$class_sources) {
452               next unless $class_sources->{$class_source}->{'used'} or
453                           ($value and $class_source eq $value)      or
454                           ($class_source eq $default_source);
455               push @authorised_values, $class_source;
456               $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
457           }
458                   $value = $default_source unless ($value);
459
460           #---- "true" authorised value
461       }
462       else {
463           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
464           $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
465           while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
466               push @authorised_values, $value;
467               
468               if ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) {
469                   $authorised_lib{$value} = $value . " - " . $lib;
470               } else {
471                   $authorised_lib{$value} = $lib;
472               }
473           }
474       }
475       $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
476           -name     => "field_value",
477           -values   => \@authorised_values,
478           -default  => $value,
479           -labels   => \%authorised_lib,
480           -override => 1,
481           -size     => 1,
482           -multiple => 0,
483           -tabindex => 1,
484           -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
485           -class    => "input_marceditor",
486       );
487     # it's a thesaurus / authority field
488     }
489     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
490         $subfield_data{marc_value} = "<input type=\"text\" $attributes />
491             <a href=\"#\" class=\"buttonDot\"
492                 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>
493     ";
494     # it's a plugin field
495     }
496     elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
497         # opening plugin
498         my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
499         if (do $plugin) {
500             my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
501             my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
502             $subfield_data{marc_value} = qq[<input $attributes
503                 onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
504                  onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
505                 <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
506                 $javascript];
507         } else {
508             warn "Plugin Failed: $plugin";
509             $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
510         }
511     }
512     elsif ( $tag eq '' ) {       # it's an hidden field
513         $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
514     }
515     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
516         $subfield_data{marc_value} = qq(<input type="text" $attributes />);
517     }
518     elsif ( length($value) > 100
519             or (C4::Context->preference("marcflavour") eq "UNIMARC" and
520                   300 <= $tag && $tag < 400 && $subfield eq 'a' )
521             or (C4::Context->preference("marcflavour") eq "MARC21"  and
522                   500 <= $tag && $tag < 600                     )
523           ) {
524         # oversize field (textarea)
525         $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
526     } else {
527         # it's a standard field
528          $subfield_data{marc_value} = "<input $attributes />";
529     }
530 #   $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
531     push (@loop_data, \%subfield_data);
532     $i++
533   }
534 }
535
536 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
537 $template->param( title => $record->title() ) if ($record ne "-1");
538 $template->param(
539     biblionumber => $biblionumber,
540     title        => $oldrecord->{title},
541     author       => $oldrecord->{author},
542     item_loop        => \@item_value_loop,
543     item_header_loop => \@header_value_loop,
544     item             => \@loop_data,
545     itemnumber       => $itemnumber,
546     itemtagfield     => $itemtagfield,
547     itemtagsubfield  => $itemtagsubfield,
548     op      => $nextop,
549     opisadd => ($nextop eq "saveitem") ? 0 : 1,
550     C4::Search::enabled_staff_search_views,
551 );
552 foreach my $error (@errors) {
553     $template->param($error => 1);
554 }
555 output_html_with_http_headers $input, $cookie, $template->output;