Adding additional role to one user

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
jswordy
User
Posts: 2

Adding additional role to one user

Post by jswordy »

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


mobhar
User
Posts: 11712

Post by mobhar »

Double check your SQL above. You may try it first in your database manager to make sure it is working and output the value as expected.


jswordy
User
Posts: 2

Post by jswordy »

The SQL has been debugged, it works correctly and return the correct values. The problem is on the functions that does not seems to affect the application behaviors.


mobhar
User
Posts: 11712

Post by mobhar »

Then double check your code again. This code:
AddUserPermission

should be:
addUserPermission


arbei
User
Posts: 9372

Post by arbei »

You may debug your code by logging the result, then check the log file and make sure the results are correct, e.g.

jswordy wrote:

         while ($row = $result->fetch()) {
                 $myTmpTableName = explode("}", $row['TableName']);
                 $myTableName = $myTmpTableName[1];
                 $myUserLevelName = $row['UserLevelName'];
                 $myPermission = $row['Permission'];
                 Log("AddUserPermission", [$myUserLevelName, $myTableName, $myPermission]); // * Log and check * 
                 $this->AddUserPermission($myUserLevelName, $myTableName,$myPermission);
         }

Post Reply