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