Permissions Management - Simple Level
The LiveUser_Admin package allows you to manage rights granted directly to users. This corresponds to the Simple Level permission management. It provides a series of methods to interact with the «liveuser_userrights» table.
The example 1 provided with this PEAR package should help you starting quite quickly.
There are a few methods for user rights management:
- grantUserRight: to add a right to the list of rights
- updateUserRight: to modify a right in the list of rights
- revokeUserRight: to remove a right from the list of rights
We'll start by adding a user right, then updating it and finally deleting a user right.
Here is the full example :
Download «LUA_test_userright.php»
Add a user right (grantUserRight)
function grantUserRight($data)
Parameter(s)
This method takes 1 parameter:
- an array with a pair key/value of all fields in the «liveuser_userrights»
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
To add a user right:
...
$data = array(
'perm_user_id' => $users[0]['perm_user_id'],
'right_id' => 5,
'right_level' => 3,
);
$granted = $LUA->perm->grantUserRight($data);
...
This gives the following result:

Update a user right (updateUserRight)
function updateUserRight($data, $filter)
Parameter(s)
This method takes 2 parameters:
- an array with key/value containing the new value(s)
- an array with key/value to select the record to be updated
Attention: if no parameter is passed, all rights will be modified.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$new_right_level = 2;
$right_id = 5;
$handle = 'test user';
$filter = array('handle' => $handle);
$users = ('auth', $filter);
$data = array('right_level' => $new_right_level);
$filter = array('perm_user_id' => $users[0]['perm_user_id'],
'right_id' => $right_id);
$updatedUserRight = $LUA->perm->updateUserRight($data, $filter);
...
This gives the following result:

Remove a user right (revokeUserRight)
function revokeUserRight($filter)
This method will remove a right granted to a user.
Parameter(s)
This method takes 1 parameter:
- an array with key/value to select the record to be deleted.
Attention: if no parameter is passed, all user rights will be removed.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$right_id = 5;
$handle = 'test user';
$filter = array('handle' => $handle);
$users = $LUA->getUsers('auth', $filter);
$filter = array(
'perm_user_id' => $users[0]['perm_user_id'],
'right_id' => $right_id
);
$revoked = $LUA->perm->revokeUserRight($filter);
...
This gives the following result:

Getting Information on the last Error (getErrors)
function getErrors()
In case a function returns «false», it means that it has encountered a problem. You can get information on this error by calling this method.
Parameter(s)
This method takes no parameter.
Return value
This method returns:
- the error information
Example
...
$granted = $LUA->perm->grantUserRight($data);
if ($granted == false)
{
echo 'Add_userright: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'User Right added';
}
...



