Exemplo n.º 1
0
/**
 * Checks if a user is a member of a group.
 *
 * @param integer auth_id auth_id
 * @param integer group_id group_id
 * @return boolean true if user is in the group, false otherwise
 */
function liveuser_checkGroupUser($group_id, $auth_id)
{
    global $liveuserPermAdmin;
    if (is_numeric($auth_id) && is_numeric($group_id) && is_numeric($perm_id = liveuser_getPermUserId('user_id', $auth_id))) {
        $groups = $liveuserPermAdmin->getGroups(array('where_user_id' => $perm_id, 'where_group_id' => $group_id));
        return is_array($groups) && !empty($groups);
    }
    return false;
}
Exemplo n.º 2
0
/**
 * Sets the specified preference's value for the specified user.
 *
 * @param string username user handle 
 * @param string field_name preference field name
 * @return boolean true if the preference was successfully set, false otherwise
 */
function liveuser_pref_setPref($username, $field_name, $field_value)
{
    global $liveuserDB;
    $user_id = liveuser_getPermUserId($username);
    /* attempt to fetch existing field_id for the field_name, or create a new field if necessary */
    if (($field_id = liveuser_pref_checkField($field_name)) === false && ($field_id = liveuser_pref_setField($field_name)) === false) {
        return false;
    }
    $pref_id = $liveuserDB->getOne('
	SELECT pref_id 
	FROM ' . LW_PREFIX . '_prefs_data 
	WHERE user_id = ? AND field_id = ?', array((int) $user_id, (int) $field_id));
    if (isset($pref_id) && is_numeric($pref_id)) {
        return $liveuserDB->query('
	    UPDATE ' . LW_PREFIX . '_prefs_data 
	    SET field_value = ? 
	    WHERE pref_id = ?', array($field_value, (int) $pref_id)) == DB_OK;
    } else {
        return $liveuserDB->query('
	    INSERT INTO ' . LW_PREFIX . '_prefs_data (field_value, user_id, field_id) VALUES (?, ?, ?)', array($field_value, (int) $user_id, (int) $field_id)) == DB_OK;
    }
}