function migrate2utf8_netpublish_name($recordid)
{
    global $CFG, $globallang;
    /// Some trivial checks
    if (empty($recordid)) {
        log_the_problem_somewhere();
        return false;
    }
    if (!($netpublish = get_record('netpublish', 'id', $recordid))) {
        log_the_problem_somewhere();
        return false;
    }
    if ($globallang) {
        $fromenc = $globallang;
    } else {
        $sitelang = $CFG->lang;
        $courselang = get_course_lang($netpublish->course);
        //Non existing!
        $userlang = get_main_teacher_lang($netpublish->course);
        //N.E.!!
        $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
    }
    /// We are going to use textlib facilities
    /// Convert the text
    if ($fromenc != 'utf-8' && $fromenc != 'UTF-8') {
        $result = utfconvert($netpublish->name, $fromenc);
        $newpublish = new object();
        $newpublish->id = $recordid;
        $newpublish->name = $result;
        migrate2utf8_update_record('netpublish', $newpublish);
    }
    /// And finally, just return the converted field
    return $result;
}
function migrate2utf8_questionnaire_question_choice_value($recordid)
{
    global $CFG, $globallang;
    /// Some trivial checks
    if (empty($recordid)) {
        log_the_problem_somewhere();
        return false;
    }
    if (!($choice = get_record('questionnaire_question_choice', 'id', $recordid))) {
        log_the_problem_somewhere();
        return false;
    }
    if (!($courseid = get_field('questionnaire_survey', 'owner', 'id', get_field('questionnaire_question', 'survey_id', 'id', $choice->question_id)))) {
        log_the_problem_somewhere();
        return false;
    }
    if ($globallang) {
        $fromenc = $globallang;
    } else {
        $sitelang = $CFG->lang;
        $courselang = get_course_lang($courseid);
        //Non existing!
        $userlang = get_main_teacher_lang($courseid);
        //N.E.!!
        $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
    }
    /// We are going to use textlib facilities
    /// Convert the text
    if ($fromenc != 'utf-8' && $fromenc != 'UTF-8') {
        $result = utfconvert($choice->value, $fromenc);
        $newchoice = new object();
        $newchoice->id = $recordid;
        $newchoice->value = $result;
        migrate2utf8_update_record('questionnaire_question_choice', $newchoice);
    }
    /// And finally, just return the converted field
    return $result;
}
function migrate2utf8_wiki_votes_username($recordid)
{
    global $CFG, $globallang;
    /// Some trivial checks
    if (empty($recordid)) {
        log_the_problem_somewhere();
        return false;
    }
    $SQL = "SELECT w.course\n           FROM {$CFG->prefix}wiki w,\n                {$CFG->prefix}wiki_votes ws\n           WHERE w.id = ws.dfwiki\n                 AND ws.id = {$recordid}";
    if (!($wiki = get_record_sql($SQL))) {
        log_the_problem_somewhere();
        return false;
    }
    if (!($wikivotes = get_record('wiki_votes', 'id', $recordid))) {
        log_the_problem_somewhere();
        return false;
    }
    if ($globallang) {
        $fromenc = $globallang;
    } else {
        $sitelang = $CFG->lang;
        $courselang = get_course_lang($wiki->course);
        //Non existing!
        $userlang = get_main_teacher_lang($wiki->course);
        //N.E.!!
        $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
    }
    /// We are going to use textlib facilities
    /// Convert the text
    if ($fromenc != 'utf-8' && $fromenc != 'UTF-8') {
        $result = utfconvert($wikivotes->username, $fromenc);
        $newwikiwikivotes = new object();
        $newwikiwikivotes->id = $recordid;
        $newwikiwikivotes->username = $result;
        migrate2utf8_update_record('wiki_votes', $newwikiwikivotes);
    }
    /// And finally, just return the converted field
    return $result;
}