Пример #1
0
/**
 * return the username or a string "user<id>" if the user does not exist
 * if show_user_realname_threshold is set and real name is not empty, return it instead
 *
 * @param integer $p_user_id A valid user identifier.
 * @return string
 */
function user_get_name($p_user_id)
{
    $t_row = user_cache_row($p_user_id, false);
    if (false == $t_row) {
        return lang_get('prefix_for_deleted_users') . (int) $p_user_id;
    } else {
        if (ON == config_get('show_realname')) {
            if (is_blank($t_row['realname'])) {
                return $t_row['username'];
            } else {
                if (isset($t_row['duplicate_realname']) && ON == $t_row['duplicate_realname']) {
                    return $t_row['realname'] . ' (' . $t_row['username'] . ')';
                } else {
                    return $t_row['realname'];
                }
            }
        } else {
            return $t_row['username'];
        }
    }
}
Пример #2
0
/**
 * This populates an option list with the appropriate users by access level
 * @todo from print_reporter_option_list
 * @param integer|array $p_user_id    A user identifier or a list of them.
 * @param integer       $p_project_id A project identifier.
 * @param integer       $p_access     An access level.
 * @return void
 */
function print_user_option_list($p_user_id, $p_project_id = null, $p_access = ANYBODY)
{
    $t_current_user = auth_get_current_user_id();
    if (null === $p_project_id) {
        $p_project_id = helper_get_current_project();
    }
    if ($p_project_id === ALL_PROJECTS) {
        $t_projects = user_get_accessible_projects($t_current_user);
        # Get list of users having access level for all accessible projects
        $t_users = array();
        foreach ($t_projects as $t_project_id) {
            $t_project_users_list = project_get_all_user_rows($t_project_id, $p_access);
            # Do a 'smart' merge of the project's user list, into an
            # associative array (to remove duplicates)
            foreach ($t_project_users_list as $t_id => $t_user) {
                $t_users[$t_id] = $t_user;
            }
            # Clear the array to release memory
            unset($t_project_users_list);
        }
        unset($t_projects);
    } else {
        $t_users = project_get_all_user_rows($p_project_id, $p_access);
    }
    # Add the specified user ID to the list
    # If we have an array of user IDs, then we've been called from a filter
    # so don't add anything
    if (!is_array($p_user_id) && $p_user_id != NO_USER && !array_key_exists($p_user_id, $t_users)) {
        $t_row = user_cache_row($p_user_id, false);
        if ($t_row === false) {
            # User doesn't exist - create a dummy record for display purposes
            $t_name = user_get_name($p_user_id);
            $t_row = array('id' => $p_user_id, 'username' => $t_name, 'realname' => $t_name);
        }
        $t_users[$p_user_id] = $t_row;
    }
    $t_display = array();
    $t_sort = array();
    $t_show_realname = ON == config_get('show_realname');
    $t_sort_by_last_name = ON == config_get('sort_by_last_name');
    foreach ($t_users as $t_key => $t_user) {
        $t_user_name = string_attribute($t_user['username']);
        $t_sort_name = utf8_strtolower($t_user_name);
        if ($t_show_realname && $t_user['realname'] != '') {
            $t_user_name = string_attribute($t_user['realname']);
            if ($t_sort_by_last_name) {
                $t_sort_name_bits = explode(' ', utf8_strtolower($t_user_name), 2);
                $t_sort_name = (isset($t_sort_name_bits[1]) ? $t_sort_name_bits[1] . ', ' : '') . $t_sort_name_bits[0];
            } else {
                $t_sort_name = utf8_strtolower($t_user_name);
            }
        }
        $t_display[] = $t_user_name;
        $t_sort[] = $t_sort_name;
    }
    array_multisort($t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display);
    unset($t_sort);
    $t_count = count($t_users);
    for ($i = 0; $i < $t_count; $i++) {
        $t_row = $t_users[$i];
        echo '<option value="' . $t_row['id'] . '" ';
        check_selected($p_user_id, (int) $t_row['id']);
        echo '>' . $t_display[$i] . '</option>';
    }
}