[svn r12528] fix a bug when accents are present in xml doc :

simplexml convert by default the string in utf8, then we have to convert it again in the current charset
skala
Eric Marguin 18 years ago
parent 62b99a7d89
commit f783f1d793
  1. 37
      main/admin/session_import.php

@ -32,7 +32,10 @@ $language_file = array('admin','registration');
$cidReset=true; $cidReset=true;
include('../inc/global.inc.php'); include('../inc/global.inc.php');
if(empty($charset))
{
$charset = 'ISO-8859-15';
}
api_protect_admin_script(); api_protect_admin_script();
include(api_get_path(LIBRARY_PATH).'/fileManage.lib.php'); include(api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
@ -80,7 +83,7 @@ if($_POST['formSent'])
{ {
foreach($racine->Users->User as $userNode) foreach($racine->Users->User as $userNode)
{ {
$username = $userNode->Username; $username = mb_convert_encoding($userNode->Username,$charset,'utf-8');
$isCut = 0; // if the username given is too long $isCut = 0; // if the username given is too long
if(strlen($username)>20) if(strlen($username)>20)
{ {
@ -99,15 +102,15 @@ if($_POST['formSent'])
$errorMsg .= get_lang('UsernameTooLongWasCut').' '.get_lang('From').' '.$user_name_dist.' '.get_lang('To').' '.$username.' <br />'; $errorMsg .= get_lang('UsernameTooLongWasCut').' '.get_lang('From').' '.$user_name_dist.' '.get_lang('To').' '.$username.' <br />';
} }
$lastname = $userNode->Lastname; $lastname = mb_convert_encoding($userNode->Lastname,$charset,'utf-8');
$firstname = $userNode->Firstname; $firstname = mb_convert_encoding($userNode->Firstname,$charset,'utf-8');
$password = $userNode->Password; $password = mb_convert_encoding($userNode->Password,$charset,'utf-8');
if(empty($password)) if(empty($password))
$password = base64_encode(rand(1000,10000)); $password = base64_encode(rand(1000,10000));
$email = $userNode->Email; $email = mb_convert_encoding($userNode->Email,$charset,'utf-8');
$official_code = $userNode->OfficialCode; $official_code = mb_convert_encoding($userNode->OfficialCode,$charset,'utf-8');
$phone = $userNode->Phone; $phone = mb_convert_encoding($userNode->Phone,$charset,'utf-8');
$status = $userNode->Status; $status = mb_convert_encoding($userNode->Status,$charset,'utf-8');
switch($status) switch($status)
{ {
case 'student' : $status = 5; break; case 'student' : $status = 5; break;
@ -145,11 +148,11 @@ if($_POST['formSent'])
} }
foreach($racine->Courses->Course as $courseNode) foreach($racine->Courses->Course as $courseNode)
{ {
$course_code = $courseNode->CourseCode; $course_code = mb_convert_encoding($courseNode->CourseCode,$charset,'utf-8');
$title = $courseNode->CourseTitle; $title = mb_convert_encoding($courseNode->CourseTitle,$charset,'utf-8');
$description = $courseNode->CourseDescription; $description = mb_convert_encoding($courseNode->CourseDescription,$charset,'utf-8');
$language = $courseNode->CourseLanguage; $language = mb_convert_encoding($courseNode->CourseLanguage,$charset,'utf-8');
$username = $courseNode->CourseTeacher; $username = mb_convert_encoding($courseNode->CourseTeacher,$charset,'utf-8');
$sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'"; $sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'";
$rs = api_sql_query($sql, __FILE__, __LINE__); $rs = api_sql_query($sql, __FILE__, __LINE__);
@ -217,8 +220,8 @@ if($_POST['formSent'])
$countCourses = 0; $countCourses = 0;
$countUsers = 0; $countUsers = 0;
$SessionName = $sessionNode->SessionName; $SessionName = mb_convert_encoding($sessionNode->SessionName,$charset,'utf-8');
$Coach = $sessionNode->Coach; $Coach = mb_convert_encoding($sessionNode->Coach,$charset,'utf-8');
if(!empty($Coach)){ if(!empty($Coach)){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'"; $sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
@ -293,7 +296,7 @@ if($_POST['formSent'])
$session_id = mysql_insert_id(); $session_id = mysql_insert_id();
foreach ($sessionNode->User as $userNode){ foreach ($sessionNode->User as $userNode){
$username = substr($userNode->nodeValue(),0,20); $username = mb_convert_encoding(substr($userNode->nodeValue(),0,20),$charset,'utf-8');
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".Database::escape_string($username)."'"; $sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".Database::escape_string($username)."'";
$rsUser = api_sql_query($sqlUser); $rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser)); list($user_id) = (mysql_fetch_array($rsUser));

Loading…
Cancel
Save