From 6bfe5a56288000412826c500aabb76d3a2486331 Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 4 May 2007 05:13:09 +0000 Subject: UTF-8 update backpatch git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1123 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Form.pm | 10 +++++++++- LedgerSMB/Locale.pm | 3 +-- LedgerSMB/Sysconfig.pm | 1 + LedgerSMB/User.pm | 12 ++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) (limited to 'LedgerSMB') diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index a53668b1..011f2666 100755 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -41,6 +41,9 @@ use Time::Local; use Cwd; use File::Copy; +use charnames ':full'; +use open ':utf8'; + package Form; sub new { @@ -98,7 +101,7 @@ sub new { $self->error( "Access Denied", __line__, __file__ ); } - for ( keys %$self ) { $self->{$_} =~ s/\000//g } + for ( keys %$self ) { $self->{$_} =~ s/\N{NULL}//g } $self; } @@ -138,6 +141,7 @@ sub escape { $str = $self->escape( $str, 1 ) if $1 == 0 && $2 < 44; } + utf8::encode($str); $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge; $str; @@ -149,7 +153,9 @@ sub unescape { $str =~ tr/+/ /; $str =~ s/\\$//; + utf8::encode($str) if utf8::is_utf8($str); $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg; + utf8::decode($str); $str =~ s/\r?\n/\n/g; $str; @@ -1582,6 +1588,7 @@ sub dbconnect { my $dbh = DBI->connect( $myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd} ) or $self->dberror; + $dbh->{pg_enable_utf8} = 1; # set db options if ( $myconfig->{dboptions} ) { @@ -1601,6 +1608,7 @@ sub dbconnect_noauto { $myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, { AutoCommit => 0 } ) or $self->dberror; + $dbh->{pg_enable_utf8} = 1; # set db options if ( $myconfig->{dboptions} ) { diff --git a/LedgerSMB/Locale.pm b/LedgerSMB/Locale.pm index c89fbef0..6b1c4e66 100644 --- a/LedgerSMB/Locale.pm +++ b/LedgerSMB/Locale.pm @@ -27,7 +27,6 @@ package LedgerSMB::Locale; use base 'Locale::Maketext'; use Locale::Maketext::Lexicon; -use HTML::Entities; use Encode; Locale::Maketext::Lexicon->import( @@ -40,7 +39,7 @@ Locale::Maketext::Lexicon->import( sub text { my ( $self, $text, @params ) = @_; - return encode_entities( $self->maketext( $text, @params ) ); + return $self->maketext( $text, @params ); } ##sub date { diff --git a/LedgerSMB/Sysconfig.pm b/LedgerSMB/Sysconfig.pm index c1924916..6a78f3ac 100644 --- a/LedgerSMB/Sysconfig.pm +++ b/LedgerSMB/Sysconfig.pm @@ -123,6 +123,7 @@ if ( $config{globaldb}{DBname} ) { $form = new Form; $form->error("No GlobalDBH Configured or Could not Connect"); } + $GLOBALDBH->{pg_enable_utf8} = 1; } # These lines prevent other apps in mod_perl from seeing the global db diff --git a/LedgerSMB/User.pm b/LedgerSMB/User.pm index a46a530a..7ef25547 100755 --- a/LedgerSMB/User.pm +++ b/LedgerSMB/User.pm @@ -196,6 +196,7 @@ sub login { DBI->connect( $myconfig{dbconnect}, $myconfig{dbuser}, $myconfig{dbpasswd} ) or $self->error( __FILE__ . ':' . __LINE__ . ': ' . $DBI::errstr ); + $dbh->{pg_enable_utf8} = 1; # we got a connection, check the version my $query = qq| @@ -263,6 +264,7 @@ sub check_recurring { my $dbh = DBI->connect( $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; my $query = qq| SELECT count(*) FROM recurring @@ -319,6 +321,7 @@ sub dbsources { my $dbh = DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; if ( $form->{dbdriver} eq 'Pg' ) { @@ -337,6 +340,7 @@ sub dbsources { DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; $query = qq| SELECT tablename FROM pg_tables @@ -380,6 +384,7 @@ sub dbcreate { DBI->connect( $form->{dbconnect}, $form->{dbsuperuser}, $form->{dbsuperpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $superdbh->{pg_enable_utf8} = 1; my $query = qq|$dbcreate{$form->{dbdriver}}|; $superdbh->do($query) || $form->dberror( __FILE__ . ':' . __LINE__ . $query ); @@ -394,11 +399,13 @@ sub dbcreate { my $dbh = DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; if ( $form->{dbsuperuser} ) { my $superdbh = DBI->connect( $form->{dbconnect}, $form->{dbsuperuser}, $form->{dbsuperpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $superdbh->{pg_enable_utf8} = 1; # JD: We need to check for plpgsql, # if it isn't there create it, if we can't error @@ -474,6 +481,7 @@ sub dbneedsupdate { my $dbh = DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; if ( $form->{dbdriver} =~ /Pg/ ) { @@ -496,6 +504,7 @@ sub dbneedsupdate { DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; $query = qq| SELECT tablename @@ -561,6 +570,7 @@ sub dbupdate { $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, { AutoCommit => 0 } ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; # check version $query = qq| @@ -790,6 +800,7 @@ sub save_member { $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd}, { AutoCommit => 0 } ) or $self->error($DBI::errstr); + $dbh->{pg_enable_utf8} = 1; # add login to employee table if it does not exist my $login = $self->{login}; @@ -843,6 +854,7 @@ sub delete_login { $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, { AutoCommit => 0 } ) or $form->dberror( __FILE__ . ':' . __LINE__ ); + $dbh->{pg_enable_utf8} = 1; my $login = $form->{login}; $login =~ s/@.*//; -- cgit v1.2.3