From 9ea391ce0b7f254c15353d901883bcb01f674327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Mon, 20 Jun 2016 21:25:32 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 16776 - If language is set by external link language switcher does not work Content-Type: text/plain; charset="utf-8" To reproduce: - Have a multilingual koha installation, let's say en, de-CH, fr-FR and it-IT - Create external links e.g. from your multilingual library website to each language variant of OPAC: ...cgi-bin/koha/opac-main.pl?language=en ...cgi-bin/koha/opac-main.pl?language=de-CH ...cgi-bin/koha/opac-main.pl?language=fr-FR ...cgi-bin/koha/opac-main.pl?language=it-IT Each link opens fine displaying the language as appropriate. Now try to switch language on the page you just opened via the external link. It won't work, it will always stay on the language defined by the external link. To test: - Apply patch - Repeat steps above - Verify that the language switcher works - Verify in browser address field that after switching language, the param 'language= 'has vanished from url string - Try links with multiple params and with params containing 'language', e.g. ...cgi-bin/koha/opac-search.pl?language=fr-FR&q=language&mylanguage=test - Verify that only the parameter 'language=' vanishes Signed-off-by: Owen Leonard --- opac/opac-changelanguage.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/opac/opac-changelanguage.pl b/opac/opac-changelanguage.pl index 2773704..1325f5d 100755 --- a/opac/opac-changelanguage.pl +++ b/opac/opac-changelanguage.pl @@ -25,4 +25,25 @@ my $language = $query->param('language'); my $url = $query->referer() || '/'; # warn "Language : $query // $language // $url"; + +# If language was set by an external URL the parameter +# 'language=' should be removed from url string, otherwise +# the language picker will not work - Bug 16776 + +my @urlarr = split(/\?/,$url); +if (scalar @urlarr > 1) { + my @paramarr = split(/&/,$urlarr[1]); + for my $index ( reverse 0..$#paramarr ) { + if ( $paramarr[$index] =~ /^language=/) { + splice(@paramarr, $index, 1, ()); + } + } + if ( scalar @paramarr > 0) { + $url = $urlarr[0].'?'.join('&', @paramarr); + } + else { + $url = $urlarr[0]; + } +} + C4::Templates::setlanguagecookie( $query, $language, $url ); -- 2.1.4