Minor changes to systempreferences markup, including re-adding edit link on system...
[koha.git] / admin / systempreferences.pl
1 #!/usr/bin/perl
2
3 #script to administer the systempref table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 =head1 systempreferences.pl
25
26 ALGO :
27  this script use an $op to know what to do.
28  if $op is empty or none of the above values,
29     - the default screen is build (with all records, or filtered datas).
30     - the   user can clic on add, modify or delete record.
31  if $op=add_form
32     - if primkey exists, this is a modification,so we read the $primkey record
33     - builds the add/modify form
34  if $op=add_validate
35     - the user has just send datas, so we create/modify the record
36  if $op=delete_form
37     - we show the record having primkey=$primkey and ask for deletion validation form
38  if $op=delete_confirm
39     - we delete the record having primkey=$primkey
40
41 =cut
42
43 use strict;
44 use CGI;
45 use C4::Auth;
46 use C4::Context;
47 use C4::Koha;
48 use C4::Languages;
49 use C4::ClassSource;
50 use C4::Output;
51 use C4::Context;
52
53 # use Smart::Comments;
54
55
56 # FIXME, shouldnt we store this stuff in the systempreferences table? 
57
58 my %tabsysprefs;
59 # Acquisitions
60     $tabsysprefs{acquisitions}="Acquisitions";
61     $tabsysprefs{gist}="Acquisitions";
62 # Admin
63     $tabsysprefs{dateformat}="Admin";
64     $tabsysprefs{delimiter}="Admin";
65     $tabsysprefs{IndependantBranches}="Admin";
66     $tabsysprefs{HomeOrHoldingBranch}="Admin";
67     $tabsysprefs{insecure}="Admin";
68     $tabsysprefs{KohaAdmin}="Admin";
69     $tabsysprefs{KohaAdminEmailAddress}="Admin";
70     $tabsysprefs{MIME}="Admin";
71     $tabsysprefs{timeout}="Admin";
72     $tabsysprefs{Intranet_includes}="Admin";
73     $tabsysprefs{AutoLocation}="Admin";
74     $tabsysprefs{DebugLevel}="Admin";
75     $tabsysprefs{SessionStorage}="Admin";
76
77 # Authorities
78     $tabsysprefs{authoritysep}="Authorities";
79     $tabsysprefs{AuthDisplayHierarchy}="Authorities";
80     $tabsysprefs{dontmerge}="Authorities";
81     $tabsysprefs{BiblioAddsAuthorities}="Authorities";
82 # Catalogue
83     $tabsysprefs{advancedMARCEditor}="Catalogue";
84     $tabsysprefs{autoBarcode}="Catalogue";
85     $tabsysprefs{hide_marc}="Catalogue";
86     $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
87     $tabsysprefs{ISBD}="Catalogue";
88     $tabsysprefs{itemcallnumber}="Catalogue";
89     $tabsysprefs{LabelMARCView}="Catalogue";
90     $tabsysprefs{marc}="Catalogue";
91     $tabsysprefs{marcflavour}="Catalogue";
92     $tabsysprefs{serialsadditems}="Catalogue";
93     $tabsysprefs{sortbynonfiling}="Catalogue";
94     $tabsysprefs{MARCOrgCode}="Catalogue";
95     $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
96     $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
97     $tabsysprefs{Stemming}="Catalogue";
98     $tabsysprefs{WeightFields}="Catalogue";
99     $tabsysprefs{expandedSearchOption}="Catalogue";
100     $tabsysprefs{NoZebra}="Catalogue";
101     $tabsysprefs{NoZebraIndexes}="Catalogue";
102     $tabsysprefs{ReceiveBackIssues}="Catalogue";
103     $tabsysprefs{DefaultClassificationSource}="Catalogue";
104     $tabsysprefs{RoutingSerials}="Catalogue";
105     $tabsysprefs{'item-level_itypes'}="Catalogue";
106
107 # Circulation
108     $tabsysprefs{maxoutstanding}="Circulation";
109     $tabsysprefs{maxreserves}="Circulation";
110     $tabsysprefs{noissuescharge}="Circulation";
111     $tabsysprefs{IssuingInProcess}="Circulation";
112     $tabsysprefs{patronimages}="Circulation";
113     $tabsysprefs{printcirculationslips}="Circulation";
114     $tabsysprefs{ReturnBeforeExpiry}="Circulation";
115     $tabsysprefs{SpecifyDueDate}="Circulation";
116     $tabsysprefs{AutomaticItemReturn}="Circulation";
117     $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
118     $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
119     $tabsysprefs{useDaysMode}="Circulation";
120     $tabsysprefs{ReservesNeedReturns}="Circulation";
121     $tabsysprefs{CircAutocompl}="Circulation";
122     $tabsysprefs{canreservefromotherbranches}="Circulation";
123
124 # Intranet
125     $tabsysprefs{TemplateEncoding}="Intranet";
126     $tabsysprefs{template}="Intranet";
127     $tabsysprefs{intranetstylesheet}="Intranet";
128     $tabsysprefs{IntranetNav}="Intranet";
129     $tabsysprefs{intranetcolorstylesheet}="Intranet";
130     $tabsysprefs{intranetuserjs}="Intranet";
131         $tabsysprefs{yuipath}="Intranet";
132         $tabsysprefs{IntranetmainUserblock}="Intranet";
133         
134 # Members
135     $tabsysprefs{automembernum}="Members";
136     $tabsysprefs{checkdigit}="Members";
137     $tabsysprefs{intranetreadinghistory}="Members";
138     $tabsysprefs{NotifyBorrowerDeparture}="Members";
139     $tabsysprefs{memberofinstitution}="Members";
140     $tabsysprefs{ReadingHistory}="Members";
141     $tabsysprefs{BorrowerMandatoryField}="Members";
142     $tabsysprefs{borrowerRelationship}="Members";
143     $tabsysprefs{BorrowersTitles}="Members";    
144     $tabsysprefs{patronimages}="Members";
145     $tabsysprefs{MinPasswordLength}="Members";
146     $tabsysprefs{uppercasesurnames}="Members";
147     $tabsysprefs{NoReturnSetLost}="Members";
148     $tabsysprefs{MaxFine}="Members";
149     $tabsysprefs{NotifyBorrowerDeparture}="Members";
150 # FRBA
151         $tabsysprefs{FRBRizeEditions}="FRBR";
152         $tabsysprefs{XISBN}="FRBR";
153         $tabsysprefs{OCLCAffiliateID}="FRBR";
154         $tabsysprefs{XISBNDailyLimit}="FRBR";
155         $tabsysprefs{PINESISBN}="FRBR";
156     $tabsysprefs{ThingISBN}="FRBR";
157     $tabsysprefs{OPACFRBRizeEditions}="FRBR";
158     $tabsysprefs{XISBNAmazonSimilarItems}="FRBR";
159
160 # OPAC
161     $tabsysprefs{AmazonAssocTag}="OPAC";
162     $tabsysprefs{AmazonSimilarItems}="OPAC";
163     $tabsysprefs{AmazonContent}="OPAC";
164     $tabsysprefs{OPACAmazonContent}="OPAC";
165     $tabsysprefs{AmazonDevKey}="OPAC";
166     $tabsysprefs{BiblioDefaultView}="OPAC";
167     $tabsysprefs{LibraryName}="OPAC";
168     $tabsysprefs{opaccolorstylesheet}="OPAC";
169     $tabsysprefs{opaccredits}="OPAC";
170     $tabsysprefs{opaclanguages}="OPAC";
171     $tabsysprefs{opaclargeimage}="OPAC";
172     $tabsysprefs{opaclayoutstylesheet}="OPAC";
173     $tabsysprefs{OpacNav}="OPAC";
174     $tabsysprefs{opacsmallimage}="OPAC";
175     $tabsysprefs{opacstylesheet}="OPAC";
176     $tabsysprefs{opacthemes}="OPAC";
177     $tabsysprefs{opacuserjs}="OPAC";
178     $tabsysprefs{SubscriptionHistory}="OPAC";
179     $tabsysprefs{opacheader}="OPAC";
180     $tabsysprefs{OPACAmazonSimilarItems}="OPAC";
181     $tabsysprefs{OPACXISBNAmazonSimilarItems}="OPAC";
182     
183 # OPACFeatures
184         $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
185     $tabsysprefs{Disable_Dictionary}="OPACFeatures";
186     $tabsysprefs{hidelostitems}="OPACFeatures";
187     $tabsysprefs{opacbookbag}="OPACFeatures";
188     $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
189     $tabsysprefs{OpacPasswordChange}="OPACFeatures";
190     $tabsysprefs{opacreadinghistory}="OPACFeatures";
191     $tabsysprefs{virtualshelves}="OPACFeatures";
192     $tabsysprefs{RequestOnOpac}="OPACFeatures";
193     $tabsysprefs{reviewson}="OPACFeatures";
194     $tabsysprefs{OpacTopissues}="OPACFeatures";
195     $tabsysprefs{OpacAuthorities}="OPACFeatures";
196     $tabsysprefs{OpacCloud}="OPACFeatures";
197     $tabsysprefs{opacuserlogin}="OPACFeatures";
198     $tabsysprefs{AnonSuggestions}="OPACFeatures";
199     $tabsysprefs{suggestion}="OPACFeatures";
200     $tabsysprefs{OpacTopissue}="OPACFeatures";
201     $tabsysprefs{OpacBrowser}="OPACFeatures";
202     $tabsysprefs{kohaspsuggest} = "OPACFeatures";
203
204 # LOGFeatures
205     $tabsysprefs{CataloguingLog}  = "LOGFeatures";
206     $tabsysprefs{BorrowersLog}    = "LOGFeatures";
207     $tabsysprefs{SubscriptionLog} = "LOGFeatures";
208     $tabsysprefs{IssueLog}        = "LOGFeatures";
209     $tabsysprefs{ReturnLog}       = "LOGFeatures";
210     $tabsysprefs{LetterLog}       = "LOGFeatures";
211     $tabsysprefs{FinesLog}        = "LOGFeatures";
212     
213 sub StringSearch  {
214     my ($searchstring,$type)=@_;
215     my $dbh = C4::Context->dbh;
216     $searchstring=~ s/\'/\\\'/g;
217     my @data=split(' ',$searchstring);
218     my $count=@data;
219     my @results;
220     my $cnt=0;
221
222     # used for doing a plain-old sys-pref search
223     if ($type eq 'all' ){
224         my $sth=$dbh->prepare("SELECT * FROM systempreferences 
225                 WHERE variable LIKE ? OR explanation LIKE ? 
226                 ORDER BY VARIABLE");
227         $sth->execute("%$searchstring%", "%$searchstring%");
228         while (my $data=$sth->fetchrow_hashref){
229             $data->{value} =~ s/</&lt;/g;
230             $data->{value} =~ s/>/&gt;/g;
231             $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
232             push(@results,$data);
233             $cnt++;
234         }
235         $sth->finish;
236
237     }  elsif ($type){
238         foreach my $syspref (sort keys %tabsysprefs){
239             if ($tabsysprefs{$syspref} eq $type){
240                 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
241                 $sth->execute($syspref);
242                 while (my $data=$sth->fetchrow_hashref){
243                     $data->{value} =~ s/</&lt;/g;
244                     $data->{value} =~ s/>/&gt;/g;
245                     $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
246                     push(@results,$data);
247                     $cnt++;
248                 }
249                 $sth->finish;
250             }
251         }
252     } else {
253         my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
254         foreach my $syspref (keys %tabsysprefs){
255             $strsth .= $dbh->quote($syspref).",";
256         }
257         $strsth =~ s/,$/) /;
258         $strsth .= " order by variable";
259         my $sth=$dbh->prepare($strsth);
260         $sth->execute();
261         while (my $data=$sth->fetchrow_hashref){
262             $data->{value}=substr($data->{value},0,100);
263             push(@results,$data);
264             $cnt++;
265         }
266         $sth->finish;
267     }
268     return ($cnt,\@results);
269 }
270
271 my $input = new CGI;
272 my $searchfield=$input->param('searchfield');
273 my $offset=$input->param('offset');
274 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
275
276 my ($template, $borrowernumber, $cookie)
277     = get_template_and_user({template_name => "admin/systempreferences.tmpl",
278                  query => $input,
279                  type => "intranet",
280                  authnotrequired => 0,
281                  flagsrequired => {parameters => 1},
282                  debug => 1,
283                  });
284 my $pagesize=100;
285 my $op = $input->param('op');
286 $searchfield=~ s/\,//g;
287
288 if ($op) {
289 $template->param(script_name => $script_name,
290                         $op              => 1); # we show only the TMPL_VAR names $op
291 } else {
292 $template->param(script_name => $script_name,
293                         else              => 1); # we show only the TMPL_VAR names $op
294 }
295
296 if ($op eq 'update_and_reedit') {
297     foreach ($input->param) {
298     }
299     my $value='';
300     if (my $currentorder=$input->param('currentorder')) {
301         my @currentorder=split /\|/, $currentorder;
302         my $orderchanged=0;
303         foreach my $param ($input->param) {
304             if ($param=~m#up-(\d+).x#) {
305                 my $temp=$currentorder[$1];
306                 $currentorder[$1]=$currentorder[$1-1];
307                 $currentorder[$1-1]=$temp;
308                 $orderchanged=1;
309                 last;
310             } elsif ($param=~m#down-(\d+).x#) {
311                 my $temp=$currentorder[$1];
312                 $currentorder[$1]=$currentorder[$1+1];
313                 $currentorder[$1+1]=$temp;
314                 $orderchanged=1;
315                 last;
316             }
317         }
318         $value=join ' ', @currentorder;
319         if ($orderchanged) {
320             $op='add_form';
321             $template->param(script_name => $script_name,
322                             $op              => 1); # we show only the TMPL_VAR names $op
323         } else {
324             $op='';
325             $searchfield='';
326             $template->param(script_name => $script_name,
327                             else              => 1); # we show only the TMPL_VAR names $op
328         }
329     }
330     my $dbh = C4::Context->dbh;
331     my $query="select * from systempreferences where variable=?";
332     my $sth=$dbh->prepare($query);
333     $sth->execute($input->param('variable'));
334     if ($sth->rows) {
335         unless (C4::Context->config('demo') eq 1) {
336             my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
337             $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
338             $sth->finish;
339         }
340     } else {
341         unless (C4::Context->config('demo') eq 1) {
342             my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
343             $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
344             $sth->finish;
345         }
346     }
347     $sth->finish;
348
349 }
350
351 ################## ADD_FORM ##################################
352 # called by default. Used to create form to add or  modify a record
353
354 if ($op eq 'add_form') {
355     #---- if primkey exists, it's a modify action, so read values to modify...
356     my $data;
357     if ($searchfield) {
358         my $dbh = C4::Context->dbh;
359         my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
360         $sth->execute($searchfield);
361         $data=$sth->fetchrow_hashref;
362         $sth->finish;
363         $template->param(modify => 1);
364     }
365
366     my @options;
367     foreach my $option (split(/\|/, $data->{'options'})) {
368         my $selected='0';
369         $option eq $data->{'value'} and $selected=1;
370         push @options, { option => $option, selected => $selected };
371     }
372     if ($data->{'type'} eq 'Choice') {
373         $template->param('type-choice' => 1);
374     } elsif ($data->{'type'} eq 'YesNo') {
375         $template->param('type-yesno' => 1);
376         $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
377         ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
378     } elsif ($data->{'type'} eq 'Integer') {
379         $template->param('type-free' => 1);
380         $template->param('fieldlength' => $data->{'options'});
381     } elsif ($data->{'type'} eq 'Textarea') {
382         $template->param('type-textarea' => 1);
383         $data->{options} =~ /(.*)\|(.*)/;
384         $template->param('cols' => $1, 'rows' => $2);;
385     } elsif ($data->{'type'} eq 'Float') {
386         $template->param('type-free' => 1);
387         $template->param('fieldlength' => $data->{'options'});
388     } elsif ($data->{'type'} eq 'Themes') {
389         $template->param('type-choice' => 1);
390         my $type='';
391         ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
392         @options=();
393         my $currently_selected_themes;
394         my $counter=0;
395         foreach my $theme (split /\s+/, $data->{'value'}) {
396             push @options, { option => $theme, counter => $counter };
397             $currently_selected_themes->{$theme}=1;
398             $counter++;
399         }
400         foreach my $theme (getallthemes($type)) {
401             my $selected='0';
402             next if $currently_selected_themes->{$theme};
403             push @options, { option => $theme, counter => $counter };
404             $counter++;
405         }
406     } elsif ($data->{'type'} eq 'ClassSources') {
407         $template->param('type-choice' => 1);
408         my $type='';
409         @options=();
410         my $sources = GetClassSources();
411         my $counter=0;
412         foreach my $cn_source (sort keys %$sources) {
413             if ($cn_source eq $data->{'value'}) {
414                 push @options, { option => $cn_source, counter => $counter, selected => 1 };
415             } else {
416                 push @options, { option => $cn_source, counter => $counter };
417             }
418             $counter++; 
419         }
420     } elsif ($data->{'type'} eq 'Languages') {
421         $template->param('type-choice' => 1);
422         my $type='';
423         @options=();
424         my $currently_selected_languages;
425         my $counter=0;
426         foreach my $language (split /\s+/, $data->{'value'}) {
427             next if $language eq 'images';
428             push @options, { option => $language, counter => $counter };
429             $currently_selected_languages->{$language}=1;
430             $counter++;
431         }
432                 my $langavail = getTranslatedLanguages();
433         foreach my $language (@$langavail) {
434             my $selected='0';
435             next if $currently_selected_languages->{$language->{'language_code'}};
436                         #FIXME: could add language_name and language_locale_name for better display
437             push @options, { option => $language->{'language_code'}, counter => $counter };
438             $counter++;
439         }
440     } else {
441         $template->param('type-free' => 1);
442         $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
443     }
444     $template->param(explanation => $data->{'explanation'},
445              value => $data->{'value'},
446              type => $data->{'type'},
447              options => \@options,
448              preftype => $data->{'type'},
449              prefoptions => $data->{'options'},
450              searchfield => $searchfield);
451
452 ################## ADD_VALIDATE ##################################
453 # called by add_form, used to insert/modify data in DB
454 } elsif ($op eq 'add_validate') {
455     my $dbh = C4::Context->dbh;
456     my $sth=$dbh->prepare("select * from systempreferences where variable=?");
457     $sth->execute($input->param('variable'));
458     if ($sth->rows) {
459         unless (C4::Context->config('demo') eq 1) {
460             my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
461             $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
462             $sth->finish;
463         }
464     } else {
465         unless (C4::Context->config('demo') eq 1) {
466             my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
467             $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
468             $sth->finish;
469         }
470     }
471     $sth->finish;
472     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
473     exit;
474 ################## DELETE_CONFIRM ##################################
475 # called by default form, used to confirm deletion of data in DB
476 } elsif ($op eq 'delete_confirm') {
477     my $dbh = C4::Context->dbh;
478     my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
479     $sth->execute($searchfield);
480     my $data=$sth->fetchrow_hashref;
481     $sth->finish;
482     $template->param(searchfield => $searchfield,
483                             Tvalue => $data->{'value'},
484                             );
485
486                                                     # END $OP eq DELETE_CONFIRM
487 ################## DELETE_CONFIRMED ##################################
488 # called by delete_confirm, used to effectively confirm deletion of data in DB
489 } elsif ($op eq 'delete_confirmed') {
490     my $dbh = C4::Context->dbh;
491     my $sth=$dbh->prepare("delete from systempreferences where variable=?");
492     $sth->execute($searchfield);
493     $sth->finish;
494
495                                                     # END $OP eq DELETE_CONFIRMED
496 ################## DEFAULT ##################################
497 } else { # DEFAULT
498     #Adding tab management for system preferences
499     my $tab=$input->param('tab');
500     my ($count,$results)=StringSearch($searchfield,$tab);
501     my $toggle=0;
502     my @loop_data = ();
503     for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
504           if ($toggle eq 0){
505             $toggle=1;
506           } else {
507             $toggle=0;
508           }
509         my %row_data;  # get a fresh hash for the row data
510         $row_data{variable} = $results->[$i]{'variable'};
511         $row_data{value} = $results->[$i]{'value'};
512                 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
513                 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
514         $row_data{explanation} = $results->[$i]{'explanation'};
515         $row_data{toggle} = $toggle;
516         $row_data{edit} = "$script_name?op=add_form&amp;searchfield=".$results->[$i]{'variable'};
517         $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'variable'};
518         push(@loop_data, \%row_data);
519     }
520     $tab=($tab?$tab:"Others");
521     $template->param(loop => \@loop_data, $tab => 1);
522     if ($offset>0) {
523         my $prevpage = $offset-$pagesize;
524         $template->param("<a href=$script_name?offset=".$prevpage.'&lt;&lt; Prev</a>');
525     }
526     if ($offset+$pagesize<$count) {
527         my $nextpage =$offset+$pagesize;
528         $template->param("a href=$script_name?offset=".$nextpage.'Next &gt;&gt;</a>');
529     }
530     $template->param(        tab => $tab,
531             );
532 } #---- END $OP eq DEFAULT
533 output_html_with_http_headers $input, $cookie, $template->output;