From 18e412c6958709f4918a2f9eb714538485660903 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] Bug 16776 - If language is set by external link language switcher does not work 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 --- opac/opac-changelanguage.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/opac/opac-changelanguage.pl b/opac/opac-changelanguage.pl index 2773704..db85380 100755 --- a/opac/opac-changelanguage.pl +++ b/opac/opac-changelanguage.pl @@ -25,4 +25,22 @@ 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); + } +} + C4::Templates::setlanguagecookie( $query, $language, $url ); -- 1.7.10.4