Changing to two-column layout
[koha.git] / installer / install.pl
1 #!/usr/bin/perl -w # please develop with -w
2
3 #use diagnostics;
4
5 # use Install;
6 use InstallAuth;
7 use C4::Context;
8 use C4::Output;
9 use C4::Languages;
10
11 use strict;    # please develop with the strict pragma
12
13 use CGI;
14
15 my $query = new CGI;
16 my $step  = $query->param('step');
17
18 my $language = $query->param('language');
19 my ( $template, $loggedinuser, $cookie );
20
21 my $all_languages = getAllLanguages();
22
23 if ( defined($language) ) {
24     setlanguagecookie( $query, $language, "install.pl?step=1" );
25 }
26 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
27     {
28         template_name => "installer/step" . ( $step ? $step : 1 ) . ".tmpl",
29         query         => $query,
30         type          => "intranet",
31         authnotrequired => 0,
32         debug           => 1,
33     }
34 );
35
36 my %info;
37 $info{'dbname'} = C4::Context->config("database");
38 $info{'dbms'} =
39   (   C4::Context->config("db_scheme")
40     ? C4::Context->config("db_scheme")
41     : "mysql" );
42 $info{'hostname'} = C4::Context->config("hostname");
43 ( $info{'hostname'}, $info{'port'} ) = ( $1, $2 )
44   if $info{'hostname'} =~ /([^:]*):([0-9]+)/;
45 $info{'user'}     = C4::Context->config("user");
46 $info{'password'} = C4::Context->config("pass");
47 my $dbh = DBI->connect(
48     "DBI:$info{dbms}:$info{dbname}:$info{hostname}"
49       . ( $info{port} ? ":$info{port}" : "" ),
50     $info{'user'}, $info{'password'}
51 );
52
53 if ( $step && $step == 1 ) {
54     #First Step
55     #Checking ALL perl Modules and services needed are installed.
56     #Whenever there is an error, adding a report to the page
57     $template->param( language => 1 );
58     my $problem;
59
60     unless ( $] >= 5.006001 ) {    # Bug 179
61         $template->param( "problems" => 1, "perlversion" => 1 );
62         $problem = 1;
63     }
64
65     # We could here use a special find
66     my @missing = ();
67     unless ( eval { require ZOOM } ) {
68         push @missing, { name => "ZOOM" };
69     }
70     unless ( eval { require LWP::Simple } ) {
71         push @missing, { name => "LWP::Simple" };
72     }
73     unless ( eval { require XML::Simple } ) {
74         push @missing, { name => "XML::Simple" };
75     }
76     unless ( eval { require MARC::File::XML } ) {
77         push @missing, { name => "MARC::File::XML" };
78     }
79     unless ( eval { require MARC::File::USMARC } ) {
80         push @missing, { name => "MARC::File::USMARC" };
81     }
82     unless ( eval { require DBI } ) {
83         push @missing, { name => "DBI" };
84     }
85     unless ( eval { require Date::Manip } ) {
86         push @missing, { name => "Date::Manip" };
87     }
88     unless ( eval { require DBD::mysql } ) {
89         push @missing, { name => "DBD::mysql" };
90     }
91     unless ( eval { require HTML::Template } ) {
92         push @missing, { name => "HTML::Template::Pro" };
93     }
94     unless ( eval { require HTML::Template } ) {
95         push @missing, { name => "Date::Calc" };
96     }
97     unless ( eval { require Digest::MD5 } ) {
98         push @missing, { name => "Digest::MD5" };
99     }
100     unless ( eval { require MARC::Record } ) {
101         push @missing, { name => "MARC::Record" };
102     }
103     unless ( eval { require Mail::Sendmail } ) {
104         push @missing, { name => "Mail::Sendmail", usagemail => 1 };
105     }
106     unless ( eval { require List::MoreUtils } ) {
107         push @missing, { name => "List::MoreUtils" };
108     }
109     unless ( eval { require XML::RSS } ) {
110         push @missing, { name => "XML::RSS" };
111     }
112     unless ( eval { require CGI::Carp } ) {
113         push @missing, { name => "CGI::Carp" };
114     }
115
116
117 # The following modules are not mandatory, depends on how the library want to use Koha
118     unless ( eval { require PDF::API2 } ) {
119         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
120             push @missing, { name => "PDF::API2", usagebarcode => 1 };
121         }
122     }
123     unless ( eval { require GD::Barcorde } ) {
124         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
125             push @missing,
126               { name => "GD::Barcode", usagebarcode => 1, usagespine => 1 };
127         }
128     }
129     unless ( eval { require Data::Random } ) {
130         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
131             push @missing, { name => "Data::Random", usagebarcode => 1 };
132         }
133     }
134     unless ( eval { require PDF::Reuse::Barcode } ) {
135         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
136             push @missing, { name => "PDF::Reuse::Barcode", usagebarcode => 1 };
137         }
138     }
139     unless ( eval { require PDF::Report } ) {
140         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
141             push @missing, { name => "PDF::Report", usagebarcode => 1 };
142         }
143     }
144     unless ( eval { require Net::LDAP } ) {
145         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
146             push @missing, { name => "Algorithm::CheckDigits", usagebarcode => 1 };
147         }
148     }
149     unless ( eval { require GD::Barcode::UPCE } ) {
150         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
151             push @missing, { name => "GD::Barcode::UPCE", usagepine => 1 };
152         }
153     }
154     unless ( eval { require Net::LDAP } ) {
155         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
156             push @missing, { name => "Net::LDAP", usageLDAP => 1 };
157         }
158     }
159     $template->param( missings => \@missing ) if ( scalar(@missing) > 0 );
160     $template->param( 'checkmodule' => 1 )
161       unless ( scalar(@missing) && $problem );
162
163 }
164 elsif ( $step && $step == 2 ) {
165 #
166 #STEP 2 Check Database connection and access
167 #
168     $template->param(%info);
169     my $checkmysql = $query->param("checkmysql");
170     $template->param( 'mysqlconnection' => $checkmysql );
171     if ($checkmysql) {
172         if ($dbh) {
173
174             # Can connect to the mysql
175             $template->param( "checkdatabaseaccess" => 1 );
176             if ( $info{dbms} eq "mysql" ) {
177
178                 #Check if database created
179                 my $rv = $dbh->do("SHOW DATABASES LIKE \'$info{dbname}\'");
180                 if ( $rv == 1 ) {
181                     $template->param( 'checkdatabasecreated' => 1 );
182                 }
183
184                 #Check if user have all necessary grants on this database.
185                 my $rq =
186                   $dbh->prepare(
187                     "SHOW GRANTS FOR \'$info{user}\'\@'$info{hostname}'");
188                 $rq->execute;
189                 my $grantaccess;
190                 while ( my ($line) = $rq->fetchrow ) {
191                     my $dbname = $info{dbname};
192                     if ( $line =~ m/$dbname/ || index( $line, '*.*' ) > 0 ) {
193                         $grantaccess = 1
194                           if (
195                             index( $line, 'ALL PRIVILEGES' ) > 0
196                             || (   ( index( $line, 'SELECT' ) > 0 )
197                                 && ( index( $line, 'INSERT' ) > 0 )
198                                 && ( index( $line, 'UPDATE' ) > 0 )
199                                 && ( index( $line, 'DELETE' ) > 0 )
200                                 && ( index( $line, 'CREATE' ) > 0 )
201                                 && ( index( $line, 'DROP' ) > 0 ) )
202                           );
203                     }
204                 }
205                 unless ($grantaccess) {
206                     $rq =
207                       $dbh->prepare("SHOW GRANTS FOR \'$info{user}\'\@'\%'");
208                     $rq->execute;
209                     while ( my ($line) = $rq->fetchrow ) {
210                         my $dbname = $info{dbname};
211                         if ( $line =~ m/$dbname/ || index( $line, '*.*' ) > 0 )
212                         {
213                             $grantaccess = 1
214                               if (
215                                 index( $line, 'ALL PRIVILEGES' ) > 0
216                                 || (   ( index( $line, 'SELECT' ) > 0 )
217                                     && ( index( $line, 'INSERT' ) > 0 )
218                                     && ( index( $line, 'UPDATE' ) > 0 )
219                                     && ( index( $line, 'DELETE' ) > 0 )
220                                     && ( index( $line, 'CREATE' ) > 0 )
221                                     && ( index( $line, 'DROP' ) > 0 ) )
222                               );
223                         }
224                     }
225                 }
226                 $template->param( "checkgrantaccess" => $grantaccess );
227             }
228         }
229         else {
230             $template->param( "error" => DBI::err, "message" => DBI::errstr );
231         }
232     }
233 }
234 elsif ( $step && $step == 3 ) {
235 #
236 #
237 # STEP 3 : database setup
238 #
239
240     my $op = $query->param('op');
241     if ( $op && $op eq 'finished' ) {
242         #
243         # we have finished, just redirect to mainpage.
244         #
245         print $query->redirect("/cgi-bin/koha/mainpage.pl");
246         exit 1;
247     }
248     elsif ( $op && $op eq 'finish' ) {
249         my $kohaversion=C4::Context::KOHAVERSION;
250         # remove the 3 last . to have a Perl number
251         $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
252         if (C4::Context->preference('Version')) {
253             warn "UPDATE Version";
254             my $finish=$dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
255             $finish->execute($kohaversion);
256         } else {
257             warn "INSERT Version";
258             my $finish=$dbh->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. Don t change this value manually, it s holded by the webinstaller')");
259             $finish->execute($kohaversion);
260         }
261
262         # Installation is finished.
263         # We just deny anybody acess to install
264         # And we redirect people to mainpage.
265         # The installer wil have to relogin since we donot pass cookie to redirection.
266         $template->param( "$op" => 1 );
267     }
268     elsif ( $op && $op eq 'Nozebra' ) {
269         if ($query->param('Nozebra')) {
270             $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='NoZebra'");
271         } else {
272             $dbh->do("UPDATE systempreferences SET value=0 WHERE variable='NoZebra'");
273         }
274         $template->param( "$op" => 1 );
275     }
276     elsif ( $op && $op eq 'addframeworks' ) {
277     #
278     # 1ST install, 3rd sub-step : insert the SQL files the user has selected
279     #
280
281         #Framework importing and reports
282         my $lang;
283         my %hashlevel;
284
285        # sort by filename -> prepend with numbers to specify order of insertion.
286         my @fnames = sort {
287             my @aa = split /\/|\\/, ($a);
288             my @bb = split /\/|\\/, ($b);
289             $aa[-1] lt $bb[-1]
290         } $query->param('framework');
291         $dbh->do('SET FOREIGN_KEY_CHECKS=0');
292         my $request =
293           $dbh->prepare(
294             "SELECT value FROM systempreferences WHERE variable='FrameworksLoaded'"
295           );
296         $request->execute;
297         my ($systempreference) = $request->fetchrow;
298         foreach my $file (@fnames) {
299
300             #      warn $file;
301             undef $/;
302             my $strcmd = "mysql "
303               . ( $info{hostname} ? " -h $info{hostname} " : "" )
304               . ( $info{port}     ? " -P $info{port} "     : "" )
305               . ( $info{user}     ? " -u $info{user} "     : "" )
306               . ( $info{password} ? " -p$info{password}"   : "" )
307               . " $info{dbname} ";
308             my $error = qx($strcmd < $file 2>&1);
309             my @file = split qr(\/|\\), $file;
310             $lang = $file[ scalar(@file) - 3 ] unless ($lang);
311             my $level = $file[ scalar(@file) - 2 ];
312             unless ($error) {
313                 $systempreference .= "$file[scalar(@file)-1]|"
314                   unless (
315                     index( $systempreference, $file[ scalar(@file) - 1 ] ) >=
316                     0 );
317             }
318
319             #Bulding here a hierarchy to display files by level.
320             push @{ $hashlevel{$level} },
321               { "fwkname" => $file[ scalar(@file) - 1 ], "error" => $error };
322         }
323
324         #systempreference contains an ending |
325         chop $systempreference;
326         my @list;
327         map { push @list, { "level" => $_, "fwklist" => $hashlevel{$_} } }
328           keys %hashlevel;
329         my $fwk_language;
330         for my $each_language (@$all_languages) {
331
332             #           warn "CODE".$each_language->{'language_code'};
333             #           warn "LANG:".$lang;
334             if ( $lang eq $each_language->{'language_code'} ) {
335                 $fwk_language = $each_language->{language_locale_name};
336             }
337         }
338         my $updateflag =
339           $dbh->do(
340             "UPDATE systempreferences set value=\"$systempreference\" where variable='FrameworksLoaded'"
341           );
342         unless ( $updateflag == 1 ) {
343             my $string =
344                 "INSERT INTO systempreferences (value, variable, explanation, type) VALUES (\"$systempreference\",'FrameworksLoaded','Frameworks loaded through webinstaller','choice')";
345             my $rq = $dbh->prepare($string);
346             $rq->execute;
347         }
348         $template->param(
349             "fwklanguage" => $fwk_language,
350             "list"        => \@list
351         );
352         $template->param( "$op" => 1 );
353         $dbh->do('SET FOREIGN_KEY_CHECKS=1');
354     }
355     elsif ( $op && $op eq 'selectframeworks' ) {
356         #
357         #
358         # 1ST install, 2nd sub-step : show the user the sql datas he can insert in the database.
359         #
360         #
361         # (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks)
362         
363         #Framework Selection
364         #sql data for import are supposed to be located in installer/data/<language>/<level>
365         # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
366         # Where <level> is a category of requirement : required, recommended optional
367         # level should contain :
368         #   SQL File for import With a readable name.
369         #   txt File taht explains what this SQL File is meant for.
370         # Could be VERY useful to have A Big file for a kind of library.
371         # But could also be useful to have some Authorised values data set prepared here.
372         # Framework Selection is achieved through checking boxes.
373         my $langchoice = $query->param('fwklanguage');
374         $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
375         my $marcflavour = $query->param('marcflavour');
376         if ($marcflavour){    
377           my $request =
378             $dbh->prepare(
379               "INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('marcflavour','$marcflavour','Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice');"
380             );     
381           $request->execute;
382         };    
383         $marcflavour = C4::Context->preference('marcflavour') unless ($marcflavour);
384         #Insert into database the selected marcflavour
385     
386         undef $/;
387         my $dir =
388           C4::Context->config('intranetdir') . "/installer/data/$langchoice/marcflavour/".lc($marcflavour);
389         opendir( MYDIR, $dir ) || warn "no open $dir";
390         my @listdir = sort grep { !/^\.|CVS|marcflavour/ && -d "$dir/$_" } readdir(MYDIR);
391         closedir MYDIR;
392                   
393         my @fwklist;
394         my $request =
395           $dbh->prepare(
396             "SELECT value FROM systempreferences WHERE variable='FrameworksLoaded'"
397           );
398         $request->execute;
399         my ($frameworksloaded) = $request->fetchrow;
400         my %frameworksloaded;
401         foreach ( split( /\|/, $frameworksloaded ) ) {
402             $frameworksloaded{$_} = 1;
403         }
404         
405         foreach my $requirelevel (@listdir) {
406             opendir( MYDIR, "$dir/$requirelevel" );
407             my @listname =
408               grep { !/^\.|CVS/ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ }
409               readdir(MYDIR);
410             closedir MYDIR;
411             my %cell;
412             my @frameworklist;
413             map {
414                 my $name = substr( $_, 0, -4 );
415                 open FILE, "< $dir/$requirelevel/$name.txt";
416                 my $lines = <FILE>;
417                 $lines =~ s/\n|\r/<br \/>/g;
418                 use utf8;
419                 utf8::encode($lines) unless ( utf8::is_utf8($lines) );
420                 push @frameworklist,
421                   {
422                     'fwkname'        => $name,
423                     'fwkfile'        => "$dir/$requirelevel/$_",
424                     'fwkdescription' => $lines,
425                     'checked'        => (
426                         (
427                             $frameworksloaded{$_}
428                               || ( $requirelevel =~
429                                 /(mandatory|requi|oblig|necess)/i )
430                         ) ? 1 : 0
431                     )
432                   };
433             } @listname;
434             my @fwks =
435               sort { $a->{'fwkname'} lt $b->{'fwkname'} } @frameworklist;
436
437 #             $cell{"mandatory"}=($requirelevel=~/(mandatory|requi|oblig|necess)/i);
438             $cell{"frameworks"} = \@fwks;
439             $cell{"label"}      = ucfirst($requirelevel);
440             $cell{"code"}       = lc($requirelevel);
441             push @fwklist, \%cell;
442         }
443         $template->param( "frameworksloop" => \@fwklist );
444         $template->param( "marcflavour" => ucfirst($marcflavour));
445         
446         $dir =
447           C4::Context->config('intranetdir') . "/installer/data/$langchoice";
448         opendir( MYDIR, $dir ) || warn "no open $dir";
449         @listdir = sort grep { !/^\.|CVS|marcflavour/ && -d "$dir/$_" } readdir(MYDIR);
450         closedir MYDIR;
451         my @levellist;
452         foreach my $requirelevel (@listdir) {
453             opendir( MYDIR, "$dir/$requirelevel" );
454             my @listname =
455               grep { !/^\.|CVS/ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ }
456               readdir(MYDIR);
457             closedir MYDIR;
458             my %cell;
459             my @frameworklist;
460             map {
461                 my $name = substr( $_, 0, -4 );
462                 open FILE, "< $dir/$requirelevel/$name.txt";
463                 my $lines = <FILE>;
464                 $lines =~ s/\n|\r/<br \/>/g;
465                 use utf8;
466                 utf8::encode($lines) unless ( utf8::is_utf8($lines) );
467                 push @frameworklist,
468                   {
469                     'fwkname'        => $name,
470                     'fwkfile'        => "$dir/$requirelevel/$_",
471                     'fwkdescription' => $lines,
472                     'checked'        => (
473                         (
474                             $frameworksloaded{$_}
475                               || ( $requirelevel =~
476                                 /(mandatory|requi|oblig|necess)/i )
477                         ) ? 1 : 0
478                     )
479                   };
480             } @listname;
481             my @fwks =
482               sort { $a->{'fwkname'} lt $b->{'fwkname'} } @frameworklist;
483
484 #             $cell{"mandatory"}=($requirelevel=~/(mandatory|requi|oblig|necess)/i);
485             $cell{"frameworks"} = \@fwks;
486             $cell{"label"}      = ucfirst($requirelevel);
487             $cell{"code"}       = lc($requirelevel);
488             push @levellist, \%cell;
489         }
490         $template->param( "levelloop" => \@levellist );
491         $template->param( "$op"       => 1 );
492     }
493     elsif ( $op && $op eq 'choosemarc' ) {
494         #
495         #
496         # 1ST install, 2nd sub-step : show the user the marcflavour available.
497         #
498         #
499         
500         #Choose Marc Flavour
501         #sql data are supposed to be located in installer/data/<language>/marcflavour/marcflavourname
502         # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
503         # Where <level> is a category of requirement : required, recommended optional
504         # level should contain :
505         #   SQL File for import With a readable name.
506         #   txt File taht explains what this SQL File is meant for.
507         # Could be VERY useful to have A Big file for a kind of library.
508         # But could also be useful to have some Authorised values data set prepared here.
509         # Marcflavour Selection is achieved through radiobuttons.
510         my $langchoice = $query->param('fwklanguage');
511         $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
512         my $dir =
513           C4::Context->config('intranetdir') . "/installer/data/$langchoice/marcflavour";
514         opendir( MYDIR, $dir ) || warn "no open $dir";
515         my @listdir = grep { !/^\.|CVS/ && -d "$dir/$_" } readdir(MYDIR);
516         closedir MYDIR;
517         my $marcflavour=C4::Context->preference("marcflavour");    
518         my @flavourlist;
519         foreach my $marc (@listdir) {
520             my %cell=(    
521             "label"=> ucfirst($marc),
522             "code"=>uc($marc),
523             "checked"=>uc($marc) eq $marcflavour);      
524 #             $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> };
525             push @flavourlist, \%cell;
526         }
527         $template->param( "flavourloop" => \@flavourlist );
528         $template->param( "$op"       => 1 );
529     }
530     elsif ( $op && $op eq 'importdatastructure' ) {
531         #
532         #
533         # 1st install, 1st "sub-step" : import kohastructure
534         #
535         #
536         my $dbh = DBI->connect(
537             "DBI:$info{dbms}:$info{dbname}:$info{hostname}"
538               . ( $info{port} ? ":$info{port}" : "" ),
539             $info{'user'}, $info{'password'}
540         );
541         open( INPUT, "<kohastructure.sql" );
542         my $file = do { local $/ = undef; <INPUT> };
543         my @commands = split( /;/, $file );
544         pop @commands;
545         map { $dbh->do($_) } @commands;
546         close(INPUT);
547         $template->param(
548             "error" => $dbh->errstr,
549             "$op"   => 1,
550         );
551         $dbh->disconnect;
552     }
553     elsif ( $op && $op eq 'updatestructure' ) {
554         #
555         # Not 1st install, the only sub-step : update database
556         #
557         #Do updatedatabase And report
558         my $execstring =
559           C4::Context->config("intranetdir") . "/updater/updatedatabase";
560         undef $/;
561         my $string = qx|$execstring 2>&1|;
562         if ($string) {
563             $string =~ s/\n|\r/<br \/>/g;
564             $string =~
565                 s/(DBD::mysql.*? failed: .*? line [0-9]*.|=================.*?====================)/<font color=red>$1<\/font>/g;
566             $template->param( "updatereport" => $string );
567         }
568         $template->param( $op => 1 );
569     }
570     else {
571         #
572         # check wether it's a 1st install or an update
573         #
574         #Check if there are enough tables.
575         # Paul has cleaned up tables so reduced the count
576         #I put it there because it implied a data import if condition was not satisfied.
577         my $dbh = DBI->connect(
578             "DBI:$info{dbms}:$info{dbname}:$info{hostname}"
579               . ( $info{port} ? ":$info{port}" : "" ),
580             $info{'user'}, $info{'password'}
581         );
582         my $rq = $dbh->prepare( "SHOW TABLES FROM " . $info{'dbname'} );
583         $rq->execute;
584         my $data = $rq->fetchall_arrayref( {} );
585         my $count = scalar(@$data);
586         #
587         # we don't have tables, propose DB import
588         #
589         if ( $count < 70 ) {
590             $template->param( "count" => $count, "proposeimport" => 1 );
591         }
592         else {
593             #
594             # we have tables, propose to select files to upload or updatedatabase
595             #
596             $template->param( "count" => $count, "default" => 1 );
597             #
598             # 1st part of step 3 : check if there is a databaseversion systempreference
599             # if there is, then we just need to upgrade
600             # if there is none, then we need to install the database
601             #
602             if (C4::Context->preference('Version')) {
603                 my $dbversion = C4::Context->preference('Version');
604                 $dbversion =~ /(.*)\.(..)(..)(...)/;
605                 $dbversion = "$1.$2.$3.$4";
606                 $template->param("upgrading" => 1,
607                                 "dbversion" => $dbversion,
608                                 "kohaversion" => C4::Context->KOHAVERSION,
609                                 );
610             }
611         }
612
613         $dbh->disconnect;
614     }
615 }
616 else {
617
618     # LANGUAGE SELECTION page by default
619     # using opendir + language Hash
620
621     my $langavail = getTranslatedLanguages();
622
623     my @languages;
624     foreach (@$langavail) {
625         push @languages,
626           {
627             'value'       => $_->{'language_code'},
628             'description' => $_->{'language_name'}
629           }
630           if ( $_->{'language_code'} );
631     }
632     $template->param( languages => \@languages );
633     if ($dbh) {
634         my $rq =
635           $dbh->prepare(
636             "SELECT * from systempreferences WHERE variable='Version'");
637         if ( $rq->execute ) {
638             my ($version) = $rq->fetchrow;
639             if ($version) {
640                 $query->redirect("install.pl?step=3");
641             }
642         }
643     }
644 }
645 output_html_with_http_headers $query, $cookie, $template->output;