Ejemplo n.º 1
0
/**
 * Function to transform Moodle username to Alfresco username
 * converting 'admin' user and adding tenant info.
 * Check to make sure username has NOT already been transformed
 *
 * @param  $username the username to transform
 * @uses   $CFG
 * @uses   $USER
 * @return string    the transformed username.
 */
function elis_files_transform_username($username) {
    global $CFG, $USER;

    $tenantpos = strpos(elis::$config->elisfiles->server_username, '@');
    if ($username == 'admin' || empty($USER->username) || $USER->username == $username ||
        (($atpos = strpos($username, '@')) !== false &&
          ($tenantpos === false ||
           strcmp(substr($username, $atpos),
                  substr(elis::$config->elisfiles->server_username, $tenantpos))))
       || ($atpos === false && $tenantpos !== false)) {

        // Fix username
        $username = ELIS_files::alfresco_username_fix($username);

        // So that we don't conflict with the default Alfresco admin account.
        $username = ($username == 'admin')
                    ? elis::$config->elisfiles->admin_username : $username;

        // We must include the tenant portion of the username here.
        if ($tenantpos > 0) {
            $username .= substr(elis::$config->elisfiles->server_username, $tenantpos);
        }
    }
    return $username;
}