Merge branch 'master' of ssh://lx-office/~/lx-office-erp
authorSven Schöling <s.schoeling@linet-services.de>
Mon, 3 Jan 2011 17:35:03 +0000 (18:35 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Mon, 3 Jan 2011 17:35:03 +0000 (18:35 +0100)
12 files changed:
SL/AR.pm
SL/Auth.pm
SL/DBUpgrade2.pm
SL/Dispatcher.pm
SL/FCGIFixes.pm
SL/ReportGenerator.pm
admin.pl
bin/mozilla/admin.pl
bin/mozilla/ap.pl
bin/mozilla/ar.pl
bin/mozilla/gl.pl
dispatcher.fpl

index a4d1000..1754fe6 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -171,7 +171,7 @@ sub post_transaction {
         # insert detail records in acc_trans
         $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey)
                      VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|;
-        @values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"amount_$i"}), conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id,
+        @values = (conv_i($form->{id}), $form->{AR_amounts}{"amount_$i"}, conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id,
                    conv_i($form->{"taxkey_$i"}));
         do_query($form, $dbh, $query, @values);
 
@@ -179,7 +179,7 @@ sub post_transaction {
           # insert detail records in acc_trans
           $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey)
                        VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|;
-          @values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"tax_$i"}), conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id,
+          @values = (conv_i($form->{id}), $form->{AR_amounts}{"tax_$i"}, conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id,
                      conv_i($form->{"taxkey_$i"}));
           do_query($form, $dbh, $query, @values);
         }
index 2bd2d09..087301a 100644 (file)
@@ -13,6 +13,7 @@ use SL::Auth::DB;
 use SL::Auth::LDAP;
 
 use SL::User;
+use SL::DBUpgrade2;
 use SL::DBUtils;
 
 use strict;
@@ -303,7 +304,7 @@ sub create_tables {
   $charset     ||= Common::DEFAULT_CHARSET;
 
   $dbh->rollback();
-  User->process_query($main::form, $dbh, 'sql/auth_db.sql', undef, $charset);
+  SL::DBUpgrade2->new(form => $::form)->process_query($dbh, 'sql/auth_db.sql', undef, $charset);
 
   $main::lxdebug->leave_sub();
 }
index 8e61f22..ca45510 100644 (file)
@@ -4,6 +4,7 @@ use IO::File;
 use List::MoreUtils qw(any);
 
 use SL::Common;
+use SL::DBUtils;
 use SL::Iconv;
 
 use strict;
index cc886d8..4a3f131 100644 (file)
@@ -22,6 +22,15 @@ use File::Basename;
 # number 'die' was called in.
 use constant END_OF_REQUEST => "END-OF-REQUEST\n";
 
+sub new {
+  my ($class, $interface) = @_;
+
+  my $self           = bless {}, $class;
+  $self->{interface} = lc($interface || 'cgi');
+
+  return $self;
+}
+
 sub pre_request_checks {
   if (!$::auth->session_tables_present) {
     if ($::form->{script} eq 'admin.pl') {
@@ -138,15 +147,17 @@ sub _run_controller {
 }
 
 sub handle_request {
+  my $self         = shift;
+  $self->{request} = shift;
+
   $::lxdebug->enter_sub;
   $::lxdebug->begin_request;
 
-  my $interface = lc(shift || 'cgi');
   my ($script, $path, $suffix, $script_name, $action, $routing_type);
 
   $script_name = $ENV{SCRIPT_NAME};
 
-  unrequire_bin_mozilla($interface);
+  $self->unrequire_bin_mozilla;
 
   $::cgi         = CGI->new('');
   $::locale      = Locale->new($::language);
@@ -230,7 +241,8 @@ sub handle_request {
 }
 
 sub unrequire_bin_mozilla {
-  return unless $_[0] =~ m/^(?:fastcgi|fcgid|fcgi)$/;
+  my $self = shift;
+  return unless $self->{interface} =~ m/^(?:fastcgi|fcgid|fcgi)$/;
 
   for (keys %INC) {
     next unless m#^bin/mozilla/#;
@@ -295,6 +307,12 @@ sub _route_controller_request {
   return ($controller, $action);
 }
 
+sub get_standard_filehandles {
+  my $self = shift;
+
+  return $self->{interface} =~ m/f(?:ast)cgi/i ? $self->{request}->GetHandles() : (\*STDIN, \*STDOUT, \*STDERR);
+}
+
 package main;
 
 use strict;
index 47393aa..d341f4a 100644 (file)
@@ -25,6 +25,7 @@ use version;
 
 sub fix_print_and_internal_encoding_after_0_68 {
   return if version->new("$FCGI::VERSION")->numify <= version->new("0.68")->numify;
+  return if lc($::dbcharset) !~ m/^(?:utf-?8|unicode)$/;
 
   my $encoder             = Encode::find_encoding('UTF-8');
   my $original_fcgi_print = \&FCGI::Stream::PRINT;
index 2b37e78..f6095a8 100644 (file)
@@ -686,17 +686,26 @@ sub _print_content {
   }
 }
 
-sub unescape_string {
-  my ($self, $text, $do_iconv) = @_;
+sub _handle_quoting_and_encoding {
+  my ($self, $text, $do_unquote) = @_;
 
-  $text = $main::locale->unquote_special_chars('HTML', $text);
-  $text = $::locale->{iconv}->convert($text) if $do_iconv;
+  $text = $main::locale->unquote_special_chars('HTML', $text) if $do_unquote;
+  $text = Encode::encode('UTF-8', $text) if $::locale->is_utf8;
 
   return $text;
 }
 
 sub generate_csv_content {
-  my $self = shift;
+  my $self   = shift;
+  my $stdout = ($::dispatcher->get_standard_filehandles)[1];
+
+  # Text::CSV_XS seems to downgrade to bytes already (see
+  # SL/FCGIFixes.pm). Therefore don't let FCGI do that again.
+  $::locale->with_raw_io($stdout, sub { $self->_generate_csv_content($stdout) });
+}
+
+sub _generate_csv_content {
+  my ($self, $stdout) = @_;
 
   my %valid_sep_chars    = (';' => ';', ',' => ',', ':' => ':', 'TAB' => "\t");
   my %valid_escape_chars = ('"' => 1, "'" => 1);
@@ -718,13 +727,9 @@ sub generate_csv_content {
 
   my @visible_columns = $self->get_visible_columns('CSV');
 
-  my $stdout;
-  open $stdout, '>-';
-  binmode $stdout, ':encoding(utf8)' if $::locale->is_utf8;
-
   if ($opts->{headers}) {
     if (!$self->{custom_headers}) {
-      $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}, 1) } @visible_columns ]);
+      $csv->print($stdout, [ map { $self->_handle_quoting_and_encoding($self->{columns}->{$_}->{text}, 1) } @visible_columns ]);
 
     } else {
       foreach my $row (@{ $self->{custom_headers} }) {
@@ -732,7 +737,7 @@ sub generate_csv_content {
 
         foreach my $col (@{ $row }) {
           my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1;
-          push @{ $fields }, ($self->unescape_string($col->{text})) x $num_output;
+          push @{ $fields }, ($self->_handle_quoting_and_encoding($col->{text}, 1)) x $num_output;
         }
 
         $csv->print($stdout, $fields);
@@ -754,7 +759,7 @@ sub generate_csv_content {
         my $num_output = ($row->{$col}{colspan} && ($row->{$col}->{colspan} > 1)) ? $row->{$col}->{colspan} : 1;
         $skip_next     = $num_output - 1;
 
-        push @data, join($eol, map { s/\r?\n/$eol/g; $_ } @{ $row->{$col}->{data} });
+        push @data, join($eol, map { s/\r?\n/$eol/g; $self->_handle_quoting_and_encoding($_, 0) } @{ $row->{$col}->{data} });
         push @data, ('') x $skip_next if ($skip_next);
       }
 
index 603d166..433ffe9 100755 (executable)
--- a/admin.pl
+++ b/admin.pl
@@ -4,7 +4,8 @@ use strict;
 
 use SL::Dispatcher;
 
-SL::Dispatcher::pre_startup();
-SL::Dispatcher::handle_request('CGI');
+our $dispatcher = SL::Dispatcher->new('CGI');
+$dispatcher->pre_startup;
+$dispatcher->handle_request;
 
 1;
index 2819da0..eac4d08 100755 (executable)
@@ -84,10 +84,9 @@ sub run {
       if ($auth->session_tables_present()) {
         $::auth->set_session_value('rpw', $::form->{rpw});
         $::auth->create_or_refresh_session();
+        _apply_dbupgrade_scripts();
       }
 
-      _apply_dbupgrade_scripts();
-
       call_sub($locale->findsub($form->{action}));
     }
   } else {
@@ -363,8 +362,12 @@ sub add_user {
     "dateformat"   => "dd.mm.yy",
     "stylesheet"   => "lx-office-erp.css",
     "menustyle"    => "old",
+    dbport         => $::auth->{DB_config}->{port} || 5432,
+    dbuser         => $::auth->{DB_config}->{user} || 'lxoffice',
+    dbhost         => $::auth->{DB_config}->{host} || 'localhost',
   };
 
+
   edit_user_form($myconfig);
 }
 
@@ -650,10 +653,10 @@ sub dbselect_source {
   my $form           = $main::form;
   my $locale         = $main::locale;
 
-  $form->{dbport}    = '5432';
-  $form->{dbuser}    = 'lxoffice';
+  $form->{dbport}    = $::auth->{DB_config}->{port} || 5432;
+  $form->{dbuser}    = $::auth->{DB_config}->{user} || 'lxoffice';
   $form->{dbdefault} = 'template1';
-  $form->{dbhost}    = 'localhost';
+  $form->{dbhost}    = $::auth->{DB_config}->{host} || 'localhost';
 
   $form->{title}     = "Lx-Office ERP / " . $locale->text('Database Administration');
 
index 35fef99..74285e7 100644 (file)
@@ -92,7 +92,7 @@ sub add {
 
   $form->{title} = "Add";
 
-  $form->{callback} = "ap.pl?action=add" unless $form->{callback};
+  $form->{callback} = "ap.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
 
   AP->get_transdate(\%myconfig, $form);
   $form->{initial_transdate} = $form->{transdate};
index 251c464..0e5ab85 100644 (file)
@@ -95,7 +95,7 @@ sub add {
   # /saving the history
 
   $form->{title}    = "Add";
-  $form->{callback} = "ar.pl?action=add" unless $form->{callback};
+  $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
 
   AR->get_transdate(\%myconfig, $form);
   $form->{initial_transdate} = $form->{transdate};
@@ -983,12 +983,12 @@ sub update {
   $form->{invdate} = $form->{transdate};
 
   my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 oldcustomer);
+
   &check_name("customer");
-     
+
   # check_name ruft get_customer auf, oldcustomer wird überschrieben, daher wird dies vorher gemerkt
   # get_customer holt Bemerkungen als intnotes, für Debitorenbuchungen gibt es aber nur das Feld notes
-  $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer}; 
+  $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer};
 
   $form->{AR} = $saved_variables{AR};
   if ($saved_variables{AR_amount_1} =~ m/.--./) {
index 5417918..518e430 100644 (file)
@@ -1610,7 +1610,7 @@ sub post {
 
   remove_draft() if $form->{remove_draft};
 
-  $form->{callback} = build_std_url("action=add", "show_details");
+  $form->{callback} = build_std_url("action=add&DONT_LOAD_DRAFT=1", "show_details");
   $form->redirect($form->{callback});
 
   $main::lxdebug->leave_sub();
index afe1bc6..7d2dfb5 100755 (executable)
@@ -6,10 +6,12 @@ use FCGI;
 use SL::Dispatcher;
 use SL::FCGIFixes;
 
+our $dispatcher = SL::Dispatcher->new('FastCGI');
+$dispatcher->pre_startup_setup;
 SL::FCGIFixes::apply_fixes();
+$dispatcher->pre_startup_checks;
 
-SL::Dispatcher::pre_startup();
 my $request = FCGI::Request();
-SL::Dispatcher::handle_request('FastCGI') while $request->Accept() >= 0;
+$dispatcher->handle_request($request) while $request->Accept() >= 0;
 
 1;