Die JavaScript-Funktion "encodeURIComponent()" benutzt immer UTF-8 als Zeichensatz...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 16 Mar 2009 17:25:15 +0000 (17:25 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 16 Mar 2009 17:25:15 +0000 (17:25 +0000)
15 files changed:
SL/Form.pm
js/calculate_qty.js
js/common.js
js/customer_or_vendor_selection.js
js/delivery_customer_selection.js
js/dunning.js
js/follow_up.js
js/part_selection.js
js/parts_language_selection.js
js/show_history.js
js/show_vc_details.js
js/stock_in_out.js
js/vendor_selection.js
templates/webpages/admin/edit_user_de.html
templates/webpages/admin/edit_user_master.html

index 355d60a..71af15e 100644 (file)
@@ -70,12 +70,10 @@ END {
 sub _store_value {
   $main::lxdebug->enter_sub(2);
 
-  my $self  = shift;
+  my $curr  = shift;
   my $key   = shift;
   my $value = shift;
 
-  my $curr  = $self;
-
   while ($key =~ /\[\+?\]\.|\./) {
     substr($key, 0, $+[0]) = '';
 
@@ -103,14 +101,14 @@ sub _store_value {
 sub _input_to_hash {
   $main::lxdebug->enter_sub(2);
 
-  my $self  = shift;
-  my $input = shift;
+  my $params = shift;
+  my $input  = shift;
 
-  my @pairs = split(/&/, $input);
+  my @pairs  = split(/&/, $input);
 
   foreach (@pairs) {
     my ($key, $value) = split(/=/, $_, 2);
-    $self->_store_value($self->unescape($key), $self->unescape($value));
+    _store_value($params, unescape(undef, $key), unescape(undef, $value));
   }
 
   $main::lxdebug->leave_sub(2);
@@ -119,13 +117,13 @@ sub _input_to_hash {
 sub _request_to_hash {
   $main::lxdebug->enter_sub(2);
 
-  my $self  = shift;
-  my $input = shift;
+  my $params = shift;
+  my $input  = shift;
 
   if (!$ENV{'CONTENT_TYPE'}
       || ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
 
-    $self->_input_to_hash($input);
+    _input_to_hash($params, $input);
 
     $main::lxdebug->leave_sub(2);
     return;
@@ -173,8 +171,8 @@ sub _request_to_hash {
           substr $line, $-[0], $+[0] - $-[0], "";
         }
 
-        $previous         = $self->_store_value($name, '');
-        $self->{FILENAME} = $filename if ($filename);
+        $previous           = _store_value($params, $name, '');
+        $params->{FILENAME} = $filename if ($filename);
 
         next;
       }
@@ -196,6 +194,29 @@ sub _request_to_hash {
   $main::lxdebug->leave_sub(2);
 }
 
+sub _recode_recursively {
+  my ($iconv, $param) = @_;
+
+  if (ref $param eq 'HASH') {
+    foreach my $key (keys %{ $param }) {
+      if (!ref $param->{$key}) {
+        $param->{$key} = $iconv->convert($param->{$key});
+      } else {
+        _recode_recursively($iconv, $param->{$key});
+      }
+    }
+
+  } elsif (ref $param eq 'ARRAY') {
+    foreach my $idx (0 .. scalar(@{ $param }) - 1) {
+      if (!ref $param->[$idx]) {
+        $param->[$idx] = $iconv->convert($param->[$idx]);
+      } else {
+        _recode_recursively($iconv, $param->[$idx]);
+      }
+    }
+  }
+}
+
 sub new {
   $main::lxdebug->enter_sub();
 
@@ -220,7 +241,22 @@ sub new {
 
   bless $self, $type;
 
-  $self->_request_to_hash($_);
+  my $parameters = { };
+  _request_to_hash($parameters, $_);
+
+  my $db_charset   = $main::dbcharset;
+  $db_charset    ||= Common::DEFAULT_CHARSET;
+
+  if ($parameters->{INPUT_ENCODING} && (lc $parameters->{INPUT_ENCODING} ne $db_charset)) {
+    require Text::Iconv;
+    my $iconv = Text::Iconv->new($parameters->{INPUT_ENCODING}, $db_charset);
+
+    _recode_recursively($iconv, $parameters);
+
+    delete $parameters{INPUT_ENCODING};
+  }
+
+  map { $self->{$_} = $parameters->{$_}; } keys %{ $parameters };
 
   $self->{action}  =  lc $self->{action};
   $self->{action}  =~ s/( |-|,|\#)/_/g;
index 4a7f91b..a3bf3ad 100644 (file)
@@ -7,6 +7,7 @@ function calculate_qty_selection_window(input_name, alu, formel, row) {
     var description = document.getElementsByName("description_" + row)[0].value;
   }  else var action = "calculate_qty";
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=" + action + "&" +
     "name=" + encodeURIComponent(name) + "&" +
     "input_name=" + encodeURIComponent(input_name) + "&" +
index 6d818f3..8decd61 100644 (file)
@@ -42,6 +42,7 @@ function set_longdescription_window(input_name) {
   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
   var name = document.getElementsByName(input_name)[0].value;
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=set_longdescription&" +
     "longdescription=" + encodeURIComponent(document.getElementsByName(input_name)[0].value) + "&" +
     "input_name=" + encodeURIComponent(input_name) + "&"
index 2e16980..b09183f 100644 (file)
@@ -2,6 +2,7 @@ function customer_or_vendor_selection_window(input_name, input_id, is_vendor, al
   var parm = centerParms(800,600) + ",width=800,height=600,status=yes,scrollbars=yes";
   var name = document.getElementsByName(input_name)[0].value;
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=cov_selection_internal&" +
     "name=" + encodeURIComponent(name) + "&" +
     "input_name=" + encodeURIComponent(input_name) + "&" +
index c44b338..89f7740 100644 (file)
@@ -2,6 +2,7 @@ function delivery_customer_selection_window(input_name, input_id) {
   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
   var name = document.getElementsByName(input_name)[0].value;
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=delivery_customer_selection&" +
     "name=" + encodeURIComponent(name) + "&" +
     "input_name=" + encodeURIComponent(input_name) + "&" +
index ccf80c6..9a794a9 100644 (file)
@@ -1,6 +1,7 @@
 function set_email_window(input_subject, input_body, input_attachment) {
   var parm = centerParms(800,600) + ",width=800,height=600,status=yes,scrollbars=yes";
   var url = "dn.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=set_email&" +
     "email_subject=" + encodeURIComponent(document.getElementsByName(input_subject)[0].value) + "&" +
     "email_body=" + encodeURIComponent(document.getElementsByName(input_body)[0].value) + "&" +
index 379c716..4b11dcd 100644 (file)
@@ -4,6 +4,7 @@ function follow_up_window() {
   var parm = centerParms(width, height) + ",width=" + width + ",height=" + height + ",status=yes,scrollbars=yes";
 
   url = "fu.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=add" + "&" +
     "POPUP_MODE=1";
 
index 3e0c500..9ce022c 100644 (file)
@@ -24,6 +24,7 @@ function part_selection_window(input_partnumber, input_description, input_partsi
     options = "";
 
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=part_selection_internal&" +
     "partnumber="              + encodeURIComponent(partnumber)        + "&" +
     "description="             + encodeURIComponent(description)       + "&" +
index de5dafd..a060716 100644 (file)
@@ -2,6 +2,7 @@ function parts_language_selection_window(input_name) {
   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
   var name = document.getElementsByName(input_name)[0].value;
   url = "ic.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=parts_language_selection&" +
     "id="              + encodeURIComponent(document.ic.id.value)              + "&" +
     "language_values=" + encodeURIComponent(document.ic.language_values.value) + "&" +
index 5591259..e0cfec4 100644 (file)
@@ -14,6 +14,7 @@ function set_history_window(id) {
   var parm = centerParms(800,500) + ",width=800,height=500,status=yes,scrollbars=yes";
   var name = "History";
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=show_history&" +
     "longdescription=" + "&" +
     "input_name=" + encodeURIComponent(id) + "&"
index 3e5bffc..067a264 100644 (file)
@@ -6,6 +6,7 @@ function show_vc_details(vc) {
   if (vc_id)
     vc_id = vc_id[0].value;
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=show_vc_details&" +
     "vc=" + encodeURIComponent(vc) + "&" +
     "vc_id=" + encodeURIComponent(vc_id)
index 93d120a..5cffa3d 100644 (file)
@@ -11,6 +11,7 @@ function open_stock_in_out_window(in_out, row) {
   var delivered = document.getElementsByName("delivered")[0].value;
 
   url = "do.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=stock_in_out_form&" +
     "in_out="    + encodeURIComponent(in_out)    + "&" +
     "row="       + encodeURIComponent(row)       + "&" +
index 2986357..3d98f4b 100644 (file)
@@ -2,6 +2,7 @@ function vendor_selection_window(input_name, input_id) {
   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
   var name = document.getElementsByName(input_name)[0].value;
   url = "common.pl?" +
+    "INPUT_ENCODING=UTF-8&" +
     "action=vendor_selection&" +
     "name=" + encodeURIComponent(name) + "&" +
     "input_name=" + encodeURIComponent(input_name) + "&" +
index 3b76671..b35b8da 100644 (file)
@@ -5,7 +5,7 @@
   <!--
       function open_connection_test_window() {
         // host name port user passwd
-        var url = "admin.pl?action=test_db_connection&" +
+        var url = "admin.pl?INPUT_ENCODING=UTF-8&action=test_db_connection&" +
           "dbhost="   + encodeURIComponent(get_input_value("dbhost"))   + "&" +
           "dbport="   + encodeURIComponent(get_input_value("dbport"))   + "&" +
           "dbname="   + encodeURIComponent(get_input_value("dbname"))   + "&" +
index 92152a7..2bc4ec8 100644 (file)
@@ -5,7 +5,7 @@
   <!--
       function open_connection_test_window() {
         // host name port user passwd
-        var url = "admin.pl?action=test_db_connection&" +
+        var url = "admin.pl?INPUT_ENCODING=UTF-8&action=test_db_connection&" +
           "dbhost="   + encodeURIComponent(get_input_value("dbhost"))   + "&" +
           "dbport="   + encodeURIComponent(get_input_value("dbport"))   + "&" +
           "dbname="   + encodeURIComponent(get_input_value("dbname"))   + "&" +