From bc4337116357a3daf6232fb3d921574cd995da2a Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 22 Nov 2010 17:37:44 +0100 Subject: [PATCH] Funktionen format_dates und reformat_numbers von common.pl nach Form.pm verschoben --- SL/Form.pm | 74 ++++++++++++++++++++++++++ bin/mozilla/common.pl | 119 +----------------------------------------- 2 files changed, 76 insertions(+), 117 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index db9b5033d..a2835a203 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -3507,6 +3507,80 @@ sub restore_vars { $main::lxdebug->leave_sub(); } +sub format_dates { + my ($self, $dateformat, $longformat, @indices) = @_; + + $dateformat ||= $::myconfig{dateformat}; + + foreach my $idx (@indices) { + if ($self->{TEMPLATE_ARRAYS} && (ref($self->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { + for (my $i = 0; $i < scalar(@{ $self->{TEMPLATE_ARRAYS}->{$idx} }); $i++) { + $self->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $::locale->reformat_date(\%::myconfig, $self->{TEMPLATE_ARRAYS}->{$idx}->[$i], $dateformat, $longformat); + } + } + + next unless defined $self->{$idx}; + + if (!ref($self->{$idx})) { + $self->{$idx} = $::locale->reformat_date(\%::myconfig, $self->{$idx}, $dateformat, $longformat); + + } elsif (ref($self->{$idx}) eq "ARRAY") { + for (my $i = 0; $i < scalar(@{ $self->{$idx} }); $i++) { + $self->{$idx}->[$i] = $::locale->reformat_date(\%::myconfig, $self->{$idx}->[$i], $dateformat, $longformat); + } + } + } +} + +sub reformat_numbers { + my ($self, $numberformat, $places, @indices) = @_; + + return if !$numberformat || ($numberformat eq $::myconfig{numberformat}); + + foreach my $idx (@indices) { + if ($self->{TEMPLATE_ARRAYS} && (ref($self->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { + for (my $i = 0; $i < scalar(@{ $self->{TEMPLATE_ARRAYS}->{$idx} }); $i++) { + $self->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $self->parse_amount(\%::myconfig, $self->{TEMPLATE_ARRAYS}->{$idx}->[$i]); + } + } + + next unless defined $self->{$idx}; + + if (!ref($self->{$idx})) { + $self->{$idx} = $self->parse_amount(\%::myconfig, $self->{$idx}); + + } elsif (ref($self->{$idx}) eq "ARRAY") { + for (my $i = 0; $i < scalar(@{ $self->{$idx} }); $i++) { + $self->{$idx}->[$i] = $self->parse_amount(\%::myconfig, $self->{$idx}->[$i]); + } + } + } + + my $saved_numberformat = $::myconfig{numberformat}; + $::myconfig{numberformat} = $numberformat; + + foreach my $idx (@indices) { + if ($self->{TEMPLATE_ARRAYS} && (ref($self->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { + for (my $i = 0; $i < scalar(@{ $self->{TEMPLATE_ARRAYS}->{$idx} }); $i++) { + $self->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $self->format_amount(\%::myconfig, $self->{TEMPLATE_ARRAYS}->{$idx}->[$i], $places); + } + } + + next unless defined $self->{$idx}; + + if (!ref($self->{$idx})) { + $self->{$idx} = $self->format_amount(\%::myconfig, $self->{$idx}, $places); + + } elsif (ref($self->{$idx}) eq "ARRAY") { + for (my $i = 0; $i < scalar(@{ $self->{$idx} }); $i++) { + $self->{$idx}->[$i] = $self->format_amount(\%::myconfig, $self->{$idx}->[$i], $places); + } + } + } + + $::myconfig{numberformat} = $saved_numberformat; +} + 1; __END__ diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index a6f7ef48c..64aac69ea 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -386,126 +386,11 @@ sub NTI { } sub format_dates { - $main::lxdebug->enter_sub(); - - my ($dateformat, $longformat, @indices) = @_; - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $dateformat = $myconfig{"dateformat"} unless ($dateformat); - - foreach my $idx (@indices) { - if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { - for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) { - $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = - $locale->reformat_date(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i], - $dateformat, $longformat); - } - } - - next unless (defined($form->{$idx})); - - if (!ref($form->{$idx})) { - $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx}, - $dateformat, $longformat); - - } elsif (ref($form->{$idx}) eq "ARRAY") { - for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { - $form->{$idx}->[$i] = - $locale->reformat_date(\%myconfig, $form->{$idx}->[$i], - $dateformat, $longformat); - } - } - } - - $main::lxdebug->leave_sub(); + return $::form->format_dates(@_); } sub reformat_numbers { - $main::lxdebug->enter_sub(); - - my ($numberformat, $places, @indices) = @_; - - my $form = $main::form; - my %myconfig = %main::myconfig; - - return $main::lxdebug->leave_sub() - if (!$numberformat || ($numberformat eq $myconfig{"numberformat"})); - - foreach my $idx (@indices) { - if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { - for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) { - $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->parse_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i]); - } - } - - next unless (defined($form->{$idx})); - - if (!ref($form->{$idx})) { - $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx}); - - } elsif (ref($form->{$idx}) eq "ARRAY") { - for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { - $form->{$idx}->[$i] = - $form->parse_amount(\%myconfig, $form->{$idx}->[$i]); - } - } - } - - my $saved_numberformat = $myconfig{"numberformat"}; - $myconfig{"numberformat"} = $numberformat; - - foreach my $idx (@indices) { - if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { - for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) { - $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->format_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i], $places); - } - } - - next unless (defined($form->{$idx})); - - if (!ref($form->{$idx})) { - $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places); - - } elsif (ref($form->{$idx}) eq "ARRAY") { - for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { - $form->{$idx}->[$i] = - $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places); - } - } - } - - $myconfig{"numberformat"} = $saved_numberformat; - - $main::lxdebug->leave_sub(); -} - -# ------------------------------------------------------------------------- - -sub show_history { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - my $dbh = $form->dbconnect(\%myconfig); - my ($sort, $sortby) = split(/\-\-/, $form->{order}); - $sort =~ s/.*\.(.*)/$1/; - - $form->{title} = $locale->text("History"); - $form->header(); - print $form->parse_html_template( "common/show_history", { - "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}), - "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"), - uc($sort) => 1, - uc($sort)."BY" => $sortby - } ); - - $dbh->disconnect(); - $main::lxdebug->leave_sub(); + return $::form->format_numbers(@_); } # ------------------------------------------------------------------------- -- 2.20.1