my $db_charset = $main::dbcharset;
$db_charset ||= Common::DEFAULT_CHARSET;
- if ($self->{INPUT_ENCODING}) {
- if (lc $self->{INPUT_ENCODING} ne lc $db_charset) {
- require Text::Iconv;
- my $iconv = Text::Iconv->new($self->{INPUT_ENCODING}, $db_charset);
+ my $encoding = $self->{INPUT_ENCODING} || $db_charset;
+ delete $self->{INPUT_ENCODING};
- _recode_recursively($iconv, $self);
- }
-
- delete $self->{INPUT_ENCODING};
- }
+ _recode_recursively(SL::Iconv->new($encoding, $db_charset), $self);
$self->{action} = lc $self->{action};
$self->{action} =~ s/( |-|,|\#)/_/g;
- $self->{version} = "2.6.1";
+ #$self->{version} = "2.6.1"; # Old hardcoded but secure style
+ open VERSION_FILE, "VERSION"; # New but flexible code reads version from VERSION-file
+ $self->{version} = <VERSION_FILE>;
+ close VERSION_FILE;
+ $self->{version} =~ s/[^0-9A-Za-z\.\_\-]//g; # only allow numbers, letters, points, underscores and dashes. Prevents injecting of malicious code.
$main::lxdebug->leave_sub();
if (!$self->{header}) {
$self->header;
- print qq|
- <body>|;
+ print qq|<body>|;
}
print qq|
-
- <p><b>$msg</b>
+ <p class="message_ok"><b>$msg</b></p>
+
+ <script type="text/javascript">
+ <!--
+ // If JavaScript is enabled, the whole thing will be reloaded.
+ // The reason is: When one changes his menu setup (HTML / XUL / CSS ...)
+ // it now loads the correct code into the browser instead of do nothing.
+ setTimeout("top.frames.location.href='login.pl'",500);
+ //-->
+ </script>
+
+</body>
|;
} else {
</script>
| if $self->{"fokus"};
+ my $title_hack = qq|
+ <script type="text/javascript">
+ <!--
+ // Write a meaningful title-tag for our frameset.
+ top.document.title="| . $self->{"title"} . qq| - | . $self->{"login"} . qq| - | . $::myconfig{dbname} . qq| - Ver. | . $self->{"version"} . qq|";
+ //-->
+ </script>
+ |;
+
#Set Calendar
my $jsscript = "";
if ($self->{jsscript} == 1) {
$favicon
$jsscript
$ajax
-
$fokus
-
+ $title_hack
+
<link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
<meta name="robots" content="noindex,nofollow" />
'CACHE_SIZE' => 0,
'PLUGIN_BASE' => 'SL::Template::Plugin',
'INCLUDE_PATH' => '.:templates/webpages',
- 'COMPILE_EXT' => $main::template_compile_ext,
- 'COMPILE_DIR' => $main::template_compile_dir,
+ 'COMPILE_EXT' => '.tcc',
+ 'COMPILE_DIR' => $::userspath . '/templates-cache',
})) || die;
}
$main::lxdebug->enter_sub();
my ($self, $myconfig, $userspath) = @_;
- my ($template, $out);
+ my $out;
local (*IN, *OUT);
my $ext_for_format;
+ my $template_type;
if ($self->{"format"} =~ /(opendocument|oasis)/i) {
- $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+ $template_type = 'OpenDocument';
$ext_for_format = $self->{"format"} =~ m/pdf/ ? 'pdf' : 'odt';
} elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
$ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
- $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+ $template_type = 'LaTeX';
$ext_for_format = 'pdf';
} elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
- $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+ $template_type = 'HTML';
$ext_for_format = 'html';
} elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
- $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+ $template_type = 'XML';
$ext_for_format = 'xml';
- } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
- $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
-
- } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
- $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+ } elsif ( $self->{"format"} =~ /elster(?:winston|taxbird)/i ) {
+ $template_type = 'xml';
} elsif ( $self->{"format"} =~ /excel/i ) {
- $template = ExcelTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+ $template_type = 'Excel';
$ext_for_format = 'xls';
} elsif ( defined $self->{'format'}) {
$self->error("Outputformat not defined: $self->{'format'}");
}
+ my $template = SL::Template::create(type => $template_type,
+ file_name => $self->{IN},
+ form => $self,
+ myconfig => $myconfig,
+ userspath => $userspath);
+
# Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
$self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
# Database routines used throughout
+sub _dbconnect_options {
+ my $self = shift;
+ my $options = { pg_enable_utf8 => $::locale->is_utf8,
+ @_ };
+
+ return $options;
+}
+
sub dbconnect {
$main::lxdebug->enter_sub(2);
my ($self, $myconfig) = @_;
# connect to database
- my $dbh =
- DBI->connect($myconfig->{dbconnect},
- $myconfig->{dbuser}, $myconfig->{dbpasswd})
+ my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options)
or $self->dberror;
# set db options
my ($self, $myconfig) = @_;
# connect to database
- my $dbh =
- DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
- $myconfig->{dbpasswd}, { AutoCommit => 0 })
+ my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0))
or $self->dberror;
# set db options
my $options = ref $key eq 'HASH' ? $key : { key => $key };
$options->{key} ||= "all_customers";
my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
- my $where = $options->{business_is_salesman} ? qq| AND business_id IN (SELECT id FROM business WHERE salesman)| : '';
- my $query = qq|SELECT * FROM customer WHERE NOT obsolete $where ORDER BY name $limit_clause|;
+ my @where;
+ push @where, qq|business_id IN (SELECT id FROM business WHERE salesman)| if $options->{business_is_salesman};
+ push @where, qq|NOT obsolete| if !$options->{with_obsolete};
+ my $where_str = @where ? "WHERE " . join(" AND ", map { "($_)" } @where) : '';
+
+ my $query = qq|SELECT * FROM customer $where_str ORDER BY name $limit_clause|;
$self->{ $options->{key} } = selectall_hashref_query($self, $dbh, $query);
$main::lxdebug->leave_sub();