Hi,

The module works as promised, but a Japanese course title from Moodle (ドイツ語レッスン) gets mangled in Drupal and displays only as ????????.

The encoding of both databases is utf8_unicode_ci.

Frank

Comments

borgo’s picture

I can confirm this

Any special chars like čšľšť etc. will prevent title from displaying.

Removing check_plain() helps a little, but thats not the way to go I suppose

function _moodle_courselist_make_links($rows) {
  $url_to_moodle = variable_get('moodle_courselist_moodleurl', '');

  foreach ($rows as $row) {
    $url = $url_to_moodle . "course/view.php?id=". check_plain($row['cid']);
    //$coursename = check_plain($row['fullname']);
    $coursename = $row['fullname'];
    $linklist .= l($coursename,check_url($url)) . "<br>";
  }
  return $linklist;
}
frank ralf’s picture

Looks like the function isn't fully UTF-8 compatible. I only had a quick look at the API documentation of check_plain(). It uses drupal_validate_utf8() which in turn uses the PHP function preg_match():

This function exploits preg_match behaviour (since PHP 4.3.5) when used with the u modifier, as a fast way to find invalid UTF-8. When the matched string contains an invalid byte sequence, it will fail silently.

Haven't done any further investigating or testing yet.

darafsheh’s picture

Hi guys,

the solution to this problem is actually quite easy. all you have to do is to set the mysql charset to utf-8 by adding this line:

mysql_set_charset("UTF8");

So it would look something like this:

 mysql_connect($server, $username, $password) or drupal_set_message(mysql_error(),'warning');
  mysql_select_db($database_name) or drupal_set_message(mysql_error(),'warning');
  mysql_set_charset("UTF8");
  $query = "SELECT c.fullname, c.id as cid, usr.id as uid, usr.username
            FROM ".$database_prefix."course c
            INNER JOIN ".$database_prefix."context cx ON c.id = cx.instanceid
            AND cx.contextlevel = '50'
            INNER JOIN ".$database_prefix."role_assignments ra ON cx.id = ra.contextid
            INNER JOIN ".$database_prefix."role r ON ra.roleid = r.id
            INNER JOIN ".$database_prefix."user usr ON ra.userid = usr.id
            WHERE usr.username = '". mysql_real_escape_string($user->name) ."'";
....

i hope this works.

thanks,
shar

frank ralf’s picture

Thanks, Shar, that did the trick!

agerson’s picture

Status: Active » Needs review
agerson’s picture

Version: 6.x-1.2 » 6.x-1.3
Status: Needs review » Fixed
agerson’s picture

Status: Fixed » Closed (fixed)