X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=28e12258a2564558bd1f69c3285859eb51583e95;hb=b354d72972e377a3007f8f03ad9b719488c4b3bf;hp=f3fe6e5d9b49de814da4b2c0251c812a50b7b66b;hpb=6f2893dcf199d5e5147cc2020c2ab6984f4274dc;p=kivitendo-erp.git
diff --git a/SL/Form.pm b/SL/Form.pm
index f3fe6e5d9..28e12258a 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -42,21 +42,31 @@ use Data::Dumper;
use CGI;
use CGI::Ajax;
use Cwd;
+use Encode;
+use File::Copy;
use IO::File;
use SL::Auth;
use SL::Auth::DB;
use SL::Auth::LDAP;
use SL::AM;
use SL::Common;
+use SL::CVar;
+use SL::DB;
+use SL::DBConnect;
use SL::DBUtils;
+use SL::DO;
+use SL::IC;
+use SL::IS;
use SL::Mailer;
use SL::Menu;
+use SL::OE;
use SL::Template;
use SL::User;
+use SL::X;
use Template;
use URI;
use List::Util qw(first max min sum);
-use List::MoreUtils qw(any apply);
+use List::MoreUtils qw(all any apply);
use strict;
@@ -125,6 +135,7 @@ sub _request_to_hash {
my $self = shift;
my $input = shift;
+ my $uploads = {};
if (!$ENV{'CONTENT_TYPE'}
|| ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
@@ -132,7 +143,7 @@ sub _request_to_hash {
$self->_input_to_hash($input);
$main::lxdebug->leave_sub(2);
- return;
+ return $uploads;
}
my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous);
@@ -177,7 +188,7 @@ sub _request_to_hash {
substr $line, $-[0], $+[0] - $-[0], "";
}
- $previous = $self->_store_value($name, '') if ($name);
+ $previous = _store_value($uploads, $name, '') if ($name);
$self->{FILENAME} = $filename if ($filename);
next;
@@ -198,6 +209,8 @@ sub _request_to_hash {
${ $previous } =~ s|\r?\n$|| if $previous;
$main::lxdebug->leave_sub(2);
+
+ return $uploads;
}
sub _recode_recursively {
@@ -248,13 +261,14 @@ sub new {
$self->_input_to_hash($ENV{QUERY_STRING}) if $ENV{QUERY_STRING};
$self->_input_to_hash($ARGV[0]) if @ARGV && $ARGV[0];
+ my $uploads;
if ($ENV{CONTENT_LENGTH}) {
my $content;
read STDIN, $content, $ENV{CONTENT_LENGTH};
- $self->_request_to_hash($content);
+ $uploads = $self->_request_to_hash($content);
}
- my $db_charset = $main::dbcharset;
+ my $db_charset = $::lx_office_conf{system}->{dbcharset};
$db_charset ||= Common::DEFAULT_CHARSET;
my $encoding = $self->{INPUT_ENCODING} || $db_charset;
@@ -262,8 +276,7 @@ sub new {
_recode_recursively(SL::Iconv->new($encoding, $db_charset), $self);
- $self->{action} = lc $self->{action};
- $self->{action} =~ s/( |-|,|\#)/_/g;
+ map { $self->{$_} = $uploads->{$_} } keys %{ $uploads } if $uploads;
#$self->{version} = "2.6.1"; # Old hardcoded but secure style
open VERSION_FILE, "VERSION"; # New but flexible code reads version from VERSION-file
@@ -379,7 +392,8 @@ sub escape {
my ($self, $str) = @_;
- $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
+ $str = Encode::encode('utf-8-strict', $str) if $::locale->is_utf8;
+ $str =~ s/([^a-zA-Z0-9_.:-])/sprintf("%%%02x", ord($1))/ge;
$main::lxdebug->leave_sub(2);
@@ -395,6 +409,7 @@ sub unescape {
$str =~ s/\\$//;
$str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
+ $str = Encode::decode('utf-8-strict', $str) if $::locale->is_utf8;
$main::lxdebug->leave_sub(2);
@@ -442,13 +457,23 @@ sub hide_form {
$main::lxdebug->leave_sub();
}
+sub throw_on_error {
+ my ($self, $code) = @_;
+ local $self->{__ERROR_HANDLER} = sub { die SL::X::FormError->new($_[0]) };
+ $code->();
+}
+
sub error {
$main::lxdebug->enter_sub();
$main::lxdebug->show_backtrace();
my ($self, $msg) = @_;
- if ($ENV{HTTP_USER_AGENT}) {
+
+ if ($self->{__ERROR_HANDLER}) {
+ $self->{__ERROR_HANDLER}->($msg);
+
+ } elsif ($ENV{HTTP_USER_AGENT}) {
$msg =~ s/\n/
/g;
$self->show_generic_error($msg);
@@ -592,20 +617,23 @@ sub create_http_response {
pop @segments;
$uri->path_segments(@segments);
- my $session_cookie_value = $main::auth->get_session_id();
- $session_cookie_value ||= 'NO_SESSION';
+ my $session_cookie_value = $main::auth->get_session_id();
- $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(),
- '-value' => $session_cookie_value,
- '-path' => $uri->path,
- '-secure' => $ENV{HTTPS});
+ if ($session_cookie_value) {
+ $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(),
+ '-value' => $session_cookie_value,
+ '-path' => $uri->path,
+ '-secure' => $ENV{HTTPS});
+ }
}
my %cgi_params = ('-type' => $params{content_type});
$cgi_params{'-charset'} = $params{charset} if ($params{charset});
+ $cgi_params{'-cookie'} = $session_cookie if ($session_cookie);
- my $output = $cgi->header('-cookie' => $session_cookie,
- %cgi_params);
+ map { $cgi_params{'-' . $_} = $params{$_} if exists $params{$_} } qw(content_disposition content_length);
+
+ my $output = $cgi->header(%cgi_params);
$main::lxdebug->leave_sub();
@@ -614,120 +642,71 @@ sub create_http_response {
sub header {
- $main::lxdebug->enter_sub();
+ $::lxdebug->enter_sub;
- # extra code ist currently only used by menuv3 and menuv4 to set their css.
+ # extra code is currently only used by menuv3 and menuv4 to set their css.
# it is strongly deprecated, and will be changed in a future version.
my ($self, $extra_code) = @_;
+ my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET;
+ my @header;
+
+ $::lxdebug->leave_sub and return if !$ENV{HTTP_USER_AGENT} || $self->{header}++;
+
+ $self->{favicon} ||= "favicon.ico";
+ $self->{titlebar} = "$self->{title} - $self->{titlebar}" if $self->{title};
+
+ # build includes
+ if ($self->{refresh_url} || $self->{refresh_time}) {
+ my $refresh_time = $self->{refresh_time} || 3;
+ my $refresh_url = $self->{refresh_url} || $ENV{REFERER};
+ push @header, "";
+ }
+
+ push @header, ""
+ for grep { -f "css/$_" } apply { s|.*/|| } $self->{stylesheet}, $self->{stylesheets};
+
+ push @header, "" if $self->{landscape};
+ push @header, "" if -f $self->{favicon};
+ push @header, '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '';
+ push @header, $self->{javascript} if $self->{javascript};
+ push @header, map { $_->show_javascript } @{ $self->{AJAX} || [] };
+ push @header, "" if $self->{fokus};
+ push @header, sprintf "",
+ join ' - ', grep $_, $self->{title}, $self->{login}, $::myconfig{dbname}, $self->{version} if $self->{title};
- if ($self->{header}) {
- $main::lxdebug->leave_sub();
- return;
- }
-
- my ($stylesheet, $favicon, $pagelayout);
-
- if ($ENV{HTTP_USER_AGENT}) {
- my $doctype;
-
- if ($ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/) {
- # Only set the DOCTYPE for Internet Explorer. Other browsers have problems displaying the menu otherwise.
- $doctype = qq|\n|;
- }
-
- my $stylesheets = "$self->{stylesheet} $self->{stylesheets}";
-
- $stylesheets =~ s|^\s*||;
- $stylesheets =~ s|\s*$||;
- foreach my $file (split m/\s+/, $stylesheets) {
- $file =~ s|.*/||;
- next if (! -f "css/$file");
-
- $stylesheet .= qq|\n|;
- }
-
- $self->{favicon} = "favicon.ico" unless $self->{favicon};
-
- if ($self->{favicon} && (-f "$self->{favicon}")) {
- $favicon =
- qq|
- |;
- }
-
- my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
-
- if ($self->{landscape}) {
- $pagelayout = qq||;
- }
-
- my $fokus = qq|
+ # if there is a title, we put some JavaScript in to the page, wich writes a
+ # meaningful title-tag for our frameset.
+ my $title_hack = '';
+ if ($self->{title}) {
+ $title_hack = qq|
- | if $self->{"fokus"};
-
- # if there is a title, we put some JavaScript in to the page, wich writes a
- # meaningful title-tag for our frameset.
- my $title_hack;
- if ($self->{"title"}){
- $title_hack = qq|
-
- |;
- }
-
- #Set Calendar
- my $jsscript = "";
- if ($self->{jsscript} == 1) {
-
- $jsscript = qq|
-
-
-
-
-
-
- $self->{javascript}
- |;
- }
-
- $self->{titlebar} =
- ($self->{title})
- ? "$self->{title} - $self->{titlebar}"
- : $self->{titlebar};
- my $ajax = "";
- for my $item (@ { $self->{AJAX} || [] }) {
- $ajax .= $item->show_javascript();
- }
+ |;
+ }
- print $self->create_http_response('content_type' => 'text/html',
- 'charset' => $db_charset,);
- print qq|${doctype}
-
$info|); + my $info = "Web page template '${file}' not found.\n"; + print qq|
$info|; ::end_of_request(); } @@ -837,13 +813,16 @@ sub _prepare_html_template { map { $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys %::myconfig; } - $additional_params->{"conf_dbcharset"} = $main::dbcharset; - $additional_params->{"conf_webdav"} = $main::webdav; - $additional_params->{"conf_lizenzen"} = $main::lizenzen; - $additional_params->{"conf_latex_templates"} = $main::latex; - $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates; - $additional_params->{"conf_vertreter"} = $main::vertreter; - $additional_params->{"conf_show_best_before"} = $main::show_best_before; + $additional_params->{"conf_dbcharset"} = $::lx_office_conf{system}->{dbcharset}; + $additional_params->{"conf_webdav"} = $::lx_office_conf{features}->{webdav}; + $additional_params->{"conf_lizenzen"} = $::lx_office_conf{features}->{lizenzen}; + $additional_params->{"conf_latex_templates"} = $::lx_office_conf{print_templates}->{latex}; + $additional_params->{"conf_opendocument_templates"} = $::lx_office_conf{print_templates}->{opendocument}; + $additional_params->{"conf_vertreter"} = $::lx_office_conf{features}->{vertreter}; + $additional_params->{"conf_show_best_before"} = $::lx_office_conf{features}->{show_best_before}; + $additional_params->{"conf_parts_image_css"} = $::lx_office_conf{features}->{parts_image_css}; + $additional_params->{"conf_parts_listing_images"} = $::lx_office_conf{features}->{parts_listing_images}; + $additional_params->{"conf_parts_show_image"} = $::lx_office_conf{features}->{parts_show_image}; if (%main::debug_options) { map { $additional_params->{'DEBUG_' . uc($_)} = $main::debug_options{$_} } keys %main::debug_options; @@ -893,7 +872,7 @@ sub init_template { 'PLUGIN_BASE' => 'SL::Template::Plugin', 'INCLUDE_PATH' => '.:templates/webpages', 'COMPILE_EXT' => '.tcc', - 'COMPILE_DIR' => $::userspath . '/templates-cache', + 'COMPILE_DIR' => $::lx_office_conf{paths}->{userspath} . '/templates-cache', })) || die; } @@ -908,6 +887,12 @@ sub show_generic_error { my ($self, $error, %params) = @_; + if ($self->{__ERROR_HANDLER}) { + $self->{__ERROR_HANDLER}->($error); + $main::lxdebug->leave_sub(); + return; + } + my $add_params = { 'title_error' => $params{title}, 'label_error' => $error, @@ -1012,17 +997,13 @@ sub redirect { my ($self, $msg) = @_; if (!$self->{callback}) { - $self->info($msg); - ::end_of_request(); - } -# my ($script, $argv) = split(/\?/, $self->{callback}, 2); -# $script =~ s|.*/||; -# $script =~ s|[^a-zA-Z0-9_\.]||g; -# exec("perl", "$script", $argv); + } else { + print $::form->redirect_header($self->{callback}); + } - print $::form->redirect_header($self->{callback}); + ::end_of_request(); $main::lxdebug->leave_sub(); } @@ -1217,11 +1198,13 @@ sub round_amount { sub parse_template { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $userspath) = @_; + my ($self, $myconfig) = @_; my $out; local (*IN, *OUT); + my $userspath = $::lx_office_conf{paths}->{userspath}; + $self->{"cwd"} = getcwd(); $self->{"tmpdir"} = $self->{cwd} . "/${userspath}"; @@ -1246,7 +1229,7 @@ sub parse_template { $ext_for_format = 'xml'; } elsif ( $self->{"format"} =~ /elster(?:winston|taxbird)/i ) { - $template_type = 'xml'; + $template_type = 'XML'; } elsif ( $self->{"format"} =~ /excel/i ) { $template_type = 'Excel'; @@ -1276,6 +1259,7 @@ sub parse_template { } map { $self->{"${_}"} = $myconfig->{$_}; } qw(co_ustid); + map { $self->{"myconfig_${_}"} = $myconfig->{$_} } grep { $_ ne 'dbpasswd' } keys %{ $myconfig }; $self->{copies} = 1 if (($self->{copies} *= 1) <= 0); @@ -1317,6 +1301,16 @@ sub parse_template { $self->error("$self->{IN} : " . $template->get_error()); } + if ($self->{media} eq 'file') { + copy(join('/', $self->{cwd}, $userspath, $self->{tmpfile}), $out =~ m|^/| ? $out : join('/', $self->{cwd}, $out)) if $template->uses_temp_file; + $self->cleanup; + chdir("$self->{cwd}"); + + $::lxdebug->leave_sub(); + + return; + } + if ($template->uses_temp_file() || $self->{media} eq 'email') { if ($self->{media} eq 'email') { @@ -1325,7 +1319,7 @@ sub parse_template { map { $mail->{$_} = $self->{$_} } qw(cc bcc subject message version format); - $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET; + $mail->{charset} = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email}; $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|; $mail->{fileid} = "$fileid."; @@ -1372,6 +1366,7 @@ sub parse_template { my $numbytes = (-s $self->{tmpfile}); open(IN, $self->{tmpfile}) or $self->error($self->cleanup . "$self->{tmpfile} : $!"); + binmode IN; $self->{copies} = 1 unless $self->{media} eq 'printer'; @@ -1422,7 +1417,6 @@ sub get_formname_translation { bin_list => $main::locale->text('Bin List'), credit_note => $main::locale->text('Credit Note'), invoice => $main::locale->text('Invoice'), - packing_list => $main::locale->text('Packing List'), pick_list => $main::locale->text('Pick List'), proforma => $main::locale->text('Proforma Invoice'), purchase_order => $main::locale->text('Purchase Order'), @@ -1430,7 +1424,6 @@ sub get_formname_translation { sales_order => $main::locale->text('Confirmation'), sales_quotation => $main::locale->text('Quotation'), storno_invoice => $main::locale->text('Storno Invoice'), - storno_packing_list => $main::locale->text('Storno Packing List'), sales_delivery_order => $main::locale->text('Delivery Order'), purchase_delivery_order => $main::locale->text('Delivery Order'), dunning => $main::locale->text('Dunning'), @@ -1522,7 +1515,7 @@ sub cleanup { close(FH); } - if ($self->{tmpfile} && ! $::keep_temp_files) { + if ($self->{tmpfile} && !($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})) { $self->{tmpfile} =~ s|.*/||g; # strip extension $self->{tmpfile} =~ s/\.\w+$//g; @@ -1587,7 +1580,7 @@ sub dbconnect { my ($self, $myconfig) = @_; # connect to database - my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options) + my $dbh = SL::DBConnect->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options) or $self->dberror; # set db options @@ -1606,7 +1599,7 @@ sub dbconnect_noauto { my ($self, $myconfig) = @_; # connect to database - my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0)) + my $dbh = SL::DBConnect->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0)) or $self->dberror; # set db options @@ -2388,7 +2381,7 @@ $main::lxdebug->enter_sub(); $key = "all_payments" unless ($key); - my $query = qq|SELECT * FROM payment_terms ORDER BY id|; + my $query = qq|SELECT * FROM payment_terms ORDER BY sortkey|; $self->{$key} = selectall_hashref_query($self, $dbh, $query); @@ -2466,7 +2459,8 @@ sub _get_warehouses { $self->{$key} = selectall_hashref_query($self, $dbh, $query); if ($bins_key) { - $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|; + $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ? + ORDER BY description|; my $sth = prepare_query($self, $dbh, $query); foreach my $warehouse (@{ $self->{$key} }) { @@ -3273,7 +3267,6 @@ sub save_status { # $main::locale->text('invoice') # $main::locale->text('proforma') # $main::locale->text('sales_order') -# $main::locale->text('packing_list') # $main::locale->text('pick_list') # $main::locale->text('purchase_order') # $main::locale->text('bin_list') @@ -3547,6 +3540,163 @@ sub restore_vars { $main::lxdebug->leave_sub(); } +sub prepare_for_printing { + my ($self) = @_; + + $self->{templates} ||= $::myconfig{templates}; + $self->{formname} ||= $self->{type}; + $self->{media} ||= 'email'; + + die "'media' other than 'email', 'file', 'printer' is not supported yet" unless $self->{media} =~ m/^(?:email|file|printer)$/; + + # set shipto from billto unless set + my $has_shipto = any { $self->{"shipto$_"} } qw(name street zipcode city country contact); + if (!$has_shipto && ($self->{type} =~ m/^(?:purchase_order|request_quotation)$/)) { + $self->{shiptoname} = $::myconfig{company}; + $self->{shiptostreet} = $::myconfig{address}; + } + + my $language = $self->{language} ? '_' . $self->{language} : ''; + + my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates); + if ($self->{language_id}) { + ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) = AM->get_language_details(\%::myconfig, $self, $self->{language_id}); + } else { + $output_dateformat = $::myconfig{dateformat}; + $output_numberformat = $::myconfig{numberformat}; + $output_longdates = 1; + } + + # Retrieve accounts for tax calculation. + IC->retrieve_accounts(\%::myconfig, $self, map { $_ => $self->{"id_$_"} } 1 .. $self->{rowcount}); + + if ($self->{type} =~ /_delivery_order$/) { + DO->order_details(); + } elsif ($self->{type} =~ /sales_order|sales_quotation|request_quotation|purchase_order/) { + OE->order_details(\%::myconfig, $self); + } else { + IS->invoice_details(\%::myconfig, $self, $::locale); + } + + # Chose extension & set source file name + my $extension = 'html'; + if ($self->{format} eq 'postscript') { + $self->{postscript} = 1; + $extension = 'tex'; + } elsif ($self->{"format"} =~ /pdf/) { + $self->{pdf} = 1; + $extension = $self->{'format'} =~ m/opendocument/i ? 'odt' : 'tex'; + } elsif ($self->{"format"} =~ /opendocument/) { + $self->{opendocument} = 1; + $extension = 'odt'; + } elsif ($self->{"format"} =~ /excel/) { + $self->{excel} = 1; + $extension = 'xls'; + } + + my $printer_code = '_' . $self->{printer_code} if $self->{printer_code}; + my $email_extension = '_email' if -f "$self->{templates}/$self->{formname}_email${language}${printer_code}.${extension}"; + $self->{IN} = "$self->{formname}${email_extension}${language}${printer_code}.${extension}"; + + # Format dates. + $self->format_dates($output_dateformat, $output_longdates, + qw(invdate orddate quodate pldate duedate reqdate transdate shippingdate deliverydate validitydate paymentdate datepaid + transdate_oe deliverydate_oe employee_startdate employee_enddate), + grep({ /^(?:datepaid|transdate_oe|reqdate|deliverydate|deliverydate_oe|transdate)_\d+$/ } keys(%{$self}))); + + $self->reformat_numbers($output_numberformat, 2, + qw(invtotal ordtotal quototal subtotal linetotal listprice sellprice netprice discount tax taxbase total paid), + grep({ /^(?:linetotal|listprice|sellprice|netprice|taxbase|discount|paid|subtotal|total|tax)_\d+$/ } keys(%{$self}))); + + $self->reformat_numbers($output_numberformat, undef, qw(qty price_factor), grep({ /^qty_\d+$/} keys(%{$self}))); + + my ($cvar_date_fields, $cvar_number_fields) = CVar->get_field_format_list('module' => 'CT', 'prefix' => 'vc_'); + + if (scalar @{ $cvar_date_fields }) { + $self->format_dates($output_dateformat, $output_longdates, @{ $cvar_date_fields }); + } + + while (my ($precision, $field_list) = each %{ $cvar_number_fields }) { + $self->reformat_numbers($output_numberformat, $precision, @{ $field_list }); + } + + return $self; +} + +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__ @@ -3566,9 +3716,7 @@ Points of interest for a beginner are: =head1 SPECIAL FUNCTIONS -=over 4 - -=item _store_value() +=head2 C<_store_value()> parses a complex var name, and stores it in the form. @@ -3623,7 +3771,7 @@ supported key structures are: filter.status[] => $form->{status}->[ val1, val2, ... ] -=item update_business PARAMS +=head2 C