- my %connect_settings;
- my $initial_sql;
-
- if (!%::myconfig) {
- $type = 'LXOFFICE_EMPTY';
- %connect_settings = ( driver => 'Pg' );
-
- } elsif ($type eq 'LXOFFICE_AUTH') {
- %connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg',
- database => $::auth->{DB_config}->{db},
- host => $::auth->{DB_config}->{host} || 'localhost',
- port => $::auth->{DB_config}->{port} || 5432,
- username => $::auth->{DB_config}->{user},
- password => $::auth->{DB_config}->{password},
- connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8,
- });
- } else {
- my $european_dates = 0;
- if ($::myconfig{dateformat}) {
- $european_dates = 1 if $_dateformats{ $::myconfig{dateformat} }
- && $_dateformats{ $::myconfig{dateformat} } =~ m/european/i;
- }
+ require SL::DBConnect;
+ my %specific_connect_settings;
+ my %common_connect_settings = (
+ driver => 'Pg',
+ european_dates => ((SL::DBConnect->get_datestyle || '') =~ m/european/i) ? 1 : 0,
+ connect_options => {
+ pg_enable_utf8 => 1,
+ },
+ );
+
+ if (($type eq 'KIVITENDO_AUTH') && $::auth && $::auth->{DB_config} && $::auth->session_tables_present) {
+ %specific_connect_settings = (
+ database => $::auth->{DB_config}->{db},
+ host => $::auth->{DB_config}->{host} || 'localhost',
+ port => $::auth->{DB_config}->{port} || 5432,
+ username => $::auth->{DB_config}->{user},
+ password => $::auth->{DB_config}->{password},
+ );
+
+ } elsif ($::auth && $::auth->client) {
+ my $client = $::auth->client;
+ %specific_connect_settings = (
+ database => $client->{dbname},
+ host => $client->{dbhost} || 'localhost',
+ port => $client->{dbport} || 5432,
+ username => $client->{dbuser},
+ password => $client->{dbpasswd},
+ );
+
+ } elsif (%::myconfig && $::myconfig{dbname}) {
+ %specific_connect_settings = (
+ database => $::myconfig{dbname},
+ host => $::myconfig{dbhost} || 'localhost',
+ port => $::myconfig{dbport} || 5432,
+ username => $::myconfig{dbuser},
+ password => $::myconfig{dbpasswd},
+ );