From c5c80b4b9773ff800fbcf1a3603ce849ec650e1c Mon Sep 17 00:00:00 2001 From: Andreas Back Date: Sun, 19 Jun 2011 15:08:59 +0300 Subject: [PATCH] Utf8 support and Real names --- pages/import_issues_inc.php | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-) diff --git a/pages/import_issues_inc.php b/pages/import_issues_inc.php index 8e9640b..db3ef08 100644 --- a/pages/import_issues_inc.php +++ b/pages/import_issues_inc.php @@ -8,6 +8,8 @@ if( $g_project_id == ALL_PROJECTS ) # This identify a custom field $g_custom_field_identifier = 'custom_'; +#Normally we expect the file to be in Latin1 and the database to be in utf-8 +$g_files_is_ISO8859_1 = true; # All column names that can be used with this project $g_all_fields = array(); @@ -104,9 +106,22 @@ function csv_string_unescape( $p_string ) { # -------------------- function read_csv_file( $p_filename ) { + global $g_files_is_ISO8859_1; $t_regexp = '/\G((?:[^"\r\n]+|"[^"]*")+)[\r|\n]*/sm'; $t_file_content = file_get_contents( $p_filename ); + # Do it exist a UTF-8 byte order mark? + $bom = pack("CCC", 0xef, 0xbb, 0xbf); + if (0 == strncmp($t_file_content, $bom, 2)) { + $t_file_content = substr($t_file_content, 3); + $g_files_is_ISO8859_1 = false; + }else{ + $g_files_is_ISO8859_1 = true; + } + + # Need to add a non default module for this so we support both UTF and Latin1 + #$t_file_content = mb_convert_encoding($t_file_content 'UTF-8'); + preg_match_all($t_regexp, $t_file_content, $t_file_rows); return $t_file_rows[1]; } @@ -137,7 +152,13 @@ function category_get_id_by_name_ne( $p_category_name, $p_project_id ) { } function prepare_output( $t_string , $t_encode_only = false ) { - return string_html_specialchars( utf8_encode($t_string) ); + + global $g_files_is_ISO8859_1; + + if($g_files_is_ISO8859_1 == true){ + $t_string = utf8_encode($t_string); + } + return string_html_specialchars( $t_string ); } function get_csv_import_category_id( $t_project_id , $t_category_name ) { @@ -234,6 +255,10 @@ function get_user_column_value( $p_name, $p_row, $p_default ) { return $p_default; } + if( ($t_user_id = user_get_id_by_realname($t_username)) !== false ) { + return $t_user_id; + } + if( ($t_user_id = user_get_id_by_name($t_username)) !== false ) { return $t_user_id; } @@ -253,8 +278,18 @@ function get_user_column_value( $p_name, $p_row, $p_default ) { #----------------------- function get_column_value( $p_name, $p_row, $p_default = '' ) { global $f_columns; + global $g_files_is_ISO8859_1; + $t_column = array_isearch( $p_name, $f_columns ); - return ( ($t_column === false) || (!isset( $p_row[$t_column] )) ) ? $p_default : utf8_encode(trim( $p_row[$t_column] )); + $column_val; + if(( ($t_column === false) || (!isset( $p_row[$t_column] )) )){ + $column_val = $p_default; + } elseif ($g_files_is_ISO8859_1 == true){ + $column_val = utf8_encode(trim( $p_row[$t_column] )); + }else{ + $column_val = trim( $p_row[$t_column] ); + } + return $column_val; } #----------------------- -- 1.7.4.msysgit.0