}
} else {
    if ($mbuser = $helper->registerUser($fullname, 1, $email)) {
        $account_link = (object) null;
        $account_link->external_id = $moodleid;
        $account_link->internal_id = $mbuser;
        $account_link->system = "moodle";
        insert_record("studynotes_account_links", $account_link, false);
    } else {
        error(get_string('error_linking', 'studynotes'));
    }
}
$auth = new MediabirdMoodleAuth($mbuser);
//set up config
MediabirdConfig::$latex_path = $CFG->studynotes_latex_path;
MediabirdConfig::$convert_path = $CFG->studynotes_dvipng_path;
//set up proxy
if (isset($CFG->proxyhost) && strlen($CFG->proxyhost) > 0 && (!isset($CFG->proxytype) || $CFG->proxytype == 'HTTP')) {
    MediabirdConfig::$proxy_address = $CFG->proxyhost;
    MediabirdConfig::$proxy_port = $CFG->proxyport;
}
MediabirdConfig::$uploads_folder = $CFG->dataroot . DIRECTORY_SEPARATOR . "1" . DIRECTORY_SEPARATOR . "moddata" . DIRECTORY_SEPARATOR . "studynotes" . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR;
if (!file_exists(MediabirdConfig::$uploads_folder . $auth->userId)) {
    make_mod_upload_directory(1);
    make_upload_directory("1/moddata/studynotes/uploads/" . $auth->userId);
    // we store our images in a subfolder in here
}
MediabirdConfig::$cache_folder = $CFG->dataroot . DIRECTORY_SEPARATOR . "temp" . DIRECTORY_SEPARATOR . "studynotes" . DIRECTORY_SEPARATOR;
if (!file_exists(MediabirdConfig::$cache_folder)) {
    make_upload_directory("temp/studynotes");
}