Hello,
i would like to give an user two roles, as for this i'm using the "UserLevel_Loaded" function feature.
I set two roles that give different permission on to two different tables, then i have tried to give the first role to the user via configuration and the second role via code in runtime. To do it I have edited the following code (added to the "UserLevel_Loaded"):
/* i have removed some checks but included only the real code */
$myUserId = CurrentUserID();
// getting the additional role i need to add to the user.
// I'm getting the values directly from the "Dynamic User levels" tables and a table i have created to join the "additional" role with the user (usersroles)
$sql = "SELECT ULV.UserLevelName AS UserLevelName, ULP.TableName AS TableName, ULP.Permission AS Permission
FROM userlevelpermissions AS ULP, userlevels AS ULV
WHERE ULP.UserLevelId = ULV.UserLevelID
AND ULP.Permission <> 0
AND ULP.UserLevelId IN (SELECT roleid FROM usersroles WHERE userid = ".$myUserId.");";
$result = ExecuteQuery($sql);
if ($result->rowCount() > 0) {
while ($row = $result->fetch()) {
$myTmpTableName = explode("}", $row['TableName']);
$myTableName = $myTmpTableName[1];
$myUserLevelName = $row['UserLevelName'];
$myPermission = $row['Permission'];
$this->AddUserPermission($myUserLevelName, $myTableName,$myPermission);
}
}
Unfortunately the permission are not added to the user, have any one a working code ?
Thanks