Removed tab indexes in additem.pl to enable tabbing to buttons in order. Previously...
[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 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 $frameworkcode = &GetFrameworkCode($biblionumber);
79
80 # Defining which userflag is needing according to the framework currently used
81 my $userflags;
82 if (defined $input->param('frameworkcode')) {
83     $userflags = ($input->param('frameworkcode') eq 'FA') ? "fast_cataloging" : "edit_catalogue";
84 }
85
86 if (not defined $userflags) {
87     $userflags = ($frameworkcode eq 'FA') ? "fast_cataloging" : "edit_catalogue";
88 }
89
90 my ($template, $loggedinuser, $cookie)
91     = get_template_and_user({template_name => "cataloguing/additem.tmpl",
92                  query => $input,
93                  type => "intranet",
94                  authnotrequired => 0,
95                  flagsrequired => {editcatalogue => $userflags},
96                  debug => 1,
97                  });
98
99
100 my $today_iso = C4::Dates->today('iso');
101 $template->param(today_iso => $today_iso);
102
103 my $tagslib = &GetMarcStructure(1,$frameworkcode);
104 my $record = GetMarcBiblio($biblionumber);
105 my $oldrecord = TransformMarcToKoha($dbh,$record);
106 my $itemrecord;
107 my $nextop="additem";
108 my @errors; # store errors found while checking data BEFORE saving item.
109 #-------------------------------------------------------------------------------
110 if ($op eq "additem") {
111 #-------------------------------------------------------------------------------
112     # rebuild
113     my @tags      = $input->param('tag');
114     my @subfields = $input->param('subfield');
115     my @values    = $input->param('field_value');
116     # build indicator hash.
117     my @ind_tag   = $input->param('ind_tag');
118     my @indicator = $input->param('indicator');
119     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
120     my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
121
122     # type of add
123     my $add_submit                 = $input->param('add_submit');
124     my $add_duplicate_submit       = $input->param('add_duplicate_submit');
125     my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
126     my $number_of_copies           = $input->param('number_of_copies');
127
128     # if autoBarcode is set to 'incremental', calculate barcode...
129         # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
130         # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
131     if (C4::Context->preference('autoBarcode') eq 'incremental') {
132         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
133         unless ($record->field($tagfield)->subfield($tagsubfield)) {
134             my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
135             $sth_barcode->execute;
136             my ($newbarcode) = $sth_barcode->fetchrow;
137             $newbarcode++;
138             # OK, we have the new barcode, now create the entry in MARC record
139             my $fieldItem = $record->field($tagfield);
140             $record->delete_field($fieldItem);
141             $fieldItem->add_subfields($tagsubfield => $newbarcode);
142             $record->insert_fields_ordered($fieldItem);
143         }
144     }
145
146     my $addedolditem = TransformMarcToKoha($dbh,$record);
147
148     # If we have to add or add & duplicate, we add the item
149     if ($add_submit || $add_duplicate_submit) {
150         # check for item barcode # being unique
151         my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
152         push @errors,"barcode_not_unique" if($exist_itemnumber);
153         # if barcode exists, don't create, but report The problem.
154     unless ($exist_itemnumber) {
155             my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
156         set_item_default_location($oldbibitemnum);
157     }
158         $nextop = "additem";
159         if ($exist_itemnumber) {
160             $itemrecord = $record;
161         }
162     }
163
164     # If we have to add & duplicate
165     if ($add_duplicate_submit) {
166
167         # We try to get the next barcode
168         use C4::Barcodes;
169         my $barcodeobj = C4::Barcodes->new;
170         my $barcodevalue = $barcodeobj->next_value($addedolditem->{'barcode'}) if $barcodeobj;
171         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
172         if ($record->field($tagfield)->subfield($tagsubfield)) {
173             # If we got the next codebar value, we put it in the record
174             if ($barcodevalue) {
175                 $record->field($tagfield)->update($tagsubfield => $barcodevalue);
176             # If not, we delete the recently inserted barcode from the record (so the user can input a barcode himself)
177             } else {
178                 $record->field($tagfield)->update($tagsubfield => '');
179             }
180         }
181         $itemrecord = $record;
182     }
183
184     # If we have to add multiple copies
185     if ($add_multiple_copies_submit) {
186
187         use C4::Barcodes;
188         my $barcodeobj = C4::Barcodes->new;
189         my $oldbarcode = $addedolditem->{'barcode'};
190         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
191
192         # If there is a barcode and we can't find him new values, we can't add multiple copies
193         my $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
194         if ($oldbarcode && !$testbarcode) {
195
196             push @errors, "no_next_barcode";
197             $itemrecord = $record;
198
199         } else {
200         # We add each item
201
202             # For the first iteration
203             my $barcodevalue = $oldbarcode;
204             my $exist_itemnumber;
205
206
207             for (my $i = 0; $i < $number_of_copies;) {
208
209                 # If there is a barcode
210                 if ($barcodevalue) {
211
212                     # Getting a new barcode (if it is not the first iteration or the barcode we tried already exists)
213                     $barcodevalue = $barcodeobj->next_value($oldbarcode) if ($i > 0 || $exist_itemnumber);
214
215                     # Putting it into the record
216                     if ($barcodevalue) {
217                         $record->field($tagfield)->update($tagsubfield => $barcodevalue);
218                     }
219
220                     # Checking if the barcode already exists
221                     $exist_itemnumber = get_item_from_barcode($barcodevalue);
222                 }
223
224                 # Adding the item
225         if (!$exist_itemnumber) {
226             my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
227             set_item_default_location($oldbibitemnum);
228
229             # We count the item only if it was really added
230             # That way, all items are added, even if there was some already existing barcodes
231             # FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode
232             $i++;
233         }
234
235                 # Preparing the next iteration
236                 $oldbarcode = $barcodevalue;
237             }
238             undef($itemrecord);
239         }
240     }
241
242
243 #-------------------------------------------------------------------------------
244 } elsif ($op eq "edititem") {
245 #-------------------------------------------------------------------------------
246 # retrieve item if exist => then, it's a modif
247     $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
248     $nextop = "saveitem";
249 #-------------------------------------------------------------------------------
250 } elsif ($op eq "delitem") {
251 #-------------------------------------------------------------------------------
252     # check that there is no issue on this item before deletion.
253     $error = &DelItemCheck($dbh,$biblionumber,$itemnumber);
254     if($error == 1){
255         print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
256     }else{
257         push @errors,$error;
258         $nextop="additem";
259     }
260 #-------------------------------------------------------------------------------
261 } elsif ($op eq "delallitems") {
262 #-------------------------------------------------------------------------------
263     my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber);
264     foreach my $biblioitem (@biblioitems){
265         my $items = &GetItemsByBiblioitemnumber($biblioitem->{biblioitemnumber});
266
267         foreach my $item (@$items){
268             &DelItem($dbh,$biblionumber,$item->{itemnumber});
269         }
270         }
271 #-------------------------------------------------------------------------------
272 } elsif ($op eq "saveitem") {
273 #-------------------------------------------------------------------------------
274     # rebuild
275     my @tags      = $input->param('tag');
276     my @subfields = $input->param('subfield');
277     my @values    = $input->param('field_value');
278     # build indicator hash.
279     my @ind_tag   = $input->param('ind_tag');
280     my @indicator = $input->param('indicator');
281     # my $itemnumber = $input->param('itemnumber');
282     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM');
283     my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
284     # MARC::Record builded => now, record in DB
285     # warn "R: ".$record->as_formatted;
286     # check that the barcode don't exist already
287     my $addedolditem = TransformMarcToKoha($dbh,$itemtosave);
288     my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
289     if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
290         push @errors,"barcode_not_unique";
291     } else {
292         my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
293         $itemnumber="";
294     }
295     $nextop="additem";
296 }
297
298 #
299 #-------------------------------------------------------------------------------
300 # build screen with existing items. and "new" one
301 #-------------------------------------------------------------------------------
302
303 # now, build existiing item list
304 my $temp = GetMarcBiblio( $biblionumber );
305 my @fields = $temp->fields();
306 #my @fields = $record->fields();
307 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
308 my @big_array;
309 #---- finds where items.itemnumber is stored
310 my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
311 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
312
313 foreach my $field (@fields) {
314     next if ($field->tag()<10);
315     my @subf = $field->subfields or (); # don't use ||, as that forces $field->subfelds to be interpreted in scalar context
316     my %this_row;
317 # loop through each subfield
318     for my $i (0..$#subf) {
319         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10 
320                 && ($field->tag() ne $itemtagfield 
321                 && $subf[$i][0]   ne $itemtagsubfield));
322
323         $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10);
324                 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  eq 10) {
325                 $this_row{$subf[$i][0]}=GetAuthorisedValueDesc( $field->tag(),
326                         $subf[$i][0], $subf[$i][1], '', $tagslib) 
327                                                 || $subf[$i][1];
328                 }
329
330         if (($field->tag eq $branchtagfield) && ($subf[$i][$0] eq $branchtagsubfield) && C4::Context->preference("IndependantBranches")) {
331             #verifying rights
332             my $userenv = C4::Context->userenv();
333             unless (($userenv->{'flags'} == 1) or (($userenv->{'branch'} eq $subf[$i][1]))){
334                     $this_row{'nomod'}=1;
335             }
336         }
337         $this_row{itemnumber} = $subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield);
338     }
339     if (%this_row) {
340         push(@big_array, \%this_row);
341     }
342 }
343
344 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
345 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
346
347 # now, construct template !
348 # First, the existing items for display
349 my @item_value_loop;
350 my @header_value_loop;
351 for my $row ( @big_array ) {
352     my %row_data;
353     my @item_fields = map +{ field => $_ || '' }, @$row{ sort keys(%witness) };
354     $row_data{item_value} = [ @item_fields ];
355     $row_data{itemnumber} = $row->{itemnumber};
356     #reporting this_row values
357     $row_data{'nomod'} = $row->{'nomod'};
358     push(@item_value_loop,\%row_data);
359 }
360 foreach my $subfield_code (sort keys(%witness)) {
361     my %header_value;
362     $header_value{header_value} = $witness{$subfield_code};
363     push(@header_value_loop, \%header_value);
364 }
365
366 # now, build the item form for entering a new item
367 my @loop_data =();
368 my $i=0;
369
370 my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
371 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
372
373 # Getting the fields where the item location is
374 my ($location_field, $location_subfield) = GetMarcFromKohaField('items.location', $frameworkcode);
375
376 # Getting the name of the authorised values' category for item location
377 my $item_location_category = $tagslib->{$location_field}->{$location_subfield}->{'authorised_value'};
378
379 foreach my $tag (sort keys %{$tagslib}) {
380 # loop through each subfield
381   foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
382     next if subfield_is_koha_internal_p($subfield);
383     next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
384     my %subfield_data;
385  
386     my $index_subfield = int(rand(1000000)); 
387     if ($subfield eq '@'){
388         $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
389     } else {
390         $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
391     }
392     $subfield_data{tag}        = $tag;
393     $subfield_data{subfield}   = $subfield;
394     $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
395 #   $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
396     $subfield_data{marc_lib}   ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
397     $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
398     $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
399     my ($x,$value);
400     ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord);
401     $value =~ s/"/&quot;/g;
402     unless ($value) {
403         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
404         # get today date & replace YYYY, MM, DD if provided in the default value
405         my ( $year, $month, $day ) = split ',', $today_iso;     # FIXME: iso dates don't have commas!
406         $value =~ s/YYYY/$year/g;
407         $value =~ s/MM/$month/g;
408         $value =~ s/DD/$day/g;
409     }
410     $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
411     # testing branch value if IndependantBranches.
412     if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
413         my $CNtag       = substr($pref_itemcallnumber, 0, 3);
414         my $CNsubfield  = substr($pref_itemcallnumber, 3, 1);
415         my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
416         my $temp2 = $temp->field($CNtag);
417         if ($temp2) {
418             $value = ($temp2->subfield($CNsubfield)).' '.($temp2->subfield($CNsubfield2));
419             #remove any trailing space incase one subfield is used
420             $value =~ s/^\s+|\s+$//g;
421         }
422     }
423
424     my $attributes_no_value = qq(id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
425     my $attributes          = qq($attributes_no_value value="$value" );
426     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
427       my @authorised_values;
428       my %authorised_lib;
429       # builds list, depending on authorised value...
430   
431       if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
432           foreach my $thisbranch (@$branches) {
433               push @authorised_values, $thisbranch->{value};
434               $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
435              # $value = $thisbranch->{value} if $thisbranch->{selected};
436           }
437       }
438       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
439           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
440           my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
441           $sth->execute;
442           while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
443               push @authorised_values, $itemtype;
444               $authorised_lib{$itemtype} = $description;
445           }
446
447           unless ( $value ) {
448               my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
449               $itype_sth->execute( $biblionumber );
450               ( $value ) = $itype_sth->fetchrow_array;
451           }
452   
453           #---- class_sources
454       }
455       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
456           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
457             
458           my $class_sources = GetClassSources();
459           my $default_source = C4::Context->preference("DefaultClassificationSource");
460           
461           foreach my $class_source (sort keys %$class_sources) {
462               next unless $class_sources->{$class_source}->{'used'} or
463                           ($value and $class_source eq $value)      or
464                           ($class_source eq $default_source);
465               push @authorised_values, $class_source;
466               $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
467           }
468                   $value = $default_source unless ($value);
469
470           #---- "true" authorised value
471       }
472       else {
473           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
474
475           # Are we dealing with item location ?
476           my $item_location = ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) ? 1 : 0;
477
478           # If so, we sort by authorised_value, else by libelle
479           my $orderby = $item_location ? 'authorised_value' : 'lib';
480
481           my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY $orderby");
482
483           $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value});
484
485
486           while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
487             push @authorised_values, $value;
488                 if ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) {
489                                 $authorised_lib{$value} = $value . " - " . $lib;
490                 } else {
491                                 $authorised_lib{$value} = $lib;
492                 }
493
494                 # For item location, we show the code and the libelle
495                 $authorised_lib{$value} = ($item_location) ? $value . " - " . $lib : $lib;
496           }
497       }
498       $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
499           -name     => "field_value",
500           -values   => \@authorised_values,
501           -default  => $value,
502           -labels   => \%authorised_lib,
503           -override => 1,
504           -size     => 1,
505           -multiple => 0,
506          # -tabindex => 1,
507           -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
508           -class    => "input_marceditor",
509       );
510     # it's a thesaurus / authority field
511     }
512     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
513         $subfield_data{marc_value} = "<input type=\"text\" $attributes />
514             <a href=\"#\" class=\"buttonDot\"
515                 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>
516     ";
517     # it's a plugin field
518     }
519     elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
520         # opening plugin
521         my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
522         if (do $plugin) {
523             my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
524             my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
525             $subfield_data{marc_value} = qq[<input $attributes
526                 onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
527                  onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
528                 <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
529                 $javascript];
530         } else {
531             warn "Plugin Failed: $plugin";
532             $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
533         }
534     }
535     elsif ( $tag eq '' ) {       # it's an hidden field
536         $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
537     }
538     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
539         $subfield_data{marc_value} = qq(<input type="text" $attributes />);
540     }
541     elsif ( length($value) > 100
542             or (C4::Context->preference("marcflavour") eq "UNIMARC" and
543                   300 <= $tag && $tag < 400 && $subfield eq 'a' )
544             or (C4::Context->preference("marcflavour") eq "MARC21"  and
545                   500 <= $tag && $tag < 600                     )
546           ) {
547         # oversize field (textarea)
548         $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
549     } else {
550         # it's a standard field
551          $subfield_data{marc_value} = "<input $attributes />";
552     }
553 #   $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
554     push (@loop_data, \%subfield_data);
555     $i++
556   }
557 }
558
559 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
560 $template->param( title => $record->title() ) if ($record ne "-1");
561 $template->param(
562     biblionumber => $biblionumber,
563     title        => $oldrecord->{title},
564     author       => $oldrecord->{author},
565     item_loop        => \@item_value_loop,
566     item_header_loop => \@header_value_loop,
567     item             => \@loop_data,
568     itemnumber       => $itemnumber,
569     itemtagfield     => $itemtagfield,
570     itemtagsubfield  => $itemtagsubfield,
571     op      => $nextop,
572     opisadd => ($nextop eq "saveitem") ? 0 : 1,
573     C4::Search::enabled_staff_search_views,
574 );
575 foreach my $error (@errors) {
576     $template->param($error => 1);
577 }
578 output_html_with_http_headers $input, $cookie, $template->output;