#======================================================================
package Form;
+
+#use strict;
+
use Data::Dumper;
use CGI;
sub _store_value {
$main::lxdebug->enter_sub(2);
- my $self = shift;
+ my $curr = shift;
my $key = shift;
my $value = shift;
- my $curr = $self;
-
while ($key =~ /\[\+?\]\.|\./) {
substr($key, 0, $+[0]) = '';
sub _input_to_hash {
$main::lxdebug->enter_sub(2);
- my $self = shift;
- my $input = shift;
+ my $params = shift;
+ my $input = shift;
- my @pairs = split(/&/, $input);
+ my @pairs = split(/&/, $input);
foreach (@pairs) {
my ($key, $value) = split(/=/, $_, 2);
- $self->_store_value($self->unescape($key), $self->unescape($value));
+ _store_value($params, unescape(undef, $key), unescape(undef, $value));
}
$main::lxdebug->leave_sub(2);
sub _request_to_hash {
$main::lxdebug->enter_sub(2);
- my $self = shift;
- my $input = shift;
+ my $params = shift;
+ my $input = shift;
if (!$ENV{'CONTENT_TYPE'}
|| ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
- $self->_input_to_hash($input);
+ _input_to_hash($params, $input);
$main::lxdebug->leave_sub(2);
return;
substr $line, $-[0], $+[0] - $-[0], "";
}
- $previous = $self->_store_value($name, '');
- $self->{FILENAME} = $filename if ($filename);
+ $previous = _store_value($params, $name, '');
+ $params->{FILENAME} = $filename if ($filename);
next;
}
$main::lxdebug->leave_sub(2);
}
+sub _recode_recursively {
+ my ($iconv, $param) = @_;
+
+ if (ref $param eq 'HASH') {
+ foreach my $key (keys %{ $param }) {
+ if (!ref $param->{$key}) {
+ $param->{$key} = $iconv->convert($param->{$key});
+ } else {
+ _recode_recursively($iconv, $param->{$key});
+ }
+ }
+
+ } elsif (ref $param eq 'ARRAY') {
+ foreach my $idx (0 .. scalar(@{ $param }) - 1) {
+ if (!ref $param->[$idx]) {
+ $param->[$idx] = $iconv->convert($param->[$idx]);
+ } else {
+ _recode_recursively($iconv, $param->[$idx]);
+ }
+ }
+ }
+}
+
sub new {
$main::lxdebug->enter_sub();
bless $self, $type;
- $self->_request_to_hash($_);
+ my $parameters = { };
+ _request_to_hash($parameters, $_);
+
+ my $db_charset = $main::dbcharset;
+ $db_charset ||= Common::DEFAULT_CHARSET;
+
+ if ($parameters->{INPUT_ENCODING} && (lc $parameters->{INPUT_ENCODING} ne $db_charset)) {
+ require Text::Iconv;
+ my $iconv = Text::Iconv->new($parameters->{INPUT_ENCODING}, $db_charset);
+
+ _recode_recursively($iconv, $parameters);
+
+ delete $parameters{INPUT_ENCODING};
+ }
+
+ map { $self->{$_} = $parameters->{$_}; } keys %{ $parameters };
$self->{action} = lc $self->{action};
$self->{action} =~ s/( |-|,|\#)/_/g;
<script type="text/javascript">
<!--
- function fokus() {
+ function focus() {
$fokus
}
//-->
if ($amount eq "") {
$amount = 0;
}
-
+
# Hey watch out! The amount can be an exponential term like 1.13686837721616e-13
-
+
my $neg = ($amount =~ s/^-//);
my $exp = ($amount =~ m/[e]/) ? 1 : 0;
-
+
if (defined($places) && ($places ne '')) {
if (not $exp) {
if ($places < 0) {
open(OUT, $self->{OUT})
or $self->error($self->cleanup . "$self->{OUT} : $!");
} else {
- $self->{attachment_filename} = ($self->{attachment_filename})
+ $self->{attachment_filename} = ($self->{attachment_filename})
? $self->{attachment_filename}
: $self->generate_attachment_filename();
$main::lxdebug->enter_sub();
my ($self, $myconfig) = @_;
-
+
# connect to database
my $dbh =
DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
if ($curr eq '') {
$main::lxdebug->leave_sub();
return;
- }
+ }
$query = qq|SELECT curr FROM defaults|;
my ($currency) = selectrow_query($self, $dbh, $query);
SET $set
WHERE curr = ?
AND transdate = ?|;
-
+
} else {
$query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
VALUES (?, $buy, $sell, ?)|;
my ($self, $myconfig, $currency, $transdate, $fld) = @_;
+ if ($fld !~/^buy|sell$/) {
+ $self->error('Fatal: check_exchangerate called with invalid buy/sell argument');
+ }
+
unless ($transdate) {
$main::lxdebug->leave_sub();
return "";
shiptophone = ? AND
shiptofax = ? AND
shiptoemail = ? AND
- module = ? AND
+ module = ? AND
trans_id = ?|;
my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
if(!$insert_check){
sub _get_taxcharts {
$main::lxdebug->enter_sub();
- my ($self, $dbh, $key) = @_;
+ my ($self, $dbh, $params) = @_;
+
+ my $key = "all_taxcharts";
+ my @where;
+
+ if (ref $params eq 'HASH') {
+ $key = $params->{key} if ($params->{key});
+ if ($params->{module} eq 'AR') {
+ push @where, 'taxkey NOT IN (8, 9, 18, 19)';
- $key = "all_taxcharts" unless ($key);
+ } elsif ($params->{module} eq 'AP') {
+ push @where, 'taxkey NOT IN (1, 2, 3, 12, 13)';
+ }
+
+ } elsif ($params) {
+ $key = $params;
+ }
- my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
+ my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where);
+
+ my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|;
$self->{$key} = selectall_hashref_query($self, $dbh, $query);
$key = "all_currencies" unless ($key);
my $query = qq|SELECT curr AS currency FROM defaults|;
-
+
$self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
$main::lxdebug->leave_sub();
$key = "all_payments" unless ($key);
my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
-
+
$self->{$key} = selectall_hashref_query($self, $dbh, $query);
$main::lxdebug->leave_sub();
if ($params{"employees"}) {
$self->_get_employees($dbh, "all_employees", $params{"employees"});
}
-
+
if ($params{"salesmen"}) {
$self->_get_employees($dbh, "all_salesmen", $params{"salesmen"});
}
if ($params{"dunning_configs"}) {
$self->_get_dunning_configs($dbh, $params{"dunning_configs"});
}
-
+
if($params{"currencies"}) {
$self->_get_currencies($dbh, $params{"currencies"});
}
-
+
if($params{"customers"}) {
if (ref $params{"customers"} eq 'HASH') {
$self->_get_customers($dbh, $params{"customers"}{key}, $params{"customers"}{limit});
$self->_get_customers($dbh, $params{"customers"});
}
}
-
+
if($params{"vendors"}) {
if (ref $params{"vendors"} eq 'HASH') {
$self->_get_vendors($dbh, $params{"vendors"}{key}, $params{"vendors"}{limit});
$self->_get_vendors($dbh, $params{"vendors"});
}
}
-
+
if($params{"payments"}) {
$self->_get_payments($dbh, $params{"payments"});
}
qq|WHERE trans_id = | . $trans_id
. $restriction . qq| |
. $order;
-
+
my $sth = $dbh->prepare($query) || $self->dberror($query);
$sth->execute() || $self->dberror("$query");
$hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
$tempArray[$i++] = $hash_ref;
}
- $main::lxdebug->leave_sub() and return \@tempArray
+ $main::lxdebug->leave_sub() and return \@tempArray
if ($i > 0 && $tempArray[0] ne "");
}
$main::lxdebug->leave_sub();