summaryrefslogtreecommitdiff
path: root/templates_nb
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-10-04 18:24:40 +0200
committerJonas Smedegaard <dr@jones.dk>2010-10-04 18:24:40 +0200
commit86c7735be729573ba10d6fbd10cc68cdf9d125e7 (patch)
treec521a6b4b6ceaec1bb6866aaa289344fd8f5bdcc /templates_nb
parent83fec4958d6a4100e6038b39df6f383f304798c8 (diff)
parent256990695c6892e4c7661ac21b9a513b4b0120ff (diff)
Merge branch 'allinone-da' into allinone-multilang
Diffstat (limited to 'templates_nb')
0 files changed, 0 insertions, 0 deletions
kwa">use LedgerSMB::Sysconfig;
  • package Form;
  • sub new {
  • my $type = shift;
  • my $self = {};
  • read(STDIN, $_, $ENV{CONTENT_LENGTH});
  • if ($ENV{QUERY_STRING}) {
  • $_ = $ENV{QUERY_STRING};
  • }
  • if ($ARGV[0]) {
  • $_ = $ARGV[0];
  • }
  • %$self = split /[&=]/;
  • for (keys %$self) { $self->{$_} = unescape("", $self->{$_}) }
  • if (substr($self->{action}, 0, 1) !~ /( |\.)/) {
  • $self->{action} = lc $self->{action};
  • $self->{action} =~ s/( |-|,|\#|\/|\.$)/_/g;
  • }
  • $self->{menubar} = 1 if $self->{path} =~ /lynx/i;
  • #menubar will be deprecated, replaced with below
  • $self->{lynx} = 1 if $self->{path} =~ /lynx/i;
  • $self->{version} = "1.1.1";
  • $self->{dbversion} = "1.2.0";
  • bless $self, $type;
  • }
  • sub debug {
  • my ($self, $file) = @_;
  • if ($file) {
  • open(FH, "> $file") or die $!;
  • for (sort keys %$self) { print FH "$_ = $self->{$_}\n" }
  • close(FH);
  • } else {
  • print "\n";
  • for (sort keys %$self) { print "$_ = $self->{$_}\n" }
  • }
  • }
  • sub escape {
  • my ($self, $str, $beenthere) = @_;
  • # for Apache 2 we escape strings twice
  • if (($ENV{SERVER_SIGNATURE} =~ /Apache\/2\.(\d+)\.(\d+)/) && !$beenthere) {
  • $str = $self->escape($str, 1) if $1 == 0 && $2 < 44;
  • }
  • $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
  • $str;
  • }
  • sub unescape {
  • my ($self, $str) = @_;
  • $str =~ tr/+/ /;
  • $str =~ s/\\$//;
  • $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
  • $str =~ s/\r?\n/\n/g;
  • $str;
  • }
  • sub quote {
  • my ($self, $str) = @_;
  • if ($str && ! ref($str)) {
  • $str =~ s/"/&quot;/g;
  • }
  • $str;
  • }
  • sub unquote {
  • my ($self, $str) = @_;
  • if ($str && ! ref($str)) {
  • $str =~ s/&quot;/"/g;
  • }
  • $str;
  • }
  • sub hide_form {
  • my $self = shift;
  • if (@_) {
  • for (@_) {
  • print qq|<input type="hidden" name="$_" value="|.$self->quote($self->{$_}).qq|" />\n|
  • }
  • } else {
  • delete $self->{header};
  • for (sort keys %$self) {
  • print qq|<input type="hidden" name="$_" value="|.$self->quote($self->{$_}).qq|" />\n|
  • }
  • }
  • }
  • sub error {
  • my ($self, $msg) = @_;
  • if ($ENV{HTTP_USER_AGENT}) {
  • $self->{msg} = $msg;
  • $self->{format} = "html";
  • $self->format_string('msg');
  • delete $self->{pre};
  • if (!$self->{header}) {
  • $self->header;
  • }
  • print qq|<body><h2 class="error">Error!</h2> <p><b>$self->{msg}</b></body>|;
  • exit;
  • } else {
  • if ($self->{error_function}) {
  • &{ $self->{error_function} }($msg);
  • } else {
  • die "Error: $msg\n";
  • }
  • }
  • }
  • sub info {
  • my ($self, $msg) = @_;
  • if ($ENV{HTTP_USER_AGENT}) {
  • $msg =~ s/\n/<br>/g;
  • delete $self->{pre};
  • if (!$self->{header}) {
  • $self->header;
  • print qq| <body>|;
  • $self->{header} = 1;
  • }
  • print "<b>$msg</b>";
  • } else {
  • if ($self->{info_function}) {
  • &{ $self->{info_function} }($msg);
  • } else {
  • print "$msg\n";
  • }
  • }
  • }
  • sub numtextrows {
  • my ($self, $str, $cols, $maxrows) = @_;
  • my $rows = 0;
  • for (split /\n/, $str) {
  • $rows += int (((length) - 2)/$cols) + 1
  • }
  • $maxrows = $rows unless defined $maxrows;
  • return ($rows > $maxrows) ? $maxrows : $rows;
  • }
  • sub dberror {
  • my ($self, $msg) = @_;
  • $self->error("$msg\n".$DBI::errstr);
  • }
  • sub isblank {
  • my ($self, $name, $msg) = @_;
  • $self->error($msg) if $self->{$name} =~ /^\s*$/;
  • }
  • sub header {
  • my ($self, $init, $headeradd) = @_;
  • return if $self->{header};
  • my ($stylesheet, $favicon, $charset);
  • if ($ENV{HTTP_USER_AGENT}) {
  • if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) {
  • $stylesheet = qq|<link rel="stylesheet" href="css/$self->{stylesheet}" type="text/css" title="LedgerSMB stylesheet" />\n|;
  • }
  • if ($self->{charset}) {
  • $charset = qq|<meta http-equiv="content-type" content="text/html; charset=$self->{charset}" />\n|;
  • }
  • $self->{titlebar} = ($self->{title}) ? "$self->{title} - $self->{titlebar}" : $self->{titlebar};
  • $self->set_cookie($init);
  • print qq|Content-Type: text/html\n\n
  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  • "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  • <head>
  • <title>$self->{titlebar}</title>
  • <meta http-equiv="Pragma" content="no-cache" />
  • <meta http-equiv="Expires" content="-1" />
  • <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  • $stylesheet
  • $charset
  • <meta name="robots" content="noindex,nofollow" />
  • $headeradd
  • </head>
  • $self->{pre} \n|;
  • }
  • $self->{header} = 1;
  • }
  • sub set_cookie {
  • my ($self, $init) = @_;
  • $self->{timeout} = ($self->{timeout} > 0) ? $self->{timeout} : 3600;
  • my $t = ($self->{endsession}) ? time : time + $self->{timeout};
  • if ($ENV{HTTP_USER_AGENT}) {
  • my @d = split / +/, scalar gmtime($t);
  • my $today = "$d[0], $d[2]-$d[1]-$d[4] $d[3] GMT";
  • if ($init) {
  • $self->{sessionid} = time;
  • }
  • print qq|Set-Cookie: LedgerSMB-$self->{login}=$self->{sessionid}; expires=$today; path=/;\n| if $self->{login};
  • }
  • }
  • sub redirect {
  • my ($self, $msg) = @_;
  • if ($self->{callback}) {
  • my ($script, $argv) = split(/\?/, $self->{callback});
  • exec ("perl", $script, $argv);
  • } else {
  • $self->info($msg);
  • }
  • }
  • sub sort_columns {
  • my ($self, @columns) = @_;
  • if ($self->{sort}) {
  • if (@columns) {
  • @columns = grep !/^$self->{sort}$/, @columns;
  • splice @columns, 0, 0, $self->{sort};
  • }
  • }
  • @columns;
  • }
  • sub sort_order {
  • my ($self, $columns, $ordinal) = @_;
  • # setup direction
  • if ($self->{direction}) {
  • if ($self->{sort} eq $self->{oldsort}) {
  • if ($self->{direction} eq 'ASC') {
  • $self->{direction} = "DESC";
  • } else {
  • $self->{direction} = "ASC";
  • }
  • }
  • } else {
  • $self->{direction} = "ASC";
  • }
  • $self->{oldsort} = $self->{sort};
  • my @a = $self->sort_columns(@{$columns});
  • if (%$ordinal) {
  • $a[0] = ($ordinal->{$a[$_]}) ? "$ordinal->{$a[0]} $self->{direction}" : "$a[0] $self->{direction}";
  • for (1 .. $#a) {
  • $a[$_] = $ordinal->{$a[$_]} if $ordinal->{$a[$_]}
  • }
  • } else {
  • $a[0] .= " $self->{direction}";
  • }
  • $sortorder = join ',', @a;
  • $sortorder;
  • }
  • sub format_amount {
  • my ($self, $myconfig, $amount, $places, $dash) = @_;
  • my $negative ;
  • if ($amount){
  • $amount = $self->parse_amount($myconfig, $amount);
  • $negative = ($amount < 0);
  • $amount =~ s/-//;
  • }
  • if ($places =~ /\d+/) {
  • #$places = 4 if $places == 2;
  • $amount = $self->round_amount($amount, $places);
  • }
  • # is the amount negative
  • # Parse $myconfig->{numberformat}
  • my ($ts, $ds) = ($1, $2);
  • if ($amount) {
  • if ($myconfig->{numberformat}) {
  • my ($whole, $dec) = split /\./, "$amount";
  • $amount = join '', reverse split //, $whole;
  • if ($places) {
  • $dec .= "0" x $places;
  • $dec = substr($dec, 0, $places);
  • }
  • if ($myconfig->{numberformat} eq '1,000.00') {
  • $amount =~ s/\d{3,}?/$&,/g;
  • $amount =~ s/,$//;
  • $amount = join '', reverse split //, $amount;
  • $amount .= "\.$dec" if ($dec ne "");
  • }
  • if ($myconfig->{numberformat} eq '1 000.00') {
  • $amount =~ s/\d{3,}?/$& /g;
  • $amount =~ s/\s$//;
  • $amount = join '', reverse split //, $amount;
  • $amount .= "\.$dec" if ($dec ne "");
  • }
  • if ($myconfig->{numberformat} eq "1'000.00") {
  • $amount =~ s/\d{3,}?/$&'/g;
  • $amount =~ s/'$//;
  • $amount = join '', reverse split //, $amount;
  • $amount .= "\.$dec" if ($dec ne "");
  • }
  • if ($myconfig->{numberformat} eq '1.000,00') {
  • $amount =~ s/\d{3,}?/$&./g;
  • $amount =~ s/\.$//;
  • $amount = join '', reverse split //, $amount;
  • $amount .= ",$dec" if ($dec ne "");
  • }
  • if ($myconfig->{numberformat} eq '1000,00') {
  • $amount = "$whole";
  • $amount .= ",$dec" if ($dec ne "");
  • }
  • if ($myconfig->{numberformat} eq '1000.00') {
  • $amount = "$whole";
  • $amount .= ".$dec" if ($dec ne "");
  • }
  • if ($dash =~ /-/) {
  • $amount = ($negative) ? "($amount)" : "$amount";
  • } elsif ($dash =~ /DRCR/) {
  • $amount = ($negative) ? "$amount DR" : "$amount CR";
  • } else {
  • $amount = ($negative) ? "-$amount" : "$amount";
  • }
  • }
  • } else {
  • if ($dash eq "0" && $places) {
  • if ($myconfig->{numberformat} eq '1.000,00') {
  • $amount = "0".","."0" x $places;
  • } else {
  • $amount = "0"."."."0" x $places;
  • }
  • } else {
  • $amount = ($dash ne "") ? "$dash" : "";
  • }
  • }
  • $amount;
  • }
  • sub parse_amount {
  • my ($self, $myconfig, $amount) = @_;
  • if ($amount eq '') {
  • return undef;
  • }
  • if (UNIVERSAL::isa($amount, 'Math::BigFloat')){ # Amount may not be an object
  • return $amount;
  • }
  • my $numberformat = $myconfig->{numberformat};
  • if (($numberformat eq '1.000,00') ||
  • ($numberformat eq '1000,00')) {
  • $amount =~ s/\.//g;
  • $amount =~ s/,/./;
  • }
  • if ($numberformat eq '1 000.00'){
  • $amount =~ s/\s//g;
  • }
  • if ($numberformat eq "1'000.00") {
  • $amount =~ s/'//g;
  • }
  • $amount =~ s/,//g;
  • if ($amount =~ s/\((\d*\.?\d*)\)/$1/){
  • $amount = $1 * -1;
  • }
  • if ($amount =~ s/(\d*\.?\d*)\s?DR/$1/){
  • $amount = $1 * -1;
  • }
  • $amount =~ s/\s?CR//;
  • $amount = new Math::BigFloat($amount);
  • return ($amount * 1);
  • }
  • sub round_amount {
  • my ($self, $amount, $places) = @_;
  • # These rounding rules follow from the previous implementation.
  • # They should be changed to allow different rules for different accounts.
  • Math::BigFloat->round_mode('+inf') if $amount >= 0;
  • Math::BigFloat->round_mode('-inf') if $amount < 0;
  • $amount = Math::BigFloat->new($amount)->ffround(-$places) if $places >= 0;
  • $amount = Math::BigFloat->new($amount)->ffround(-($places-1)) if $places < 0;
  • return $amount;
  • }
  • sub callproc {
  • my $procname = shift @_;
  • my $argstr = "";
  • my @results;