1 #!/usr/bin/perl -w # please develop with -w
9 use C4::Languages qw(getAllLanguages getTranslatedLanguages);
11 use strict; # please develop with the strict pragma
16 my $step = $query->param('step');
18 my $language = $query->param('language');
19 my ( $template, $loggedinuser, $cookie );
21 my $all_languages = getAllLanguages();
23 if ( defined($language) ) {
24 setlanguagecookie( $query, $language, "install.pl?step=1" );
26 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
28 template_name => "installer/step" . ( $step ? $step : 1 ) . ".tmpl",
37 $info{'dbname'} = C4::Context->config("database");
39 ( C4::Context->config("db_scheme")
40 ? C4::Context->config("db_scheme")
42 $info{'hostname'} = C4::Context->config("hostname");
43 $info{'port'} = C4::Context->config("port");
44 $info{'user'} = C4::Context->config("user");
45 $info{'password'} = C4::Context->config("pass");
46 my $dbh = DBI->connect(
47 "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}"
48 . ( $info{port} ? ";port=$info{port}" : "" ),
49 $info{'user'}, $info{'password'}
52 if ( $step && $step == 1 ) {
54 #Checking ALL perl Modules and services needed are installed.
55 #Whenever there is an error, adding a report to the page
56 $template->param( language => 1 );
59 unless ( $] >= 5.006001 ) { # Bug 179
60 $template->param( "problems" => 1, "perlversion" => 1 );
64 # We could here use a special find
66 unless ( eval { require ZOOM } ) {
67 push @missing, { name => "ZOOM" };
69 unless ( eval { require YAML::Syck } ) {
70 push @missing, { name => "YAML::Syck" };
72 unless ( eval { require LWP::Simple } ) {
73 push @missing, { name => "LWP::Simple" };
75 unless ( eval { require XML::Simple } ) {
76 push @missing, { name => "XML::Simple" };
78 unless ( eval { require MARC::File::XML } ) {
79 push @missing, { name => "MARC::File::XML" };
81 unless ( eval { require MARC::File::USMARC } ) {
82 push @missing, { name => "MARC::File::USMARC" };
84 unless ( eval { require DBI } ) {
85 push @missing, { name => "DBI" };
87 unless ( eval { require Date::Manip } ) {
88 push @missing, { name => "Date::Manip" };
90 unless ( eval { require DBD::mysql } ) {
91 push @missing, { name => "DBD::mysql" };
93 unless ( eval { require HTML::Template::Pro } ) {
94 push @missing, { name => "HTML::Template::Pro" };
96 unless ( eval { require Date::Calc } ) {
97 push @missing, { name => "Date::Calc" };
99 unless ( eval { require Digest::MD5 } ) {
100 push @missing, { name => "Digest::MD5" };
102 unless ( eval { require MARC::Record } ) {
103 push @missing, { name => "MARC::Record" };
105 unless ( eval { require Mail::Sendmail } ) {
106 push @missing, { name => "Mail::Sendmail", usagemail => 1 };
108 unless ( eval { require List::MoreUtils } ) {
109 push @missing, { name => "List::MoreUtils" };
111 unless ( eval { require XML::RSS } ) {
112 push @missing, { name => "XML::RSS" };
114 unless ( eval { require CGI::Carp } ) {
115 push @missing, { name => "CGI::Carp" };
119 # The following modules are not mandatory, depends on how the library want to use Koha
120 unless ( eval { require PDF::API2 } ) {
121 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
122 push @missing, { name => "PDF::API2", usagebarcode => 1 };
125 unless ( eval { require GD::Barcorde } ) {
126 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
128 { name => "GD::Barcode", usagebarcode => 1, usagespine => 1 };
131 unless ( eval { require Data::Random } ) {
132 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
133 push @missing, { name => "Data::Random", usagebarcode => 1 };
136 unless ( eval { require PDF::Reuse::Barcode } ) {
137 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
138 push @missing, { name => "PDF::Reuse::Barcode", usagebarcode => 1 };
141 unless ( eval { require PDF::Report } ) {
142 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
143 push @missing, { name => "PDF::Report", usagebarcode => 1 };
146 unless ( eval { require Algorithm::CheckDigits } ) {
147 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
148 push @missing, { name => "Algorithm::CheckDigits", usagebarcode => 1 };
151 unless ( eval { require GD::Barcode::UPCE } ) {
152 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
153 push @missing, { name => "GD::Barcode::UPCE", usagepine => 1 };
156 unless ( eval { require Net::LDAP } ) {
157 if ( $#missing >= 0 ) { # only when $#missing >= 0 so this isn't fatal
158 push @missing, { name => "Net::LDAP", usageLDAP => 1 };
161 $template->param( missings => \@missing ) if ( scalar(@missing) > 0 );
162 $template->param( 'checkmodule' => 1 )
163 unless ( scalar(@missing) && $problem );
166 elsif ( $step && $step == 2 ) {
168 #STEP 2 Check Database connection and access
170 $template->param(%info);
171 my $checkdb = $query->param("checkdb");
172 $template->param( 'dbconnection' => $checkdb );
176 # Can connect to the mysql
177 $template->param( "checkdatabaseaccess" => 1 );
178 if ( $info{dbms} eq "mysql" ) {
180 #Check if database created
181 my $rv = $dbh->do("SHOW DATABASES LIKE \'$info{dbname}\'");
183 $template->param( 'checkdatabasecreated' => 1 );
186 #Check if user have all necessary grants on this database.
189 "SHOW GRANTS FOR \'$info{user}\'\@'$info{hostname}'");
192 while ( my ($line) = $rq->fetchrow ) {
193 my $dbname = $info{dbname};
194 if ( $line =~ m/^GRANT (.*?) ON `$dbname`\.\*/ || index( $line, '*.*' ) > 0 ) {
197 index( $line, 'ALL PRIVILEGES' ) > 0
198 || ( ( index( $line, 'SELECT' ) > 0 )
199 && ( index( $line, 'INSERT' ) > 0 )
200 && ( index( $line, 'UPDATE' ) > 0 )
201 && ( index( $line, 'DELETE' ) > 0 )
202 && ( index( $line, 'CREATE' ) > 0 )
203 && ( index( $line, 'DROP' ) > 0 ) )
207 unless ($grantaccess) {
209 $dbh->prepare("SHOW GRANTS FOR \'$info{user}\'\@'\%'");
211 while ( my ($line) = $rq->fetchrow ) {
212 my $dbname = $info{dbname};
213 if ( $line =~ m/$dbname/ || index( $line, '*.*' ) > 0 )
217 index( $line, 'ALL PRIVILEGES' ) > 0
218 || ( ( index( $line, 'SELECT' ) > 0 )
219 && ( index( $line, 'INSERT' ) > 0 )
220 && ( index( $line, 'UPDATE' ) > 0 )
221 && ( index( $line, 'DELETE' ) > 0 )
222 && ( index( $line, 'CREATE' ) > 0 )
223 && ( index( $line, 'DROP' ) > 0 ) )
228 $template->param( "checkgrantaccess" => $grantaccess );
229 } # End mysql connect check...
231 elsif ( $info{dbms} eq "Pg" ) {
232 # Check if database has been created...
233 my $rv = $dbh->do( "SELECT * FROM pg_catalog.pg_database WHERE datname = \'$info{dbname}\';" );
235 $template->param( 'checkdatabasecreated' => 1 );
238 # Check if user has all necessary grants on this database...
239 my $rq = $dbh->do( "SELECT u.usesuper
240 FROM pg_catalog.pg_user as u
241 WHERE u.usename = \'$info{user}\';" );
243 $template->param( "checkgrantaccess" => 1 );
245 } # End Pg connect check...
248 $template->param( "error" => DBI::err, "message" => DBI::errstr );
252 elsif ( $step && $step == 3 ) {
255 # STEP 3 : database setup
258 my $op = $query->param('op');
259 if ( $op && $op eq 'finished' ) {
261 # we have finished, just redirect to mainpage.
263 print $query->redirect("/cgi-bin/koha/mainpage.pl");
266 elsif ( $op && $op eq 'finish' ) {
267 my $kohaversion=C4::Context::KOHAVERSION;
268 # remove the 3 last . to have a Perl number
269 $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
270 if (C4::Context->preference('Version')) {
271 warn "UPDATE Version";
272 my $finish=$dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
273 $finish->execute($kohaversion);
275 warn "INSERT Version";
276 my $finish=$dbh->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')");
277 $finish->execute($kohaversion);
280 # Installation is finished.
281 # We just deny anybody access to install
282 # And we redirect people to mainpage.
283 # The installer will have to relogin since we do not pass cookie to redirection.
284 $template->param( "$op" => 1 );
286 elsif ( $op && $op eq 'SetIndexingEngine' ) {
287 if ($query->param('NoZebra')) {
288 $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='NoZebra'");
289 $dbh->do("UPDATE systempreferences SET value=0 WHERE variable in ('QueryFuzzy','QueryWeightFields','QueryStemming')");
291 $dbh->do("UPDATE systempreferences SET value=0 WHERE variable='NoZebra'");
293 $template->param( "$op" => 1 );
295 elsif ( $op && $op eq 'addframeworks' ) {
297 # 1ST install, 3rd sub-step : insert the SQL files the user has selected
300 #Framework importing and reports
304 # sort by filename -> prepend with numbers to specify order of insertion.
306 my @aa = split /\/|\\/, ($a);
307 my @bb = split /\/|\\/, ($b);
309 } $query->param('framework');
312 "SELECT value FROM systempreferences WHERE variable='FrameworksLoaded'"
315 my ($systempreference) = $request->fetchrow;
316 $systempreference = '' unless defined $systempreference; # avoid warning
317 foreach my $file (@fnames) {
322 if ( $info{dbms} eq 'mysql' ) {
323 my $strcmd = "mysql "
324 . ( $info{hostname} ? " -h $info{hostname} " : "" )
325 . ( $info{port} ? " -P $info{port} " : "" )
326 . ( $info{user} ? " -u $info{user} " : "" )
327 . ( $info{password} ? " -p'$info{password}'" : "" )
329 $error = qx($strcmd < $file 2>&1 1>/dev/null); # We want to send stdout to null and return only stderr... -fbcit
331 elsif ( $info{dbms} eq 'Pg' ) {
333 . ( $info{hostname} ? " -h $info{hostname} " : "" )
334 . ( $info{port} ? " -p $info{port} " : "" )
335 . ( $info{user} ? " -U $info{user} " : "" )
336 # . ( $info{password} ? " -W $info{password}" : "" )
338 $error = qx($strcmd -f $file 2>&1 1>/dev/null); # ...even more so with psql...
340 my @file = split qr(\/|\\), $file;
341 $lang = $file[ scalar(@file) - 3 ] unless ($lang);
342 my $level = $file[ scalar(@file) - 2 ];
344 $systempreference .= "$file[scalar(@file)-1]|"
346 index( $systempreference, $file[ scalar(@file) - 1 ] ) >=
350 #Bulding here a hierarchy to display files by level.
351 push @{ $hashlevel{$level} },
352 { "fwkname" => $file[ scalar(@file) - 1 ], "error" => $error };
355 #systempreference contains an ending |
356 chop $systempreference;
358 map { push @list, { "level" => $_, "fwklist" => $hashlevel{$_} } }
361 for my $each_language (@$all_languages) {
363 # warn "CODE".$each_language->{'language_code'};
364 # warn "LANG:".$lang;
365 if ( $lang eq $each_language->{'language_code'} ) {
366 $fwk_language = $each_language->{language_locale_name};
371 "UPDATE systempreferences set value=\"$systempreference\" where variable='FrameworksLoaded'"
373 unless ( $updateflag == 1 ) {
375 "INSERT INTO systempreferences (value, variable, explanation, type) VALUES (\"$systempreference\",'FrameworksLoaded','Frameworks loaded through webinstaller','choice')";
376 my $rq = $dbh->prepare($string);
380 "fwklanguage" => $fwk_language,
383 $template->param( "$op" => 1 );
385 elsif ( $op && $op eq 'selectframeworks' ) {
388 # 1ST install, 2nd sub-step : show the user the sql datas he can insert in the database.
391 # (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks)
394 #sql data for import are supposed to be located in installer/data/<language>/<level>
395 # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
396 # Where <level> is a category of requirement : required, recommended optional
397 # level should contain :
398 # SQL File for import With a readable name.
399 # txt File taht explains what this SQL File is meant for.
400 # Could be VERY useful to have A Big file for a kind of library.
401 # But could also be useful to have some Authorised values data set prepared here.
402 # Framework Selection is achieved through checking boxes.
403 my $langchoice = $query->param('fwklanguage');
404 $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
405 my $marcflavour = $query->param('marcflavour');
407 # we can have some variants of marc flavour, by having different directories, like : unimarc_small and unimarc_full, for small and complete unimarc frameworks.
408 # marc_cleaned finds the marcflavour, without the variant.
409 my $marc_cleaned = 'MARC21';
410 $marc_cleaned = 'UNIMARC' if $marcflavour =~ /unimarc/i;
413 "INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('marcflavour','$marc_cleaned','Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice');"
417 $marcflavour = C4::Context->preference('marcflavour') unless ($marcflavour);
418 #Insert into database the selected marcflavour
422 C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/$langchoice/marcflavour/".lc($marcflavour);
423 unless (opendir( MYDIR, $dir )) {
424 if ($langchoice eq 'en') {
425 warn "cannot open MARC frameworks directory $dir";
427 # if no translated MARC framework is available,
429 $dir = C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/en/marcflavour/".lc($marcflavour);
430 opendir(MYDIR, $dir) or warn "cannot open English MARC frameworks directory $dir";
431 $template->param('en_marc_frameworks' => 1);
434 my @listdir = sort grep { !/^\.|marcflavour/ && -d "$dir/$_" } readdir(MYDIR);
440 "SELECT value FROM systempreferences WHERE variable='FrameworksLoaded'"
443 my ($frameworksloaded) = $request->fetchrow;
444 $frameworksloaded = '' unless defined $frameworksloaded; # avoid warning
445 my %frameworksloaded;
446 foreach ( split( /\|/, $frameworksloaded ) ) {
447 $frameworksloaded{$_} = 1;
450 foreach my $requirelevel (@listdir) {
451 opendir( MYDIR, "$dir/$requirelevel" );
453 grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ }
459 my $name = substr( $_, 0, -4 );
460 open FILE, "<:utf8","$dir/$requirelevel/$name.txt";
462 $lines =~ s/\n|\r/<br \/>/g;
464 utf8::encode($lines) unless ( utf8::is_utf8($lines) );
468 'fwkfile' => "$dir/$requirelevel/$_",
469 'fwkdescription' => $lines,
472 $frameworksloaded{$_}
473 || ( $requirelevel =~
474 /(mandatory|requi|oblig|necess)/i )
480 sort { $a->{'fwkname'} cmp $b->{'fwkname'} } @frameworklist;
482 # $cell{"mandatory"}=($requirelevel=~/(mandatory|requi|oblig|necess)/i);
483 $cell{"frameworks"} = \@fwks;
484 $cell{"label"} = ucfirst($requirelevel);
485 $cell{"code"} = lc($requirelevel);
486 push @fwklist, \%cell;
488 $template->param( "frameworksloop" => \@fwklist );
489 $template->param( "marcflavour" => ucfirst($marcflavour));
492 C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/$langchoice";
493 unless (opendir( MYDIR, $dir )) {
494 if ($langchoice eq 'en') {
495 warn "cannot open sample data directory $dir";
497 # if no sample data is available,
499 $dir = C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/en";
500 opendir(MYDIR, $dir) or warn "cannot open English sample data directory $dir";
501 $template->param('en_sample_data' => 1);
504 @listdir = sort grep { !/^\.|marcflavour/ && -d "$dir/$_" } readdir(MYDIR);
507 foreach my $requirelevel (@listdir) {
508 opendir( MYDIR, "$dir/$requirelevel" );
510 grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ }
516 my $name = substr( $_, 0, -4 );
517 open FILE, "<:utf8","$dir/$requirelevel/$name.txt";
519 $lines =~ s/\n|\r/<br \/>/g;
521 utf8::encode($lines) unless ( utf8::is_utf8($lines) );
525 'fwkfile' => "$dir/$requirelevel/$_",
526 'fwkdescription' => $lines,
529 $frameworksloaded{$_}
530 || ( $requirelevel =~
531 /(mandatory|requi|oblig|necess)/i )
537 sort { $a->{'fwkname'} cmp $b->{'fwkname'} } @frameworklist;
539 # $cell{"mandatory"}=($requirelevel=~/(mandatory|requi|oblig|necess)/i);
540 $cell{"frameworks"} = \@fwks;
541 $cell{"label"} = ucfirst($requirelevel);
542 $cell{"code"} = lc($requirelevel);
543 push @levellist, \%cell;
545 $template->param( "levelloop" => \@levellist );
546 $template->param( "$op" => 1 );
548 elsif ( $op && $op eq 'choosemarc' ) {
551 # 1ST install, 2nd sub-step : show the user the marcflavour available.
556 #sql data are supposed to be located in installer/data/<dbms>/<language>/marcflavour/marcflavourname
557 # Where <dbms> is database type according to DBD syntax
558 # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
559 # Where <level> is a category of requirement : required, recommended optional
560 # level should contain :
561 # SQL File for import With a readable name.
562 # txt File taht explains what this SQL File is meant for.
563 # Could be VERY useful to have A Big file for a kind of library.
564 # But could also be useful to have some Authorised values data set prepared here.
565 # Marcflavour Selection is achieved through radiobuttons.
566 my $langchoice = $query->param('fwklanguage');
567 $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
569 C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/$langchoice/marcflavour";
570 unless (opendir( MYDIR, $dir )) {
571 if ($langchoice eq 'en') {
572 warn "cannot open MARC frameworks directory $dir";
574 # if no translated MARC framework is available,
576 $dir = C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/en/marcflavour";
577 opendir(MYDIR, $dir) or warn "cannot open English MARC frameworks directory $dir";
580 my @listdir = grep { !/^\./ && -d "$dir/$_" } readdir(MYDIR);
582 my $marcflavour=C4::Context->preference("marcflavour");
584 foreach my $marc (@listdir) {
586 "label"=> ucfirst($marc),
588 "checked"=> defined($marcflavour) ? uc($marc) eq $marcflavour : 0);
589 # $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> };
590 push @flavourlist, \%cell;
592 $template->param( "flavourloop" => \@flavourlist );
593 $template->param( "$op" => 1 );
595 elsif ( $op && $op eq 'importdatastructure' ) {
598 # 1st install, 1st "sub-step" : import kohastructure
601 my $datadir = C4::Context->config('intranetdir') . "/installer/data/$info{dbms}";
603 if ( $info{dbms} eq 'mysql' ) {
604 my $strcmd = "mysql "
605 . ( $info{hostname} ? " -h $info{hostname} " : "" )
606 . ( $info{port} ? " -P $info{port} " : "" )
607 . ( $info{user} ? " -u $info{user} " : "" )
608 . ( $info{password} ? " -p'$info{password}'" : "" )
610 $error = qx($strcmd <$datadir/kohastructure.sql 2>&1 1>/dev/null);
612 elsif ( $info{dbms} eq 'Pg' ) {
614 . ( $info{hostname} ? " -h $info{hostname} " : "" )
615 . ( $info{port} ? " -p $info{port} " : "" )
616 . ( $info{user} ? " -U $info{user} " : "" )
617 # . ( $info{password} ? " -W $info{password}" : "" ) # psql will NOT accept a password, but prompts...
618 . " $info{dbname} "; # Therefore, be sure to run 'trust' on localhost in pg_hba.conf -fbcit
619 $error = qx($strcmd -f $datadir/kohastructure.sql 2>&1 1>/dev/null);# Be sure to set 'client_min_messages = error' in postgresql.conf
620 # so that only true errors are returned to stderr or else the installer will
621 # report the import a failure although it really succeded -fbcit
628 elsif ( $op && $op eq 'updatestructure' ) {
630 # Not 1st install, the only sub-step : update database
632 #Do updatedatabase And report
634 C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl";
636 my $string = qx($execstring 2>&1 1>/dev/null); # added '1>/dev/null' to return only stderr in $string. Needs testing here. -fbcit
638 $string =~ s/\n|\r/<br \/>/g;
640 s/(DBD::mysql.*? failed: .*? line [0-9]*.|=================.*?====================)/<font color=red>$1<\/font>/g;
641 $template->param( "updatereport" => $string );
643 $template->param( $op => 1 );
647 # check wether it's a 1st install or an update
649 #Check if there are enough tables.
650 # Paul has cleaned up tables so reduced the count
651 #I put it there because it implied a data import if condition was not satisfied.
652 my $dbh = DBI->connect(
653 "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}"
654 . ( $info{port} ? ";port=$info{port}" : "" ),
655 $info{'user'}, $info{'password'}
658 if ( $info{dbms} eq 'mysql' ) { $rq = $dbh->prepare( "SHOW TABLES FROM " . $info{'dbname'} ); }
659 elsif ( $info{dbms} eq 'Pg' ) { $rq = $dbh->prepare( "SELECT *
660 FROM information_schema.tables
661 WHERE table_schema='public' and table_type='BASE TABLE';" ); }
663 my $data = $rq->fetchall_arrayref( {} );
664 my $count = scalar(@$data);
666 # we don't have tables, propose DB import
669 $template->param( "count" => $count, "proposeimport" => 1 );
673 # we have tables, propose to select files to upload or updatedatabase
675 $template->param( "count" => $count, "default" => 1 );
677 # 1st part of step 3 : check if there is a databaseversion systempreference
678 # if there is, then we just need to upgrade
679 # if there is none, then we need to install the database
681 if (C4::Context->preference('Version')) {
682 my $dbversion = C4::Context->preference('Version');
683 $dbversion =~ /(.*)\.(..)(..)(...)/;
684 $dbversion = "$1.$2.$3.$4";
685 $template->param("upgrading" => 1,
686 "dbversion" => $dbversion,
687 "kohaversion" => C4::Context->KOHAVERSION,
697 # LANGUAGE SELECTION page by default
698 # using opendir + language Hash
699 my $languages_loop = getTranslatedLanguages();
700 $template->param( installer_languages_loop => $languages_loop );
704 "SELECT * from systempreferences WHERE variable='Version'");
705 if ( $rq->execute ) {
706 my ($version) = $rq->fetchrow;
708 $query->redirect("install.pl?step=3");
714 output_html_with_http_headers $query, $cookie, $template->output;