I find some problems in changing the user's role, and correct them by modifying the method "assign" in the class "roles" (file: include/class.roles.php, at line 130 and following).
Here's my version:
function assign($role, $user)
{
global $conn;
$role = (int) $role;
$user = (int) $user;
// get the number of roles already assigned to $user
$chk = $conn->query("SELECT COUNT(*) FROM roles_assigned WHERE user = $user")->fetch();
$chk = $chk[0];
// If there already is a role assigned to the user, just update this entry
// Otherwise create a new entry
if ($chk > 0) {
$insStmt = $conn->prepare("UPDATE roles_assigned SET role = ? WHERE user = ?");
} else {
$insStmt = $conn->prepare("INSERT INTO roles_assigned (role,user) VALUES (?,?)");
}
$ins = $insStmt->execute(array($role, $user));
if ($ins) {
return true;
} else {
return false;
}
}
I find some problems in changing the user's role, and correct them by modifying the method "assign" in the class "roles" (file: include/class.roles.php, at line 130 and following). Here's my version: