Bug 7026 Web installer does not switch language
[koha.git] / installer / InstallAuth.pm
index 2f39aab..2c07bbe 100644 (file)
@@ -16,16 +16,18 @@ package InstallAuth;
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
+#use warnings; FIXME - Bug 2505
 use Digest::MD5 qw(md5_base64);
 
 require Exporter;
 use C4::Context;
 use C4::Output;
+use C4::Templates;
 use C4::Koha;
 use CGI::Session;
 
@@ -42,6 +44,7 @@ InstallAuth - Authenticates Koha users for Install process
 
   use CGI;
   use InstallAuth;
+  use C4::Output;
 
   my $query = new CGI;
 
@@ -53,11 +56,7 @@ InstallAuth - Authenticates Koha users for Install process
                             flagsrequired   => {borrow => 1},
                          });
 
-  print $query->header(
-    -type => 'utf-8',
-    -cookie => $cookie
-  ), $template->output;
-
+  output_html_with_http_headers $query, $cookie, $template->output;
 
 =head1 DESCRIPTION
 
@@ -80,7 +79,6 @@ InstallAuth - Authenticates Koha users for Install process
 @EXPORT = qw(
   &checkauth
   &get_template_and_user
-  &setlanguagecookie
 );
 
 =item get_template_and_user
@@ -105,25 +103,22 @@ InstallAuth - Authenticates Koha users for Install process
     authenticated page.
 
     More information on the C<gettemplate> sub can be found in the
-    Output.pm module.
+    Templates.pm module.
 
 =cut
 
 sub get_template_and_user {
     my $in       = shift;
     my $query    = $in->{'query'};
-    my $language = $query->cookie('KohaOpacLanguage');
-    my $path =
-      C4::Context->config('intrahtdocs') . "/prog/"
-      . ( $language ? $language : "en" );
-    my $template = HTML::Template::Pro->new(
-        filename          => "$path/modules/" . $in->{template_name},
-        die_on_bad_params => 1,
-        global_vars       => 1,
-        case_sensitive    => 1,
-        path              => ["$path/includes"]
-    );
-
+    my $language =_get_template_language($query->cookie('KohaOpacLanguage'));
+    my $path     = C4::Context->config('intrahtdocs'). "/prog/". $language;
+
+    my $tmplbase = $in->{template_name};
+    $tmplbase=~ s/\.tmpl$/.tt/;
+    my $filename = "$path/modules/" . $tmplbase;
+    my $interface = 'intranet';
+    my $template = C4::Templates->new( $interface, $filename, $tmplbase);
+    
     my ( $user, $cookie, $sessionID, $flags ) = checkauth(
         $in->{'query'},
         $in->{'authnotrequired'},
@@ -162,6 +157,15 @@ sub get_template_and_user {
     return ( $template, $borrowernumber, $cookie );
 }
 
+sub _get_template_language {
+  #verify if opac language exists in staff (bug 5660)
+  #conditions are 1) dir exists and 2) enabled in prefs
+  my ($opaclang)= @_;
+  return 'en' unless $opaclang;
+  my $path= C4::Context->config('intrahtdocs')."/prog/$opaclang";
+  -d $path ? $opaclang : 'en';
+}
+
 =item checkauth
 
   ($userid, $cookie, $sessionID) = &checkauth($query, $noauth, $flagsrequired, $type);
@@ -241,7 +245,7 @@ sub checkauth {
     if ( $sessionID = $query->cookie("CGISESSID") ) {
         C4::Context->_new_userenv($sessionID);
         my $session =
-          new CGI::Session( "driver:File", $sessionID,
+          new CGI::Session( "driver:File;serializer:yaml", $sessionID,
             { Directory => '/tmp' } );
         if ( $session->param('cardnumber') ) {
             C4::Context::set_userenv(
@@ -277,7 +281,7 @@ sub checkauth {
     }
     unless ($userid) {
         my $session =
-          new CGI::Session( "driver:File", undef, { Directory => '/tmp' } );
+          new CGI::Session( "driver:File;serializer:yaml", undef, { Directory => '/tmp' } );
         $sessionID = $session->id;
         $userid    = $query->param('userid');
         C4::Context->_new_userenv($sessionID);
@@ -358,13 +362,10 @@ sub checkauth {
     my $path =
       C4::Context->config('intrahtdocs') . "/prog/"
       . ( $query->param('language') ? $query->param('language') : "en" );
-    my $template = HTML::Template::Pro->new(
-        filename          => "$path/modules/$template_name",
-        die_on_bad_params => 1,
-        global_vars       => 1,
-        case_sensitive    => 1,
-        path              => ["$path/includes"]
-    );
+    my $filename = "$path/modules/$template_name";
+    $filename =~ s/\.tmpl$/.tt/;
+    my $interface = 'intranet';
+    my $template = C4::Templates->new( $interface, $filename);
     $template->param(
         INPUTS => \@inputs,