Bug 22358: (RM follow-up) Typo fix
[koha.git] / authorities / authorities.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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use CGI qw ( -utf8 );
24 use C4::Auth;
25 use C4::Output;
26 use C4::AuthoritiesMarc;
27 use C4::ImportBatch; #GetImportRecordMarc
28 use C4::Context;
29 use C4::Koha;
30 use Date::Calc qw(Today);
31 use MARC::File::USMARC;
32 use MARC::File::XML;
33 use C4::Biblio;
34 use Koha::Authority::Types;
35 use Koha::ItemTypes;
36 use vars qw( $tagslib);
37 use vars qw( $authorised_values_sth);
38 use vars qw( $is_a_modif );
39
40 my $itemtype; # created here because it can be used in build_authorized_values_list sub
41 our($authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
42
43 =head1 FUNCTIONS
44
45 =over
46
47 =item build_authorized_values_list
48
49 builds list, depending on authorised value...
50
51 =cut
52
53 sub MARCfindbreeding_auth {
54     my ( $id ) = @_;
55     my ($marc, $encoding) = GetImportRecordMarc($id);
56     if ($marc) {
57         my $record = MARC::Record->new_from_usmarc($marc);
58         if ( !defined(ref($record)) ) {
59                 return -1;
60         } else {
61             return $record, $encoding;
62         }
63     } else {
64         return -1;
65     }
66 }
67
68 sub build_authorized_values_list {
69     my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
70
71     my @authorised_values;
72     my %authorised_lib;
73
74
75     #---- branch
76     if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
77         my $sth =
78         $dbh->prepare(
79             "select branchcode,branchname from branches order by branchname");
80         $sth->execute;
81         push @authorised_values, ""
82         unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
83
84         while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
85             push @authorised_values, $branchcode;
86             $authorised_lib{$branchcode} = $branchname;
87         }
88     }
89     elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
90         push @authorised_values, ""
91           unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
92             && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
93
94         my $itemtype;
95         my $itemtypes = Koha::ItemTypes->search_with_localization;
96         while ( $itemtype = $itemtypes->next ) {
97             push @authorised_values, $itemtype->itemtype;
98             $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
99         }
100         $value = $itemtype unless ($value);
101
102         #---- "true" authorised value
103     }
104     else {
105         $authorised_values_sth->execute(
106             $tagslib->{$tag}->{$subfield}->{authorised_value} );
107
108         push @authorised_values, ""
109           unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
110             && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
111
112         while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
113             push @authorised_values, $value;
114             $authorised_lib{$value} = $lib;
115         }
116     }
117     return {
118         type     => 'select',
119         id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
120         name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
121         values   => \@authorised_values,
122         labels   => \%authorised_lib,
123         default  => $value,
124     };
125 }
126
127
128 =item create_input
129
130 builds the <input ...> entry for a subfield.
131
132 =cut
133
134 sub create_input {
135     my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
136     
137     my $index_subfield = CreateKey(); # create a specifique key for each subfield
138
139     # determine maximum length; 9999 bytes per ISO 2709 except for leader and MARC21 008
140     my $max_length = 9999;
141     if ($tag eq '000') {
142         $max_length = 24;
143     } elsif ($tag eq '008' and C4::Context->preference('marcflavour') eq 'MARC21')  {
144         $max_length = 40;
145     }
146
147     # if there is no value provided but a default value in parameters, get it
148     if ($value eq '') {
149         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
150         if (!defined $value) {
151             $value = q{};
152         }
153
154         # get today date & replace YYYY, MM, DD if provided in the default value
155         my ( $year, $month, $day ) = Today();
156         $month = sprintf( "%02d", $month );
157         $day   = sprintf( "%02d", $day );
158         $value =~ s/YYYY/$year/g;
159         $value =~ s/MM/$month/g;
160         $value =~ s/DD/$day/g;
161     }
162     my $dbh = C4::Context->dbh;
163
164     # map '@' as "subfield" label for fixed fields
165     # to something that's allowed in a div id.
166     my $id_subfield = $subfield;
167     $id_subfield = "00" if $id_subfield eq "@";
168
169     my %subfield_data = (
170         tag        => $tag,
171         subfield   => $id_subfield,
172         marc_lib       => $tagslib->{$tag}->{$subfield}->{lib},
173         tag_mandatory  => $tagslib->{$tag}->{mandatory},
174         mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
175         repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
176         kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
177         index          => $index_tag,
178         id             => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
179         value          => $value,
180         random         => CreateKey(),
181     );
182
183     if(exists $mandatory_z3950->{$tag.$subfield}){
184         $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
185     }
186     
187     $subfield_data{visibility} = "display:none;"
188         if( $tagslib->{$tag}->{$subfield}->{hidden} and $value ne ''
189             or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory})
190         );
191     
192     # it's an authorised field
193     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
194         $subfield_data{marc_value} =
195         build_authorized_values_list( $tag, $subfield, $value, $dbh,
196             $authorised_values_sth,$index_tag,$index_subfield );
197
198     # it's a thesaurus / authority field
199     }
200     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
201         $subfield_data{marc_value} = {
202             type         => 'text1',
203             id           => $subfield_data{id},
204             name         => $subfield_data{id},
205             value        => $value,
206             authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode},
207         };
208     }
209     elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) { # plugin
210         require Koha::FrameworkPlugin;
211         my $plugin = Koha::FrameworkPlugin->new({
212             name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
213         });
214         my $pars=  { dbh => $dbh, record => $rec, tagslib =>$tagslib,
215             id => $subfield_data{id}, tabloop => $tabloop };
216         $plugin->build( $pars );
217         if( !$plugin->errstr ) {
218             $subfield_data{marc_value} = {
219                 type       => 'text2',
220                 id        => $subfield_data{id},
221                 name      => $subfield_data{id},
222                 value     => $value,
223                 maxlength => $max_length,
224                 javascript => $plugin->javascript,
225                 noclick    => $plugin->noclick,
226             };
227         } else { # warn and supply default field
228             warn $plugin->errstr;
229             $subfield_data{marc_value} = {
230                 type      => 'text',
231                 id        => $subfield_data{id},
232                 name      => $subfield_data{id},
233                 value     => $value,
234                 maxlength => $max_length,
235             };
236         }
237     }
238     # it's an hidden field
239     elsif ( $tag eq '' ) {
240         $subfield_data{marc_value} = {
241             type      => 'hidden',
242             id        => $subfield_data{id},
243             name      => $subfield_data{id},
244             value     => $value,
245             maxlength => $max_length,
246         }
247     }
248     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
249         $subfield_data{marc_value} = {
250             type => 'text',
251             id        => $subfield_data{id},
252             name      => $subfield_data{id},
253             value     => $value,
254             maxlength => $max_length,
255         };
256
257         # it's a standard field
258     }
259     else {
260         if (
261             length($value) > 100
262             or
263             ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
264                 and $tag < 400 && $subfield eq 'a' )
265             or (    $tag >= 600
266                 and $tag < 700
267                 && C4::Context->preference("marcflavour") eq "MARC21" )
268         )
269         {
270             $subfield_data{marc_value} = {
271                 type => 'textarea',
272                 id        => $subfield_data{id},
273                 name      => $subfield_data{id},
274                 value     => $value,
275                 maxlength => $max_length,
276             };
277
278         }
279         else {
280             $subfield_data{marc_value} = {
281                 type => 'text',
282                 id        => $subfield_data{id},
283                 name      => $subfield_data{id},
284                 value     => $value,
285                 maxlength => $max_length,
286             };
287
288         }
289     }
290     $subfield_data{'index_subfield'} = $index_subfield;
291     return \%subfield_data;
292 }
293
294 =item format_indicator
295
296 Translate indicator value for output form - specifically, map
297 indicator = ' ' to ''.  This is for the convenience of a cataloger
298 using a mouse to select an indicator input.
299
300 =cut
301
302 sub format_indicator {
303     my $ind_value = shift;
304     return '' if not defined $ind_value;
305     return '' if $ind_value eq ' ';
306     return $ind_value;
307 }
308
309 =item CreateKey
310
311 Create a random value to set it into the input name
312
313 =cut
314
315 sub CreateKey {
316     return int(rand(1000000));
317 }
318
319 =item GetMandatoryFieldZ3950
320
321     This function returns a hashref which contains all mandatory field
322     to search with z3950 server.
323
324 =cut
325
326 sub GetMandatoryFieldZ3950 {
327     my $authtypecode = shift;
328     if ( C4::Context->preference('marcflavour') eq 'MARC21' ){
329         return {
330             '100a' => 'authorpersonal',
331             '110a' => 'authorcorp',
332             '111a' => 'authormeetingcon',
333             '130a' => 'uniformtitle',
334             '150a' => 'topic',
335         };
336     }else{
337         return {
338             '200a' => 'authorpersonal',
339             '210a' => 'authormeetingcon', #210 in UNIMARC is used for both corporation and meeting
340             '230a' => 'uniformtitle',
341         };
342     }
343 }
344
345 sub build_tabs {
346     my ( $template, $record, $dbh, $encoding,$input ) = @_;
347
348     # fill arrays
349     my @loop_data = ();
350     my $tag;
351
352     my $authorised_values_sth = $dbh->prepare(
353         "SELECT authorised_value,lib
354         FROM authorised_values
355         WHERE category=? ORDER BY lib"
356     );
357     
358     # in this array, we will push all the 10 tabs
359     # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
360     my @BIG_LOOP;
361     my %seen;
362     my @tab_data; # all tags to display
363     
364     foreach my $used ( keys %$tagslib ){
365         push @tab_data,$used if not $seen{$used};
366         $seen{$used}++;
367     }
368         
369     my $max_num_tab=9;
370     # loop through each tab 0 through 9
371     for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
372         my @loop_data = (); #innerloop in the template.
373         my $i = 0;
374         foreach my $tag (sort @tab_data) {
375             $i++;
376             next if ! $tag;
377             my ($indicator1, $indicator2);
378             my $index_tag = CreateKey;
379
380             # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
381             # if MARC::Record is empty => use tab as master loop.
382             if ( $record != -1 && ( $record->field($tag) || $tag eq '000' ) ) {
383                 my @fields;
384                 if ( $tag ne '000' ) {
385                                 @fields = $record->field($tag);
386                 }
387                 else {
388                 push @fields, $record->leader(); # if tag == 000
389                 }
390                 # loop through each field
391                 foreach my $field (@fields) {
392                     
393                     my @subfields_data;
394                     if ( $tag < 10 ) {
395                         my ( $value, $subfield );
396                         if ( $tag ne '000' ) {
397                             $value    = $field->data();
398                             $subfield = "@";
399                         }
400                         else {
401                             $value    = $field;
402                             $subfield = '@';
403                         }
404                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
405                         next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9';
406                         push(
407                             @subfields_data,
408                             &create_input(
409                                 $tag, $subfield, $value, $index_tag, $tabloop, $record,
410                                 $authorised_values_sth,$input
411                             )
412                         );
413                     }
414                     else {
415                         my @subfields = $field->subfields();
416                         foreach my $subfieldcount ( 0 .. $#subfields ) {
417                             my $subfield = $subfields[$subfieldcount][0];
418                             my $value    = $subfields[$subfieldcount][1];
419                             next if ( length $subfield != 1 );
420                             next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
421                             next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9';
422                             push(
423                                 @subfields_data,
424                                 &create_input(
425                                     $tag, $subfield, $value, $index_tag, $tabloop,
426                                     $record, $authorised_values_sth,$input
427                                 )
428                             );
429                         }
430                     }
431
432                     # now, loop again to add parameter subfield that are not in the MARC::Record
433                     foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
434                     {
435                         next if ( length $subfield != 1 );
436                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
437                         next if ( $tag < 10 );
438                         next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9';
439                         next if ( defined( $field->subfield($subfield) ) );
440                         push(
441                             @subfields_data,
442                             &create_input(
443                                 $tag, $subfield, '', $index_tag, $tabloop, $record,
444                                 $authorised_values_sth,$input
445                             )
446                         );
447                     }
448                     if ( $#subfields_data >= 0 ) {
449                         # build the tag entry.
450                         # note that the random() field is mandatory. Otherwise, on repeated fields, you'll 
451                         # have twice the same "name" value, and cgi->param() will return only one, making
452                         # all subfields to be merged in a single field.
453                         my %tag_data = (
454                             tag           => $tag,
455                             index         => $index_tag,
456                             tag_lib       => $tagslib->{$tag}->{lib},
457                             repeatable       => $tagslib->{$tag}->{repeatable},
458                             mandatory       => $tagslib->{$tag}->{mandatory},
459                             subfield_loop => \@subfields_data,
460                             fixedfield    => ($tag < 10)?(1):(0),
461                             random        => CreateKey,
462                         );
463                         if ($tag >= 10){ # no indicator for theses tag
464                             $tag_data{indicator1} = format_indicator($field->indicator(1)),
465                             $tag_data{indicator2} = format_indicator($field->indicator(2)),
466                         }
467                         push( @loop_data, \%tag_data );
468                     }
469                 } # foreach $field end
470
471             # if breeding is empty
472             }
473             else {
474                 my @subfields_data;
475                 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
476                     next if ( length $subfield != 1 );
477                     next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9';
478                     next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
479                     push(
480                         @subfields_data,
481                         &create_input(
482                             $tag, $subfield, '', $index_tag, $tabloop, $record,
483                             $authorised_values_sth,$input
484                         )
485                     );
486                 }
487                 if ( $#subfields_data >= 0 ) {
488                     my %tag_data = (
489                         tag              => $tag,
490                         index            => $index_tag,
491                         tag_lib          => $tagslib->{$tag}->{lib},
492                         repeatable       => $tagslib->{$tag}->{repeatable},
493                         mandatory       => $tagslib->{$tag}->{mandatory},
494                         indicator1       => $indicator1,
495                         indicator2       => $indicator2,
496                         subfield_loop    => \@subfields_data,
497                         tagfirstsubfield => $subfields_data[0],
498                         fixedfield       => ($tag < 10)?(1):(0)
499                     );
500                     
501                     push @loop_data, \%tag_data ;
502                 }
503             }
504         }
505         if ( $#loop_data >= 0 ) {
506             push @BIG_LOOP, {
507                 number    => $tabloop,
508                 innerloop => \@loop_data,
509             };
510         }
511     }
512     $template->param( BIG_LOOP => \@BIG_LOOP );
513 }
514
515
516 sub build_hidden_data {
517     # build hidden data =>
518     # we store everything, even if we show only requested subfields.
519
520     my @loop_data =();
521     my $i=0;
522     foreach my $tag (keys %{$tagslib}) {
523         my $previous_tag = '';
524
525         # loop through each subfield
526         foreach my $subfield (keys %{$tagslib->{$tag}}) {
527             next if ($subfield eq 'lib');
528             next if ($subfield eq 'tab');
529             next if ($subfield eq 'mandatory');
530                 next if ($subfield eq 'repeatable');
531             next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "-1");
532             my %subfield_data;
533             $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
534             $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
535             $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
536             $subfield_data{marc_value} = {
537                 type => 'hidden_simple',
538                 name => 'field_value[]',
539             };
540             push(@loop_data, \%subfield_data);
541             $i++
542         }
543     }
544 }
545
546 =back
547
548 =cut
549
550
551 # ======================== 
552 #          MAIN 
553 #=========================
554 my $input = new CGI;
555 my $z3950 = $input->param('z3950');
556 my $error = $input->param('error');
557 my $authid=$input->param('authid'); # if authid exists, it's a modif, not a new authority.
558 my $op = $input->param('op');
559 my $nonav = $input->param('nonav');
560 my $myindex = $input->param('index');
561 my $linkid=$input->param('linkid');
562 my $authtypecode = $input->param('authtypecode');
563 my $breedingid    = $input->param('breedingid');
564
565 my $dbh = C4::Context->dbh;
566 if(!$authtypecode) {
567     $authtypecode = $authid ? Koha::Authorities->find($authid)->authtypecode : '';
568 }
569
570 my ($template, $loggedinuser, $cookie)
571     = get_template_and_user({template_name => "authorities/authorities.tt",
572                             query => $input,
573                             type => "intranet",
574                             authnotrequired => 0,
575                             flagsrequired => {editauthorities => 1},
576                             debug => 1,
577                             });
578 $template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
579
580 $tagslib = GetTagsLabels(1,$authtypecode);
581 $mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
582
583 my $record=-1;
584 my $encoding="";
585 if (($authid) && !($breedingid)){
586     $record = GetAuthority($authid);
587 }
588 if ($breedingid) {
589     ( $record, $encoding ) = MARCfindbreeding_auth( $breedingid );
590 }
591
592 my ($oldauthnumtagfield,$oldauthnumtagsubfield);
593 my ($oldauthtypetagfield,$oldauthtypetagsubfield);
594 $is_a_modif=0;
595 if ($authid) {
596     $is_a_modif=1;
597     ($oldauthnumtagfield,$oldauthnumtagsubfield) = &GetAuthMARCFromKohaField("auth_header.authid",$authtypecode);
598     ($oldauthtypetagfield,$oldauthtypetagsubfield) = &GetAuthMARCFromKohaField("auth_header.authtypecode",$authtypecode);
599 }
600 $op ||= q{};
601 #------------------------------------------------------------------------------------------------------------------------------
602 if ($op eq "add") {
603 #------------------------------------------------------------------------------------------------------------------------------
604     # rebuild
605     my @tags = $input->multi_param('tag');
606     my @subfields = $input->multi_param('subfield');
607     my @values = $input->multi_param('field_value');
608     # build indicator hash.
609     my @ind_tag = $input->multi_param('ind_tag');
610     my @indicator = $input->multi_param('indicator');
611     my $record = TransformHtmlToMarc($input, 0);
612
613     my ($duplicateauthid,$duplicateauthvalue);
614      ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
615     my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
616     # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
617     if (!$duplicateauthid or $confirm_not_duplicate) {
618         if ($is_a_modif ) {     
619             ModAuthority($authid,$record,$authtypecode);
620         } else {
621             ($authid) = AddAuthority($record,$authid,$authtypecode);
622         }
623         if ($myindex) {
624             print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
625         } else {
626             print $input->redirect("detail.pl?authid=$authid");
627         }
628         exit;
629     } else {
630     # it may be a duplicate, warn the user and do nothing
631         build_tabs($template, $record, $dbh, $encoding,$input);
632         build_hidden_data;
633         $template->param(authid =>$authid,
634                         duplicateauthid     => $duplicateauthid,
635                         duplicateauthvalue  => $duplicateauthvalue->{'authorized'}->[0]->{'heading'},
636                         );
637     }
638 } elsif ($op eq "delete") {
639 #------------------------------------------------------------------------------------------------------------------------------
640         DelAuthority({ authid => $authid });
641         if ($nonav){
642             print $input->redirect("auth_finder.pl");
643         }else{
644             print $input->redirect("authorities-home.pl?authid=0");
645         }
646                 exit;
647 } else {
648 if ($op eq "duplicate")
649         {
650                 $authid = "";
651         }
652         build_tabs ($template, $record, $dbh,$encoding,$input);
653         build_hidden_data;
654         $template->param(oldauthtypetagfield=>$oldauthtypetagfield, oldauthtypetagsubfield=>$oldauthtypetagsubfield,
655                         oldauthnumtagfield=>$oldauthnumtagfield, oldauthnumtagsubfield=>$oldauthnumtagsubfield,
656                         authid                      => $authid , authtypecode=>$authtypecode,   );
657 }
658
659 my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } );
660
661 my $type = $authority_types->find($authtypecode);
662 $template->param(
663     authority_types => $authority_types,
664     authtypecode    => $authtypecode,
665     authid          => $authid,
666     linkid          => $linkid,
667     authtypetext    => $type ? $type->authtypetext : "",
668     hide_marc       => C4::Context->preference('hide_marc'),
669 );
670 output_html_with_http_headers $input, $cookie, $template->output;