From a200453a04fc89fdf02dbe39e1d951cb1b55191c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 3 May 2007 15:06:28 +0000 Subject: [PATCH] =?utf8?q?Kleines=20Hilfsmodul=20f=C3=BCr=20Zeichensatzkon?= =?utf8?q?vertierung=20hinzugef=C3=BCgt.=20In=20am.pl=20und=20rp.pl=20werd?= =?utf8?q?en=20die=20hardcodierten=20Umlaute=20auch=20in=20den=20Ausgabeze?= =?utf8?q?ichensatz=20konvertiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Iconv.pm | 31 +++++++++++++++++++++++++++++++ SL/User.pm | 15 ++++----------- bin/mozilla/am.pl | 11 +++++++---- bin/mozilla/rp.pl | 6 ++++++ 4 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 SL/Iconv.pm diff --git a/SL/Iconv.pm b/SL/Iconv.pm new file mode 100644 index 000000000..29bf99df4 --- /dev/null +++ b/SL/Iconv.pm @@ -0,0 +1,31 @@ +package SL::Iconv; + +use Text::Iconv; + +use SL::Common; + +use vars qw(%converters); + +sub get_converter { + my ($from_charset, $to_charset) = @_; + + my $index = "${from_charset}::${to_charset}"; + if (!$converters{$index}) { + $converters{$index} = Text::Iconv->new($from_charset, $to_charset) || die; + } + + return $converters{$index}; +} + +sub convert { + my ($from_charset, $to_charset, $text) = @_; + + $from_charset ||= Common::DEFAULT_CHARSET; + $to_charset ||= Common::DEFAULT_CHARSET; + + my $converter = get_converter($from_charset, $to_charset); + return $converter->convert($text); +} + +1; + diff --git a/SL/User.pm b/SL/User.pm index d7d138588..93c88834e 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -36,10 +36,10 @@ package User; use IO::File; use Fcntl qw(:seek); -use Text::Iconv; use SL::DBUpgrade2; use SL::DBUtils; +use SL::Iconv; sub new { $main::lxdebug->enter_sub(); @@ -460,7 +460,7 @@ sub process_perl_script { $db_charset ||= Common::DEFAULT_CHARSET; - my $iconv = Text::Iconv->new($file_charset, $db_charset); + my $iconv = SL::Iconv::get_converter($file_charset, $db_charset); $dbh->begin_work(); @@ -524,12 +524,10 @@ sub process_query { $db_charset ||= Common::DEFAULT_CHARSET; - my $iconv = Text::Iconv->new($file_charset, $db_charset); - $dbh->begin_work(); while (<$fh>) { - $_ = $iconv->convert($_); + $_ = SL::Iconv::convert($file_charset, $db_charset, $_); # Remove DOS and Unix style line endings. chomp; @@ -912,8 +910,6 @@ sub dbupdate2 { my $db_charset = $main::dbcharset; $db_charset ||= Common::DEFAULT_CHARSET; - my %converters; - foreach my $db (split / /, $form->{dbupdate}) { next unless $form->{$db}; @@ -949,10 +945,7 @@ sub dbupdate2 { foreach my $control (@upgradescripts) { next if ($control->{"applied"}); - if (!$converters{$control->{charset}}) { - $converters{$control->{charset}} = Text::Iconv->new($control->{charset}, $db_charset); - } - $control->{description} = $converters{$control->{charset}}->convert($control->{description}); + $control->{description} = SL::Iconv::convert($control->{charset}, $db_charset, $control->{description}); $control->{"file"} =~ /\.(sql|pl)$/; my $file_type = $1; diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index c4f2a291d..77d8878ff 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -36,6 +36,7 @@ use SL::CA; use SL::Form; use SL::User; use SL::USTVA; +use SL::Iconv; use CGI::Ajax; use CGI; @@ -223,10 +224,11 @@ sub account_header { 30 => "Ausserordentlicher Aufwand", 31 => "Betriebliche Steuern"); foreach $item (sort({ $a <=> $b } keys(%eur))) { + my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $eur{$item})); if ($item == $form->{pos_eur}) { - $select_eur .= qq|\n|; + $select_eur .= qq|\n|; } else { - $select_eur .= qq|\n|; + $select_eur .= qq|\n|; } } @@ -256,10 +258,11 @@ sub account_header { 34 => 'Verr.kalk.Kosten', 35 => 'Steuern Eink.u.Ertr.'); foreach $item (sort({ $a <=> $b } keys %bwapos)) { + my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $bwapos{$item})); if ($item == $form->{pos_bwa}) { - $select_bwa .= qq|